1 /* Copyright (c) 2012-2017, 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_MAX_NUM_REQUESTED_FACES[] = "qc-max-num-requested-faces";
399 
400 //Values for DENOISE
401 const char QCameraParameters::DENOISE_OFF[] = "denoise-off";
402 const char QCameraParameters::DENOISE_ON[] = "denoise-on";
403 
404 // Values for selectable zone af Settings
405 const char QCameraParameters::FOCUS_ALGO_AUTO[] = "auto";
406 const char QCameraParameters::FOCUS_ALGO_SPOT_METERING[] = "spot-metering";
407 const char QCameraParameters::FOCUS_ALGO_CENTER_WEIGHTED[] = "center-weighted";
408 const char QCameraParameters::FOCUS_ALGO_FRAME_AVERAGE[] = "frame-average";
409 
410 // Values for HFR settings.
411 const char QCameraParameters::VIDEO_HFR_OFF[] = "off";
412 const char QCameraParameters::VIDEO_HFR_2X[] = "60";
413 const char QCameraParameters::VIDEO_HFR_3X[] = "90";
414 const char QCameraParameters::VIDEO_HFR_4X[] = "120";
415 const char QCameraParameters::VIDEO_HFR_5X[] = "150";
416 const char QCameraParameters::VIDEO_HFR_6X[] = "180";
417 const char QCameraParameters::VIDEO_HFR_7X[] = "210";
418 const char QCameraParameters::VIDEO_HFR_8X[] = "240";
419 const char QCameraParameters::VIDEO_HFR_9X[] = "480";
420 
421 // Values for HDR Bracketing settings.
422 const char QCameraParameters::AE_BRACKET_OFF[] = "Off";
423 const char QCameraParameters::AE_BRACKET[] = "AE-Bracket";
424 
425 // Values for AF Bracketing setting.
426 const char QCameraParameters::AF_BRACKET_OFF[] = "af-bracket-off";
427 const char QCameraParameters::AF_BRACKET_ON[] = "af-bracket-on";
428 
429 // Values for Refocus setting.
430 const char QCameraParameters::RE_FOCUS_OFF[] = "re-focus-off";
431 const char QCameraParameters::RE_FOCUS_ON[] = "re-focus-on";
432 
433 // Values for Chroma Flash setting.
434 const char QCameraParameters::CHROMA_FLASH_OFF[] = "chroma-flash-off";
435 const char QCameraParameters::CHROMA_FLASH_ON[] = "chroma-flash-on";
436 
437 // Values for Opti Zoom setting.
438 const char QCameraParameters::OPTI_ZOOM_OFF[] = "opti-zoom-off";
439 const char QCameraParameters::OPTI_ZOOM_ON[] = "opti-zoom-on";
440 
441 // Values for Still More setting.
442 const char QCameraParameters::STILL_MORE_OFF[] = "still-more-off";
443 const char QCameraParameters::STILL_MORE_ON[] = "still-more-on";
444 
445 // Values for HDR mode setting.
446 const char QCameraParameters::HDR_MODE_SENSOR[] = "hdr-mode-sensor";
447 const char QCameraParameters::HDR_MODE_MULTI_FRAME[] = "hdr-mode-multiframe";
448 
449 // Values for True Portrait setting.
450 const char QCameraParameters::TRUE_PORTRAIT_OFF[] = "true-portrait-off";
451 const char QCameraParameters::TRUE_PORTRAIT_ON[] = "true-portrait-on";
452 
453 // Values for FLIP settings.
454 const char QCameraParameters::FLIP_MODE_OFF[] = "off";
455 const char QCameraParameters::FLIP_MODE_V[] = "flip-v";
456 const char QCameraParameters::FLIP_MODE_H[] = "flip-h";
457 const char QCameraParameters::FLIP_MODE_VH[] = "flip-vh";
458 
459 const char QCameraParameters::CDS_MODE_OFF[] = "off";
460 const char QCameraParameters::CDS_MODE_ON[] = "on";
461 const char QCameraParameters::CDS_MODE_AUTO[] = "auto";
462 
463 // Values for video rotation settings.
464 const char QCameraParameters::VIDEO_ROTATION_0[] = "0";
465 const char QCameraParameters::VIDEO_ROTATION_90[] = "90";
466 const char QCameraParameters::VIDEO_ROTATION_180[] = "180";
467 const char QCameraParameters::VIDEO_ROTATION_270[] = "270";
468 
469 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_FOCUS_MODES[] = "manual-focus-modes";
470 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_EXPOSURE_MODES[] = "manual-exposure-modes";
471 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_WB_MODES[] = "manual-wb-modes";
472 const char QCameraParameters::KEY_QC_FOCUS_SCALE_MODE[] = "scale-mode";
473 const char QCameraParameters::KEY_QC_FOCUS_DIOPTER_MODE[] = "diopter-mode";
474 const char QCameraParameters::KEY_QC_ISO_PRIORITY[] = "iso-priority";
475 const char QCameraParameters::KEY_QC_EXP_TIME_PRIORITY[] = "exp-time-priority";
476 const char QCameraParameters::KEY_QC_USER_SETTING[] = "user-setting";
477 const char QCameraParameters::KEY_QC_WB_CCT_MODE[] = "color-temperature";
478 const char QCameraParameters::KEY_QC_WB_GAIN_MODE[] = "rbgb-gains";
479 const char QCameraParameters::KEY_QC_NOISE_REDUCTION_MODE[] = "noise-reduction-mode";
480 const char QCameraParameters::KEY_QC_NOISE_REDUCTION_MODE_VALUES[] = "noise-reduction-mode-values";
481 
482 #ifdef TARGET_TS_MAKEUP
483 const char QCameraParameters::KEY_TS_MAKEUP[] = "tsmakeup";
484 const char QCameraParameters::KEY_TS_MAKEUP_WHITEN[] = "tsmakeup_whiten";
485 const char QCameraParameters::KEY_TS_MAKEUP_CLEAN[] = "tsmakeup_clean";
486 #endif
487 
488 //KEY to share HFR batch size with video encoder.
489 const char QCameraParameters::KEY_QC_VIDEO_BATCH_SIZE[] = "video-batch-size";
490 
491 //Camera supported metadata.  App can use this to read metadata callback type.
492 const char QCameraParameters::KEY_QC_SUPPORTED_METADATA_TYPES[] = "metadata-types";
493 const char QCameraParameters::QC_METADATA_ASD[] = "metadata-asd";
494 const char QCameraParameters::QC_METADATA_FD[] = "metadata-fd";
495 const char QCameraParameters::QC_METADATA_HDR[] = "metadata-hdr";
496 const char QCameraParameters::QC_METADATA_LED_CALIB[] = "metadata-led-calib";
497 
498 const char QCameraParameters::KEY_QC_LED_CALIBRATION[] = "led-calibration";
499 
500 static const char* portrait = "portrait";
501 static const char* landscape = "landscape";
502 
503 const cam_dimension_t QCameraParameters::THUMBNAIL_SIZES_MAP[] = {
504     { 256, 154 }, //1.66233
505     { 240, 160 }, //1.5
506     { 320, 320 }, //1.0
507     { 320, 240 }, //1.33333
508     { 256, 144 }, //1.777778
509     { 240, 144 }, //1.666667
510     { 176, 144 }, //1.222222
511     /*Thumbnail sizes to match portrait picture size aspect ratio*/
512     { 240, 320 }, //to match 480X640 & 240X320 picture size
513     { 144, 176 }, //to match 144X176  picture size
514     { 0, 0 }      // required by Android SDK
515 };
516 
517 const QCameraParameters::QCameraMap<cam_auto_exposure_mode_type>
518         QCameraParameters::AUTO_EXPOSURE_MAP[] = {
519     { AUTO_EXPOSURE_FRAME_AVG,           CAM_AEC_MODE_FRAME_AVERAGE },
520     { AUTO_EXPOSURE_CENTER_WEIGHTED,     CAM_AEC_MODE_CENTER_WEIGHTED },
521     { AUTO_EXPOSURE_SPOT_METERING,       CAM_AEC_MODE_SPOT_METERING },
522     { AUTO_EXPOSURE_SMART_METERING,      CAM_AEC_MODE_SMART_METERING },
523     { AUTO_EXPOSURE_USER_METERING,       CAM_AEC_MODE_USER_METERING },
524     { AUTO_EXPOSURE_SPOT_METERING_ADV,   CAM_AEC_MODE_SPOT_METERING_ADV },
525     { AUTO_EXPOSURE_CENTER_WEIGHTED_ADV, CAM_AEC_MODE_CENTER_WEIGHTED_ADV },
526 };
527 
528 const QCameraParameters::QCameraMap<cam_aec_convergence_type>
529         QCameraParameters::INSTANT_AEC_MODES_MAP[] = {
530     { KEY_QC_INSTANT_AEC_DISABLE,        CAM_AEC_NORMAL_CONVERGENCE },
531     { KEY_QC_INSTANT_AEC_AGGRESSIVE_AEC, CAM_AEC_AGGRESSIVE_CONVERGENCE },
532     { KEY_QC_INSTANT_AEC_FAST_AEC,       CAM_AEC_FAST_CONVERGENCE },
533 };
534 
535 const QCameraParameters::QCameraMap<cam_aec_convergence_type>
536         QCameraParameters::INSTANT_CAPTURE_MODES_MAP[] = {
537     { KEY_QC_INSTANT_CAPTURE_DISABLE,        CAM_AEC_NORMAL_CONVERGENCE },
538     { KEY_QC_INSTANT_CAPTURE_AGGRESSIVE_AEC, CAM_AEC_AGGRESSIVE_CONVERGENCE },
539     { KEY_QC_INSTANT_CAPTURE_FAST_AEC,       CAM_AEC_FAST_CONVERGENCE },
540 };
541 
542 const QCameraParameters::QCameraMap<cam_format_t>
543         QCameraParameters::PREVIEW_FORMATS_MAP[] = {
544     {PIXEL_FORMAT_YUV420SP,        CAM_FORMAT_YUV_420_NV21},
545     {PIXEL_FORMAT_YUV420P,         CAM_FORMAT_YUV_420_YV12},
546     {PIXEL_FORMAT_YUV420SP_ADRENO, CAM_FORMAT_YUV_420_NV21_ADRENO},
547     {PIXEL_FORMAT_YV12,            CAM_FORMAT_YUV_420_YV12},
548     {PIXEL_FORMAT_NV12,            CAM_FORMAT_YUV_420_NV12},
549     {QC_PIXEL_FORMAT_NV12_VENUS,   CAM_FORMAT_YUV_420_NV12_VENUS}
550 };
551 
552 const QCameraParameters::QCameraMap<cam_format_t>
553         QCameraParameters::PICTURE_TYPES_MAP[] = {
554     {PIXEL_FORMAT_JPEG,                          CAM_FORMAT_JPEG},
555     {PIXEL_FORMAT_YUV420SP,                      CAM_FORMAT_YUV_420_NV21},
556     {PIXEL_FORMAT_YUV422SP,                      CAM_FORMAT_YUV_422_NV16},
557     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YUYV,          CAM_FORMAT_YUV_RAW_8BIT_YUYV},
558     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YVYU,          CAM_FORMAT_YUV_RAW_8BIT_YVYU},
559     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_UYVY,          CAM_FORMAT_YUV_RAW_8BIT_UYVY},
560     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_VYUY,          CAM_FORMAT_YUV_RAW_8BIT_VYUY},
561     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GBRG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GBRG},
562     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GRBG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GRBG},
563     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8RGGB,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_RGGB},
564     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8BGGR,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_BGGR},
565     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GBRG},
566     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GRBG},
567     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_RGGB},
568     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_BGGR},
569     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GBRG},
570     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GRBG},
571     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_RGGB},
572     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_BGGR},
573     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_GBRG},
574     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_GRBG},
575     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_RGGB},
576     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_BGGR},
577     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GBRG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GBRG},
578     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GRBG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GRBG},
579     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8RGGB,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_RGGB},
580     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8BGGR,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_BGGR},
581     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GBRG},
582     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GRBG},
583     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_RGGB},
584     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_BGGR},
585     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GBRG},
586     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GRBG},
587     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_RGGB},
588     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_BGGR},
589     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_GBRG},
590     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_GRBG},
591     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_RGGB},
592     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_BGGR},
593     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GBRG},
594     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GRBG},
595     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_RGGB},
596     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_BGGR},
597     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GBRG},
598     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GRBG},
599     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_RGGB},
600     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_BGGR},
601     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GBRG},
602     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GRBG},
603     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_RGGB},
604     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_BGGR},
605     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_GBRG},
606     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_GRBG},
607     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_RGGB},
608     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_BGGR},
609     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GBRG},
610     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GRBG},
611     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_RGGB},
612     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_BGGR},
613     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GBRG},
614     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GRBG},
615     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_RGGB},
616     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_BGGR},
617     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GBRG},
618     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GRBG},
619     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_RGGB},
620     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_BGGR},
621     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_GBRG},
622     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_GRBG},
623     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_RGGB},
624     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_BGGR},
625     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GBRG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GBRG},
626     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GRBG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GRBG},
627     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8RGGB,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_RGGB},
628     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8BGGR,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_BGGR},
629     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GBRG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GBRG},
630     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GRBG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GRBG},
631     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8RGGB,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_RGGB},
632     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8BGGR,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_BGGR},
633     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GBRG},
634     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GRBG},
635     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_RGGB},
636     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_BGGR},
637     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GBRG},
638     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GRBG},
639     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_RGGB},
640     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_BGGR},
641     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_GBRG},
642     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_GRBG},
643     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_RGGB},
644     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_BGGR}
645 };
646 
647 const QCameraParameters::QCameraMap<cam_focus_mode_type>
648         QCameraParameters::FOCUS_MODES_MAP[] = {
649     { FOCUS_MODE_AUTO,               CAM_FOCUS_MODE_AUTO },
650     { FOCUS_MODE_INFINITY,           CAM_FOCUS_MODE_INFINITY },
651     { FOCUS_MODE_MACRO,              CAM_FOCUS_MODE_MACRO },
652     { FOCUS_MODE_FIXED,              CAM_FOCUS_MODE_FIXED },
653     { FOCUS_MODE_EDOF,               CAM_FOCUS_MODE_EDOF },
654     { FOCUS_MODE_CONTINUOUS_PICTURE, CAM_FOCUS_MODE_CONTINOUS_PICTURE },
655     { FOCUS_MODE_CONTINUOUS_VIDEO,   CAM_FOCUS_MODE_CONTINOUS_VIDEO },
656     { FOCUS_MODE_MANUAL_POSITION,    CAM_FOCUS_MODE_MANUAL},
657 };
658 
659 const QCameraParameters::QCameraMap<cam_effect_mode_type>
660         QCameraParameters::EFFECT_MODES_MAP[] = {
661     { EFFECT_NONE,       CAM_EFFECT_MODE_OFF },
662     { EFFECT_MONO,       CAM_EFFECT_MODE_MONO },
663     { EFFECT_NEGATIVE,   CAM_EFFECT_MODE_NEGATIVE },
664     { EFFECT_SOLARIZE,   CAM_EFFECT_MODE_SOLARIZE },
665     { EFFECT_SEPIA,      CAM_EFFECT_MODE_SEPIA },
666     { EFFECT_POSTERIZE,  CAM_EFFECT_MODE_POSTERIZE },
667     { EFFECT_WHITEBOARD, CAM_EFFECT_MODE_WHITEBOARD },
668     { EFFECT_BLACKBOARD, CAM_EFFECT_MODE_BLACKBOARD },
669     { EFFECT_AQUA,       CAM_EFFECT_MODE_AQUA },
670     { EFFECT_EMBOSS,     CAM_EFFECT_MODE_EMBOSS },
671     { EFFECT_SKETCH,     CAM_EFFECT_MODE_SKETCH },
672     { EFFECT_NEON,       CAM_EFFECT_MODE_NEON },
673     { EFFECT_BEAUTY,     CAM_EFFECT_MODE_BEAUTY }
674 };
675 
676 const QCameraParameters::QCameraMap<cam_scene_mode_type>
677         QCameraParameters::SCENE_MODES_MAP[] = {
678     { SCENE_MODE_AUTO,           CAM_SCENE_MODE_OFF },
679     { SCENE_MODE_ACTION,         CAM_SCENE_MODE_ACTION },
680     { SCENE_MODE_PORTRAIT,       CAM_SCENE_MODE_PORTRAIT },
681     { SCENE_MODE_LANDSCAPE,      CAM_SCENE_MODE_LANDSCAPE },
682     { SCENE_MODE_NIGHT,          CAM_SCENE_MODE_NIGHT },
683     { SCENE_MODE_NIGHT_PORTRAIT, CAM_SCENE_MODE_NIGHT_PORTRAIT },
684     { SCENE_MODE_THEATRE,        CAM_SCENE_MODE_THEATRE },
685     { SCENE_MODE_BEACH,          CAM_SCENE_MODE_BEACH },
686     { SCENE_MODE_SNOW,           CAM_SCENE_MODE_SNOW },
687     { SCENE_MODE_SUNSET,         CAM_SCENE_MODE_SUNSET },
688     { SCENE_MODE_STEADYPHOTO,    CAM_SCENE_MODE_ANTISHAKE },
689     { SCENE_MODE_FIREWORKS ,     CAM_SCENE_MODE_FIREWORKS },
690     { SCENE_MODE_SPORTS ,        CAM_SCENE_MODE_SPORTS },
691     { SCENE_MODE_PARTY,          CAM_SCENE_MODE_PARTY },
692     { SCENE_MODE_CANDLELIGHT,    CAM_SCENE_MODE_CANDLELIGHT },
693     { SCENE_MODE_ASD,            CAM_SCENE_MODE_AUTO },
694     { SCENE_MODE_BACKLIGHT,      CAM_SCENE_MODE_BACKLIGHT },
695     { SCENE_MODE_FLOWERS,        CAM_SCENE_MODE_FLOWERS },
696     { SCENE_MODE_AR,             CAM_SCENE_MODE_AR },
697     { SCENE_MODE_HDR,            CAM_SCENE_MODE_HDR },
698 };
699 
700 const QCameraParameters::QCameraMap<cam_flash_mode_t>
701         QCameraParameters::FLASH_MODES_MAP[] = {
702     { FLASH_MODE_OFF,   CAM_FLASH_MODE_OFF },
703     { FLASH_MODE_AUTO,  CAM_FLASH_MODE_AUTO },
704     { FLASH_MODE_ON,    CAM_FLASH_MODE_ON },
705     { FLASH_MODE_TORCH, CAM_FLASH_MODE_TORCH }
706 };
707 
708 const QCameraParameters::QCameraMap<cam_focus_algorithm_type>
709          QCameraParameters::FOCUS_ALGO_MAP[] = {
710     { FOCUS_ALGO_AUTO,            CAM_FOCUS_ALGO_AUTO },
711     { FOCUS_ALGO_SPOT_METERING,   CAM_FOCUS_ALGO_SPOT },
712     { FOCUS_ALGO_CENTER_WEIGHTED, CAM_FOCUS_ALGO_CENTER_WEIGHTED },
713     { FOCUS_ALGO_FRAME_AVERAGE,   CAM_FOCUS_ALGO_AVERAGE }
714 };
715 
716 const QCameraParameters::QCameraMap<cam_wb_mode_type>
717         QCameraParameters::WHITE_BALANCE_MODES_MAP[] = {
718     { WHITE_BALANCE_AUTO,            CAM_WB_MODE_AUTO },
719     { WHITE_BALANCE_INCANDESCENT,    CAM_WB_MODE_INCANDESCENT },
720     { WHITE_BALANCE_FLUORESCENT,     CAM_WB_MODE_FLUORESCENT },
721     { WHITE_BALANCE_WARM_FLUORESCENT,CAM_WB_MODE_WARM_FLUORESCENT},
722     { WHITE_BALANCE_DAYLIGHT,        CAM_WB_MODE_DAYLIGHT },
723     { WHITE_BALANCE_CLOUDY_DAYLIGHT, CAM_WB_MODE_CLOUDY_DAYLIGHT },
724     { WHITE_BALANCE_TWILIGHT,        CAM_WB_MODE_TWILIGHT },
725     { WHITE_BALANCE_SHADE,           CAM_WB_MODE_SHADE },
726     { WHITE_BALANCE_MANUAL,          CAM_WB_MODE_MANUAL},
727 };
728 
729 const QCameraParameters::QCameraMap<cam_antibanding_mode_type>
730         QCameraParameters::ANTIBANDING_MODES_MAP[] = {
731     { ANTIBANDING_OFF,  CAM_ANTIBANDING_MODE_OFF },
732     { ANTIBANDING_50HZ, CAM_ANTIBANDING_MODE_50HZ },
733     { ANTIBANDING_60HZ, CAM_ANTIBANDING_MODE_60HZ },
734     { ANTIBANDING_AUTO, CAM_ANTIBANDING_MODE_AUTO }
735 };
736 
737 const QCameraParameters::QCameraMap<cam_iso_mode_type>
738         QCameraParameters::ISO_MODES_MAP[] = {
739     { ISO_AUTO,  CAM_ISO_MODE_AUTO },
740     { ISO_HJR,   CAM_ISO_MODE_DEBLUR },
741     { ISO_100,   CAM_ISO_MODE_100 },
742     { ISO_200,   CAM_ISO_MODE_200 },
743     { ISO_400,   CAM_ISO_MODE_400 },
744     { ISO_800,   CAM_ISO_MODE_800 },
745     { ISO_1600,  CAM_ISO_MODE_1600 },
746     { ISO_3200,  CAM_ISO_MODE_3200 }
747 };
748 
749 const QCameraParameters::QCameraMap<cam_hfr_mode_t>
750         QCameraParameters::HFR_MODES_MAP[] = {
751     { VIDEO_HFR_OFF, CAM_HFR_MODE_OFF },
752     { VIDEO_HFR_2X, CAM_HFR_MODE_60FPS },
753     { VIDEO_HFR_3X, CAM_HFR_MODE_90FPS },
754     { VIDEO_HFR_4X, CAM_HFR_MODE_120FPS },
755     { VIDEO_HFR_5X, CAM_HFR_MODE_150FPS },
756     { VIDEO_HFR_6X, CAM_HFR_MODE_180FPS },
757     { VIDEO_HFR_7X, CAM_HFR_MODE_210FPS },
758     { VIDEO_HFR_8X, CAM_HFR_MODE_240FPS },
759     { VIDEO_HFR_9X, CAM_HFR_MODE_480FPS }
760 };
761 
762 const QCameraParameters::QCameraMap<cam_bracket_mode>
763         QCameraParameters::BRACKETING_MODES_MAP[] = {
764     { AE_BRACKET_OFF, CAM_EXP_BRACKETING_OFF },
765     { AE_BRACKET,     CAM_EXP_BRACKETING_ON }
766 };
767 
768 const QCameraParameters::QCameraMap<int>
769         QCameraParameters::ON_OFF_MODES_MAP[] = {
770     { VALUE_OFF, 0 },
771     { VALUE_ON,  1 }
772 };
773 
774 const QCameraParameters::QCameraMap<int>
775         QCameraParameters::TOUCH_AF_AEC_MODES_MAP[] = {
776     { QCameraParameters::TOUCH_AF_AEC_OFF, 0 },
777     { QCameraParameters::TOUCH_AF_AEC_ON, 1 }
778 };
779 
780 const QCameraParameters::QCameraMap<int>
781         QCameraParameters::ENABLE_DISABLE_MODES_MAP[] = {
782     { VALUE_ENABLE,  1 },
783     { VALUE_DISABLE, 0 }
784 };
785 
786 const QCameraParameters::QCameraMap<int>
787         QCameraParameters::DENOISE_ON_OFF_MODES_MAP[] = {
788     { DENOISE_OFF, 0 },
789     { DENOISE_ON,  1 }
790 };
791 
792 const QCameraParameters::QCameraMap<int>
793         QCameraParameters::TRUE_FALSE_MODES_MAP[] = {
794     { VALUE_FALSE, 0},
795     { VALUE_TRUE,  1}
796 };
797 
798 const QCameraParameters::QCameraMap<cam_flip_t>
799         QCameraParameters::FLIP_MODES_MAP[] = {
800     {FLIP_MODE_OFF, FLIP_NONE},
801     {FLIP_MODE_V, FLIP_V},
802     {FLIP_MODE_H, FLIP_H},
803     {FLIP_MODE_VH, FLIP_V_H}
804 };
805 
806 const QCameraParameters::QCameraMap<int>
807         QCameraParameters::AF_BRACKETING_MODES_MAP[] = {
808     { AF_BRACKET_OFF, 0 },
809     { AF_BRACKET_ON,  1 }
810 };
811 
812 const QCameraParameters::QCameraMap<int>
813         QCameraParameters::RE_FOCUS_MODES_MAP[] = {
814     { RE_FOCUS_OFF, 0 },
815     { RE_FOCUS_ON,  1 }
816 };
817 
818 const QCameraParameters::QCameraMap<int>
819         QCameraParameters::CHROMA_FLASH_MODES_MAP[] = {
820     { CHROMA_FLASH_OFF, 0 },
821     { CHROMA_FLASH_ON,  1 }
822 };
823 
824 const QCameraParameters::QCameraMap<int>
825         QCameraParameters::OPTI_ZOOM_MODES_MAP[] = {
826     { OPTI_ZOOM_OFF, 0 },
827     { OPTI_ZOOM_ON,  1 }
828 };
829 
830 const QCameraParameters::QCameraMap<int>
831         QCameraParameters::TRUE_PORTRAIT_MODES_MAP[] = {
832     { TRUE_PORTRAIT_OFF, 0 },
833     { TRUE_PORTRAIT_ON,  1 }
834 };
835 
836 const QCameraParameters::QCameraMap<int>
837         QCameraParameters::STILL_MORE_MODES_MAP[] = {
838     { STILL_MORE_OFF, 0 },
839     { STILL_MORE_ON,  1 }
840 };
841 
842 const QCameraParameters::QCameraMap<cam_cds_mode_type_t>
843         QCameraParameters::CDS_MODES_MAP[] = {
844     { CDS_MODE_OFF, CAM_CDS_MODE_OFF },
845     { CDS_MODE_ON, CAM_CDS_MODE_ON },
846     { CDS_MODE_AUTO, CAM_CDS_MODE_AUTO}
847 };
848 
849 const QCameraParameters::QCameraMap<int>
850         QCameraParameters::HDR_MODES_MAP[] = {
851     { HDR_MODE_SENSOR, 0 },
852     { HDR_MODE_MULTI_FRAME, 1 }
853 };
854 
855 const QCameraParameters::QCameraMap<int>
856         QCameraParameters::VIDEO_ROTATION_MODES_MAP[] = {
857     { VIDEO_ROTATION_0, 0 },
858     { VIDEO_ROTATION_90, 90 },
859     { VIDEO_ROTATION_180, 180 },
860     { VIDEO_ROTATION_270, 270 }
861 };
862 
863 const QCameraParameters::QCameraMap<int>
864         QCameraParameters::NOISE_REDUCTION_MODES_MAP[] = {
865     { VALUE_OFF, 0 },
866     { VALUE_FAST,  1 },
867     { VALUE_HIGH_QUALITY,  2 }
868 };
869 
870 const QCameraParameters::QCameraMap<int>
871         QCameraParameters::METADATA_TYPES_MAP[] = {
872     {QC_METADATA_ASD,        QCAMERA_METADATA_ASD},
873     {QC_METADATA_FD,         QCAMERA_METADATA_FD},
874     {QC_METADATA_HDR,        QCAMERA_METADATA_HDR},
875     {QC_METADATA_LED_CALIB,  QCAMERA_METADATA_LED_CALIB}
876 };
877 
878 
879 #define DEFAULT_CAMERA_AREA "(0, 0, 0, 0, 0)"
880 #define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
881 #define TOTAL_RAM_SIZE_512MB 536870912
882 #define PARAM_MAP_SIZE(MAP) (sizeof(MAP)/sizeof(MAP[0]))
883 
884 // initialise to some default value
885 uint32_t QCameraParameters::sessionId[] = {0};
886 
887 /*===========================================================================
888  * FUNCTION   : isOEMFeat1PropEnabled
889  *
890  * DESCRIPTION: inline function to check from property if custom feature
891  *            is enabled
892  *
893  * PARAMETERS : none
894  *
895  * RETURN     : boolean true/false
896  *==========================================================================*/
isOEMFeat1PropEnabled()897 static inline bool isOEMFeat1PropEnabled()
898 {
899     char value[PROPERTY_VALUE_MAX];
900     property_get("persist.camera.imglib.oemfeat1", value, "0");
901     return atoi(value) > 0 ? true : false;
902 }
903 
904 /*===========================================================================
905  * FUNCTION   : QCameraParameters
906  *
907  * DESCRIPTION: default constructor of QCameraParameters
908  *
909  * PARAMETERS : none
910  *
911  * RETURN     : None
912  *==========================================================================*/
QCameraParameters()913 QCameraParameters::QCameraParameters()
914     : CameraParameters(),
915       m_reprocScaleParam(),
916       mCommon(),
917       m_pCapability(NULL),
918       m_pCamOpsTbl(NULL),
919       m_pParamHeap(NULL),
920       m_pParamBuf(NULL),
921       m_pParamBufAux(NULL),
922       m_pDualCamCmdHeap(NULL),
923       m_bFrameSyncEnabled(false),
924       mIsTypeVideo(IS_TYPE_NONE),
925       mIsTypePreview(IS_TYPE_NONE),
926       m_bZslMode(false),
927       m_bZslMode_new(false),
928       m_bForceZslMode(false),
929       m_bRecordingHint(false),
930       m_bRecordingHint_new(false),
931       m_bHistogramEnabled(false),
932       m_bLongshotEnabled(false),
933       m_nFaceProcMask(0),
934       m_bFaceDetectionOn(0),
935       m_bDebugFps(false),
936       mFocusMode(CAM_FOCUS_MODE_MAX),
937       mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
938       mAppPreviewFormat(CAM_FORMAT_YUV_420_NV21),
939       mPictureFormat(CAM_FORMAT_JPEG),
940       m_bNeedRestart(false),
941       m_bNoDisplayMode(false),
942       m_bWNROn(false),
943       m_bTNRPreviewOn(false),
944       m_bTNRVideoOn(false),
945       m_bTNRSnapshotOn(false),
946       m_bInited(false),
947       m_nRetroBurstNum(0),
948       m_nBurstLEDOnPeriod(100),
949       m_bUpdateEffects(false),
950       m_bSceneTransitionAuto(false),
951       m_bPreviewFlipChanged(false),
952       m_bVideoFlipChanged(false),
953       m_bSnapshotFlipChanged(false),
954       m_bZoomChanged(false),
955       m_bFixedFrameRateSet(false),
956       m_bHDREnabled(false),
957       m_bLocalHDREnabled(false),
958       m_bAVTimerEnabled(false),
959       m_bDISEnabled(false),
960       m_bMetaRawEnabled(false),
961       m_MobiMask(0),
962       m_AdjustFPS(NULL),
963       m_bHDR1xFrameEnabled(false),
964       m_HDRSceneEnabled(false),
965       m_bHDRThumbnailProcessNeeded(false),
966       m_bHDR1xExtraBufferNeeded(true),
967       m_bHDROutputCropEnabled(false),
968       m_tempMap(),
969       m_bAFBracketingOn(false),
970       m_bReFocusOn(false),
971       m_bChromaFlashOn(false),
972       m_bOptiZoomOn(false),
973       m_bSceneSelection(false),
974       m_SelectedScene(CAM_SCENE_MODE_MAX),
975       m_bSeeMoreOn(false),
976       m_bStillMoreOn(false),
977       m_bHighQualityNoiseReductionMode(false),
978       m_bHfrMode(false),
979       m_bSensorHDREnabled(false),
980       m_bRdiMode(false),
981       m_bSecureMode(false),
982       m_bAeBracketingEnabled(false),
983       mFlashValue(CAM_FLASH_MODE_OFF),
984       mFlashDaemonValue(CAM_FLASH_MODE_OFF),
985       mHfrMode(CAM_HFR_MODE_OFF),
986       m_bHDRModeSensor(true),
987       mOfflineRAW(false),
988       m_bTruePortraitOn(false),
989       m_bIsLowMemoryDevice(false),
990       mCds_mode(CAM_CDS_MODE_OFF),
991       m_LLCaptureEnabled(FALSE),
992       m_LowLightLevel(CAM_LOW_LIGHT_OFF),
993       m_bLtmForSeeMoreEnabled(false),
994       m_expTime(0),
995       m_isoValue(0),
996       m_ManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF),
997       m_dualLedCalibration(0),
998       m_bInstantAEC(false),
999       m_bInstantCapture(false),
1000       mAecFrameBound(0),
1001       mAecSkipDisplayFrameBound(0),
1002       m_bQuadraCfa(false),
1003       mMasterCamera(CAM_TYPE_MAIN),
1004       m_bSmallJpegSize(false),
1005       mSecureStraemType(CAM_STREAM_TYPE_PREVIEW),
1006       mFrameNumber(0),
1007       mSyncDCParam(0),
1008       mAsymmetricSnapMode(false)
1009 {
1010     char value[PROPERTY_VALUE_MAX];
1011     // TODO: may move to parameter instead of sysprop
1012     property_get("persist.debug.sf.showfps", value, "0");
1013     m_bDebugFps = atoi(value) > 0 ? true : false;
1014 
1015     // For thermal mode, it should be set as system property
1016     // because system property applies to all applications, while
1017     // parameters only apply to specific app.
1018     property_get("persist.camera.thermal.mode", value, "fps");
1019     if (!strcmp(value, "frameskip")) {
1020         m_ThermalMode = QCAMERA_THERMAL_ADJUST_FRAMESKIP;
1021     } else {
1022         if (strcmp(value, "fps"))
1023             LOGW("Invalid camera thermal mode %s", value);
1024         m_ThermalMode = QCAMERA_THERMAL_ADJUST_FPS;
1025     }
1026 
1027     memset(value, 0, sizeof(value));
1028     // As per Power/Quality evaluation, LTM is enabled by default in SeeMore/StillMore usecase
1029     // to improve the quality as there is no much impact to power
1030     property_get("persist.camera.ltmforseemore", value, "1");
1031     m_bLtmForSeeMoreEnabled = atoi(value);
1032 
1033     memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
1034     memset(&m_default_fps_range, 0, sizeof(m_default_fps_range));
1035     memset(&m_hfrFpsRange, 0, sizeof(m_hfrFpsRange));
1036     memset(&m_stillmore_config, 0, sizeof(cam_still_more_t));
1037     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
1038     memset(&m_relCamSyncInfo, 0, sizeof(cam_sync_related_sensors_event_info_t));
1039     memset(m_pDualCamCmdPtr, 0, sizeof(m_pDualCamCmdPtr));
1040     mTotalPPCount = 1;
1041     mZoomLevel = 0;
1042     mParmZoomLevel = 0;
1043     mCurPPCount = 0;
1044     mBufBatchCnt = 0;
1045     mRotation = 0;
1046     mJpegRotation = 0;
1047     mVideoBatchSize = 0;
1048     m_bOEMFeatEnabled = isOEMFeat1PropEnabled();
1049     m_bDualCamera = 0;
1050 }
1051 
1052 /*===========================================================================
1053  * FUNCTION   : QCameraParameters
1054  *
1055  * DESCRIPTION: constructor of QCameraParameters
1056  *
1057  * PARAMETERS :
1058  *   @params  : parameters in string
1059  *
1060  * RETURN     : None
1061  *==========================================================================*/
QCameraParameters(const String8 & params)1062 QCameraParameters::QCameraParameters(const String8 &params)
1063     : CameraParameters(params),
1064     m_reprocScaleParam(),
1065     m_pCapability(NULL),
1066     m_pCamOpsTbl(NULL),
1067     m_pParamHeap(NULL),
1068     m_pParamBuf(NULL),
1069     m_pParamBufAux(NULL),
1070     m_pDualCamCmdHeap(NULL),
1071     m_bFrameSyncEnabled(false),
1072     m_bZslMode(false),
1073     m_bZslMode_new(false),
1074     m_bForceZslMode(false),
1075     m_bRecordingHint(false),
1076     m_bRecordingHint_new(false),
1077     m_bHistogramEnabled(false),
1078     m_bLongshotEnabled(false),
1079     m_nFaceProcMask(0),
1080     m_bDebugFps(false),
1081     mFocusMode(CAM_FOCUS_MODE_MAX),
1082     mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
1083     mAppPreviewFormat(CAM_FORMAT_YUV_420_NV21),
1084     mPictureFormat(CAM_FORMAT_JPEG),
1085     m_bNeedRestart(false),
1086     m_bNoDisplayMode(false),
1087     m_bWNROn(false),
1088     m_bTNRPreviewOn(false),
1089     m_bTNRVideoOn(false),
1090     m_bTNRSnapshotOn(false),
1091     m_bInited(false),
1092     m_nRetroBurstNum(0),
1093     m_nBurstLEDOnPeriod(100),
1094     m_bPreviewFlipChanged(false),
1095     m_bVideoFlipChanged(false),
1096     m_bSnapshotFlipChanged(false),
1097     m_bFixedFrameRateSet(false),
1098     m_bHDREnabled(false),
1099     m_bLocalHDREnabled(false),
1100     m_bAVTimerEnabled(false),
1101     m_AdjustFPS(NULL),
1102     m_bHDR1xFrameEnabled(false),
1103     m_HDRSceneEnabled(false),
1104     m_bHDRThumbnailProcessNeeded(false),
1105     m_bHDR1xExtraBufferNeeded(true),
1106     m_bHDROutputCropEnabled(false),
1107     m_tempMap(),
1108     m_bAFBracketingOn(false),
1109     m_bReFocusOn(false),
1110     m_bChromaFlashOn(false),
1111     m_bOptiZoomOn(false),
1112     m_bSceneSelection(false),
1113     m_SelectedScene(CAM_SCENE_MODE_MAX),
1114     m_bSeeMoreOn(false),
1115     m_bStillMoreOn(false),
1116     m_bHighQualityNoiseReductionMode(false),
1117     m_bHfrMode(false),
1118     m_bSensorHDREnabled(false),
1119     m_bRdiMode(false),
1120     m_bSecureMode(false),
1121     m_bAeBracketingEnabled(false),
1122     mFlashValue(CAM_FLASH_MODE_OFF),
1123     mFlashDaemonValue(CAM_FLASH_MODE_OFF),
1124     mHfrMode(CAM_HFR_MODE_OFF),
1125     m_bHDRModeSensor(true),
1126     mOfflineRAW(false),
1127     m_bTruePortraitOn(false),
1128     m_bIsLowMemoryDevice(false),
1129     mCds_mode(CAM_CDS_MODE_OFF),
1130     mParmEffect(CAM_EFFECT_MODE_OFF),
1131     m_LLCaptureEnabled(FALSE),
1132     m_LowLightLevel(CAM_LOW_LIGHT_OFF),
1133     m_bLtmForSeeMoreEnabled(false),
1134     m_expTime(0),
1135     m_isoValue(0),
1136     m_ManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF),
1137     m_dualLedCalibration(0),
1138     m_bInstantAEC(false),
1139     m_bInstantCapture(false),
1140     mAecFrameBound(0),
1141     mAecSkipDisplayFrameBound(0),
1142     m_bQuadraCfa(false),
1143     mMasterCamera(CAM_TYPE_MAIN),
1144     m_bSmallJpegSize(false),
1145     mSecureStraemType(CAM_STREAM_TYPE_PREVIEW),
1146     mFrameNumber(0),
1147     mSyncDCParam(0),
1148     mAsymmetricSnapMode(false)
1149 {
1150     memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
1151     memset(&m_default_fps_range, 0, sizeof(m_default_fps_range));
1152     memset(&m_hfrFpsRange, 0, sizeof(m_hfrFpsRange));
1153     memset(&m_stillmore_config, 0, sizeof(cam_still_more_t));
1154     memset(&m_relCamSyncInfo, 0, sizeof(cam_sync_related_sensors_event_info_t));
1155     memset(m_pDualCamCmdPtr, 0, sizeof(m_pDualCamCmdPtr));
1156     mTotalPPCount = 0;
1157     mZoomLevel = 0;
1158     mParmZoomLevel = 0;
1159     mCurPPCount = 0;
1160     mRotation = 0;
1161     mJpegRotation = 0;
1162     mBufBatchCnt = 0;
1163     mVideoBatchSize = 0;
1164     m_bOEMFeatEnabled = isOEMFeat1PropEnabled();
1165     m_bDualCamera = 0;
1166 }
1167 
1168 /*===========================================================================
1169  * FUNCTION   : ~QCameraParameters
1170  *
1171  * DESCRIPTION: deconstructor of QCameraParameters
1172  *
1173  * PARAMETERS : none
1174  *
1175  * RETURN     : None
1176  *==========================================================================*/
~QCameraParameters()1177 QCameraParameters::~QCameraParameters()
1178 {
1179     deinit();
1180 }
1181 
1182 /*===========================================================================
1183  * FUNCTION   : createSizesString
1184  *
1185  * DESCRIPTION: create string obj contains array of dimensions
1186  *
1187  * PARAMETERS :
1188  *   @sizes   : array of dimensions
1189  *   @len     : size of dimension array
1190  *
1191  * RETURN     : string obj
1192  *==========================================================================*/
createSizesString(const cam_dimension_t * sizes,size_t len)1193 String8 QCameraParameters::createSizesString(const cam_dimension_t *sizes, size_t len)
1194 {
1195     String8 str;
1196     char buffer[32];
1197 
1198     if (len > 0) {
1199         snprintf(buffer, sizeof(buffer), "%dx%d", sizes[0].width, sizes[0].height);
1200         str.append(buffer);
1201     }
1202     for (size_t i = 1; i < len; i++) {
1203         snprintf(buffer, sizeof(buffer), ",%dx%d",
1204                 sizes[i].width, sizes[i].height);
1205         str.append(buffer);
1206     }
1207     return str;
1208 }
1209 
1210 /*===========================================================================
1211  * FUNCTION   : createValuesString
1212  *
1213  * DESCRIPTION: create string obj contains array of values from map when matched
1214  *              from input values array
1215  *
1216  * PARAMETERS :
1217  *   @values  : array of values
1218  *   @len     : size of values array
1219  *   @map     : map contains the mapping between values and enums
1220  *   @map_len : size of the map
1221  *
1222  * RETURN     : string obj
1223  *==========================================================================*/
createValuesString(const valuesType * values,size_t len,const mapType * map,size_t map_len)1224 template <typename valuesType, class mapType> String8 createValuesString(
1225         const valuesType *values, size_t len, const mapType *map, size_t map_len)
1226 {
1227     String8 str;
1228     int count = 0;
1229 
1230     for (size_t i = 0; i < len; i++ ) {
1231         for (size_t j = 0; j < map_len; j ++)
1232             if (map[j].val == values[i]) {
1233                 if (NULL != map[j].desc) {
1234                     if (count > 0) {
1235                         str.append(",");
1236                     }
1237                     str.append(map[j].desc);
1238                     count++;
1239                     break; //loop j
1240                 }
1241             }
1242     }
1243     return str;
1244 }
1245 
1246 /*===========================================================================
1247  * FUNCTION   : createValuesStringFromMap
1248  *
1249  * DESCRIPTION: create string obj contains array of values directly from map
1250  *
1251  * PARAMETERS :
1252  *   @map     : map contains the mapping between values and enums
1253  *   @map_len : size of the map
1254  *
1255  * RETURN     : string obj
1256  *==========================================================================*/
createValuesStringFromMap(const mapType * map,size_t map_len)1257 template <class mapType> String8 createValuesStringFromMap(
1258         const mapType *map, size_t map_len)
1259 {
1260     String8 str;
1261 
1262     for (size_t i = 0; i < map_len; i++) {
1263         if (NULL != map[i].desc) {
1264             if (i > 0) {
1265                 str.append(",");
1266             }
1267             str.append(map[i].desc);
1268         }
1269     }
1270     return str;
1271 }
1272 
1273 /*===========================================================================
1274  * FUNCTION   : createZoomRatioValuesString
1275  *
1276  * DESCRIPTION: create string obj contains array of zoom ratio values
1277  *
1278  * PARAMETERS :
1279  *   @zoomRaios  : array of zoom ratios
1280  *   @length     : size of the array
1281  *
1282  * RETURN     : string obj
1283  *==========================================================================*/
createZoomRatioValuesString(uint32_t * zoomRatios,size_t length)1284 String8 QCameraParameters::createZoomRatioValuesString(uint32_t *zoomRatios,
1285         size_t length)
1286 {
1287     String8 str;
1288     char buffer[32] = {0};
1289 
1290     if(length > 0){
1291         snprintf(buffer, sizeof(buffer), "%d", zoomRatios[0]);
1292         str.append(buffer);
1293     }
1294 
1295     for (size_t i = 1; i < length; i++) {
1296         memset(buffer, 0, sizeof(buffer));
1297         snprintf(buffer, sizeof(buffer), ",%d", zoomRatios[i]);
1298         str.append(buffer);
1299     }
1300     return str;
1301 }
1302 
1303 /*===========================================================================
1304  * FUNCTION   : createHfrValuesString
1305  *
1306  * DESCRIPTION: create string obj contains array of hfr values from map when
1307  *              matched from input hfr values
1308  *
1309  * PARAMETERS :
1310  *   @values  : array of hfr info
1311  *   @len     : size of the array
1312  *   @map     : map of hfr string value and enum
1313  *   map_len  : size of map
1314  *
1315  * RETURN     : string obj
1316  *==========================================================================*/
createHfrValuesString(const cam_hfr_info_t * values,size_t len,const QCameraMap<cam_hfr_mode_t> * map,size_t map_len)1317 String8 QCameraParameters::createHfrValuesString(const cam_hfr_info_t *values,
1318         size_t len, const QCameraMap<cam_hfr_mode_t> *map, size_t map_len)
1319 {
1320     String8 str;
1321     int count = 0;
1322 
1323     //Create HFR supported size string.
1324     for (size_t i = 0; i < len; i++ ) {
1325         for (size_t j = 0; j < map_len; j ++) {
1326             if (map[j].val == (int)values[i].mode) {
1327                 if (NULL != map[j].desc) {
1328                     if (count > 0) {
1329                         str.append(",");
1330                     }
1331                      str.append(map[j].desc);
1332                      count++;
1333                      break; //loop j
1334                 }
1335             }
1336         }
1337     }
1338     if (count > 0) {
1339         str.append(",");
1340     }
1341     str.append(VIDEO_HFR_OFF);
1342     return str;
1343 }
1344 
1345 /*===========================================================================
1346  * FUNCTION   : createHfrSizesString
1347  *
1348  * DESCRIPTION: create string obj contains array of hfr sizes
1349  *
1350  * PARAMETERS :
1351  *   @values  : array of hfr info
1352  *   @len     : size of the array
1353  *
1354  * RETURN     : string obj
1355  *==========================================================================*/
createHfrSizesString(const cam_hfr_info_t * values,size_t len)1356 String8 QCameraParameters::createHfrSizesString(const cam_hfr_info_t *values, size_t len)
1357 {
1358     String8 str;
1359     char buffer[32];
1360 
1361     if (len > 0) {
1362         snprintf(buffer, sizeof(buffer), "%dx%d",
1363                  values[0].dim[0].width, values[0].dim[0].height);
1364         str.append(buffer);
1365     }
1366     for (size_t i = 1; i < len; i++) {
1367         snprintf(buffer, sizeof(buffer), ",%dx%d",
1368                  values[i].dim[0].width, values[i].dim[0].height);
1369         str.append(buffer);
1370     }
1371     return str;
1372 }
1373 
1374 /*===========================================================================
1375  * FUNCTION   : createFpsString
1376  *
1377  * DESCRIPTION: create string obj contains array of FPS rates
1378  *
1379  * PARAMETERS :
1380  *   @fps     : default fps range
1381  *
1382  * RETURN     : string obj
1383  *==========================================================================*/
createFpsString(cam_fps_range_t & fps)1384 String8 QCameraParameters::createFpsString(cam_fps_range_t &fps)
1385 {
1386     char buffer[32];
1387     String8 fpsValues;
1388 
1389     int min_fps = int(fps.min_fps);
1390     int max_fps = int(fps.max_fps);
1391 
1392     if (min_fps < fps.min_fps){
1393         min_fps++;
1394     }
1395     if (max_fps > fps.max_fps) {
1396         max_fps--;
1397     }
1398     if (min_fps <= max_fps) {
1399         snprintf(buffer, sizeof(buffer), "%d", min_fps);
1400         fpsValues.append(buffer);
1401     }
1402 
1403     for (int i = min_fps+1; i <= max_fps; i++) {
1404         snprintf(buffer, sizeof(buffer), ",%d", i);
1405         fpsValues.append(buffer);
1406     }
1407 
1408     return fpsValues;
1409 }
1410 
1411 /*===========================================================================
1412  * FUNCTION   : createFpsRangeString
1413  *
1414  * DESCRIPTION: create string obj contains array of FPS ranges
1415  *
1416  * PARAMETERS :
1417  *   @fps     : array of fps ranges
1418  *   @len     : size of the array
1419  *   @default_fps_index : reference to index of default fps range
1420  *
1421  * RETURN     : string obj
1422  *==========================================================================*/
createFpsRangeString(const cam_fps_range_t * fps,size_t len,int & default_fps_index)1423 String8 QCameraParameters::createFpsRangeString(const cam_fps_range_t* fps,
1424         size_t len, int &default_fps_index)
1425 {
1426     String8 str;
1427     char buffer[32];
1428     int max_range = 0;
1429     int min_fps, max_fps;
1430 
1431     if (len > 0) {
1432         min_fps = int(fps[0].min_fps * 1000);
1433         max_fps = int(fps[0].max_fps * 1000);
1434         max_range = max_fps - min_fps;
1435         default_fps_index = 0;
1436         snprintf(buffer, sizeof(buffer), "(%d,%d)", min_fps, max_fps);
1437         str.append(buffer);
1438     }
1439     for (size_t i = 1; i < len; i++) {
1440         min_fps = int(fps[i].min_fps * 1000);
1441         max_fps = int(fps[i].max_fps * 1000);
1442         if (max_range < (max_fps - min_fps)) {
1443             max_range = max_fps - min_fps;
1444             default_fps_index = (int)i;
1445         }
1446         snprintf(buffer, sizeof(buffer), ",(%d,%d)", min_fps, max_fps);
1447         str.append(buffer);
1448     }
1449     return str;
1450 }
1451 
1452 /*===========================================================================
1453  * FUNCTION   : lookupAttr
1454  *
1455  * DESCRIPTION: lookup a value by its name
1456  *
1457  * PARAMETERS :
1458  *   @attr    : map contains <name, value>
1459  *   @len     : size of the map
1460  *   @name    : name to be looked up
1461  *
1462  * RETURN     : valid value if found
1463  *              NAME_NOT_FOUND if not found
1464  *==========================================================================*/
lookupAttr(const mapType * arr,size_t len,const char * name)1465 template <class mapType> int lookupAttr(const mapType *arr,
1466         size_t len, const char *name)
1467 {
1468     if (name) {
1469         for (size_t i = 0; i < len; i++) {
1470             if (!strcmp(arr[i].desc, name))
1471                 return arr[i].val;
1472         }
1473     }
1474     return NAME_NOT_FOUND;
1475 }
1476 
1477 /*===========================================================================
1478  * FUNCTION   : lookupNameByValue
1479  *
1480  * DESCRIPTION: lookup a name by its value
1481  *
1482  * PARAMETERS :
1483  *   @attr    : map contains <name, value>
1484  *   @len     : size of the map
1485  *   @value   : value to be looked up
1486  *
1487  * RETURN     : name str or NULL if not found
1488  *==========================================================================*/
lookupNameByValue(const mapType * arr,size_t len,int value)1489 template <class mapType> const char *lookupNameByValue(const mapType *arr,
1490         size_t len, int value)
1491 {
1492     for (size_t i = 0; i < len; i++) {
1493         if (arr[i].val == value) {
1494             return arr[i].desc;
1495         }
1496     }
1497     return NULL;
1498 }
1499 
1500 /*===========================================================================
1501  * FUNCTION   : setPreviewSize
1502  *
1503  * DESCRIPTION: set preview size from user setting
1504  *
1505  * PARAMETERS :
1506  *   @params  : user setting parameters
1507  *
1508  * RETURN     : int32_t type of status
1509  *              NO_ERROR  -- success
1510  *              none-zero failure code
1511  *==========================================================================*/
setPreviewSize(const QCameraParameters & params)1512 int32_t QCameraParameters::setPreviewSize(const QCameraParameters& params)
1513 {
1514     int width = 0, height = 0;
1515     int old_width = 0, old_height = 0;
1516     params.getPreviewSize(&width, &height);
1517     CameraParameters::getPreviewSize(&old_width, &old_height);
1518 
1519     // Validate the preview size
1520     for (size_t i = 0; i < m_pCapability->preview_sizes_tbl_cnt; ++i) {
1521         if (width ==  m_pCapability->preview_sizes_tbl[i].width
1522            && height ==  m_pCapability->preview_sizes_tbl[i].height) {
1523             // check if need to restart preview in case of preview size change
1524             if (width != old_width || height != old_height) {
1525                 LOGI("Requested preview size %d x %d", width, height);
1526                 m_bNeedRestart = true;
1527             }
1528             // set the new value
1529             CameraParameters::setPreviewSize(width, height);
1530             return NO_ERROR;
1531         }
1532     }
1533     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
1534         char prop[PROPERTY_VALUE_MAX];
1535         // set prop to configure aux preview size
1536         property_get("persist.camera.aux.preview.size", prop, "0");
1537         parse_pair(prop, &width, &height, 'x', NULL);
1538         bool foundMatch = false;
1539         for (size_t i = 0; i < m_pCapability->preview_sizes_tbl_cnt; ++i) {
1540             if (width ==  m_pCapability->preview_sizes_tbl[i].width &&
1541                     height ==  m_pCapability->preview_sizes_tbl[i].height) {
1542                foundMatch = true;
1543             }
1544         }
1545         if (!foundMatch) {
1546             width = m_pCapability->preview_sizes_tbl[0].width;
1547             height = m_pCapability->preview_sizes_tbl[0].height;
1548         }
1549         // check if need to restart preview in case of preview size change
1550         if (width != old_width || height != old_height) {
1551             m_bNeedRestart = true;
1552         }
1553         CameraParameters::setPreviewSize(width, height);
1554         LOGH("Secondary Camera: preview size %d x %d", width, height);
1555         return NO_ERROR;
1556     }
1557 
1558     LOGE("Invalid preview size requested: %dx%d", width, height);
1559     return BAD_VALUE;
1560 }
1561 
1562 /*===========================================================================
1563  * FUNCTION   : setPictureSize
1564  *
1565  * DESCRIPTION: set picture size from user setting
1566  *
1567  * PARAMETERS :
1568  *   @params  : user setting parameters
1569  *
1570  * RETURN     : int32_t type of status
1571  *              NO_ERROR  -- success
1572  *              none-zero failure code
1573  *==========================================================================*/
setPictureSize(const QCameraParameters & params)1574 int32_t QCameraParameters::setPictureSize(const QCameraParameters& params)
1575 {
1576     int width, height;
1577     params.getPictureSize(&width, &height);
1578     int old_width, old_height;
1579     CameraParameters::getPictureSize(&old_width, &old_height);
1580 
1581     // Validate the picture size
1582     if(!m_reprocScaleParam.isScaleEnabled()){
1583         for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
1584             if (width ==  m_pCapability->picture_sizes_tbl[i].width
1585                && height ==  m_pCapability->picture_sizes_tbl[i].height) {
1586                 // check if need to restart preview in case of picture size change
1587                 if ((m_bZslMode || m_bRecordingHint) &&
1588                     (width != old_width || height != old_height)) {
1589                     LOGI("Requested picture size %d x %d", width, height);
1590                     m_bNeedRestart = true;
1591                 }
1592                 // set the new value
1593                 CameraParameters::setPictureSize(width, height);
1594                 // Update View angles based on Picture Aspect ratio
1595                 updateViewAngles();
1596                 return NO_ERROR;
1597             }
1598         }
1599     }else{
1600         //should use scaled picture size table to validate
1601         if(m_reprocScaleParam.setValidatePicSize(width, height) == NO_ERROR){
1602             // check if need to restart preview in case of picture size change
1603             if ((m_bZslMode || m_bRecordingHint) &&
1604                 (width != old_width || height != old_height)) {
1605                 m_bNeedRestart = true;
1606             }
1607             // set the new value
1608             char val[32];
1609             snprintf(val, sizeof(val), "%dx%d", width, height);
1610             updateParamEntry(KEY_PICTURE_SIZE, val);
1611             LOGH("%s", val);
1612             // Update View angles based on Picture Aspect ratio
1613             updateViewAngles();
1614             return NO_ERROR;
1615         }
1616     }
1617     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
1618         char prop[PROPERTY_VALUE_MAX];
1619         // set prop to configure aux preview size
1620         property_get("persist.camera.aux.picture.size", prop, "0");
1621         parse_pair(prop, &width, &height, 'x', NULL);
1622         bool foundMatch = false;
1623         for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
1624             if (width ==  m_pCapability->picture_sizes_tbl[i].width &&
1625                     height ==  m_pCapability->picture_sizes_tbl[i].height) {
1626                foundMatch = true;
1627             }
1628         }
1629         if (!foundMatch) {
1630             width = m_pCapability->picture_sizes_tbl[0].width;
1631             height = m_pCapability->picture_sizes_tbl[0].height;
1632         }
1633         // check if need to restart preview in case of preview size change
1634         if (width != old_width || height != old_height) {
1635             m_bNeedRestart = true;
1636         }
1637         char val[32];
1638         snprintf(val, sizeof(val), "%dx%d", width, height);
1639         set(KEY_PICTURE_SIZE, val);
1640         LOGH("Secondary Camera: picture size %s", val);
1641         return NO_ERROR;
1642     }
1643     LOGE("Invalid picture size requested: %dx%d", width, height);
1644     return BAD_VALUE;
1645 }
1646 
1647 /*===========================================================================
1648  * FUNCTION   : updateViewAngles
1649  *
1650  * DESCRIPTION: Update the Horizontal & Vertical based on the Aspect ratio of Preview and
1651  *                        Picture aspect ratio
1652  *
1653  * PARAMETERS : none
1654  *
1655  * RETURN     : none
1656  *==========================================================================*/
updateViewAngles()1657 void QCameraParameters::updateViewAngles()
1658 {
1659     double stillAspectRatio, maxPictureAspectRatio;
1660     int stillWidth, stillHeight, maxWidth, maxHeight;
1661     // The crop factors from the full sensor array to the still picture crop region
1662     double horizCropFactor = 1.f,vertCropFactor = 1.f;
1663     float horizViewAngle, vertViewAngle, maxHfov, maxVfov;
1664 
1665     // Get current Picture & max Snapshot sizes
1666     getPictureSize(&stillWidth, &stillHeight);
1667     maxWidth  = m_pCapability->picture_sizes_tbl[0].width;
1668     maxHeight = m_pCapability->picture_sizes_tbl[0].height;
1669 
1670     // Get default maximum FOV from corresponding sensor driver
1671     maxHfov = m_pCapability->hor_view_angle;
1672     maxVfov = m_pCapability->ver_view_angle;
1673 
1674     stillAspectRatio = (double)stillWidth/stillHeight;
1675     maxPictureAspectRatio = (double)maxWidth/maxHeight;
1676     LOGD("Stillwidth: %d, height: %d", stillWidth, stillHeight);
1677     LOGD("Max width: %d, height: %d", maxWidth, maxHeight);
1678     LOGD("still aspect: %f, Max Pic Aspect: %f",
1679             stillAspectRatio, maxPictureAspectRatio);
1680 
1681     // crop as per the Maximum Snapshot aspect ratio
1682     if (stillAspectRatio < maxPictureAspectRatio)
1683         horizCropFactor = stillAspectRatio/maxPictureAspectRatio;
1684     else
1685         vertCropFactor = maxPictureAspectRatio/stillAspectRatio;
1686 
1687     LOGD("horizCropFactor %f, vertCropFactor %f",
1688              horizCropFactor, vertCropFactor);
1689 
1690     // Now derive the final FOV's based on field of view formula is i.e,
1691     // angle of view = 2 * arctangent ( d / 2f )
1692     // where d is the physical sensor dimension of interest, and f is
1693     // the focal length. This only applies to rectilinear sensors, for focusing
1694     // at distances >> f, etc.
1695     // Here d/2f is nothing but the Maximum Horizontal or Veritical FOV
1696     horizViewAngle = (180/PI)*2*atan(horizCropFactor*tan((maxHfov/2)*(PI/180)));
1697     vertViewAngle = (180/PI)*2*atan(horizCropFactor*tan((maxVfov/2)*(PI/180)));
1698 
1699     setFloat(QCameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, horizViewAngle);
1700     setFloat(QCameraParameters::KEY_VERTICAL_VIEW_ANGLE, vertViewAngle);
1701     LOGH("Final horizViewAngle %f, vertViewAngle %f",
1702             horizViewAngle, vertViewAngle);
1703 }
1704 
1705 /*===========================================================================
1706  * FUNCTION   : setVideoSize
1707  *
1708  * DESCRIPTION: set video size from user setting
1709  *
1710  * PARAMETERS :
1711  *   @params  : user setting parameters
1712  *
1713  * RETURN     : int32_t type of status
1714  *              NO_ERROR  -- success
1715  *              none-zero failure code
1716  *==========================================================================*/
setVideoSize(const QCameraParameters & params)1717 int32_t QCameraParameters::setVideoSize(const QCameraParameters& params)
1718 {
1719     const char *str= NULL;
1720     int width, height;
1721     str = params.get(KEY_VIDEO_SIZE);
1722     int old_width, old_height;
1723     CameraParameters::getVideoSize(&old_width, &old_height);
1724     if(!str) {
1725         //If application didn't set this parameter string, use the values from
1726         //getPreviewSize() as video dimensions.
1727         params.getPreviewSize(&width, &height);
1728         LOGW("No Record Size requested, use the preview dimensions");
1729     } else {
1730         params.getVideoSize(&width, &height);
1731     }
1732 
1733     // Validate the video size
1734     for (size_t i = 0; i < m_pCapability->video_sizes_tbl_cnt; ++i) {
1735         if (width ==  m_pCapability->video_sizes_tbl[i].width
1736                 && height ==  m_pCapability->video_sizes_tbl[i].height) {
1737             // check if need to restart preview in case of video size change
1738             if (m_bRecordingHint &&
1739                (width != old_width || height != old_height)) {
1740                 m_bNeedRestart = true;
1741             }
1742 
1743             // set the new value
1744             LOGH("Requested video size %d x %d", width, height);
1745             CameraParameters::setVideoSize(width, height);
1746             return NO_ERROR;
1747         }
1748     }
1749     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
1750         // Set the default preview size for secondary camera
1751         width = m_pCapability->video_sizes_tbl[0].width;
1752         height = m_pCapability->video_sizes_tbl[0].height;
1753         // check if need to restart preview in case of preview size change
1754         if (width != old_width || height != old_height) {
1755             m_bNeedRestart = true;
1756         }
1757 
1758         CameraParameters::setVideoSize(width, height);
1759         LOGH("Secondary Camera: video size %d x %d",
1760                  width, height);
1761         return NO_ERROR;
1762     }
1763 
1764     LOGE("Error !! Invalid video size requested: %dx%d", width, height);
1765     return BAD_VALUE;
1766 }
1767 
1768 /*===========================================================================
1769  * FUNCTION   : getLiveSnapshotSize
1770  *
1771  * DESCRIPTION: get live snapshot size
1772  *
1773  * PARAMETERS : dim - Update dim with the liveshot size
1774  *
1775  *==========================================================================*/
getLiveSnapshotSize(cam_dimension_t & dim)1776 void QCameraParameters::getLiveSnapshotSize(cam_dimension_t &dim)
1777 {
1778     if(is4k2kVideoResolution()) {
1779         // We support maximum 8M liveshot @4K2K video resolution
1780         cam_dimension_t resolution = {0, 0};
1781         CameraParameters::getVideoSize(&resolution.width, &resolution.height);
1782         if((m_LiveSnapshotSize.width > resolution.width) ||
1783                 (m_LiveSnapshotSize.height > resolution.height)) {
1784             m_LiveSnapshotSize.width = resolution.width;
1785             m_LiveSnapshotSize.height = resolution.height;
1786         }
1787     }
1788     dim = m_LiveSnapshotSize;
1789     LOGH("w x h: %d x %d", dim.width, dim.height);
1790 }
1791 
1792 /*===========================================================================
1793  * FUNCTION   : setLiveSnapshotSize
1794  *
1795  * DESCRIPTION: set live snapshot size
1796  *
1797  * PARAMETERS :
1798  *   @params  : user setting parameters
1799  *
1800  * RETURN     : int32_t type of status
1801  *              NO_ERROR  -- success
1802  *              none-zero failure code
1803  *==========================================================================*/
setLiveSnapshotSize(const QCameraParameters & params)1804 int32_t QCameraParameters::setLiveSnapshotSize(const QCameraParameters& params)
1805 {
1806     char value[PROPERTY_VALUE_MAX];
1807     property_get("persist.camera.opt.livepic", value, "1");
1808     bool useOptimal = atoi(value) > 0 ? true : false;
1809     bool vHdrOn;
1810     int32_t liveSnapWidth = 0, liveSnapHeight = 0;
1811     // use picture size from user setting
1812     params.getPictureSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
1813 
1814     size_t livesnapshot_sizes_tbl_cnt =
1815             m_pCapability->livesnapshot_sizes_tbl_cnt;
1816     cam_dimension_t *livesnapshot_sizes_tbl =
1817             &m_pCapability->livesnapshot_sizes_tbl[0];
1818 
1819     if(is4k2kVideoResolution()) {
1820         // We support maximum 8M liveshot @4K2K video resolution
1821         cam_dimension_t resolution = {0, 0};
1822         CameraParameters::getVideoSize(&resolution.width, &resolution.height);
1823         if((m_LiveSnapshotSize.width > resolution.width) ||
1824                 (m_LiveSnapshotSize.height > resolution.height)) {
1825             m_LiveSnapshotSize.width = resolution.width;
1826             m_LiveSnapshotSize.height = resolution.height;
1827         }
1828     }
1829 
1830     // check if HFR is enabled
1831     const char *hfrStr = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
1832     cam_hfr_mode_t hfrMode = CAM_HFR_MODE_OFF;
1833     const char *hsrStr = params.get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
1834 
1835     const char *vhdrStr = params.get(KEY_QC_VIDEO_HDR);
1836     vHdrOn = (vhdrStr != NULL && (0 == strcmp(vhdrStr,"on"))) ? true : false;
1837     if (vHdrOn) {
1838         livesnapshot_sizes_tbl_cnt = m_pCapability->vhdr_livesnapshot_sizes_tbl_cnt;
1839         livesnapshot_sizes_tbl = &m_pCapability->vhdr_livesnapshot_sizes_tbl[0];
1840     }
1841     if ((hsrStr != NULL) && strcmp(hsrStr, "off")) {
1842         int32_t hsr = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hsrStr);
1843         if ((hsr != NAME_NOT_FOUND) && (hsr > CAM_HFR_MODE_OFF)) {
1844             // if HSR is enabled, change live snapshot size
1845             for (size_t i = 0; i < m_pCapability->hfr_tbl_cnt; i++) {
1846                 if (m_pCapability->hfr_tbl[i].mode == hsr) {
1847                     livesnapshot_sizes_tbl_cnt =
1848                             m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl_cnt;
1849                     livesnapshot_sizes_tbl =
1850                             &m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl[0];
1851                     hfrMode = m_pCapability->hfr_tbl[i].mode;
1852                     break;
1853                 }
1854             }
1855         }
1856     } else if ((hfrStr != NULL) && strcmp(hfrStr, "off")) {
1857         int32_t hfr = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hfrStr);
1858         if ((hfr != NAME_NOT_FOUND) && (hfr > CAM_HFR_MODE_OFF)) {
1859             // if HFR is enabled, change live snapshot size
1860             for (size_t i = 0; i < m_pCapability->hfr_tbl_cnt; i++) {
1861                 if (m_pCapability->hfr_tbl[i].mode == hfr) {
1862                     livesnapshot_sizes_tbl_cnt =
1863                             m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl_cnt;
1864                     livesnapshot_sizes_tbl =
1865                             &m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl[0];
1866                     hfrMode = m_pCapability->hfr_tbl[i].mode;
1867                     break;
1868                 }
1869             }
1870         }
1871     }
1872 
1873     if (useOptimal || hfrMode != CAM_HFR_MODE_OFF || vHdrOn) {
1874         bool found = false;
1875 
1876         // first check if picture size is within the list of supported sizes
1877         for (size_t i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
1878             if (m_LiveSnapshotSize.width == livesnapshot_sizes_tbl[i].width &&
1879                 m_LiveSnapshotSize.height == livesnapshot_sizes_tbl[i].height) {
1880                 found = true;
1881                 break;
1882             }
1883         }
1884 
1885         if (!found) {
1886             // use optimal live snapshot size from supported list,
1887             // that has same preview aspect ratio
1888             int width = 0, height = 0;
1889             params.getPreviewSize(&width, &height);
1890 
1891             double previewAspectRatio = (double)width / height;
1892             for (size_t i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
1893                 double ratio = (double)livesnapshot_sizes_tbl[i].width /
1894                                 livesnapshot_sizes_tbl[i].height;
1895                 if (fabs(previewAspectRatio - ratio) <= ASPECT_TOLERANCE) {
1896                     m_LiveSnapshotSize = livesnapshot_sizes_tbl[i];
1897                     found = true;
1898                     break;
1899                 }
1900             }
1901 
1902             if (!found && ((hfrMode != CAM_HFR_MODE_OFF) || vHdrOn)) {
1903                 // Cannot find matching aspect ration from supported live snapshot list
1904                 // choose the max dim from preview and video size
1905                 LOGD("Cannot find matching aspect ratio, choose max of preview or video size");
1906                 params.getVideoSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
1907                 if (m_LiveSnapshotSize.width < width && m_LiveSnapshotSize.height < height) {
1908                     m_LiveSnapshotSize.width = width;
1909                     m_LiveSnapshotSize.height = height;
1910                 }
1911             }
1912         }
1913     }
1914     //To read liveshot resolution from setprop instead of matching aspect ratio.
1915     //The setprop resolution format should be WxH.
1916     //e.g: adb shell setprop persist.camera.liveshot.size 1280x720
1917     memset(value, 0, PROPERTY_VALUE_MAX);
1918     property_get("persist.camera.liveshot.size", value, "");
1919     if (strlen(value) > 0) {
1920         char *saveptr = NULL;
1921         char *token = strtok_r(value, "x", &saveptr);
1922         if (token != NULL) {
1923             liveSnapWidth = atoi(token);
1924         }
1925         token = strtok_r(NULL, "x", &saveptr);
1926         if (token != NULL) {
1927             liveSnapHeight = atoi(token);
1928         }
1929         if ((liveSnapWidth!=0) && (liveSnapHeight!=0)) {
1930             for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
1931                 if (liveSnapWidth ==  m_pCapability->picture_sizes_tbl[i].width
1932                         && liveSnapHeight ==  m_pCapability->picture_sizes_tbl[i].height) {
1933                    m_LiveSnapshotSize.width = liveSnapWidth;
1934                    m_LiveSnapshotSize.height = liveSnapHeight;
1935                    break;
1936                 }
1937             }
1938         }
1939     }
1940     LOGH("live snapshot size %d x %d",
1941           m_LiveSnapshotSize.width, m_LiveSnapshotSize.height);
1942 
1943     return NO_ERROR;
1944 }
1945 
1946 
1947 /*===========================================================================
1948  * FUNCTION   : setRawSize
1949  *
1950  * DESCRIPTION: set live snapshot size
1951  *
1952  * PARAMETERS :
1953  *   @params  : user setting parameters
1954  *
1955  * RETURN     : int32_t type of status
1956  *              NO_ERROR  -- success
1957  *              none-zero failure code
1958  *==========================================================================*/
setRawSize(cam_dimension_t & dim)1959 int32_t QCameraParameters::setRawSize(cam_dimension_t &dim)
1960 {
1961     m_rawSize = dim;
1962     return NO_ERROR;
1963 }
1964 /*===========================================================================
1965  * FUNCTION   : setPreviewFormat
1966  *
1967  * DESCRIPTION: set preview format from user setting
1968  *
1969  * PARAMETERS :
1970  *   @params  : user setting parameters
1971  *
1972  * RETURN     : int32_t type of status
1973  *              NO_ERROR  -- success
1974  *              none-zero failure code
1975  *==========================================================================*/
setPreviewFormat(const QCameraParameters & params)1976 int32_t QCameraParameters::setPreviewFormat(const QCameraParameters& params)
1977 {
1978     const char *str = params.getPreviewFormat();
1979     int32_t previewFormat = lookupAttr(PREVIEW_FORMATS_MAP,
1980             PARAM_MAP_SIZE(PREVIEW_FORMATS_MAP), str);
1981     if (previewFormat != NAME_NOT_FOUND) {
1982         if (isUBWCEnabled()) {
1983             char prop[PROPERTY_VALUE_MAX];
1984             int pFormat;
1985             memset(prop, 0, sizeof(prop));
1986             property_get("persist.camera.preview.ubwc", prop, "1");
1987 
1988             pFormat = atoi(prop);
1989             if (pFormat == 1) {
1990                 mPreviewFormat = CAM_FORMAT_YUV_420_NV12_UBWC;
1991                 mAppPreviewFormat = (cam_format_t)previewFormat;
1992             } else {
1993                 mPreviewFormat = (cam_format_t)previewFormat;
1994                 mAppPreviewFormat = (cam_format_t)previewFormat;
1995             }
1996         } else {
1997             mPreviewFormat = (cam_format_t)previewFormat;
1998             mAppPreviewFormat = (cam_format_t)previewFormat;
1999         }
2000         CameraParameters::setPreviewFormat(str);
2001         LOGH("format %d\n", mPreviewFormat);
2002         return NO_ERROR;
2003     }
2004     LOGE("Invalid preview format value: %s", (str == NULL) ? "NULL" : str);
2005     return BAD_VALUE;
2006 }
2007 
2008 /*===========================================================================
2009  * FUNCTION   : setPictureFormat
2010  *
2011  * DESCRIPTION: set picture format from user setting
2012  *
2013  * PARAMETERS :
2014  *   @params  : user setting parameters
2015  *
2016  * RETURN     : int32_t type of status
2017  *              NO_ERROR  -- success
2018  *              none-zero failure code
2019  *==========================================================================*/
setPictureFormat(const QCameraParameters & params)2020 int32_t QCameraParameters::setPictureFormat(const QCameraParameters& params)
2021 {
2022     const char *str = params.getPictureFormat();
2023     int32_t pictureFormat = lookupAttr(PICTURE_TYPES_MAP, PARAM_MAP_SIZE(PICTURE_TYPES_MAP), str);
2024     if (pictureFormat != NAME_NOT_FOUND) {
2025         mPictureFormat = pictureFormat;
2026 
2027         CameraParameters::setPictureFormat(str);
2028         LOGH("format %d\n", mPictureFormat);
2029         return NO_ERROR;
2030     }
2031     LOGE("Invalid picture format value: %s", (str == NULL) ? "NULL" : str);
2032     return BAD_VALUE;
2033 }
2034 
2035 /*===========================================================================
2036  * FUNCTION   : setJpegThumbnailSize
2037  *
2038  * DESCRIPTION: set jpeg thumbnail size from user setting
2039  *
2040  * PARAMETERS :
2041  *   @params  : user setting parameters
2042  *
2043  * RETURN     : int32_t type of status
2044  *              NO_ERROR  -- success
2045  *              none-zero failure code
2046  *==========================================================================*/
setJpegThumbnailSize(const QCameraParameters & params)2047 int32_t QCameraParameters::setJpegThumbnailSize(const QCameraParameters& params)
2048 {
2049     int width = params.getInt(KEY_JPEG_THUMBNAIL_WIDTH);
2050     int height = params.getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
2051 
2052     LOGD("requested jpeg thumbnail size %d x %d", width, height);
2053     int sizes_cnt = sizeof(THUMBNAIL_SIZES_MAP) / sizeof(cam_dimension_t);
2054     // Validate thumbnail size
2055     for (int i = 0; i < sizes_cnt; i++) {
2056         if (width == THUMBNAIL_SIZES_MAP[i].width &&
2057                 height == THUMBNAIL_SIZES_MAP[i].height) {
2058            set(KEY_JPEG_THUMBNAIL_WIDTH, width);
2059            set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
2060            return NO_ERROR;
2061         }
2062     }
2063     LOGE("error: setting jpeg thumbnail size (%d, %d)", width, height);
2064     return BAD_VALUE;
2065 }
2066 
2067 /*===========================================================================
2068 
2069  * FUNCTION   : setBurstLEDOnPeriod
2070  *
2071  * DESCRIPTION: set burst LED on period
2072  *
2073  * PARAMETERS :
2074  *   @params  : user setting parameters
2075  *
2076  * RETURN     : int32_t type of status
2077  *              NO_ERROR  -- success
2078  *              none-zero failure code
2079  *==========================================================================*/
setBurstLEDOnPeriod(const QCameraParameters & params)2080 int32_t QCameraParameters::setBurstLEDOnPeriod(const QCameraParameters& params)
2081 {
2082     int nBurstLEDOnPeriod = params.getInt(KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD);
2083     //Check if the LED ON period is within limits
2084     if ((nBurstLEDOnPeriod <= 0) || (nBurstLEDOnPeriod > 800)) {
2085         // if burst led on period is not set in parameters,
2086         // read from sys prop
2087         char prop[PROPERTY_VALUE_MAX];
2088         memset(prop, 0, sizeof(prop));
2089         property_get("persist.camera.led.on.period", prop, "0");
2090         nBurstLEDOnPeriod = atoi(prop);
2091         if (nBurstLEDOnPeriod <= 0) {
2092             nBurstLEDOnPeriod = 300;
2093         }
2094     }
2095 
2096     set(KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD, nBurstLEDOnPeriod);
2097     m_nBurstLEDOnPeriod = nBurstLEDOnPeriod;
2098     LOGH("Burst LED on period  %u", m_nBurstLEDOnPeriod);
2099     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BURST_LED_ON_PERIOD,
2100             (uint32_t)nBurstLEDOnPeriod)) {
2101         return BAD_VALUE;
2102     }
2103 
2104     return NO_ERROR;
2105 }
2106 
2107 
2108 
2109 /*===========================================================================
2110  * FUNCTION   : setRetroActiveBurstNum
2111  *
2112  * DESCRIPTION: set retro active burst num
2113  *
2114  * PARAMETERS :
2115  *   @params  : user setting parameters
2116  *
2117  * RETURN     : int32_t type of status
2118  *              NO_ERROR  -- success
2119  *              none-zero failure code
2120  *==========================================================================*/
setRetroActiveBurstNum(const QCameraParameters & params)2121 int32_t QCameraParameters::setRetroActiveBurstNum(
2122         const QCameraParameters& params)
2123 {
2124     int32_t nBurstNum = params.getInt(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER);
2125     LOGH("m_nRetroBurstNum = %d", m_nRetroBurstNum);
2126     if (nBurstNum <= 0) {
2127         // if burst number is not set in parameters,
2128         // read from sys prop
2129         char prop[PROPERTY_VALUE_MAX];
2130         memset(prop, 0, sizeof(prop));
2131         property_get("persist.camera.retro.number", prop, "0");
2132         nBurstNum = atoi(prop);
2133         if (nBurstNum < 0) {
2134             nBurstNum = 0;
2135         }
2136     }
2137 
2138     set(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER, nBurstNum);
2139 
2140     m_nRetroBurstNum = nBurstNum;
2141     LOGH("m_nRetroBurstNum = %d", m_nRetroBurstNum);
2142     return NO_ERROR;
2143 }
2144 
2145 /*===========================================================================
2146  * FUNCTION   : setJpegQuality
2147  *
2148  * DESCRIPTION: set jpeg encpding quality from user setting
2149  *
2150  * PARAMETERS :
2151  *   @params  : user setting parameters
2152  *
2153  * RETURN     : int32_t type of status
2154  *              NO_ERROR  -- success
2155  *              none-zero failure code
2156  *==========================================================================*/
setJpegQuality(const QCameraParameters & params)2157 int32_t QCameraParameters::setJpegQuality(const QCameraParameters& params)
2158 {
2159     int32_t rc = NO_ERROR;
2160     int quality = params.getInt(KEY_JPEG_QUALITY);
2161     if (quality >= 0 && quality <= 100) {
2162         set(KEY_JPEG_QUALITY, quality);
2163     } else {
2164         LOGE("Invalid jpeg quality=%d", quality);
2165         rc = BAD_VALUE;
2166     }
2167 
2168     quality = params.getInt(KEY_JPEG_THUMBNAIL_QUALITY);
2169     if (quality >= 0 && quality <= 100) {
2170         set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
2171     } else {
2172         LOGE("Invalid jpeg thumbnail quality=%d", quality);
2173         rc = BAD_VALUE;
2174     }
2175     return rc;
2176 }
2177 
2178 /*===========================================================================
2179  * FUNCTION   : setOrientaion
2180  *
2181  * DESCRIPTION: set orientaion from user setting
2182  *
2183  * PARAMETERS :
2184  *   @params  : user setting parameters
2185  *
2186  * RETURN     : int32_t type of status
2187  *              NO_ERROR  -- success
2188  *              none-zero failure code
2189  *==========================================================================*/
setOrientation(const QCameraParameters & params)2190 int32_t QCameraParameters::setOrientation(const QCameraParameters& params)
2191 {
2192     const char *str = params.get(KEY_QC_ORIENTATION);
2193 
2194     if (str != NULL) {
2195         if (strcmp(str, portrait) == 0 || strcmp(str, landscape) == 0) {
2196             // Camera service needs this to decide if the preview frames and raw
2197             // pictures should be rotated.
2198             set(KEY_QC_ORIENTATION, str);
2199         } else {
2200             LOGE("Invalid orientation value: %s", str);
2201             return BAD_VALUE;
2202         }
2203     }
2204     return NO_ERROR;
2205 }
2206 
2207 /*===========================================================================
2208  * FUNCTION   : setAutoExposure
2209  *
2210  * DESCRIPTION: set auto exposure value from user setting
2211  *
2212  * PARAMETERS :
2213  *   @params  : user setting parameters
2214  *
2215  * RETURN     : int32_t type of status
2216  *              NO_ERROR  -- success
2217  *              none-zero failure code
2218  *==========================================================================*/
setAutoExposure(const QCameraParameters & params)2219 int32_t QCameraParameters::setAutoExposure(const QCameraParameters& params)
2220 {
2221     const char *str = params.get(KEY_QC_AUTO_EXPOSURE);
2222     const char *prev_str = get(KEY_QC_AUTO_EXPOSURE);
2223     if (str != NULL) {
2224         if (prev_str == NULL ||
2225             strcmp(str, prev_str) != 0) {
2226             return setAutoExposure(str);
2227         }
2228     }
2229     return NO_ERROR;
2230 }
2231 
2232 /*===========================================================================
2233  * FUNCTION   : setPreviewFpsRange
2234  *
2235  * DESCRIPTION: set preview FPS range from user setting
2236  *
2237  * PARAMETERS :
2238  *   @params  : user setting parameters
2239  *
2240  * RETURN     : int32_t type of status
2241  *              NO_ERROR  -- success
2242  *              none-zero failure code
2243  *==========================================================================*/
setPreviewFpsRange(const QCameraParameters & params)2244 int32_t QCameraParameters::setPreviewFpsRange(const QCameraParameters& params)
2245 {
2246     int minFps,maxFps;
2247     int prevMinFps, prevMaxFps, vidMinFps, vidMaxFps;
2248     int rc = NO_ERROR;
2249     bool found = false, updateNeeded = false;
2250 
2251     CameraParameters::getPreviewFpsRange(&prevMinFps, &prevMaxFps);
2252     params.getPreviewFpsRange(&minFps, &maxFps);
2253 
2254     LOGH("FpsRange Values:(%d, %d)", prevMinFps, prevMaxFps);
2255     LOGH("Requested FpsRange Values:(%d, %d)", minFps, maxFps);
2256 
2257     //first check if we need to change fps because of HFR mode change
2258     updateNeeded = UpdateHFRFrameRate(params);
2259     if (updateNeeded) {
2260         m_bNeedRestart = true;
2261         rc = setHighFrameRate(mHfrMode);
2262         if (rc != NO_ERROR) goto end;
2263     }
2264     LOGH("UpdateHFRFrameRate %d", updateNeeded);
2265 
2266     vidMinFps = (int)m_hfrFpsRange.video_min_fps;
2267     vidMaxFps = (int)m_hfrFpsRange.video_max_fps;
2268 
2269     if(minFps == prevMinFps && maxFps == prevMaxFps) {
2270         if ( m_bFixedFrameRateSet ) {
2271             minFps = params.getPreviewFrameRate() * 1000;
2272             maxFps = params.getPreviewFrameRate() * 1000;
2273             m_bFixedFrameRateSet = false;
2274         } else if (!updateNeeded) {
2275             LOGH("No change in FpsRange");
2276             rc = NO_ERROR;
2277             goto end;
2278         }
2279     }
2280     for(size_t i = 0; i < m_pCapability->fps_ranges_tbl_cnt; i++) {
2281         // if the value is in the supported list
2282         if (minFps >= m_pCapability->fps_ranges_tbl[i].min_fps * 1000 &&
2283                 maxFps <= m_pCapability->fps_ranges_tbl[i].max_fps * 1000) {
2284             found = true;
2285             LOGH("FPS i=%d : minFps = %d, maxFps = %d"
2286                     " vidMinFps = %d, vidMaxFps = %d",
2287                      i, minFps, maxFps,
2288                     (int)m_hfrFpsRange.video_min_fps,
2289                     (int)m_hfrFpsRange.video_max_fps);
2290             if ((0.0f >= m_hfrFpsRange.video_min_fps) ||
2291                     (0.0f >= m_hfrFpsRange.video_max_fps)) {
2292                 vidMinFps = minFps;
2293                 vidMaxFps = maxFps;
2294             }
2295             else {
2296                 vidMinFps = (int)m_hfrFpsRange.video_min_fps;
2297                 vidMaxFps = (int)m_hfrFpsRange.video_max_fps;
2298             }
2299 
2300             setPreviewFpsRange(minFps, maxFps, vidMinFps, vidMaxFps);
2301             break;
2302         }
2303     }
2304     if(found == false){
2305         LOGE("error: FPS range value not supported");
2306         rc = BAD_VALUE;
2307     }
2308 end:
2309     return rc;
2310 }
2311 
2312 /*===========================================================================
2313  * FUNCTION   : UpdateHFRFrameRate
2314  *
2315  * DESCRIPTION: set preview FPS range based on HFR setting
2316  *
2317  * PARAMETERS :
2318  *   @params  : user setting parameters
2319  *
2320  * RETURN     : bool true/false
2321  *                  true -if HAL needs to overwrite FPS range set by app, false otherwise.
2322  *==========================================================================*/
2323 
UpdateHFRFrameRate(const QCameraParameters & params)2324 bool QCameraParameters::UpdateHFRFrameRate(const QCameraParameters& params)
2325 {
2326     bool updateNeeded = false;
2327     int min_fps, max_fps;
2328     int32_t hfrMode = CAM_HFR_MODE_OFF;
2329     int32_t newHfrMode = CAM_HFR_MODE_OFF;
2330 
2331     int parm_minfps,parm_maxfps;
2332     int prevMinFps, prevMaxFps;
2333     CameraParameters::getPreviewFpsRange(&prevMinFps, &prevMaxFps);
2334     params.getPreviewFpsRange(&parm_minfps, &parm_maxfps);
2335     LOGH("CameraParameters - : minFps = %d, maxFps = %d ",
2336                  prevMinFps, prevMaxFps);
2337     LOGH("Requested params - : minFps = %d, maxFps = %d ",
2338                  parm_minfps, parm_maxfps);
2339 
2340     const char *hfrStr = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
2341     const char *hsrStr = params.get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
2342 
2343     const char *prev_hfrStr = CameraParameters::get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
2344     const char *prev_hsrStr = CameraParameters::get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
2345 
2346     if ((hfrStr != NULL) && (prev_hfrStr != NULL) && strcmp(hfrStr, prev_hfrStr)) {
2347         updateParamEntry(KEY_QC_VIDEO_HIGH_FRAME_RATE, hfrStr);
2348     }
2349 
2350     if ((hsrStr != NULL) && (prev_hsrStr != NULL) && strcmp(hsrStr, prev_hsrStr)) {
2351         updateParamEntry(KEY_QC_VIDEO_HIGH_SPEED_RECORDING, hsrStr);
2352 
2353     }
2354 
2355     // check if HFR is enabled
2356     if ((hfrStr != NULL) && strcmp(hfrStr, "off")) {
2357         hfrMode = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hfrStr);
2358         if (NAME_NOT_FOUND != hfrMode) newHfrMode = hfrMode;
2359     }
2360     // check if HSR is enabled
2361     else if ((hsrStr != NULL) && strcmp(hsrStr, "off")) {
2362         hfrMode = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hsrStr);
2363         if (NAME_NOT_FOUND != hfrMode) newHfrMode = hfrMode;
2364     }
2365     LOGH("prevHfrMode - %d, currentHfrMode = %d ",
2366                  mHfrMode, newHfrMode);
2367 
2368     if (mHfrMode != newHfrMode) {
2369         updateNeeded = true;
2370         mHfrMode = newHfrMode;
2371         switch (mHfrMode) {
2372             case CAM_HFR_MODE_60FPS:
2373                 min_fps = 60000;
2374                 max_fps = 60000;
2375                 break;
2376             case CAM_HFR_MODE_90FPS:
2377                 min_fps = 90000;
2378                 max_fps = 90000;
2379                 break;
2380             case CAM_HFR_MODE_120FPS:
2381                 min_fps = 120000;
2382                 max_fps = 120000;
2383                 break;
2384             case CAM_HFR_MODE_150FPS:
2385                 min_fps = 150000;
2386                 max_fps = 150000;
2387                 break;
2388             case CAM_HFR_MODE_180FPS:
2389                 min_fps = 180000;
2390                 max_fps = 180000;
2391                 break;
2392             case CAM_HFR_MODE_210FPS:
2393                 min_fps = 210000;
2394                 max_fps = 210000;
2395                 break;
2396             case CAM_HFR_MODE_240FPS:
2397                 min_fps = 240000;
2398                 max_fps = 240000;
2399                 break;
2400             case CAM_HFR_MODE_480FPS:
2401                 min_fps = 480000;
2402                 max_fps = 480000;
2403                 break;
2404             case CAM_HFR_MODE_OFF:
2405             default:
2406                 // Set Video Fps to zero
2407                 min_fps = 0;
2408                 max_fps = 0;
2409                 break;
2410         }
2411         m_hfrFpsRange.video_min_fps = (float)min_fps;
2412         m_hfrFpsRange.video_max_fps = (float)max_fps;
2413 
2414         LOGH("HFR mode (%d) Set video FPS : minFps = %d, maxFps = %d ",
2415                  mHfrMode, min_fps, max_fps);
2416     }
2417 
2418     // Remember if HFR mode is ON
2419     if ((mHfrMode > CAM_HFR_MODE_OFF) && (mHfrMode < CAM_HFR_MODE_MAX)) {
2420         LOGH("HFR mode is ON");
2421         m_bHfrMode = true;
2422     } else {
2423         m_hfrFpsRange.video_min_fps = 0;
2424         m_hfrFpsRange.video_max_fps = 0;
2425         m_bHfrMode = false;
2426         LOGH("HFR mode is OFF");
2427     }
2428     m_hfrFpsRange.min_fps = (float)parm_minfps;
2429     m_hfrFpsRange.max_fps = (float)parm_maxfps;
2430 
2431     if (m_bHfrMode && (mHfrMode > CAM_HFR_MODE_120FPS)
2432             && (parm_maxfps != 0)) {
2433         //Configure buffer batch count to use batch mode for higher fps
2434         setBufBatchCount((int8_t)(m_hfrFpsRange.video_max_fps / parm_maxfps));
2435     } else {
2436         //Reset batch count and update KEY for encoder
2437         setBufBatchCount(0);
2438     }
2439     return updateNeeded;
2440 }
2441 
2442 /*===========================================================================
2443  * FUNCTION   : setPreviewFrameRate
2444  *
2445  * DESCRIPTION: set preview frame rate from user setting
2446  *
2447  * PARAMETERS :
2448  *   @params  : user setting parameters
2449  *
2450  * RETURN     : int32_t type of status
2451  *              NO_ERROR  -- success
2452  *              none-zero failure code
2453  *==========================================================================*/
setPreviewFrameRate(const QCameraParameters & params)2454 int32_t QCameraParameters::setPreviewFrameRate(const QCameraParameters& params)
2455 {
2456     const char *str = params.get(KEY_PREVIEW_FRAME_RATE);
2457     const char *prev_str = get(KEY_PREVIEW_FRAME_RATE);
2458 
2459     if ( str ) {
2460         if ( prev_str &&
2461              strcmp(str, prev_str)) {
2462             LOGD("Requested Fixed Frame Rate %s", str);
2463             updateParamEntry(KEY_PREVIEW_FRAME_RATE, str);
2464             m_bFixedFrameRateSet = true;
2465         }
2466     }
2467     return NO_ERROR;
2468 }
2469 
2470 /*===========================================================================
2471  * FUNCTION   : setEffect
2472  *
2473  * DESCRIPTION: set effect value from user setting
2474  *
2475  * PARAMETERS :
2476  *   @params  : user setting parameters
2477  *
2478  * RETURN     : int32_t type of status
2479  *              NO_ERROR  -- success
2480  *              none-zero failure code
2481  *==========================================================================*/
setEffect(const QCameraParameters & params)2482 int32_t QCameraParameters::setEffect(const QCameraParameters& params)
2483 {
2484     const char *str = params.get(KEY_EFFECT);
2485     const char *prev_str = get(KEY_EFFECT);
2486 
2487     char prop[PROPERTY_VALUE_MAX];
2488     memset(prop, 0, sizeof(prop));
2489     property_get("persist.camera.effect", prop, "none");
2490 
2491     if (strcmp(prop, "none")) {
2492         if ((prev_str == NULL) ||
2493                 (strcmp(prop, prev_str) != 0) ||
2494                 (m_bUpdateEffects == true)) {
2495             m_bUpdateEffects = false;
2496             return setEffect(prop);
2497         }
2498     } else if (str != NULL) {
2499         if ((prev_str == NULL) ||
2500                 (strcmp(str, prev_str) != 0) ||
2501                 (m_bUpdateEffects == true)) {
2502             m_bUpdateEffects = false;
2503             return setEffect(str);
2504         }
2505     }
2506     return NO_ERROR;
2507 }
2508 
2509 /*===========================================================================
2510  * FUNCTION   : setFocusMode
2511  *
2512  * DESCRIPTION: set focus mode from user setting
2513  *
2514  * PARAMETERS :
2515  *   @params  : user setting parameters
2516  *
2517  * RETURN     : int32_t type of status
2518  *              NO_ERROR  -- success
2519  *              none-zero failure code
2520  *==========================================================================*/
setFocusMode(const QCameraParameters & params)2521 int32_t QCameraParameters::setFocusMode(const QCameraParameters& params)
2522 {
2523     const char *str = params.get(KEY_FOCUS_MODE);
2524     const char *prev_str = get(KEY_FOCUS_MODE);
2525     if (str != NULL) {
2526         if (prev_str == NULL ||
2527             strcmp(str, prev_str) != 0) {
2528             return setFocusMode(str);
2529         }
2530     }
2531     return NO_ERROR;
2532 }
2533 
2534 /*===========================================================================
2535  * FUNCTION   : setFocusPosition
2536  *
2537  * DESCRIPTION: set focus position from user setting
2538  *
2539  * PARAMETERS :
2540  *   @params  : user setting parameters
2541  *
2542  * RETURN     : int32_t type of status
2543  *              NO_ERROR  -- success
2544  *              none-zero failure code
2545  *==========================================================================*/
setFocusPosition(const QCameraParameters & params)2546 int32_t  QCameraParameters::setFocusPosition(const QCameraParameters& params)
2547 {
2548     const char *focus_str = params.get(KEY_FOCUS_MODE);
2549     const char *prev_focus_str = get(KEY_FOCUS_MODE);
2550 
2551     if (NULL == focus_str) {
2552         return NO_ERROR;
2553     }
2554 
2555     LOGD("current focus mode: %s", focus_str);
2556     if (strcmp(focus_str, FOCUS_MODE_MANUAL_POSITION)) {
2557         LOGH(", dont set focus pos to back-end!");
2558         return NO_ERROR;
2559     }
2560 
2561     const char *pos = params.get(KEY_QC_MANUAL_FOCUS_POSITION);
2562     const char *prev_pos = get(KEY_QC_MANUAL_FOCUS_POSITION);
2563     const char *type = params.get(KEY_QC_MANUAL_FOCUS_POS_TYPE);
2564     const char *prev_type = get(KEY_QC_MANUAL_FOCUS_POS_TYPE);
2565 
2566     if ((pos != NULL) && (type != NULL) && (focus_str != NULL)) {
2567         if (prev_pos  == NULL || (strcmp(pos, prev_pos) != 0) ||
2568             prev_type == NULL || (strcmp(type, prev_type) != 0) ||
2569             prev_focus_str == NULL || (strcmp(focus_str, prev_focus_str) != 0)) {
2570             return setFocusPosition(type, pos);
2571         }
2572     }
2573 
2574     return NO_ERROR;
2575 }
2576 
2577 /*===========================================================================
2578  * FUNCTION   : setBrightness
2579  *
2580  * DESCRIPTION: set brightness control value from user setting
2581  *
2582  * PARAMETERS :
2583  *   @params  : user setting parameters
2584  *
2585  * RETURN     : int32_t type of status
2586  *              NO_ERROR  -- success
2587  *              none-zero failure code
2588  *==========================================================================*/
setBrightness(const QCameraParameters & params)2589 int32_t QCameraParameters::setBrightness(const QCameraParameters& params)
2590 {
2591     int currentBrightness = getInt(KEY_QC_BRIGHTNESS);
2592     int brightness = params.getInt(KEY_QC_BRIGHTNESS);
2593 
2594     if(params.get(KEY_QC_BRIGHTNESS) == NULL) {
2595        LOGH("Brigtness not set by App ");
2596        return NO_ERROR;
2597     }
2598     if (currentBrightness !=  brightness) {
2599         if (brightness >= m_pCapability->brightness_ctrl.min_value &&
2600             brightness <= m_pCapability->brightness_ctrl.max_value) {
2601             LOGD("new brightness value : %d ", brightness);
2602             return setBrightness(brightness);
2603         } else {
2604             LOGE("invalid value %d out of (%d, %d)",
2605                    brightness,
2606                   m_pCapability->brightness_ctrl.min_value,
2607                   m_pCapability->brightness_ctrl.max_value);
2608             return BAD_VALUE;
2609         }
2610     } else {
2611         LOGD("No brightness value changed.");
2612         return NO_ERROR;
2613     }
2614 }
2615 
2616 /*===========================================================================
2617  * FUNCTION   : getBrightness
2618  *
2619  * DESCRIPTION: get brightness control value from user setting
2620  *
2621  * PARAMETERS :
2622  *   @params  : user setting parameters
2623  *
2624  * RETURN     : int32_t type of status
2625  *              NO_ERROR  -- success
2626  *              none-zero failure code
2627  *==========================================================================*/
getBrightness()2628 int QCameraParameters::getBrightness()
2629 {
2630     return getInt(KEY_QC_BRIGHTNESS);
2631 }
2632 
2633 /*===========================================================================
2634  * FUNCTION   : setSharpness
2635  *
2636  * DESCRIPTION: set sharpness control value from user setting
2637  *
2638  * PARAMETERS :
2639  *   @params  : user setting parameters
2640  *
2641  * RETURN     : int32_t type of status
2642  *              NO_ERROR  -- success
2643  *              none-zero failure code
2644  *==========================================================================*/
setSharpness(const QCameraParameters & params)2645 int32_t QCameraParameters::setSharpness(const QCameraParameters& params)
2646 {
2647     int shaprness = params.getInt(KEY_QC_SHARPNESS);
2648     int prev_sharp = getInt(KEY_QC_SHARPNESS);
2649 
2650     if(params.get(KEY_QC_SHARPNESS) == NULL) {
2651        LOGH("Sharpness not set by App ");
2652        return NO_ERROR;
2653     }
2654     if (prev_sharp !=  shaprness) {
2655         if((shaprness >= m_pCapability->sharpness_ctrl.min_value) &&
2656            (shaprness <= m_pCapability->sharpness_ctrl.max_value)) {
2657             LOGD("new sharpness value : %d ", shaprness);
2658             return setSharpness(shaprness);
2659         } else {
2660             LOGE("invalid value %d out of (%d, %d)",
2661                    shaprness,
2662                   m_pCapability->sharpness_ctrl.min_value,
2663                   m_pCapability->sharpness_ctrl.max_value);
2664             return BAD_VALUE;
2665         }
2666     } else {
2667         LOGD("No value change in shaprness");
2668         return NO_ERROR;
2669     }
2670 }
2671 
2672 /*===========================================================================
2673  * FUNCTION   : setSkintoneEnahancement
2674  *
2675  * DESCRIPTION: set skin tone enhancement factor from user setting
2676  *
2677  * PARAMETERS :
2678  *   @params  : user setting parameters
2679  *
2680  * RETURN     : int32_t type of status
2681  *              NO_ERROR  -- success
2682  *              none-zero failure code
2683  *==========================================================================*/
setSkinToneEnhancement(const QCameraParameters & params)2684 int32_t QCameraParameters::setSkinToneEnhancement(const QCameraParameters& params)
2685 {
2686     int sceFactor = params.getInt(KEY_QC_SCE_FACTOR);
2687     int prev_sceFactor = getInt(KEY_QC_SCE_FACTOR);
2688 
2689     if(params.get(KEY_QC_SCE_FACTOR) == NULL) {
2690        LOGH("Skintone enhancement not set by App ");
2691        return NO_ERROR;
2692     }
2693     if (prev_sceFactor != sceFactor) {
2694         if((sceFactor >= m_pCapability->sce_ctrl.min_value) &&
2695            (sceFactor <= m_pCapability->sce_ctrl.max_value)) {
2696             LOGD("new Skintone Enhancement value : %d ", sceFactor);
2697             return setSkinToneEnhancement(sceFactor);
2698         } else {
2699             LOGE("invalid value %d out of (%d, %d)",
2700                    sceFactor,
2701                   m_pCapability->sce_ctrl.min_value,
2702                   m_pCapability->sce_ctrl.max_value);
2703             return BAD_VALUE;
2704         }
2705     } else {
2706         LOGD("No value change in skintone enhancement factor");
2707         return NO_ERROR;
2708     }
2709 }
2710 
2711 /*===========================================================================
2712  * FUNCTION   : setSaturation
2713  *
2714  * DESCRIPTION: set saturation control value from user setting
2715  *
2716  * PARAMETERS :
2717  *   @params  : user setting parameters
2718  *
2719  * RETURN     : int32_t type of status
2720  *              NO_ERROR  -- success
2721  *              none-zero failure code
2722  *==========================================================================*/
setSaturation(const QCameraParameters & params)2723 int32_t QCameraParameters::setSaturation(const QCameraParameters& params)
2724 {
2725     int saturation = params.getInt(KEY_QC_SATURATION);
2726     int prev_sat = getInt(KEY_QC_SATURATION);
2727 
2728     if(params.get(KEY_QC_SATURATION) == NULL) {
2729        LOGH("Saturation not set by App ");
2730        return NO_ERROR;
2731     }
2732     if (prev_sat !=  saturation) {
2733         if((saturation >= m_pCapability->saturation_ctrl.min_value) &&
2734            (saturation <= m_pCapability->saturation_ctrl.max_value)) {
2735             LOGD("new saturation value : %d ", saturation);
2736             return setSaturation(saturation);
2737         } else {
2738             LOGE("invalid value %d out of (%d, %d)",
2739                    saturation,
2740                   m_pCapability->saturation_ctrl.min_value,
2741                   m_pCapability->saturation_ctrl.max_value);
2742             return BAD_VALUE;
2743         }
2744     } else {
2745         LOGD("No value change in saturation factor");
2746         return NO_ERROR;
2747     }
2748 }
2749 
2750 /*===========================================================================
2751  * FUNCTION   : setContrast
2752  *
2753  * DESCRIPTION: set contrast control value from user setting
2754  *
2755  * PARAMETERS :
2756  *   @params  : user setting parameters
2757  *
2758  * RETURN     : int32_t type of status
2759  *              NO_ERROR  -- success
2760  *              none-zero failure code
2761  *==========================================================================*/
setContrast(const QCameraParameters & params)2762 int32_t QCameraParameters::setContrast(const QCameraParameters& params)
2763 {
2764     int contrast = params.getInt(KEY_QC_CONTRAST);
2765     int prev_contrast = getInt(KEY_QC_CONTRAST);
2766 
2767     if(params.get(KEY_QC_CONTRAST) == NULL) {
2768        LOGH("Contrast not set by App ");
2769        return NO_ERROR;
2770     }
2771     if (prev_contrast !=  contrast) {
2772         if((contrast >= m_pCapability->contrast_ctrl.min_value) &&
2773            (contrast <= m_pCapability->contrast_ctrl.max_value)) {
2774             LOGD("new contrast value : %d ", contrast);
2775             int32_t rc = setContrast(contrast);
2776             return rc;
2777         } else {
2778             LOGE("invalid value %d out of (%d, %d)",
2779                    contrast,
2780                   m_pCapability->contrast_ctrl.min_value,
2781                   m_pCapability->contrast_ctrl.max_value);
2782             return BAD_VALUE;
2783         }
2784     } else {
2785         LOGD("No value change in contrast");
2786         return NO_ERROR;
2787     }
2788 }
2789 
2790 /*===========================================================================
2791  * FUNCTION   : setExposureCompensation
2792  *
2793  * DESCRIPTION: set exposure compensation value from user setting
2794  *
2795  * PARAMETERS :
2796  *   @params  : user setting parameters
2797  *
2798  * RETURN     : int32_t type of status
2799  *              NO_ERROR  -- success
2800  *              none-zero failure code
2801  *==========================================================================*/
setExposureCompensation(const QCameraParameters & params)2802 int32_t QCameraParameters::setExposureCompensation(const QCameraParameters & params)
2803 {
2804     int expComp = params.getInt(KEY_EXPOSURE_COMPENSATION);
2805     int prev_expComp = getInt(KEY_EXPOSURE_COMPENSATION);
2806 
2807     if(params.get(KEY_EXPOSURE_COMPENSATION) == NULL) {
2808        LOGH("Exposure compensation not set by App ");
2809        return NO_ERROR;
2810     }
2811     if (prev_expComp != expComp) {
2812         if((expComp >= m_pCapability->exposure_compensation_min) &&
2813            (expComp <= m_pCapability->exposure_compensation_max)) {
2814             LOGD("new Exposure Compensation value : %d ", expComp);
2815             return setExposureCompensation(expComp);
2816         } else {
2817             LOGE("invalid value %d out of (%d, %d)",
2818                    expComp,
2819                   m_pCapability->exposure_compensation_min,
2820                   m_pCapability->exposure_compensation_max);
2821             return BAD_VALUE;
2822         }
2823     } else {
2824         LOGD("No value change in Exposure Compensation");
2825         return NO_ERROR;
2826     }
2827 }
2828 
2829 /*===========================================================================
2830  * FUNCTION   : setWhiteBalance
2831  *
2832  * DESCRIPTION: set white balance value from user setting
2833  *
2834  * PARAMETERS :
2835  *   @params  : user setting parameters
2836  *
2837  * RETURN     : int32_t type of status
2838  *              NO_ERROR  -- success
2839  *              none-zero failure code
2840  *==========================================================================*/
setWhiteBalance(const QCameraParameters & params)2841 int32_t QCameraParameters::setWhiteBalance(const QCameraParameters& params)
2842 {
2843     const char *str = params.get(KEY_WHITE_BALANCE);
2844     const char *prev_str = get(KEY_WHITE_BALANCE);
2845     if (str != NULL) {
2846         if (prev_str == NULL ||
2847             strcmp(str, prev_str) != 0) {
2848             return setWhiteBalance(str);
2849         }
2850     }
2851     return NO_ERROR;
2852 }
2853 
2854 /*===========================================================================
2855  * FUNCTION   : setManualWhiteBalance
2856  *
2857  * DESCRIPTION: set manual white balance from user setting
2858  *
2859  * PARAMETERS :
2860  *   @params  : user setting parameters
2861  *
2862  * RETURN     : int32_t type of status
2863  *              NO_ERROR  -- success
2864  *              none-zero failure code
2865  *==========================================================================*/
setManualWhiteBalance(const QCameraParameters & params)2866 int32_t  QCameraParameters::setManualWhiteBalance(const QCameraParameters& params)
2867 {
2868     int32_t rc = NO_ERROR;
2869     const char *wb_str = params.get(KEY_WHITE_BALANCE);
2870     const char *prev_wb_str = get(KEY_WHITE_BALANCE);
2871     LOGD("current wb mode: %s", wb_str);
2872 
2873     if (wb_str != NULL) {
2874         if (strcmp(wb_str, WHITE_BALANCE_MANUAL)) {
2875             LOGD("dont set cct to back-end.");
2876             return NO_ERROR;
2877         }
2878     }
2879 
2880     const char *value = params.get(KEY_QC_MANUAL_WB_VALUE);
2881     const char *prev_value = get(KEY_QC_MANUAL_WB_VALUE);
2882     const char *type = params.get(KEY_QC_MANUAL_WB_TYPE);
2883     const char *prev_type = get(KEY_QC_MANUAL_WB_TYPE);
2884 
2885     if ((value != NULL) && (type != NULL) && (wb_str != NULL)) {
2886         if (prev_value  == NULL || (strcmp(value, prev_value) != 0) ||
2887             prev_type == NULL || (strcmp(type, prev_type) != 0) ||
2888             prev_wb_str == NULL || (strcmp(wb_str, prev_wb_str) != 0)) {
2889             updateParamEntry(KEY_QC_MANUAL_WB_TYPE, type);
2890             updateParamEntry(KEY_QC_MANUAL_WB_VALUE, value);
2891             int32_t wb_type = atoi(type);
2892             if (wb_type == CAM_MANUAL_WB_MODE_CCT) {
2893                 rc = setWBManualCCT(value);
2894             } else if (wb_type == CAM_MANUAL_WB_MODE_GAIN) {
2895                 rc = setManualWBGains(value);
2896             } else {
2897                 rc = BAD_VALUE;
2898             }
2899         }
2900     }
2901     return rc;
2902 }
2903 
2904 /*===========================================================================
2905  * FUNCTION   : setAntibanding
2906  *
2907  * DESCRIPTION: set antibanding value from user setting
2908  *
2909  * PARAMETERS :
2910  *   @params  : user setting parameters
2911  *
2912  * RETURN     : int32_t type of status
2913  *              NO_ERROR  -- success
2914  *              none-zero failure code
2915  *==========================================================================*/
setAntibanding(const QCameraParameters & params)2916 int32_t QCameraParameters::setAntibanding(const QCameraParameters& params)
2917 {
2918     const char *str = params.get(KEY_ANTIBANDING);
2919     const char *prev_str = get(KEY_ANTIBANDING);
2920     if (str != NULL) {
2921         if (prev_str == NULL ||
2922             strcmp(str, prev_str) != 0) {
2923             return setAntibanding(str);
2924         }
2925     }
2926     return NO_ERROR;
2927 }
2928 
2929 /*===========================================================================
2930  * FUNCTION   : setStatsDebugMask
2931  *
2932  * DESCRIPTION: get the value from persist file in Stats module that will
2933  *              control funtionality in the module
2934  *
2935  * PARAMETERS : none
2936  *
2937  * RETURN     : int32_t type of status
2938  *              NO_ERROR  -- success
2939  *              none-zero failure code
2940  *==========================================================================*/
setStatsDebugMask()2941 int32_t QCameraParameters::setStatsDebugMask()
2942 {
2943     uint32_t mask = 0;
2944     char value[PROPERTY_VALUE_MAX];
2945 
2946     property_get("persist.camera.stats.debug.mask", value, "0");
2947     mask = (uint32_t)atoi(value);
2948 
2949     LOGH("ctrl mask :%d", mask);
2950 
2951     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_STATS_DEBUG_MASK, mask)) {
2952         return BAD_VALUE;
2953     }
2954 
2955     return NO_ERROR;
2956 }
2957 
2958 /*===========================================================================
2959  * FUNCTION   : setPAAF
2960  *
2961  * DESCRIPTION: get the value from persist file in Stats module that will
2962  *              control the preview assisted AF in the module
2963  *
2964  * PARAMETERS : none
2965  *
2966  * RETURN     : int32_t type of status
2967  *              NO_ERROR  -- success
2968  *              none-zero failure code
2969  *==========================================================================*/
setPAAF()2970 int32_t QCameraParameters::setPAAF()
2971 {
2972     uint32_t paaf = 0;
2973     char value[PROPERTY_VALUE_MAX];
2974 
2975     property_get("persist.camera.stats.af.paaf", value, "1");
2976     paaf = (uint32_t)atoi(value);
2977 
2978     LOGH("PAAF is: %s", paaf ? "ON": "OFF");
2979 
2980     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_STATS_AF_PAAF, paaf)) {
2981         return BAD_VALUE;
2982     }
2983 
2984     return NO_ERROR;
2985 }
2986 
2987 /*===========================================================================
2988  * FUNCTION   : setSceneDetect
2989  *
2990  * DESCRIPTION: set scenen detect value from user setting
2991  *
2992  * PARAMETERS :
2993  *   @params  : user setting parameters
2994  *
2995  * RETURN     : int32_t type of status
2996  *              NO_ERROR  -- success
2997  *              none-zero failure code
2998  *==========================================================================*/
setSceneDetect(const QCameraParameters & params)2999 int32_t QCameraParameters::setSceneDetect(const QCameraParameters& params)
3000 {
3001     const char *str = params.get(KEY_QC_SCENE_DETECT);
3002     const char *prev_str = get(KEY_QC_SCENE_DETECT);
3003     if (str != NULL) {
3004         if (prev_str == NULL ||
3005             strcmp(str, prev_str) != 0) {
3006             return setSceneDetect(str);
3007         }
3008     }
3009     return NO_ERROR;
3010 }
3011 
3012 /*===========================================================================
3013  * FUNCTION   : setVideoHDR
3014  *
3015  * DESCRIPTION: set video HDR value from user setting
3016  *
3017  * PARAMETERS :
3018  *   @params  : user setting parameters
3019  *
3020  * RETURN     : int32_t type of status
3021  *              NO_ERROR  -- success
3022  *              none-zero failure code
3023  *==========================================================================*/
setVideoHDR(const QCameraParameters & params)3024 int32_t QCameraParameters::setVideoHDR(const QCameraParameters& params)
3025 {
3026     const char *str = params.get(KEY_QC_VIDEO_HDR);
3027     const char *prev_str = get(KEY_QC_VIDEO_HDR);
3028     if (str != NULL) {
3029         if (prev_str == NULL ||
3030             strcmp(str, prev_str) != 0) {
3031             return setVideoHDR(str);
3032         }
3033     }
3034     return NO_ERROR;
3035 }
3036 
3037 /*===========================================================================
3038  * FUNCTION   : setVtEnable
3039  *
3040  * DESCRIPTION: set vt Time Stamp enable from user setting
3041  *
3042  * PARAMETERS :
3043  *   @params  : user setting parameters
3044  *
3045  * RETURN     : int32_t type of status
3046  *              NO_ERROR  -- success
3047  *              none-zero failure code
3048  *==========================================================================*/
setVtEnable(const QCameraParameters & params)3049 int32_t QCameraParameters::setVtEnable(const QCameraParameters& params)
3050 {
3051     const char *str = params.get(KEY_QC_VT_ENABLE);
3052     const char *prev_str = get(KEY_QC_VT_ENABLE);
3053     if (str != NULL) {
3054         if (prev_str == NULL ||
3055             strcmp(str, prev_str) != 0) {
3056             return setVtEnable(str);
3057         }
3058     }
3059     return NO_ERROR;
3060 }
3061 
3062 /*===========================================================================
3063  * FUNCTION   : setFaceRecognition
3064  *
3065  * DESCRIPTION: set face recognition mode from user setting
3066  *
3067  * PARAMETERS :
3068  *   @params  : user setting parameters
3069  *
3070  * RETURN     : int32_t type of status
3071  *              NO_ERROR  -- success
3072  *              none-zero failure code
3073  *==========================================================================*/
setFaceRecognition(const QCameraParameters & params)3074 int32_t QCameraParameters::setFaceRecognition(const QCameraParameters& params)
3075 {
3076     const char *str = params.get(KEY_QC_FACE_RECOGNITION);
3077     const char *prev_str = get(KEY_QC_FACE_RECOGNITION);
3078     if (str != NULL) {
3079         if (prev_str == NULL ||
3080             strcmp(str, prev_str) != 0) {
3081             uint32_t maxFaces = (uint32_t)params.getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
3082             return setFaceRecognition(str, maxFaces);
3083         }
3084     }
3085     return NO_ERROR;
3086 }
3087 
3088 /*===========================================================================
3089  * FUNCTION   : setZoom
3090  *
3091  * DESCRIPTION: set zoom value from user setting
3092  *
3093  * PARAMETERS :
3094  *   @params  : user setting parameters
3095  *
3096  * RETURN     : int32_t type of status
3097  *              NO_ERROR  -- success
3098  *              none-zero failure code
3099  *==========================================================================*/
setZoom(const QCameraParameters & params)3100 int32_t QCameraParameters::setZoom(const QCameraParameters& params)
3101 {
3102     if ((m_pCapability->zoom_supported == 0 ||
3103          m_pCapability->zoom_ratio_tbl_cnt == 0)) {
3104         LOGH("no zoom support");
3105         return NO_ERROR;
3106     }
3107 
3108     int zoomLevel = params.getInt(KEY_ZOOM);
3109     mParmZoomLevel = zoomLevel;
3110     if ((zoomLevel < 0) || (zoomLevel >= (int)m_pCapability->zoom_ratio_tbl_cnt)) {
3111         LOGE("invalid value %d out of (%d, %d)",
3112                zoomLevel,
3113               0, m_pCapability->zoom_ratio_tbl_cnt-1);
3114         return BAD_VALUE;
3115     }
3116 
3117     int prevZoomLevel = getInt(KEY_ZOOM);
3118     if (prevZoomLevel == zoomLevel) {
3119         LOGD("No value change in zoom %d %d", prevZoomLevel, zoomLevel);
3120         m_bZoomChanged = false;
3121         return NO_ERROR;
3122     }
3123     m_bZoomChanged = true;
3124 
3125     return setZoom(zoomLevel);
3126 }
3127 
3128 /*===========================================================================
3129  * FUNCTION   : setISOValue
3130  *
3131  * DESCRIPTION: set ISO value from user setting
3132  *
3133  * PARAMETERS :
3134  *   @params  : user setting parameters
3135  *
3136  * RETURN     : int32_t type of status
3137  *              NO_ERROR  -- success
3138  *              none-zero failure code
3139  *==========================================================================*/
setISOValue(const QCameraParameters & params)3140 int32_t  QCameraParameters::setISOValue(const QCameraParameters& params)
3141 {
3142     const char *str = params.get(KEY_QC_ISO_MODE);
3143     const char *prev_str = get(KEY_QC_ISO_MODE);
3144 
3145     if(getManualCaptureMode()) {
3146         char iso_val[PROPERTY_VALUE_MAX];
3147 
3148         property_get("persist.camera.iso", iso_val, "");
3149         if (strlen(iso_val) > 0) {
3150             if (prev_str == NULL ||
3151                     strcmp(iso_val, prev_str) != 0) {
3152                 return setISOValue(iso_val);
3153             }
3154         }
3155     } else if (str != NULL) {
3156         if (prev_str == NULL ||
3157             strcmp(str, prev_str) != 0) {
3158             return setISOValue(str);
3159         }
3160     }
3161     return NO_ERROR;
3162 }
3163 
3164 /*===========================================================================
3165  * FUNCTION   : setContinuousISO
3166  *
3167  * DESCRIPTION: set ISO value from user setting
3168  *
3169  * PARAMETERS :
3170  *   @params  : user setting parameters
3171  *
3172  * RETURN     : int32_t type of status
3173  *              NO_ERROR  -- success
3174  *              none-zero failure code
3175  *==========================================================================*/
setContinuousISO(const char * isoValue)3176 int32_t  QCameraParameters::setContinuousISO(const char *isoValue)
3177 {
3178     char iso[PROPERTY_VALUE_MAX];
3179     int32_t continous_iso = 0;
3180 
3181     // Check if continuous ISO is set through setproperty
3182     property_get("persist.camera.continuous.iso", iso, "");
3183     if (strlen(iso) > 0) {
3184         continous_iso = atoi(iso);
3185     } else {
3186         continous_iso = atoi(isoValue);
3187     }
3188 
3189     if ((continous_iso >= 0) &&
3190             (continous_iso <= m_pCapability->sensitivity_range.max_sensitivity)) {
3191         LOGH("Setting continuous ISO value %d", continous_iso);
3192         updateParamEntry(KEY_QC_CONTINUOUS_ISO, isoValue);
3193 
3194         cam_intf_parm_manual_3a_t iso_settings;
3195         memset(&iso_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
3196         iso_settings.previewOnly = FALSE;
3197         iso_settings.value = continous_iso;
3198         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ISO, iso_settings)) {
3199             return BAD_VALUE;
3200         }
3201         return NO_ERROR;
3202     }
3203     LOGE("Invalid iso value: %d", continous_iso);
3204     return BAD_VALUE;
3205 }
3206 
3207 /*===========================================================================
3208  * FUNCTION   : setExposureTime
3209  *
3210  * DESCRIPTION: set exposure time from user setting
3211  *
3212  * PARAMETERS :
3213  *   @params  : user setting parameters
3214  *
3215  * RETURN     : int32_t type of status
3216  *              NO_ERROR  -- success
3217  *              none-zero failure code
3218  *==========================================================================*/
setExposureTime(const QCameraParameters & params)3219 int32_t  QCameraParameters::setExposureTime(const QCameraParameters& params)
3220 {
3221     const char *str = params.get(KEY_QC_EXPOSURE_TIME);
3222     const char *prev_str = get(KEY_QC_EXPOSURE_TIME);
3223     if (str != NULL) {
3224         if (prev_str == NULL ||
3225                 strcmp(str, prev_str) != 0) {
3226             return setExposureTime(str);
3227         }
3228     } else if(getManualCaptureMode()) {
3229         char expTime[PROPERTY_VALUE_MAX];
3230 
3231         property_get("persist.camera.exposure.time", expTime, "");
3232         if (strlen(expTime) > 0) {
3233             if (prev_str == NULL ||
3234                     strcmp(expTime, prev_str) != 0) {
3235                 return setExposureTime(expTime);
3236             }
3237         }
3238     }
3239 
3240     return NO_ERROR;
3241 }
3242 
3243 /*===========================================================================
3244  * FUNCTION   : setVideoRotation
3245  *
3246  * DESCRIPTION: set rotation value from user setting
3247  *
3248  * PARAMETERS :
3249  *   @params  : user setting parameters
3250  *
3251  * RETURN     : int32_t type of status
3252  *              NO_ERROR  -- success
3253  *              none-zero failure code
3254  *==========================================================================*/
setVideoRotation(const QCameraParameters & params)3255 int32_t QCameraParameters::setVideoRotation(const QCameraParameters& params)
3256 {
3257     const char *str = params.get(KEY_QC_VIDEO_ROTATION);
3258     if(str != NULL) {
3259         int value = lookupAttr(VIDEO_ROTATION_MODES_MAP,
3260                 PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP), str);
3261         if (value != NAME_NOT_FOUND) {
3262             updateParamEntry(KEY_QC_VIDEO_ROTATION, str);
3263             LOGL("setVideoRotation:  %s %d: ", str, value);
3264         } else {
3265             LOGE("Invalid rotation value: %d", value);
3266             return BAD_VALUE;
3267         }
3268 
3269     }
3270     return NO_ERROR;
3271 }
3272 
3273 /*===========================================================================
3274  * FUNCTION   : setRotation
3275  *
3276  * DESCRIPTION: set rotation value from user setting
3277  *
3278  * PARAMETERS :
3279  *   @params  : user setting parameters
3280  *
3281  * RETURN     : int32_t type of status
3282  *              NO_ERROR  -- success
3283  *              none-zero failure code
3284  *==========================================================================*/
setRotation(const QCameraParameters & params)3285 int32_t QCameraParameters::setRotation(const QCameraParameters& params)
3286 {
3287     int32_t rotation = params.getInt(KEY_ROTATION);
3288     if (rotation != -1) {
3289         if (rotation == 0 || rotation == 90 ||
3290             rotation == 180 || rotation == 270) {
3291             set(KEY_ROTATION, rotation);
3292 
3293             ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_META_JPEG_ORIENTATION,
3294                     rotation);
3295             mRotation = rotation;
3296         } else {
3297             LOGE("Invalid rotation value: %d", rotation);
3298             return BAD_VALUE;
3299         }
3300     }
3301     return NO_ERROR;
3302 }
3303 
3304 /*===========================================================================
3305  * FUNCTION   : setFlash
3306  *
3307  * DESCRIPTION: set flash mode from user setting
3308  *
3309  * PARAMETERS :
3310  *   @params  : user setting parameters
3311  *
3312  * RETURN     : int32_t type of status
3313  *              NO_ERROR  -- success
3314  *              none-zero failure code
3315  *==========================================================================*/
setFlash(const QCameraParameters & params)3316 int32_t QCameraParameters::setFlash(const QCameraParameters& params)
3317 {
3318     const char *str = params.get(KEY_FLASH_MODE);
3319     const char *prev_str = get(KEY_FLASH_MODE);
3320     if (str != NULL) {
3321         if (prev_str == NULL ||
3322             strcmp(str, prev_str) != 0) {
3323             return setFlash(str);
3324         }
3325     }
3326     return NO_ERROR;
3327 }
3328 
3329 /*===========================================================================
3330  * FUNCTION   : setAecLock
3331  *
3332  * DESCRIPTION: set AEC lock value from user setting
3333  *
3334  * PARAMETERS :
3335  *   @params  : user setting parameters
3336  *
3337  * RETURN     : int32_t type of status
3338  *              NO_ERROR  -- success
3339  *              none-zero failure code
3340  *==========================================================================*/
setAecLock(const QCameraParameters & params)3341 int32_t QCameraParameters::setAecLock(const QCameraParameters& params)
3342 {
3343     const char *str = params.get(KEY_AUTO_EXPOSURE_LOCK);
3344     const char *prev_str = get(KEY_AUTO_EXPOSURE_LOCK);
3345     if (str != NULL) {
3346         if (prev_str == NULL ||
3347             strcmp(str, prev_str) != 0) {
3348             return setAecLock(str);
3349         }
3350     }
3351     return NO_ERROR;
3352 }
3353 
3354 /*===========================================================================
3355  * FUNCTION   : setAwbLock
3356  *
3357  * DESCRIPTION: set AWB lock from user setting
3358  *
3359  * PARAMETERS :
3360  *   @params  : user setting parameters
3361  *
3362  * RETURN     : int32_t type of status
3363  *              NO_ERROR  -- success
3364  *              none-zero failure code
3365  *==========================================================================*/
setAwbLock(const QCameraParameters & params)3366 int32_t QCameraParameters::setAwbLock(const QCameraParameters& params)
3367 {
3368     const char *str = params.get(KEY_AUTO_WHITEBALANCE_LOCK);
3369     const char *prev_str = get(KEY_AUTO_WHITEBALANCE_LOCK);
3370     if (str != NULL) {
3371         if (prev_str == NULL ||
3372             strcmp(str, prev_str) != 0) {
3373             return setAwbLock(str);
3374         }
3375     }
3376     return NO_ERROR;
3377 }
3378 
3379 /*===========================================================================
3380  * FUNCTION   : setAutoHDR
3381  *
3382  * DESCRIPTION: Enable/disable auto HDR
3383  *
3384  * PARAMETERS :
3385  *   @params  : user setting parameters
3386  *
3387  * RETURN     : int32_t type of status
3388  *              NO_ERROR  -- success
3389  *              none-zero failure code
3390  *==========================================================================*/
setAutoHDR(const QCameraParameters & params)3391 int32_t QCameraParameters::setAutoHDR(const QCameraParameters& params)
3392 {
3393     const char *str = params.get(KEY_QC_AUTO_HDR_ENABLE);
3394     const char *prev_str = get(KEY_QC_AUTO_HDR_ENABLE);
3395     char prop[PROPERTY_VALUE_MAX];
3396 
3397     memset(prop, 0, sizeof(prop));
3398     property_get("persist.camera.auto.hdr.enable", prop, VALUE_DISABLE);
3399     if (str != NULL) {
3400        if (prev_str == NULL ||
3401            strcmp(str, prev_str) != 0) {
3402            LOGH("Auto HDR set to: %s", str);
3403            return updateParamEntry(KEY_QC_AUTO_HDR_ENABLE, str);
3404        }
3405     } else {
3406        if (prev_str == NULL ||
3407            strcmp(prev_str, prop) != 0 ) {
3408            LOGH("Auto HDR set to: %s", prop);
3409            updateParamEntry(KEY_QC_AUTO_HDR_ENABLE, prop);
3410        }
3411     }
3412 
3413        return NO_ERROR;
3414 }
3415 
3416 /*===========================================================================
3417 * FUNCTION   : isAutoHDREnabled
3418 *
3419 * DESCRIPTION: Query auto HDR status
3420 *
3421 * PARAMETERS : None
3422 *
3423 * RETURN     : bool true/false
3424 *==========================================================================*/
isAutoHDREnabled()3425 bool QCameraParameters::isAutoHDREnabled()
3426 {
3427     const char *str = get(KEY_QC_AUTO_HDR_ENABLE);
3428     if (str != NULL) {
3429         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
3430                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
3431         if (value == NAME_NOT_FOUND) {
3432             LOGE("Invalid Auto HDR value %s", str);
3433             return false;
3434         }
3435 
3436         LOGH("Auto HDR status is: %d", value);
3437         return value ? true : false;
3438     }
3439 
3440     LOGH("Auto HDR status not set!");
3441     return false;
3442 }
3443 
3444 /*===========================================================================
3445  * FUNCTION   : setMCEValue
3446  *
3447  * DESCRIPTION: set memory color enhancement value from user setting
3448  *
3449  * PARAMETERS :
3450  *   @params  : user setting parameters
3451  *
3452  * RETURN     : int32_t type of status
3453  *              NO_ERROR  -- success
3454  *              none-zero failure code
3455  *==========================================================================*/
setMCEValue(const QCameraParameters & params)3456 int32_t QCameraParameters::setMCEValue(const QCameraParameters& params)
3457 {
3458     const char *str = params.get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
3459     const char *prev_str = get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
3460     if (str != NULL) {
3461         if (prev_str == NULL ||
3462             strcmp(str, prev_str) != 0) {
3463             return setMCEValue(str);
3464         }
3465     }
3466     return NO_ERROR;
3467 }
3468 
3469 /*===========================================================================
3470  * FUNCTION   : setDISValue
3471  *
3472  * DESCRIPTION: enable/disable DIS from user setting
3473  *
3474  * PARAMETERS :
3475  *   @params  : user setting parameters
3476  *
3477  * RETURN     : int32_t type of status
3478  *              NO_ERROR  -- success
3479  *              none-zero failure code
3480  *==========================================================================*/
setDISValue(const QCameraParameters & params)3481 int32_t QCameraParameters::setDISValue(const QCameraParameters& params)
3482 {
3483     const char *str = params.get(KEY_QC_DIS);
3484     const char *prev_str = get(KEY_QC_DIS);
3485     if (str != NULL) {
3486         if (prev_str == NULL ||
3487             strcmp(str, prev_str) != 0) {
3488             return setDISValue(str);
3489         }
3490     }
3491     return NO_ERROR;
3492 }
3493 
3494 /*===========================================================================
3495  * FUNCTION   : setLensShadeValue
3496  *
3497  * DESCRIPTION: set lens shade value from user setting
3498  *
3499  * PARAMETERS :
3500  *   @params  : user setting parameters
3501  *
3502  * RETURN     : int32_t type of status
3503  *              NO_ERROR  -- success
3504  *              none-zero failure code
3505  *==========================================================================*/
setLensShadeValue(const QCameraParameters & params)3506 int32_t QCameraParameters::setLensShadeValue(const QCameraParameters& params)
3507 {
3508     const char *str = params.get(KEY_QC_LENSSHADE);
3509     const char *prev_str = get(KEY_QC_LENSSHADE);
3510     if (str != NULL) {
3511         if (prev_str == NULL ||
3512             strcmp(str, prev_str) != 0) {
3513             return setLensShadeValue(str);
3514         }
3515     }
3516     return NO_ERROR;
3517 }
3518 
3519 /*===========================================================================
3520  * FUNCTION   : setFocusAreas
3521  *
3522  * DESCRIPTION: set focus 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  *==========================================================================*/
setFocusAreas(const QCameraParameters & params)3531 int32_t QCameraParameters::setFocusAreas(const QCameraParameters& params)
3532 {
3533     const char *str = params.get(KEY_FOCUS_AREAS);
3534 
3535     if (getRelatedCamSyncInfo()->mode == CAM_MODE_SECONDARY) {
3536         // Ignore focus areas for secondary camera
3537         LOGH("Ignore focus areas for secondary camera!! ");
3538         return NO_ERROR;
3539     }
3540     if (str != NULL) {
3541         int max_num_af_areas = getInt(KEY_MAX_NUM_FOCUS_AREAS);
3542         if(max_num_af_areas == 0) {
3543             LOGE("max num of AF area is 0, cannot set focus areas");
3544             return BAD_VALUE;
3545         }
3546 
3547         const char *prev_str = get(KEY_FOCUS_AREAS);
3548         if (prev_str == NULL ||
3549             strcmp(str, prev_str) != 0) {
3550             return setFocusAreas(str);
3551         }
3552     }
3553     return NO_ERROR;
3554 }
3555 
3556 /*===========================================================================
3557  * FUNCTION   : setMeteringAreas
3558  *
3559  * DESCRIPTION: set metering areas from user setting
3560  *
3561  * PARAMETERS :
3562  *   @params  : user setting parameters
3563  *
3564  * RETURN     : int32_t type of status
3565  *              NO_ERROR  -- success
3566  *              none-zero failure code
3567  *==========================================================================*/
setMeteringAreas(const QCameraParameters & params)3568 int32_t QCameraParameters::setMeteringAreas(const QCameraParameters& params)
3569 {
3570     const char *str = params.get(KEY_METERING_AREAS);
3571     if (str != NULL) {
3572         int max_num_mtr_areas = getInt(KEY_MAX_NUM_METERING_AREAS);
3573         if(max_num_mtr_areas == 0) {
3574             LOGE("max num of metering areas is 0, cannot set focus areas");
3575             return BAD_VALUE;
3576         }
3577 
3578         const char *prev_str = get(KEY_METERING_AREAS);
3579         if (prev_str == NULL ||
3580             strcmp(str, prev_str) != 0 ||
3581             (m_bNeedRestart == true)) {
3582             return setMeteringAreas(str);
3583         }
3584     }
3585     return NO_ERROR;
3586 }
3587 
3588 /*===========================================================================
3589  * FUNCTION   : setSceneMode
3590  *
3591  * DESCRIPTION: set scenen mode from user setting
3592  *
3593  * PARAMETERS :
3594  *   @params  : user setting parameters
3595  *
3596  * RETURN     : int32_t type of status
3597  *              NO_ERROR  -- success
3598  *              none-zero failure code
3599  *==========================================================================*/
setSceneMode(const QCameraParameters & params)3600 int32_t QCameraParameters::setSceneMode(const QCameraParameters& params)
3601 {
3602     const char *str = params.get(KEY_SCENE_MODE);
3603     const char *prev_str = get(KEY_SCENE_MODE);
3604     LOGH("str - %s, prev_str - %s", str, prev_str);
3605 
3606     // HDR & Recording are mutually exclusive and so disable HDR if recording hint is set
3607     if (m_bRecordingHint_new && m_bHDREnabled) {
3608         LOGH("Disable the HDR and set it to Auto");
3609         str = SCENE_MODE_AUTO;
3610         m_bLocalHDREnabled = true;
3611     } else if (!m_bRecordingHint_new && m_bLocalHDREnabled) {
3612         LOGH("Restore the HDR from Auto scene mode");
3613         str = SCENE_MODE_HDR;
3614         m_bLocalHDREnabled = false;
3615     }
3616 
3617     if (str != NULL) {
3618         if (prev_str == NULL ||
3619             strcmp(str, prev_str) != 0) {
3620 
3621             if(strcmp(str, SCENE_MODE_AUTO) == 0) {
3622                 m_bSceneTransitionAuto = true;
3623             }
3624             if (strcmp(str, SCENE_MODE_HDR) == 0) {
3625 
3626                 // If HDR is set from client  and the feature is not enabled in the backend, ignore it.
3627                 if (m_bHDRModeSensor && isSupportedSensorHdrSize(params)) {
3628                     m_bSensorHDREnabled = true;
3629                     m_bHDREnabled = false;
3630                     LOGH("Sensor HDR mode Enabled");
3631                 } else {
3632                     m_bHDREnabled = true;
3633                     LOGH("S/W HDR Enabled");
3634                 }
3635             } else {
3636                 m_bHDREnabled = false;
3637                 if (m_bSensorHDREnabled) {
3638                     m_bSensorHDREnabled = false;
3639                     m_bNeedRestart = true;
3640                     setSensorSnapshotHDR("off");
3641                 }
3642             }
3643 
3644             if (m_bSensorHDREnabled) {
3645                 setSensorSnapshotHDR("on");
3646                 m_bNeedRestart = true;
3647             } else if ((m_bHDREnabled) ||
3648                 ((prev_str != NULL) && (strcmp(prev_str, SCENE_MODE_HDR) == 0))) {
3649                 LOGH("scene mode changed between HDR and non-HDR, need restart");
3650                 m_bNeedRestart = true;
3651             }
3652 
3653             return setSceneMode(str);
3654         }
3655     }
3656     return NO_ERROR;
3657 }
3658 
3659 /*===========================================================================
3660  * FUNCTION   : setSelectableZoneAf
3661  *
3662  * DESCRIPTION: set selectable zone auto focus value from user setting
3663  *
3664  * PARAMETERS :
3665  *   @params  : user setting parameters
3666  *
3667  * RETURN     : int32_t type of status
3668  *              NO_ERROR  -- success
3669  *              none-zero failure code
3670  *==========================================================================*/
setSelectableZoneAf(const QCameraParameters & params)3671 int32_t QCameraParameters::setSelectableZoneAf(const QCameraParameters& params)
3672 {
3673     const char *str = params.get(KEY_QC_SELECTABLE_ZONE_AF);
3674     const char *prev_str = get(KEY_QC_SELECTABLE_ZONE_AF);
3675     if (str != NULL) {
3676         if (prev_str == NULL ||
3677             strcmp(str, prev_str) != 0) {
3678             return setSelectableZoneAf(str);
3679         }
3680     }
3681     return NO_ERROR;
3682 }
3683 
3684 /*===========================================================================
3685  * FUNCTION   : setAEBracket
3686  *
3687  * DESCRIPTION: set AE bracket from user setting
3688  *
3689  * PARAMETERS :
3690  *   @params  : user setting parameters
3691  *
3692  * RETURN     : int32_t type of status
3693  *              NO_ERROR  -- success
3694  *              none-zero failure code
3695  *==========================================================================*/
setAEBracket(const QCameraParameters & params)3696 int32_t QCameraParameters::setAEBracket(const QCameraParameters& params)
3697 {
3698     if (isHDREnabled()) {
3699         LOGH("scene mode is HDR, overwrite AE bracket setting to off");
3700         return setAEBracket(AE_BRACKET_OFF);
3701     }
3702 
3703     const char *expStr = params.get(KEY_QC_CAPTURE_BURST_EXPOSURE);
3704     if (NULL != expStr && strlen(expStr) > 0) {
3705         set(KEY_QC_CAPTURE_BURST_EXPOSURE, expStr);
3706     } else {
3707         char prop[PROPERTY_VALUE_MAX];
3708         memset(prop, 0, sizeof(prop));
3709         property_get("persist.capture.burst.exposures", prop, "");
3710         if (strlen(prop) > 0) {
3711             set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
3712         } else {
3713             remove(KEY_QC_CAPTURE_BURST_EXPOSURE);
3714         }
3715     }
3716 
3717     const char *str = params.get(KEY_QC_AE_BRACKET_HDR);
3718     const char *prev_str = get(KEY_QC_AE_BRACKET_HDR);
3719     if (str != NULL) {
3720         if (prev_str == NULL ||
3721             strcmp(str, prev_str) != 0) {
3722             return setAEBracket(str);
3723         }
3724     }
3725     return NO_ERROR;
3726 }
3727 
3728 /*===========================================================================
3729  * FUNCTION   : setAFBracket
3730  *
3731  * DESCRIPTION: set AF bracket from user setting
3732  *
3733  * PARAMETERS :
3734  *   @params  : user setting parameters
3735  *
3736  * RETURN     : int32_t type of status
3737  *              NO_ERROR  -- success
3738  *              none-zero failure code
3739  *==========================================================================*/
setAFBracket(const QCameraParameters & params)3740 int32_t QCameraParameters::setAFBracket(const QCameraParameters& params)
3741 {
3742     if ((m_pCapability->qcom_supported_feature_mask &
3743             (CAM_QCOM_FEATURE_REFOCUS | CAM_QCOM_FEATURE_UBIFOCUS)) == 0) {
3744         LOGH("AF Bracketing is not supported");
3745         return NO_ERROR;
3746     }
3747     const char *str = params.get(KEY_QC_AF_BRACKET);
3748     const char *prev_str = get(KEY_QC_AF_BRACKET);
3749     LOGH("str =%s & prev_str =%s", str, prev_str);
3750     if (str != NULL) {
3751         if (prev_str == NULL ||
3752             strcmp(str, prev_str) != 0) {
3753             m_bNeedRestart = true;
3754             return setAFBracket(str);
3755         }
3756     }
3757     return NO_ERROR;
3758 }
3759 
3760 /*===========================================================================
3761  * FUNCTION   : setReFocus
3762  *
3763  * DESCRIPTION: set refocus from user setting
3764  *
3765  * PARAMETERS :
3766  *   @params  : user setting parameters
3767  *
3768  * RETURN     : int32_t type of status
3769  *              NO_ERROR  -- success
3770  *              none-zero failure code
3771  *==========================================================================*/
setReFocus(const QCameraParameters & params)3772 int32_t QCameraParameters::setReFocus(const QCameraParameters& params)
3773 {
3774     if ((m_pCapability->qcom_supported_feature_mask &
3775             (CAM_QCOM_FEATURE_REFOCUS | CAM_QCOM_FEATURE_UBIFOCUS)) == 0) {
3776         LOGD("AF Bracketing is not supported");
3777         return NO_ERROR;
3778     }
3779     const char *str = params.get(KEY_QC_RE_FOCUS);
3780     const char *prev_str = get(KEY_QC_RE_FOCUS);
3781     LOGH("str =%s & prev_str =%s", str, prev_str);
3782     if (str != NULL) {
3783         if (prev_str == NULL ||
3784             strcmp(str, prev_str) != 0) {
3785             m_bNeedRestart = true;
3786             return setReFocus(str);
3787         }
3788     }
3789     return NO_ERROR;
3790 }
3791 
3792 /*===========================================================================
3793  * FUNCTION   : setChromaFlash
3794  *
3795  * DESCRIPTION: set chroma flash from user setting
3796  *
3797  * PARAMETERS :
3798  *   @params  : user setting parameters
3799  *
3800  * RETURN     : int32_t type of status
3801  *              NO_ERROR  -- success
3802  *              none-zero failure code
3803  *==========================================================================*/
setChromaFlash(const QCameraParameters & params)3804 int32_t QCameraParameters::setChromaFlash(const QCameraParameters& params)
3805 {
3806     if ((m_pCapability->qcom_supported_feature_mask &
3807         CAM_QCOM_FEATURE_CHROMA_FLASH) == 0) {
3808         LOGH("Chroma Flash is not supported");
3809         return NO_ERROR;
3810     }
3811     const char *str = params.get(KEY_QC_CHROMA_FLASH);
3812     const char *prev_str = get(KEY_QC_CHROMA_FLASH);
3813     LOGH("str =%s & prev_str =%s", str, prev_str);
3814     if (str != NULL) {
3815         if (prev_str == NULL ||
3816             strcmp(str, prev_str) != 0) {
3817             m_bNeedRestart = true;
3818             return setChromaFlash(str);
3819         }
3820     }
3821     return NO_ERROR;
3822 }
3823 
3824 /*===========================================================================
3825  * FUNCTION   : setOptiZoom
3826  *
3827  * DESCRIPTION: set opti zoom from user setting
3828  *
3829  * PARAMETERS :
3830  *   @params  : user setting parameters
3831  *
3832  * RETURN     : int32_t type of status
3833  *              NO_ERROR  -- success
3834  *              none-zero failure code
3835  *==========================================================================*/
setOptiZoom(const QCameraParameters & params)3836 int32_t QCameraParameters::setOptiZoom(const QCameraParameters& params)
3837 {
3838     if ((m_pCapability->qcom_supported_feature_mask &
3839         CAM_QCOM_FEATURE_OPTIZOOM) == 0){
3840         LOGH("Opti Zoom is not supported");
3841         return NO_ERROR;
3842     }
3843     const char *str = params.get(KEY_QC_OPTI_ZOOM);
3844     const char *prev_str = get(KEY_QC_OPTI_ZOOM);
3845     LOGH("str =%s & prev_str =%s", str, prev_str);
3846     if (str != NULL) {
3847         if (prev_str == NULL ||
3848             strcmp(str, prev_str) != 0) {
3849             m_bNeedRestart = true;
3850             return setOptiZoom(str);
3851         }
3852     }
3853     return NO_ERROR;
3854 }
3855 
3856 /*===========================================================================
3857  * FUNCTION   : setTruePortrait
3858  *
3859  * DESCRIPTION: set true portrait from user setting
3860  *
3861  * PARAMETERS :
3862  *   @params  : user setting parameters
3863  *
3864  * RETURN     : int32_t type of status
3865  *              NO_ERROR  -- success
3866  *              none-zero failure code
3867  *==========================================================================*/
setTruePortrait(const QCameraParameters & params)3868 int32_t QCameraParameters::setTruePortrait(const QCameraParameters& params)
3869 {
3870     if ((m_pCapability->qcom_supported_feature_mask &
3871             CAM_QCOM_FEATURE_TRUEPORTRAIT) == 0) {
3872         LOGD("True Portrait is not supported");
3873         return NO_ERROR;
3874     }
3875     const char *str = params.get(KEY_QC_TRUE_PORTRAIT);
3876     const char *prev_str = get(KEY_QC_TRUE_PORTRAIT);
3877     LOGH("str =%s & prev_str =%s", str, prev_str);
3878     if (str != NULL) {
3879         if (prev_str == NULL ||
3880             strcmp(str, prev_str) != 0) {
3881             return setTruePortrait(str);
3882         }
3883     }
3884     return NO_ERROR;
3885 }
3886 
3887 /*===========================================================================
3888  * FUNCTION   : setHDRMode
3889  *
3890  * DESCRIPTION: set HDR mode from user setting
3891  *
3892  * PARAMETERS :
3893  *   @params  : user setting parameters
3894  *
3895  * RETURN     : int32_t type of status
3896  *              NO_ERROR  -- success
3897  *              none-zero failure code
3898  *==========================================================================*/
setHDRMode(const QCameraParameters & params)3899 int32_t QCameraParameters::setHDRMode(const QCameraParameters& params)
3900 {
3901     const char *str = params.get(KEY_QC_HDR_MODE);
3902     const char *prev_str = get(KEY_QC_HDR_MODE);
3903     uint32_t supported_hdr_modes = m_pCapability->qcom_supported_feature_mask &
3904           (CAM_QCOM_FEATURE_SENSOR_HDR | CAM_QCOM_FEATURE_HDR);
3905 
3906     LOGH("str =%s & prev_str =%s", str, prev_str);
3907     if (str != NULL) {
3908         if ((CAM_QCOM_FEATURE_SENSOR_HDR == supported_hdr_modes) &&
3909                 (strncmp(str, HDR_MODE_SENSOR, strlen(HDR_MODE_SENSOR)))) {
3910             LOGH("Only sensor HDR is supported");
3911             return NO_ERROR;
3912         } else if  ((CAM_QCOM_FEATURE_HDR == supported_hdr_modes) &&
3913                 (strncmp(str, HDR_MODE_SENSOR, strlen(HDR_MODE_MULTI_FRAME)))) {
3914             LOGH("Only multi frame HDR is supported");
3915             return NO_ERROR;
3916         } else if (!supported_hdr_modes) {
3917             LOGH("HDR is not supported");
3918             return NO_ERROR;
3919         }
3920         if (prev_str == NULL ||
3921                 strcmp(str, prev_str) != 0) {
3922             return setHDRMode(str);
3923         }
3924     }
3925 
3926     return NO_ERROR;
3927 }
3928 
3929 /*===========================================================================
3930  * FUNCTION   : setHDRNeed1x
3931  *
3932  * DESCRIPTION: set HDR need 1x from user setting
3933  *
3934  * PARAMETERS :
3935  *   @params  : user setting parameters
3936  *
3937  * RETURN     : int32_t type of status
3938  *              NO_ERROR  -- success
3939  *              none-zero failure code
3940  *==========================================================================*/
setHDRNeed1x(const QCameraParameters & params)3941 int32_t QCameraParameters::setHDRNeed1x(const QCameraParameters& params)
3942 {
3943     const char *str = params.get(KEY_QC_HDR_NEED_1X);
3944     const char *prev_str = get(KEY_QC_HDR_NEED_1X);
3945 
3946     LOGH("str =%s & prev_str =%s", str, prev_str);
3947     if (str != NULL) {
3948         if (m_bHDRModeSensor) {
3949             LOGH("Only multi frame HDR supports 1x frame");
3950             return NO_ERROR;
3951         }
3952         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
3953             return setHDRNeed1x(str);
3954         }
3955     }
3956     return NO_ERROR;
3957 }
3958 
3959 /*===========================================================================
3960  * FUNCTION   : setQuadraCfaMode
3961  *
3962  * DESCRIPTION: enable or disable Quadra CFA mode
3963  *
3964  * PARAMETERS :
3965  *   @enable : enable: 1; disable 0
3966  *   @initCommit: if configuration list needs to be initialized and commited
3967  *
3968  * RETURN     : int32_t type of status
3969  *              NO_ERROR  -- success
3970  *              none-zero failure code
3971  *==========================================================================*/
setQuadraCfaMode(uint32_t enable,bool initCommit)3972 int32_t QCameraParameters::setQuadraCfaMode(uint32_t enable, bool initCommit) {
3973 
3974    int32_t rc = NO_ERROR;
3975 
3976     if (getQuadraCfa()) {
3977         if (enable) {
3978             setOfflineRAW(TRUE);
3979         } else  {
3980             setOfflineRAW(FALSE);
3981         }
3982         if (initCommit) {
3983             if (initBatchUpdate() < 0) {
3984                 LOGE("Failed to initialize group update table");
3985                 return FAILED_TRANSACTION;
3986             }
3987         }
3988         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_QUADRA_CFA, enable)) {
3989             LOGE("Failed to update Quadra CFA mode");
3990             return BAD_VALUE;
3991         }
3992         if (initCommit) {
3993             rc = commitSetBatch();
3994             if (rc != NO_ERROR) {
3995                 LOGE("Failed to commit Quadra CFA mode");
3996                 return rc;
3997             }
3998         }
3999         LOGI("Quadra CFA mode %d ", enable);
4000     }
4001     return rc;
4002 }
4003 
4004 /*===========================================================================
4005  * FUNCTION   : setQuadraCFA
4006  *
4007  * DESCRIPTION: set Quadra CFA mode
4008  *
4009  * PARAMETERS :
4010  *   @params  : user setting parameters
4011  *
4012  * RETURN     : int32_t type of status
4013  *              NO_ERROR  -- success
4014  *              none-zero failure code
4015  *==========================================================================*/
setQuadraCfa(const QCameraParameters & params)4016 int32_t QCameraParameters::setQuadraCfa(const QCameraParameters& params)
4017 {
4018 
4019     int32_t width = 0,height = 0;
4020     bool prev_quadracfa = getQuadraCfa();
4021     int32_t rc = NO_ERROR;
4022     int32_t value;
4023 
4024     if (!m_pCapability->is_remosaic_lib_present) {
4025         LOGD("Quadra CFA mode not supported");
4026         return rc;
4027     }
4028 
4029     /*Checking if the user selected dim is more than maximum dim supported by
4030     Quadra sensor in normal mode. If more then switch to Quadra CFA mode else
4031     remain in normal zsl mode */
4032     params.getPictureSize(&width, &height);
4033     if (width > m_pCapability->raw_dim[0].width ||
4034         height > m_pCapability->raw_dim[0].height) {
4035         LOGI("Quadra CFA mode selected");
4036         m_bQuadraCfa = TRUE;
4037     } else {
4038         LOGI("Quadra CFA mode not selected");
4039         m_bQuadraCfa = FALSE;
4040     }
4041     value = m_bQuadraCfa;
4042     if (prev_quadracfa == m_bQuadraCfa) {
4043         LOGD("No change in Quadra CFA mode");
4044     } else {
4045         if (m_bZslMode && m_bQuadraCfa) {
4046             m_bNeedRestart = TRUE;
4047             setZslMode(FALSE);
4048         } else {
4049             const char *str_val  = params.get(KEY_QC_ZSL);
4050             int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
4051                     str_val);
4052             if (value != NAME_NOT_FOUND && value) {
4053                 rc = setZslMode(value);
4054                 // ZSL mode changed, need restart preview
4055                 m_bNeedRestart = true;
4056             }
4057         }
4058         setReprocCount();
4059     }
4060     LOGH("Quadra CFA mode = %d", m_bQuadraCfa);
4061     return rc;
4062 }
4063 /*===========================================================================
4064  * FUNCTION   : setSeeMore
4065  *
4066  * DESCRIPTION: set see more (llvd) from user setting
4067  *
4068  * PARAMETERS :
4069  *   @params  : user setting parameters
4070  *
4071  * RETURN     : int32_t type of status
4072  *              NO_ERROR  -- success
4073  *              none-zero failure code
4074  *==========================================================================*/
setSeeMore(const QCameraParameters & params)4075 int32_t QCameraParameters::setSeeMore(const QCameraParameters& params)
4076 {
4077     if ((m_pCapability->qcom_supported_feature_mask &
4078             CAM_QCOM_FEATURE_LLVD) == 0) {
4079         LOGD("See more is not supported");
4080         return NO_ERROR;
4081     }
4082     const char *str = params.get(KEY_QC_SEE_MORE);
4083     const char *prev_str = get(KEY_QC_SEE_MORE);
4084     LOGH("str =%s & prev_str =%s", str, prev_str);
4085     if (str != NULL) {
4086         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
4087             m_bNeedRestart = true;
4088             return setSeeMore(str);
4089         }
4090     }
4091     return NO_ERROR;
4092 }
4093 
4094 /*===========================================================================
4095  * FUNCTION   : setNoiseReductionMode
4096  *
4097  * DESCRIPTION: set noise reduction mode from user setting
4098  *
4099  * PARAMETERS :
4100  *   @params  : user setting parameters
4101  *
4102  * RETURN     : int32_t type of status
4103  *              NO_ERROR  -- success
4104  *              none-zero failure code
4105  *==========================================================================*/
setNoiseReductionMode(const QCameraParameters & params)4106 int32_t QCameraParameters::setNoiseReductionMode(const QCameraParameters& params)
4107 {
4108     if ((m_pCapability->qcom_supported_feature_mask & CAM_QTI_FEATURE_SW_TNR) == 0) {
4109         LOGD("SW TNR is not supported");
4110         return NO_ERROR;
4111     }
4112     const char *str = params.get(KEY_QC_NOISE_REDUCTION_MODE);
4113     const char *prev_str = get(KEY_QC_NOISE_REDUCTION_MODE);
4114     LOGH("str =%s & prev_str =%s", str, prev_str);
4115     if (str != NULL) {
4116         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
4117             m_bNeedRestart = true;
4118             return setNoiseReductionMode(str);
4119         }
4120     }
4121     return NO_ERROR;
4122 }
4123 
4124 /*===========================================================================
4125  * FUNCTION   : setStillMore
4126  *
4127  * DESCRIPTION: set stillmore from user setting
4128  *
4129  * PARAMETERS :
4130  *   @params  : user setting parameters
4131  *
4132  * RETURN     : int32_t type of status
4133  *              NO_ERROR  -- success
4134  *              none-zero failure code
4135  *==========================================================================*/
setStillMore(const QCameraParameters & params)4136 int32_t QCameraParameters::setStillMore(const QCameraParameters& params)
4137 {
4138     if ((m_pCapability->qcom_supported_feature_mask &
4139             CAM_QCOM_FEATURE_STILLMORE) == 0) {
4140         LOGD("Stillmore is not supported");
4141         return NO_ERROR;
4142     }
4143     const char *str = params.get(KEY_QC_STILL_MORE);
4144     const char *prev_str = get(KEY_QC_STILL_MORE);
4145     LOGH("str =%s & prev_str =%s", str, prev_str);
4146     if (str != NULL) {
4147         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
4148             m_bNeedRestart = true;
4149             return setStillMore(str);
4150         }
4151     }
4152     return NO_ERROR;
4153 }
4154 
4155 #ifdef TARGET_TS_MAKEUP
4156 
4157 /*===========================================================================
4158  * FUNCTION   : setTsMakeup
4159  *
4160  * DESCRIPTION: set setTsMakeup from user setting
4161  *
4162  * PARAMETERS :
4163  *   @params  : user setting parameters
4164  *
4165  * RETURN     : int32_t type of status
4166  *              NO_ERROR  -- success
4167  *              none-zero failure code
4168  *==========================================================================*/
setTsMakeup(const QCameraParameters & params)4169 int32_t QCameraParameters::setTsMakeup(const QCameraParameters& params)
4170 {
4171     const char *str = params.get(KEY_TS_MAKEUP);
4172     const char *prev_str = get(KEY_TS_MAKEUP);
4173     LOGH("str =%s & prev_str =%s", str, prev_str);
4174     if (str != NULL) {
4175         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
4176             m_bNeedRestart = true;
4177             set(KEY_TS_MAKEUP, str);
4178         }
4179         str = params.get(KEY_TS_MAKEUP_WHITEN);
4180         prev_str = get(KEY_TS_MAKEUP_WHITEN);
4181         if (str != NULL) {
4182             if (prev_str == NULL || strcmp(str, prev_str) != 0) {
4183                 set(KEY_TS_MAKEUP_WHITEN, str);
4184             }
4185         }
4186         str = params.get(KEY_TS_MAKEUP_CLEAN);
4187         prev_str = get(KEY_TS_MAKEUP_CLEAN);
4188         if (str != NULL) {
4189             if (prev_str == NULL || strcmp(str, prev_str) != 0) {
4190                 set(KEY_TS_MAKEUP_CLEAN, str);
4191             }
4192         }
4193     }
4194     return NO_ERROR;
4195 }
4196 
4197 #endif
4198 
4199 /*===========================================================================
4200  * FUNCTION   : setRedeyeReduction
4201  *
4202  * DESCRIPTION: set red eye reduction setting from user setting
4203  *
4204  * PARAMETERS :
4205  *   @params  : user setting parameters
4206  *
4207  * RETURN     : int32_t type of status
4208  *              NO_ERROR  -- success
4209  *              none-zero failure code
4210  *==========================================================================*/
setRedeyeReduction(const QCameraParameters & params)4211 int32_t QCameraParameters::setRedeyeReduction(const QCameraParameters& params)
4212 {
4213     const char *str = params.get(KEY_QC_REDEYE_REDUCTION);
4214     const char *prev_str = get(KEY_QC_REDEYE_REDUCTION);
4215     if (str != NULL) {
4216         if (prev_str == NULL ||
4217             strcmp(str, prev_str) != 0) {
4218             return setRedeyeReduction(str);
4219         }
4220     }
4221     return NO_ERROR;
4222 }
4223 
4224 /*===========================================================================
4225  * FUNCTION   : setGpsLocation
4226  *
4227  * DESCRIPTION: set GPS location information from user setting
4228  *
4229  * PARAMETERS :
4230  *   @params  : user setting parameters
4231  *
4232  * RETURN     : int32_t type of status
4233  *              NO_ERROR  -- success
4234  *              none-zero failure code
4235  *==========================================================================*/
setGpsLocation(const QCameraParameters & params)4236 int32_t QCameraParameters::setGpsLocation(const QCameraParameters& params)
4237 {
4238     const char *method = params.get(KEY_GPS_PROCESSING_METHOD);
4239     if (method) {
4240         set(KEY_GPS_PROCESSING_METHOD, method);
4241     }else {
4242         remove(KEY_GPS_PROCESSING_METHOD);
4243     }
4244 
4245     const char *latitude = params.get(KEY_GPS_LATITUDE);
4246     if (latitude) {
4247         set(KEY_GPS_LATITUDE, latitude);
4248     }else {
4249         remove(KEY_GPS_LATITUDE);
4250     }
4251 
4252     const char *latitudeRef = params.get(KEY_QC_GPS_LATITUDE_REF);
4253     if (latitudeRef) {
4254         set(KEY_QC_GPS_LATITUDE_REF, latitudeRef);
4255     }else {
4256         remove(KEY_QC_GPS_LATITUDE_REF);
4257     }
4258 
4259     const char *longitude = params.get(KEY_GPS_LONGITUDE);
4260     if (longitude) {
4261         set(KEY_GPS_LONGITUDE, longitude);
4262     }else {
4263         remove(KEY_GPS_LONGITUDE);
4264     }
4265 
4266     const char *longitudeRef = params.get(KEY_QC_GPS_LONGITUDE_REF);
4267     if (longitudeRef) {
4268         set(KEY_QC_GPS_LONGITUDE_REF, longitudeRef);
4269     }else {
4270         remove(KEY_QC_GPS_LONGITUDE_REF);
4271     }
4272 
4273     const char *altitudeRef = params.get(KEY_QC_GPS_ALTITUDE_REF);
4274     if (altitudeRef) {
4275         set(KEY_QC_GPS_ALTITUDE_REF, altitudeRef);
4276     }else {
4277         remove(KEY_QC_GPS_ALTITUDE_REF);
4278     }
4279 
4280     const char *altitude = params.get(KEY_GPS_ALTITUDE);
4281     if (altitude) {
4282         set(KEY_GPS_ALTITUDE, altitude);
4283     }else {
4284         remove(KEY_GPS_ALTITUDE);
4285     }
4286 
4287     const char *status = params.get(KEY_QC_GPS_STATUS);
4288     if (status) {
4289         set(KEY_QC_GPS_STATUS, status);
4290     } else {
4291         remove(KEY_QC_GPS_STATUS);
4292     }
4293 
4294     const char *timestamp = params.get(KEY_GPS_TIMESTAMP);
4295     if (timestamp) {
4296         set(KEY_GPS_TIMESTAMP, timestamp);
4297     }else {
4298         remove(KEY_GPS_TIMESTAMP);
4299     }
4300     return NO_ERROR;
4301 }
4302 
4303 /*===========================================================================
4304  * FUNCTION   : setNumOfSnapshot
4305  *
4306  * DESCRIPTION: set number of snapshot per shutter from user setting
4307  *
4308  * PARAMETERS : none
4309  *
4310  * RETURN     : int32_t type of status
4311  *              NO_ERROR  -- success
4312  *              none-zero failure code
4313  *==========================================================================*/
setNumOfSnapshot()4314 int32_t QCameraParameters::setNumOfSnapshot()
4315 {
4316     int nBurstNum = 1;
4317     int nExpnum = 0;
4318 
4319     const char *bracket_str = get(KEY_QC_AE_BRACKET_HDR);
4320     if (bracket_str != NULL && strlen(bracket_str) > 0) {
4321         int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
4322                 bracket_str);
4323         switch (value) {
4324         case CAM_EXP_BRACKETING_ON:
4325             {
4326                 nExpnum = 0;
4327                 const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
4328                 if ((str_val != NULL) && (strlen(str_val) > 0)) {
4329                     char prop[PROPERTY_VALUE_MAX];
4330                     memset(prop, 0, sizeof(prop));
4331                     strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
4332                     char *saveptr = NULL;
4333                     char *token = strtok_r(prop, ",", &saveptr);
4334                     while (token != NULL) {
4335                         token = strtok_r(NULL, ",", &saveptr);
4336                         nExpnum++;
4337                     }
4338                 }
4339                 if (nExpnum == 0) {
4340                     nExpnum = 1;
4341                 }
4342             }
4343             break;
4344         default:
4345             nExpnum = 1 + getNumOfExtraHDROutBufsIfNeeded();
4346             break;
4347         }
4348     }
4349 
4350     if (isUbiRefocus()) {
4351         nBurstNum = m_pCapability->refocus_af_bracketing_need.output_count + 1;
4352     }
4353 
4354     if (mActiveCameras == MM_CAMERA_DUAL_CAM && mbundledSnapshot) {
4355         int dualfov_snap_num = 1;
4356         char prop[PROPERTY_VALUE_MAX];
4357         memset(prop, 0, sizeof(prop));
4358         property_get("persist.camera.dualfov.jpegnum", prop, "1");
4359         dualfov_snap_num = atoi(prop);
4360 
4361         memset(prop, 0, sizeof(prop));
4362         property_get("persist.camera.halpp", prop, "0");
4363         int halpp_enabled = atoi(prop);
4364         if(halpp_enabled == 0) {
4365             dualfov_snap_num = MM_CAMERA_MAX_CAM_CNT;
4366         }
4367         dualfov_snap_num = (dualfov_snap_num == 0) ? 1 : dualfov_snap_num;
4368 
4369         set(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER, (nBurstNum * nExpnum * dualfov_snap_num));
4370         LOGH("nBurstNum = %d, nExpnum = %d snapshots = %d", nBurstNum, nExpnum,
4371                 getInt(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER));
4372     } else {
4373         set(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER, (nBurstNum * nExpnum));
4374         LOGH("nBurstNum = %d, nExpnum = %d snapshots = %d", nBurstNum, nExpnum,
4375                 (nBurstNum * nExpnum * MM_CAMERA_MAX_CAM_CNT));
4376     }
4377 
4378     return NO_ERROR;
4379 }
4380 
4381 /*===========================================================================
4382  * FUNCTION   : setRecordingHint
4383  *
4384  * DESCRIPTION: set recording hint value from user setting
4385  *
4386  * PARAMETERS :
4387  *   @params  : user setting parameters
4388  *
4389  * RETURN     : int32_t type of status
4390  *              NO_ERROR  -- success
4391  *              none-zero failure code
4392  *==========================================================================*/
setRecordingHint(const QCameraParameters & params)4393 int32_t QCameraParameters::setRecordingHint(const QCameraParameters& params)
4394 {
4395     const char * str = params.get(KEY_RECORDING_HINT);
4396     const char *prev_str = get(KEY_RECORDING_HINT);
4397     if (str != NULL) {
4398         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
4399             int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
4400                     str);
4401             if(value != NAME_NOT_FOUND){
4402                 updateParamEntry(KEY_RECORDING_HINT, str);
4403                 setRecordingHintValue(value);
4404                 if (getFaceDetectionOption() == true) {
4405                     if (!fdModeInVideo()) {
4406                         setFaceDetection(value > 0 ? false : true, false);
4407                     } else {
4408                         setFaceDetection(true, false);
4409                     }
4410                 }
4411                 if (m_bDISEnabled) {
4412                     LOGH("Setting DIS value again");
4413                     setDISValue(VALUE_ENABLE);
4414                 }
4415                 return NO_ERROR;
4416             } else {
4417                 LOGE("Invalid recording hint value: %s", str);
4418                 return BAD_VALUE;
4419             }
4420         }
4421     }
4422     return NO_ERROR;
4423 }
4424 
4425 /*===========================================================================
4426  * FUNCTION   : setNoDisplayMode
4427  *
4428  * DESCRIPTION: set no display mode from user setting
4429  *
4430  * PARAMETERS :
4431  *   @params  : user setting parameters
4432  *
4433  * RETURN     : int32_t type of status
4434  *              NO_ERROR  -- success
4435  *              none-zero failure code
4436  *==========================================================================*/
setNoDisplayMode(const QCameraParameters & params)4437 int32_t QCameraParameters::setNoDisplayMode(const QCameraParameters& params)
4438 {
4439     const char *str_val  = params.get(KEY_QC_NO_DISPLAY_MODE);
4440     const char *prev_str = get(KEY_QC_NO_DISPLAY_MODE);
4441     char prop[PROPERTY_VALUE_MAX];
4442     LOGD("str_val: %s, prev_str: %s", str_val, prev_str);
4443 
4444     // Aux Camera Mode, set no display mode
4445     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
4446         if (!m_bNoDisplayMode) {
4447             set(KEY_QC_NO_DISPLAY_MODE, 1);
4448             m_bNoDisplayMode = true;
4449             m_bNeedRestart = true;
4450         }
4451         return NO_ERROR;
4452     }
4453 
4454     if(str_val && strlen(str_val) > 0) {
4455         if (prev_str == NULL || strcmp(str_val, prev_str) != 0) {
4456             m_bNoDisplayMode = atoi(str_val);
4457             set(KEY_QC_NO_DISPLAY_MODE, str_val);
4458             m_bNeedRestart = true;
4459         }
4460     } else {
4461         memset(prop, 0, sizeof(prop));
4462         property_get("persist.camera.no-display", prop, "0");
4463         m_bNoDisplayMode = atoi(prop);
4464     }
4465     LOGH("Param m_bNoDisplayMode = %d", m_bNoDisplayMode);
4466     return NO_ERROR;
4467 }
4468 
4469 /*===========================================================================
4470  * FUNCTION   : setZslMode
4471  *
4472  * DESCRIPTION: set ZSL mode from user setting
4473  *
4474  * PARAMETERS :
4475  *   @params  : user setting parameters
4476  *
4477  * RETURN     : int32_t type of status
4478  *              NO_ERROR  -- success
4479  *              none-zero failure code
4480  *==========================================================================*/
setZslMode(const QCameraParameters & params)4481 int32_t QCameraParameters::setZslMode(const QCameraParameters& params)
4482 {
4483     const char *str_val  = params.get(KEY_QC_ZSL);
4484     const char *prev_val  = get(KEY_QC_ZSL);
4485     int32_t rc = NO_ERROR;
4486 
4487     if(m_bForceZslMode) {
4488         if (!m_bZslMode) {
4489             // Force ZSL mode to ON
4490             set(KEY_QC_ZSL, VALUE_ON);
4491             setZslMode(TRUE);
4492             LOGH("ZSL Mode forced to be enabled");
4493         }
4494     } else if (str_val != NULL) {
4495         if (prev_val == NULL || strcmp(str_val, prev_val) != 0) {
4496             int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
4497                     str_val);
4498             if (value != NAME_NOT_FOUND) {
4499                 set(KEY_QC_ZSL, str_val);
4500                 rc = setZslMode(value);
4501                 // ZSL mode changed, need restart preview
4502                 m_bNeedRestart = true;
4503             } else {
4504                 LOGE("Invalid ZSL mode value: %s", str_val);
4505                 rc = BAD_VALUE;
4506             }
4507         }
4508     }
4509     return rc;
4510 }
4511 
4512 /*===========================================================================
4513  * FUNCTION   : setZslMode
4514  *
4515  * DESCRIPTION: set ZSL mode from user setting
4516  *
4517  * PARAMETERS :
4518  *   @value  : ZSL mode value
4519  *
4520  * RETURN     : int32_t type of status
4521  *              NO_ERROR  -- success
4522  *              none-zero failure code
4523  *==========================================================================*/
setZslMode(bool value)4524 int32_t QCameraParameters::setZslMode(bool value)
4525 {
4526     int32_t rc = NO_ERROR;
4527     if(m_bForceZslMode) {
4528         if (!m_bZslMode) {
4529             // Force ZSL mode to ON
4530             set(KEY_QC_ZSL, VALUE_ON);
4531             m_bZslMode_new = true;
4532             m_bZslMode = true;
4533             m_bNeedRestart = true;
4534 
4535             int32_t value = m_bForceZslMode;
4536             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value)) {
4537                 rc = BAD_VALUE;
4538             }
4539 
4540             LOGI("ZSL Mode forced to be enabled");
4541         }
4542     } else {
4543         m_bZslMode_new = (value > 0)? true : false;
4544         LOGI("ZSL Mode  -> %s", m_bZslMode_new ? "Enabled" : "Disabled");
4545         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value)) {
4546             rc = BAD_VALUE;
4547         }
4548     }
4549     LOGH("enabled: %d rc = %d", m_bZslMode_new, rc);
4550     return rc;
4551 }
4552 
4553 /*===========================================================================
4554  * FUNCTION   : updateZSLModeValue
4555  *
4556  * DESCRIPTION: update zsl mode value locally and to daemon
4557  *
4558  * PARAMETERS :
4559  *   @value   : zsl mode value
4560  *
4561  * RETURN     : int32_t type of status
4562  *              NO_ERROR  -- success
4563  *              none-zero failure code
4564  *==========================================================================*/
updateZSLModeValue(bool value)4565 int32_t QCameraParameters::updateZSLModeValue(bool value)
4566 {
4567     int32_t rc = NO_ERROR;
4568     if(initBatchUpdate() < 0 ) {
4569         LOGE("Failed to initialize group update table");
4570         return BAD_TYPE;
4571     }
4572 
4573     rc = setZslMode(value);
4574     if (rc != NO_ERROR) {
4575         LOGE("Failed to ZSL value");
4576         return rc;
4577     }
4578 
4579     rc = commitSetBatch();
4580     if (rc != NO_ERROR) {
4581         LOGE("Failed to update recording hint");
4582         return rc;
4583     }
4584 
4585     return rc;
4586 }
4587 
4588 /*===========================================================================
4589  * FUNCTION   : setWaveletDenoise
4590  *
4591  * DESCRIPTION: set wavelet denoise value from user setting
4592  *
4593  * PARAMETERS :
4594  *   @params  : user setting parameters
4595  *
4596  * RETURN     : int32_t type of status
4597  *              NO_ERROR  -- success
4598  *              none-zero failure code
4599  *==========================================================================*/
setWaveletDenoise(const QCameraParameters & params)4600 int32_t QCameraParameters::setWaveletDenoise(const QCameraParameters& params)
4601 {
4602     const char *str = params.get(KEY_QC_DENOISE);
4603     const char *prev_str = get(KEY_QC_DENOISE);
4604     if (str != NULL) {
4605         if (prev_str == NULL ||
4606             strcmp(str, prev_str) != 0) {
4607             return setWaveletDenoise(str);
4608         }
4609     }
4610     return NO_ERROR;
4611 }
4612 
4613 /*===========================================================================
4614  * FUNCTION   : setTemporalDenoise
4615  *
4616  * DESCRIPTION: set temporal denoise value from properties
4617  *
4618  * PARAMETERS : none
4619  *
4620  * RETURN     : int32_t type of status
4621  *              NO_ERROR  -- success
4622  *              none-zero failure code
4623  *==========================================================================*/
setTemporalDenoise(const QCameraParameters & params)4624 int32_t QCameraParameters::setTemporalDenoise(const QCameraParameters& params)
4625 {
4626     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_CPP_TNR) == 0) {
4627         LOGH("TNR is not supported");
4628         return NO_ERROR;
4629     }
4630 
4631     const char *str = params.get(KEY_QC_TNR_MODE);
4632     const char *prev_str = get(KEY_QC_TNR_MODE);
4633     const char *video_str = params.get(KEY_QC_VIDEO_TNR_MODE);
4634     const char *video_prev_str = get(KEY_QC_VIDEO_TNR_MODE);
4635     char video_value[PROPERTY_VALUE_MAX];
4636     char preview_value[PROPERTY_VALUE_MAX];
4637     bool prev_video_tnr = m_bTNRVideoOn;
4638     bool prev_preview_tnr = m_bTNRPreviewOn;
4639     bool prev_snap_tnr = m_bTNRSnapshotOn;
4640 
4641     char value[PROPERTY_VALUE_MAX];
4642     memset(value, 0, sizeof(value));
4643     property_get("persist.camera.tnr_cds", value, "0");
4644     uint8_t tnr_cds = (uint8_t)atoi(value);
4645 
4646     if (m_bRecordingHint_new == true) {
4647         if (video_str) {
4648             if ((video_prev_str == NULL) || (strcmp(video_str, video_prev_str) != 0)) {
4649                 if (!strcmp(video_str, VALUE_ON)) {
4650                     m_bTNRVideoOn = true;
4651                     m_bTNRPreviewOn = true;
4652                 } else {
4653                     m_bTNRVideoOn = false;
4654                     m_bTNRPreviewOn = false;
4655                 }
4656                 updateParamEntry(KEY_QC_VIDEO_TNR_MODE, video_str);
4657             } else {
4658                 return NO_ERROR;
4659             }
4660         }
4661     } else {
4662         if (str) {
4663             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
4664                 if (!strcmp(str, VALUE_ON)) {
4665                     m_bTNRPreviewOn = true;
4666                 } else {
4667                     m_bTNRPreviewOn = false;
4668                 }
4669                 updateParamEntry(KEY_QC_TNR_MODE, str);
4670             } else {
4671                 return NO_ERROR;
4672             }
4673         }
4674     }
4675 
4676     //Read setprops only if UI is not present or disabled.
4677     if ((m_bRecordingHint_new == true)
4678             && ((video_str == NULL)
4679             || (strcmp(video_str, VALUE_ON)))) {
4680         memset(video_value, 0, sizeof(video_value));
4681         property_get("persist.camera.tnr.video", video_value, VALUE_OFF);
4682         if (!strcmp(video_value, VALUE_ON)) {
4683             m_bTNRVideoOn = true;
4684         } else {
4685             m_bTNRVideoOn = false;
4686         }
4687         updateParamEntry(KEY_QC_VIDEO_TNR_MODE, video_value);
4688 
4689         memset(preview_value, 0, sizeof(preview_value));
4690         property_get("persist.camera.tnr.preview", preview_value, VALUE_OFF);
4691         if (!strcmp(preview_value, VALUE_ON)) {
4692             m_bTNRPreviewOn = true;
4693         } else {
4694             m_bTNRPreviewOn = false;
4695         }
4696         updateParamEntry(KEY_QC_TNR_MODE, preview_value);
4697     } else if ((m_bRecordingHint_new != true)
4698             && ((str == NULL) || (strcmp(str, VALUE_ON)))) {
4699         memset(preview_value, 0, sizeof(preview_value));
4700         property_get("persist.camera.tnr.preview", preview_value, VALUE_OFF);
4701         if (!strcmp(preview_value, VALUE_ON)) {
4702             m_bTNRPreviewOn = true;
4703         } else {
4704             m_bTNRPreviewOn = false;
4705         }
4706         updateParamEntry(KEY_QC_TNR_MODE, preview_value);
4707     }
4708 
4709     memset(value, 0, sizeof(value));
4710     property_get("persist.camera.tnr.snapshot", value, VALUE_OFF);
4711     if (!strcmp(value, VALUE_ON)) {
4712         m_bTNRSnapshotOn = true;
4713         LOGD("TNR enabled for SNAPSHOT stream");
4714     } else {
4715         m_bTNRSnapshotOn = false;
4716     }
4717 
4718     cam_denoise_param_t temp;
4719     memset(&temp, 0, sizeof(temp));
4720     if (m_bTNRVideoOn || m_bTNRPreviewOn || m_bTNRSnapshotOn) {
4721         temp.denoise_enable = 1;
4722         temp.process_plates = getDenoiseProcessPlate(
4723                 CAM_INTF_PARM_TEMPORAL_DENOISE);
4724 
4725         if (!tnr_cds) {
4726             int32_t cds_mode = lookupAttr(CDS_MODES_MAP,
4727                     PARAM_MAP_SIZE(CDS_MODES_MAP), CDS_MODE_OFF);
4728 
4729             if (cds_mode != NAME_NOT_FOUND) {
4730                 updateParamEntry(KEY_QC_VIDEO_CDS_MODE, CDS_MODE_OFF);
4731                 if (m_bTNRPreviewOn) {
4732                     updateParamEntry(KEY_QC_CDS_MODE, CDS_MODE_OFF);
4733                 }
4734                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
4735                         CAM_INTF_PARM_CDS_MODE, cds_mode)) {
4736                     LOGE("Failed CDS MODE to update table");
4737                     return BAD_VALUE;
4738                 }
4739                 LOGD("CDS is set to = %s when TNR is enabled",
4740                          CDS_MODE_OFF);
4741                 mCds_mode = cds_mode;
4742             } else {
4743                 LOGE("Invalid argument for video CDS MODE %d",
4744                          cds_mode);
4745             }
4746         } else {
4747             LOGH("Enabled TNR with CDS");
4748         }
4749     }
4750 
4751     if ((m_bTNRVideoOn != prev_video_tnr)
4752             || (m_bTNRPreviewOn != prev_preview_tnr)
4753             || (prev_snap_tnr != m_bTNRSnapshotOn)) {
4754         LOGD("TNR enabled = %d, plates = %d",
4755                 temp.denoise_enable, temp.process_plates);
4756         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
4757                 CAM_INTF_PARM_TEMPORAL_DENOISE, temp)) {
4758             return BAD_VALUE;
4759         }
4760     }
4761 
4762     return NO_ERROR;
4763 }
4764 
4765 /*===========================================================================
4766  * FUNCTION   : setCameraMode
4767  *
4768  * DESCRIPTION: set camera mode from user setting
4769  *
4770  * PARAMETERS :
4771  *   @params  : user setting parameters
4772  *
4773  * RETURN     : int32_t type of status
4774  *              NO_ERROR  -- success
4775  *              none-zero failure code
4776  *==========================================================================*/
setCameraMode(const QCameraParameters & params)4777 int32_t QCameraParameters::setCameraMode(const QCameraParameters& params)
4778 {
4779     const char *str = params.get(KEY_QC_CAMERA_MODE);
4780     if (str != NULL) {
4781         set(KEY_QC_CAMERA_MODE, str);
4782     } else {
4783         remove(KEY_QC_CAMERA_MODE);
4784     }
4785     return NO_ERROR;
4786 }
4787 
4788 /*===========================================================================
4789  * FUNCTION   : setSceneSelectionMode
4790  *
4791  * DESCRIPTION: set scene selection mode from user setting
4792  *
4793  * PARAMETERS :
4794  *   @params  : user setting parameters
4795  *
4796  * RETURN     : int32_t type of status
4797  *              NO_ERROR  -- success
4798  *              none-zero failure code
4799  *==========================================================================*/
setSceneSelectionMode(const QCameraParameters & params)4800 int32_t QCameraParameters::setSceneSelectionMode(const QCameraParameters& params)
4801 {
4802     const char *str = params.get(KEY_QC_SCENE_SELECTION);
4803     const char *prev_str = get(KEY_QC_SCENE_SELECTION);
4804     if (NULL != str) {
4805         if ((NULL == prev_str) || (strcmp(str, prev_str) != 0)) {
4806             int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
4807                     PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
4808             if (value != NAME_NOT_FOUND) {
4809                 LOGD("Setting selection value %s", str);
4810                 if (value && m_bZslMode_new) {
4811                     updateParamEntry(KEY_QC_SCENE_SELECTION, str);
4812                     m_bNeedRestart = true;
4813                     m_bSceneSelection = true;
4814                 } else if (!value) {
4815                     updateParamEntry(KEY_QC_SCENE_SELECTION, str);
4816                     m_bNeedRestart = true;
4817                     m_bSceneSelection = false;
4818                 } else {
4819                     LOGE("Trying to enable scene selection in non ZSL mode!!!");
4820                     return BAD_VALUE;
4821                 }
4822             } else {
4823                 LOGE("Trying to configure invalid scene selection value: %s",
4824                         str);
4825                 return BAD_VALUE;
4826             }
4827         }
4828     }
4829 
4830     return NO_ERROR;
4831 }
4832 
4833 /*===========================================================================
4834  * FUNCTION   : setSelectedScene
4835  *
4836  * DESCRIPTION: select specific scene
4837  *
4838  * PARAMETERS :
4839  *   @scene   : scene mode
4840  *
4841  * RETURN     : int32_t type of status
4842  *              NO_ERROR  -- success
4843  *              none-zero failure code
4844  *==========================================================================*/
setSelectedScene(cam_scene_mode_type scene)4845 int32_t QCameraParameters::setSelectedScene(cam_scene_mode_type scene)
4846 {
4847     Mutex::Autolock l(m_SceneSelectLock);
4848     m_SelectedScene = scene;
4849     return NO_ERROR;
4850 }
4851 
4852 /*===========================================================================
4853  * FUNCTION   : getSelectedScene
4854  *
4855  * DESCRIPTION: get selected scene
4856  *
4857  * PARAMETERS :
4858  *
4859  * RETURN     : currently selected scene
4860  *==========================================================================*/
getSelectedScene()4861 cam_scene_mode_type QCameraParameters::getSelectedScene()
4862 {
4863     Mutex::Autolock l(m_SceneSelectLock);
4864     return m_SelectedScene;
4865 }
4866 
4867 /*==========================================================
4868  * FUNCTION   : setRdiMode
4869  *
4870  * DESCRIPTION: set Rdi mode from user setting
4871  *
4872  * PARAMETERS :
4873  *   @params  : user setting parameters
4874  *
4875  * RETURN     : int32_t type of status
4876  *              NO_ERROR  -- success
4877  *              none-zero failure code
4878  *===========================================================*/
setRdiMode(const QCameraParameters & params)4879 int32_t QCameraParameters::setRdiMode(const QCameraParameters& params)
4880 {
4881     const char *str = params.get(KEY_QC_RDI_MODE);
4882     const char *prev_str = get(KEY_QC_RDI_MODE);
4883     char prop[PROPERTY_VALUE_MAX];
4884     memset(prop, 0, sizeof(prop));
4885 
4886     property_get("persist.camera.rdi.mode", prop, VALUE_DISABLE);
4887     if ((str != NULL) && (prev_str == NULL || strcmp(str, prev_str) != 0)) {
4888         LOGD("RDI mode set to %s", str);
4889         setRdiMode(str);
4890     } else if (prev_str == NULL || strcmp(prev_str, prop) != 0 ) {
4891         LOGD("RDI mode set to prop: %s", prop);
4892         setRdiMode(prop);
4893     }
4894     return NO_ERROR;
4895 }
4896 
4897 /*==========================================================
4898  * FUNCTION   : setSecureMode
4899  *
4900  * DESCRIPTION: set secure mode from user setting
4901  *
4902  * PARAMETERS :
4903  *   @params  : user setting parameters
4904  *
4905  * RETURN     : int32_t type of status
4906  *              NO_ERROR  -- success
4907  *              none-zero failure code
4908  *===========================================================*/
4909 
setSecureMode(const QCameraParameters & params)4910 int32_t QCameraParameters::setSecureMode(const QCameraParameters& params)
4911 {
4912     const char *str = params.get(KEY_QC_SECURE_MODE);
4913     const char *prev_str = get(KEY_QC_SECURE_MODE);
4914     char prop[PROPERTY_VALUE_MAX];
4915     memset(prop, 0, sizeof(prop));
4916 
4917     property_get("persist.camera.secure.mode", prop, VALUE_DISABLE);
4918     if ((str != NULL) && (prev_str == NULL || strcmp(str, prev_str) != 0)) {
4919         LOGD("Secure mode set to KEY: %s", str);
4920         setSecureMode(str);
4921         updateParamEntry(KEY_QC_SECURE_MODE, str);
4922     } else if (prev_str == NULL || strcmp(prev_str, prop) != 0 ) {
4923         LOGD("Secure mode set to prop: %s", prop);
4924         setSecureMode(prop);
4925     }
4926 
4927     if (isSecureMode() && (m_bZslMode || m_bZslMode_new)) {
4928         //Enable NZSl if secure mode
4929         setZslMode(FALSE);
4930         m_bNeedRestart = true;
4931     }
4932 
4933     if (get_cam_type(m_pCapability->camera_index) & CAM_TYPE_SECURE) {
4934         LOGD("Secure steam type is CAM_STREAM_TYPE_RAW");
4935         mSecureStraemType = CAM_STREAM_TYPE_RAW;
4936     } else {
4937         LOGD("Secure steam type is CAM_STREAM_TYPE_PREVIEW");
4938         mSecureStraemType = CAM_STREAM_TYPE_PREVIEW;
4939     }
4940 
4941     return NO_ERROR;
4942 }
4943 
4944 /*===========================================================================
4945  * FUNCTION   : setZslAttributes
4946  *
4947  * DESCRIPTION: set ZSL related attributes from user setting
4948  *
4949  * PARAMETERS :
4950  *   @params  : user setting parameters
4951  *
4952  * RETURN     : int32_t type of status
4953  *              NO_ERROR  -- success
4954  *              none-zero failure code
4955  *==========================================================================*/
setZslAttributes(const QCameraParameters & params)4956 int32_t QCameraParameters::setZslAttributes(const QCameraParameters& params)
4957 {
4958     // TODO: may switch to pure param instead of sysprop
4959     char prop[PROPERTY_VALUE_MAX];
4960 
4961     const char *str = params.get(KEY_QC_ZSL_BURST_INTERVAL);
4962     if (str != NULL) {
4963         set(KEY_QC_ZSL_BURST_INTERVAL, str);
4964     } else {
4965         memset(prop, 0, sizeof(prop));
4966         property_get("persist.camera.zsl.interval", prop, "1");
4967         set(KEY_QC_ZSL_BURST_INTERVAL, prop);
4968         LOGH("burst interval: %s", prop);
4969     }
4970 
4971     str = params.get(KEY_QC_ZSL_BURST_LOOKBACK);
4972     if (str != NULL) {
4973         set(KEY_QC_ZSL_BURST_LOOKBACK, str);
4974     } else {
4975         memset(prop, 0, sizeof(prop));
4976         property_get("persist.camera.zsl.backlookcnt", prop, "2");
4977         uint32_t look_back_cnt = atoi(prop);
4978         if (m_bFrameSyncEnabled) {
4979             look_back_cnt += EXTRA_FRAME_SYNC_BUFFERS;
4980         }
4981         set(KEY_QC_ZSL_BURST_LOOKBACK, look_back_cnt);
4982         LOGH("look back count: %s", prop);
4983     }
4984 
4985     str = params.get(KEY_QC_ZSL_QUEUE_DEPTH);
4986     if (str != NULL) {
4987         set(KEY_QC_ZSL_QUEUE_DEPTH, str);
4988     } else {
4989         memset(prop, 0, sizeof(prop));
4990         property_get("persist.camera.zsl.queuedepth", prop, "2");
4991         uint32_t queue_depth = atoi(prop);
4992         if (m_bFrameSyncEnabled) {
4993             queue_depth += EXTRA_FRAME_SYNC_BUFFERS;
4994         }
4995         set(KEY_QC_ZSL_QUEUE_DEPTH, queue_depth);
4996         LOGH("queue depth: %s", prop);
4997     }
4998 
4999     return NO_ERROR;
5000 }
5001 
5002 /*===========================================================================
5003  * FUNCTION   : setFlip
5004  *
5005  * DESCRIPTION: set preview/ video/ picture flip mode from user setting
5006  *
5007  * PARAMETERS :
5008  *   @params  : user setting parameters
5009  *
5010  * RETURN     : int32_t type of status
5011  *              NO_ERROR  -- success
5012  *              none-zero failure code
5013  *==========================================================================*/
setFlip(const QCameraParameters & params)5014 int32_t QCameraParameters::setFlip(const QCameraParameters& params)
5015 {
5016     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) == 0) {
5017         LOGH("flip is not supported.");
5018         return NO_ERROR;
5019     }
5020 
5021     //check preview flip setting
5022     const char *str = params.get(KEY_QC_PREVIEW_FLIP);
5023     const char *prev_val = get(KEY_QC_PREVIEW_FLIP);
5024     if(str != NULL){
5025         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
5026             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
5027             if(value != NAME_NOT_FOUND){
5028                 set(KEY_QC_PREVIEW_FLIP, str);
5029                 m_bPreviewFlipChanged = true;
5030             }
5031         }
5032     }
5033 
5034     // check video filp setting
5035     str = params.get(KEY_QC_VIDEO_FLIP);
5036     prev_val = get(KEY_QC_VIDEO_FLIP);
5037     if(str != NULL){
5038         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
5039             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
5040             if(value != NAME_NOT_FOUND){
5041                 set(KEY_QC_VIDEO_FLIP, str);
5042                 m_bVideoFlipChanged = true;
5043             }
5044         }
5045     }
5046 
5047     // check picture filp setting
5048     str = params.get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
5049     prev_val = get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
5050     if(str != NULL){
5051         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
5052             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
5053             if(value != NAME_NOT_FOUND){
5054                 set(KEY_QC_SNAPSHOT_PICTURE_FLIP, str);
5055                 m_bSnapshotFlipChanged = true;
5056             }
5057         }
5058     }
5059 
5060     return NO_ERROR;
5061 }
5062 
5063 /*===========================================================================
5064  * FUNCTION   : setSnapshotFDReq
5065  *
5066  * DESCRIPTION: set requirement of Face Detection Metadata in Snapshot mode.
5067  *
5068  * PARAMETERS :
5069  *   @params  : user setting parameters
5070  *
5071  * RETURN     : int32_t type of status
5072  *              NO_ERROR  -- success
5073  *              none-zero failure code
5074  *==========================================================================*/
setSnapshotFDReq(const QCameraParameters & params)5075 int32_t QCameraParameters::setSnapshotFDReq(const QCameraParameters& params)
5076 {
5077     char prop[PROPERTY_VALUE_MAX];
5078     const char *str = params.get(KEY_QC_SNAPSHOT_FD_DATA);
5079 
5080     if(str != NULL){
5081         set(KEY_QC_SNAPSHOT_FD_DATA, str);
5082     }else{
5083         memset(prop, 0, sizeof(prop));
5084         property_get("persist.camera.snapshot.fd", prop, "0");
5085         set(KEY_QC_SNAPSHOT_FD_DATA, prop);
5086     }
5087     return NO_ERROR;
5088 }
5089 
5090 /*===========================================================================
5091  * FUNCTION   : setMobicat
5092  *
5093  * DESCRIPTION: set Mobicat on/off.
5094  *
5095  * PARAMETERS :
5096  *   @params  : user setting parameters
5097  *
5098  * RETURN     : int32_t type of status
5099  *              NO_ERROR  -- success
5100  *              none-zero failure code
5101  *==========================================================================*/
setMobicat(const QCameraParameters &)5102 int32_t QCameraParameters::setMobicat(const QCameraParameters& )
5103 {
5104     char value [PROPERTY_VALUE_MAX];
5105     property_get("persist.camera.mobicat", value, "0");
5106     int32_t ret = NO_ERROR;
5107     uint8_t enableMobi = (uint8_t)atoi(value);
5108 
5109     if (enableMobi) {
5110         tune_cmd_t tune_cmd;
5111         tune_cmd.type = 2;
5112         tune_cmd.module = 0;
5113         tune_cmd.value = 1;
5114         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SET_VFE_COMMAND, tune_cmd)) {
5115             return BAD_VALUE;
5116         }
5117         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SET_PP_COMMAND, tune_cmd)) {
5118             ret = BAD_VALUE;
5119         }
5120     }
5121     m_MobiMask = enableMobi;
5122 
5123     return ret;
5124 }
5125 
5126 /*===========================================================================
5127  * FUNCTION   : setLongshotParam
5128  *
5129  * DESCRIPTION: set Longshot on/off.
5130  *
5131  * PARAMETERS :
5132  *   @params  : user setting parameters
5133  *
5134  * RETURN     : int32_t type of status
5135  *              NO_ERROR  -- success
5136  *              none-zero failure code
5137  *==========================================================================*/
setLongshotParam(const QCameraParameters & params)5138 int32_t QCameraParameters::setLongshotParam(const QCameraParameters& params)
5139 {
5140     const char *str = params.get(KEY_QC_LONG_SHOT);
5141     const char *prev_str = get(KEY_QC_LONG_SHOT);
5142 
5143     if (str != NULL) {
5144         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
5145             set(KEY_QC_LONG_SHOT, str);
5146             if (prev_str && !strcmp(str, "off") && !strcmp(prev_str, "on")) {
5147                 // We restart here, to reset the FPS and no
5148                 // of buffers as per the requirement of single snapshot usecase.
5149                 // Here restart happens when continuous shot is changed to off from on.
5150                 // In case of continuous shot on, restart is taken care when actual
5151                 // longshot command is triggered through sendCommand.
5152                 m_bNeedRestart = true;
5153             }
5154         }
5155     }
5156 
5157     return NO_ERROR;
5158 }
5159 
5160 /*===========================================================================
5161  * FUNCTION   : checkFeatureConcurrency
5162  *
5163  * DESCRIPTION: check if there is a feature concurrency issue with advanced
5164  *              camera features
5165  *
5166  * PARAMETERS : None
5167  *
5168  * RETURN     : int32_t type of status
5169  *              NO_ERROR  -- success
5170  *              none-zero failure code
5171  *==========================================================================*/
checkFeatureConcurrency()5172 int32_t QCameraParameters::checkFeatureConcurrency()
5173 {
5174     int32_t rc = NO_ERROR;
5175     uint32_t advancedFeatEnableBit = 0;
5176 
5177     if (isStillMoreEnabled()) {
5178         advancedFeatEnableBit |= CAM_QCOM_FEATURE_STILLMORE;
5179     }
5180     if (isHDREnabled()) {
5181         advancedFeatEnableBit |= CAM_QCOM_FEATURE_HDR;
5182     }
5183     if (isChromaFlashEnabled()) {
5184         advancedFeatEnableBit |= CAM_QCOM_FEATURE_CHROMA_FLASH;
5185     }
5186     if (isUbiFocusEnabled()) {
5187         advancedFeatEnableBit |= CAM_QCOM_FEATURE_UBIFOCUS;
5188     }
5189     if (isTruePortraitEnabled()) {
5190         advancedFeatEnableBit |= CAM_QCOM_FEATURE_TRUEPORTRAIT;
5191     }
5192     if (isOptiZoomEnabled()) {
5193         advancedFeatEnableBit |= CAM_QCOM_FEATURE_OPTIZOOM;
5194     }
5195     if (isUbiRefocus()) {
5196         advancedFeatEnableBit |= CAM_QCOM_FEATURE_REFOCUS;
5197     }
5198 
5199    if (m_bLongshotEnabled && advancedFeatEnableBit) {
5200         LOGE("Failed Longshot mode bit 0x%x",
5201                     advancedFeatEnableBit);
5202         rc = BAD_TYPE;
5203         return rc;
5204     }
5205 
5206     if(m_bRecordingHint_new) {
5207         advancedFeatEnableBit &= ~CAM_QCOM_FEATURE_STILLMORE;
5208 
5209         if (advancedFeatEnableBit) {
5210             LOGE("Failed recording mode bit 0x%x",
5211                     advancedFeatEnableBit);
5212             rc = BAD_TYPE;
5213         }
5214     } else if (m_bZslMode_new) {
5215         /* ZSL mode check if 2 bits are set */
5216         if (advancedFeatEnableBit & (advancedFeatEnableBit - 1)) {
5217             LOGE("Failed ZSL mode bit 0x%x", advancedFeatEnableBit);
5218             rc = BAD_TYPE;
5219         }
5220     } else { /* non-ZSL mode */
5221         advancedFeatEnableBit &= ~CAM_QCOM_FEATURE_HDR;
5222 
5223         /* non-ZSL mode check if 1 bit is set */
5224         if (advancedFeatEnableBit) {
5225             LOGE("Failed non-ZSL mode bit 0x%x", advancedFeatEnableBit);
5226             rc = BAD_TYPE;
5227         }
5228     }
5229     LOGI("Advance feature enabled 0x%x", advancedFeatEnableBit);
5230     return rc;
5231 }
5232 
5233 /*===========================================================================
5234  * FUNCTION   : updateParameters
5235  *
5236  * DESCRIPTION: update parameters from user setting
5237  *
5238  * PARAMETERS :
5239  *   @params  : user setting parameters
5240  *   @needRestart : [output] if preview need restart upon setting changes
5241  *
5242  * RETURN     : int32_t type of status
5243  *              NO_ERROR  -- success
5244  *              none-zero failure code
5245  *==========================================================================*/
updateParameters(const String8 & p,bool & needRestart)5246 int32_t QCameraParameters::updateParameters(const String8& p,
5247         bool &needRestart)
5248 {
5249     int32_t final_rc = NO_ERROR;
5250     int32_t rc;
5251     m_bNeedRestart = false;
5252     QCameraParameters params(p);
5253 
5254     if(initBatchUpdate() < 0 ) {
5255         LOGE("Failed to initialize group update table");
5256         rc = BAD_TYPE;
5257         goto UPDATE_PARAM_DONE;
5258     }
5259 
5260     if ((rc = setPreviewSize(params)))                  final_rc = rc;
5261     if ((rc = setVideoSize(params)))                    final_rc = rc;
5262     if ((rc = setPictureSize(params)))                  final_rc = rc;
5263     if ((rc = setPreviewFormat(params)))                final_rc = rc;
5264     if ((rc = setPictureFormat(params)))                final_rc = rc;
5265     if ((rc = setJpegQuality(params)))                  final_rc = rc;
5266     if ((rc = setOrientation(params)))                  final_rc = rc;
5267     if ((rc = setRotation(params)))                     final_rc = rc;
5268     if ((rc = setVideoRotation(params)))                final_rc = rc;
5269     if ((rc = setNoDisplayMode(params)))                final_rc = rc;
5270     if ((rc = setZslMode(params)))                      final_rc = rc;
5271     if ((rc = setZslAttributes(params)))                final_rc = rc;
5272     if ((rc = setCameraMode(params)))                   final_rc = rc;
5273     if ((rc = setSceneSelectionMode(params)))           final_rc = rc;
5274     if ((rc = setRecordingHint(params)))                final_rc = rc;
5275     if ((rc = setRdiMode(params)))                      final_rc = rc;
5276     if ((rc = setSecureMode(params)))                   final_rc = rc;
5277     if ((rc = setPreviewFrameRate(params)))             final_rc = rc;
5278     if ((rc = setPreviewFpsRange(params)))              final_rc = rc;
5279     if ((rc = setAutoExposure(params)))                 final_rc = rc;
5280     if ((rc = setEffect(params)))                       final_rc = rc;
5281     if ((rc = setBrightness(params)))                   final_rc = rc;
5282     if ((rc = setZoom(params)))                         final_rc = rc;
5283     if ((rc = setSharpness(params)))                    final_rc = rc;
5284     if ((rc = setSaturation(params)))                   final_rc = rc;
5285     if ((rc = setContrast(params)))                     final_rc = rc;
5286     if ((rc = setFocusMode(params)))                    final_rc = rc;
5287     if ((rc = setISOValue(params)))                     final_rc = rc;
5288     if ((rc = setContinuousISO(params)))                final_rc = rc;
5289     if ((rc = setExposureTime(params)))                 final_rc = rc;
5290     if ((rc = setSkinToneEnhancement(params)))          final_rc = rc;
5291     if ((rc = setFlash(params)))                        final_rc = rc;
5292     if ((rc = setAecLock(params)))                      final_rc = rc;
5293     if ((rc = setAwbLock(params)))                      final_rc = rc;
5294     if ((rc = setLensShadeValue(params)))               final_rc = rc;
5295     if ((rc = setMCEValue(params)))                     final_rc = rc;
5296     if ((rc = setDISValue(params)))                     final_rc = rc;
5297     if ((rc = setAntibanding(params)))                  final_rc = rc;
5298     if ((rc = setExposureCompensation(params)))         final_rc = rc;
5299     if ((rc = setWhiteBalance(params)))                 final_rc = rc;
5300     if ((rc = setHDRMode(params)))                      final_rc = rc;
5301     if ((rc = setHDRNeed1x(params)))                    final_rc = rc;
5302     if ((rc = setManualWhiteBalance(params)))           final_rc = rc;
5303     if ((rc = setSceneMode(params)))                    final_rc = rc;
5304     if ((rc = setFocusAreas(params)))                   final_rc = rc;
5305     if ((rc = setFocusPosition(params)))                final_rc = rc;
5306     if ((rc = setMeteringAreas(params)))                final_rc = rc;
5307     if ((rc = setSelectableZoneAf(params)))             final_rc = rc;
5308     if ((rc = setRedeyeReduction(params)))              final_rc = rc;
5309     if ((rc = setAEBracket(params)))                    final_rc = rc;
5310     if ((rc = setAutoHDR(params)))                      final_rc = rc;
5311     if ((rc = setGpsLocation(params)))                  final_rc = rc;
5312     if ((rc = setWaveletDenoise(params)))               final_rc = rc;
5313     if ((rc = setFaceRecognition(params)))              final_rc = rc;
5314     if ((rc = setFlip(params)))                         final_rc = rc;
5315     if ((rc = setVideoHDR(params)))                     final_rc = rc;
5316     if ((rc = setVtEnable(params)))                     final_rc = rc;
5317     if ((rc = setAFBracket(params)))                    final_rc = rc;
5318     if ((rc = setReFocus(params)))                      final_rc = rc;
5319     if ((rc = setChromaFlash(params)))                  final_rc = rc;
5320     if ((rc = setTruePortrait(params)))                 final_rc = rc;
5321     if ((rc = setOptiZoom(params)))                     final_rc = rc;
5322     if ((rc = setBurstLEDOnPeriod(params)))             final_rc = rc;
5323     if ((rc = setRetroActiveBurstNum(params)))          final_rc = rc;
5324     if ((rc = setSnapshotFDReq(params)))                final_rc = rc;
5325     if ((rc = setTintlessValue(params)))                final_rc = rc;
5326     if ((rc = setCDSMode(params)))                      final_rc = rc;
5327     if ((rc = setTemporalDenoise(params)))              final_rc = rc;
5328     if ((rc = setCacheVideoBuffers(params)))            final_rc = rc;
5329     if ((rc = setInitialExposureIndex(params)))         final_rc = rc;
5330     if ((rc = setInstantCapture(params)))               final_rc = rc;
5331     if ((rc = setInstantAEC(params)))                   final_rc = rc;
5332 
5333     // update live snapshot size after all other parameters are set
5334     if ((rc = setLiveSnapshotSize(params)))             final_rc = rc;
5335     if ((rc = setJpegThumbnailSize(params)))            final_rc = rc;
5336     if ((rc = setStatsDebugMask()))                     final_rc = rc;
5337     if ((rc = setPAAF()))                               final_rc = rc;
5338     if ((rc = setMobicat(params)))                      final_rc = rc;
5339     if ((rc = setSeeMore(params)))                      final_rc = rc;
5340     if ((rc = setStillMore(params)))                    final_rc = rc;
5341     if ((rc = setCustomParams(params)))                 final_rc = rc;
5342     if ((rc = setNoiseReductionMode(params)))           final_rc = rc;
5343 
5344     if ((rc = setLongshotParam(params)))                final_rc = rc;
5345     if ((rc = setDualLedCalibration(params)))           final_rc = rc;
5346 
5347     setQuadraCfa(params);
5348     setVideoBatchSize();
5349     setLowLightCapture();
5350     setAsymmetricSnapMode();
5351 
5352     if ((rc = updateFlash(false)))                      final_rc = rc;
5353 #ifdef TARGET_TS_MAKEUP
5354     if ((rc = setTsMakeup(params)))                     final_rc = rc;
5355 #endif
5356     if ((rc = setAdvancedCaptureMode()))                final_rc = rc;
5357 UPDATE_PARAM_DONE:
5358     needRestart = m_bNeedRestart;
5359     return final_rc;
5360 }
5361 
5362 /*===========================================================================
5363  * FUNCTION   : commitParameters
5364  *
5365  * DESCRIPTION: commit parameter changes to backend
5366  *
5367  * PARAMETERS : none
5368  *
5369  * RETURN     : int32_t type of status
5370  *              NO_ERROR  -- success
5371  *              none-zero failure code
5372  *==========================================================================*/
commitParameters()5373 int32_t QCameraParameters::commitParameters()
5374 {
5375     return commitSetBatch();
5376 }
5377 
5378 /*===========================================================================
5379  * FUNCTION   : initDefaultParameters
5380  *
5381  * DESCRIPTION: initialize default parameters for the first time
5382  *
5383  * PARAMETERS : none
5384  *
5385  * RETURN     : int32_t type of status
5386  *              NO_ERROR  -- success
5387  *              none-zero failure code
5388  *==========================================================================*/
initDefaultParameters()5389 int32_t QCameraParameters::initDefaultParameters()
5390 {
5391     if(initBatchUpdate() < 0 ) {
5392         LOGE("Failed to initialize group update table");
5393         return BAD_TYPE;
5394     }
5395     int32_t hal_version = CAM_HAL_V1;
5396     ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HAL_VERSION, hal_version);
5397 
5398     /*************************Initialize Values******************************/
5399     // Set read only parameters from camera capability
5400     set(KEY_SMOOTH_ZOOM_SUPPORTED,
5401         m_pCapability->smooth_zoom_supported? VALUE_TRUE : VALUE_FALSE);
5402     set(KEY_ZOOM_SUPPORTED,
5403         m_pCapability->zoom_supported? VALUE_TRUE : VALUE_FALSE);
5404     set(KEY_VIDEO_SNAPSHOT_SUPPORTED,
5405         m_pCapability->video_snapshot_supported? VALUE_TRUE : VALUE_FALSE);
5406     set(KEY_VIDEO_STABILIZATION_SUPPORTED,
5407         m_pCapability->video_stablization_supported? VALUE_TRUE : VALUE_FALSE);
5408     set(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED,
5409         m_pCapability->auto_exposure_lock_supported? VALUE_TRUE : VALUE_FALSE);
5410     set(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED,
5411         m_pCapability->auto_wb_lock_supported? VALUE_TRUE : VALUE_FALSE);
5412     set(KEY_MAX_NUM_DETECTED_FACES_HW, m_pCapability->max_num_roi);
5413     set(KEY_MAX_NUM_DETECTED_FACES_SW, m_pCapability->max_num_roi);
5414     set(KEY_QC_MAX_NUM_REQUESTED_FACES, m_pCapability->max_num_roi);
5415     // Set focal length, horizontal view angle, and vertical view angle
5416     setFloat(KEY_FOCAL_LENGTH, m_pCapability->focal_length);
5417     setFloat(KEY_HORIZONTAL_VIEW_ANGLE, m_pCapability->hor_view_angle);
5418     setFloat(KEY_VERTICAL_VIEW_ANGLE, m_pCapability->ver_view_angle);
5419     set(QCameraParameters::KEY_FOCUS_DISTANCES, "Infinity,Infinity,Infinity");
5420     set(KEY_QC_AUTO_HDR_SUPPORTED,
5421         (m_pCapability->auto_hdr_supported)? VALUE_TRUE : VALUE_FALSE);
5422     // Set supported preview sizes
5423     if (m_pCapability->preview_sizes_tbl_cnt > 0 &&
5424         m_pCapability->preview_sizes_tbl_cnt <= MAX_SIZES_CNT) {
5425         String8 previewSizeValues = createSizesString(
5426                 m_pCapability->preview_sizes_tbl, m_pCapability->preview_sizes_tbl_cnt);
5427         set(KEY_SUPPORTED_PREVIEW_SIZES, previewSizeValues.string());
5428         LOGH("supported preview sizes: %s", previewSizeValues.string());
5429         // Set default preview size
5430         CameraParameters::setPreviewSize(m_pCapability->preview_sizes_tbl[0].width,
5431                                          m_pCapability->preview_sizes_tbl[0].height);
5432     } else {
5433         LOGW("supported preview sizes cnt is 0 or exceeds max!!!");
5434     }
5435 
5436     // Set supported video sizes
5437     if (m_pCapability->video_sizes_tbl_cnt > 0 &&
5438         m_pCapability->video_sizes_tbl_cnt <= MAX_SIZES_CNT) {
5439         String8 videoSizeValues = createSizesString(
5440                 m_pCapability->video_sizes_tbl, m_pCapability->video_sizes_tbl_cnt);
5441         set(KEY_SUPPORTED_VIDEO_SIZES, videoSizeValues.string());
5442         LOGH("supported video sizes: %s", videoSizeValues.string());
5443         // Set default video size
5444         CameraParameters::setVideoSize(m_pCapability->video_sizes_tbl[0].width,
5445                                        m_pCapability->video_sizes_tbl[0].height);
5446 
5447         //Set preferred Preview size for video
5448         String8 vSize = createSizesString(&m_pCapability->preview_sizes_tbl[0], 1);
5449         set(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO, vSize.string());
5450     } else {
5451         LOGW("supported video sizes cnt is 0 or exceeds max!!!");
5452     }
5453 
5454     // Set supported picture sizes
5455     if (m_pCapability->picture_sizes_tbl_cnt > 0 &&
5456         m_pCapability->picture_sizes_tbl_cnt <= MAX_SIZES_CNT) {
5457         String8 pictureSizeValues = createSizesString(
5458                 m_pCapability->picture_sizes_tbl, m_pCapability->picture_sizes_tbl_cnt);
5459         set(KEY_SUPPORTED_PICTURE_SIZES, pictureSizeValues.string());
5460         LOGH("supported pic sizes: %s", pictureSizeValues.string());
5461         // Set default picture size to the smallest resolution
5462         CameraParameters::setPictureSize(
5463            m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].width,
5464            m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].height);
5465     } else {
5466         LOGW("supported picture sizes cnt is 0 or exceeds max!!!");
5467     }
5468 
5469     // Need check if scale should be enabled
5470     if (m_pCapability->scale_picture_sizes_cnt > 0 &&
5471         m_pCapability->scale_picture_sizes_cnt <= MAX_SCALE_SIZES_CNT){
5472         //get scale size, enable scaling. And re-set picture size table with scale sizes
5473         m_reprocScaleParam.setScaleEnable(true);
5474         int rc_s = m_reprocScaleParam.setScaleSizeTbl(
5475             m_pCapability->scale_picture_sizes_cnt, m_pCapability->scale_picture_sizes,
5476             m_pCapability->picture_sizes_tbl_cnt, m_pCapability->picture_sizes_tbl);
5477         if(rc_s == NO_ERROR){
5478             cam_dimension_t *totalSizeTbl = m_reprocScaleParam.getTotalSizeTbl();
5479             size_t totalSizeCnt = m_reprocScaleParam.getTotalSizeTblCnt();
5480             String8 pictureSizeValues = createSizesString(totalSizeTbl, totalSizeCnt);
5481             set(KEY_SUPPORTED_PICTURE_SIZES, pictureSizeValues.string());
5482             LOGH("scaled supported pic sizes: %s", pictureSizeValues.string());
5483         }else{
5484             m_reprocScaleParam.setScaleEnable(false);
5485             LOGW("reset scaled picture size table failed.");
5486         }
5487     }else{
5488         m_reprocScaleParam.setScaleEnable(false);
5489     }
5490 
5491     // Set supported thumbnail sizes
5492     String8 thumbnailSizeValues = createSizesString(
5493             THUMBNAIL_SIZES_MAP,
5494             PARAM_MAP_SIZE(THUMBNAIL_SIZES_MAP));
5495     set(KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, thumbnailSizeValues.string());
5496     // Set default thumnail size
5497     set(KEY_JPEG_THUMBNAIL_WIDTH, THUMBNAIL_SIZES_MAP[0].width);
5498     set(KEY_JPEG_THUMBNAIL_HEIGHT, THUMBNAIL_SIZES_MAP[0].height);
5499 
5500     // Set supported livesnapshot sizes
5501     if (m_pCapability->livesnapshot_sizes_tbl_cnt > 0 &&
5502         m_pCapability->livesnapshot_sizes_tbl_cnt <= MAX_SIZES_CNT) {
5503         String8 liveSnpashotSizeValues = createSizesString(
5504                 m_pCapability->livesnapshot_sizes_tbl,
5505                 m_pCapability->livesnapshot_sizes_tbl_cnt);
5506         set(KEY_QC_SUPPORTED_LIVESNAPSHOT_SIZES, liveSnpashotSizeValues.string());
5507         LOGD("supported live snapshot sizes: %s", liveSnpashotSizeValues.string());
5508         m_LiveSnapshotSize =
5509             m_pCapability->livesnapshot_sizes_tbl[m_pCapability->livesnapshot_sizes_tbl_cnt-1];
5510     }
5511 
5512     // Set supported preview formats
5513     String8 previewFormatValues = createValuesString(
5514             m_pCapability->supported_preview_fmts,
5515             m_pCapability->supported_preview_fmt_cnt,
5516             PREVIEW_FORMATS_MAP,
5517             PARAM_MAP_SIZE(PREVIEW_FORMATS_MAP));
5518     set(KEY_SUPPORTED_PREVIEW_FORMATS, previewFormatValues.string());
5519     // Set default preview format
5520     CameraParameters::setPreviewFormat(PIXEL_FORMAT_YUV420SP);
5521 
5522     // Set default Video Format as OPAQUE
5523     // Internally both Video and Camera subsystems use NV21_VENUS
5524     set(KEY_VIDEO_FRAME_FORMAT, PIXEL_FORMAT_ANDROID_OPAQUE);
5525 
5526     // Set supported picture formats
5527     String8 pictureTypeValues(PIXEL_FORMAT_JPEG);
5528     String8 str = createValuesString(
5529             m_pCapability->supported_raw_fmts,
5530             m_pCapability->supported_raw_fmt_cnt,
5531             PICTURE_TYPES_MAP,
5532             PARAM_MAP_SIZE(PICTURE_TYPES_MAP));
5533     if (str.string() != NULL) {
5534         pictureTypeValues.append(",");
5535         pictureTypeValues.append(str);
5536     }
5537 
5538     set(KEY_SUPPORTED_PICTURE_FORMATS, pictureTypeValues.string());
5539     // Set default picture Format
5540     CameraParameters::setPictureFormat(PIXEL_FORMAT_JPEG);
5541     // Set raw image size
5542     char raw_size_str[32];
5543     snprintf(raw_size_str, sizeof(raw_size_str), "%dx%d",
5544              m_pCapability->raw_dim[0].width, m_pCapability->raw_dim[0].height);
5545     set(KEY_QC_RAW_PICUTRE_SIZE, raw_size_str);
5546     LOGD("KEY_QC_RAW_PICUTRE_SIZE: w: %d, h: %d ",
5547        m_pCapability->raw_dim[0].width, m_pCapability->raw_dim[0].height);
5548 
5549     //set default jpeg quality and thumbnail quality
5550     set(KEY_JPEG_QUALITY, 85);
5551     set(KEY_JPEG_THUMBNAIL_QUALITY, 85);
5552 
5553     // Set FPS ranges
5554     if (m_pCapability->fps_ranges_tbl_cnt > 0 &&
5555         m_pCapability->fps_ranges_tbl_cnt <= MAX_SIZES_CNT) {
5556         int default_fps_index = 0;
5557         String8 fpsRangeValues = createFpsRangeString(m_pCapability->fps_ranges_tbl,
5558                                                       m_pCapability->fps_ranges_tbl_cnt,
5559                                                       default_fps_index);
5560         set(KEY_SUPPORTED_PREVIEW_FPS_RANGE, fpsRangeValues.string());
5561 
5562         int min_fps =
5563             int(m_pCapability->fps_ranges_tbl[default_fps_index].min_fps * 1000);
5564         int max_fps =
5565             int(m_pCapability->fps_ranges_tbl[default_fps_index].max_fps * 1000);
5566         m_default_fps_range = m_pCapability->fps_ranges_tbl[default_fps_index];
5567         //Set video fps same as preview fps
5568         setPreviewFpsRange(min_fps, max_fps, min_fps, max_fps);
5569 
5570         // Set legacy preview fps
5571         String8 fpsValues = createFpsString(m_pCapability->fps_ranges_tbl[default_fps_index]);
5572         set(KEY_SUPPORTED_PREVIEW_FRAME_RATES, fpsValues.string());
5573         LOGH("supported fps rates: %s", fpsValues.string());
5574         CameraParameters::setPreviewFrameRate(int(m_pCapability->fps_ranges_tbl[default_fps_index].max_fps));
5575     } else {
5576         LOGW("supported fps ranges cnt is 0 or exceeds max!!!");
5577     }
5578 
5579     // Set supported focus modes
5580     if (m_pCapability->supported_focus_modes_cnt > 0) {
5581         String8 focusModeValues = createValuesString(
5582                 m_pCapability->supported_focus_modes,
5583                 m_pCapability->supported_focus_modes_cnt,
5584                 FOCUS_MODES_MAP,
5585                 PARAM_MAP_SIZE(FOCUS_MODES_MAP));
5586         set(KEY_SUPPORTED_FOCUS_MODES, focusModeValues);
5587 
5588         // Set default focus mode and update corresponding parameter buf
5589         const char *focusMode = lookupNameByValue(FOCUS_MODES_MAP,
5590                 PARAM_MAP_SIZE(FOCUS_MODES_MAP),
5591                 m_pCapability->supported_focus_modes[0]);
5592         if (focusMode != NULL) {
5593             setFocusMode(focusMode);
5594         } else {
5595             setFocusMode(FOCUS_MODE_FIXED);
5596         }
5597     } else {
5598         LOGW("supported focus modes cnt is 0!!!");
5599     }
5600 
5601     // Set focus areas
5602     if (m_pCapability->max_num_focus_areas > MAX_ROI) {
5603         m_pCapability->max_num_focus_areas = MAX_ROI;
5604     }
5605     set(KEY_MAX_NUM_FOCUS_AREAS, m_pCapability->max_num_focus_areas);
5606     if (m_pCapability->max_num_focus_areas > 0) {
5607         setFocusAreas(DEFAULT_CAMERA_AREA);
5608     }
5609 
5610     // Set metering areas
5611     if (m_pCapability->max_num_metering_areas > MAX_ROI) {
5612         m_pCapability->max_num_metering_areas = MAX_ROI;
5613     }
5614     set(KEY_MAX_NUM_METERING_AREAS, m_pCapability->max_num_metering_areas);
5615     if (m_pCapability->max_num_metering_areas > 0) {
5616         setMeteringAreas(DEFAULT_CAMERA_AREA);
5617     }
5618 
5619     // set focus position, we should get them from m_pCapability
5620     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX] = 0;
5621     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX] = 1023;
5622     set(KEY_QC_MIN_FOCUS_POS_INDEX,
5623             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX]);
5624     set(KEY_QC_MAX_FOCUS_POS_INDEX,
5625             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX]);
5626 
5627     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE] = 0;
5628     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE] = 1023;
5629     set(KEY_QC_MIN_FOCUS_POS_DAC,
5630             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE]);
5631     set(KEY_QC_MAX_FOCUS_POS_DAC,
5632             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE]);
5633 
5634     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO] = 0;
5635     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO] = 100;
5636     set(KEY_QC_MIN_FOCUS_POS_RATIO,
5637             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO]);
5638     set(KEY_QC_MAX_FOCUS_POS_RATIO,
5639             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO]);
5640 
5641     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] = 0;
5642     if (m_pCapability->min_focus_distance > 0) {
5643         m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] =
5644                 m_pCapability->min_focus_distance;
5645     } else {
5646         m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] = 0;
5647     }
5648     setFloat(KEY_QC_MIN_FOCUS_POS_DIOPTER,
5649             m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER]);
5650     setFloat(KEY_QC_MAX_FOCUS_POS_DIOPTER,
5651             m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER]);
5652 
5653     //set supported manual focus modes
5654     String8 manualFocusModes(VALUE_OFF);
5655     if (m_pCapability->supported_focus_modes_cnt > 1 &&
5656         m_pCapability->min_focus_distance > 0) {
5657         manualFocusModes.append(",");
5658         manualFocusModes.append(KEY_QC_FOCUS_SCALE_MODE);
5659         manualFocusModes.append(",");
5660         manualFocusModes.append(KEY_QC_FOCUS_DIOPTER_MODE);
5661     }
5662     set(KEY_QC_SUPPORTED_MANUAL_FOCUS_MODES, manualFocusModes.string());
5663 
5664     // Set Saturation
5665     set(KEY_QC_MIN_SATURATION, m_pCapability->saturation_ctrl.min_value);
5666     set(KEY_QC_MAX_SATURATION, m_pCapability->saturation_ctrl.max_value);
5667     set(KEY_QC_SATURATION_STEP, m_pCapability->saturation_ctrl.step);
5668     setSaturation(m_pCapability->saturation_ctrl.def_value);
5669 
5670     // Set Sharpness
5671     set(KEY_QC_MIN_SHARPNESS, m_pCapability->sharpness_ctrl.min_value);
5672     set(KEY_QC_MAX_SHARPNESS, m_pCapability->sharpness_ctrl.max_value);
5673     set(KEY_QC_SHARPNESS_STEP, m_pCapability->sharpness_ctrl.step);
5674     setSharpness(m_pCapability->sharpness_ctrl.def_value);
5675 
5676     // Set Contrast
5677     set(KEY_QC_MIN_CONTRAST, m_pCapability->contrast_ctrl.min_value);
5678     set(KEY_QC_MAX_CONTRAST, m_pCapability->contrast_ctrl.max_value);
5679     set(KEY_QC_CONTRAST_STEP, m_pCapability->contrast_ctrl.step);
5680     setContrast(m_pCapability->contrast_ctrl.def_value);
5681 
5682     // Set SCE factor
5683     set(KEY_QC_MIN_SCE_FACTOR, m_pCapability->sce_ctrl.min_value); // -100
5684     set(KEY_QC_MAX_SCE_FACTOR, m_pCapability->sce_ctrl.max_value); // 100
5685     set(KEY_QC_SCE_FACTOR_STEP, m_pCapability->sce_ctrl.step);     // 10
5686     setSkinToneEnhancement(m_pCapability->sce_ctrl.def_value);     // 0
5687 
5688     // Set Brightness
5689     set(KEY_QC_MIN_BRIGHTNESS, m_pCapability->brightness_ctrl.min_value); // 0
5690     set(KEY_QC_MAX_BRIGHTNESS, m_pCapability->brightness_ctrl.max_value); // 6
5691     set(KEY_QC_BRIGHTNESS_STEP, m_pCapability->brightness_ctrl.step);     // 1
5692     setBrightness(m_pCapability->brightness_ctrl.def_value);
5693 
5694     // Set Auto exposure
5695     String8 autoExposureValues = createValuesString(
5696             m_pCapability->supported_aec_modes,
5697             m_pCapability->supported_aec_modes_cnt,
5698             AUTO_EXPOSURE_MAP,
5699             PARAM_MAP_SIZE(AUTO_EXPOSURE_MAP));
5700     set(KEY_QC_SUPPORTED_AUTO_EXPOSURE, autoExposureValues.string());
5701     setAutoExposure(AUTO_EXPOSURE_FRAME_AVG);
5702 
5703     // Set Exposure Compensation
5704     set(KEY_MAX_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_max); // 12
5705     set(KEY_MIN_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_min); // -12
5706     setFloat(KEY_EXPOSURE_COMPENSATION_STEP, m_pCapability->exposure_compensation_step); // 1/6
5707     setExposureCompensation(m_pCapability->exposure_compensation_default); // 0
5708 
5709     // Set Instant AEC modes
5710     String8 instantAECModes = createValuesString(
5711             m_pCapability->supported_instant_aec_modes,
5712             m_pCapability->supported_instant_aec_modes_cnt,
5713             INSTANT_AEC_MODES_MAP,
5714             PARAM_MAP_SIZE(INSTANT_AEC_MODES_MAP));
5715     set(KEY_QC_INSTANT_AEC_SUPPORTED_MODES, instantAECModes.string());
5716 
5717     // Set Instant Capture modes
5718     String8 instantCaptureModes = createValuesString(
5719             m_pCapability->supported_instant_aec_modes,
5720             m_pCapability->supported_instant_aec_modes_cnt,
5721             INSTANT_CAPTURE_MODES_MAP,
5722             PARAM_MAP_SIZE(INSTANT_CAPTURE_MODES_MAP));
5723     set(KEY_QC_INSTANT_CAPTURE_SUPPORTED_MODES, instantCaptureModes.string());
5724 
5725 
5726     // Set Antibanding
5727     String8 antibandingValues = createValuesString(
5728             m_pCapability->supported_antibandings,
5729             m_pCapability->supported_antibandings_cnt,
5730             ANTIBANDING_MODES_MAP,
5731             PARAM_MAP_SIZE(ANTIBANDING_MODES_MAP));
5732     set(KEY_SUPPORTED_ANTIBANDING, antibandingValues);
5733     setAntibanding(ANTIBANDING_OFF);
5734 
5735     // Set Effect
5736     String8 effectValues = createValuesString(
5737             m_pCapability->supported_effects,
5738             m_pCapability->supported_effects_cnt,
5739             EFFECT_MODES_MAP,
5740             PARAM_MAP_SIZE(EFFECT_MODES_MAP));
5741 
5742     if (m_pCapability->supported_effects_cnt > 0) {
5743         set(KEY_SUPPORTED_EFFECTS, effectValues);
5744     } else {
5745         LOGW("Color effects are not available");
5746         set(KEY_SUPPORTED_EFFECTS, EFFECT_NONE);
5747     }
5748     setEffect(EFFECT_NONE);
5749 
5750     // Set WhiteBalance
5751     String8 whitebalanceValues = createValuesString(
5752             m_pCapability->supported_white_balances,
5753             m_pCapability->supported_white_balances_cnt,
5754             WHITE_BALANCE_MODES_MAP,
5755             PARAM_MAP_SIZE(WHITE_BALANCE_MODES_MAP));
5756     set(KEY_SUPPORTED_WHITE_BALANCE, whitebalanceValues);
5757     setWhiteBalance(WHITE_BALANCE_AUTO);
5758 
5759     // set supported wb cct, we should get them from m_pCapability
5760     m_pCapability->min_wb_cct = 2000;
5761     m_pCapability->max_wb_cct = 8000;
5762     set(KEY_QC_MIN_WB_CCT, m_pCapability->min_wb_cct);
5763     set(KEY_QC_MAX_WB_CCT, m_pCapability->max_wb_cct);
5764 
5765     // set supported wb rgb gains, ideally we should get them from m_pCapability
5766     //but for now hardcode.
5767     m_pCapability->min_wb_gain = 1.0;
5768     m_pCapability->max_wb_gain = 4.0;
5769     setFloat(KEY_QC_MIN_WB_GAIN, m_pCapability->min_wb_gain);
5770     setFloat(KEY_QC_MAX_WB_GAIN, m_pCapability->max_wb_gain);
5771 
5772     //set supported manual wb modes
5773     String8 manualWBModes(VALUE_OFF);
5774     if(m_pCapability->sensor_type.sens_type != CAM_SENSOR_YUV) {
5775         manualWBModes.append(",");
5776         manualWBModes.append(KEY_QC_WB_CCT_MODE);
5777         manualWBModes.append(",");
5778         manualWBModes.append(KEY_QC_WB_GAIN_MODE);
5779     }
5780     set(KEY_QC_SUPPORTED_MANUAL_WB_MODES, manualWBModes.string());
5781 
5782     // Set Flash mode
5783     if(m_pCapability->supported_flash_modes_cnt > 0) {
5784        String8 flashValues = createValuesString(
5785                m_pCapability->supported_flash_modes,
5786                m_pCapability->supported_flash_modes_cnt,
5787                FLASH_MODES_MAP,
5788                PARAM_MAP_SIZE(FLASH_MODES_MAP));
5789        set(KEY_SUPPORTED_FLASH_MODES, flashValues);
5790        setFlash(FLASH_MODE_OFF);
5791     } else {
5792         LOGW("supported flash modes cnt is 0!!!");
5793     }
5794 
5795     // Set Scene Mode
5796     String8 sceneModeValues = createValuesString(
5797             m_pCapability->supported_scene_modes,
5798             m_pCapability->supported_scene_modes_cnt,
5799             SCENE_MODES_MAP,
5800             PARAM_MAP_SIZE(SCENE_MODES_MAP));
5801     set(KEY_SUPPORTED_SCENE_MODES, sceneModeValues);
5802     setSceneMode(SCENE_MODE_AUTO);
5803 
5804     // Set CDS Mode
5805     String8 cdsModeValues = createValuesStringFromMap(
5806             CDS_MODES_MAP,
5807             PARAM_MAP_SIZE(CDS_MODES_MAP));
5808     set(KEY_QC_SUPPORTED_CDS_MODES, cdsModeValues);
5809 
5810     // Set video CDS Mode
5811     String8 videoCdsModeValues = createValuesStringFromMap(
5812             CDS_MODES_MAP,
5813             PARAM_MAP_SIZE(CDS_MODES_MAP));
5814     set(KEY_QC_SUPPORTED_VIDEO_CDS_MODES, videoCdsModeValues);
5815 
5816     // Set TNR Mode
5817     String8 tnrModeValues = createValuesStringFromMap(
5818             ON_OFF_MODES_MAP,
5819             PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
5820     set(KEY_QC_SUPPORTED_TNR_MODES, tnrModeValues);
5821 
5822     // Set video TNR Mode
5823     String8 videoTnrModeValues = createValuesStringFromMap(
5824             ON_OFF_MODES_MAP,
5825             PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
5826     set(KEY_QC_SUPPORTED_VIDEO_TNR_MODES, videoTnrModeValues);
5827 
5828     // Set ISO Mode
5829     String8 isoValues = createValuesString(
5830             m_pCapability->supported_iso_modes,
5831             m_pCapability->supported_iso_modes_cnt,
5832             ISO_MODES_MAP,
5833             PARAM_MAP_SIZE(ISO_MODES_MAP));
5834     set(KEY_QC_SUPPORTED_ISO_MODES, isoValues);
5835     setISOValue(ISO_AUTO);
5836 
5837     // Set exposure time
5838     String8 manualExpModes(VALUE_OFF);
5839     bool expTimeSupported = false;
5840     bool manualISOSupported = false;
5841     //capability values are in nano sec, convert to milli sec for upper layers
5842     char expTimeStr[20];
5843     double min_exp_time = (double) m_pCapability->exposure_time_range[0] / 1000000.0;
5844     double max_exp_time = (double) m_pCapability->exposure_time_range[1] / 1000000.0;
5845     snprintf(expTimeStr, sizeof(expTimeStr), "%f", min_exp_time);
5846     set(KEY_QC_MIN_EXPOSURE_TIME, expTimeStr);
5847     snprintf(expTimeStr, sizeof(expTimeStr), "%f", max_exp_time);
5848     set(KEY_QC_MAX_EXPOSURE_TIME, expTimeStr);
5849     if ((min_exp_time > 0) && (max_exp_time > min_exp_time)) {
5850         manualExpModes.append(",");
5851         manualExpModes.append(KEY_QC_EXP_TIME_PRIORITY);
5852         expTimeSupported = true;
5853     }
5854     LOGH(", Exposure time min %f ms, max %f ms",
5855             min_exp_time, max_exp_time);
5856 
5857     // Set iso
5858     set(KEY_QC_MIN_ISO, m_pCapability->sensitivity_range.min_sensitivity);
5859     set(KEY_QC_MAX_ISO, m_pCapability->sensitivity_range.max_sensitivity);
5860     LOGH(", ISO min %d, max %d",
5861             m_pCapability->sensitivity_range.min_sensitivity,
5862             m_pCapability->sensitivity_range.max_sensitivity);
5863     if ((m_pCapability->sensitivity_range.min_sensitivity > 0) &&
5864             (m_pCapability->sensitivity_range.max_sensitivity >
5865                     m_pCapability->sensitivity_range.min_sensitivity)) {
5866         manualExpModes.append(",");
5867         manualExpModes.append(KEY_QC_ISO_PRIORITY);
5868         manualISOSupported = true;
5869     }
5870     if (expTimeSupported && manualISOSupported) {
5871         manualExpModes.append(",");
5872         manualExpModes.append(KEY_QC_USER_SETTING);
5873     }
5874     //finally set supported manual exposure modes
5875     set(KEY_QC_SUPPORTED_MANUAL_EXPOSURE_MODES, manualExpModes.string());
5876 
5877     // Set HFR
5878     String8 hfrValues = createHfrValuesString(
5879             m_pCapability->hfr_tbl,
5880             m_pCapability->hfr_tbl_cnt,
5881             HFR_MODES_MAP,
5882             PARAM_MAP_SIZE(HFR_MODES_MAP));
5883     set(KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES, hfrValues.string());
5884     set(KEY_QC_VIDEO_HIGH_SPEED_RECORDING, "off");
5885     set(KEY_QC_VIDEO_HIGH_FRAME_RATE, "off");
5886     String8 hfrSizeValues = createHfrSizesString(
5887             m_pCapability->hfr_tbl,
5888             m_pCapability->hfr_tbl_cnt);
5889     set(KEY_QC_SUPPORTED_HFR_SIZES, hfrSizeValues.string());
5890     LOGD("HFR values = %s HFR Sizes = %s", hfrValues.string(), hfrSizeValues.string());
5891     setHighFrameRate(CAM_HFR_MODE_OFF);
5892 
5893     // Set Focus algorithms
5894     String8 focusAlgoValues = createValuesString(
5895             m_pCapability->supported_focus_algos,
5896             m_pCapability->supported_focus_algos_cnt,
5897             FOCUS_ALGO_MAP,
5898             PARAM_MAP_SIZE(FOCUS_ALGO_MAP));
5899     set(KEY_QC_SUPPORTED_FOCUS_ALGOS, focusAlgoValues);
5900     setSelectableZoneAf(FOCUS_ALGO_AUTO);
5901 
5902     // Set Zoom Ratios
5903     if (m_pCapability->zoom_supported > 0) {
5904         String8 zoomRatioValues = createZoomRatioValuesString(
5905                 m_pCapability->zoom_ratio_tbl,
5906                 m_pCapability->zoom_ratio_tbl_cnt);
5907         set(KEY_ZOOM_RATIOS, zoomRatioValues);
5908         set(KEY_MAX_ZOOM, (int)(m_pCapability->zoom_ratio_tbl_cnt - 1));
5909         setZoom(0);
5910     }
5911 
5912     // Set Bracketing/HDR
5913     char prop[PROPERTY_VALUE_MAX];
5914     memset(prop, 0, sizeof(prop));
5915     property_get("persist.capture.burst.exposures", prop, "");
5916     if (strlen(prop) > 0) {
5917         set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
5918     }
5919     String8 bracketingValues = createValuesStringFromMap(
5920             BRACKETING_MODES_MAP,
5921             PARAM_MAP_SIZE(BRACKETING_MODES_MAP));
5922     set(KEY_QC_SUPPORTED_AE_BRACKET_MODES, bracketingValues);
5923     setAEBracket(AE_BRACKET_OFF);
5924 
5925     //Set AF Bracketing.
5926     for (size_t i = 0; i < m_pCapability->supported_focus_modes_cnt; i++) {
5927         if ((CAM_FOCUS_MODE_AUTO == m_pCapability->supported_focus_modes[i]) &&
5928                 ((m_pCapability->qcom_supported_feature_mask &
5929                         CAM_QCOM_FEATURE_UBIFOCUS) > 0)) {
5930             String8 afBracketingValues = createValuesStringFromMap(
5931                     AF_BRACKETING_MODES_MAP,
5932                     PARAM_MAP_SIZE(AF_BRACKETING_MODES_MAP));
5933             set(KEY_QC_SUPPORTED_AF_BRACKET_MODES, afBracketingValues);
5934             setAFBracket(AF_BRACKET_OFF);
5935             break;
5936          }
5937     }
5938 
5939     //Set Refocus.
5940     //Re-use ubifocus flag for now.
5941     for (size_t i = 0; i < m_pCapability->supported_focus_modes_cnt; i++) {
5942         if ((CAM_FOCUS_MODE_AUTO == m_pCapability->supported_focus_modes[i]) &&
5943                 (m_pCapability->qcom_supported_feature_mask &
5944                     CAM_QCOM_FEATURE_REFOCUS) > 0) {
5945             String8 reFocusValues = createValuesStringFromMap(
5946                     RE_FOCUS_MODES_MAP,
5947                     PARAM_MAP_SIZE(RE_FOCUS_MODES_MAP));
5948             set(KEY_QC_SUPPORTED_RE_FOCUS_MODES, reFocusValues);
5949             setReFocus(RE_FOCUS_OFF);
5950         }
5951     }
5952 
5953     //Set Chroma Flash.
5954     if ((m_pCapability->supported_flash_modes_cnt > 0) &&
5955             (m_pCapability->qcom_supported_feature_mask &
5956             CAM_QCOM_FEATURE_CHROMA_FLASH) > 0) {
5957         String8 chromaFlashValues = createValuesStringFromMap(
5958                 CHROMA_FLASH_MODES_MAP,
5959                 PARAM_MAP_SIZE(CHROMA_FLASH_MODES_MAP));
5960         set(KEY_QC_SUPPORTED_CHROMA_FLASH_MODES, chromaFlashValues);
5961         setChromaFlash(CHROMA_FLASH_OFF);
5962     }
5963 
5964     //Set Opti Zoom.
5965     if (m_pCapability->zoom_supported &&
5966             (m_pCapability->qcom_supported_feature_mask &
5967             CAM_QCOM_FEATURE_OPTIZOOM) > 0){
5968         String8 optiZoomValues = createValuesStringFromMap(
5969                 OPTI_ZOOM_MODES_MAP,
5970                 PARAM_MAP_SIZE(OPTI_ZOOM_MODES_MAP));
5971         set(KEY_QC_SUPPORTED_OPTI_ZOOM_MODES, optiZoomValues);
5972         setOptiZoom(OPTI_ZOOM_OFF);
5973     }
5974 
5975     //Set HDR Type
5976     uint32_t supported_hdr_modes = m_pCapability->qcom_supported_feature_mask &
5977             (CAM_QCOM_FEATURE_SENSOR_HDR | CAM_QCOM_FEATURE_HDR);
5978     if (supported_hdr_modes) {
5979         if (CAM_QCOM_FEATURE_SENSOR_HDR == supported_hdr_modes) {
5980             String8 hdrModeValues;
5981             hdrModeValues.append(HDR_MODE_SENSOR);
5982             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
5983             setHDRMode(HDR_MODE_SENSOR);
5984         } else if (CAM_QCOM_FEATURE_HDR == supported_hdr_modes) {
5985             String8 hdrModeValues;
5986             hdrModeValues.append(HDR_MODE_MULTI_FRAME);
5987             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
5988             setHDRMode(HDR_MODE_MULTI_FRAME);
5989         } else {
5990             String8 hdrModeValues = createValuesStringFromMap(
5991                     HDR_MODES_MAP,
5992                     PARAM_MAP_SIZE(HDR_MODES_MAP));
5993             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
5994             setHDRMode(HDR_MODE_MULTI_FRAME);
5995         }
5996     }
5997 
5998     //Set HDR need 1x
5999     String8 hdrNeed1xValues;
6000     if (!m_bHDRModeSensor) {
6001         hdrNeed1xValues = createValuesStringFromMap(TRUE_FALSE_MODES_MAP,
6002                 PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP));
6003     } else {
6004         hdrNeed1xValues.append(VALUE_FALSE);
6005     }
6006     setHDRNeed1x(VALUE_FALSE);
6007     set(KEY_QC_SUPPORTED_HDR_NEED_1X, hdrNeed1xValues);
6008 
6009     //Set True Portrait
6010     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_TRUEPORTRAIT) > 0) {
6011         String8 truePortraitValues = createValuesStringFromMap(
6012                 TRUE_PORTRAIT_MODES_MAP,
6013                 PARAM_MAP_SIZE(TRUE_PORTRAIT_MODES_MAP));
6014         set(KEY_QC_SUPPORTED_TRUE_PORTRAIT_MODES, truePortraitValues);
6015     }
6016 
6017     // Set Denoise
6018     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_DENOISE2D) > 0){
6019     String8 denoiseValues = createValuesStringFromMap(
6020         DENOISE_ON_OFF_MODES_MAP, PARAM_MAP_SIZE(DENOISE_ON_OFF_MODES_MAP));
6021     set(KEY_QC_SUPPORTED_DENOISE, denoiseValues.string());
6022 #ifdef DEFAULT_DENOISE_MODE_ON
6023     setWaveletDenoise(DENOISE_ON);
6024 #else
6025     setWaveletDenoise(DENOISE_OFF);
6026 #endif
6027     }
6028 
6029     // Set feature enable/disable
6030     String8 enableDisableValues = createValuesStringFromMap(
6031             ENABLE_DISABLE_MODES_MAP, PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP));
6032 
6033     // Set Lens Shading
6034     set(KEY_QC_SUPPORTED_LENSSHADE_MODES, enableDisableValues);
6035     setLensShadeValue(VALUE_ENABLE);
6036     // Set MCE
6037     set(KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES, enableDisableValues);
6038     setMCEValue(VALUE_ENABLE);
6039 
6040     // Set DIS
6041     set(KEY_QC_SUPPORTED_DIS_MODES, enableDisableValues);
6042     setDISValue(VALUE_DISABLE);
6043 
6044     // Set Histogram
6045     set(KEY_QC_SUPPORTED_HISTOGRAM_MODES,
6046         m_pCapability->histogram_supported ? enableDisableValues : "");
6047     set(KEY_QC_HISTOGRAM, VALUE_DISABLE);
6048 
6049     //Set Red Eye Reduction
6050     set(KEY_QC_SUPPORTED_REDEYE_REDUCTION, enableDisableValues);
6051     setRedeyeReduction(VALUE_DISABLE);
6052 
6053     //Set SkinTone Enhancement
6054     set(KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES, enableDisableValues);
6055 
6056     // Enable LTM by default and disable it in HDR & SeeMore usecases
6057     setToneMapMode(true, false);
6058 
6059     // Set feature on/off
6060     String8 onOffValues = createValuesStringFromMap(
6061             ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
6062 
6063     //Set See more (LLVD)
6064     if (m_pCapability->qcom_supported_feature_mask &
6065             CAM_QCOM_FEATURE_LLVD) {
6066         set(KEY_QC_SUPPORTED_SEE_MORE_MODES, onOffValues);
6067         setSeeMore(VALUE_OFF);
6068     }
6069 
6070     //Set Still more
6071     if (m_pCapability->qcom_supported_feature_mask &
6072             CAM_QCOM_FEATURE_STILLMORE) {
6073         String8 stillMoreValues = createValuesStringFromMap(
6074                 STILL_MORE_MODES_MAP,
6075                 PARAM_MAP_SIZE(STILL_MORE_MODES_MAP));
6076         set(KEY_QC_SUPPORTED_STILL_MORE_MODES, stillMoreValues);
6077         setStillMore(STILL_MORE_OFF);
6078     }
6079 
6080     //Set Noise Reduction mode
6081     if (m_pCapability->qcom_supported_feature_mask &
6082             CAM_QTI_FEATURE_SW_TNR) {
6083         String8 noiseReductionModesValues = createValuesStringFromMap(
6084                 NOISE_REDUCTION_MODES_MAP, PARAM_MAP_SIZE(NOISE_REDUCTION_MODES_MAP));
6085         set(KEY_QC_NOISE_REDUCTION_MODE_VALUES, noiseReductionModesValues);
6086         setNoiseReductionMode(VALUE_OFF);
6087     }
6088 
6089     //Set Scene Detection
6090     set(KEY_QC_SUPPORTED_SCENE_DETECT, onOffValues);
6091     setSceneDetect(VALUE_OFF);
6092     m_bHDREnabled = false;
6093     m_bHDR1xFrameEnabled = false;
6094 
6095     m_bHDRThumbnailProcessNeeded = false;
6096     m_bHDR1xExtraBufferNeeded = true;
6097     for (uint32_t i=0; i<m_pCapability->hdr_bracketing_setting.num_frames; i++) {
6098         if (0 == m_pCapability->hdr_bracketing_setting.exp_val.values[i]) {
6099             m_bHDR1xExtraBufferNeeded = false;
6100             break;
6101         }
6102     }
6103 
6104     // Set HDR output scaling
6105     char value[PROPERTY_VALUE_MAX];
6106 
6107     property_get("persist.camera.hdr.outcrop", value, VALUE_DISABLE);
6108     if (strncmp(VALUE_ENABLE, value, sizeof(VALUE_ENABLE))) {
6109       m_bHDROutputCropEnabled = false;
6110     } else {
6111       m_bHDROutputCropEnabled = true;
6112     }
6113 
6114     //Set Face Detection
6115     set(KEY_QC_SUPPORTED_FACE_DETECTION, onOffValues);
6116     set(KEY_QC_FACE_DETECTION, VALUE_OFF);
6117 
6118     //Set Face Recognition
6119     //set(KEY_QC_SUPPORTED_FACE_RECOGNITION, onOffValues);
6120     //set(KEY_QC_FACE_RECOGNITION, VALUE_OFF);
6121 
6122     //Set ZSL
6123     set(KEY_QC_SUPPORTED_ZSL_MODES, onOffValues);
6124 #ifdef DEFAULT_ZSL_MODE_ON
6125     set(KEY_QC_ZSL, VALUE_ON);
6126     m_bZslMode = true;
6127 #else
6128     set(KEY_QC_ZSL, VALUE_OFF);
6129     m_bZslMode = false;
6130 #endif
6131 
6132     // Check if zsl mode property is enabled.
6133     // If yes, force the camera to be in zsl mode
6134     // and force zsl mode to be enabled in dual camera mode.
6135     memset(value, 0x0, PROPERTY_VALUE_MAX);
6136     property_get("persist.camera.zsl.mode", value, "0");
6137     int32_t zsl_mode = atoi(value);
6138     if((zsl_mode == 1) ||
6139             (m_bZslMode == true) ||
6140             (m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON)) {
6141         LOGH("%d: Forcing Camera to ZSL mode enabled");
6142         set(KEY_QC_ZSL, VALUE_ON);
6143         m_bForceZslMode = true;
6144         m_bZslMode = true;
6145         int32_t value = m_bForceZslMode;
6146         ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value);
6147     }
6148     m_bZslMode_new = m_bZslMode;
6149 
6150     set(KEY_QC_SCENE_SELECTION, VALUE_DISABLE);
6151 
6152     // Rdi mode
6153     set(KEY_QC_SUPPORTED_RDI_MODES, enableDisableValues);
6154     setRdiMode(VALUE_DISABLE);
6155 
6156     // Secure mode
6157     set(KEY_QC_SUPPORTED_SECURE_MODES, enableDisableValues);
6158     setSecureMode(VALUE_DISABLE);
6159 
6160     //Set video HDR
6161     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_VIDEO_HDR) > 0) {
6162         set(KEY_QC_SUPPORTED_VIDEO_HDR_MODES, onOffValues);
6163         set(KEY_QC_VIDEO_HDR, VALUE_OFF);
6164     }
6165 
6166     //Set HW Sensor Snapshot HDR
6167     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_SENSOR_HDR)> 0) {
6168         set(KEY_QC_SUPPORTED_SENSOR_HDR_MODES, onOffValues);
6169         set(KEY_QC_SENSOR_HDR, VALUE_OFF);
6170         m_bSensorHDREnabled = false;
6171     }
6172 
6173     // Set VT TimeStamp
6174     set(KEY_QC_VT_ENABLE, VALUE_DISABLE);
6175     //Set Touch AF/AEC
6176     String8 touchValues = createValuesStringFromMap(
6177             TOUCH_AF_AEC_MODES_MAP, PARAM_MAP_SIZE(TOUCH_AF_AEC_MODES_MAP));
6178 
6179     set(KEY_QC_SUPPORTED_TOUCH_AF_AEC, touchValues);
6180     set(KEY_QC_TOUCH_AF_AEC, TOUCH_AF_AEC_OFF);
6181 
6182     //set flip mode
6183     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) > 0) {
6184         String8 flipModes = createValuesStringFromMap(
6185                 FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP));
6186         set(KEY_QC_SUPPORTED_FLIP_MODES, flipModes);
6187         set(KEY_QC_PREVIEW_FLIP, FLIP_MODE_OFF);
6188         set(KEY_QC_VIDEO_FLIP, FLIP_MODE_OFF);
6189         set(KEY_QC_SNAPSHOT_PICTURE_FLIP, FLIP_MODE_OFF);
6190     }
6191 
6192     // Set default Auto Exposure lock value
6193     setAecLock(VALUE_FALSE);
6194 
6195     // Set default AWB_LOCK lock value
6196     setAwbLock(VALUE_FALSE);
6197 
6198     // Set default Camera mode
6199     set(KEY_QC_CAMERA_MODE, 0);
6200 
6201     // Add support for internal preview restart
6202     set(KEY_INTERNAL_PERVIEW_RESTART, VALUE_TRUE);
6203     // Set default burst number
6204     set(KEY_QC_SNAPSHOT_BURST_NUM, 0);
6205     set(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER, 0);
6206 
6207     //Get RAM size and disable features which are memory rich
6208     struct sysinfo info;
6209     sysinfo(&info);
6210 
6211     LOGH("totalram = %ld, freeram = %ld ", info.totalram,
6212         info.freeram);
6213     if (info.totalram > TOTAL_RAM_SIZE_512MB) {
6214         set(KEY_QC_ZSL_HDR_SUPPORTED, VALUE_TRUE);
6215     } else {
6216         m_bIsLowMemoryDevice = true;
6217         set(KEY_QC_ZSL_HDR_SUPPORTED, VALUE_FALSE);
6218     }
6219 
6220     setOfflineRAW();
6221     memset(mStreamPpMask, 0, sizeof(cam_feature_mask_t)*CAM_STREAM_TYPE_MAX);
6222     //Set video buffers as uncached by default
6223     set(KEY_QC_CACHE_VIDEO_BUFFERS, VALUE_DISABLE);
6224 
6225     // Set default longshot mode
6226     set(KEY_QC_LONG_SHOT, "off");
6227     //Enable longshot by default
6228     set(KEY_QC_LONGSHOT_SUPPORTED, VALUE_TRUE);
6229 
6230     int32_t rc = commitParameters();
6231     if (rc == NO_ERROR) {
6232         rc = setNumOfSnapshot();
6233     }
6234 
6235     //Set Video Rotation
6236     String8 videoRotationValues;
6237     if (m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_ROTATION) {
6238         videoRotationValues = createValuesStringFromMap(VIDEO_ROTATION_MODES_MAP,
6239                 PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP));
6240         set(KEY_QC_SUPPORTED_VIDEO_ROTATION_VALUES, videoRotationValues.string());
6241     }
6242     set(KEY_QC_VIDEO_ROTATION, VIDEO_ROTATION_0);
6243 
6244     String8 metadataTypeValues = createValuesStringFromMap(METADATA_TYPES_MAP,
6245         PARAM_MAP_SIZE(METADATA_TYPES_MAP));
6246     set(KEY_QC_SUPPORTED_METADATA_TYPES, metadataTypeValues);
6247 
6248     //Check for EZTune
6249     setEztune();
6250     //Default set for video batch size
6251     set(KEY_QC_VIDEO_BATCH_SIZE, 0);
6252 
6253     //Setup dual-camera
6254     setDcrf();
6255     setSyncDCParams();
6256 
6257     // For Aux Camera of dual camera Mode,
6258     // by default set no display mode
6259     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
6260         set(KEY_QC_NO_DISPLAY_MODE, 1);
6261         m_bNoDisplayMode = true;
6262     }
6263 
6264     cam_dimension_t pic_dim;
6265     pic_dim.width = 0;
6266     pic_dim.height = 0;
6267 
6268     if (m_pCapability->picture_sizes_tbl_cnt > 0 &&
6269         m_pCapability->picture_sizes_tbl_cnt <= MAX_SIZES_CNT) {
6270         for(uint32_t i = 0;
6271                 i < m_pCapability->picture_sizes_tbl_cnt; i++) {
6272             if ((pic_dim.width * pic_dim.height) <
6273                     (int32_t)(m_pCapability->picture_sizes_tbl[i].width *
6274                     m_pCapability->picture_sizes_tbl[i].height)) {
6275                 pic_dim.width =
6276                         m_pCapability->picture_sizes_tbl[i].width;
6277                 pic_dim.height =
6278                         m_pCapability->picture_sizes_tbl[i].height;
6279             }
6280         }
6281         LOGD("max pic size = %d %d", pic_dim.width,
6282                 pic_dim.height);
6283         setMaxPicSize(pic_dim);
6284     } else {
6285         LOGW("supported picture sizes cnt is 0 or exceeds max!!!");
6286     }
6287 
6288     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF);
6289     return rc;
6290 }
6291 
6292 /*===========================================================================
6293  * FUNCTION   : allocate
6294  *
6295  * DESCRIPTION: Allocate buffer memory for parameter obj (if necessary)
6296  *
6297  * PARAMETERS : none
6298  *
6299  * RETURN     : int32_t type of status
6300  *              NO_ERROR  -- success
6301  *              none-zero failure code
6302  *==========================================================================*/
allocate(uint8_t bufCount)6303 int32_t QCameraParameters::allocate(uint8_t bufCount)
6304 {
6305     int32_t rc = NO_ERROR;
6306 
6307     if (m_pParamHeap != NULL) {
6308         return rc;
6309     }
6310 
6311     //Allocate Set Param Buffer
6312     m_pParamHeap = new QCameraHeapMemory(QCAMERA_ION_USE_CACHE);
6313     if (m_pParamHeap == NULL) {
6314         return NO_MEMORY;
6315     }
6316 
6317     rc = m_pParamHeap->allocate(bufCount, sizeof(parm_buffer_t));
6318     if(rc != OK) {
6319         rc = NO_MEMORY;
6320         LOGE("Error!! Param buffers have not been allocated");
6321         delete m_pParamHeap;
6322         m_pParamHeap = NULL;
6323     }
6324     return rc;
6325 }
6326 
6327 /*===========================================================================
6328  * FUNCTION   : init
6329  *
6330  * DESCRIPTION: initialize parameter obj
6331  *
6332  * PARAMETERS :
6333  *   @capabilities  : ptr to camera capabilities
6334  *   @mmops         : ptr to memory ops table for mapping/unmapping
6335  *   @adjustFPS     : object reference for additional (possibly thermal)
6336  *                    framerate adjustment
6337  *
6338  * RETURN     : int32_t type of status
6339  *              NO_ERROR  -- success
6340  *              none-zero failure code
6341  *==========================================================================*/
init(cam_capability_t * capabilities,mm_camera_vtbl_t * mmOps,QCameraAdjustFPS * adjustFPS,QCameraFOVControl * fovControl)6342 int32_t QCameraParameters::init(cam_capability_t *capabilities, mm_camera_vtbl_t *mmOps,
6343         QCameraAdjustFPS *adjustFPS, QCameraFOVControl *fovControl)
6344 {
6345     int32_t rc = NO_ERROR;
6346     uint8_t buf_cnt = 1;
6347 
6348     m_pCapability = capabilities;
6349     m_pCamOpsTbl  = mmOps;
6350     m_AdjustFPS   = adjustFPS;
6351     m_pFovControl = fovControl;
6352 
6353     if (m_pParamHeap == NULL) {
6354         LOGE("Parameter buffers have not been allocated");
6355         rc = UNKNOWN_ERROR;
6356         goto TRANS_INIT_ERROR1;
6357     }
6358 
6359     m_bDualCamera = is_dual_camera_by_handle(mmOps->camera_handle);
6360     cam_buf_map_type_list bufMapList;
6361     rc = QCameraBufferMaps::makeSingletonBufMapList(
6362             CAM_MAPPING_BUF_TYPE_PARM_BUF, 0 /*stream id*/,
6363             0 /*buffer index*/, -1 /*plane index*/, 0 /*cookie*/,
6364             m_pParamHeap->getFd(0), sizeof(parm_buffer_t), bufMapList,
6365                     m_pParamHeap->getPtr(0));
6366     if (rc == NO_ERROR) {
6367         rc = m_pCamOpsTbl->ops->map_bufs(m_pCamOpsTbl->camera_handle,
6368                 &bufMapList);
6369     }
6370     if(rc < 0) {
6371         LOGE("failed to map SETPARM buffer");
6372         rc = FAILED_TRANSACTION;
6373         goto TRANS_INIT_ERROR2;
6374     }
6375 
6376     m_pParamBuf = (parm_buffer_t*) DATA_PTR(m_pParamHeap, 0);
6377     mActiveCameras = MM_CAMERA_TYPE_MAIN;
6378     if (isDualCamera()) {
6379         mActiveCameras |= MM_CAMERA_TYPE_AUX;
6380         memset(&bufMapList, 0, sizeof(cam_buf_map_type_list));
6381         rc = QCameraBufferMaps::makeSingletonBufMapList(
6382                 CAM_MAPPING_BUF_TYPE_PARM_BUF, 0 /*stream id*/,
6383                 0 /*buffer index*/, -1 /*plane index*/, 0 /*cookie*/,
6384                 m_pParamHeap->getFd(1), sizeof(parm_buffer_t), bufMapList,
6385                         m_pParamHeap->getPtr(1));
6386         if (rc == NO_ERROR) {
6387             rc = m_pCamOpsTbl->ops->map_bufs(
6388                     get_aux_camera_handle(m_pCamOpsTbl->camera_handle),
6389                     &bufMapList);
6390         }
6391         if(rc < 0) {
6392             LOGE("failed to map SETPARM buffer");
6393             rc = FAILED_TRANSACTION;
6394             goto TRANS_INIT_ERROR2;
6395         }
6396         m_pParamBufAux = (parm_buffer_t*)DATA_PTR(m_pParamHeap, 1);
6397     }
6398 
6399     //Handle Dual camera cmd buffer
6400     if (m_bDualCamera) {
6401         buf_cnt = MM_CAMERA_MAX_CAM_CNT;
6402     }
6403 
6404     m_pDualCamCmdHeap = new QCameraHeapMemory(QCAMERA_ION_USE_CACHE);
6405     rc = m_pDualCamCmdHeap->allocate(buf_cnt,
6406             sizeof(cam_dual_camera_cmd_info_t));
6407     if(rc != OK) {
6408         rc = NO_MEMORY;
6409         LOGE("Failed to allocate dual cam Heap memory");
6410         goto TRANS_INIT_ERROR3;
6411     }
6412 
6413     for (int i = 0; i < buf_cnt; i++) {
6414         m_pDualCamCmdPtr[i] = (cam_dual_camera_cmd_info_t *)
6415                 DATA_PTR(m_pDualCamCmdHeap, i);
6416     }
6417 
6418     //Map memory for related cam sync buffer
6419     rc = m_pCamOpsTbl->ops->map_buf(
6420             get_main_camera_handle(m_pCamOpsTbl->camera_handle),
6421             CAM_MAPPING_BUF_TYPE_DUAL_CAM_CMD_BUF,
6422             m_pDualCamCmdHeap->getFd(0),
6423             sizeof(cam_dual_camera_cmd_info_t),
6424             m_pDualCamCmdPtr[0]);
6425     if(rc < 0) {
6426         LOGE("failed to map Related cam sync buffer");
6427         rc = FAILED_TRANSACTION;
6428         goto TRANS_INIT_ERROR4;
6429     }
6430 
6431     if (m_bDualCamera) {
6432         rc = m_pCamOpsTbl->ops->map_buf(
6433                 get_aux_camera_handle(m_pCamOpsTbl->camera_handle),
6434                 CAM_MAPPING_BUF_TYPE_DUAL_CAM_CMD_BUF,
6435                 m_pDualCamCmdHeap->getFd(1),
6436                 sizeof(cam_dual_camera_cmd_info_t),
6437                 m_pDualCamCmdPtr[1]);
6438         if(rc < 0) {
6439             LOGE("failed to map Related cam sync buffer");
6440             rc = FAILED_TRANSACTION;
6441             goto TRANS_INIT_ERROR4;
6442         }
6443     }
6444     rc = m_pCamOpsTbl->ops->get_session_id(m_pCamOpsTbl->camera_handle,
6445             &sessionId[m_pCapability->camera_index]);
6446 
6447     initDefaultParameters();
6448     mCommon.init(capabilities);
6449     m_bInited = true;
6450 
6451     goto TRANS_INIT_DONE;
6452 
6453 TRANS_INIT_ERROR4:
6454     m_pDualCamCmdHeap->deallocate();
6455 
6456 TRANS_INIT_ERROR3:
6457     delete m_pDualCamCmdHeap;
6458     m_pDualCamCmdHeap = NULL;
6459 
6460 TRANS_INIT_ERROR2:
6461     m_pParamHeap->deallocate();
6462     delete m_pParamHeap;
6463     m_pParamHeap = NULL;
6464 
6465 TRANS_INIT_ERROR1:
6466     m_pCapability = NULL;
6467     m_pCamOpsTbl = NULL;
6468     m_AdjustFPS = NULL;
6469 
6470 TRANS_INIT_DONE:
6471     return rc;
6472 }
6473 
6474 /*===========================================================================
6475  * FUNCTION   : deinit
6476  *
6477  * DESCRIPTION: deinitialize
6478  *
6479  * PARAMETERS : none
6480  *
6481  * RETURN     : none
6482  *==========================================================================*/
deinit()6483 void QCameraParameters::deinit()
6484 {
6485     if (NULL != m_pParamHeap) {
6486         m_pParamHeap->deallocate();
6487         delete m_pParamHeap;
6488         m_pParamHeap = NULL;
6489         m_pParamBuf = NULL;
6490         m_pParamBufAux = NULL;
6491     }
6492 
6493     if (!m_bInited) {
6494         return;
6495     }
6496 
6497     //clear all entries in the map
6498     String8 emptyStr;
6499     QCameraParameters::unflatten(emptyStr);
6500 
6501     if ((NULL != m_pCamOpsTbl) && (m_pCamOpsTbl->ops != NULL)) {
6502         m_pCamOpsTbl->ops->unmap_buf(
6503                              m_pCamOpsTbl->camera_handle,
6504                              CAM_MAPPING_BUF_TYPE_PARM_BUF);
6505         m_pCamOpsTbl->ops->unmap_buf(
6506                 get_main_camera_handle(m_pCamOpsTbl->camera_handle),
6507                 CAM_MAPPING_BUF_TYPE_DUAL_CAM_CMD_BUF);
6508         if (isDualCamera()) {
6509             m_pCamOpsTbl->ops->unmap_buf(
6510                     get_aux_camera_handle(m_pCamOpsTbl->camera_handle),
6511                     CAM_MAPPING_BUF_TYPE_DUAL_CAM_CMD_BUF);
6512         }
6513     }
6514 
6515     m_pCapability = NULL;
6516     if (NULL != m_pDualCamCmdHeap) {
6517         m_pDualCamCmdHeap->deallocate();
6518         delete m_pDualCamCmdHeap;
6519         m_pDualCamCmdHeap = NULL;
6520         memset(m_pDualCamCmdPtr, 0, sizeof(m_pDualCamCmdPtr));
6521     }
6522 
6523     m_tempMap.clear();
6524     m_pCamOpsTbl = NULL;
6525     m_AdjustFPS = NULL;
6526 
6527     m_bInited = false;
6528 }
6529 
6530 /*===========================================================================
6531  * FUNCTION   : parse_pair
6532  *
6533  * DESCRIPTION: helper function to parse string like "640x480" or "10000,20000"
6534  *
6535  * PARAMETERS :
6536  *   @str     : input string to be parse
6537  *   @first   : [output] first value of the pair
6538  *   @second  : [output]  second value of the pair
6539  *   @delim   : [input] delimeter to seperate the pair
6540  *   @endptr  : [output] ptr to the end of the pair string
6541  *
6542  * RETURN     : int32_t type of status
6543  *              NO_ERROR  -- success
6544  *              none-zero failure code
6545  *==========================================================================*/
parse_pair(const char * str,int * first,int * second,char delim,char ** endptr=NULL)6546 int32_t QCameraParameters::parse_pair(const char *str,
6547                                       int *first,
6548                                       int *second,
6549                                       char delim,
6550                                       char **endptr = NULL)
6551 {
6552     // Find the first integer.
6553     char *end;
6554     int w = (int)strtol(str, &end, 10);
6555     // If a delimeter does not immediately follow, give up.
6556     if (*end != delim) {
6557         LOGE("Cannot find delimeter (%c) in str=%s", delim, str);
6558         return BAD_VALUE;
6559     }
6560 
6561     // Find the second integer, immediately after the delimeter.
6562     int h = (int)strtol(end+1, &end, 10);
6563 
6564     *first = w;
6565     *second = h;
6566 
6567     if (endptr) {
6568         *endptr = end;
6569     }
6570 
6571     return NO_ERROR;
6572 }
6573 
6574 /*===========================================================================
6575  * FUNCTION   : parseSizesList
6576  *
6577  * DESCRIPTION: helper function to parse string containing sizes
6578  *
6579  * PARAMETERS :
6580  *   @sizesStr: [input] input string to be parse
6581  *   @sizes   : [output] reference to store parsed sizes
6582  *
6583  * RETURN     : none
6584  *==========================================================================*/
parseSizesList(const char * sizesStr,Vector<Size> & sizes)6585 void QCameraParameters::parseSizesList(const char *sizesStr, Vector<Size> &sizes)
6586 {
6587     if (sizesStr == 0) {
6588         return;
6589     }
6590 
6591     char *sizeStartPtr = (char *)sizesStr;
6592 
6593     while (true) {
6594         int width, height;
6595         int success = parse_pair(sizeStartPtr, &width, &height, 'x',
6596                                  &sizeStartPtr);
6597         if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
6598             LOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
6599             return;
6600         }
6601         sizes.push(Size(width, height));
6602 
6603         if (*sizeStartPtr == '\0') {
6604             return;
6605         }
6606         sizeStartPtr++;
6607     }
6608 }
6609 
6610 /*===========================================================================
6611  * FUNCTION   : adjustPreviewFpsRange
6612  *
6613  * DESCRIPTION: adjust preview FPS ranges
6614  *              according to external events
6615  *
6616  * PARAMETERS :
6617  *   @minFPS  : min FPS value
6618  *   @maxFPS  : max FPS value
6619  *
6620  * RETURN     : int32_t type of status
6621  *              NO_ERROR  -- success
6622  *              none-zero failure code
6623  *==========================================================================*/
adjustPreviewFpsRange(cam_fps_range_t * fpsRange)6624 int32_t QCameraParameters::adjustPreviewFpsRange(cam_fps_range_t *fpsRange)
6625 {
6626     if ( fpsRange == NULL ) {
6627         return BAD_VALUE;
6628     }
6629 
6630     if ( m_pParamBuf == NULL ) {
6631         return NO_INIT;
6632     }
6633 
6634     int32_t rc = initBatchUpdate();
6635     if ( rc != NO_ERROR ) {
6636         LOGE("Failed to initialize group update table");
6637         return rc;
6638     }
6639 
6640     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FPS_RANGE, *fpsRange)) {
6641         LOGE("Parameters batch failed");
6642         return BAD_VALUE;
6643     }
6644 
6645     rc = commitSetBatch();
6646     if ( rc != NO_ERROR ) {
6647         LOGE("Failed to commit batch parameters");
6648         return rc;
6649     }
6650 
6651     return rc;
6652 }
6653 
6654 /*===========================================================================
6655  * FUNCTION   : setPreviewFpsRanges
6656  *
6657  * DESCRIPTION: set preview FPS ranges
6658  *
6659  * PARAMETERS :
6660  *   @minFPS  : min FPS value
6661  *   @maxFPS  : max FPS value
6662  *
6663  * RETURN     : int32_t type of status
6664  *              NO_ERROR  -- success
6665  *              none-zero failure code
6666  *==========================================================================*/
setPreviewFpsRange(int min_fps,int max_fps,int vid_min_fps,int vid_max_fps)6667 int32_t QCameraParameters::setPreviewFpsRange(int min_fps,
6668         int max_fps, int vid_min_fps,int vid_max_fps)
6669 {
6670     char str[32];
6671     char value[PROPERTY_VALUE_MAX];
6672     int fixedFpsValue;
6673     /*This property get value should be the fps that user needs*/
6674     property_get("persist.debug.set.fixedfps", value, "0");
6675     fixedFpsValue = atoi(value);
6676 
6677     LOGD("E minFps = %d, maxFps = %d , vid minFps = %d, vid maxFps = %d",
6678                  min_fps, max_fps, vid_min_fps, vid_max_fps);
6679 
6680     if(fixedFpsValue != 0) {
6681         min_fps = max_fps = fixedFpsValue*1000;
6682         if (!isHfrMode()) {
6683              vid_min_fps = vid_max_fps = fixedFpsValue*1000;
6684         }
6685     }
6686     snprintf(str, sizeof(str), "%d,%d", min_fps, max_fps);
6687     LOGH("Setting preview fps range %s", str);
6688     updateParamEntry(KEY_PREVIEW_FPS_RANGE, str);
6689     cam_fps_range_t fps_range;
6690     memset(&fps_range, 0x00, sizeof(cam_fps_range_t));
6691     fps_range.min_fps = (float)min_fps / 1000.0f;
6692     fps_range.max_fps = (float)max_fps / 1000.0f;
6693     fps_range.video_min_fps = (float)vid_min_fps / 1000.0f;
6694     fps_range.video_max_fps = (float)vid_max_fps / 1000.0f;
6695 
6696     LOGH("Updated: minFps = %d, maxFps = %d ,"
6697             " vid minFps = %d, vid maxFps = %d",
6698              min_fps, max_fps, vid_min_fps, vid_max_fps);
6699 
6700     if ( NULL != m_AdjustFPS ) {
6701         if (m_ThermalMode == QCAMERA_THERMAL_ADJUST_FPS &&
6702                 !m_bRecordingHint_new) {
6703             float minVideoFps = min_fps, maxVideoFps = max_fps;
6704             if (isHfrMode()) {
6705                 minVideoFps = m_hfrFpsRange.video_min_fps;
6706                 maxVideoFps = m_hfrFpsRange.video_max_fps;
6707             }
6708             m_AdjustFPS->recalcFPSRange(min_fps, max_fps, minVideoFps,
6709                                          maxVideoFps, fps_range, m_bRecordingHint_new);
6710             LOGH("Thermal adjusted Preview fps range %3.2f,%3.2f, %3.2f, %3.2f",
6711                    fps_range.min_fps, fps_range.max_fps,
6712                   fps_range.video_min_fps, fps_range.video_max_fps);
6713         }
6714     }
6715 
6716     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FPS_RANGE, fps_range)) {
6717         return BAD_VALUE;
6718     }
6719 
6720     return NO_ERROR;
6721 }
6722 
6723 
6724 
6725 /*===========================================================================
6726  * FUNCTION   : setAutoExposure
6727  *
6728  * DESCRIPTION: set auto exposure
6729  *
6730  * PARAMETERS :
6731  *   @autoExp : auto exposure value string
6732  *
6733  * RETURN     : int32_t type of status
6734  *              NO_ERROR  -- success
6735  *              none-zero failure code
6736  *==========================================================================*/
setAutoExposure(const char * autoExp)6737 int32_t QCameraParameters::setAutoExposure(const char *autoExp)
6738 {
6739     if (autoExp != NULL) {
6740         int32_t value = lookupAttr(AUTO_EXPOSURE_MAP, PARAM_MAP_SIZE(AUTO_EXPOSURE_MAP), autoExp);
6741         if (value != NAME_NOT_FOUND) {
6742             LOGH("Setting auto exposure %s", autoExp);
6743             updateParamEntry(KEY_QC_AUTO_EXPOSURE, autoExp);
6744             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_ALGO_TYPE, value)) {
6745                 return BAD_VALUE;
6746             }
6747             return NO_ERROR;
6748         }
6749     }
6750     LOGE("Invalid auto exposure value: %s", (autoExp == NULL) ? "NULL" : autoExp);
6751     return BAD_VALUE;
6752 }
6753 
6754 /*===========================================================================
6755  * FUNCTION   : setEffect
6756  *
6757  * DESCRIPTION: set effect
6758  *
6759  * PARAMETERS :
6760  *   @effect  : effect value string
6761  *
6762  * RETURN     : int32_t type of status
6763  *              NO_ERROR  -- success
6764  *              none-zero failure code
6765  *==========================================================================*/
setEffect(const char * effect)6766 int32_t QCameraParameters::setEffect(const char *effect)
6767 {
6768     if (effect != NULL) {
6769         int32_t value = lookupAttr(EFFECT_MODES_MAP, PARAM_MAP_SIZE(EFFECT_MODES_MAP), effect);
6770         if (value != NAME_NOT_FOUND) {
6771             LOGH("Setting effect %s", effect);
6772             updateParamEntry(KEY_EFFECT, effect);
6773             uint8_t prmEffect = static_cast<uint8_t>(value);
6774             mParmEffect = prmEffect;
6775             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EFFECT, prmEffect)) {
6776                 return BAD_VALUE;
6777             }
6778             return NO_ERROR;
6779         }
6780     }
6781     LOGE("Invalid effect value: %s", (effect == NULL) ? "NULL" : effect);
6782     return BAD_VALUE;
6783 }
6784 
6785 /*===========================================================================
6786  * FUNCTION   : setBrightness
6787  *
6788  * DESCRIPTION: set brightness control value
6789  *
6790  * PARAMETERS :
6791  *   @brightness  : brightness control value
6792  *
6793  * RETURN     : int32_t type of status
6794  *              NO_ERROR  -- success
6795  *              none-zero failure code
6796  *==========================================================================*/
setBrightness(int brightness)6797 int32_t QCameraParameters::setBrightness(int brightness)
6798 {
6799     char val[16];
6800     snprintf(val, sizeof(val), "%d", brightness);
6801     updateParamEntry(KEY_QC_BRIGHTNESS, val);
6802 
6803     LOGH("Setting brightness %s", val);
6804     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BRIGHTNESS, brightness)) {
6805         return BAD_VALUE;
6806     }
6807 
6808     return NO_ERROR;
6809 }
6810 
6811 /*===========================================================================
6812  * FUNCTION   : setFocusMode
6813  *
6814  * DESCRIPTION: set focus mode
6815  *
6816  * PARAMETERS :
6817  *   @focusMode  : focus mode value string
6818  *
6819  * RETURN     : int32_t type of status
6820  *              NO_ERROR  -- success
6821  *              none-zero failure code
6822  *==========================================================================*/
setFocusMode(const char * focusMode)6823 int32_t QCameraParameters::setFocusMode(const char *focusMode)
6824 {
6825     if (focusMode != NULL) {
6826         int32_t value = lookupAttr(FOCUS_MODES_MAP, PARAM_MAP_SIZE(FOCUS_MODES_MAP), focusMode);
6827         if (value != NAME_NOT_FOUND) {
6828             int32_t rc = NO_ERROR;
6829             LOGH("Setting focus mode %s", focusMode);
6830             mFocusMode = (cam_focus_mode_type)value;
6831 
6832             updateParamEntry(KEY_FOCUS_MODE, focusMode);
6833             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
6834                     CAM_INTF_PARM_FOCUS_MODE, (uint8_t)value)) {
6835                 rc = BAD_VALUE;
6836             }
6837             if (strcmp(focusMode,"infinity")==0){
6838                 set(QCameraParameters::KEY_FOCUS_DISTANCES, "Infinity,Infinity,Infinity");
6839             }
6840             return rc;
6841         }
6842     }
6843     LOGE("Invalid focus mode value: %s", (focusMode == NULL) ? "NULL" : focusMode);
6844     return BAD_VALUE;
6845 }
6846 
6847 /*===========================================================================
6848  * FUNCTION   : setFocusPosition
6849  *
6850  * DESCRIPTION: set focus position
6851  *
6852  * PARAMETERS :
6853  *   @typeStr : focus position type, index or dac_code
6854  *   @posStr : focus positon.
6855  *
6856  * RETURN     : int32_t type of status
6857  *              NO_ERROR  -- success
6858  *              none-zero failure code
6859  *==========================================================================*/
setFocusPosition(const char * typeStr,const char * posStr)6860 int32_t  QCameraParameters::setFocusPosition(const char *typeStr, const char *posStr)
6861 {
6862     LOGH(", type:%s, pos: %s", typeStr, posStr);
6863     int32_t type = atoi(typeStr);
6864     float pos = (float) atof(posStr);
6865 
6866     if ((type >= CAM_MANUAL_FOCUS_MODE_INDEX) &&
6867             (type < CAM_MANUAL_FOCUS_MODE_MAX)) {
6868         // get max and min focus position from m_pCapability
6869         float minFocusPos = m_pCapability->min_focus_pos[type];
6870         float maxFocusPos = m_pCapability->max_focus_pos[type];
6871         LOGH(", focusPos min: %f, max: %f", minFocusPos, maxFocusPos);
6872 
6873         if (pos >= minFocusPos && pos <= maxFocusPos) {
6874             updateParamEntry(KEY_QC_MANUAL_FOCUS_POS_TYPE, typeStr);
6875             updateParamEntry(KEY_QC_MANUAL_FOCUS_POSITION, posStr);
6876 
6877             cam_manual_focus_parm_t manual_focus;
6878             manual_focus.flag = (cam_manual_focus_mode_type)type;
6879             if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_DIOPTER) {
6880                 manual_focus.af_manual_diopter = pos;
6881             } else if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_RATIO) {
6882                 manual_focus.af_manual_lens_position_ratio = (int32_t) pos;
6883             } else if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_INDEX) {
6884                 manual_focus.af_manual_lens_position_index = (int32_t) pos;
6885             } else {
6886                 manual_focus.af_manual_lens_position_dac = (int32_t) pos;
6887             }
6888 
6889             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MANUAL_FOCUS_POS,
6890                     manual_focus)) {
6891                 return BAD_VALUE;
6892             }
6893             return NO_ERROR;
6894         }
6895     }
6896 
6897     LOGE("invalid params, type:%d, pos: %f", type, pos);
6898     return BAD_VALUE;
6899 }
6900 
6901 /*===========================================================================
6902  * FUNCTION   : updateAEInfo
6903  *
6904  * DESCRIPTION: update exposure information from metadata callback
6905  *
6906  * PARAMETERS :
6907  *   @ae_params : auto exposure params
6908  *
6909  * RETURN     : void
6910  *==========================================================================*/
updateAEInfo(cam_3a_params_t & ae_params)6911 void  QCameraParameters::updateAEInfo(cam_3a_params_t &ae_params)
6912 {
6913     const char *prevExpTime = get(KEY_QC_CURRENT_EXPOSURE_TIME);
6914     char newExpTime[15];
6915     snprintf(newExpTime, sizeof(newExpTime), "%f", ae_params.exp_time*1000.0);
6916 
6917     if (prevExpTime == NULL || strcmp(prevExpTime, newExpTime)) {
6918         LOGD("update exposure time: old: %s, new: %s", prevExpTime, newExpTime);
6919         set(KEY_QC_CURRENT_EXPOSURE_TIME, newExpTime);
6920     }
6921 
6922     int32_t prevISO = getInt(KEY_QC_CURRENT_ISO);
6923     int32_t newISO = ae_params.iso_value;
6924     if (prevISO != newISO) {
6925         LOGD("update iso: old:%d, new:%d", prevISO, newISO);
6926         set(KEY_QC_CURRENT_ISO, newISO);
6927     }
6928 }
6929 
6930 /*===========================================================================
6931  * FUNCTION   : updateCurrentFocusPosition
6932  *
6933  * DESCRIPTION: update current focus position from metadata callback
6934  *
6935  * PARAMETERS :
6936  *   @pos : current focus position
6937  *
6938  * RETURN     : void
6939  *==========================================================================*/
updateCurrentFocusPosition(cam_focus_pos_info_t & cur_pos_info)6940 void  QCameraParameters::updateCurrentFocusPosition(cam_focus_pos_info_t &cur_pos_info)
6941 {
6942     int prevScalePos = getInt(KEY_QC_FOCUS_POSITION_SCALE);
6943     int newScalePos = (int) cur_pos_info.scale;
6944     if (prevScalePos != newScalePos) {
6945         LOGD("update focus scale: old:%d, new:%d", prevScalePos, newScalePos);
6946         set(KEY_QC_FOCUS_POSITION_SCALE, newScalePos);
6947     }
6948 
6949     float prevDiopterPos = getFloat(KEY_QC_FOCUS_POSITION_DIOPTER);
6950     float newDiopterPos = cur_pos_info.diopter;
6951     if (prevDiopterPos != newDiopterPos) {
6952         LOGD("update focus diopter: old:%f, new:%f", prevDiopterPos, newDiopterPos);
6953         setFloat(KEY_QC_FOCUS_POSITION_DIOPTER, newDiopterPos);
6954     }
6955 }
6956 
6957 /*===========================================================================
6958  * FUNCTION   : setSharpness
6959  *
6960  * DESCRIPTION: set sharpness control value
6961  *
6962  * PARAMETERS :
6963  *   @sharpness  : sharpness control value
6964  *
6965  * RETURN     : int32_t type of status
6966  *              NO_ERROR  -- success
6967  *              none-zero failure code
6968  *==========================================================================*/
setSharpness(int sharpness)6969 int32_t QCameraParameters::setSharpness(int sharpness)
6970 {
6971     char val[16];
6972     snprintf(val, sizeof(val), "%d", sharpness);
6973     updateParamEntry(KEY_QC_SHARPNESS, val);
6974     LOGH("Setting sharpness %s", val);
6975     m_nSharpness = sharpness;
6976     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SHARPNESS, m_nSharpness)) {
6977         return BAD_VALUE;
6978     }
6979 
6980     return NO_ERROR;
6981 }
6982 
6983 /*===========================================================================
6984  * FUNCTION   : setSkinToneEnhancement
6985  *
6986  * DESCRIPTION: set skin tone enhancement value
6987  *
6988  * PARAMETERS :
6989  *   @sceFactore  : skin tone enhancement factor value
6990  *
6991  * RETURN     : int32_t type of status
6992  *              NO_ERROR  -- success
6993  *              none-zero failure code
6994  *==========================================================================*/
setSkinToneEnhancement(int sceFactor)6995 int32_t QCameraParameters::setSkinToneEnhancement(int sceFactor)
6996 {
6997     char val[16];
6998     snprintf(val, sizeof(val), "%d", sceFactor);
6999     updateParamEntry(KEY_QC_SCE_FACTOR, val);
7000     LOGH("Setting skintone enhancement %s", val);
7001 
7002     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SCE_FACTOR, sceFactor)) {
7003         return BAD_VALUE;
7004     }
7005 
7006     return NO_ERROR;
7007 }
7008 
7009 /*===========================================================================
7010  * FUNCTION   : setSaturation
7011  *
7012  * DESCRIPTION: set saturation control value
7013  *
7014  * PARAMETERS :
7015  *   @saturation : saturation control value
7016  *
7017  * RETURN     : int32_t type of status
7018  *              NO_ERROR  -- success
7019  *              none-zero failure code
7020  *==========================================================================*/
setSaturation(int saturation)7021 int32_t QCameraParameters::setSaturation(int saturation)
7022 {
7023     char val[16];
7024     snprintf(val, sizeof(val), "%d", saturation);
7025     updateParamEntry(KEY_QC_SATURATION, val);
7026     LOGH("Setting saturation %s", val);
7027 
7028     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SATURATION, saturation)) {
7029         return BAD_VALUE;
7030     }
7031 
7032     return NO_ERROR;
7033 }
7034 
7035 /*===========================================================================
7036  * FUNCTION   : setContrast
7037  *
7038  * DESCRIPTION: set contrast control value
7039  *
7040  * PARAMETERS :
7041  *   @contrast : contrast control value
7042  *
7043  * RETURN     : int32_t type of status
7044  *              NO_ERROR  -- success
7045  *              none-zero failure code
7046  *==========================================================================*/
setContrast(int contrast)7047 int32_t QCameraParameters::setContrast(int contrast)
7048 {
7049     char val[16];
7050     snprintf(val, sizeof(val), "%d", contrast);
7051     updateParamEntry(KEY_QC_CONTRAST, val);
7052     LOGH("Setting contrast %s", val);
7053 
7054     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CONTRAST, contrast)) {
7055         return BAD_VALUE;
7056     }
7057 
7058     return NO_ERROR;
7059 }
7060 
7061 /*===========================================================================
7062  * FUNCTION   : setSceneDetect
7063  *
7064  * DESCRIPTION: set scenen detect value
7065  *
7066  * PARAMETERS :
7067  *   @sceneDetect  : scene detect value string
7068  *
7069  * RETURN     : int32_t type of status
7070  *              NO_ERROR  -- success
7071  *              none-zero failure code
7072  *==========================================================================*/
setSceneDetect(const char * sceneDetect)7073 int32_t QCameraParameters::setSceneDetect(const char *sceneDetect)
7074 {
7075     if (sceneDetect != NULL) {
7076         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
7077                 sceneDetect);
7078         if (value != NAME_NOT_FOUND) {
7079             LOGH("Setting Scene Detect %s", sceneDetect);
7080             updateParamEntry(KEY_QC_SCENE_DETECT, sceneDetect);
7081             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ASD_ENABLE, value)) {
7082                 return BAD_VALUE;
7083             }
7084             return NO_ERROR;
7085         }
7086     }
7087     LOGE("Invalid Scene Detect value: %s",
7088           (sceneDetect == NULL) ? "NULL" : sceneDetect);
7089     return BAD_VALUE;
7090 }
7091 
7092 /*===========================================================================
7093  * FUNCTION   : setSensorSnapshotHDR
7094  *
7095  * DESCRIPTION: set snapshot HDR value
7096  *
7097  * PARAMETERS :
7098  *   @snapshotHDR  : snapshot HDR value string
7099  *
7100  * RETURN     : int32_t type of status
7101  *              NO_ERROR  -- success
7102  *              none-zero failure code
7103  *==========================================================================*/
setSensorSnapshotHDR(const char * snapshotHDR)7104 int32_t QCameraParameters::setSensorSnapshotHDR(const char *snapshotHDR)
7105 {
7106     if (snapshotHDR != NULL) {
7107         int32_t value = (cam_sensor_hdr_type_t) lookupAttr(ON_OFF_MODES_MAP,
7108                 PARAM_MAP_SIZE(ON_OFF_MODES_MAP), snapshotHDR);
7109         if (value != NAME_NOT_FOUND) {
7110             LOGH("Setting Sensor Snapshot HDR %s", snapshotHDR);
7111             updateParamEntry(KEY_QC_SENSOR_HDR, snapshotHDR);
7112 
7113             char zz_prop[PROPERTY_VALUE_MAX];
7114             memset(zz_prop, 0, sizeof(zz_prop));
7115             property_get("persist.camera.zzhdr.enable", zz_prop, "0");
7116             uint8_t zzhdr_enable = (uint8_t)atoi(zz_prop);
7117 
7118             if (zzhdr_enable && (value != CAM_SENSOR_HDR_OFF)) {
7119                 value = CAM_SENSOR_HDR_ZIGZAG;
7120                 LOGH("%s: Overriding to ZZ HDR Mode", __func__);
7121             }
7122 
7123             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SENSOR_HDR, (cam_sensor_hdr_type_t)value)) {
7124                 return BAD_VALUE;
7125             }
7126             return NO_ERROR;
7127         }
7128     }
7129     LOGE("Invalid Snapshot HDR value: %s",
7130           (snapshotHDR == NULL) ? "NULL" : snapshotHDR);
7131     return BAD_VALUE;
7132 
7133 }
7134 
7135 
7136 /*===========================================================================
7137  * FUNCTION   : setVideoHDR
7138  *
7139  * DESCRIPTION: set video HDR value
7140  *
7141  * PARAMETERS :
7142  *   @videoHDR  : svideo HDR value string
7143  *
7144  * RETURN     : int32_t type of status
7145  *              NO_ERROR  -- success
7146  *              none-zero failure code
7147  *==========================================================================*/
setVideoHDR(const char * videoHDR)7148 int32_t QCameraParameters::setVideoHDR(const char *videoHDR)
7149 {
7150     if (videoHDR != NULL) {
7151         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP), videoHDR);
7152         if (value != NAME_NOT_FOUND) {
7153 
7154             char zz_prop[PROPERTY_VALUE_MAX];
7155             memset(zz_prop, 0, sizeof(zz_prop));
7156             property_get("persist.camera.hdr.video", zz_prop, "0");
7157             uint8_t use_zzhdr_video = (uint8_t)atoi(zz_prop);
7158 
7159             if (use_zzhdr_video == CAM_SENSOR_HDR_ZIGZAG) {
7160                 LOGH("%s: Using ZZ HDR for video mode", __func__);
7161                 if (value)
7162                     value = CAM_SENSOR_HDR_ZIGZAG;
7163                 else
7164                     value = CAM_SENSOR_HDR_OFF;
7165                 LOGH("%s: Overriding to sensor HDR Mode to:%d", __func__, value);
7166                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SENSOR_HDR, (cam_sensor_hdr_type_t) value)) {
7167                     LOGE("%s: Override to sensor HDR mode for video HDR failed", __func__);
7168                     return BAD_VALUE;
7169                 }
7170                 updateParamEntry(KEY_QC_VIDEO_HDR, videoHDR);
7171             } else {
7172                 LOGH("%s: Setting Video HDR %s", __func__, videoHDR);
7173                 updateParamEntry(KEY_QC_VIDEO_HDR, videoHDR);
7174                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_VIDEO_HDR, value)) {
7175                     return BAD_VALUE;
7176                 }
7177             }
7178 
7179             return NO_ERROR;
7180         }
7181     }
7182     LOGE("Invalid Video HDR value: %s",
7183           (videoHDR == NULL) ? "NULL" : videoHDR);
7184     return BAD_VALUE;
7185 }
7186 
7187 
7188 
7189 /*===========================================================================
7190  * FUNCTION   : setVtEnable
7191  *
7192  * DESCRIPTION: set vt Enable value
7193  *
7194  * PARAMETERS :
7195  *   @videoHDR  : svtEnable value string
7196  *
7197  * RETURN     : int32_t type of status
7198  *              NO_ERROR  -- success
7199  *              none-zero failure code
7200  *==========================================================================*/
setVtEnable(const char * vtEnable)7201 int32_t QCameraParameters::setVtEnable(const char *vtEnable)
7202 {
7203     if (vtEnable != NULL) {
7204         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
7205                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), vtEnable);
7206         if (value != NAME_NOT_FOUND) {
7207             LOGI("Setting Vt Enable %s", vtEnable);
7208             m_bAVTimerEnabled = true;
7209             updateParamEntry(KEY_QC_VT_ENABLE, vtEnable);
7210             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_VT, value)) {
7211                 return BAD_VALUE;
7212             }
7213             return NO_ERROR;
7214         }
7215     }
7216     LOGE("Invalid Vt Enable value: %s",
7217           (vtEnable == NULL) ? "NULL" : vtEnable);
7218     m_bAVTimerEnabled = false;
7219     return BAD_VALUE;
7220 }
7221 
7222 /*===========================================================================
7223  * FUNCTION   : setFaceRecognition
7224  *
7225  * DESCRIPTION: set face recognition value
7226  *
7227  * PARAMETERS :
7228  *   @faceRecog  : face recognition value string
7229  *   @maxFaces   : number of max faces to be detected/recognized
7230  *
7231  * RETURN     : int32_t type of status
7232  *              NO_ERROR  -- success
7233  *              none-zero failure code
7234  *==========================================================================*/
setFaceRecognition(const char * faceRecog,uint32_t maxFaces)7235 int32_t QCameraParameters::setFaceRecognition(const char *faceRecog,
7236         uint32_t maxFaces)
7237 {
7238     if (faceRecog != NULL) {
7239         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP), faceRecog);
7240         if (value != NAME_NOT_FOUND) {
7241             LOGH("Setting face recognition %s", faceRecog);
7242             updateParamEntry(KEY_QC_FACE_RECOGNITION, faceRecog);
7243 
7244             uint32_t faceProcMask = m_nFaceProcMask;
7245             if (value > 0) {
7246                 faceProcMask |= CAM_FACE_PROCESS_MASK_RECOGNITION;
7247             } else {
7248                 faceProcMask &= (uint32_t)(~CAM_FACE_PROCESS_MASK_RECOGNITION);
7249             }
7250 
7251             if(m_nFaceProcMask == faceProcMask) {
7252                 LOGH("face process mask not changed, no ops here");
7253                 return NO_ERROR;
7254             }
7255             m_nFaceProcMask = faceProcMask;
7256             LOGH("FaceProcMask -> %d", m_nFaceProcMask);
7257 
7258             // set parm for face process
7259             cam_fd_set_parm_t fd_set_parm;
7260             memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
7261             fd_set_parm.fd_mode = m_nFaceProcMask;
7262             fd_set_parm.num_fd = maxFaces;
7263 
7264             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FD, fd_set_parm)) {
7265                 return BAD_VALUE;
7266             }
7267             return NO_ERROR;
7268         }
7269     }
7270     LOGE("Invalid face recognition value: %s", (faceRecog == NULL) ? "NULL" : faceRecog);
7271     return BAD_VALUE;
7272 }
7273 
7274 /*===========================================================================
7275  * FUNCTION   : setZoom
7276  *
7277  * DESCRIPTION: set zoom level
7278  *
7279  * PARAMETERS :
7280  *   @zoom_level : zoom level
7281  *
7282  * RETURN     : int32_t type of status
7283  *              NO_ERROR  -- success
7284  *              none-zero failure code
7285  *==========================================================================*/
setZoom(int zoom_level)7286 int32_t QCameraParameters::setZoom(int zoom_level)
7287 {
7288     char val[16];
7289     snprintf(val, sizeof(val), "%d", zoom_level);
7290     updateParamEntry(KEY_ZOOM, val);
7291     LOGH("zoom level: %d", zoom_level);
7292     mZoomLevel = zoom_level;
7293     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZOOM, zoom_level)) {
7294         return BAD_VALUE;
7295     }
7296 
7297     return NO_ERROR;
7298 }
7299 
7300 /*===========================================================================
7301  * FUNCTION   : setISOValue
7302  *
7303  * DESCRIPTION: set ISO value
7304  *
7305  * PARAMETERS :
7306  *   @isoValue : ISO value string
7307  *
7308  * RETURN     : int32_t type of status
7309  *              NO_ERROR  -- success
7310  *              none-zero failure code
7311  *==========================================================================*/
setISOValue(const char * isoValue)7312 int32_t  QCameraParameters::setISOValue(const char *isoValue)
7313 {
7314     if (isoValue != NULL) {
7315         if (!strcmp(isoValue, ISO_MANUAL)) {
7316             LOGD("iso manual mode - use continuous iso");
7317             updateParamEntry(KEY_QC_ISO_MODE, isoValue);
7318             return NO_ERROR;
7319         }
7320         int32_t value = lookupAttr(ISO_MODES_MAP, PARAM_MAP_SIZE(ISO_MODES_MAP), isoValue);
7321         if (value != NAME_NOT_FOUND) {
7322             LOGH("Setting ISO value %s", isoValue);
7323             updateParamEntry(KEY_QC_ISO_MODE, isoValue);
7324 
7325             cam_intf_parm_manual_3a_t iso_settings;
7326             memset(&iso_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
7327             iso_settings.previewOnly = FALSE;
7328             iso_settings.value = value;
7329             if (getManualCaptureMode() != CAM_MANUAL_CAPTURE_TYPE_OFF) {
7330                 iso_settings.previewOnly = TRUE;
7331             }
7332 
7333             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ISO, iso_settings)) {
7334                 return BAD_VALUE;
7335             }
7336             m_isoValue = value;
7337             return NO_ERROR;
7338         }
7339     }
7340     LOGE("Invalid ISO value: %s",
7341           (isoValue == NULL) ? "NULL" : isoValue);
7342     return BAD_VALUE;
7343 }
7344 
7345 
7346 /*===========================================================================
7347  * FUNCTION   : setContinuousISO
7348  *
7349  * DESCRIPTION: set continuous ISO value
7350  *
7351  * PARAMETERS :
7352  *   @params : ISO value parameter
7353  *
7354  * RETURN     : int32_t type of status
7355  *              NO_ERROR  -- success
7356  *              none-zero failure code
7357  *==========================================================================*/
setContinuousISO(const QCameraParameters & params)7358 int32_t  QCameraParameters::setContinuousISO(const QCameraParameters& params)
7359 {
7360     const char *iso = params.get(KEY_QC_ISO_MODE);
7361     LOGD("current iso mode: %s", iso);
7362 
7363     if (iso != NULL) {
7364         if (strcmp(iso, ISO_MANUAL)) {
7365             LOGD("dont set iso to back-end.");
7366             return NO_ERROR;
7367         }
7368     }
7369 
7370     const char *str = params.get(KEY_QC_CONTINUOUS_ISO);
7371     const char *prev_str = get(KEY_QC_CONTINUOUS_ISO);
7372     if (str != NULL) {
7373         if (prev_str == NULL ||
7374             strcmp(str, prev_str) != 0) {
7375             return setContinuousISO(str);
7376         }
7377     }
7378     return NO_ERROR;
7379 }
7380 
7381 /*===========================================================================
7382  * FUNCTION   : setExposureTime
7383  *
7384  * DESCRIPTION: set exposure time
7385  *
7386  * PARAMETERS :
7387  *   @expTimeStr : string of exposure time in ms
7388  *
7389  * RETURN     : int32_t type of status
7390  *              NO_ERROR  -- success
7391  *              none-zero failure code
7392  *==========================================================================*/
setExposureTime(const char * expTimeStr)7393 int32_t  QCameraParameters::setExposureTime(const char *expTimeStr)
7394 {
7395     if (expTimeStr != NULL) {
7396         double expTimeMs = atof(expTimeStr);
7397         //input is in milli seconds. Convert to nano sec for backend
7398         int64_t expTimeNs = (int64_t)(expTimeMs*1000000L);
7399 
7400         // expTime == 0 means not to use manual exposure time.
7401         if ((0 <= expTimeNs) &&
7402                 ((expTimeNs == 0) ||
7403                 ((expTimeNs >= m_pCapability->exposure_time_range[0]) &&
7404                 (expTimeNs <= m_pCapability->exposure_time_range[1])))) {
7405             LOGH(", exposure time: %f ms", expTimeMs);
7406             updateParamEntry(KEY_QC_EXPOSURE_TIME, expTimeStr);
7407 
7408             cam_intf_parm_manual_3a_t exp_settings;
7409             memset(&exp_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
7410             if (getManualCaptureMode() != CAM_MANUAL_CAPTURE_TYPE_OFF) {
7411                 exp_settings.previewOnly = TRUE;
7412                 if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL1) {
7413                     exp_settings.value = expTimeNs;
7414                 } else {
7415                     exp_settings.value =
7416                             (int64_t)(QCAMERA_MAX_EXP_TIME_LEVEL1*1000000L);
7417                 }
7418             } else {
7419                 exp_settings.previewOnly = FALSE;
7420                 exp_settings.value = expTimeNs;
7421             }
7422 
7423             //Based on exposure values we can decide the capture type here
7424             if (getManualCaptureMode() != CAM_MANUAL_CAPTURE_TYPE_OFF) {
7425                 if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL1) {
7426                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_1);
7427                 } else if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL2) {
7428                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_2);
7429                 } else if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL4) {
7430                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_3);
7431                 } else {
7432                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF);
7433                 }
7434             }
7435 
7436             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EXPOSURE_TIME,
7437                     exp_settings)) {
7438                 return BAD_VALUE;
7439             }
7440             m_expTime = expTimeNs;
7441 
7442             return NO_ERROR;
7443         }
7444     }
7445 
7446     LOGE("Invalid exposure time, value: %s",
7447           (expTimeStr == NULL) ? "NULL" : expTimeStr);
7448     return BAD_VALUE;
7449 }
7450 
7451 /*===========================================================================
7452  * FUNCTION   : setLongshotEnable
7453  *
7454  * DESCRIPTION: set a flag indicating longshot mode
7455  *
7456  * PARAMETERS :
7457  *   @enable  : true - Longshot enabled
7458  *              false - Longshot disabled
7459  *
7460  * RETURN     : int32_t type of status
7461  *              NO_ERROR  -- success
7462  *              none-zero failure code
7463  *==========================================================================*/
setLongshotEnable(bool enable)7464 int32_t QCameraParameters::setLongshotEnable(bool enable)
7465 {
7466     int32_t rc = NO_ERROR;
7467     int8_t value = enable ? 1 : 0;
7468 
7469     if(initBatchUpdate() < 0 ) {
7470         LOGE("Failed to initialize group update table");
7471         return BAD_TYPE;
7472     }
7473 
7474     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LONGSHOT_ENABLE, value)) {
7475         LOGE("Failed to update table");
7476         return BAD_VALUE;
7477     }
7478 
7479     rc = commitSetBatch();
7480     if (rc != NO_ERROR) {
7481         LOGE("Failed to parameter changes");
7482         return rc;
7483     }
7484 
7485     m_bLongshotEnabled = enable;
7486 
7487     return rc;
7488 }
7489 
7490 /*===========================================================================
7491  * FUNCTION   : setFlash
7492  *
7493  * DESCRIPTION: set flash mode
7494  *
7495  * PARAMETERS :
7496  *   @flashStr : LED flash mode value string
7497  *
7498  * RETURN     : int32_t type of status
7499  *              NO_ERROR  -- success
7500  *              none-zero failure code
7501  *==========================================================================*/
setFlash(const char * flashStr)7502 int32_t QCameraParameters::setFlash(const char *flashStr)
7503 {
7504     if (flashStr != NULL) {
7505         int32_t value = lookupAttr(FLASH_MODES_MAP, PARAM_MAP_SIZE(FLASH_MODES_MAP), flashStr);
7506         if (value != NAME_NOT_FOUND) {
7507             LOGH("Setting Flash value %s", flashStr);
7508             updateParamEntry(KEY_FLASH_MODE, flashStr);
7509             mFlashValue = value;
7510             return NO_ERROR;
7511         }
7512     }
7513     LOGE("Invalid flash value: %s", (flashStr == NULL) ? "NULL" : flashStr);
7514     return BAD_VALUE;
7515 }
7516 
7517 /*===========================================================================
7518  * FUNCTION   : updateFlashMode
7519  *
7520  * DESCRIPTION: update flash mode
7521  *
7522  * PARAMETERS :
7523  *   @flashStr : LED flash mode value
7524  *
7525  * RETURN     : int32_t type of status
7526  *              NO_ERROR  -- success
7527  *              none-zero failure code
7528  *==========================================================================*/
updateFlashMode(cam_flash_mode_t flash_mode)7529 int32_t QCameraParameters::updateFlashMode(cam_flash_mode_t flash_mode)
7530 {
7531     int32_t rc = NO_ERROR;
7532     if (flash_mode >= CAM_FLASH_MODE_MAX) {
7533         LOGH("Error!! Invalid flash mode (%d)", flash_mode);
7534         return BAD_VALUE;
7535     }
7536     LOGH("Setting Flash mode from EZTune %d", flash_mode);
7537 
7538     const char *flash_mode_str = lookupNameByValue(FLASH_MODES_MAP,
7539             PARAM_MAP_SIZE(FLASH_MODES_MAP), flash_mode);
7540     if(initBatchUpdate() < 0 ) {
7541         LOGE("Failed to initialize group update table");
7542         return BAD_TYPE;
7543     }
7544     rc = setFlash(flash_mode_str);
7545     if (rc != NO_ERROR) {
7546         LOGE("Failed to update Flash mode");
7547         return rc;
7548     }
7549 
7550     LOGH("Setting Flash mode %d", mFlashValue);
7551     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LED_MODE, mFlashValue)) {
7552         LOGE("Failed to set led mode");
7553         return BAD_VALUE;
7554     }
7555 
7556     rc = commitSetBatch();
7557     if (rc != NO_ERROR) {
7558         LOGE("Failed to commit parameters");
7559         return rc;
7560     }
7561 
7562     return NO_ERROR;
7563 }
7564 
7565 
7566 /*===========================================================================
7567  * FUNCTION   : configureFlash
7568  *
7569  * DESCRIPTION: configure Flash Bracketing.
7570  *
7571  * PARAMETERS :
7572  *    @frame_config : output configuration structure to fill in.
7573  *
7574  * RETURN     : int32_t type of status
7575  *              NO_ERROR  -- success
7576  *              none-zero failure code
7577  *==========================================================================*/
configureFlash(cam_capture_frame_config_t & frame_config)7578 int32_t QCameraParameters::configureFlash(cam_capture_frame_config_t &frame_config)
7579 {
7580     LOGH("E");
7581     int32_t rc = NO_ERROR;
7582     uint32_t i = 0;
7583 
7584     if (isChromaFlashEnabled()) {
7585 
7586         rc = setToneMapMode(false, false);
7587         if (rc != NO_ERROR) {
7588             LOGE("Failed to configure tone map");
7589             return rc;
7590         }
7591 
7592         rc = setCDSMode(CAM_CDS_MODE_OFF, false);
7593         if (rc != NO_ERROR) {
7594             LOGE("Failed to configure csd mode");
7595             return rc;
7596         }
7597 
7598         LOGH("Enable Chroma Flash capture");
7599         cam_flash_mode_t flash_mode = CAM_FLASH_MODE_OFF;
7600         frame_config.num_batch =
7601                 m_pCapability->chroma_flash_settings_need.burst_count;
7602         if (frame_config.num_batch > CAM_MAX_FLASH_BRACKETING) {
7603             frame_config.num_batch = CAM_MAX_FLASH_BRACKETING;
7604         }
7605         for (i = 0; i < frame_config.num_batch; i++) {
7606             flash_mode = (m_pCapability->chroma_flash_settings_need.flash_bracketing[i]) ?
7607                     CAM_FLASH_MODE_ON:CAM_FLASH_MODE_OFF;
7608             frame_config.configs[i].num_frames = 1;
7609             frame_config.configs[i].type = CAM_CAPTURE_FLASH;
7610             frame_config.configs[i].flash_mode = flash_mode;
7611         }
7612     } else if (mFlashValue != CAM_FLASH_MODE_OFF) {
7613         frame_config.num_batch = 1;
7614         for (i = 0; i < frame_config.num_batch; i++) {
7615             frame_config.configs[i].num_frames = getNumOfSnapshots();
7616             frame_config.configs[i].type = CAM_CAPTURE_FLASH;
7617             frame_config.configs[i].flash_mode =(cam_flash_mode_t)mFlashValue;
7618         }
7619     }
7620 
7621     LOGD("Flash frame batch cnt = %d",frame_config.num_batch);
7622     return rc;
7623 }
7624 
7625 /*===========================================================================
7626  * FUNCTION   : configureHDRBracketing
7627  *
7628  * DESCRIPTION: configure HDR Bracketing.
7629  *
7630  * PARAMETERS :
7631  *    @frame_config : output configuration structure to fill in.
7632  *
7633  * RETURN     : int32_t type of status
7634  *              NO_ERROR  -- success
7635  *              none-zero failure code
7636  *==========================================================================*/
configureHDRBracketing(cam_capture_frame_config_t & frame_config)7637 int32_t QCameraParameters::configureHDRBracketing(cam_capture_frame_config_t &frame_config)
7638 {
7639     LOGH("E");
7640     int32_t rc = NO_ERROR;
7641     uint32_t i = 0;
7642 
7643     uint32_t hdrFrameCount = m_pCapability->hdr_bracketing_setting.num_frames;
7644     LOGH("HDR values %d, %d frame count: %u",
7645           (int8_t) m_pCapability->hdr_bracketing_setting.exp_val.values[0],
7646           (int8_t) m_pCapability->hdr_bracketing_setting.exp_val.values[1],
7647           hdrFrameCount);
7648 
7649     frame_config.num_batch = hdrFrameCount;
7650 
7651     cam_bracket_mode mode =
7652             m_pCapability->hdr_bracketing_setting.exp_val.mode;
7653     if (mode == CAM_EXP_BRACKETING_ON) {
7654         rc = setToneMapMode(false, true);
7655         if (rc != NO_ERROR) {
7656             LOGW("Failed to disable tone map during HDR");
7657         }
7658     }
7659     for (i = 0; i < frame_config.num_batch; i++) {
7660         frame_config.configs[i].num_frames = 1;
7661         frame_config.configs[i].type = CAM_CAPTURE_BRACKETING;
7662         frame_config.configs[i].hdr_mode.mode = mode;
7663         frame_config.configs[i].hdr_mode.values =
7664                 m_pCapability->hdr_bracketing_setting.exp_val.values[i];
7665         LOGD("exp values %d",
7666                 (int)frame_config.configs[i].hdr_mode.values);
7667     }
7668     return rc;
7669 }
7670 
7671 /*===========================================================================
7672  * FUNCTION   : configureAEBracketing
7673  *
7674  * DESCRIPTION: configure AE Bracketing.
7675  *
7676  * PARAMETERS :
7677  *    @frame_config : output configuration structure to fill in.
7678  *
7679  * RETURN     : int32_t type of status
7680  *              NO_ERROR  -- success
7681  *              none-zero failure code
7682  *==========================================================================*/
configureAEBracketing(cam_capture_frame_config_t & frame_config)7683 int32_t QCameraParameters::configureAEBracketing(cam_capture_frame_config_t &frame_config)
7684 {
7685     LOGH("E");
7686     int32_t rc = NO_ERROR;
7687     uint32_t i = 0;
7688     char exp_value[MAX_EXP_BRACKETING_LENGTH];
7689 
7690     rc = setToneMapMode(false, true);
7691     if (rc != NO_ERROR) {
7692         LOGH("Failed to disable tone map during AEBracketing");
7693     }
7694 
7695     uint32_t burstCount = 0;
7696     const char *str_val = m_AEBracketingClient.values;
7697     if ((str_val != NULL) && (strlen(str_val) > 0)) {
7698         char prop[PROPERTY_VALUE_MAX];
7699         memset(prop, 0, sizeof(prop));
7700         strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
7701         char *saveptr = NULL;
7702         char *token = strtok_r(prop, ",", &saveptr);
7703         if (token != NULL) {
7704             exp_value[burstCount++] = (char)atoi(token);
7705             while (token != NULL) {
7706                 token = strtok_r(NULL, ",", &saveptr);
7707                 if (token != NULL) {
7708                     exp_value[burstCount++] = (char)atoi(token);
7709                 }
7710             }
7711         }
7712     }
7713 
7714     frame_config.num_batch = burstCount;
7715     cam_bracket_mode mode = m_AEBracketingClient.mode;
7716 
7717     for (i = 0; i < frame_config.num_batch; i++) {
7718         frame_config.configs[i].num_frames = 1;
7719         frame_config.configs[i].type = CAM_CAPTURE_BRACKETING;
7720         frame_config.configs[i].hdr_mode.mode = mode;
7721         frame_config.configs[i].hdr_mode.values =
7722                 m_AEBracketingClient.values[i];
7723         LOGD("exp values %d", (int)m_AEBracketingClient.values[i]);
7724     }
7725 
7726     LOGH("num_frame = %d X", burstCount);
7727     return rc;
7728 }
7729 
7730 /*===========================================================================
7731  * FUNCTION   : configureLowLight
7732  *
7733  * DESCRIPTION: configure low light frame capture use case.
7734  *
7735  * PARAMETERS :
7736  *    @frame_config : output configuration structure to fill in.
7737  *
7738  * RETURN     : int32_t type of status
7739  *              NO_ERROR  -- success
7740  *              none-zero failure code
7741  *==========================================================================*/
configureLowLight(cam_capture_frame_config_t & frame_config)7742 int32_t QCameraParameters::configureLowLight(cam_capture_frame_config_t &frame_config)
7743 {
7744     int32_t rc = NO_ERROR;
7745 
7746     frame_config.num_batch = 1;
7747     frame_config.configs[0].num_frames = getNumOfSnapshots();
7748     frame_config.configs[0].type = CAM_CAPTURE_LOW_LIGHT;
7749     frame_config.configs[0].low_light_mode = CAM_LOW_LIGHT_ON;
7750     LOGH("Snapshot Count: %d", frame_config.configs[0].num_frames);
7751     return rc;
7752 }
7753 
7754 /*===========================================================================
7755  * FUNCTION   : configureManualCapture
7756  *
7757  * DESCRIPTION: configure manual capture.
7758  *
7759  * PARAMETERS :
7760  *    @frame_config : output configaration structure to fill in.
7761  *
7762  * RETURN     : int32_t type of status
7763  *              NO_ERROR  -- success
7764  *              none-zero failure code
7765  *==========================================================================*/
configureManualCapture(cam_capture_frame_config_t & frame_config)7766 int32_t QCameraParameters::configureManualCapture(cam_capture_frame_config_t &frame_config)
7767 {
7768     int32_t rc = NO_ERROR;
7769     uint32_t i = 0;
7770 
7771     LOGD("E");
7772     if (getManualCaptureMode()) {
7773         frame_config.num_batch = 1;
7774         for (i = 0; i < frame_config.num_batch; i++) {
7775             frame_config.configs[i].num_frames = getNumOfSnapshots();
7776             frame_config.configs[i].type = CAM_CAPTURE_MANUAL_3A;
7777             if (m_expTime != 0) {
7778                 frame_config.configs[i].manual_3A_mode.exp_mode = CAM_SETTINGS_TYPE_ON;
7779                 frame_config.configs[i].manual_3A_mode.exp_time = m_expTime;
7780             } else {
7781                 frame_config.configs[i].manual_3A_mode.exp_mode = CAM_SETTINGS_TYPE_AUTO;
7782                 frame_config.configs[i].manual_3A_mode.exp_time = 0;
7783             }
7784 
7785             if (m_isoValue != 0) {
7786                 frame_config.configs[i].manual_3A_mode.iso_mode = CAM_SETTINGS_TYPE_ON;
7787                 frame_config.configs[i].manual_3A_mode.iso_value = m_isoValue;
7788             } else {
7789                 frame_config.configs[i].manual_3A_mode.iso_mode = CAM_SETTINGS_TYPE_AUTO;
7790                 frame_config.configs[i].manual_3A_mode.iso_value = 0;
7791             }
7792         }
7793     }
7794     LOGD("X: batch cnt = %d", frame_config.num_batch);
7795     return rc;
7796 }
7797 
7798 /*===========================================================================
7799  * FUNCTION   : configFrameCapture
7800  *
7801  * DESCRIPTION: configuration for ZSL special captures (FLASH/HDR etc)
7802  *
7803  * PARAMETERS :
7804  *   @commitSettings : flag to enable or disable commit this this settings
7805  *
7806  * RETURN     : int32_t type of status
7807  *              NO_ERROR  -- success
7808  *              none-zero failure code
7809  *==========================================================================*/
configFrameCapture(bool commitSettings)7810 int32_t QCameraParameters::configFrameCapture(bool commitSettings)
7811 {
7812     int32_t rc = NO_ERROR;
7813     int32_t value;
7814 
7815     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
7816 
7817     if (commitSettings) {
7818         if(initBatchUpdate() < 0 ) {
7819             LOGE("Failed to initialize group update table");
7820             return BAD_TYPE;
7821         }
7822     }
7823 
7824     if (isHDREnabled() || m_bAeBracketingEnabled || m_bAFBracketingOn ||
7825           m_bOptiZoomOn || m_bReFocusOn || getManualCaptureMode()) {
7826         value = CAM_FLASH_MODE_OFF;
7827     } else if (isChromaFlashEnabled()) {
7828         value = CAM_FLASH_MODE_ON;
7829     } else {
7830         value = mFlashValue;
7831     }
7832 
7833     if (m_LowLightLevel && (value != CAM_FLASH_MODE_ON)) {
7834         configureLowLight (m_captureFrameConfig);
7835 
7836         //Added reset capture type as a last batch for back-end to restore settings.
7837         int32_t batch_count = m_captureFrameConfig.num_batch;
7838         m_captureFrameConfig.configs[batch_count].type = CAM_CAPTURE_RESET;
7839         m_captureFrameConfig.configs[batch_count].num_frames = 0;
7840         m_captureFrameConfig.num_batch++;
7841     } else if (value != CAM_FLASH_MODE_OFF) {
7842         configureFlash(m_captureFrameConfig);
7843     } else if(isHDREnabled()) {
7844         configureHDRBracketing (m_captureFrameConfig);
7845     } else if(isAEBracketEnabled()) {
7846         configureAEBracketing (m_captureFrameConfig);
7847     } else if (getManualCaptureMode() >= CAM_MANUAL_CAPTURE_TYPE_2){
7848         rc = configureManualCapture (m_captureFrameConfig);
7849         //Added reset capture type as a last batch for back-end to restore settings.
7850         int32_t batch_count = m_captureFrameConfig.num_batch;
7851         m_captureFrameConfig.configs[batch_count].type = CAM_CAPTURE_RESET;
7852         m_captureFrameConfig.configs[batch_count].num_frames = 0;
7853         m_captureFrameConfig.num_batch++;
7854     }
7855 
7856     rc = ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CAPTURE_FRAME_CONFIG,
7857             (cam_capture_frame_config_t)m_captureFrameConfig);
7858     if (rc != NO_ERROR) {
7859         rc = BAD_VALUE;
7860         LOGE("Failed to set capture settings");
7861         return rc;
7862     }
7863 
7864     if (commitSettings) {
7865         rc = commitSetBatch();
7866         if (rc != NO_ERROR) {
7867             LOGE("Failed to commit parameters");
7868             return rc;
7869         }
7870     }
7871     return rc;
7872 }
7873 
7874 /*===========================================================================
7875  * FUNCTION   : resetFrameCapture
7876  *
7877  * DESCRIPTION: reset special captures settings(FLASH/HDR etc)
7878  *
7879  * PARAMETERS :
7880  *   @commitSettings : flag to enable or disable commit this this settings
7881  *   @lowLightEnabled: flag to indicate if low light scene detected
7882  *
7883  * RETURN     : int32_t type of status
7884  *              NO_ERROR  -- success
7885  *              none-zero failure code
7886  *==========================================================================*/
resetFrameCapture(bool commitSettings,bool lowLightEnabled)7887 int32_t QCameraParameters::resetFrameCapture(bool commitSettings, bool lowLightEnabled)
7888 {
7889     int32_t rc = NO_ERROR;
7890     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
7891 
7892     if (commitSettings) {
7893         if(initBatchUpdate() < 0 ) {
7894             LOGE("Failed to initialize group update table");
7895             return BAD_TYPE;
7896         }
7897     }
7898 
7899     if (isHDREnabled() || isAEBracketEnabled()) {
7900         rc = setToneMapMode(true, true);
7901         if (rc != NO_ERROR) {
7902             LOGH("Failed to enable tone map during HDR/AEBracketing");
7903         }
7904         rc = stopAEBracket();
7905     } else if ((isChromaFlashEnabled()) || (mFlashValue != CAM_FLASH_MODE_OFF)
7906             || (lowLightEnabled == true)) {
7907         rc = setToneMapMode(true, false);
7908         if (rc != NO_ERROR) {
7909             LOGH("Failed to enable tone map during chroma flash");
7910         }
7911 
7912         rc = setCDSMode(mCds_mode, false);
7913         if (rc != NO_ERROR) {
7914             LOGE("Failed to configure csd mode");
7915             return rc;
7916         }
7917     }
7918 
7919     rc = ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CAPTURE_FRAME_CONFIG,
7920             (cam_capture_frame_config_t)m_captureFrameConfig);
7921     if (rc != NO_ERROR) {
7922         rc = BAD_VALUE;
7923         LOGE("Failed to set capture settings");
7924         return rc;
7925     }
7926 
7927     if (commitSettings) {
7928         rc = commitSetBatch();
7929         if (rc != NO_ERROR) {
7930             LOGE("Failed to commit parameters");
7931             return rc;
7932         }
7933     }
7934     return rc;
7935 }
7936 
7937 /*===========================================================================
7938  * FUNCTION   : setAecLock
7939  *
7940  * DESCRIPTION: set AEC lock value
7941  *
7942  * PARAMETERS :
7943  *   @aecLockStr : AEC lock value string
7944  *
7945  * RETURN     : int32_t type of status
7946  *              NO_ERROR  -- success
7947  *              none-zero failure code
7948  *==========================================================================*/
setAecLock(const char * aecLockStr)7949 int32_t QCameraParameters::setAecLock(const char *aecLockStr)
7950 {
7951     if (aecLockStr != NULL) {
7952         int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
7953                 aecLockStr);
7954         if (value != NAME_NOT_FOUND) {
7955             LOGH("Setting AECLock value %s", aecLockStr);
7956             updateParamEntry(KEY_AUTO_EXPOSURE_LOCK, aecLockStr);
7957             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
7958                     CAM_INTF_PARM_AEC_LOCK, (uint32_t)value)) {
7959                 return BAD_VALUE;
7960             }
7961             return NO_ERROR;
7962         }
7963     }
7964     LOGE("Invalid AECLock value: %s",
7965         (aecLockStr == NULL) ? "NULL" : aecLockStr);
7966     return BAD_VALUE;
7967 }
7968 
7969 /*===========================================================================
7970  * FUNCTION   : setAwbLock
7971  *
7972  * DESCRIPTION: set AWB lock value
7973  *
7974  * PARAMETERS :
7975  *   @awbLockStr : AWB lock value string
7976  *
7977  * RETURN     : int32_t type of status
7978  *              NO_ERROR  -- success
7979  *              none-zero failure code
7980  *==========================================================================*/
setAwbLock(const char * awbLockStr)7981 int32_t QCameraParameters::setAwbLock(const char *awbLockStr)
7982 {
7983     if (awbLockStr != NULL) {
7984         int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
7985                 awbLockStr);
7986         if (value != NAME_NOT_FOUND) {
7987             LOGH("Setting AWBLock value %s", awbLockStr);
7988             updateParamEntry(KEY_AUTO_WHITEBALANCE_LOCK, awbLockStr);
7989             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
7990                     CAM_INTF_PARM_AWB_LOCK, (uint32_t)value)) {
7991                 return BAD_VALUE;
7992             }
7993             return NO_ERROR;
7994         }
7995     }
7996     LOGE("Invalid AWBLock value: %s", (awbLockStr == NULL) ? "NULL" : awbLockStr);
7997     return BAD_VALUE;
7998 }
7999 
8000 /*===========================================================================
8001  * FUNCTION   : setMCEValue
8002  *
8003  * DESCRIPTION: set memory color enhancement value
8004  *
8005  * PARAMETERS :
8006  *   @mceStr : MCE value string
8007  *
8008  * RETURN     : int32_t type of status
8009  *              NO_ERROR  -- success
8010  *              none-zero failure code
8011  *==========================================================================*/
setMCEValue(const char * mceStr)8012 int32_t QCameraParameters::setMCEValue(const char *mceStr)
8013 {
8014     if (mceStr != NULL) {
8015         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
8016                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), mceStr);
8017         if (value != NAME_NOT_FOUND) {
8018             LOGH("Setting AWBLock value %s", mceStr);
8019             updateParamEntry(KEY_QC_MEMORY_COLOR_ENHANCEMENT, mceStr);
8020             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MCE, value)) {
8021                 return BAD_VALUE;
8022             }
8023             return NO_ERROR;
8024         }
8025     }
8026     LOGE("Invalid MCE value: %s", (mceStr == NULL) ? "NULL" : mceStr);
8027     return BAD_VALUE;
8028 }
8029 
8030 /*===========================================================================
8031  * FUNCTION   : setTintlessValue
8032  *
8033  * DESCRIPTION: enable/disable tintless from user setting
8034  *
8035  * PARAMETERS :
8036  *   @params  : user setting parameters
8037  *
8038  * RETURN     : int32_t type of status
8039  *              NO_ERROR  -- success
8040  *              none-zero failure code
8041  *==========================================================================*/
setTintlessValue(const QCameraParameters & params)8042 int32_t QCameraParameters::setTintlessValue(const QCameraParameters& params)
8043 {
8044     const char *str = params.get(KEY_QC_TINTLESS_ENABLE);
8045     const char *prev_str = get(KEY_QC_TINTLESS_ENABLE);
8046     char prop[PROPERTY_VALUE_MAX];
8047 
8048     memset(prop, 0, sizeof(prop));
8049     property_get("persist.camera.tintless", prop, VALUE_ENABLE);
8050     if (str != NULL) {
8051         if (prev_str == NULL ||
8052             strcmp(str, prev_str) != 0) {
8053             return setTintlessValue(str);
8054         }
8055     } else {
8056         if (prev_str == NULL ||
8057             strcmp(prev_str, prop) != 0 ) {
8058             setTintlessValue(prop);
8059         }
8060     }
8061 
8062     return NO_ERROR;
8063 }
8064 
8065 /*===========================================================================
8066  * FUNCTION   : setTintless
8067  *
8068  * DESCRIPTION: set tintless mode
8069  *
8070  * PARAMETERS :
8071  *   @enable : 1 = enable, 0 = disable
8072  *
8073  * RETURN     : int32_t type of status
8074  *              NO_ERROR  -- success
8075  *              none-zero failure code
8076  *==========================================================================*/
setTintless(bool enable)8077 void QCameraParameters::setTintless(bool enable)
8078 {
8079     if (enable) {
8080         setTintlessValue(VALUE_ENABLE);
8081     } else {
8082         setTintlessValue(VALUE_DISABLE);
8083     }
8084 }
8085 
8086 /*===========================================================================
8087  * FUNCTION   : setTintlessValue
8088  *
8089  * DESCRIPTION: set tintless value
8090  *
8091  * PARAMETERS :
8092  *   @tintStr : Tintless value string
8093  *
8094  * RETURN     : int32_t type of status
8095  *              NO_ERROR  -- success
8096  *              none-zero failure code
8097  *==========================================================================*/
setTintlessValue(const char * tintStr)8098 int32_t QCameraParameters::setTintlessValue(const char *tintStr)
8099 {
8100     if (tintStr != NULL) {
8101         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
8102                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), tintStr);
8103         if (value != NAME_NOT_FOUND) {
8104             LOGH("Setting Tintless value %s", tintStr);
8105             updateParamEntry(KEY_QC_TINTLESS_ENABLE, tintStr);
8106             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TINTLESS, value)) {
8107                 return BAD_VALUE;
8108             }
8109             return NO_ERROR;
8110         }
8111     }
8112     LOGE("Invalid Tintless value: %s", (tintStr == NULL) ? "NULL" : tintStr);
8113     return BAD_VALUE;
8114 }
8115 
8116 /*===========================================================================
8117  * FUNCTION   : setCDSMode
8118  *
8119  * DESCRIPTION: Set CDS mode
8120  *
8121  * PARAMETERS :
8122  *   @params  : user setting parameters
8123  *
8124  * RETURN     : int32_t type of status
8125  *              NO_ERROR  -- success
8126  *              none-zero failure code
8127  *==========================================================================*/
setCDSMode(const QCameraParameters & params)8128 int32_t QCameraParameters::setCDSMode(const QCameraParameters& params)
8129 {
8130     const char *str = params.get(KEY_QC_CDS_MODE);
8131     const char *prev_str = get(KEY_QC_CDS_MODE);
8132     const char *video_str = params.get(KEY_QC_VIDEO_CDS_MODE);
8133     const char *video_prev_str = get(KEY_QC_VIDEO_CDS_MODE);
8134     int32_t rc = NO_ERROR;
8135 
8136     if (m_bRecordingHint_new == true) {
8137         if (video_str) {
8138             if ((video_prev_str == NULL) || (strcmp(video_str, video_prev_str) != 0)) {
8139                 int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
8140                         video_str);
8141                 if (cds_mode != NAME_NOT_FOUND) {
8142                     updateParamEntry(KEY_QC_VIDEO_CDS_MODE, video_str);
8143                     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
8144                         LOGE("Failed CDS MODE to update table");
8145                         rc = BAD_VALUE;
8146                     } else {
8147                         LOGD("Set CDS in video mode = %d", cds_mode);
8148                         mCds_mode = cds_mode;
8149                         m_bNeedRestart = true;
8150                     }
8151                 } else {
8152                     LOGE("Invalid argument for video CDS MODE %d",  cds_mode);
8153                     rc = BAD_VALUE;
8154                 }
8155             }
8156         } else {
8157             char video_prop[PROPERTY_VALUE_MAX];
8158             memset(video_prop, 0, sizeof(video_prop));
8159             property_get("persist.camera.video.CDS", video_prop, CDS_MODE_ON);
8160             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
8161                     video_prop);
8162             if (cds_mode != NAME_NOT_FOUND) {
8163                 updateParamEntry(KEY_QC_VIDEO_CDS_MODE, video_prop);
8164                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
8165                     LOGE("Failed CDS MODE to update table");
8166                     rc = BAD_VALUE;
8167                 } else {
8168                     LOGD("Set CDS in video mode from setprop = %d", cds_mode);
8169                     mCds_mode = cds_mode;
8170                 }
8171             } else {
8172                 LOGE("Invalid prop for video CDS MODE %d",  cds_mode);
8173                 rc = BAD_VALUE;
8174             }
8175         }
8176     } else {
8177         if (str) {
8178             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
8179                 int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
8180                         str);
8181                 if (cds_mode != NAME_NOT_FOUND) {
8182                     updateParamEntry(KEY_QC_CDS_MODE, str);
8183                     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
8184                         LOGE("Failed CDS MODE to update table");
8185                         rc = BAD_VALUE;
8186                     } else {
8187                         LOGD("Set CDS in capture mode = %d", cds_mode);
8188                         mCds_mode = cds_mode;
8189                         m_bNeedRestart = true;
8190                     }
8191                 } else {
8192                     LOGE("Invalid argument for snapshot CDS MODE %d",  cds_mode);
8193                     rc = BAD_VALUE;
8194                 }
8195             }
8196         } else {
8197             char prop[PROPERTY_VALUE_MAX];
8198             memset(prop, 0, sizeof(prop));
8199             property_get("persist.camera.CDS", prop, CDS_MODE_ON);
8200             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
8201                     prop);
8202             if (cds_mode != NAME_NOT_FOUND) {
8203                 updateParamEntry(KEY_QC_CDS_MODE, prop);
8204                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
8205                     LOGE("Failed CDS MODE to update table");
8206                     rc = BAD_VALUE;
8207                 } else {
8208                     LOGD("Set CDS in snapshot mode from setprop = %d", cds_mode);
8209                     mCds_mode = cds_mode;
8210                 }
8211             } else {
8212                 LOGE("Invalid prop for snapshot CDS MODE %d",  cds_mode);
8213                 rc = BAD_VALUE;
8214             }
8215         }
8216     }
8217 
8218     return rc;
8219 }
8220 
8221 /*===========================================================================
8222  * FUNCTION   : setInitialExposureIndex
8223  *
8224  * DESCRIPTION: Set initial exposure index value
8225  *
8226  * PARAMETERS :
8227  *   @params  : user setting parameters
8228  *
8229  * RETURN     : int32_t type of status
8230  *              NO_ERROR  -- success
8231  *              none-zero failure code
8232  *==========================================================================*/
setInitialExposureIndex(const QCameraParameters & params)8233 int32_t QCameraParameters::setInitialExposureIndex(const QCameraParameters& params)
8234 {
8235     int32_t rc = NO_ERROR;
8236     int value = -1;
8237     const char *str = params.get(KEY_QC_INITIAL_EXPOSURE_INDEX);
8238     const char *prev_str = get(KEY_QC_INITIAL_EXPOSURE_INDEX);
8239     if (str) {
8240         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
8241             value = atoi(str);
8242             LOGD("Set initial exposure index value from param = %d", value);
8243             if (value >= 0) {
8244                 updateParamEntry(KEY_QC_INITIAL_EXPOSURE_INDEX, str);
8245             }
8246         }
8247     } else {
8248         char prop[PROPERTY_VALUE_MAX];
8249         memset(prop, 0, sizeof(prop));
8250         property_get("persist.camera.initial.exp.val", prop, "");
8251         if ((strlen(prop) > 0) &&
8252                 ( (prev_str == NULL) || (strcmp(prop, prev_str) != 0))) {
8253             value = atoi(prop);
8254             LOGD("Set initial exposure index value from setprop = %d", value);
8255             if (value >= 0) {
8256                 updateParamEntry(KEY_QC_INITIAL_EXPOSURE_INDEX, prop);
8257             }
8258         }
8259     }
8260 
8261     if (value >= 0) {
8262         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
8263                 CAM_INTF_PARM_INITIAL_EXPOSURE_INDEX, (uint32_t)value)) {
8264             LOGE("Failed to update initial exposure index value");
8265             rc = BAD_VALUE;
8266         }
8267     } else {
8268         LOGD("Invalid value for initial exposure index value %d", value);
8269     }
8270 
8271     return rc;
8272 }
8273 
8274 /*===========================================================================
8275  * FUNCTION   : setInstantCapture
8276  *
8277  * DESCRIPTION: Set Instant Capture related params
8278  *
8279  * PARAMETERS :
8280  *   @params  : user setting parameters
8281  *
8282  * RETURN     : int32_t type of status
8283  *              NO_ERROR  -- success
8284  *              none-zero failure code
8285  *==========================================================================*/
setInstantCapture(const QCameraParameters & params)8286 int32_t QCameraParameters::setInstantCapture(const QCameraParameters& params)
8287 {
8288     int32_t rc = NO_ERROR;
8289     int value = -1;
8290     // Check for instant capture, this will enable instant AEC as well.
8291     // This param will trigger the instant AEC param to backend
8292     // And also will be useful for instant capture.
8293     const char *str = params.get(KEY_QC_INSTANT_CAPTURE);
8294     const char *prev_str = get(KEY_QC_INSTANT_CAPTURE);
8295     if (str) {
8296         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
8297             value = lookupAttr(INSTANT_CAPTURE_MODES_MAP,
8298                     PARAM_MAP_SIZE(INSTANT_CAPTURE_MODES_MAP), str);
8299             LOGD("Set instant Capture from param = %d", value);
8300             if(value != NAME_NOT_FOUND) {
8301                 updateParamEntry(KEY_QC_INSTANT_CAPTURE, str);
8302             } else {
8303                 LOGE("Invalid value for instant capture %s", str);
8304                 return BAD_VALUE;
8305             }
8306         }
8307     } else {
8308         char prop[PROPERTY_VALUE_MAX];
8309         memset(prop, 0, sizeof(prop));
8310         property_get("persist.camera.instant.capture", prop, KEY_QC_INSTANT_CAPTURE_DISABLE);
8311         if ((prev_str == NULL) || (strcmp(prop, prev_str) != 0)) {
8312             value = lookupAttr(INSTANT_CAPTURE_MODES_MAP,
8313                     PARAM_MAP_SIZE(INSTANT_CAPTURE_MODES_MAP), prop);
8314             LOGD("Set instant capture from setprop = %d", value);
8315             if (value != NAME_NOT_FOUND) {
8316                 updateParamEntry(KEY_QC_INSTANT_CAPTURE, prop);
8317             } else {
8318                 LOGE("Invalid value for instant capture %s", prop);
8319                 return BAD_VALUE;
8320             }
8321         }
8322     }
8323 
8324     // Set instant AEC param to the backend for either instant capture or instant AEC
8325     // 0 - disbale (normal AEC)
8326     // 1 - Aggressive AEC (algo used in backend)
8327     // 2 - Fast AEC (algo used in backend)
8328     if (value != NAME_NOT_FOUND && value != -1) {
8329         m_bInstantCapture = (value > 0)? true : false;
8330         setInstantAEC((uint8_t)value, false);
8331     }
8332 
8333 
8334     // get frame aec bound value from setprop.
8335     // This value indicates the number of frames, camera interface
8336     // will wait for getting the instant capture frame.
8337     // Default value set to 7.
8338     // This value also indicates the number of frames, that HAL
8339     // will not display and will not send preview frames to app
8340     // This will be applicable only if instant capture is set.
8341     if (m_bInstantCapture) {
8342         char prop[PROPERTY_VALUE_MAX];
8343         memset(prop, 0, sizeof(prop));
8344         property_get("persist.camera.ae.capture.bound", prop, "7");
8345         int32_t frame_bound = atoi(prop);
8346         if (frame_bound >= 0) {
8347             mAecFrameBound = (uint8_t)frame_bound;
8348         } else {
8349             LOGE("Invalid prop for aec frame bound %d", frame_bound);
8350             rc = BAD_VALUE;
8351         }
8352     }
8353     return rc;
8354 }
8355 
8356 /*===========================================================================
8357  * FUNCTION   : setInstantAEC
8358  *
8359  * DESCRIPTION: Set Instant AEC related params
8360  *
8361  * PARAMETERS :
8362  *   @params  : user setting parameters
8363  *
8364  * RETURN     : int32_t type of status
8365  *              NO_ERROR  -- success
8366  *              none-zero failure code
8367  *==========================================================================*/
setInstantAEC(const QCameraParameters & params)8368 int32_t QCameraParameters::setInstantAEC(const QCameraParameters& params)
8369 {
8370     int32_t rc = NO_ERROR;
8371     int value = -1;
8372 
8373     // Check for instant AEC only when instant capture is not enabled.
8374     // Instant capture already takes care of the instant AEC as well.
8375     if (!m_bInstantCapture) {
8376         // Check for instant AEC. Instant AEC will only enable fast AEC.
8377         // It will not enable instant capture.
8378         // This param will trigger the instant AEC param to backend
8379         // Instant AEC param is session based param,
8380         // the param change will be applicable for next camera open/close session.
8381         const char *str = params.get(KEY_QC_INSTANT_AEC);
8382         const char *prev_str = get(KEY_QC_INSTANT_AEC);
8383         if (str) {
8384             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
8385                 value = lookupAttr(INSTANT_AEC_MODES_MAP,
8386                         PARAM_MAP_SIZE(INSTANT_AEC_MODES_MAP), str);
8387                 LOGD("Set instant AEC from param = %d", value);
8388                 if(value != NAME_NOT_FOUND) {
8389                     updateParamEntry(KEY_QC_INSTANT_AEC, str);
8390                 } else {
8391                     LOGE("Invalid value for instant AEC %s", str);
8392                     return BAD_VALUE;
8393                 }
8394             }
8395         } else {
8396             char prop[PROPERTY_VALUE_MAX];
8397             memset(prop, 0, sizeof(prop));
8398             property_get("persist.camera.instant.aec", prop, KEY_QC_INSTANT_AEC_DISABLE);
8399             if ((prev_str == NULL) || (strcmp(prop, prev_str) != 0)) {
8400                 value = lookupAttr(INSTANT_AEC_MODES_MAP,
8401                         PARAM_MAP_SIZE(INSTANT_AEC_MODES_MAP), prop);
8402                 LOGD("Set instant AEC from setprop = %d", value);
8403                 if(value != NAME_NOT_FOUND) {
8404                     updateParamEntry(KEY_QC_INSTANT_AEC, prop);
8405                 } else {
8406                     LOGE("Invalid value for instant AEC %s", prop);
8407                     return BAD_VALUE;
8408                 }
8409             }
8410         }
8411 
8412         // Set instant AEC param to the backend for either instant capture or instant AEC
8413         // 0 - disbale (normal AEC)
8414         // 1 - Aggressive AEC (algo used in backend)
8415         // 2 - Fast AEC (algo used in backend)
8416         if (value != NAME_NOT_FOUND && value != -1) {
8417             setInstantAEC((uint8_t)value, false);
8418         }
8419 
8420     }
8421 
8422     // get frame aec preview skip count from setprop.
8423     // This value indicates the number of frames, that HAL
8424     // will not display and will not send preview frames to app
8425     // Default value set to 7.
8426     // This will be applicable only if instant aec is set.
8427     if (m_bInstantAEC) {
8428         char prop[PROPERTY_VALUE_MAX];
8429         memset(prop, 0, sizeof(prop));
8430         property_get("persist.camera.ae.instant.bound", prop, "7");
8431         int32_t aec_frame_skip_cnt = atoi(prop);
8432         if (aec_frame_skip_cnt >= 0) {
8433             mAecSkipDisplayFrameBound = (uint8_t)aec_frame_skip_cnt;
8434         } else {
8435             LOGE("Invalid prop for aec frame bound %d", aec_frame_skip_cnt);
8436             rc = BAD_VALUE;
8437         }
8438     }
8439     return rc;
8440 }
8441 
8442 /*===========================================================================
8443  * FUNCTION   : setDISValue
8444  *
8445  * DESCRIPTION: set DIS value
8446  *
8447  * PARAMETERS :
8448  *   @disStr : DIS value string
8449  *
8450  * RETURN     : int32_t type of status
8451  *              NO_ERROR  -- success
8452  *              none-zero failure code
8453  *==========================================================================*/
setDISValue(const char * disStr)8454 int32_t QCameraParameters::setDISValue(const char *disStr)
8455 {
8456     if (disStr != NULL) {
8457         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
8458                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), disStr);
8459         if (value != NAME_NOT_FOUND) {
8460             //For some IS types (like EIS 2.0), when DIS value is changed, we need to restart
8461             //preview because of topology change in backend. But, for now, restart preview
8462             //for all IS types.
8463             m_bNeedRestart = true;
8464             LOGH("Setting DIS value %s", disStr);
8465             updateParamEntry(KEY_QC_DIS, disStr);
8466             if (!(strcmp(disStr,"enable"))) {
8467                 m_bDISEnabled = true;
8468             } else {
8469                 m_bDISEnabled = false;
8470             }
8471             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_DIS_ENABLE, value)) {
8472                 return BAD_VALUE;
8473             }
8474             return NO_ERROR;
8475         }
8476     }
8477     LOGE("Invalid DIS value: %s", (disStr == NULL) ? "NULL" : disStr);
8478     m_bDISEnabled = false;
8479     return BAD_VALUE;
8480 }
8481 
8482 /*===========================================================================
8483  * FUNCTION   : updateOisValue
8484  *
8485  * DESCRIPTION: update OIS value
8486  *
8487  * PARAMETERS :
8488  *   @oisValue : OIS value TRUE/FALSE
8489  *
8490  * RETURN     : int32_t type of status
8491  *              NO_ERROR  -- success
8492  *              none-zero failure code
8493  *==========================================================================*/
updateOisValue(bool oisValue)8494 int32_t QCameraParameters::updateOisValue(bool oisValue)
8495 {
8496     uint8_t enable = 0;
8497     int32_t rc = NO_ERROR;
8498 
8499     // Check for OIS disable
8500     char ois_prop[PROPERTY_VALUE_MAX];
8501     memset(ois_prop, 0, sizeof(ois_prop));
8502     property_get("persist.camera.ois.disable", ois_prop, "0");
8503     uint8_t ois_disable = (uint8_t)atoi(ois_prop);
8504 
8505     //Enable OIS if it is camera mode or Camcoder 4K mode
8506     if (!m_bRecordingHint || (is4k2kVideoResolution() && m_bRecordingHint)) {
8507         enable = 1;
8508         LOGH("Valid OIS mode!! ");
8509     }
8510     // Disable OIS if setprop is set
8511     if (ois_disable || !oisValue) {
8512         //Disable OIS
8513         enable = 0;
8514         LOGH("Disable OIS mode!! ois_disable(%d) oisValue(%d)",
8515                  ois_disable, oisValue);
8516 
8517     }
8518     m_bOISEnabled = enable;
8519     if (m_bOISEnabled) {
8520         updateParamEntry(KEY_QC_OIS, VALUE_ENABLE);
8521     } else {
8522         updateParamEntry(KEY_QC_OIS, VALUE_DISABLE);
8523     }
8524 
8525     if (initBatchUpdate() < 0 ) {
8526         LOGE("Failed to initialize group update table");
8527         return BAD_TYPE;
8528     }
8529 
8530     LOGH("Sending OIS mode (%d)", enable);
8531     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_META_LENS_OPT_STAB_MODE, enable)) {
8532         LOGE("Failed to update table");
8533         return BAD_VALUE;
8534     }
8535 
8536     rc = commitSetBatch();
8537     if (rc != NO_ERROR) {
8538         LOGE("Failed to parameter changes");
8539         return rc;
8540     }
8541 
8542     return rc;
8543 }
8544 
8545 /*===========================================================================
8546  * FUNCTION   : setHighFrameRate
8547  *
8548  * DESCRIPTION: set high frame rate
8549  *
8550  * PARAMETERS :
8551  *   @hfrMode : HFR mode
8552  *
8553  * RETURN     : int32_t type of status
8554  *              NO_ERROR  -- success
8555  *              none-zero failure code
8556  *==========================================================================*/
setHighFrameRate(const int32_t hfrMode)8557 int32_t QCameraParameters::setHighFrameRate(const int32_t hfrMode)
8558 {
8559     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HFR, hfrMode)) {
8560         return BAD_VALUE;
8561     }
8562 
8563     return NO_ERROR;
8564 }
8565 
8566 /*===========================================================================
8567  * FUNCTION   : setLensShadeValue
8568  *
8569  * DESCRIPTION: set lens shade value
8570  *
8571  * PARAMETERS :
8572  *   @lensSahdeStr : lens shade value string
8573  *
8574  * RETURN     : int32_t type of status
8575  *              NO_ERROR  -- success
8576  *              none-zero failure code
8577  *==========================================================================*/
setLensShadeValue(const char * lensShadeStr)8578 int32_t QCameraParameters::setLensShadeValue(const char *lensShadeStr)
8579 {
8580     if (lensShadeStr != NULL) {
8581         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
8582                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), lensShadeStr);
8583         if (value != NAME_NOT_FOUND) {
8584             LOGH("Setting LensShade value %s", lensShadeStr);
8585             updateParamEntry(KEY_QC_LENSSHADE, lensShadeStr);
8586             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ROLLOFF, value)) {
8587                 return BAD_VALUE;
8588             }
8589             return NO_ERROR;
8590         }
8591     }
8592     LOGE("Invalid LensShade value: %s",
8593           (lensShadeStr == NULL) ? "NULL" : lensShadeStr);
8594     return BAD_VALUE;
8595 }
8596 
8597 /*===========================================================================
8598  * FUNCTION   : setExposureCompensation
8599  *
8600  * DESCRIPTION: set exposure compensation value
8601  *
8602  * PARAMETERS :
8603  *   @expComp : exposure compensation value
8604  *
8605  * RETURN     : int32_t type of status
8606  *              NO_ERROR  -- success
8607  *              none-zero failure code
8608  *==========================================================================*/
setExposureCompensation(int expComp)8609 int32_t QCameraParameters::setExposureCompensation(int expComp)
8610 {
8611     char val[16];
8612     snprintf(val, sizeof(val), "%d", expComp);
8613     updateParamEntry(KEY_EXPOSURE_COMPENSATION, val);
8614 
8615     // Don't need to pass step as part of setParameter because
8616     // camera daemon is already aware of it.
8617     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EXPOSURE_COMPENSATION, expComp)) {
8618         return BAD_VALUE;
8619     }
8620 
8621     return NO_ERROR;
8622 }
8623 
8624 /*===========================================================================
8625  * FUNCTION   : setWhiteBalance
8626  *
8627  * DESCRIPTION: set white balance mode
8628  *
8629  * PARAMETERS :
8630  *   @wbStr   : white balance mode value string
8631  *
8632  * RETURN     : int32_t type of status
8633  *              NO_ERROR  -- success
8634  *              none-zero failure code
8635  *==========================================================================*/
setWhiteBalance(const char * wbStr)8636 int32_t QCameraParameters::setWhiteBalance(const char *wbStr)
8637 {
8638     if (wbStr != NULL) {
8639         int32_t value = lookupAttr(WHITE_BALANCE_MODES_MAP,
8640                 PARAM_MAP_SIZE(WHITE_BALANCE_MODES_MAP), wbStr);
8641         if (value != NAME_NOT_FOUND) {
8642             LOGH("Setting WhiteBalance value %s", wbStr);
8643             updateParamEntry(KEY_WHITE_BALANCE, wbStr);
8644             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WHITE_BALANCE, value)) {
8645                 return BAD_VALUE;
8646             }
8647             return NO_ERROR;
8648         }
8649     }
8650     LOGE("Invalid WhiteBalance value: %s", (wbStr == NULL) ? "NULL" : wbStr);
8651     return BAD_VALUE;
8652 }
8653 
8654 /*===========================================================================
8655  * FUNCTION   : setWBManualCCT
8656  *
8657  * DESCRIPTION: set setWBManualCCT time
8658  *
8659  * PARAMETERS :
8660  *   @cctStr : string of wb cct, range (2000, 8000) in K.
8661  *
8662  * RETURN     : int32_t type of status
8663  *              NO_ERROR  -- success
8664  *              none-zero failure code
8665  *==========================================================================*/
setWBManualCCT(const char * cctStr)8666 int32_t  QCameraParameters::setWBManualCCT(const char *cctStr)
8667 {
8668     if (cctStr != NULL) {
8669         int32_t cctVal = atoi(cctStr);
8670         int32_t minCct = m_pCapability->min_wb_cct; /* 2000K */
8671         int32_t maxCct = m_pCapability->max_wb_cct; /* 8000K */
8672 
8673         if (cctVal >= minCct && cctVal <= maxCct) {
8674             LOGH(", cct value: %d", cctVal);
8675             updateParamEntry(KEY_QC_WB_MANUAL_CCT, cctStr);
8676             cam_manual_wb_parm_t manual_wb;
8677             manual_wb.type = CAM_MANUAL_WB_MODE_CCT;
8678             manual_wb.cct = cctVal;
8679             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WB_MANUAL, manual_wb)) {
8680                 return BAD_VALUE;
8681             }
8682             return NO_ERROR;
8683         }
8684     }
8685 
8686     LOGE("Invalid cct, value: %s",
8687             (cctStr == NULL) ? "NULL" : cctStr);
8688     return BAD_VALUE;
8689 }
8690 
8691 /*===========================================================================
8692  * FUNCTION   : updateAWBParams
8693  *
8694  * DESCRIPTION: update CCT parameters key
8695  *
8696  * PARAMETERS :
8697  *   @awb_params : WB parameters
8698  *
8699  * RETURN     : int32_t type of status
8700  *              NO_ERROR  -- success
8701  *              none-zero failure code
8702  *==========================================================================*/
updateAWBParams(cam_awb_params_t & awb_params)8703 int32_t QCameraParameters::updateAWBParams(cam_awb_params_t &awb_params)
8704 {
8705     //check and update CCT
8706     int32_t prev_cct = getInt(KEY_QC_WB_MANUAL_CCT);
8707     if (prev_cct != awb_params.cct_value) {
8708         LOGD("update current cct value. old:%d, now:%d",
8709                 prev_cct, awb_params.cct_value);
8710         set(KEY_QC_WB_MANUAL_CCT, awb_params.cct_value);
8711     }
8712 
8713     //check and update WB gains
8714     const char *prev_gains = get(KEY_QC_MANUAL_WB_GAINS);
8715     char gainStr[30];
8716     snprintf(gainStr, sizeof(gainStr), "%f,%f,%f", awb_params.rgb_gains.r_gain,
8717         awb_params.rgb_gains.g_gain, awb_params.rgb_gains.b_gain);
8718 
8719     if (prev_gains == NULL || strcmp(prev_gains, gainStr)) {
8720         set(KEY_QC_MANUAL_WB_GAINS, gainStr);
8721         LOGD("update currernt RGB gains: old %s new %s", prev_gains, gainStr);
8722     }
8723     return NO_ERROR;
8724 }
8725 
8726 /*===========================================================================
8727  * FUNCTION   : parseGains
8728  *
8729  * DESCRIPTION: parse WB gains
8730  *
8731  * PARAMETERS :
8732  *   @gainStr : WB result string
8733  *   @r_gain  : WB red gain
8734  *   @g_gain  : WB green gain
8735  *   @b_gain  : WB blue gain
8736  *
8737  * RETURN     : int32_t type of status
8738  *              NO_ERROR  -- success
8739  *              none-zero failure code
8740  *==========================================================================*/
parseGains(const char * gainStr,double & r_gain,double & g_gain,double & b_gain)8741 int32_t QCameraParameters::parseGains(const char *gainStr, double &r_gain,
8742                                           double &g_gain, double &b_gain)
8743 {
8744     int32_t rc = NO_ERROR;
8745     char *saveptr = NULL;
8746     size_t gains_size = strlen(gainStr) + 1;
8747     char* gains = (char*) calloc(1, gains_size);
8748     if (NULL == gains) {
8749         LOGE("No memory for gains");
8750         return NO_MEMORY;
8751     }
8752     strlcpy(gains, gainStr, gains_size);
8753     char *token = strtok_r(gains, ",", &saveptr);
8754 
8755     if (NULL != token) {
8756         r_gain = (float) atof(token);
8757         token = strtok_r(NULL, ",", &saveptr);
8758     }
8759 
8760     if (NULL != token) {
8761         g_gain = (float) atof(token);
8762         token = strtok_r(NULL, ",", &saveptr);
8763     }
8764 
8765     if (NULL != token) {
8766         b_gain = (float) atof(token);
8767     } else {
8768         LOGE("Malformed string for gains");
8769         rc = BAD_VALUE;
8770     }
8771 
8772     free(gains);
8773     return rc;
8774 }
8775 
8776 /*===========================================================================
8777  * FUNCTION   : setManualWBGains
8778  *
8779  * DESCRIPTION: set manual wb gains for r,g,b
8780  *
8781  * PARAMETERS :
8782  *   @cctStr : string of wb gains, range (1.0, 4.0).
8783  *
8784  * RETURN     : int32_t type of status
8785  *              NO_ERROR  -- success
8786  *              none-zero failure code
8787  *==========================================================================*/
setManualWBGains(const char * gainStr)8788 int32_t QCameraParameters::setManualWBGains(const char *gainStr)
8789 {
8790     int32_t rc = NO_ERROR;
8791     if (gainStr != NULL) {
8792         double r_gain,g_gain,b_gain;
8793         rc = parseGains(gainStr, r_gain, g_gain, b_gain);
8794         if (rc != NO_ERROR) {
8795             return rc;
8796         }
8797 
8798         double minGain = m_pCapability->min_wb_gain;
8799         double maxGain = m_pCapability->max_wb_gain;
8800 
8801         if (r_gain >= minGain && r_gain <= maxGain &&
8802             g_gain >= minGain && g_gain <= maxGain &&
8803             b_gain >= minGain && b_gain <= maxGain) {
8804             LOGH(", setting rgb gains: r = %lf g = %lf b = %lf",
8805                      r_gain, g_gain, b_gain);
8806             updateParamEntry(KEY_QC_MANUAL_WB_GAINS, gainStr);
8807             cam_manual_wb_parm_t manual_wb;
8808             manual_wb.type = CAM_MANUAL_WB_MODE_GAIN;
8809             manual_wb.gains.r_gain = r_gain;
8810             manual_wb.gains.g_gain = g_gain;
8811             manual_wb.gains.b_gain = b_gain;
8812             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WB_MANUAL, manual_wb)) {
8813                 return BAD_VALUE;
8814             }
8815             return NO_ERROR;
8816         }
8817     }
8818 
8819     LOGH("Invalid manual wb gains: %s",
8820           (gainStr == NULL) ? "NULL" : gainStr);
8821     return BAD_VALUE;
8822 }
8823 
getAutoFlickerMode()8824 int QCameraParameters::getAutoFlickerMode()
8825 {
8826     /* Enable Advanced Auto Antibanding where we can set
8827        any of the following option
8828        ie. CAM_ANTIBANDING_MODE_AUTO
8829            CAM_ANTIBANDING_MODE_AUTO_50HZ
8830            CAM_ANTIBANDING_MODE_AUTO_60HZ
8831       Currently setting it to default    */
8832     char prop[PROPERTY_VALUE_MAX];
8833     memset(prop, 0, sizeof(prop));
8834     property_get("persist.camera.set.afd", prop, "3");
8835     return atoi(prop);
8836 }
8837 
8838 /*===========================================================================
8839  * FUNCTION   : setAntibanding
8840  *
8841  * DESCRIPTION: set antibanding value
8842  *
8843  * PARAMETERS :
8844  *   @antiBandingStr : antibanding value string
8845  *
8846  * RETURN     : int32_t type of status
8847  *              NO_ERROR  -- success
8848  *              none-zero failure code
8849  *==========================================================================*/
setAntibanding(const char * antiBandingStr)8850 int32_t QCameraParameters::setAntibanding(const char *antiBandingStr)
8851 {
8852     if (antiBandingStr != NULL) {
8853         int32_t value = lookupAttr(ANTIBANDING_MODES_MAP, PARAM_MAP_SIZE(ANTIBANDING_MODES_MAP),
8854                 antiBandingStr);
8855         if (value != NAME_NOT_FOUND) {
8856             LOGH("Setting AntiBanding value %s", antiBandingStr);
8857             updateParamEntry(KEY_ANTIBANDING, antiBandingStr);
8858             if(value == CAM_ANTIBANDING_MODE_AUTO) {
8859                value = getAutoFlickerMode();
8860             }
8861             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
8862                     CAM_INTF_PARM_ANTIBANDING, (uint32_t)value)) {
8863                 return BAD_VALUE;
8864             }
8865             return NO_ERROR;
8866         }
8867     }
8868     LOGE("Invalid AntiBanding value: %s",
8869           (antiBandingStr == NULL) ? "NULL" : antiBandingStr);
8870     return BAD_VALUE;
8871 }
8872 
8873 /*===========================================================================
8874  * FUNCTION   : setFocusAreas
8875  *
8876  * DESCRIPTION: set focus areas
8877  *
8878  * PARAMETERS :
8879  *   @focusAreasStr : focus areas value string
8880  *
8881  * RETURN     : int32_t type of status
8882  *              NO_ERROR  -- success
8883  *              none-zero failure code
8884  *==========================================================================*/
setFocusAreas(const char * focusAreasStr)8885 int32_t QCameraParameters::setFocusAreas(const char *focusAreasStr)
8886 {
8887     if (m_pCapability->max_num_focus_areas == 0 ||
8888         focusAreasStr == NULL) {
8889         LOGD("Parameter string is null");
8890         return NO_ERROR;
8891     }
8892 
8893     cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
8894     if (NULL == areas) {
8895         LOGE("No memory for areas");
8896         return NO_MEMORY;
8897     }
8898     memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
8899     int num_areas_found = 0;
8900     if (parseCameraAreaString(focusAreasStr,
8901                               m_pCapability->max_num_focus_areas,
8902                               areas,
8903                               num_areas_found) != NO_ERROR) {
8904         LOGE("Failed to parse the string: %s", focusAreasStr);
8905         free(areas);
8906         return BAD_VALUE;
8907     }
8908 
8909     if (validateCameraAreas(areas, num_areas_found) == false) {
8910         LOGE("invalid areas specified : %s", focusAreasStr);
8911         free(areas);
8912         return BAD_VALUE;
8913     }
8914 
8915     updateParamEntry(KEY_FOCUS_AREAS, focusAreasStr);
8916 
8917     //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
8918     //so no action is takenby the lower layer
8919     if (num_areas_found == 1 &&
8920         areas[0].rect.left == 0 &&
8921         areas[0].rect.top == 0 &&
8922         areas[0].rect.width == 0 &&
8923         areas[0].rect.height == 0 &&
8924         areas[0].weight == 0) {
8925         num_areas_found = 0;
8926     }
8927 
8928     int previewWidth, previewHeight;
8929     getPreviewSize(&previewWidth, &previewHeight);
8930     cam_roi_info_t af_roi_value;
8931     memset(&af_roi_value, 0, sizeof(cam_roi_info_t));
8932     af_roi_value.num_roi = (uint8_t)num_areas_found;
8933     for (int i = 0; i < num_areas_found; i++) {
8934         LOGH("FocusArea[%d] = (%d, %d, %d, %d)",
8935                i, (areas[i].rect.top), (areas[i].rect.left),
8936               (areas[i].rect.width), (areas[i].rect.height));
8937 
8938         // Transform the coords from (-1000, 1000)
8939         // to (0, previewWidth or previewHeight).
8940         af_roi_value.roi[i].left =
8941                 (int32_t)(((double)areas[i].rect.left + 1000.0) *
8942                     ((double)previewWidth / 2000.0));
8943         af_roi_value.roi[i].top =
8944                 (int32_t)(((double)areas[i].rect.top + 1000.0) *
8945                     ((double)previewHeight / 2000.0));
8946         af_roi_value.roi[i].width =
8947                 (int32_t)((double)areas[i].rect.width *
8948                     (double)previewWidth / 2000.0);
8949         af_roi_value.roi[i].height =
8950                 (int32_t)((double)areas[i].rect.height *
8951                     (double)previewHeight / 2000.0);
8952         af_roi_value.weight[i] = areas[i].weight;
8953     }
8954     free(areas);
8955     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AF_ROI, af_roi_value)) {
8956         return BAD_VALUE;
8957     }
8958 
8959     return NO_ERROR;
8960 }
8961 
8962 /*===========================================================================
8963  * FUNCTION   : setMeteringAreas
8964  *
8965  * DESCRIPTION: set metering areas value
8966  *
8967  * PARAMETERS :
8968  *   @meteringAreasStr : metering areas value string
8969  *
8970  * RETURN     : int32_t type of status
8971  *              NO_ERROR  -- success
8972  *              none-zero failure code
8973  *==========================================================================*/
setMeteringAreas(const char * meteringAreasStr)8974 int32_t QCameraParameters::setMeteringAreas(const char *meteringAreasStr)
8975 {
8976     if (m_pCapability->max_num_metering_areas == 0 ||
8977         meteringAreasStr == NULL) {
8978         LOGD("Parameter string is null");
8979         return NO_ERROR;
8980     }
8981 
8982     cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
8983     if (NULL == areas) {
8984         LOGE("No memory for areas");
8985         return NO_MEMORY;
8986     }
8987     memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
8988     int num_areas_found = 0;
8989     if (parseCameraAreaString(meteringAreasStr,
8990                               m_pCapability->max_num_metering_areas,
8991                               areas,
8992                               num_areas_found) < 0) {
8993         LOGE("Failed to parse the string: %s", meteringAreasStr);
8994         free(areas);
8995         return BAD_VALUE;
8996     }
8997 
8998     if (validateCameraAreas(areas, num_areas_found) == false) {
8999         LOGE("invalid areas specified : %s", meteringAreasStr);
9000         free(areas);
9001         return BAD_VALUE;
9002     }
9003 
9004     updateParamEntry(KEY_METERING_AREAS, meteringAreasStr);
9005 
9006     //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
9007     //so no action is takenby the lower layer
9008     if (num_areas_found == 1 &&
9009         areas[0].rect.left == 0 &&
9010         areas[0].rect.top == 0 &&
9011         areas[0].rect.width == 0 &&
9012         areas[0].rect.height == 0 &&
9013         areas[0].weight == 0) {
9014         num_areas_found = 0;
9015     }
9016     cam_set_aec_roi_t aec_roi_value;
9017     int previewWidth, previewHeight;
9018     getPreviewSize(&previewWidth, &previewHeight);
9019 
9020     memset(&aec_roi_value, 0, sizeof(cam_set_aec_roi_t));
9021     aec_roi_value.num_roi = num_areas_found;
9022     if (num_areas_found > 0) {
9023         aec_roi_value.aec_roi_enable = CAM_AEC_ROI_ON;
9024         aec_roi_value.aec_roi_type = CAM_AEC_ROI_BY_COORDINATE;
9025 
9026         for (int i = 0; i < num_areas_found; i++) {
9027             LOGH("MeteringArea[%d] = (%d, %d, %d, %d)",
9028                    i, (areas[i].rect.top), (areas[i].rect.left),
9029                   (areas[i].rect.width), (areas[i].rect.height));
9030 
9031             // Transform the coords from (-1000, 1000) to
9032             // (0, previewWidth or previewHeight).
9033             aec_roi_value.cam_aec_roi_position.coordinate[i].x =
9034                     (uint32_t)((((double)areas[i].rect.left +
9035                         (double)areas[i].rect.width / 2.0) + 1000.0) *
9036                             (double)previewWidth / 2000.0);
9037             aec_roi_value.cam_aec_roi_position.coordinate[i].y =
9038                     (uint32_t)((((double)areas[i].rect.top +
9039                         (double)areas[i].rect.height / 2.0) + 1000.0) *
9040                             (double)previewHeight / 2000.0);
9041         }
9042     } else {
9043         aec_roi_value.aec_roi_enable = CAM_AEC_ROI_OFF;
9044     }
9045     free(areas);
9046     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_ROI, aec_roi_value)) {
9047         return BAD_VALUE;
9048     }
9049 
9050     return NO_ERROR;
9051 }
9052 
9053 
9054 /*===========================================================================
9055  * FUNCTION   : isSupportedSensorHdrSize
9056  *
9057  * DESCRIPTION: Checks if the requested snapshot size is compatible with currently
9058  *              configured HDR mode, currently primary target for validation is
9059  *              zzhdr however this function can be extended in the future to vet
9060  *              all sensor based HDR configs
9061  *
9062  * PARAMETERS :
9063  *   @params  : CameraParameters object
9064  *
9065  * RETURN     : boolean type
9066  *              True  -- indicates supported config
9067  *              False -- indicated unsupported config should fallback to other
9068  *              available HDR modes
9069  *==========================================================================*/
isSupportedSensorHdrSize(const QCameraParameters & params)9070 bool QCameraParameters::isSupportedSensorHdrSize(const QCameraParameters& params)
9071 {
9072     char value[PROPERTY_VALUE_MAX];
9073     memset(value, 0, sizeof(value));
9074     property_get("persist.camera.zzhdr.enable", value, "0");
9075     uint8_t zzhdr_enable = (uint8_t)atoi(value);
9076 
9077     if (zzhdr_enable) {
9078 
9079         int req_w, req_h;
9080         params.getPictureSize(&req_w, &req_h);
9081 
9082         // Check if requested w x h is in zzhdr supported list
9083         for (size_t i = 0; i< m_pCapability->zzhdr_sizes_tbl_cnt; ++i) {
9084 
9085             if (req_w == m_pCapability->zzhdr_sizes_tbl[i].width &&
9086                     req_h == m_pCapability->zzhdr_sizes_tbl[i].height) {
9087                 LOGD("%s: Found match for %d x %d", __func__, req_w, req_h);
9088                 return true;
9089             }
9090         }
9091         LOGH("%s: %d x %d is not supported for zzhdr mode", __func__, req_w, req_h);
9092         return false;
9093     }
9094 
9095     return true;
9096 }
9097 
9098 /*===========================================================================
9099  * FUNCTION   : setSceneMode
9100  *
9101  * DESCRIPTION: set scene mode
9102  *
9103  * PARAMETERS :
9104  *   @sceneModeStr : scene mode value string
9105  *
9106  * RETURN     : int32_t type of status
9107  *              NO_ERROR  -- success
9108  *              none-zero failure code
9109  *==========================================================================*/
setSceneMode(const char * sceneModeStr)9110 int32_t QCameraParameters::setSceneMode(const char *sceneModeStr)
9111 {
9112     if (sceneModeStr != NULL) {
9113         int32_t value = lookupAttr(SCENE_MODES_MAP, PARAM_MAP_SIZE(SCENE_MODES_MAP), sceneModeStr);
9114         if (value != NAME_NOT_FOUND) {
9115             LOGD("Setting SceneMode %s", sceneModeStr);
9116             updateParamEntry(KEY_SCENE_MODE, sceneModeStr);
9117             if (m_bSensorHDREnabled) {
9118               // Incase of HW HDR mode, we do not update the same as Best shot mode.
9119               LOGH("H/W HDR mode enabled. Do not set Best Shot Mode");
9120               return NO_ERROR;
9121             }
9122             if (m_bSceneSelection) {
9123                 setSelectedScene((cam_scene_mode_type) value);
9124             }
9125             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BESTSHOT_MODE,
9126                     (uint32_t)value)) {
9127                 return BAD_VALUE;
9128             }
9129             return NO_ERROR;
9130         }
9131     }
9132     LOGE("Invalid Secene Mode: %s",
9133            (sceneModeStr == NULL) ? "NULL" : sceneModeStr);
9134     return BAD_VALUE;
9135 }
9136 
9137 /*===========================================================================
9138  * FUNCTION   : setSelectableZoneAf
9139  *
9140  * DESCRIPTION: set selectable zone AF algorithm
9141  *
9142  * PARAMETERS :
9143  *   @selZoneAFStr : selectable zone AF algorithm value string
9144  *
9145  * RETURN     : int32_t type of status
9146  *              NO_ERROR  -- success
9147  *              none-zero failure code
9148  *==========================================================================*/
setSelectableZoneAf(const char * selZoneAFStr)9149 int32_t QCameraParameters::setSelectableZoneAf(const char *selZoneAFStr)
9150 {
9151     if (selZoneAFStr != NULL) {
9152         int32_t value = lookupAttr(FOCUS_ALGO_MAP, PARAM_MAP_SIZE(FOCUS_ALGO_MAP), selZoneAFStr);
9153         if (value != NAME_NOT_FOUND) {
9154             LOGD("Setting Selectable Zone AF value %s", selZoneAFStr);
9155             updateParamEntry(KEY_QC_SELECTABLE_ZONE_AF, selZoneAFStr);
9156             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_ALGO_TYPE, value)) {
9157                 return BAD_VALUE;
9158             }
9159             return NO_ERROR;
9160         }
9161     }
9162     LOGE("Invalid selectable zone af value: %s",
9163            (selZoneAFStr == NULL) ? "NULL" : selZoneAFStr);
9164     return BAD_VALUE;
9165 }
9166 
9167 /*===========================================================================
9168  * FUNCTION   : isAEBracketEnabled
9169  *
9170  * DESCRIPTION: checks if AE bracketing is enabled
9171  *
9172  * PARAMETERS :
9173  *
9174  * RETURN     : TRUE/FALSE
9175  *==========================================================================*/
isAEBracketEnabled()9176 bool QCameraParameters::isAEBracketEnabled()
9177 {
9178     const char *str = get(KEY_QC_AE_BRACKET_HDR);
9179     if (str != NULL) {
9180         if (strcmp(str, AE_BRACKET_OFF) != 0) {
9181             return true;
9182         }
9183     }
9184     return false;
9185 }
9186 
9187 /*===========================================================================
9188  * FUNCTION   : setAEBracket
9189  *
9190  * DESCRIPTION: set AE bracket value
9191  *
9192  * PARAMETERS :
9193  *   @aecBracketStr : AE bracket value string
9194  *
9195  * RETURN     : int32_t type of status
9196  *              NO_ERROR  -- success
9197  *              none-zero failure code
9198  *==========================================================================*/
setAEBracket(const char * aecBracketStr)9199 int32_t QCameraParameters::setAEBracket(const char *aecBracketStr)
9200 {
9201     if (aecBracketStr == NULL) {
9202         LOGD("setAEBracket with NULL value");
9203         return NO_ERROR;
9204     }
9205 
9206     cam_exp_bracketing_t expBracket;
9207     memset(&expBracket, 0, sizeof(expBracket));
9208 
9209     int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
9210             aecBracketStr);
9211     switch (value) {
9212     case CAM_EXP_BRACKETING_ON:
9213         {
9214             LOGD("EXP_BRACKETING_ON");
9215             const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
9216             if ((str_val != NULL) && (strlen(str_val)>0)) {
9217                 expBracket.mode = CAM_EXP_BRACKETING_ON;
9218                 m_bAeBracketingEnabled = true;
9219                 strlcpy(expBracket.values, str_val, MAX_EXP_BRACKETING_LENGTH);
9220                 LOGD("setting Exposure Bracketing value of %s",
9221                        expBracket.values);
9222             }
9223             else {
9224                 /* Apps not set capture-burst-exposures, error case fall into bracketing off mode */
9225                 LOGD("capture-burst-exposures not set, back to HDR OFF mode");
9226                 m_bAeBracketingEnabled = false;
9227                 expBracket.mode = CAM_EXP_BRACKETING_OFF;
9228             }
9229         }
9230         break;
9231     default:
9232         {
9233             m_bAeBracketingEnabled = false;
9234             LOGH(", EXP_BRACKETING_OFF");
9235             expBracket.mode = CAM_EXP_BRACKETING_OFF;
9236         }
9237         break;
9238     }
9239 
9240     // Cache client AE bracketing configuration
9241     memcpy(&m_AEBracketingClient, &expBracket, sizeof(cam_exp_bracketing_t));
9242 
9243     /* save the value*/
9244     updateParamEntry(KEY_QC_AE_BRACKET_HDR, aecBracketStr);
9245     return NO_ERROR;
9246 }
9247 
9248 /*===========================================================================
9249  * FUNCTION   : set3ALock
9250  *
9251  * DESCRIPTION: enable/disable 3A lock.
9252  *
9253  * PARAMETERS :
9254  *   @lock3A  : lock or unlock
9255  *
9256  * RETURN     : int32_t type of status
9257  *              NO_ERROR  -- success
9258  *              none-zero failure code
9259  *==========================================================================*/
set3ALock(bool lock3A)9260 int32_t QCameraParameters::set3ALock(bool lock3A)
9261 {
9262     int32_t rc = NO_ERROR;
9263     LOGH("Setting Lock %d", lock3A);
9264     if(initBatchUpdate() < 0 ) {
9265         LOGE("Failed to initialize group update table");
9266         return BAD_TYPE;
9267     }
9268     uint32_t focus_mode = CAM_FOCUS_MODE_AUTO;
9269     if (lock3A) {
9270         if (isUbiFocusEnabled() || isUbiRefocus()) {
9271             //For Ubi focus move focus to infinity.
9272             focus_mode = CAM_FOCUS_MODE_INFINITY;
9273         } else if (isOptiZoomEnabled() || isStillMoreEnabled()) {
9274             //For optizoom and stillmore, set focus as fixed.
9275             focus_mode = CAM_FOCUS_MODE_FIXED;
9276         }
9277     } else {
9278         // retrieve previous focus value.
9279         const char *focus = get(KEY_FOCUS_MODE);
9280         int val = lookupAttr(FOCUS_MODES_MAP, PARAM_MAP_SIZE(FOCUS_MODES_MAP), focus);
9281         if (val != NAME_NOT_FOUND) {
9282             focus_mode = (uint32_t) val;
9283             LOGD("focus mode %s", focus);
9284         }
9285     }
9286     //Lock AWB
9287     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AWB_LOCK, (uint32_t)lock3A)) {
9288         return BAD_VALUE;
9289     }
9290     //Lock AEC
9291     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_LOCK, (uint32_t)lock3A)) {
9292         return BAD_VALUE;
9293     }
9294     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_MODE, focus_mode)) {
9295         return BAD_VALUE;
9296     }
9297 
9298     rc = commitSetBatch();
9299     if (rc != NO_ERROR) {
9300         LOGE("Failed to commit batch");
9301     }
9302     return rc;
9303 }
9304 
9305 /*===========================================================================
9306  * FUNCTION   : setAndCommitZoom
9307  *
9308  * DESCRIPTION: set zoom.
9309  *
9310  * PARAMETERS :
9311  *     @zoom_level : zoom level to set.
9312  *
9313  * RETURN     : int32_t type of status
9314  *              NO_ERROR  -- success
9315  *              none-zero failure code
9316  *==========================================================================*/
setAndCommitZoom(int zoom_level)9317 int32_t QCameraParameters::setAndCommitZoom(int zoom_level)
9318 {
9319     LOGH("E");
9320     int32_t rc = NO_ERROR;
9321     if (initBatchUpdate() < 0 ) {
9322         LOGE("Failed to initialize group update table");
9323         return BAD_TYPE;
9324     }
9325 
9326     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZOOM, zoom_level)) {
9327         LOGE("Failed to update table");
9328         return BAD_VALUE;
9329     }
9330 
9331     rc = commitSetBatch();
9332     if (rc != NO_ERROR) {
9333         LOGE("Failed to set Flash value");
9334     }
9335 
9336     mZoomLevel = zoom_level;
9337     LOGH("X");
9338 
9339     return rc;
9340 }
9341 
9342 /*===========================================================================
9343  * FUNCTION   : isOptiZoomEnabled
9344  *
9345  * DESCRIPTION: checks whether optizoom is enabled
9346  *
9347  * PARAMETERS :
9348  *
9349  * RETURN     : true - enabled, false - disabled
9350  *
9351  *==========================================================================*/
isOptiZoomEnabled()9352 bool QCameraParameters::isOptiZoomEnabled()
9353 {
9354     if (m_bOptiZoomOn && (0 <= mParmZoomLevel)) {
9355         uint32_t zoom_level = (uint32_t) mParmZoomLevel;
9356         cam_opti_zoom_t *opti_zoom_settings_need =
9357                 &(m_pCapability->opti_zoom_settings_need);
9358         uint32_t zoom_threshold = (uint32_t) opti_zoom_settings_need->zoom_threshold;
9359         LOGH("current zoom level =%u & zoom_threshold =%u",
9360                  zoom_level, zoom_threshold);
9361 
9362         if (zoom_level >= zoom_threshold) {
9363             return true;
9364         }
9365     }
9366 
9367     return false;
9368 }
9369 
9370 /*===========================================================================
9371  * FUNCTION   : setNoiseReductionMode
9372  *
9373  * DESCRIPTION: set noise reduction mode
9374  *
9375  * PARAMETERS :
9376  *   @noiseReductionModeStr : noise reduction mode
9377  *
9378  * RETURN     : int32_t type of status
9379  *              NO_ERROR  -- success
9380  *              none-zero failure code
9381  *==========================================================================*/
setNoiseReductionMode(const char * noiseReductionModeStr)9382 int32_t QCameraParameters::setNoiseReductionMode(const char *noiseReductionModeStr)
9383 {
9384     LOGH("noiseReductionModeStr = %s", noiseReductionModeStr);
9385     if (noiseReductionModeStr != NULL) {
9386         int value = lookupAttr(NOISE_REDUCTION_MODES_MAP, PARAM_MAP_SIZE(NOISE_REDUCTION_MODES_MAP),
9387                 noiseReductionModeStr);
9388         if (value != NAME_NOT_FOUND) {
9389             m_bHighQualityNoiseReductionMode =
9390                     !strncmp(VALUE_HIGH_QUALITY, noiseReductionModeStr, strlen(VALUE_HIGH_QUALITY));
9391             updateParamEntry(KEY_QC_NOISE_REDUCTION_MODE, noiseReductionModeStr);
9392             return NO_ERROR;
9393         }
9394     }
9395     LOGE("Invalid noise reduction mode value: %s",
9396             (noiseReductionModeStr == NULL) ? "NULL" : noiseReductionModeStr);
9397     return BAD_VALUE;
9398 }
9399 
9400 /*===========================================================================
9401  * FUNCTION   : commitAFBracket
9402  *
9403  * DESCRIPTION: commit AF Bracket.
9404  *
9405  * PARAMETERS :
9406  *   @AFBracket : AF bracketing configuration
9407  *
9408  * RETURN     : int32_t type of status
9409  *              NO_ERROR  -- success
9410  *              none-zero failure code
9411  *==========================================================================*/
commitAFBracket(cam_af_bracketing_t afBracket)9412 int32_t QCameraParameters::commitAFBracket(cam_af_bracketing_t afBracket)
9413 {
9414 
9415     int32_t rc = NO_ERROR;
9416     if(initBatchUpdate() < 0 ) {
9417         LOGE("Failed to initialize group update table");
9418         return BAD_TYPE;
9419     }
9420 
9421     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_BRACKETING, afBracket)) {
9422         LOGE("Failed to update table");
9423         return BAD_VALUE;
9424     }
9425 
9426     rc = commitSetBatch();
9427     if (rc != NO_ERROR) {
9428         LOGE("Failed to commit batch");
9429         return rc;
9430     }
9431 
9432     return rc;
9433 }
9434 
9435 /*===========================================================================
9436  * FUNCTION   : setAFBracket
9437  *
9438  * DESCRIPTION: set AF bracket value
9439  *
9440  * PARAMETERS :
9441  *   @afBracketStr : AF bracket value string
9442  *
9443  * RETURN     : int32_t type of status
9444  *              NO_ERROR  -- success
9445  *              none-zero failure code
9446  *==========================================================================*/
setAFBracket(const char * afBracketStr)9447 int32_t QCameraParameters::setAFBracket(const char *afBracketStr)
9448 {
9449     LOGH("afBracketStr =%s",afBracketStr);
9450 
9451     if(afBracketStr != NULL) {
9452         int value = lookupAttr(AF_BRACKETING_MODES_MAP, PARAM_MAP_SIZE(AF_BRACKETING_MODES_MAP),
9453                 afBracketStr);
9454         if (value != NAME_NOT_FOUND) {
9455             m_bAFBracketingOn = (value != 0);
9456             updateParamEntry(KEY_QC_AF_BRACKET, afBracketStr);
9457 
9458             return NO_ERROR;
9459         }
9460     }
9461 
9462     LOGE("Invalid af bracket value: %s",
9463         (afBracketStr == NULL) ? "NULL" : afBracketStr);
9464     return BAD_VALUE;
9465 }
9466 
9467 /*===========================================================================
9468  * FUNCTION   : setReFocus
9469  *
9470  * DESCRIPTION: set refocus value
9471  *
9472  * PARAMETERS :
9473  *   @afBracketStr : refocus value string
9474  *
9475  * RETURN     : int32_t type of status
9476  *              NO_ERROR  -- success
9477  *              none-zero failure code
9478  *==========================================================================*/
setReFocus(const char * reFocusStr)9479 int32_t QCameraParameters::setReFocus(const char *reFocusStr)
9480 {
9481     LOGH("reFocusStr =%s",reFocusStr);
9482 
9483     if (reFocusStr != NULL) {
9484         int value = lookupAttr(RE_FOCUS_MODES_MAP, PARAM_MAP_SIZE(RE_FOCUS_MODES_MAP),
9485                 reFocusStr);
9486         if (value != NAME_NOT_FOUND) {
9487             m_bReFocusOn = (value != 0);
9488             updateParamEntry(KEY_QC_RE_FOCUS, reFocusStr);
9489             return NO_ERROR;
9490         }
9491     }
9492 
9493     return NO_ERROR;
9494 }
9495 
9496 /*===========================================================================
9497  * FUNCTION   : setChromaFlash
9498  *
9499  * DESCRIPTION: set chroma flash value
9500  *
9501  * PARAMETERS :
9502  *   @aecBracketStr : chroma flash value string
9503  *
9504  * RETURN     : int32_t type of status
9505  *              NO_ERROR  -- success
9506  *              none-zero failure code
9507  *==========================================================================*/
setChromaFlash(const char * chromaFlashStr)9508 int32_t QCameraParameters::setChromaFlash(const char *chromaFlashStr)
9509 {
9510     LOGH("chromaFlashStr =%s",chromaFlashStr);
9511     if(chromaFlashStr != NULL) {
9512         int value = lookupAttr(CHROMA_FLASH_MODES_MAP, PARAM_MAP_SIZE(CHROMA_FLASH_MODES_MAP),
9513                 chromaFlashStr);
9514         if(value != NAME_NOT_FOUND) {
9515             m_bChromaFlashOn = (value != 0);
9516             updateParamEntry(KEY_QC_CHROMA_FLASH, chromaFlashStr);
9517 
9518             return NO_ERROR;
9519         }
9520     }
9521 
9522     LOGE("Invalid chroma flash value: %s",
9523         (chromaFlashStr == NULL) ? "NULL" : chromaFlashStr);
9524     return BAD_VALUE;
9525 }
9526 
9527 /*===========================================================================
9528  * FUNCTION   : setOptiZoom
9529  *
9530  * DESCRIPTION: set opti zoom value
9531  *
9532  * PARAMETERS :
9533  *   @optiZoomStr : opti zoom value string
9534  *
9535  * RETURN     : int32_t type of status
9536  *              NO_ERROR  -- success
9537  *              none-zero failure code
9538  *==========================================================================*/
setOptiZoom(const char * optiZoomStr)9539 int32_t QCameraParameters::setOptiZoom(const char *optiZoomStr)
9540 {
9541     LOGH("optiZoomStr =%s",optiZoomStr);
9542     if(optiZoomStr != NULL) {
9543         int value = lookupAttr(OPTI_ZOOM_MODES_MAP, PARAM_MAP_SIZE(OPTI_ZOOM_MODES_MAP),
9544                 optiZoomStr);
9545         if(value != NAME_NOT_FOUND) {
9546             m_bOptiZoomOn = (value != 0);
9547             updateParamEntry(KEY_QC_OPTI_ZOOM, optiZoomStr);
9548 
9549             return NO_ERROR;
9550         }
9551     }
9552     LOGE("Invalid opti zoom value: %s",
9553         (optiZoomStr == NULL) ? "NULL" : optiZoomStr);
9554     return BAD_VALUE;
9555 }
9556 
9557 /*===========================================================================
9558  * FUNCTION   : setTruePortrait
9559  *
9560  * DESCRIPTION: set true portrait value
9561  *
9562  * PARAMETERS :
9563  *   @optiZoomStr : true portrait value string
9564  *
9565  * RETURN     : int32_t type of status
9566  *              NO_ERROR  -- success
9567  *              none-zero failure code
9568  *==========================================================================*/
setTruePortrait(const char * truePortraitStr)9569 int32_t QCameraParameters::setTruePortrait(const char *truePortraitStr)
9570 {
9571     LOGH("truePortraitStr =%s", truePortraitStr);
9572     if (truePortraitStr != NULL) {
9573         int value = lookupAttr(TRUE_PORTRAIT_MODES_MAP,
9574                 PARAM_MAP_SIZE(TRUE_PORTRAIT_MODES_MAP),
9575                 truePortraitStr);
9576         if (value != NAME_NOT_FOUND) {
9577             m_bTruePortraitOn = (value != 0);
9578             updateParamEntry(KEY_QC_TRUE_PORTRAIT, truePortraitStr);
9579             setFaceDetection(m_bFaceDetectionOn, false);
9580             return NO_ERROR;
9581         }
9582     }
9583     LOGH("Invalid true portrait value: %s",
9584             (truePortraitStr == NULL) ? "NULL" : truePortraitStr);
9585     return BAD_VALUE;
9586 }
9587 
9588 /*===========================================================================
9589  * FUNCTION   : setHDRMode
9590  *
9591  * DESCRIPTION: set hdr mode value
9592  *
9593  * PARAMETERS :
9594  *   @hdrModeStr : hdr mode value string
9595  *
9596  * RETURN     : int32_t type of status
9597  *              NO_ERROR  -- success
9598  *              none-zero failure code
9599  *==========================================================================*/
setHDRMode(const char * hdrModeStr)9600 int32_t QCameraParameters::setHDRMode(const char *hdrModeStr)
9601 {
9602     LOGH("hdrModeStr =%s", hdrModeStr);
9603     if (hdrModeStr != NULL) {
9604         int value = lookupAttr(HDR_MODES_MAP, PARAM_MAP_SIZE(HDR_MODES_MAP), hdrModeStr);
9605         if (value != NAME_NOT_FOUND) {
9606             const char *str = get(KEY_SCENE_MODE);
9607 
9608             m_bHDRModeSensor = !strncmp(hdrModeStr, HDR_MODE_SENSOR, strlen(HDR_MODE_SENSOR));
9609 
9610             updateParamEntry(KEY_QC_HDR_MODE, hdrModeStr);
9611 
9612             // If hdr is already selected, need to deselect it in local cache
9613             // So the new hdr mode will be applied
9614             if (str && !strncmp(str, SCENE_MODE_HDR, strlen(SCENE_MODE_HDR))) {
9615                 updateParamEntry(KEY_SCENE_MODE, SCENE_MODE_AUTO);
9616                 m_bNeedRestart = true;
9617             }
9618 
9619             return NO_ERROR;
9620         }
9621     }
9622     LOGH("Invalid hdr mode value: %s",
9623             (hdrModeStr == NULL) ? "NULL" : hdrModeStr);
9624     return BAD_VALUE;
9625 }
9626 
9627 /*===========================================================================
9628  * FUNCTION   : setSeeMore
9629  *
9630  * DESCRIPTION: set see more value
9631  *
9632  * PARAMETERS :
9633  *   @seeMoreStr : see more value string
9634  *
9635  * RETURN     : int32_t type of status
9636  *              NO_ERROR  -- success
9637  *              none-zero failure code
9638  *==========================================================================*/
setSeeMore(const char * seeMoreStr)9639 int32_t QCameraParameters::setSeeMore(const char *seeMoreStr)
9640 {
9641     int32_t rc = NO_ERROR;
9642 
9643     LOGH("seeMoreStr =%s", seeMoreStr);
9644     if (seeMoreStr != NULL) {
9645         int value = lookupAttr(ON_OFF_MODES_MAP,
9646                 PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
9647                 seeMoreStr);
9648         if (value != NAME_NOT_FOUND) {
9649             m_bSeeMoreOn = (value != 0);
9650 
9651             // If SeeMore is enabled, enable StillMore for live snapshot
9652             // and disable tone map
9653             if (m_bSeeMoreOn) {
9654                 m_bStillMoreOn = TRUE;
9655                 if (!m_bLtmForSeeMoreEnabled) {
9656                     rc = setToneMapMode(false, false);
9657                 }
9658                 if (rc != NO_ERROR) {
9659                     LOGH("Failed to disable tone map during SeeMore");
9660                 }
9661             } else {
9662                 m_bStillMoreOn = FALSE;
9663                 if (!m_bLtmForSeeMoreEnabled) {
9664                     rc = setToneMapMode(true, false);
9665                 }
9666                 if (rc != NO_ERROR) {
9667                     LOGH("Failed to enable tone map during SeeMore");
9668                 }
9669             }
9670             updateParamEntry(KEY_QC_SEE_MORE, seeMoreStr);
9671             return NO_ERROR;
9672         }
9673     }
9674     LOGE("Invalid see more value: %s",
9675             (seeMoreStr == NULL) ? "NULL" : seeMoreStr);
9676     return BAD_VALUE;
9677 }
9678 
9679 /*===========================================================================
9680  * FUNCTION   : setStillMore
9681  *
9682  * DESCRIPTION: set still more value
9683  *
9684  * PARAMETERS :
9685  *   @seeMoreStr : still more value string
9686  *
9687  * RETURN     : int32_t type of status
9688  *              NO_ERROR  -- success
9689  *              none-zero failure code
9690  *==========================================================================*/
setStillMore(const char * stillMoreStr)9691 int32_t QCameraParameters::setStillMore(const char *stillMoreStr)
9692 {
9693     LOGH("stillMoreStr =%s", stillMoreStr);
9694     if (stillMoreStr != NULL) {
9695         int value = lookupAttr(STILL_MORE_MODES_MAP, PARAM_MAP_SIZE(STILL_MORE_MODES_MAP),
9696                 stillMoreStr);
9697         if (value != NAME_NOT_FOUND) {
9698             m_bStillMoreOn = (value != 0);
9699             updateParamEntry(KEY_QC_STILL_MORE, stillMoreStr);
9700 
9701             return NO_ERROR;
9702         }
9703     }
9704     LOGE("Invalid still more value: %s",
9705             (stillMoreStr == NULL) ? "NULL" : stillMoreStr);
9706     return BAD_VALUE;
9707 }
9708 
9709 /*===========================================================================
9710  * FUNCTION   : setHDRNeed1x
9711  *
9712  * DESCRIPTION: set hdr need 1x value
9713  *
9714  * PARAMETERS :
9715  *   @hdrModeStr : hdr need 1x value string
9716  *
9717  * RETURN     : int32_t type of status
9718  *              NO_ERROR  -- success
9719  *              none-zero failure code
9720  *==========================================================================*/
setHDRNeed1x(const char * hdrNeed1xStr)9721 int32_t QCameraParameters::setHDRNeed1x(const char *hdrNeed1xStr)
9722 {
9723     LOGH("hdrNeed1xStr =%s", hdrNeed1xStr);
9724     if (hdrNeed1xStr != NULL) {
9725         int value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
9726                 hdrNeed1xStr);
9727         if (value != NAME_NOT_FOUND) {
9728             updateParamEntry(KEY_QC_HDR_NEED_1X, hdrNeed1xStr);
9729             m_bHDR1xFrameEnabled = !strncmp(hdrNeed1xStr, VALUE_TRUE, strlen(VALUE_TRUE));
9730             m_bNeedRestart = true;
9731 
9732             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR_NEED_1X,
9733                     m_bHDR1xFrameEnabled)) {
9734                 return BAD_VALUE;
9735             }
9736             return NO_ERROR;
9737         }
9738     }
9739 
9740     LOGH("Invalid hdr need 1x value: %s",
9741             (hdrNeed1xStr == NULL) ? "NULL" : hdrNeed1xStr);
9742     return BAD_VALUE;
9743 }
9744 
9745 /*===========================================================================
9746  * FUNCTION   : setAEBracketing
9747  *
9748  * DESCRIPTION: enables AE bracketing
9749  *
9750  * PARAMETERS :
9751  *
9752  * RETURN     : int32_t type of status
9753  *              NO_ERROR  -- success
9754  *              none-zero failure code
9755  *==========================================================================*/
setAEBracketing()9756 int32_t QCameraParameters::setAEBracketing()
9757 {
9758     int32_t rc = NO_ERROR;
9759     if(initBatchUpdate() < 0 ) {
9760         LOGE("Failed to initialize group update table");
9761         return BAD_TYPE;
9762     }
9763 
9764     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR, m_AEBracketingClient)) {
9765         LOGE("Failed to update AE bracketing");
9766         return BAD_VALUE;
9767     }
9768 
9769     rc = commitSetBatch();
9770     if (rc != NO_ERROR) {
9771         LOGE("Failed to configure AE bracketing");
9772         return rc;
9773     }
9774 
9775     return rc;
9776 }
9777 
9778 /*===========================================================================
9779  * FUNCTION   : setHDRAEBracket
9780  *
9781  * DESCRIPTION: enables AE bracketing for HDR
9782  *
9783  * PARAMETERS :
9784  *   @hdrBracket : HDR bracketing configuration
9785  *
9786  * RETURN     : int32_t type of status
9787  *              NO_ERROR  -- success
9788  *              none-zero failure code
9789  *==========================================================================*/
setHDRAEBracket(cam_exp_bracketing_t hdrBracket)9790 int32_t QCameraParameters::setHDRAEBracket(cam_exp_bracketing_t hdrBracket)
9791 {
9792     int32_t rc = NO_ERROR;
9793     if(initBatchUpdate() < 0 ) {
9794         LOGE("Failed to initialize group update table");
9795         return BAD_TYPE;
9796     }
9797 
9798     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR, hdrBracket)) {
9799         LOGE("Failed to update table");
9800         return BAD_TYPE;
9801     }
9802 
9803     rc = commitSetBatch();
9804     if (rc != NO_ERROR) {
9805         LOGE("Failed to configure HDR bracketing");
9806         return rc;
9807     }
9808 
9809     return rc;
9810 }
9811 
9812 /*===========================================================================
9813  * FUNCTION   : setCacheVideoBuffers
9814  *
9815  * DESCRIPTION: set cache video buffers value
9816  *
9817  * PARAMETERS :
9818  *   @cacheVideoStr : cache video buffer value string
9819  *
9820  * RETURN     : int32_t type of status
9821  *              NO_ERROR  -- success
9822  *              none-zero failure code
9823  *==========================================================================*/
setCacheVideoBuffers(const char * cacheVideoBufStr)9824 int32_t QCameraParameters::setCacheVideoBuffers(const char *cacheVideoBufStr)
9825 {
9826     if (cacheVideoBufStr != NULL) {
9827         int8_t cacheVideoBuf = lookupAttr(ENABLE_DISABLE_MODES_MAP,
9828                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), cacheVideoBufStr);
9829         char prop[PROPERTY_VALUE_MAX];
9830         memset(prop, 0, sizeof(prop));
9831         property_get("persist.camera.mem.usecache", prop, "");
9832         if (strlen(prop) > 0) {
9833             cacheVideoBuf = atoi(prop);
9834         }
9835         if (cacheVideoBuf != NAME_NOT_FOUND) {
9836             const char *cacheStr = (strlen(prop)>0) ? prop : cacheVideoBufStr;
9837             LOGD("Setting video buffer %s",
9838                     (cacheVideoBuf == 0) ? "UnCached" : "Cached");
9839             return updateParamEntry(KEY_QC_CACHE_VIDEO_BUFFERS, cacheStr);
9840         }
9841         LOGE("Cache video buffers not set correctly");
9842     }
9843     return BAD_VALUE;
9844 }
9845 
9846 
9847 /*===========================================================================
9848  * FUNCTION   : setCacheVideoBuffers
9849  *
9850  * DESCRIPTION: Set buffers as Cache/Uncache Memory
9851  *
9852  * PARAMETERS :
9853  *   @params  : user setting parameters
9854  *
9855  * RETURN     : int32_t type of status
9856  *              NO_ERROR  -- success
9857  *              none-zero failure code
9858  *==========================================================================*/
setCacheVideoBuffers(const QCameraParameters & params)9859 int32_t QCameraParameters::setCacheVideoBuffers(const QCameraParameters& params)
9860 {
9861     const char *str = params.get(KEY_QC_CACHE_VIDEO_BUFFERS);;
9862     const char *prev_str = get(KEY_QC_CACHE_VIDEO_BUFFERS);
9863 
9864     if (str != NULL) {
9865         if (prev_str == NULL ||
9866                 strcmp(str, prev_str) != 0) {
9867             return setCacheVideoBuffers(str);
9868         }
9869     }
9870     return NO_ERROR;
9871 }
9872 
9873 /*===========================================================================
9874  * FUNCTION   : restoreAEBracket
9875  *
9876  * DESCRIPTION: restores client AE bracketing configuration after HDR is done
9877  *
9878  * PARAMETERS :
9879  *
9880  * RETURN     : int32_t type of status
9881  *              NO_ERROR  -- success
9882  *              none-zero failure code
9883  *==========================================================================*/
stopAEBracket()9884 int32_t QCameraParameters::stopAEBracket()
9885 {
9886   cam_exp_bracketing_t bracketing;
9887 
9888   bracketing.mode = CAM_EXP_BRACKETING_OFF;
9889 
9890   return setHDRAEBracket(bracketing);
9891 }
9892 
9893 /*===========================================================================
9894  * FUNCTION   : updateFlash
9895  *
9896  * DESCRIPTION: restores client flash configuration or disables flash
9897  *
9898  * PARAMETERS :
9899  *   @commitSettings : flag indicating whether settings need to be commited
9900  *
9901  * RETURN     : int32_t type of status
9902  *              NO_ERROR  -- success
9903  *              none-zero failure code
9904  *==========================================================================*/
updateFlash(bool commitSettings)9905 int32_t QCameraParameters::updateFlash(bool commitSettings)
9906 {
9907     int32_t rc = NO_ERROR;
9908     int32_t value;
9909 
9910     if (commitSettings) {
9911       if(initBatchUpdate() < 0 ) {
9912           LOGE("Failed to initialize group update table");
9913           return BAD_TYPE;
9914       }
9915     }
9916     // Turn Off Flash if any of the below AOST features are enabled
9917     if (isHDREnabled() || m_bAeBracketingEnabled || m_bAFBracketingOn ||
9918           m_bOptiZoomOn || m_bReFocusOn || (m_bStillMoreOn && !m_bSeeMoreOn)) {
9919         value = CAM_FLASH_MODE_OFF;
9920     } else if (m_bChromaFlashOn) {
9921         value = CAM_FLASH_MODE_ON;
9922     } else {
9923         value = mFlashValue;
9924     }
9925 
9926     if (value != mFlashDaemonValue) {
9927         LOGD("Setting Flash value %d", value);
9928         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LED_MODE, value)) {
9929             LOGE("Failed to set led mode");
9930             return BAD_VALUE;
9931         }
9932         mFlashDaemonValue = value;
9933     } else {
9934         rc = NO_ERROR;
9935     }
9936 
9937     if (commitSettings) {
9938         rc = commitSetBatch();
9939         if (rc != NO_ERROR) {
9940             LOGE("Failed to configure HDR bracketing");
9941             return rc;
9942         }
9943     }
9944 
9945     return rc;
9946 }
9947 
9948 /*===========================================================================
9949  * FUNCTION   : setRedeyeReduction
9950  *
9951  * DESCRIPTION: set red eye reduction value
9952  *
9953  * PARAMETERS :
9954  *   @redeyeStr : red eye reduction value string
9955  *
9956  * RETURN     : int32_t type of status
9957  *              NO_ERROR  -- success
9958  *              none-zero failure code
9959  *==========================================================================*/
setRedeyeReduction(const char * redeyeStr)9960 int32_t QCameraParameters::setRedeyeReduction(const char *redeyeStr)
9961 {
9962     if (redeyeStr != NULL) {
9963         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
9964                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), redeyeStr);
9965         if (value != NAME_NOT_FOUND) {
9966             LOGD("Setting RedEye Reduce value %s", redeyeStr);
9967             updateParamEntry(KEY_QC_REDEYE_REDUCTION, redeyeStr);
9968             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
9969                     CAM_INTF_PARM_REDEYE_REDUCTION, value)) {
9970                 return BAD_VALUE;
9971             }
9972             return NO_ERROR;
9973         }
9974     }
9975     LOGE("Invalid RedEye Reduce value: %s",
9976            (redeyeStr == NULL) ? "NULL" : redeyeStr);
9977     return BAD_VALUE;
9978 }
9979 
9980 /*===========================================================================
9981  * FUNCTION   : getDenoiseProcessPlate
9982  *
9983  * DESCRIPTION: query denoise process plate
9984  *
9985  * PARAMETERS : None
9986  *
9987  * RETURN     : NR process plate vlaue
9988  *==========================================================================*/
9989 cam_denoise_process_type_t
getDenoiseProcessPlate(cam_intf_parm_type_t type)9990         QCameraParameters::getDenoiseProcessPlate(cam_intf_parm_type_t type)
9991 {
9992     char prop[PROPERTY_VALUE_MAX];
9993     memset(prop, 0, sizeof(prop));
9994     cam_denoise_process_type_t processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
9995     if (CAM_INTF_PARM_WAVELET_DENOISE == type) {
9996         property_get("persist.denoise.process.plates", prop, "");
9997     } else if (CAM_INTF_PARM_TEMPORAL_DENOISE == type) {
9998         property_get("persist.tnr.process.plates", prop, "");
9999     } else {
10000         LOGW("Type not supported");
10001         prop[0] = '\0';
10002     }
10003     if (strlen(prop) > 0) {
10004         switch(atoi(prop)) {
10005         case 0:
10006             processPlate = CAM_WAVELET_DENOISE_YCBCR_PLANE;
10007             break;
10008         case 1:
10009             processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
10010             break;
10011         case 2:
10012             processPlate = CAM_WAVELET_DENOISE_STREAMLINE_YCBCR;
10013             break;
10014         case 3:
10015             processPlate = CAM_WAVELET_DENOISE_STREAMLINED_CBCR;
10016             break;
10017         default:
10018             processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
10019             break;
10020         }
10021     }
10022     return processPlate;
10023 }
10024 
10025 /*===========================================================================
10026  * FUNCTION   : setWaveletDenoise
10027  *
10028  * DESCRIPTION: set wavelet denoise value
10029  *
10030  * PARAMETERS :
10031  *   @wnrStr : wavelet denoise value string
10032  *
10033  * RETURN     : int32_t type of status
10034  *              NO_ERROR  -- success
10035  *              none-zero failure code
10036  *==========================================================================*/
setWaveletDenoise(const char * wnrStr)10037 int32_t QCameraParameters::setWaveletDenoise(const char *wnrStr)
10038 {
10039     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_DENOISE2D) == 0){
10040         LOGH("WNR is not supported");
10041         return NO_ERROR;
10042     }
10043 
10044     if (wnrStr != NULL) {
10045         int value = lookupAttr(DENOISE_ON_OFF_MODES_MAP,
10046                 PARAM_MAP_SIZE(DENOISE_ON_OFF_MODES_MAP), wnrStr);
10047         if (value != NAME_NOT_FOUND) {
10048             updateParamEntry(KEY_QC_DENOISE, wnrStr);
10049 
10050             cam_denoise_param_t temp;
10051             memset(&temp, 0, sizeof(temp));
10052             temp.denoise_enable = (uint8_t)value;
10053             m_bWNROn = (value != 0);
10054             if (m_bWNROn) {
10055                 temp.process_plates = getDenoiseProcessPlate(CAM_INTF_PARM_WAVELET_DENOISE);
10056             }
10057             LOGD("Denoise enable=%d, plates=%d",
10058                    temp.denoise_enable, temp.process_plates);
10059             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WAVELET_DENOISE, temp)) {
10060                 return BAD_VALUE;
10061             }
10062             return NO_ERROR;
10063         }
10064     }
10065     LOGE("Invalid Denoise value: %s", (wnrStr == NULL) ? "NULL" : wnrStr);
10066     return BAD_VALUE;
10067 }
10068 
10069 /*===========================================================================
10070  * FUNCTION   : setRdiMode
10071  *
10072  * DESCRIPTION: set rdi mode value
10073  *
10074  * PARAMETERS :
10075  *   @str     : rdi mode value string
10076  *
10077  * RETURN     : int32_t type of status
10078  *              NO_ERROR  -- success
10079  *              none-zero failure code
10080  *==========================================================================*/
setRdiMode(const char * str)10081 int32_t QCameraParameters::setRdiMode(const char *str)
10082 {
10083     LOGD("RDI_DEBUG  rdi mode value: %s", str);
10084 
10085     if (str != NULL) {
10086         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
10087                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
10088         if (value != NAME_NOT_FOUND) {
10089             updateParamEntry(KEY_QC_RDI_MODE, str);
10090             m_bRdiMode = (value == 0) ? false : true;
10091             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RDI_MODE, value)) {
10092                 return BAD_VALUE;
10093             }
10094             return NO_ERROR;
10095         }
10096     }
10097     LOGE("Invalid rdi mode value: %s", (str == NULL) ? "NULL" : str);
10098     return BAD_VALUE;
10099 }
10100 
10101 
10102 /*===========================================================================
10103  * FUNCTION   : setSecureMode
10104  *
10105  * DESCRIPTION: set secure mode value
10106  *
10107  * PARAMETERS :
10108  *   @str     : secure mode value string
10109  *
10110  * RETURN     : int32_t type of status
10111  *              NO_ERROR  -- success
10112  *              none-zero failure code
10113  *==========================================================================*/
setSecureMode(const char * str)10114 int32_t QCameraParameters::setSecureMode(const char *str)
10115 {
10116   LOGD("Secure mode value: %s", str);
10117 
10118   if (str != NULL) {
10119     int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
10120             PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
10121     if (value != NAME_NOT_FOUND) {
10122         m_bSecureMode = (value == 0)? false : true;
10123         return NO_ERROR;
10124     }
10125   }
10126   LOGE("Invalid Secure mode value: %s",
10127      (str == NULL) ? "NULL" : str);
10128   return BAD_VALUE;
10129 }
10130 
10131 /*===========================================================================
10132  * FUNCTION   : getStreamRotation
10133  *
10134  * DESCRIPTION: get stream rotation by its type
10135  *
10136  * PARAMETERS :
10137  *   @streamType        : stream type
10138  *
10139  * RETURN     : rotation value for stream
10140  *==========================================================================*/
getStreamRotation(cam_stream_type_t streamType)10141 cam_rotation_t QCameraParameters::getStreamRotation(cam_stream_type_t streamType)
10142 {
10143     cam_rotation_t rotation = ROTATE_0;
10144     const char *str = get(KEY_QC_VIDEO_ROTATION);
10145     int rotationParam = lookupAttr(VIDEO_ROTATION_MODES_MAP,
10146             PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP), str);
10147     switch (streamType) {
10148         case CAM_STREAM_TYPE_VIDEO:
10149             switch(rotationParam) {
10150                 case 90:
10151                     rotation = ROTATE_90;
10152                     break;
10153                 case 180:
10154                     rotation = ROTATE_180;
10155                     break;
10156                 case 270:
10157                     rotation = ROTATE_270;
10158                     break;
10159                 default:
10160                     rotation = ROTATE_0;
10161             }
10162             break;
10163         default:
10164             break;
10165     }
10166     return rotation;
10167 }
10168 
10169 /*===========================================================================
10170  * FUNCTION   : getStreamRotation
10171  *
10172  * DESCRIPTION: get stream rotation by its type
10173  *
10174  * PARAMETERS :
10175  *   @streamType        : stream type
10176  *   @featureConfig     : stream feature config structure
10177  *   @dim               : stream dimension
10178  *
10179  * RETURN     : int32_t type of status
10180  *              NO_ERROR  -- success
10181  *              none-zero failure code
10182  *==========================================================================*/
getStreamRotation(cam_stream_type_t streamType,cam_pp_feature_config_t & featureConfig,cam_dimension_t & dim)10183 int32_t QCameraParameters::getStreamRotation(cam_stream_type_t streamType,
10184                                             cam_pp_feature_config_t &featureConfig,
10185                                             cam_dimension_t &dim)
10186 {
10187     int32_t ret = NO_ERROR;
10188 
10189     cam_rotation_t rotation = getStreamRotation(streamType);
10190     featureConfig.rotation = ROTATE_0;
10191     int swapDim = 0;
10192     switch (streamType) {
10193         case CAM_STREAM_TYPE_VIDEO:
10194             switch(rotation) {
10195                 case ROTATE_90:
10196                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
10197                     featureConfig.rotation = ROTATE_90;
10198                     swapDim = 1;
10199                     break;
10200                 case ROTATE_180:
10201                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
10202                     featureConfig.rotation = ROTATE_180;
10203                     break;
10204                 case ROTATE_270:
10205                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
10206                     featureConfig.rotation = ROTATE_270;
10207                     swapDim = 1;
10208                     break;
10209                 default:
10210                     featureConfig.rotation = ROTATE_0;
10211             }
10212             break;
10213         case CAM_STREAM_TYPE_PREVIEW:
10214         case CAM_STREAM_TYPE_POSTVIEW:
10215         case CAM_STREAM_TYPE_SNAPSHOT:
10216         case CAM_STREAM_TYPE_RAW:
10217         case CAM_STREAM_TYPE_METADATA:
10218         case CAM_STREAM_TYPE_OFFLINE_PROC:
10219         case CAM_STREAM_TYPE_DEFAULT:
10220         default:
10221             break;
10222     }
10223 
10224     if (swapDim > 0) {
10225         int w = 0;
10226         w = dim.width;
10227         dim.width = dim.height;
10228         dim.height = w;
10229     }
10230     return ret;
10231 }
10232 
getStreamSubFormat(cam_stream_type_t streamType,cam_sub_format_type_t & sub_format)10233 int32_t QCameraParameters::getStreamSubFormat(cam_stream_type_t streamType,
10234                             cam_sub_format_type_t &sub_format)
10235 {
10236     int32_t ret = NO_ERROR;
10237     sub_format = CAM_FORMAT_SUBTYPE_MAX;
10238 
10239     switch (streamType) {
10240         case CAM_STREAM_TYPE_RAW: {
10241           char raw_sub_format[PROPERTY_VALUE_MAX];
10242           int rawSubFormat;
10243           memset(raw_sub_format, 0, sizeof(raw_sub_format));
10244           /*Default value is CAM_FORMAT_SUBTYPE_PDAF_STATS*/
10245           property_get("persist.camera.raw.subformat", raw_sub_format, "1");
10246           rawSubFormat = atoi(raw_sub_format);
10247           sub_format = (cam_sub_format_type_t)rawSubFormat;
10248           LOGH("Subformat for raw stream = %d", sub_format);
10249         }
10250             break;
10251         default:
10252             break;
10253     }
10254     return ret;
10255 }
10256 /*===========================================================================
10257  * FUNCTION   : getStreamFormat
10258  *
10259  * DESCRIPTION: get stream format by its type
10260  *
10261  * PARAMETERS :
10262  *   @streamType : [input] stream type
10263  *   @format     : [output] stream format
10264  *
10265  * RETURN     : int32_t type of status
10266  *              NO_ERROR  -- success
10267  *              none-zero failure code
10268  *==========================================================================*/
getStreamFormat(cam_stream_type_t streamType,cam_format_t & format)10269 int32_t QCameraParameters::getStreamFormat(cam_stream_type_t streamType,
10270                                             cam_format_t &format)
10271 {
10272     int32_t ret = NO_ERROR;
10273     format = CAM_FORMAT_MAX;
10274     switch (streamType) {
10275     case CAM_STREAM_TYPE_PREVIEW:
10276         if (!isUBWCEnabled()) {
10277 #if VENUS_PRESENT
10278             cam_dimension_t preview;
10279             cam_dimension_t video;
10280             getStreamDimension(CAM_STREAM_TYPE_VIDEO , video);
10281             getStreamDimension(CAM_STREAM_TYPE_PREVIEW, preview);
10282             if (getRecordingHintValue() == true &&
10283                     video.width == preview.width &&
10284                     video.height == preview.height &&
10285                     mPreviewFormat == CAM_FORMAT_YUV_420_NV21) {
10286                 format = CAM_FORMAT_YUV_420_NV21_VENUS;
10287             } else
10288 #endif
10289             format = mPreviewFormat;
10290         } else {
10291             cam_dimension_t preview;
10292             cam_dimension_t video;
10293             getStreamDimension(CAM_STREAM_TYPE_VIDEO , video);
10294             getStreamDimension(CAM_STREAM_TYPE_PREVIEW, preview);
10295             /* Disable UBWC for preview, though supported, to take advantage of CPP duplication*/
10296             if (getRecordingHintValue() == true && (!QCameraCommon::isVideoUBWCEnabled()) &&
10297                 (video.width == preview.width) &&
10298                 (video.height == preview.height)) {
10299 #if VENUS_PRESENT
10300             format = CAM_FORMAT_YUV_420_NV21_VENUS;
10301 #else
10302             format = CAM_FORMAT_YUV_420_NV21;
10303 #endif
10304             }else {
10305                 format = mPreviewFormat;
10306             }
10307         }
10308         break;
10309     case CAM_STREAM_TYPE_POSTVIEW:
10310     case CAM_STREAM_TYPE_CALLBACK:
10311         format = mAppPreviewFormat;
10312         break;
10313     case CAM_STREAM_TYPE_ANALYSIS:
10314         cam_analysis_info_t analysisInfo;
10315         cam_feature_mask_t featureMask;
10316 
10317         featureMask = 0;
10318         getStreamPpMask(CAM_STREAM_TYPE_ANALYSIS, featureMask);
10319         ret = getAnalysisInfo(
10320                 ((getRecordingHintValue() == true) && fdModeInVideo()),
10321                 featureMask,
10322                 &analysisInfo);
10323         if (ret != NO_ERROR) {
10324             LOGE("getAnalysisInfo failed, ret = %d", ret);
10325             return ret;
10326         }
10327 
10328         if (analysisInfo.hw_analysis_supported &&
10329                 analysisInfo.analysis_format == CAM_FORMAT_Y_ONLY) {
10330             format = analysisInfo.analysis_format;
10331         } else {
10332             if (analysisInfo.hw_analysis_supported) {
10333                 LOGW("Invalid analysis_format %d\n",
10334                         analysisInfo.analysis_format);
10335             }
10336             format = mAppPreviewFormat;
10337         }
10338         break;
10339     case CAM_STREAM_TYPE_SNAPSHOT:
10340         if ( mPictureFormat == CAM_FORMAT_YUV_422_NV16 ) {
10341             format = CAM_FORMAT_YUV_422_NV16;
10342         } else {
10343             char prop[PROPERTY_VALUE_MAX];
10344             int snapshotFormat;
10345             memset(prop, 0, sizeof(prop));
10346             property_get("persist.camera.snap.format", prop, "0");
10347             snapshotFormat = atoi(prop);
10348             if(snapshotFormat == 1) {
10349                 format = CAM_FORMAT_YUV_422_NV61;
10350             } else {
10351                 format = CAM_FORMAT_YUV_420_NV21;
10352             }
10353         }
10354         break;
10355     case CAM_STREAM_TYPE_VIDEO:
10356         if (isUBWCEnabled()) {
10357             if (QCameraCommon::isVideoUBWCEnabled()) {
10358                 format = CAM_FORMAT_YUV_420_NV12_UBWC;
10359             } else {
10360                 format = CAM_FORMAT_YUV_420_NV21_VENUS;
10361             }
10362         } else{
10363 #if VENUS_PRESENT
10364             format = CAM_FORMAT_YUV_420_NV21_VENUS;
10365 #else
10366             format = CAM_FORMAT_YUV_420_NV21;
10367 #endif
10368         }
10369         break;
10370     case CAM_STREAM_TYPE_RAW:
10371         if ((isRdiMode()) || (getofflineRAW())|| (getQuadraCfa()) || (isSecureMode())) {
10372             format = m_pCapability->rdi_mode_stream_fmt;
10373         } else if (mPictureFormat >= CAM_FORMAT_YUV_RAW_8BIT_YUYV) {
10374             format = (cam_format_t)mPictureFormat;
10375         } else {
10376             char raw_format[PROPERTY_VALUE_MAX];
10377             int rawFormat;
10378             memset(raw_format, 0, sizeof(raw_format));
10379             /*Default value is CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GBRG*/
10380             property_get("persist.camera.raw.format", raw_format, "17");
10381             rawFormat = atoi(raw_format);
10382             format = (cam_format_t)rawFormat;
10383             LOGH("Raw stream format %d bundled with snapshot",
10384                     format);
10385         }
10386         break;
10387     case CAM_STREAM_TYPE_OFFLINE_PROC:
10388         if (getQuadraCfa()) {
10389             if (m_pCapability->color_arrangement == CAM_FILTER_ARRANGEMENT_BGGR) {
10390                 format = CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_BGGR;
10391             } else if (m_pCapability->color_arrangement == CAM_FILTER_ARRANGEMENT_GBRG) {
10392                 format = CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GBRG;
10393             } else if (m_pCapability->color_arrangement == CAM_FILTER_ARRANGEMENT_GRBG) {
10394                 format = CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GRBG;
10395             } else if (m_pCapability->color_arrangement == CAM_FILTER_ARRANGEMENT_RGGB) {
10396                 format = CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_RGGB;
10397             } else {
10398                 LOGW("Unrecognized format set by sensor, setting default");
10399                 format = m_pCapability->quadra_cfa_format;
10400             }
10401         }
10402         break;
10403     case CAM_STREAM_TYPE_METADATA:
10404     case CAM_STREAM_TYPE_DEFAULT:
10405     default:
10406         break;
10407     }
10408 
10409     LOGD("Stream type = %d Stream Format = %d", streamType, format);
10410     return ret;
10411 }
10412 
10413 /*===========================================================================
10414  * FUNCTION   : getFlipMode
10415  *
10416  * DESCRIPTION: get flip mode
10417  *
10418  * PARAMETERS :
10419  *   @cam_intf_parm_type_t : [input] stream type
10420  *
10421  * RETURN     : int type of flip mode
10422  *              0 - no filp
10423  *              1 - FLIP_H
10424  *              2 - FLIP_V
10425  *              3 - FLIP_H | FLIP_V
10426  *==========================================================================*/
getFlipMode(cam_stream_type_t type)10427 int QCameraParameters::getFlipMode(cam_stream_type_t type)
10428 {
10429     const char *str = NULL;
10430     int flipMode = 0; // no flip
10431 
10432     switch(type){
10433     case CAM_STREAM_TYPE_PREVIEW:
10434         if (!isRdiMode()) {
10435             str = get(KEY_QC_PREVIEW_FLIP);
10436         }
10437         break;
10438     case CAM_STREAM_TYPE_VIDEO:
10439         str = get(KEY_QC_VIDEO_FLIP);
10440         break;
10441     case CAM_STREAM_TYPE_SNAPSHOT:
10442     case CAM_STREAM_TYPE_POSTVIEW:
10443         str = get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
10444         break;
10445     default:
10446         LOGD("No flip mode for stream type %d", type);
10447         break;
10448     }
10449 
10450     if(str != NULL){
10451         //Need give corresponding filp value based on flip mode strings
10452         int value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
10453         if(value != NAME_NOT_FOUND)
10454             flipMode = value;
10455         }
10456 
10457     LOGH("the filp mode of stream type %d is %d .", type, flipMode);
10458     return flipMode;
10459 }
10460 
10461 /*===========================================================================
10462  * FUNCTION   : isSnapshotFDNeeded
10463  *
10464  * DESCRIPTION: check whether Face Detection Metadata is needed
10465  *
10466  * PARAMETERS : none
10467  *
10468  * RETURN     : bool type of status
10469  *              0 - need
10470  *              1 - not need
10471  *==========================================================================*/
isSnapshotFDNeeded()10472 bool QCameraParameters::isSnapshotFDNeeded()
10473 {
10474     return getInt(KEY_QC_SNAPSHOT_FD_DATA);
10475 }
10476 
10477 /*===========================================================================
10478  * FUNCTION   : getStreamDimension
10479  *
10480  * DESCRIPTION: get stream dimension by its type
10481  *
10482  * PARAMETERS :
10483  *   @streamType : [input] stream type
10484  *   @dim             : [output] stream dimension
10485  *   @cam_type    : Camera type in case of dual camera
10486  *
10487  * RETURN     : int32_t type of status
10488  *              NO_ERROR  -- success
10489  *              none-zero failure code
10490  *==========================================================================*/
getStreamDimension(cam_stream_type_t streamType,cam_dimension_t & dim,uint32_t cam_type)10491 int32_t QCameraParameters::getStreamDimension(cam_stream_type_t streamType,
10492         cam_dimension_t &dim, uint32_t cam_type)
10493 {
10494     int32_t ret = NO_ERROR;
10495     memset(&dim, 0, sizeof(cam_dimension_t));
10496 
10497     switch (streamType) {
10498     case CAM_STREAM_TYPE_PREVIEW:
10499     case CAM_STREAM_TYPE_CALLBACK:
10500         getPreviewSize(&dim.width, &dim.height);
10501         break;
10502     case CAM_STREAM_TYPE_POSTVIEW:
10503         getPreviewSize(&dim.width, &dim.height);
10504         break;
10505     case CAM_STREAM_TYPE_SNAPSHOT:
10506         if (isPostProcScaling()) {
10507             getMaxPicSize(dim);
10508         } else if (getRecordingHintValue()) {
10509             // live snapshot
10510             getLiveSnapshotSize(dim);
10511         } else {
10512             getPictureSize(&dim.width, &dim.height);
10513         }
10514         if (isDCmAsymmetricSnapMode()) {
10515             int32_t supportedWidth = 0, supportedHeight = 0;
10516             if (cam_type & MM_CAMERA_TYPE_MAIN) {
10517                 supportedWidth = m_pCapability->main_cam_cap->picture_sizes_tbl[0].width;
10518                 supportedHeight = m_pCapability->main_cam_cap->picture_sizes_tbl[0].height;
10519             } else {
10520                 supportedWidth = m_pCapability->aux_cam_cap->picture_sizes_tbl[0].width;
10521                 supportedHeight = m_pCapability->aux_cam_cap->picture_sizes_tbl[0].height;
10522             }
10523             if ((dim.width * dim.height) >
10524                     (supportedWidth * supportedHeight)){
10525                 dim.width = supportedWidth;
10526                 dim.height = supportedHeight;
10527             }
10528         }
10529         break;
10530     case CAM_STREAM_TYPE_VIDEO:
10531         getVideoSize(&dim.width, &dim.height);
10532         break;
10533     case CAM_STREAM_TYPE_RAW:
10534         //dim = m_pCapability->raw_dim;
10535         getRawSize(dim);
10536         break;
10537     case CAM_STREAM_TYPE_METADATA:
10538         dim.width = (int32_t)sizeof(metadata_buffer_t);
10539         dim.height = 1;
10540         break;
10541     case CAM_STREAM_TYPE_OFFLINE_PROC:
10542         if (isPostProcScaling() || isDCmAsymmetricSnapMode()) {
10543             if (getRecordingHintValue()) {
10544                 // live snapshot
10545                 getLiveSnapshotSize(dim);
10546             } else {
10547                 getPictureSize(&dim.width, &dim.height);
10548             }
10549         }
10550         break;
10551     case CAM_STREAM_TYPE_ANALYSIS:
10552         cam_dimension_t prv_dim;
10553 
10554         /* Analysis stream need aspect ratio as preview stream */
10555         getPreviewSize(&prv_dim.width, &prv_dim.height);
10556 
10557         cam_analysis_info_t analysisInfo;
10558         cam_feature_mask_t featureMask;
10559 
10560         featureMask = 0;
10561         getStreamPpMask(CAM_STREAM_TYPE_ANALYSIS, featureMask);
10562         ret = getAnalysisInfo(
10563                 ((getRecordingHintValue() == true) && fdModeInVideo()),
10564                 featureMask,
10565                 &analysisInfo);
10566         if (ret != NO_ERROR) {
10567             LOGE("getAnalysisInfo failed, ret = %d", ret);
10568             return ret;
10569         }
10570 
10571         dim = mCommon.getMatchingDimension(
10572                 prv_dim, analysisInfo.analysis_recommended_res);
10573         break;
10574     case CAM_STREAM_TYPE_DEFAULT:
10575     default:
10576         LOGE("no dimension for unsupported stream type %d",
10577                streamType);
10578         ret = BAD_VALUE;
10579         break;
10580     }
10581 
10582     LOGD("Stream type = %d Stream Dimension = %d X %d",
10583              streamType, dim.width, dim.height);
10584     return ret;
10585 }
10586 
10587 /*===========================================================================
10588  * FUNCTION   : getParameters
10589  *
10590  * DESCRIPTION: Return a C string containing the parameters
10591  *
10592  * PARAMETERS : none
10593  *
10594  * RETURN     : a string containing parameter pairs
10595  *==========================================================================*/
getParameters()10596 char* QCameraParameters::getParameters()
10597 {
10598     char* strParams = NULL;
10599     String8 str;
10600 
10601     int cur_width, cur_height;
10602     //Need take care Scale picture size
10603     if(m_reprocScaleParam.isScaleEnabled() &&
10604         m_reprocScaleParam.isUnderScaling()){
10605         int scale_width, scale_height;
10606 
10607         m_reprocScaleParam.getPicSizeFromAPK(scale_width,scale_height);
10608         getPictureSize(&cur_width, &cur_height);
10609 
10610         String8 pic_size;
10611         char buffer[32];
10612         snprintf(buffer, sizeof(buffer), "%dx%d", scale_width, scale_height);
10613         pic_size.append(buffer);
10614         set(CameraParameters::KEY_PICTURE_SIZE, pic_size);
10615     }
10616 
10617     str = flatten();
10618     strParams = (char *)malloc(sizeof(char)*(str.length()+1));
10619     if(strParams != NULL){
10620         memset(strParams, 0, sizeof(char)*(str.length()+1));
10621         strlcpy(strParams, str.string(), str.length()+1);
10622         strParams[str.length()] = 0;
10623     }
10624 
10625     if(m_reprocScaleParam.isScaleEnabled() &&
10626         m_reprocScaleParam.isUnderScaling()){
10627         //need set back picture size
10628         String8 pic_size;
10629         char buffer[32];
10630         snprintf(buffer, sizeof(buffer), "%dx%d", cur_width, cur_height);
10631         pic_size.append(buffer);
10632         set(CameraParameters::KEY_PICTURE_SIZE, pic_size);
10633     }
10634     return strParams;
10635 }
10636 
10637 #ifdef TARGET_TS_MAKEUP
10638 /*===========================================================================
10639  * FUNCTION   : getTsMakeupInfo
10640  *
10641  * DESCRIPTION: get TsMakeup info
10642  *
10643  * PARAMETERS :
10644  *   @whiteLevel : [output] white level
10645  *   @cleanLevel : [output] clean level
10646 
10647  * RETURN     : Whether makeup is enabled or not
10648  *==========================================================================*/
getTsMakeupInfo(int & whiteLevel,int & cleanLevel) const10649 bool QCameraParameters::getTsMakeupInfo(int &whiteLevel, int &cleanLevel) const
10650 {
10651     const char* pch_makeup_enable = get(QCameraParameters::KEY_TS_MAKEUP);
10652     if (pch_makeup_enable == NULL) {
10653         LOGH("pch_makeup_enable = null");
10654         return false;
10655     }
10656     bool enableMakeup =
10657             (strcmp(pch_makeup_enable,"On") == 0);
10658     if (enableMakeup) {
10659         whiteLevel = getInt(QCameraParameters::KEY_TS_MAKEUP_WHITEN);
10660         cleanLevel = getInt(QCameraParameters::KEY_TS_MAKEUP_CLEAN);
10661     }
10662     return enableMakeup;
10663 }
10664 #endif
10665 
10666 /*===========================================================================
10667  * FUNCTION   : getPreviewHalPixelFormat
10668  *
10669  * DESCRIPTION: get preview HAL pixel format
10670  *
10671  * PARAMETERS : none
10672  *
10673  * RETURN     : HAL pixel format
10674  *==========================================================================*/
getPreviewHalPixelFormat()10675 int QCameraParameters::getPreviewHalPixelFormat()
10676 {
10677     int32_t halPixelFormat;
10678     cam_format_t fmt;
10679     getStreamFormat(CAM_STREAM_TYPE_PREVIEW,fmt);
10680 
10681     switch (fmt) {
10682     case CAM_FORMAT_YUV_420_NV12:
10683         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP;
10684         break;
10685     case CAM_FORMAT_YUV_420_NV21:
10686         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
10687         break;
10688     case CAM_FORMAT_YUV_420_NV21_ADRENO:
10689         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO;
10690         break;
10691     case CAM_FORMAT_YUV_420_YV12:
10692         halPixelFormat = HAL_PIXEL_FORMAT_YV12;
10693         break;
10694     case CAM_FORMAT_YUV_420_NV12_VENUS:
10695         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS;
10696         break;
10697     case CAM_FORMAT_YUV_420_NV21_VENUS:
10698         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS;
10699         break;
10700     case CAM_FORMAT_YUV_420_NV12_UBWC:
10701         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC;
10702         break;
10703     case CAM_FORMAT_YUV_422_NV16:
10704     case CAM_FORMAT_YUV_422_NV61:
10705     default:
10706         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
10707         break;
10708     }
10709     LOGH("format %d\n", halPixelFormat);
10710     return halPixelFormat;
10711 }
10712 
10713 /*===========================================================================
10714  * FUNCTION   : getQuadraCFA
10715  *
10716  * DESCRIPTION: get QuadraCFA mode
10717  *
10718  * PARAMETERS :
10719  *
10720  * RETURN     : none
10721  *==========================================================================*/
getQuadraCfa()10722 bool QCameraParameters::getQuadraCfa()
10723 {
10724     return m_bQuadraCfa;
10725 }
10726 /*===========================================================================
10727  * FUNCTION   : getthumbnailSize
10728  *
10729  * DESCRIPTION: get thumbnail size
10730  *
10731  * PARAMETERS :
10732  *   @width, height : [output] thumbnail width and height
10733  *
10734  * RETURN     : none
10735  *==========================================================================*/
getThumbnailSize(int * width,int * height) const10736 void QCameraParameters::getThumbnailSize(int *width, int *height) const
10737 {
10738     *width = getInt(KEY_JPEG_THUMBNAIL_WIDTH);
10739     *height = getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
10740 }
10741 
10742 /*===========================================================================
10743  * FUNCTION   : getZSLBurstInterval
10744  *
10745  * DESCRIPTION: get ZSL burst interval setting
10746  *
10747  * PARAMETERS : none
10748  *
10749  * RETURN     : ZSL burst interval value
10750  *==========================================================================*/
getZSLBurstInterval()10751 uint8_t QCameraParameters::getZSLBurstInterval()
10752 {
10753     int interval = getInt(KEY_QC_ZSL_BURST_INTERVAL);
10754     if (interval < 0) {
10755         interval = 1;
10756     }
10757     return (uint8_t)interval;
10758 }
10759 
10760 /*===========================================================================
10761  * FUNCTION   : getZSLQueueDepth
10762  *
10763  * DESCRIPTION: get ZSL queue depth
10764  *
10765  * PARAMETERS : none
10766  *
10767  * RETURN     : ZSL queue depth value
10768  *==========================================================================*/
getZSLQueueDepth()10769 uint8_t QCameraParameters::getZSLQueueDepth()
10770 {
10771     int qdepth = getInt(KEY_QC_ZSL_QUEUE_DEPTH);
10772     if (qdepth < 0) {
10773         qdepth = 2;
10774     }
10775     if (isLowMemoryDevice()) {
10776         qdepth = 1;
10777     }
10778     return (uint8_t)qdepth;
10779 }
10780 
10781 /*===========================================================================
10782  * FUNCTION   : getZSLBackLookCount
10783  *
10784  * DESCRIPTION: get ZSL backlook count setting
10785  *
10786  * PARAMETERS : none
10787  *
10788  * RETURN     : ZSL backlook count value
10789  *==========================================================================*/
getZSLBackLookCount()10790 uint8_t QCameraParameters::getZSLBackLookCount()
10791 {
10792     int look_back = getInt(KEY_QC_ZSL_BURST_LOOKBACK);
10793     if (look_back < 0) {
10794         look_back = 2;
10795     }
10796     if (isLowMemoryDevice()) {
10797         look_back = 1;
10798     }
10799     return (uint8_t)look_back;
10800 }
10801 /*===========================================================================
10802  * FUNCTION   : isVideoBuffersCached
10803  *
10804  * DESCRIPTION: Query buffers are cached /un cached
10805  *
10806  * PARAMETERS : None
10807  *
10808  * RETURN     : buffers are cached /un cached
10809  *==========================================================================*/
isVideoBuffersCached()10810 bool QCameraParameters::isVideoBuffersCached()
10811 {
10812     const char *cached_mem  = get(KEY_QC_CACHE_VIDEO_BUFFERS);
10813     if (cached_mem != NULL) {
10814         if (strcmp(cached_mem, VALUE_DISABLE) != 0) {
10815             return true;
10816         }
10817     }
10818     return false;
10819 }
10820 /*===========================================================================
10821  * FUNCTION   : getZSLMaxUnmatchedFrames
10822  *
10823  * DESCRIPTION: get allowed ZSL max unmatched frames number
10824  *
10825  * PARAMETERS : none
10826  *
10827  * RETURN     : ZSL backlook count value
10828  *==========================================================================*/
getMaxUnmatchedFramesInQueue()10829 uint8_t QCameraParameters::getMaxUnmatchedFramesInQueue()
10830 {
10831     return (uint8_t)(m_pCapability->min_num_pp_bufs);
10832 }
10833 
10834 /*===========================================================================
10835  * FUNCTION   : setRecordingHintValue
10836  *
10837  * DESCRIPTION: set recording hint
10838  *
10839  * PARAMETERS :
10840  *   @value   : video hint value
10841  *
10842  * RETURN     : int32_t type of status
10843  *              NO_ERROR  -- success
10844  *              none-zero failure code
10845  *==========================================================================*/
setRecordingHintValue(int32_t value)10846 int QCameraParameters::setRecordingHintValue(int32_t value)
10847 {
10848     LOGH("VideoHint = %d", value);
10849     bool newValue = (value > 0)? true : false;
10850 
10851     if ( m_bRecordingHint != newValue ) {
10852         m_bNeedRestart = true;
10853         m_bRecordingHint_new = newValue;
10854     } else {
10855         m_bRecordingHint_new = m_bRecordingHint;
10856     }
10857     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RECORDING_HINT, value)) {
10858         return BAD_VALUE;
10859     }
10860 
10861     return NO_ERROR;
10862 }
10863 
10864 /*===========================================================================
10865  * FUNCTION   : getNumOfSnapshots
10866  *
10867  * DESCRIPTION: get number of snapshot per shutter
10868  *
10869  * PARAMETERS : none
10870  *
10871  * RETURN     : number of snapshot per shutter
10872  *==========================================================================*/
getNumOfSnapshots()10873 uint8_t QCameraParameters::getNumOfSnapshots()
10874 {
10875     uint8_t numOfSnapshot = 1;
10876     int val = getInt(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER);
10877     if (0 < val) {
10878         numOfSnapshot = (uint8_t)val;
10879     }
10880 
10881     return (uint8_t)numOfSnapshot;
10882 }
10883 
10884 /*===========================================================================
10885  * FUNCTION   : getBurstCountForAdvancedCapture
10886  *
10887  * DESCRIPTION: get burst count for advanced capture.
10888  *
10889  * PARAMETERS : none
10890  *
10891  * RETURN     : number of snapshot required for advanced capture.
10892  *==========================================================================*/
getBurstCountForAdvancedCapture()10893 uint8_t QCameraParameters::getBurstCountForAdvancedCapture()
10894 {
10895     uint32_t burstCount = 0;
10896     if (isUbiFocusEnabled()) {
10897         //number of snapshots required for Ubi Focus.
10898         burstCount = m_pCapability->ubifocus_af_bracketing_need.burst_count;
10899     } else if (isUbiRefocus()) {
10900         //number of snapshots required for Opti Zoom.
10901         burstCount = m_pCapability->refocus_af_bracketing_need.burst_count;
10902     } else if (isOptiZoomEnabled()) {
10903         //number of snapshots required for Opti Zoom.
10904         burstCount = m_pCapability->opti_zoom_settings_need.burst_count;
10905     } else if (isChromaFlashEnabled()) {
10906         //number of snapshots required for Chroma Flash.
10907         burstCount = m_pCapability->chroma_flash_settings_need.burst_count;
10908     } else if (isStillMoreEnabled()) {
10909         //number of snapshots required for Still More.
10910         if (isSeeMoreEnabled()) {
10911             burstCount = 1;
10912         } else if ((m_stillmore_config.burst_count >=
10913                 m_pCapability->stillmore_settings_need.min_burst_count) &&
10914                 (m_stillmore_config.burst_count <=
10915                 m_pCapability->stillmore_settings_need.max_burst_count)) {
10916             burstCount = m_stillmore_config.burst_count;
10917         } else {
10918             burstCount = m_pCapability->stillmore_settings_need.burst_count;
10919         }
10920     } else if (isHDREnabled()) {
10921         //number of snapshots required for HDR.
10922         burstCount = m_pCapability->hdr_bracketing_setting.num_frames;
10923     } else if (isAEBracketEnabled()) {
10924       burstCount = 0;
10925       const char *str_val = m_AEBracketingClient.values;
10926       if ((str_val != NULL) && (strlen(str_val) > 0)) {
10927           char prop[PROPERTY_VALUE_MAX];
10928           memset(prop, 0, sizeof(prop));
10929           strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
10930           char *saveptr = NULL;
10931           char *token = strtok_r(prop, ",", &saveptr);
10932           while (token != NULL) {
10933               token = strtok_r(NULL, ",", &saveptr);
10934               burstCount++;
10935           }
10936       }
10937     }
10938 
10939     if (burstCount <= 0) {
10940         burstCount = getNumOfSnapshots();
10941     }
10942 
10943     LOGH("Snapshot burst count = %d", burstCount);
10944     return (uint8_t)burstCount;
10945 }
10946 
10947 /*===========================================================================
10948  * FUNCTION   : getNumOfRetroSnapshots
10949  *
10950  * DESCRIPTION: get number of retro active snapshots per shutter
10951  *
10952  * PARAMETERS : none
10953  *
10954  * RETURN     : number of retro active snapshots per shutter
10955  *==========================================================================*/
getNumOfRetroSnapshots()10956 uint8_t QCameraParameters::getNumOfRetroSnapshots()
10957 {
10958     int numOfRetroSnapshots = getInt(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER);
10959     if (numOfRetroSnapshots < 0) {
10960         numOfRetroSnapshots = 0;
10961     }
10962     LOGH("numOfRetroSnaps - %d", numOfRetroSnapshots);
10963     return (uint8_t)numOfRetroSnapshots;
10964 }
10965 
10966 /*===========================================================================
10967  * FUNCTION   : getNumOfExtraHDRInBufsIfNeeded
10968  *
10969  * DESCRIPTION: get number of extra input buffers needed by HDR
10970  *
10971  * PARAMETERS : none
10972  *
10973  * RETURN     : number of extra buffers needed by HDR; 0 if not HDR enabled
10974  *==========================================================================*/
getNumOfExtraHDRInBufsIfNeeded()10975 uint8_t QCameraParameters::getNumOfExtraHDRInBufsIfNeeded()
10976 {
10977     unsigned int numOfBufs = 0;
10978 
10979     if (isHDREnabled()) {
10980         numOfBufs += m_pCapability->hdr_bracketing_setting.num_frames;
10981         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
10982             numOfBufs++;
10983         }
10984         numOfBufs--; // Only additional buffers need to be returned
10985     }
10986 
10987     return (uint8_t)(numOfBufs);
10988 }
10989 
10990 /*===========================================================================
10991  * FUNCTION   : getNumOfExtraHDROutBufsIfNeeded
10992  *
10993  * DESCRIPTION: get number of extra output buffers needed by HDR
10994  *
10995  * PARAMETERS : none
10996  *
10997  * RETURN     : number of extra buffers needed by HDR; 0 if not HDR enabled
10998  *==========================================================================*/
getNumOfExtraHDROutBufsIfNeeded()10999 uint8_t QCameraParameters::getNumOfExtraHDROutBufsIfNeeded()
11000 {
11001     int numOfBufs = 0;
11002 
11003     if (isHDREnabled() && isHDR1xFrameEnabled()) {
11004         numOfBufs++;
11005     }
11006 
11007     return (uint8_t)(numOfBufs);
11008 }
11009 
11010 /*===========================================================================
11011  * FUNCTION   : getJpegQuality
11012  *
11013  * DESCRIPTION: get jpeg encoding quality
11014  *
11015  * PARAMETERS : none
11016  *
11017  * RETURN     : jpeg encoding quality
11018  *==========================================================================*/
getJpegQuality()11019 uint32_t QCameraParameters::getJpegQuality()
11020 {
11021     int quality = getInt(KEY_JPEG_QUALITY);
11022     if (quality < 0) {
11023         quality = 85; // set to default quality value
11024     }
11025     return (uint32_t)quality;
11026 }
11027 
11028 /*===========================================================================
11029  * FUNCTION   : getRotation
11030  *
11031  * DESCRIPTION: get application configured rotation
11032  *
11033  * PARAMETERS : none
11034  *
11035  * RETURN     : rotation value
11036  *==========================================================================*/
getRotation()11037 uint32_t QCameraParameters::getRotation() {
11038     int rotation = 0;
11039 
11040     //If exif rotation is set, do not rotate captured image
11041     if (!useJpegExifRotation()) {
11042         rotation = mRotation;
11043         if (rotation < 0) {
11044             rotation = 0;
11045         }
11046     }
11047     return (uint32_t)rotation;
11048 }
11049 
11050 /*===========================================================================
11051  * FUNCTION   : setJpegRotation
11052  *
11053  * DESCRIPTION: set jpeg rotation value configured internally
11054  *
11055  * PARAMETERS : none
11056  *
11057  * RETURN     : jpeg rotation value
11058  *==========================================================================*/
setJpegRotation(int rotation)11059 void QCameraParameters::setJpegRotation(int rotation) {
11060     if (rotation == 0 || rotation == 90 ||
11061             rotation == 180 || rotation == 270) {
11062         mJpegRotation = (uint32_t)rotation;
11063     }
11064 }
11065 
11066 /*===========================================================================
11067  * FUNCTION   : getDeviceRotation
11068  *
11069  * DESCRIPTION: get device rotation value
11070  *
11071  * PARAMETERS : none
11072  *
11073  * RETURN     : device rotation value
11074  *==========================================================================*/
getDeviceRotation()11075 uint32_t QCameraParameters::getDeviceRotation() {
11076     int rotation = 0;
11077 
11078     rotation = mRotation;
11079     if (rotation < 0) {
11080         rotation = 0;
11081     }
11082 
11083     return (uint32_t)rotation;
11084 }
11085 
11086 /*===========================================================================
11087  * FUNCTION   : getJpegExifRotation
11088  *
11089  * DESCRIPTION: get exif rotation value
11090  *
11091  * PARAMETERS : none
11092  *
11093  * RETURN     : rotation value
11094  *==========================================================================*/
getJpegExifRotation()11095 uint32_t QCameraParameters::getJpegExifRotation() {
11096     int rotation = 0;
11097 
11098     if (useJpegExifRotation()) {
11099         rotation = mRotation;
11100         if (rotation < 0) {
11101             rotation = 0;
11102         }
11103     }
11104     return (uint32_t)rotation;
11105 }
11106 
11107 /*===========================================================================
11108  * FUNCTION   : useJpegExifRotation
11109  *
11110  * DESCRIPTION: Check if jpeg exif rotation need to be used
11111  *
11112  * PARAMETERS : none
11113  *
11114  * RETURN     : true if jpeg exif rotation need to be used
11115  *==========================================================================*/
useJpegExifRotation()11116 bool QCameraParameters::useJpegExifRotation() {
11117     char exifRotation[PROPERTY_VALUE_MAX];
11118 
11119     property_get("persist.camera.exif.rotation", exifRotation, "off");
11120 
11121     if (!strcmp(exifRotation, "on")) {
11122         return true;
11123     }
11124 
11125     if (!(m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_ROTATION)) {
11126         return true;
11127     }
11128 
11129     return false;
11130 }
11131 
11132 /*===========================================================================
11133  * FUNCTION   : getEffectValue
11134  *
11135  * DESCRIPTION: get effect value
11136  *
11137  * PARAMETERS : none
11138  *
11139  * RETURN     : effect value
11140  *==========================================================================*/
getEffectValue()11141 int32_t QCameraParameters::getEffectValue()
11142 {
11143     uint32_t cnt = 0;
11144     const char *effect = get(KEY_EFFECT);
11145     if (effect) {
11146         while (NULL != EFFECT_MODES_MAP[cnt].desc) {
11147             if (!strcmp(EFFECT_MODES_MAP[cnt].desc, effect)) {
11148                 return EFFECT_MODES_MAP[cnt].val;
11149             }
11150             cnt++;
11151         }
11152     } else {
11153         LOGW("Missing effect value");
11154     }
11155     return CAM_EFFECT_MODE_OFF;
11156 }
11157 
11158 /*===========================================================================
11159  * FUNCTION   : parseGPSCoordinate
11160  *
11161  * DESCRIPTION: parse GPS coordinate string
11162  *
11163  * PARAMETERS :
11164  *   @coord_str : [input] coordinate string
11165  *   @coord     : [output]  ptr to struct to store coordinate
11166  *
11167  * RETURN     : int32_t type of status
11168  *              NO_ERROR  -- success
11169  *              none-zero failure code
11170  *==========================================================================*/
parseGPSCoordinate(const char * coord_str,rat_t * coord)11171 int QCameraParameters::parseGPSCoordinate(const char *coord_str, rat_t* coord)
11172 {
11173     if(coord == NULL) {
11174         LOGE("error, invalid argument coord == NULL");
11175         return BAD_VALUE;
11176     }
11177     double degF = atof(coord_str);
11178     if (degF < 0) {
11179         degF = -degF;
11180     }
11181     double minF = (degF - (double)(int) degF) * 60.0;
11182     double secF = (minF - (double)(int) minF) * 60.0;
11183 
11184     getRational(&coord[0], (int)degF, 1);
11185     getRational(&coord[1], (int)minF, 1);
11186     getRational(&coord[2], (int)(secF * 10000.0), 10000);
11187     return NO_ERROR;
11188 }
11189 
11190 /*===========================================================================
11191  * FUNCTION   : getExifDateTime
11192  *
11193  * DESCRIPTION: query exif date time
11194  *
11195  * PARAMETERS :
11196  *   @dateTime    : String to store exif date time.
11197  *                  Should be leaved unchanged in case of error.
11198  *   @subsecTime  : String to store exif time nanoseconds.
11199  *                  Should be leaved unchanged in case of error.
11200  *
11201  * RETURN     : int32_t type of status
11202  *              NO_ERROR  -- success
11203  *              none-zero failure code
11204  *==========================================================================*/
getExifDateTime(String8 & dateTime,String8 & subsecTime)11205 int32_t QCameraParameters::getExifDateTime(String8 &dateTime, String8 &subsecTime)
11206 {
11207     int32_t ret = NO_ERROR;
11208 
11209     //get time and date from system
11210     struct timeval tv;
11211     struct tm timeinfo_data;
11212 
11213     int res = gettimeofday(&tv, NULL);
11214     if (0 == res) {
11215         struct tm *timeinfo = localtime_r(&tv.tv_sec, &timeinfo_data);
11216         if (NULL != timeinfo) {
11217             //Write datetime according to EXIF Spec
11218             //"YYYY:MM:DD HH:MM:SS" (20 chars including \0)
11219             dateTime = String8::format("%04d:%02d:%02d %02d:%02d:%02d",
11220                     timeinfo->tm_year + 1900, timeinfo->tm_mon + 1,
11221                     timeinfo->tm_mday, timeinfo->tm_hour,
11222                     timeinfo->tm_min, timeinfo->tm_sec);
11223             //Write subsec according to EXIF Sepc
11224             subsecTime = String8::format("%06ld", tv.tv_usec);
11225         } else {
11226             LOGE("localtime_r() error");
11227             ret = UNKNOWN_ERROR;
11228         }
11229     } else if (-1 == res) {
11230         LOGE("gettimeofday() error: %s", strerror(errno));
11231         ret = UNKNOWN_ERROR;
11232     } else {
11233         LOGE("gettimeofday() unexpected return code: %d", res);
11234         ret = UNKNOWN_ERROR;
11235     }
11236 
11237     return ret;
11238 }
11239 
11240 /*===========================================================================
11241  * FUNCTION   : getRational
11242  *
11243  * DESCRIPTION: compose rational struct
11244  *
11245  * PARAMETERS :
11246  *   @rat     : ptr to struct to store rational info
11247  *   @num     :num of the rational
11248  *   @denom   : denom of the rational
11249  *
11250  * RETURN     : int32_t type of status
11251  *              NO_ERROR  -- success
11252  *              none-zero failure code
11253  *==========================================================================*/
getRational(rat_t * rat,int num,int denom)11254 int32_t QCameraParameters::getRational(rat_t *rat, int num, int denom)
11255 {
11256     if ((0 > num) || (0 > denom)) {
11257         LOGE("Negative values");
11258         return BAD_VALUE;
11259     }
11260     if (NULL == rat) {
11261         LOGE("NULL rat input");
11262         return BAD_VALUE;
11263     }
11264     rat->num = (uint32_t)num;
11265     rat->denom = (uint32_t)denom;
11266     return NO_ERROR;
11267 }
11268 
11269 /*===========================================================================
11270  * FUNCTION   : getExifFocalLength
11271  *
11272  * DESCRIPTION: get exif focal lenght
11273  *
11274  * PARAMETERS :
11275  *   @focalLength : ptr to rational strcut to store focal lenght
11276  *
11277  * RETURN     : int32_t type of status
11278  *              NO_ERROR  -- success
11279  *              none-zero failure code
11280  *==========================================================================*/
getExifFocalLength(rat_t * focalLength)11281 int32_t QCameraParameters::getExifFocalLength(rat_t *focalLength)
11282 {
11283     int focalLengthValue =
11284         (int)(getFloat(QCameraParameters::KEY_FOCAL_LENGTH) * FOCAL_LENGTH_DECIMAL_PRECISION);
11285     return getRational(focalLength, focalLengthValue, FOCAL_LENGTH_DECIMAL_PRECISION);
11286 }
11287 
11288 /*===========================================================================
11289  * FUNCTION   : getExifIsoSpeed
11290  *
11291  * DESCRIPTION: get exif ISO speed
11292  *
11293  * PARAMETERS : none
11294  *
11295  * RETURN     : ISO speed value
11296  *==========================================================================*/
getExifIsoSpeed()11297 uint16_t QCameraParameters::getExifIsoSpeed()
11298 {
11299     uint16_t isoSpeed = 0;
11300     const char *iso_str = get(QCameraParameters::KEY_QC_ISO_MODE);
11301     int iso_index = lookupAttr(ISO_MODES_MAP, PARAM_MAP_SIZE(ISO_MODES_MAP), iso_str);
11302     switch (iso_index) {
11303     case CAM_ISO_MODE_AUTO:
11304         isoSpeed = 0;
11305         break;
11306     case CAM_ISO_MODE_DEBLUR:
11307         isoSpeed = 1;
11308         break;
11309     case CAM_ISO_MODE_100:
11310         isoSpeed = 100;
11311         break;
11312     case CAM_ISO_MODE_200:
11313         isoSpeed = 200;
11314         break;
11315     case CAM_ISO_MODE_400:
11316         isoSpeed = 400;
11317         break;
11318     case CAM_ISO_MODE_800:
11319         isoSpeed = 800;
11320         break;
11321     case CAM_ISO_MODE_1600:
11322         isoSpeed = 1600;
11323         break;
11324     case CAM_ISO_MODE_3200:
11325         isoSpeed = 3200;
11326         break;
11327     }
11328     return isoSpeed;
11329 }
11330 
11331 /*===========================================================================
11332  * FUNCTION   : getExifGpsProcessingMethod
11333  *
11334  * DESCRIPTION: get GPS processing method
11335  *
11336  * PARAMETERS :
11337  *   @gpsProcessingMethod : string to store GPS process method
11338  *   @count               : lenght of the string
11339  *
11340  * RETURN     : int32_t type of status
11341  *              NO_ERROR  -- success
11342  *              none-zero failure code
11343  *==========================================================================*/
getExifGpsProcessingMethod(char * gpsProcessingMethod,uint32_t & count)11344 int32_t QCameraParameters::getExifGpsProcessingMethod(char *gpsProcessingMethod,
11345                                                       uint32_t &count)
11346 {
11347     const char *str = get(KEY_GPS_PROCESSING_METHOD);
11348     if(str != NULL) {
11349         memcpy(gpsProcessingMethod, ExifAsciiPrefix, EXIF_ASCII_PREFIX_SIZE);
11350         count = EXIF_ASCII_PREFIX_SIZE;
11351         strlcpy(gpsProcessingMethod + EXIF_ASCII_PREFIX_SIZE, str, GPS_PROCESSING_METHOD_SIZE);
11352         count += (uint32_t)strlen(str);
11353         gpsProcessingMethod[count++] = '\0'; // increase 1 for the last NULL char
11354         return NO_ERROR;
11355     } else {
11356         return BAD_VALUE;
11357     }
11358 }
11359 
11360 /*===========================================================================
11361  * FUNCTION   : getExifLatitude
11362  *
11363  * DESCRIPTION: get exif latitude
11364  *
11365  * PARAMETERS :
11366  *   @latitude : ptr to rational struct to store latitude info
11367  *   @ladRef   : charater to indicate latitude reference
11368  *
11369  * RETURN     : int32_t type of status
11370  *              NO_ERROR  -- success
11371  *              none-zero failure code
11372  *==========================================================================*/
getExifLatitude(rat_t * latitude,char * latRef)11373 int32_t QCameraParameters::getExifLatitude(rat_t *latitude,
11374                                            char *latRef)
11375 {
11376     const char *str = get(KEY_GPS_LATITUDE);
11377     if(str != NULL) {
11378         parseGPSCoordinate(str, latitude);
11379 
11380         //set Latitude Ref
11381         float latitudeValue = getFloat(KEY_GPS_LATITUDE);
11382         if(latitudeValue < 0.0f) {
11383             latRef[0] = 'S';
11384         } else {
11385             latRef[0] = 'N';
11386         }
11387         latRef[1] = '\0';
11388         return NO_ERROR;
11389     }else{
11390         return BAD_VALUE;
11391     }
11392 }
11393 
11394 /*===========================================================================
11395  * FUNCTION   : getExifLongitude
11396  *
11397  * DESCRIPTION: get exif longitude
11398  *
11399  * PARAMETERS :
11400  *   @longitude : ptr to rational struct to store longitude info
11401  *   @lonRef    : charater to indicate longitude reference
11402  *
11403  * RETURN     : int32_t type of status
11404  *              NO_ERROR  -- success
11405  *              none-zero failure code
11406  *==========================================================================*/
getExifLongitude(rat_t * longitude,char * lonRef)11407 int32_t QCameraParameters::getExifLongitude(rat_t *longitude,
11408                                             char *lonRef)
11409 {
11410     const char *str = get(KEY_GPS_LONGITUDE);
11411     if(str != NULL) {
11412         parseGPSCoordinate(str, longitude);
11413 
11414         //set Longitude Ref
11415         float longitudeValue = getFloat(KEY_GPS_LONGITUDE);
11416         if(longitudeValue < 0.0f) {
11417             lonRef[0] = 'W';
11418         } else {
11419             lonRef[0] = 'E';
11420         }
11421         lonRef[1] = '\0';
11422         return NO_ERROR;
11423     }else{
11424         return BAD_VALUE;
11425     }
11426 }
11427 
11428 /*===========================================================================
11429  * FUNCTION   : getExifAltitude
11430  *
11431  * DESCRIPTION: get exif altitude
11432  *
11433  * PARAMETERS :
11434  *   @altitude : ptr to rational struct to store altitude info
11435  *   @altRef   : charater to indicate altitude reference
11436  *
11437  * RETURN     : int32_t type of status
11438  *              NO_ERROR  -- success
11439  *              none-zero failure code
11440  *==========================================================================*/
getExifAltitude(rat_t * altitude,char * altRef)11441 int32_t QCameraParameters::getExifAltitude(rat_t *altitude,
11442                                            char *altRef)
11443 {
11444     const char *str = get(KEY_GPS_ALTITUDE);
11445     if(str != NULL) {
11446         double value = atof(str);
11447         *altRef = 0;
11448         if(value < 0){
11449             *altRef = 1;
11450             value = -value;
11451         }
11452         return getRational(altitude, (int)(value*1000), 1000);
11453     }else{
11454         return BAD_VALUE;
11455     }
11456 }
11457 
11458 /*===========================================================================
11459  * FUNCTION   : getExifGpsDateTimeStamp
11460  *
11461  * DESCRIPTION: get exif GPS date time stamp
11462  *
11463  * PARAMETERS :
11464  *   @gpsDateStamp : GPS date time stamp string
11465  *   @bufLen       : length of the string
11466  *   @gpsTimeStamp : ptr to rational struct to store time stamp info
11467  *
11468  * RETURN     : int32_t type of status
11469  *              NO_ERROR  -- success
11470  *              none-zero failure code
11471  *==========================================================================*/
getExifGpsDateTimeStamp(char * gpsDateStamp,uint32_t bufLen,rat_t * gpsTimeStamp)11472 int32_t QCameraParameters::getExifGpsDateTimeStamp(char *gpsDateStamp,
11473                                                    uint32_t bufLen,
11474                                                    rat_t *gpsTimeStamp)
11475 {
11476     const char *str = get(KEY_GPS_TIMESTAMP);
11477     if(str != NULL) {
11478         time_t unixTime = (time_t)atol(str);
11479         struct tm *UTCTimestamp = gmtime(&unixTime);
11480 
11481         if(!UTCTimestamp) {
11482             LOGE("UTCTimestamp is null\n");
11483             return BAD_VALUE;
11484         }
11485 
11486         strftime(gpsDateStamp, bufLen, "%Y:%m:%d", UTCTimestamp);
11487 
11488         getRational(&gpsTimeStamp[0], UTCTimestamp->tm_hour, 1);
11489         getRational(&gpsTimeStamp[1], UTCTimestamp->tm_min, 1);
11490         getRational(&gpsTimeStamp[2], UTCTimestamp->tm_sec, 1);
11491 
11492         return NO_ERROR;
11493     } else {
11494         return BAD_VALUE;
11495     }
11496 }
11497 
11498 /*===========================================================================
11499  * FUNCTION   : updateFocusDistances
11500  *
11501  * DESCRIPTION: update focus distances
11502  *
11503  * PARAMETERS :
11504  *   @focusDistances : ptr to focus distance info
11505  *
11506  * RETURN     : int32_t type of status
11507  *              NO_ERROR  -- success
11508  *              none-zero failure code
11509  *==========================================================================*/
updateFocusDistances(cam_focus_distances_info_t * focusDistances)11510 int32_t QCameraParameters::updateFocusDistances(cam_focus_distances_info_t *focusDistances)
11511 {
11512     String8 str;
11513     char buffer[32] = {0};
11514     //set all distances to infinity if focus mode is infinity
11515     if(mFocusMode == CAM_FOCUS_MODE_INFINITY) {
11516         str.append("Infinity,Infinity,Infinity");
11517     } else {
11518         if (focusDistances->focus_distance[0] < FOCUS_PERCISION) {
11519             str.append("Infinity");
11520         } else {
11521             snprintf(buffer, sizeof(buffer), "%f", 1.0/focusDistances->focus_distance[0]);
11522             str.append(buffer);
11523         }
11524         if (focusDistances->focus_distance[1] < FOCUS_PERCISION) {
11525             str.append(",Infinity");
11526         } else {
11527             snprintf(buffer, sizeof(buffer), ",%f", 1.0/focusDistances->focus_distance[1]);
11528             str.append(buffer);
11529         }
11530         if (focusDistances->focus_distance[2] < FOCUS_PERCISION) {
11531             str.append(",Infinity");
11532         } else {
11533             snprintf(buffer, sizeof(buffer), ",%f", 1.0/focusDistances->focus_distance[2]);
11534             str.append(buffer);
11535         }
11536     }
11537     LOGH("setting KEY_FOCUS_DISTANCES as %s", __FUNCTION__, str.string());
11538     set(QCameraParameters::KEY_FOCUS_DISTANCES, str.string());
11539     return NO_ERROR;
11540 }
11541 
11542 /*===========================================================================
11543  * FUNCTION   : updateRecordingHintValue
11544  *
11545  * DESCRIPTION: update recording hint locally and to daemon
11546  *
11547  * PARAMETERS :
11548  *   @value   : video hint value
11549  *
11550  * RETURN     : int32_t type of status
11551  *              NO_ERROR  -- success
11552  *              none-zero failure code
11553  *==========================================================================*/
updateRecordingHintValue(int32_t value)11554 int32_t QCameraParameters::updateRecordingHintValue(int32_t value)
11555 {
11556     int32_t rc = NO_ERROR;
11557     if(initBatchUpdate() < 0 ) {
11558         LOGE("Failed to initialize group update table");
11559         return BAD_TYPE;
11560     }
11561 
11562     rc = setRecordingHintValue(value);
11563     if (rc != NO_ERROR) {
11564         LOGE("Failed to update table");
11565         return rc;
11566     }
11567 
11568     if(m_bDISEnabled && (value==1)) {
11569         LOGH("%d: Setting DIS value again!!");
11570         setDISValue(VALUE_ENABLE);
11571     }
11572 
11573     rc = commitSetBatch();
11574     if (rc != NO_ERROR) {
11575         LOGE("Failed to update recording hint");
11576         return rc;
11577     }
11578 
11579     return rc;
11580 }
11581 
11582 /*===========================================================================
11583  * FUNCTION   : setHistogram
11584  *
11585  * DESCRIPTION: set histogram
11586  *
11587  * PARAMETERS :
11588  *   @enabled : if histogram is enabled
11589  *
11590  * RETURN     : int32_t type of status
11591  *              NO_ERROR  -- success
11592  *              none-zero failure code
11593  *==========================================================================*/
setHistogram(bool enabled)11594 int32_t QCameraParameters::setHistogram(bool enabled)
11595 {
11596     if(m_bHistogramEnabled == enabled) {
11597         LOGH("histogram flag not changed, no ops here");
11598         return NO_ERROR;
11599     }
11600 
11601     // set parm for histogram
11602     if(initBatchUpdate() < 0 ) {
11603         LOGE("Failed to initialize group update table");
11604         return BAD_TYPE;
11605     }
11606 
11607     int32_t value = enabled ? 1 : 0;
11608     int32_t rc = NO_ERROR;
11609     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HISTOGRAM, value)) {
11610         LOGE("Failed to update table");
11611         return BAD_VALUE;
11612     }
11613 
11614     rc = commitSetBatch();
11615     if (rc != NO_ERROR) {
11616         LOGE("Failed to set histogram");
11617         return rc;
11618     }
11619 
11620     m_bHistogramEnabled = enabled;
11621 
11622     LOGH("Histogram -> %s", m_bHistogramEnabled ? "Enabled" : "Disabled");
11623 
11624     return rc;
11625 }
11626 
11627 /*===========================================================================
11628  * FUNCTION   : setIntEvent
11629  *
11630  * DESCRIPTION: set setIntEvent
11631  *
11632  * PARAMETERS :
11633  *   @params : image size and dimensions
11634  *
11635  * RETURN     : int32_t type of status
11636  *              NO_ERROR  -- success
11637  *              none-zero failure code
11638  *==========================================================================*/
setIntEvent(cam_int_evt_params_t params)11639 int32_t QCameraParameters::setIntEvent(cam_int_evt_params_t params)
11640 {
11641     int32_t rc = NO_ERROR;
11642 
11643     if ( m_pParamBuf == NULL ) {
11644         return NO_INIT;
11645     }
11646 
11647     if(initBatchUpdate() < 0 ) {
11648         LOGE("Failed to initialize group update table");
11649         return BAD_TYPE;
11650     }
11651 
11652     //Sending snapshot taken notification back to Eztune"
11653     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_INT_EVT, params)) {
11654         LOGE("Failed to update table");
11655         return BAD_VALUE;
11656     }
11657 
11658     rc = commitSetBatch();
11659     if (rc != NO_ERROR) {
11660         LOGE("Failed to set frameskip info parm");
11661         return rc;
11662     }
11663 
11664     return rc;
11665 }
11666 
11667 /*===========================================================================
11668  * FUNCTION   : setFaceDetectionOption
11669  *
11670  * DESCRIPTION: set if face detection is enabled by SendCommand
11671  *
11672  * PARAMETERS :
11673  *   @enabled : bool flag if face detection should be enabled
11674  *
11675  * RETURN     : int32_t type of status
11676  *              NO_ERROR  -- success
11677  *              none-zero failure code
11678  *==========================================================================*/
setFaceDetectionOption(bool enabled)11679  int32_t QCameraParameters::setFaceDetectionOption(bool enabled)
11680 {
11681     m_bFaceDetectionOn = enabled;
11682     return NO_ERROR;
11683 }
11684 
11685 /*===========================================================================
11686  * FUNCTION   : setFaceDetection
11687  *
11688  * DESCRIPTION: set face detection
11689  *
11690  * PARAMETERS :
11691  *   @enabled : if face detection is enabled
11692  *   @initCommit : if configuration list need to be initialized and commited
11693  *
11694  * RETURN     : int32_t type of status
11695  *              NO_ERROR  -- success
11696  *              none-zero failure code
11697  *==========================================================================*/
setFaceDetection(bool enabled,bool initCommit)11698 int32_t QCameraParameters::setFaceDetection(bool enabled, bool initCommit)
11699 {
11700     uint32_t faceProcMask = m_nFaceProcMask;
11701     // set face detection mask
11702     if (enabled) {
11703         if (m_pCapability->max_num_roi == 0) {
11704             LOGE("Face detection is not support becuase max number of face is 0");
11705             return BAD_VALUE;
11706         }
11707         faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
11708         if (getRecordingHintValue() > 0) {
11709             faceProcMask = 0;
11710             faceProcMask |= CAM_FACE_PROCESS_MASK_FOCUS;
11711             if (fdModeInVideo() == CAM_FACE_PROCESS_MASK_DETECTION) {
11712                 faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
11713             }
11714         } else {
11715             faceProcMask |= CAM_FACE_PROCESS_MASK_FOCUS;
11716             faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
11717         }
11718         if (isTruePortraitEnabled()) {
11719             LOGL("QCameraParameters::setFaceDetection trueportrait enabled");
11720             faceProcMask |= CAM_FACE_PROCESS_MASK_GAZE;
11721         } else {
11722             LOGL("QCameraParameters::setFaceDetection trueportrait disabled");
11723             faceProcMask &= ~CAM_FACE_PROCESS_MASK_GAZE;
11724         }
11725     } else {
11726         faceProcMask &= ~(CAM_FACE_PROCESS_MASK_DETECTION
11727                 | CAM_FACE_PROCESS_MASK_FOCUS
11728                 | CAM_FACE_PROCESS_MASK_GAZE);
11729     }
11730 
11731     if(m_nFaceProcMask == faceProcMask) {
11732         LOGH("face process mask not changed, no ops here");
11733         return NO_ERROR;
11734     }
11735 
11736     m_nFaceProcMask = faceProcMask;
11737 
11738     // set parm for face detection
11739     uint32_t requested_faces = (uint32_t)getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
11740     cam_fd_set_parm_t fd_set_parm;
11741     memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
11742     fd_set_parm.fd_mode = faceProcMask;
11743     fd_set_parm.num_fd = requested_faces;
11744 
11745     LOGH("[KPI Perf]: PROFILE_FACE_DETECTION_VALUE = %d num_fd = %d",
11746            faceProcMask,requested_faces);
11747 
11748     if (initCommit) {
11749         if(initBatchUpdate() < 0 ) {
11750             LOGE("Failed to initialize group update table");
11751             return BAD_TYPE;
11752         }
11753     }
11754 
11755     int32_t rc = NO_ERROR;
11756 
11757     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FD, fd_set_parm)) {
11758         LOGE("Failed to update table");
11759         return BAD_VALUE;
11760     }
11761 
11762     if (initCommit) {
11763         rc = commitSetBatch();
11764         if (rc != NO_ERROR) {
11765             LOGE("Failed to set face detection parm");
11766             return rc;
11767         }
11768     }
11769 
11770     LOGH("FaceProcMask -> %d", m_nFaceProcMask);
11771 
11772     return rc;
11773 }
11774 
11775 /*===========================================================================
11776  * FUNCTION   : setFrameSkip
11777  *
11778  * DESCRIPTION: send ISP frame skip pattern to camera daemon
11779  *
11780  * PARAMETERS :
11781  *   @pattern : skip pattern for ISP
11782  *
11783  * RETURN     : int32_t type of status
11784  *              NO_ERROR  -- success
11785  *              none-zero failure code
11786  *==========================================================================*/
setFrameSkip(enum msm_vfe_frame_skip_pattern pattern)11787 int32_t QCameraParameters::setFrameSkip(enum msm_vfe_frame_skip_pattern pattern)
11788 {
11789     int32_t rc = NO_ERROR;
11790 
11791     if ( m_pParamBuf == NULL ) {
11792         return NO_INIT;
11793     }
11794 
11795     if(initBatchUpdate() < 0 ) {
11796         LOGE("Failed to initialize group update table");
11797         return BAD_TYPE;
11798     }
11799 
11800     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FRAMESKIP, (int32_t)pattern)) {
11801         LOGE("Failed to update table");
11802         return BAD_VALUE;
11803     }
11804 
11805     rc = commitSetBatch();
11806     if (rc != NO_ERROR) {
11807         LOGE("Failed to set frameskip info parm");
11808         return rc;
11809     }
11810 
11811     return rc;
11812 }
11813 
11814 /*===========================================================================
11815  * FUNCTION   : getSensorOutputSize
11816  *
11817  * DESCRIPTION: Query sensor output size based on maximum stream dimension
11818  *
11819  * PARAMETERS :
11820  *   @max_dim    : maximum stream dimension
11821  *   @sensor_dim : sensor dimension
11822  *   @cam_type   : camera type in case of dual camera
11823  *
11824  * RETURN     : int32_t type of status
11825  *              NO_ERROR  -- success
11826  *              none-zero failure code
11827  *==========================================================================*/
getSensorOutputSize(cam_dimension_t max_dim,cam_dimension_t & sensor_dim,uint32_t cam_type)11828 int32_t QCameraParameters::getSensorOutputSize(cam_dimension_t max_dim,
11829         cam_dimension_t &sensor_dim, uint32_t cam_type)
11830 {
11831     int32_t rc = NO_ERROR;
11832     cam_sensor_mode_info_t modeInfo;
11833     cam_dimension_t pic_dim;
11834 
11835     //No need to update RAW dimensions if meta raw is enabled.
11836     if (m_bMetaRawEnabled) {
11837         return rc;
11838     }
11839     // If offline raw is enabled, check the dimensions from Picture size since snapshot
11840     // stream is not added but final JPEG is required of snapshot size
11841     if (getofflineRAW()) {
11842         if (getQuadraCfa()) {
11843             max_dim.width = m_pCapability->quadra_cfa_dim[0].width;
11844             max_dim.height = m_pCapability->quadra_cfa_dim[0].height;
11845         } else {
11846             getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT, pic_dim);
11847             if (pic_dim.width > max_dim.width) {
11848                 max_dim.width = pic_dim.width;
11849             }
11850             if (pic_dim.height > max_dim.height) {
11851                 max_dim.height = pic_dim.height;
11852             }
11853         }
11854     }
11855 
11856     if (max_dim.width == 0 || max_dim.height == 0) {
11857         max_dim = m_pCapability->raw_dim[0];
11858     }
11859 
11860     if(initBatchUpdate() < 0 ) {
11861         LOGE("Failed to initialize group update table");
11862         return BAD_TYPE;
11863     }
11864 
11865     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MAX_DIMENSION, max_dim)) {
11866         LOGE("Failed to update table for CAM_INTF_PARM_MAX_DIMENSION ");
11867         return BAD_VALUE;
11868     }
11869 
11870     rc = commitSetBatch();
11871     if (rc != NO_ERROR) {
11872         LOGE("Failed to set lock CAM_INTF_PARM_MAX_DIMENSION parm");
11873         return rc;
11874     }
11875 
11876     if(initBatchUpdate() < 0 ) {
11877         LOGE("Failed to initialize group update table");
11878         return BAD_TYPE;
11879     }
11880 
11881     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SENSOR_MODE_INFO);
11882 
11883     rc = commitGetBatch();
11884     if (rc != NO_ERROR) {
11885         LOGE("Failed to get commit CAM_INTF_PARM_SENSOR_MODE_INFO");
11886         return rc;
11887     }
11888 
11889     READ_PARAM_ENTRY(m_pParamBuf, CAM_INTF_PARM_SENSOR_MODE_INFO, modeInfo);
11890     sensor_dim = modeInfo.active_array_size;
11891 
11892 #if 0 // Update to 07.01.01.253.071
11893     if (cam_type == MM_CAMERA_TYPE_AUX) {
11894         READ_PARAM_ENTRY(m_pParamBufAux, CAM_INTF_PARM_RAW_DIMENSION, sensor_dim);
11895     } else {
11896         READ_PARAM_ENTRY(m_pParamBuf, CAM_INTF_PARM_RAW_DIMENSION, sensor_dim);
11897     }
11898 #else
11899     (void) cam_type;
11900 #endif // Update to 07.01.01.253.071
11901 
11902     LOGH("RAW Dimension = %d X %d",sensor_dim.width,sensor_dim.height);
11903     if (sensor_dim.width == 0 || sensor_dim.height == 0) {
11904         LOGW("Error getting RAW size. Setting to Capability value");
11905         if (getQuadraCfa()) {
11906             sensor_dim = m_pCapability->quadra_cfa_dim[0];
11907         } else {
11908             sensor_dim = m_pCapability->raw_dim[0];
11909         }
11910     }
11911     return rc;
11912 }
11913 
11914 /*===========================================================================
11915  * FUNCTION   : updateRAW
11916  *
11917  * DESCRIPTION: get sensor output size and update
11918  *
11919  * PARAMETERS :
11920  *   @max_dim : maximum stream dimension
11921  *
11922  * RETURN     : int32_t type of status
11923  *              NO_ERROR  -- success
11924  *              none-zero failure code
11925  *==========================================================================*/
updateRAW(cam_dimension_t max_dim)11926 int32_t QCameraParameters::updateRAW(cam_dimension_t max_dim)
11927 {
11928     int32_t rc = NO_ERROR;
11929     cam_dimension_t raw_dim;
11930 
11931     getSensorOutputSize(max_dim,raw_dim);
11932     setRawSize(raw_dim);
11933     return rc;
11934 }
11935 
11936 /*===========================================================================
11937  * FUNCTION   : setHDRSceneEnable
11938  *
11939  * DESCRIPTION: sets hdr scene deteced flag
11940  *
11941  * PARAMETERS :
11942  *   @bflag : hdr scene deteced
11943  *
11944  * RETURN     : nothing
11945  *==========================================================================*/
setHDRSceneEnable(bool bflag)11946 void QCameraParameters::setHDRSceneEnable(bool bflag)
11947 {
11948     bool bupdate = false;
11949     if (m_HDRSceneEnabled != bflag) {
11950         bupdate = true;
11951     }
11952     m_HDRSceneEnabled = bflag;
11953 
11954     if (bupdate) {
11955         updateFlash(true);
11956     }
11957 }
11958 
11959 /*===========================================================================
11960  * FUNCTION   : getASDStateString
11961  *
11962  * DESCRIPTION: get ASD result in string format
11963  *
11964  * PARAMETERS :
11965  *   @scene : selected scene mode
11966  *
11967  * RETURN     : int32_t type of status
11968  *              NO_ERROR  -- success
11969  *              none-zero failure code
11970  *==========================================================================*/
getASDStateString(cam_auto_scene_t scene)11971  const char *QCameraParameters::getASDStateString(cam_auto_scene_t scene)
11972 {
11973     switch (scene) {
11974       case S_NORMAL :
11975         return "Normal";
11976       case S_SCENERY:
11977         return "Scenery";
11978       case S_PORTRAIT:
11979         return "Portrait";
11980       case S_PORTRAIT_BACKLIGHT:
11981         return "Portrait-Backlight";
11982       case S_SCENERY_BACKLIGHT:
11983         return "Scenery-Backlight";
11984       case S_BACKLIGHT:
11985         return "Backlight";
11986       default:
11987         return "<Unknown!>";
11988       }
11989 }
11990 
11991 /*===========================================================================
11992  * FUNCTION   : parseNDimVector
11993  *
11994  * DESCRIPTION: helper function to parse a string like "(1, 2, 3, 4, ..., N)"
11995  *              into N-dimension vector
11996  *
11997  * PARAMETERS :
11998  *   @str     : string to be parsed
11999  *   @num     : output array of size N to store vector element values
12000  *   @N       : number of dimension
12001  *   @delim   : delimeter to seperete string
12002  *
12003  * RETURN     : int32_t type of status
12004  *              NO_ERROR  -- success
12005  *              none-zero failure code
12006  *==========================================================================*/
parseNDimVector(const char * str,int * num,int N,char delim=',')12007 int32_t QCameraParameters::parseNDimVector(const char *str, int *num, int N, char delim = ',')
12008 {
12009     char *start, *end;
12010     if (num == NULL) {
12011         LOGE("Invalid output array (num == NULL)");
12012         return BAD_VALUE;
12013     }
12014 
12015     //check if string starts and ends with parantheses
12016     if(str[0] != '(' || str[strlen(str)-1] != ')') {
12017         LOGE("Invalid format of string %s, valid format is (n1, n2, n3, n4 ...)",
12018                str);
12019         return BAD_VALUE;
12020     }
12021     start = (char*) str;
12022     start++;
12023     for(int i=0; i<N; i++) {
12024         *(num+i) = (int) strtol(start, &end, 10);
12025         if(*end != delim && i < N-1) {
12026             LOGE("Cannot find delimeter '%c' in string \"%s\". end = %c",
12027                    delim, str, *end);
12028             return -1;
12029         }
12030         start = end+1;
12031     }
12032     return NO_ERROR;
12033 }
12034 
12035 /*===========================================================================
12036  * FUNCTION   : parseCameraAreaString
12037  *
12038  * DESCRIPTION: helper function to parse a string of camera areas like
12039  *              "(1, 2, 3, 4, 5),(1, 2, 3, 4, 5),..."
12040  *
12041  * PARAMETERS :
12042  *   @str             : string to be parsed
12043  *   @max_num_areas   : max number of areas
12044  *   @pAreas          : ptr to struct to store areas
12045  *   @num_areas_found : number of areas found
12046  *
12047  * RETURN     : int32_t type of status
12048  *              NO_ERROR  -- success
12049  *              none-zero failure code
12050  *==========================================================================*/
parseCameraAreaString(const char * str,int max_num_areas,cam_area_t * pAreas,int & num_areas_found)12051 int32_t QCameraParameters::parseCameraAreaString(const char *str,
12052                                                  int max_num_areas,
12053                                                  cam_area_t *pAreas,
12054                                                  int& num_areas_found)
12055 {
12056     char area_str[32];
12057     const char *start, *end, *p;
12058     start = str; end = NULL;
12059     int values[5], index=0;
12060     num_areas_found = 0;
12061 
12062     memset(values, 0, sizeof(values));
12063     while(start != NULL) {
12064        if(*start != '(') {
12065             LOGE("error: Ill formatted area string: %s", str);
12066             return BAD_VALUE;
12067        }
12068        end = strchr(start, ')');
12069        if(end == NULL) {
12070             LOGE("error: Ill formatted area string: %s", str);
12071             return BAD_VALUE;
12072        }
12073        int i;
12074        for (i=0,p=start; p<=end; p++, i++) {
12075            area_str[i] = *p;
12076        }
12077        area_str[i] = '\0';
12078        if(parseNDimVector(area_str, values, 5) < 0){
12079             LOGE("error: Failed to parse the area string: %s", area_str);
12080             return BAD_VALUE;
12081        }
12082        // no more areas than max_num_areas are accepted.
12083        if(index >= max_num_areas) {
12084             LOGE("error: too many areas specified %s", str);
12085             return BAD_VALUE;
12086        }
12087        pAreas[index].rect.left = values[0];
12088        pAreas[index].rect.top = values[1];
12089        pAreas[index].rect.width = values[2] - values[0];
12090        pAreas[index].rect.height = values[3] - values[1];
12091        pAreas[index].weight = values[4];
12092 
12093        index++;
12094        start = strchr(end, '('); // serach for next '('
12095     }
12096     num_areas_found = index;
12097     return 0;
12098 }
12099 
12100 /*===========================================================================
12101  * FUNCTION   : validateCameraAreas
12102  *
12103  * DESCRIPTION: helper function to validate camera areas within (-1000, 1000)
12104  *
12105  * PARAMETERS :
12106  *   @areas     : ptr to array of areas
12107  *   @num_areas : number of areas
12108  *
12109  * RETURN     : true --  area is in valid range
12110  *              false -- not valid
12111  *==========================================================================*/
validateCameraAreas(cam_area_t * areas,int num_areas)12112 bool QCameraParameters::validateCameraAreas(cam_area_t *areas, int num_areas)
12113 {
12114     // special case: default area
12115     if (num_areas == 1 &&
12116         areas[0].rect.left == 0 &&
12117         areas[0].rect.top == 0 &&
12118         areas[0].rect.width == 0 &&
12119         areas[0].rect.height == 0 &&
12120         areas[0].weight == 0) {
12121         return true;
12122     }
12123 
12124     for(int i = 0; i < num_areas; i++) {
12125         // left should be >= -1000
12126         if(areas[i].rect.left < -1000) {
12127             return false;
12128         }
12129 
12130         // top  should be >= -1000
12131         if(areas[i].rect.top < -1000) {
12132             return false;
12133         }
12134 
12135         // width or height should be > 0
12136         if (areas[i].rect.width <= 0 || areas[i].rect.height <= 0) {
12137             return false;
12138         }
12139 
12140         // right  should be <= 1000
12141         if(areas[i].rect.left + areas[i].rect.width > 1000) {
12142             return false;
12143         }
12144 
12145         // bottom should be <= 1000
12146         if(areas[i].rect.top + areas[i].rect.height > 1000) {
12147             return false;
12148         }
12149 
12150         // weight should be within (1, 1000)
12151         if (areas[i].weight < 1 || areas[i].weight > 1000) {
12152             return false;
12153         }
12154     }
12155     return true;
12156 }
12157 
12158 /*===========================================================================
12159  * FUNCTION   : isYUVFrameInfoNeeded
12160  *
12161  * DESCRIPTION: In AE-Bracket mode, we need set yuv buffer information for up-layer
12162  *
12163  * PARAMETERS : none
12164  *
12165  * RETURN     : true: needed
12166  *              false: no need
12167  *==========================================================================*/
isYUVFrameInfoNeeded()12168 bool QCameraParameters::isYUVFrameInfoNeeded()
12169 {
12170     //In AE-Bracket mode, we need set raw buffer information for up-layer
12171     if(!isNV21PictureFormat() && !isNV16PictureFormat()){
12172         return false;
12173     }
12174     const char *aecBracketStr =  get(KEY_QC_AE_BRACKET_HDR);
12175 
12176     int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
12177             aecBracketStr);
12178     LOGH("aecBracketStr=%s, value=%d.", aecBracketStr, value);
12179     return (value == CAM_EXP_BRACKETING_ON);
12180 }
12181 
12182 /*===========================================================================
12183  * FUNCTION   : getFrameFmtString
12184  *
12185  * DESCRIPTION: get string name of frame format
12186  *
12187  * PARAMETERS :
12188  *   @frame   : frame format
12189  *
12190  * RETURN     : string name of frame format
12191  *==========================================================================*/
getFrameFmtString(cam_format_t fmt)12192 const char *QCameraParameters::getFrameFmtString(cam_format_t fmt)
12193 {
12194     return lookupNameByValue(PICTURE_TYPES_MAP, PARAM_MAP_SIZE(PICTURE_TYPES_MAP), fmt);
12195 }
12196 
12197 /*===========================================================================
12198  * FUNCTION   : setDcrf
12199  *
12200  * DESCRIPTION: Enable/Disable DCRF (dual-camera-range-finding)
12201  *
12202  * RETURN     : none
12203  *==========================================================================*/
setDcrf()12204 void QCameraParameters::setDcrf()
12205 {
12206     char prop[PROPERTY_VALUE_MAX];
12207     memset(prop, 0, sizeof(prop));
12208 
12209     // Set DCRF to off by default (assuming single-camera mode)
12210     m_bDcrfEnabled = 0;
12211 
12212     // In dual-cam mode, get sysprop and set it to on by default
12213     if(m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
12214         property_get("persist.camera.dcrf.enable", prop, "1");
12215         m_bDcrfEnabled = atoi(prop);
12216     }
12217 }
12218 
12219 /*===========================================================================
12220  * FUNCTION   : setRelatedCamSyncInfo
12221  *
12222  * DESCRIPTION: set the related cam info parameters
12223  * the related cam info is cached into params to make some decisions beforehand
12224  *
12225  * PARAMETERS :
12226  *   @info  : ptr to related cam info parameters
12227  *
12228  * RETURN     : int32_t type of status
12229  *              NO_ERROR  -- success
12230  *              none-zero failure code
12231  *==========================================================================*/
setRelatedCamSyncInfo(cam_sync_related_sensors_event_info_t * info)12232 int32_t QCameraParameters::setRelatedCamSyncInfo(
12233         cam_sync_related_sensors_event_info_t* info)
12234 {
12235     if(info != NULL){
12236         memcpy(&m_relCamSyncInfo, info,
12237                 sizeof(cam_sync_related_sensors_event_info_t));
12238         return NO_ERROR;
12239     } else {
12240         LOGE("info buffer is null");
12241         return UNKNOWN_ERROR;
12242     }
12243 }
12244 
12245 /*===========================================================================
12246  * FUNCTION   : getRelatedCamSyncInfo
12247  *
12248  * DESCRIPTION:returns the related cam sync info for this HWI instance
12249  *
12250  * PARAMETERS :none
12251  *
12252  * RETURN     : const pointer to cam_sync_related_sensors_event_info_t
12253  *==========================================================================*/
12254 const cam_sync_related_sensors_event_info_t*
getRelatedCamSyncInfo(void)12255         QCameraParameters::getRelatedCamSyncInfo(void)
12256 {
12257     return &m_relCamSyncInfo;
12258 }
12259 
12260 /*===========================================================================
12261  * FUNCTION   : setFrameSyncEnabled
12262  *
12263  * DESCRIPTION: sets whether frame sync is enabled
12264  *
12265  * PARAMETERS :
12266  *   @enable  : flag whether to enable or disable frame sync
12267  *
12268  * RETURN     : int32_t type of status
12269  *              NO_ERROR  -- success
12270  *              none-zero failure code
12271  *==========================================================================*/
setFrameSyncEnabled(bool enable)12272 int32_t QCameraParameters::setFrameSyncEnabled(bool enable)
12273 {
12274     m_bFrameSyncEnabled = enable;
12275     return NO_ERROR;
12276 }
12277 
12278 /*===========================================================================
12279  * FUNCTION   : isFrameSyncEnabled
12280  *
12281  * DESCRIPTION: returns whether frame sync is enabled
12282  *
12283  * PARAMETERS :none
12284  *
12285  * RETURN     : bool indicating whether frame sync is enabled
12286  *==========================================================================*/
isFrameSyncEnabled(void)12287 bool QCameraParameters::isFrameSyncEnabled(void)
12288 {
12289     return m_bFrameSyncEnabled;
12290 }
12291 
12292 /*===========================================================================
12293  * FUNCTION   : sendDualCamBundle
12294  *
12295  * DESCRIPTION: send trigger for bundling related camera sessions in the server
12296  *
12297  * PARAMETERS :
12298  *   @sync_enable :indicates whether syncing is On or Off
12299  *   @sessionid   :session id for other camera session
12300  *
12301  * RETURN     : int32_t type of status
12302  *              NO_ERROR  -- success
12303  *              none-zero failure code
12304  *NOTE: This bundle info needs to called only once per session.
12305  * Should be called after open and before start stream.
12306  * Application can trigger this function to enable module SYNC in dual camera case
12307  *==========================================================================*/
setDualCamBundleInfo(bool enable_sync,uint8_t bundle_cam_idx)12308 int32_t QCameraParameters::setDualCamBundleInfo(bool enable_sync,
12309         uint8_t bundle_cam_idx)
12310 {
12311     int32_t rc = NO_ERROR;
12312     cam_dual_camera_bundle_info_t bundle_info;
12313     uint8_t num_cam = 0;
12314     int32_t sync = 0;
12315     uint32_t mode, type, role = 0;
12316     cam_3a_sync_mode_t sync_3a_mode = CAM_3A_SYNC_FOLLOW;
12317     char prop[PROPERTY_VALUE_MAX];
12318     memset(prop, 0, sizeof(prop));
12319 
12320     if(enable_sync) {
12321         sync = (int32_t)CAM_SYNC_RELATED_SENSORS_ON;
12322     } else {
12323         sync = (int32_t)CAM_SYNC_RELATED_SENSORS_OFF;
12324     }
12325 
12326     property_get("persist.camera.stats.test.2outs", prop, "0");
12327     sync_3a_mode = (atoi(prop) > 0) ? CAM_3A_SYNC_ALGO_CTRL : sync_3a_mode;
12328 
12329     if (m_pCapability->position == CAM_POSITION_BACK_AUX) {
12330         mode = CAM_MODE_SECONDARY;
12331         type = CAM_TYPE_AUX;
12332     } else {
12333         mode = CAM_MODE_PRIMARY;
12334         type = CAM_TYPE_MAIN;
12335     }
12336 
12337     if (m_pCapability->lens_type == CAM_LENS_WIDE) {
12338         role = CAM_ROLE_WIDE;
12339     } else if (m_pCapability->lens_type == CAM_LENS_TELE) {
12340         role = CAM_ROLE_TELE;
12341     }
12342     bundle_info.sync_control =
12343             (cam_sync_related_sensors_control_t)sync;
12344     bundle_info.mode = (cam_sync_mode_t)mode;
12345     bundle_info.type = (cam_sync_type_t)type;
12346     bundle_info.cam_role = (cam_dual_camera_role_t)role;
12347     bundle_info.related_sensor_session_id = sessionId[bundle_cam_idx];
12348     bundle_info.perf_mode = getLowPowerMode(bundle_info.type);
12349     bundle_info.is_hw_sync_enabled = DUALCAM_HW_SYNC_ENABLED;
12350     num_cam++;
12351 
12352     rc = sendDualCamCmd(CAM_DUAL_CAMERA_BUNDLE_INFO,
12353             num_cam, &bundle_info);
12354     return rc;
12355 }
12356 
12357 /*===========================================================================
12358  * FUNCTION   : sendDualCamCmd
12359  *
12360  * DESCRIPTION: send dual camera related commands
12361  *
12362  * PARAMETERS :
12363  *   @sync_enable        :indicates whether syncing is On or Off
12364  *   @sessionid  :session id for other camera session
12365  *
12366  * RETURN     : int32_t type of status
12367  *              NO_ERROR  -- success
12368  *              none-zero failure code
12369  *NOTE: This bundle info needs to called only once per session.
12370  * Should be called after open and before start stream.
12371  *==========================================================================*/
sendDualCamCmd(cam_dual_camera_cmd_type type,uint8_t num_cam,void * cmd_value)12372 int32_t QCameraParameters::sendDualCamCmd(cam_dual_camera_cmd_type type,
12373         uint8_t num_cam, void *cmd_value)
12374 {
12375     int32_t rc = NO_ERROR;
12376     if (NULL == m_pCamOpsTbl) {
12377         LOGE("Ops not initialized");
12378         return NO_INIT;
12379     }
12380 
12381     if (cmd_value == NULL || num_cam > MM_CAMERA_MAX_CAM_CNT
12382             || m_pDualCamCmdPtr[0] == NULL) {
12383         LOGE("Invalid argument = %d, %p", num_cam, cmd_value);
12384         return BAD_VALUE;
12385     }
12386 
12387     for (int i = 0; i < MM_CAMERA_MAX_CAM_CNT; i++) {
12388         memset(m_pDualCamCmdPtr[i], 0,
12389                 sizeof(cam_dual_camera_cmd_info_t));
12390     }
12391 
12392     switch(type) {
12393         case CAM_DUAL_CAMERA_BUNDLE_INFO: {
12394             for (int i = 0; i < num_cam; i++) {
12395                 cam_dual_camera_bundle_info_t *info =
12396                         (cam_dual_camera_bundle_info_t *)cmd_value;
12397                 m_pDualCamCmdPtr[i]->cmd_type = type;
12398                 memcpy(&m_pDualCamCmdPtr[i]->bundle_info,
12399                         &info[i],
12400                         sizeof(cam_dual_camera_bundle_info_t));
12401                 LOGH("SYNC CMD %d: cmd %d mode %d type %d hw-sync %d session - %d", i,
12402                         m_pDualCamCmdPtr[i]->cmd_type,
12403                         m_pDualCamCmdPtr[i]->bundle_info.mode,
12404                         m_pDualCamCmdPtr[i]->bundle_info.type,
12405                         m_pDualCamCmdPtr[i]->bundle_info.is_hw_sync_enabled,
12406                         m_pDualCamCmdPtr[i]->bundle_info.related_sensor_session_id);
12407             }
12408         }
12409         break;
12410 
12411         case CAM_DUAL_CAMERA_LOW_POWER_MODE: {
12412             for (int i = 0; i < num_cam; i++) {
12413                 cam_dual_camera_perf_control_t *info =
12414                         (cam_dual_camera_perf_control_t *)cmd_value;
12415                 m_pDualCamCmdPtr[i]->cmd_type = type;
12416                 memcpy(&m_pDualCamCmdPtr[i]->value,
12417                         &info[i],
12418                         sizeof(cam_dual_camera_perf_control_t));
12419                 LOGH("LPM CMD %d: cmd %d LPM Enable - %d mode = %d", i,
12420                         m_pDualCamCmdPtr[i]->cmd_type,
12421                         m_pDualCamCmdPtr[i]->value.enable,
12422                         m_pDualCamCmdPtr[i]->value.perf_mode);
12423             }
12424         }
12425         break;
12426 
12427         case CAM_DUAL_CAMERA_MASTER_INFO: {
12428             for (int i = 0; i < num_cam; i++) {
12429                 cam_dual_camera_master_info_t *info =
12430                         (cam_dual_camera_master_info_t *)cmd_value;
12431                 m_pDualCamCmdPtr[i]->cmd_type = type;
12432                 memcpy(&m_pDualCamCmdPtr[i]->mode,
12433                         &info[i],
12434                         sizeof(cam_dual_camera_master_info_t));
12435                 LOGH("MASTER INFO CMD %d: cmd %d value %d", i,
12436                         m_pDualCamCmdPtr[i]->cmd_type,
12437                         m_pDualCamCmdPtr[i]->mode);
12438             }
12439         }
12440         break;
12441 
12442         case CAM_DUAL_CAMERA_DEFER_INFO: {
12443             cam_dual_camera_defer_cmd_t *info =
12444                     (cam_dual_camera_defer_cmd_t *)cmd_value;
12445             for (int i = 0; i < num_cam; i++) {
12446                 m_pDualCamCmdPtr[i]->cmd_type = type;
12447                 memcpy(&m_pDualCamCmdPtr[i]->defer_cmd,
12448                         &info[i],
12449                         sizeof(cam_dual_camera_master_info_t));
12450                 LOGH("DEFER INFO CMD %d: cmd %d value %d", i,
12451                         m_pDualCamCmdPtr[i]->cmd_type,
12452                         m_pDualCamCmdPtr[i]->defer_cmd);
12453             }
12454         }
12455         break;
12456         default :
12457         break;
12458     }
12459 
12460     rc = m_pCamOpsTbl->ops->set_dual_cam_cmd(m_pCamOpsTbl->camera_handle);
12461     return rc;
12462 }
12463 
12464 /*===========================================================================
12465  * FUNCTION   : bundleRelatedCameras
12466  *
12467  * DESCRIPTION: send trigger for bundling related camera sessions in the server
12468  *
12469  * PARAMETERS :
12470  *   @sync        :indicates whether syncing is On or Off
12471  *   @sessionid  :session id for other camera session
12472  *
12473  * RETURN     : int32_t type of status
12474  *              NO_ERROR  -- success
12475  *              none-zero failure code
12476  *==========================================================================*/
bundleRelatedCameras(bool sync)12477 int32_t QCameraParameters::bundleRelatedCameras(bool sync)
12478 {
12479     int32_t rc = NO_ERROR;
12480     setDualCamBundleInfo(sync, m_pCapability->camera_index);
12481     return rc;
12482 }
12483 
12484 /*===========================================================================
12485  * FUNCTION   : getRelatedCamCalibration
12486  *
12487  * DESCRIPTION: fetch the related camera subsystem calibration data
12488  *
12489  * PARAMETERS :
12490  *   @calib  : calibration data fetched
12491  *
12492  * RETURN     : int32_t type of status
12493  *              NO_ERROR  -- success
12494  *              none-zero failure code
12495  *==========================================================================*/
getRelatedCamCalibration(cam_related_system_calibration_data_t * calib)12496 int32_t QCameraParameters::getRelatedCamCalibration(
12497         cam_related_system_calibration_data_t* calib)
12498 {
12499     int32_t rc = NO_ERROR;
12500 
12501     if(!calib) {
12502         return BAD_TYPE;
12503     }
12504 
12505     if(initBatchUpdate() < 0 ) {
12506         LOGE("Failed to initialize group update table");
12507         return BAD_TYPE;
12508     }
12509 
12510     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
12511             CAM_INTF_PARM_RELATED_SENSORS_CALIBRATION);
12512 
12513     rc = commitGetBatch();
12514     if (rc != NO_ERROR) {
12515         LOGE("Failed to get related cam calibration info");
12516         return rc;
12517     }
12518 
12519     READ_PARAM_ENTRY(m_pParamBuf,
12520             CAM_INTF_PARM_RELATED_SENSORS_CALIBRATION, *calib);
12521 
12522     LOGD("CALIB version %d ", calib->calibration_format_version);
12523     LOGD("CALIB normalized_focal_length %f ",
12524             calib->main_cam_specific_calibration.normalized_focal_length);
12525     LOGD("CALIB native_sensor_resolution_width %d ",
12526             calib->main_cam_specific_calibration.native_sensor_resolution_width);
12527     LOGD("CALIB native_sensor_resolution_height %d ",
12528             calib->main_cam_specific_calibration.native_sensor_resolution_height);
12529     LOGD("CALIB sensor_resolution_width %d ",
12530             calib->main_cam_specific_calibration.calibration_sensor_resolution_width);
12531     LOGD("CALIB sensor_resolution_height %d ",
12532             calib->main_cam_specific_calibration.calibration_sensor_resolution_height);
12533     LOGD("CALIB focal_length_ratio %f ",
12534             calib->main_cam_specific_calibration.focal_length_ratio);
12535 
12536     return rc;
12537 }
12538 
12539 /*===========================================================================
12540  * FUNCTION   : setSyncDCParams
12541  *
12542  * DESCRIPTION: Enable/Disable sync Dual-camera Parameters
12543  *              Set this parameter when Dual camera needs to sync
12544  *
12545  * RETURN     : none
12546  *==========================================================================*/
setSyncDCParams()12547 void QCameraParameters::setSyncDCParams()
12548 {
12549     uint32_t temp_mSyncDCParam = 0;
12550     char prop[PROPERTY_VALUE_MAX];
12551     memset(prop, 0, sizeof(prop));
12552 
12553     //Keep it enable by default.
12554     //It will be used for Dual camera sync parameters
12555     property_get("persist.camera.syncDCParams.en", prop, "1");
12556     temp_mSyncDCParam = atoi(prop);
12557 
12558     if (MM_CAMERA_DUAL_CAM == mActiveCameras) {
12559         mSyncDCParam = temp_mSyncDCParam;
12560     }
12561 }
12562 
12563 
12564 /*===========================================================================
12565  * FUNCTION   : SyncDCParams
12566  *
12567  * DESCRIPTION: Add sync dual camera parameter if this super parameter applies
12568  *              to all related camera.
12569                 This is the indication to MCT that this parameter needs to
12570  *              synchronized. There will be another parameter entry in
12571                 other camera with different values
12572  *
12573  * PARAMETERS : none
12574  *
12575  * RETURN     : int32_t type of status
12576  *              NO_ERROR  -- success
12577  *              none-zero failure code
12578  *==========================================================================*/
SyncDCParams()12579 int32_t QCameraParameters::SyncDCParams()
12580 {
12581     //Add dual-parameter in parameters
12582     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
12583         CAM_INTF_PARM_SYNC_DC_PARAMETERS, mSyncDCParam)) {
12584         LOGE("Failed to update table");
12585         return BAD_VALUE;
12586     }
12587     return NO_ERROR;
12588 }
12589 
12590 /*===========================================================================
12591  * FUNCTION   : updateFrameNumber
12592  *
12593  * DESCRIPTION: update frame number and add frame number in parameters
12594  *
12595  * PARAMETERS : none
12596  *
12597  * RETURN     : int32_t type of status
12598  *              NO_ERROR  -- success
12599  *              none-zero failure code
12600  *==========================================================================*/
updateFrameNumber()12601 int32_t QCameraParameters::updateFrameNumber()
12602 {
12603     mFrameNumber++;
12604     //Add frame number in parameters
12605     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_META_FRAME_NUMBER,
12606             mFrameNumber)) {
12607         LOGE("Failed to update table");
12608         return BAD_VALUE;
12609     }
12610     return NO_ERROR;
12611 }
12612 
12613 /*===========================================================================
12614  * FUNCTION   : initBatchUpdate
12615  *
12616  * DESCRIPTION: init camera parameters buf entries
12617  *
12618  * PARAMETERS :
12619  *   @p_table : ptr to parameter buffer
12620  *
12621  * RETURN     : int32_t type of status
12622  *              NO_ERROR  -- success
12623  *              none-zero failure code
12624  *==========================================================================*/
initBatchUpdate()12625 int32_t QCameraParameters::initBatchUpdate()
12626 {
12627     m_tempMap.clear();
12628     clear_metadata_buffer(m_pParamBuf);
12629     clear_metadata_buffer(m_pParamBufAux);
12630     return NO_ERROR;
12631 }
12632 
12633 /*===========================================================================
12634 * FUNCTION   : setAuxParameters
12635 *
12636 * DESCRIPTION: Parameter only required for auxillary camera is set.
12637 *
12638 * PARAMETERS : none
12639 *
12640 * RETURN     : none
12641 *NOTE: We can use this function configure auxillary camera related parameters.
12642 *==========================================================================*/
setAuxParameters()12643 void QCameraParameters::setAuxParameters()
12644 {
12645     void *aux_param = NULL;
12646     if (m_pParamBufAux->is_valid[CAM_INTF_META_STREAM_INFO]) {
12647         aux_param = POINTER_OF_META(CAM_INTF_META_STREAM_INFO, m_pParamBufAux);
12648         if (aux_param) {
12649             cam_stream_size_info_t *info = (cam_stream_size_info_t *)aux_param;
12650             info->sync_type = CAM_TYPE_AUX;
12651 
12652             if (isDCmAsymmetricSnapMode()) {
12653                 for (uint32_t i = 0; i < info->num_streams; i++) {
12654                     if (info->type[i] == CAM_STREAM_TYPE_SNAPSHOT) {
12655                         getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
12656                                 info->stream_sizes[i], CAM_TYPE_AUX);
12657                         break;
12658                     }
12659                 }
12660             }
12661         }
12662     }
12663 }
12664 
12665 /*===========================================================================
12666  * FUNCTION   : commitSetBatch
12667  *
12668  * DESCRIPTION: commit all set parameters in the batch work to backend
12669  *
12670  * PARAMETERS : none
12671  *
12672  * RETURN     : int32_t type of status
12673  *              NO_ERROR  -- success
12674  *              none-zero failure code
12675  *==========================================================================*/
commitSetBatch()12676 int32_t QCameraParameters::commitSetBatch()
12677 {
12678     int32_t rc = NO_ERROR;
12679     int32_t i = 0;
12680 
12681     if (NULL == m_pParamBuf) {
12682         LOGE("Params not initialized");
12683         return NO_INIT;
12684     }
12685 
12686     /* Loop to check if atleast one entry is valid */
12687     for(i = 0; i < CAM_INTF_PARM_MAX; i++){
12688         if(m_pParamBuf->is_valid[i])
12689             break;
12690     }
12691 
12692     if (NULL == m_pCamOpsTbl) {
12693         LOGE("Ops not initialized");
12694         return NO_INIT;
12695     }
12696     if (isDualCamera()) {
12697         /* Add frame number logic for HAL1 in dual camera
12698          * to synchronize parameters in MCT
12699          */
12700         updateFrameNumber();
12701         SyncDCParams();
12702     }
12703     if (i < CAM_INTF_PARM_MAX) {
12704         rc = m_pCamOpsTbl->ops->set_parms(get_main_camera_handle(m_pCamOpsTbl->camera_handle),
12705             m_pParamBuf);
12706     }
12707 
12708     if ((i < CAM_INTF_PARM_MAX) && isDualCamera()) {
12709         // Translate input parameters from main camera to create parameter set for aux camera
12710         rc = m_pFovControl->translateInputParams(m_pParamBuf, m_pParamBufAux);
12711 
12712         if (rc != NO_ERROR) {
12713             LOGE("FOV-control: Failed to translate params for aux camera");
12714             return rc;
12715         }
12716 
12717         rc = commitSetBatchAux();
12718         if (rc != NO_ERROR) {
12719             LOGE("FOV-control: Failed to set params for Aux camera");
12720             return rc;
12721         }
12722     }
12723 
12724     if (rc == NO_ERROR) {
12725         // commit change from temp storage into param map
12726         rc = commitParamChanges();
12727     }
12728     return rc;
12729 }
12730 
12731 /*===========================================================================
12732  * FUNCTION   : commitSetBatchAux
12733  *
12734  * DESCRIPTION: commit all Aux set parameters in the batch work to backend
12735  *
12736  * PARAMETERS : none
12737  *
12738  * RETURN     : int32_t type of status
12739  *              NO_ERROR  -- success
12740  *              none-zero failure code
12741  *==========================================================================*/
commitSetBatchAux()12742 int32_t QCameraParameters::commitSetBatchAux()
12743 {
12744     int32_t rc = NO_ERROR;
12745 
12746     if (NULL == m_pParamBufAux || NULL == m_pParamBuf) {
12747         LOGE("Params not initialized");
12748         return NO_INIT;
12749     }
12750 
12751     if (NULL == m_pCamOpsTbl->ops) {
12752         LOGE("Ops not initialized");
12753         return NO_INIT;
12754     }
12755 
12756     setAuxParameters();
12757     rc = m_pCamOpsTbl->ops->set_parms(
12758             get_aux_camera_handle(m_pCamOpsTbl->camera_handle),
12759             m_pParamBufAux);
12760     return rc;
12761 }
12762 
12763 /*===========================================================================
12764  * FUNCTION   : commitGetBatch
12765  *
12766  * DESCRIPTION: commit all get parameters in the batch work to backend
12767  *
12768  * PARAMETERS : none
12769  *
12770  * RETURN     : int32_t type of status
12771  *              NO_ERROR  -- success
12772  *              none-zero failure code
12773  *==========================================================================*/
commitGetBatch()12774 int32_t QCameraParameters::commitGetBatch()
12775 {
12776     int32_t rc = NO_ERROR;
12777     int32_t i = 0;
12778 
12779     if (NULL == m_pParamBuf) {
12780         LOGE("Params not initialized");
12781         return NO_INIT;
12782     }
12783 
12784     /* Loop to check if atleast one entry is valid */
12785     for(i = 0; i < CAM_INTF_PARM_MAX; i++){
12786         if(m_pParamBuf->is_valid[i])
12787             break;
12788     }
12789 
12790     if (NULL == m_pCamOpsTbl) {
12791         LOGE("Ops not initialized");
12792         return NO_INIT;
12793     }
12794 
12795     if (i < CAM_INTF_PARM_MAX) {
12796         return m_pCamOpsTbl->ops->get_parms(m_pCamOpsTbl->camera_handle, m_pParamBuf);
12797     } else {
12798         return NO_ERROR;
12799     }
12800 
12801     if (i < CAM_INTF_PARM_MAX &&
12802         is_dual_camera_by_handle(m_pCamOpsTbl->camera_handle)) {
12803         rc = commitGetBatchAux();
12804         if (rc != NO_ERROR) {
12805             LOGE("Failed to get parma for Aux camera");
12806             return rc;
12807         }
12808     }
12809     return rc;
12810 }
12811 
12812 /*===========================================================================
12813  * FUNCTION   : commitGetBatchAux
12814  *
12815  * DESCRIPTION: commit all Aux get parameters in the batch work to backend
12816  *
12817  * PARAMETERS : none
12818  *
12819  * RETURN     : int32_t type of status
12820  *              NO_ERROR  -- success
12821  *              none-zero failure code
12822  *==========================================================================*/
commitGetBatchAux()12823 int32_t QCameraParameters::commitGetBatchAux()
12824 {
12825     int32_t rc = NO_ERROR;
12826     int32_t i = 0;
12827 
12828     if (NULL == m_pParamBufAux) {
12829         LOGE("Params not initialized");
12830         return NO_INIT;
12831     }
12832 
12833     /* Loop to check if atleast one entry is valid */
12834     for(i = 0; i < CAM_INTF_PARM_MAX; i++){
12835         if(m_pParamBufAux->is_valid[i])
12836             break;
12837     }
12838 
12839     if (NULL == m_pCamOpsTbl->ops) {
12840         LOGE("Ops not initialized");
12841         return NO_INIT;
12842     }
12843 
12844     if (i < CAM_INTF_PARM_MAX) {
12845         return m_pCamOpsTbl->ops->get_parms(
12846                 get_aux_camera_handle(m_pCamOpsTbl->camera_handle),
12847                 m_pParamBufAux);
12848     } else {
12849         return NO_ERROR;
12850     }
12851     return rc;
12852 }
12853 
12854 /*===========================================================================
12855  * FUNCTION   : updateParamEntry
12856  *
12857  * DESCRIPTION: update a parameter entry in the local temp map obj
12858  *
12859  * PARAMETERS :
12860  *   @key     : key of the entry
12861  *   @value   : value of the entry
12862  *
12863  * RETURN     : int32_t type of status
12864  *              NO_ERROR  -- success
12865  *              none-zero failure code
12866  *==========================================================================*/
updateParamEntry(const char * key,const char * value)12867 int32_t QCameraParameters::updateParamEntry(const char *key, const char *value)
12868 {
12869     m_tempMap.replaceValueFor(String8(key), String8(value));
12870     return NO_ERROR;
12871 }
12872 
12873 /*===========================================================================
12874  * FUNCTION   : commitParamChanges
12875  *
12876  * DESCRIPTION: commit all changes in local temp map obj into parameter obj
12877  *
12878  * PARAMETERS : none
12879  *
12880  * RETURN     : int32_t type of status
12881  *              NO_ERROR  -- success
12882  *              none-zero failure code
12883  *==========================================================================*/
commitParamChanges()12884 int32_t QCameraParameters::commitParamChanges()
12885 {
12886     size_t size = m_tempMap.size();
12887     for (size_t i = 0; i < size; i++) {
12888         String8 k, v;
12889         k = m_tempMap.keyAt(i);
12890         v = m_tempMap.valueAt(i);
12891         set(k, v);
12892     }
12893     m_tempMap.clear();
12894 
12895     // update local changes
12896     m_bRecordingHint = m_bRecordingHint_new;
12897     m_bZslMode = m_bZslMode_new;
12898 
12899     /* After applying scene mode auto,
12900       Camera effects need to be reapplied */
12901     if ( m_bSceneTransitionAuto ) {
12902         m_bUpdateEffects = true;
12903         m_bSceneTransitionAuto = false;
12904     }
12905 
12906 
12907     return NO_ERROR;
12908 }
12909 
12910 /*===========================================================================
12911  * FUNCTION   : QCameraReprocScaleParam
12912  *
12913  * DESCRIPTION: constructor of QCameraReprocScaleParam
12914  *
12915  * PARAMETERS : none
12916  *
12917  * RETURN     : none
12918  *==========================================================================*/
QCameraReprocScaleParam()12919 QCameraParameters::QCameraReprocScaleParam::QCameraReprocScaleParam()
12920   : mScaleEnabled(false),
12921     mIsUnderScaling(false),
12922     mNeedScaleCnt(0),
12923     mSensorSizeTblCnt(0),
12924     mSensorSizeTbl(NULL),
12925     mTotalSizeTblCnt(0)
12926 {
12927     mPicSizeFromAPK.width = 0;
12928     mPicSizeFromAPK.height = 0;
12929     mPicSizeSetted.width = 0;
12930     mPicSizeSetted.height = 0;
12931     memset(mNeedScaledSizeTbl, 0, sizeof(mNeedScaledSizeTbl));
12932     memset(mTotalSizeTbl, 0, sizeof(mTotalSizeTbl));
12933 }
12934 
12935 /*===========================================================================
12936  * FUNCTION   : ~~QCameraReprocScaleParam
12937  *
12938  * DESCRIPTION: destructor of QCameraReprocScaleParam
12939  *
12940  * PARAMETERS : none
12941  *
12942  * RETURN     : none
12943  *==========================================================================*/
~QCameraReprocScaleParam()12944 QCameraParameters::QCameraReprocScaleParam::~QCameraReprocScaleParam()
12945 {
12946     //do nothing now.
12947 }
12948 
12949 /*===========================================================================
12950  * FUNCTION   : setScaledSizeTbl
12951  *
12952  * DESCRIPTION: re-set picture size table with dimensions that need scaling if Reproc Scale is enabled
12953  *
12954  * PARAMETERS :
12955  *   @scale_cnt   : count of picture sizes that want scale
12956  *   @scale_tbl    : picture size table that want scale
12957  *   @org_cnt     : sensor supported picture size count
12958  *   @org_tbl      : sensor supported picture size table
12959  *
12960  * RETURN     : int32_t type of status
12961  *              NO_ERROR  -- success
12962  *              none-zero failure code
12963  *==========================================================================*/
setScaleSizeTbl(size_t scale_cnt,cam_dimension_t * scale_tbl,size_t org_cnt,cam_dimension_t * org_tbl)12964 int32_t QCameraParameters::QCameraReprocScaleParam::setScaleSizeTbl(size_t scale_cnt,
12965         cam_dimension_t *scale_tbl, size_t org_cnt, cam_dimension_t *org_tbl)
12966 {
12967     int32_t rc = NO_ERROR;
12968     size_t i;
12969     mNeedScaleCnt = 0;
12970 
12971     if(!mScaleEnabled || scale_cnt <=0 || scale_tbl == NULL || org_cnt <=0 || org_tbl == NULL){
12972         return BAD_VALUE;    // Do not need scale, so also need not reset picture size table
12973     }
12974 
12975     mSensorSizeTblCnt = org_cnt;
12976     mSensorSizeTbl = org_tbl;
12977     mNeedScaleCnt = checkScaleSizeTable(scale_cnt, scale_tbl, org_cnt, org_tbl);
12978     if(mNeedScaleCnt <= 0){
12979         LOGE("do not have picture sizes need scaling.");
12980         return BAD_VALUE;
12981     }
12982 
12983     if(mNeedScaleCnt + org_cnt > MAX_SIZES_CNT){
12984         LOGE("picture size list exceed the max count.");
12985         return BAD_VALUE;
12986     }
12987 
12988     //get the total picture size table
12989     mTotalSizeTblCnt = mNeedScaleCnt + org_cnt;
12990 
12991     if (mNeedScaleCnt > MAX_SCALE_SIZES_CNT) {
12992         LOGE("Error!! mNeedScaleCnt (%d) is more than MAX_SCALE_SIZES_CNT",
12993                  mNeedScaleCnt);
12994         return BAD_VALUE;
12995     }
12996 
12997     for(i = 0; i < mNeedScaleCnt; i++){
12998         mTotalSizeTbl[i].width = mNeedScaledSizeTbl[i].width;
12999         mTotalSizeTbl[i].height = mNeedScaledSizeTbl[i].height;
13000         LOGH("scale picture size: i =%d, width=%d, height=%d.",
13001             i, mTotalSizeTbl[i].width, mTotalSizeTbl[i].height);
13002     }
13003     for(; i < mTotalSizeTblCnt; i++){
13004         mTotalSizeTbl[i].width = org_tbl[i-mNeedScaleCnt].width;
13005         mTotalSizeTbl[i].height = org_tbl[i-mNeedScaleCnt].height;
13006         LOGH("sensor supportted picture size: i =%d, width=%d, height=%d.",
13007             i, mTotalSizeTbl[i].width, mTotalSizeTbl[i].height);
13008     }
13009     return rc;
13010 }
13011 
13012 /*===========================================================================
13013  * FUNCTION   : getScaledSizeTblCnt
13014  *
13015  * DESCRIPTION: get picture size cnt that need scale
13016  *
13017  * PARAMETERS : none
13018  *
13019  * RETURN     : uint8_t type of picture size count
13020  *==========================================================================*/
getScaleSizeTblCnt()13021 size_t QCameraParameters::QCameraReprocScaleParam::getScaleSizeTblCnt()
13022 {
13023     return mNeedScaleCnt;
13024 }
13025 
13026 /*===========================================================================
13027  * FUNCTION   : getScaledSizeTbl
13028  *
13029  * DESCRIPTION: get picture size table that need scale
13030  *
13031  * PARAMETERS :  none
13032  *
13033  * RETURN     : cam_dimension_t list of picture size table
13034  *==========================================================================*/
getScaledSizeTbl()13035 cam_dimension_t *QCameraParameters::QCameraReprocScaleParam::getScaledSizeTbl()
13036 {
13037     if(!mScaleEnabled)
13038         return NULL;
13039 
13040     return mNeedScaledSizeTbl;
13041 }
13042 
13043 /*===========================================================================
13044  * FUNCTION   : setScaleEnable
13045  *
13046  * DESCRIPTION: enable or disable Reproc Scale
13047  *
13048  * PARAMETERS :
13049  *   @enabled : enable: 1; disable 0
13050  *
13051  * RETURN     : none
13052  *==========================================================================*/
setScaleEnable(bool enabled)13053 void QCameraParameters::QCameraReprocScaleParam::setScaleEnable(bool enabled)
13054 {
13055     mScaleEnabled = enabled;
13056 }
13057 
13058 /*===========================================================================
13059  * FUNCTION   : isScaleEnabled
13060  *
13061  * DESCRIPTION: check if Reproc Scale is enabled
13062  *
13063  * PARAMETERS :  none
13064  *
13065  * RETURN     : bool type of status
13066  *==========================================================================*/
isScaleEnabled()13067 bool QCameraParameters::QCameraReprocScaleParam::isScaleEnabled()
13068 {
13069     return mScaleEnabled;
13070 }
13071 
13072 /*===========================================================================
13073  * FUNCTION   : isScalePicSize
13074  *
13075  * DESCRIPTION: check if current picture size is from Scale Table
13076  *
13077  * PARAMETERS :
13078  *   @width     : current picture width
13079  *   @height    : current picture height
13080  *
13081  * RETURN     : bool type of status
13082  *==========================================================================*/
isScalePicSize(int width,int height)13083 bool QCameraParameters::QCameraReprocScaleParam::isScalePicSize(int width, int height)
13084 {
13085     //Check if the picture size is in scale table
13086     if(mNeedScaleCnt <= 0)
13087         return FALSE;
13088 
13089     for (size_t i = 0; i < mNeedScaleCnt; i++) {
13090         if ((mNeedScaledSizeTbl[i].width == width) && (mNeedScaledSizeTbl[i].height == height)) {
13091             //found match
13092             return TRUE;
13093         }
13094     }
13095 
13096     LOGE("Not in scale picture size table.");
13097     return FALSE;
13098 }
13099 
13100 /*===========================================================================
13101  * FUNCTION   : isValidatePicSize
13102  *
13103  * DESCRIPTION: check if current picture size is validate
13104  *
13105  * PARAMETERS :
13106  *   @width     : current picture width
13107  *   @height    : current picture height
13108  *
13109  * RETURN     : bool type of status
13110  *==========================================================================*/
isValidatePicSize(int width,int height)13111 bool QCameraParameters::QCameraReprocScaleParam::isValidatePicSize(int width, int height)
13112 {
13113     size_t i = 0;
13114 
13115     for(i = 0; i < mSensorSizeTblCnt; i++){
13116         if(mSensorSizeTbl[i].width == width
13117             && mSensorSizeTbl[i].height== height){
13118             return TRUE;
13119         }
13120     }
13121 
13122     for(i = 0; i < mNeedScaleCnt; i++){
13123         if(mNeedScaledSizeTbl[i].width == width
13124             && mNeedScaledSizeTbl[i].height== height){
13125             return TRUE;
13126         }
13127     }
13128 
13129     LOGE("Invalidate input picture size.");
13130     return FALSE;
13131 }
13132 
13133 /*===========================================================================
13134  * FUNCTION   : setSensorSupportedPicSize
13135  *
13136  * DESCRIPTION: set sensor supported picture size.
13137  *    For Snapshot stream size configuration, we need use sensor supported size.
13138  *    We will use CPP to do Scaling based on output Snapshot stream.
13139  *
13140  * PARAMETERS : none
13141  *
13142  * RETURN     : int32_t type of status
13143  *              NO_ERROR  -- success
13144  *              none-zero failure code
13145  *==========================================================================*/
setSensorSupportedPicSize()13146 int32_t QCameraParameters::QCameraReprocScaleParam::setSensorSupportedPicSize()
13147 {
13148     //will find a suitable picture size (here we leave a prossibility to add other scale requirement)
13149     //Currently we only focus on upscaling, and checkScaleSizeTable() has guaranteed the dimension ratio.
13150 
13151     if(!mIsUnderScaling || mSensorSizeTblCnt <= 0)
13152         return BAD_VALUE;
13153 
13154     //We just get the max sensor supported size here.
13155     mPicSizeSetted.width = mSensorSizeTbl[0].width;
13156     mPicSizeSetted.height = mSensorSizeTbl[0].height;
13157 
13158     return NO_ERROR;
13159 }
13160 
13161 
13162 /*===========================================================================
13163  * FUNCTION   : setValidatePicSize
13164  *
13165  * DESCRIPTION: set sensor supported size and change scale status.
13166  *
13167  * PARAMETERS :
13168  *   @width    : input picture width
13169  *   @height   : input picture height
13170  *
13171  * RETURN     : int32_t type of status
13172  *              NO_ERROR  -- success
13173  *              none-zero failure code
13174  *==========================================================================*/
setValidatePicSize(int & width,int & height)13175 int32_t QCameraParameters::QCameraReprocScaleParam::setValidatePicSize(int &width,int &height)
13176 {
13177     if(!mScaleEnabled)
13178         return BAD_VALUE;
13179 
13180     mIsUnderScaling = FALSE; //default: not under scale
13181 
13182     if(isScalePicSize(width, height)){
13183         // input picture size need scaling operation. Record size from APK and setted
13184         mIsUnderScaling = TRUE;
13185         mPicSizeFromAPK.width = width;
13186         mPicSizeFromAPK.height = height;
13187 
13188         if(setSensorSupportedPicSize() != NO_ERROR)
13189             return BAD_VALUE;
13190 
13191         //re-set picture size to sensor supported size
13192         width = mPicSizeSetted.width;
13193         height = mPicSizeSetted.height;
13194         LOGH("mPicSizeFromAPK- with=%d, height=%d, mPicSizeSetted- with =%d, height=%d.",
13195              mPicSizeFromAPK.width, mPicSizeFromAPK.height, mPicSizeSetted.width, mPicSizeSetted.height);
13196     }else{
13197         mIsUnderScaling = FALSE;
13198         //no scale is needed for input picture size
13199         if(!isValidatePicSize(width, height)){
13200             LOGE("invalidate input picture size.");
13201             return BAD_VALUE;
13202         }
13203         mPicSizeSetted.width = width;
13204         mPicSizeSetted.height = height;
13205     }
13206 
13207     LOGH("X. mIsUnderScaling=%d, width=%d, height=%d.", mIsUnderScaling, width, height);
13208     return NO_ERROR;
13209 }
13210 
13211 /*===========================================================================
13212  * FUNCTION   : getPicSizeFromAPK
13213  *
13214  * DESCRIPTION: get picture size that get from APK
13215  *
13216  * PARAMETERS :
13217  *   @width     : input width
13218  *   @height    : input height
13219  *
13220  * RETURN     : int32_t type of status
13221  *              NO_ERROR  -- success
13222  *              none-zero failure code
13223  *==========================================================================*/
getPicSizeFromAPK(int & width,int & height)13224 int32_t QCameraParameters::QCameraReprocScaleParam::getPicSizeFromAPK(int &width, int &height)
13225 {
13226     if(!mIsUnderScaling)
13227         return BAD_VALUE;
13228 
13229     width = mPicSizeFromAPK.width;
13230     height = mPicSizeFromAPK.height;
13231     return NO_ERROR;
13232 }
13233 
13234 /*===========================================================================
13235  * FUNCTION   : getPicSizeSetted
13236  *
13237  * DESCRIPTION: get picture size that setted into mm-camera
13238  *
13239  * PARAMETERS :
13240  *   @width     : input width
13241  *   @height    : input height
13242  *
13243  * RETURN     : int32_t type of status
13244  *              NO_ERROR  -- success
13245  *              none-zero failure code
13246  *==========================================================================*/
getPicSizeSetted(int & width,int & height)13247 int32_t QCameraParameters::QCameraReprocScaleParam::getPicSizeSetted(int &width, int &height)
13248 {
13249     width = mPicSizeSetted.width;
13250     height = mPicSizeSetted.height;
13251     return NO_ERROR;
13252 }
13253 
13254 /*===========================================================================
13255  * FUNCTION   : isUnderScaling
13256  *
13257  * DESCRIPTION: check if we are in Reproc Scaling requirment
13258  *
13259  * PARAMETERS :  none
13260  *
13261  * RETURN     : bool type of status
13262  *==========================================================================*/
isUnderScaling()13263 bool QCameraParameters::QCameraReprocScaleParam::isUnderScaling()
13264 {
13265     return mIsUnderScaling;
13266 }
13267 
13268 /*===========================================================================
13269  * FUNCTION   : checkScaleSizeTable
13270  *
13271  * DESCRIPTION: check PICTURE_SIZE_NEED_SCALE to choose
13272  *
13273  * PARAMETERS :
13274  *   @scale_cnt   : count of picture sizes that want scale
13275  *   @scale_tbl    : picture size table that want scale
13276  *   @org_cnt     : sensor supported picture size count
13277  *   @org_tbl      : sensor supported picture size table
13278  *
13279  * RETURN     : bool type of status
13280  *==========================================================================*/
checkScaleSizeTable(size_t scale_cnt,cam_dimension_t * scale_tbl,size_t org_cnt,cam_dimension_t * org_tbl)13281 size_t QCameraParameters::QCameraReprocScaleParam::checkScaleSizeTable(size_t scale_cnt,
13282         cam_dimension_t *scale_tbl, size_t org_cnt, cam_dimension_t *org_tbl)
13283 {
13284     size_t stbl_cnt = 0;
13285     size_t temp_cnt = 0;
13286     ssize_t i = 0;
13287     if(scale_cnt <=0 || scale_tbl == NULL || org_tbl == NULL || org_cnt <= 0)
13288         return stbl_cnt;
13289 
13290     //get validate scale size table. Currently we only support:
13291     // 1. upscale. The scale size must larger than max sensor supported size
13292     // 2. Scale dimension ratio must be same as the max sensor supported size.
13293     temp_cnt = scale_cnt;
13294     for (i = (ssize_t)(scale_cnt - 1); i >= 0; i--) {
13295         if (scale_tbl[i].width > org_tbl[0].width ||
13296                 (scale_tbl[i].width == org_tbl[0].width &&
13297                     scale_tbl[i].height > org_tbl[0].height)) {
13298             //get the smallest scale size
13299             break;
13300         }
13301         temp_cnt--;
13302     }
13303 
13304     //check dimension ratio
13305     double supported_ratio = (double)org_tbl[0].width / (double)org_tbl[0].height;
13306     for (i = 0; i < (ssize_t)temp_cnt; i++) {
13307         double cur_ratio = (double)scale_tbl[i].width / (double)scale_tbl[i].height;
13308         if (fabs(supported_ratio - cur_ratio) > ASPECT_TOLERANCE) {
13309             continue;
13310         }
13311         mNeedScaledSizeTbl[stbl_cnt].width = scale_tbl[i].width;
13312         mNeedScaledSizeTbl[stbl_cnt].height= scale_tbl[i].height;
13313         stbl_cnt++;
13314     }
13315 
13316     return stbl_cnt;
13317 }
13318 
13319 /*===========================================================================
13320  * FUNCTION   : getTotalSizeTblCnt
13321  *
13322  * DESCRIPTION: get total picture size count after adding dimensions that need scaling
13323  *
13324  * PARAMETERS : none
13325  *
13326  * RETURN     : uint8_t type of picture size count
13327  *==========================================================================*/
getTotalSizeTblCnt()13328 size_t QCameraParameters::QCameraReprocScaleParam::getTotalSizeTblCnt()
13329 {
13330     return mTotalSizeTblCnt;
13331 }
13332 
13333 /*===========================================================================
13334  * FUNCTION   : getTotalSizeTbl
13335  *
13336  * DESCRIPTION: get picture size table after adding dimensions that need scaling
13337  *
13338  * PARAMETERS :  none
13339  *
13340  * RETURN     : cam_dimension_t list of picture size table
13341  *==========================================================================*/
getTotalSizeTbl()13342 cam_dimension_t *QCameraParameters::QCameraReprocScaleParam::getTotalSizeTbl()
13343 {
13344     if(!mScaleEnabled)
13345         return NULL;
13346 
13347     return mTotalSizeTbl;
13348 }
13349 
13350 /*===========================================================================
13351  * FUNCTION   : setEztune
13352  *
13353  * DESCRIPTION: Enable/Disable EZtune
13354  *
13355  *==========================================================================*/
setEztune()13356 int32_t QCameraParameters::setEztune()
13357 {
13358     char prop[PROPERTY_VALUE_MAX];
13359     memset(prop, 0, sizeof(prop));
13360     property_get("persist.camera.eztune.enable", prop, "0");
13361     m_bEztuneEnabled = atoi(prop);
13362     return NO_ERROR;
13363 }
13364 
13365 /*===========================================================================
13366  * FUNCTION   : isHDREnabled
13367  *
13368  * DESCRIPTION: if HDR is enabled
13369  *
13370  * PARAMETERS : none
13371  *
13372  * RETURN     : true: needed
13373  *              false: no need
13374  *==========================================================================*/
isHDREnabled()13375 bool QCameraParameters::isHDREnabled()
13376 {
13377     return ((m_bHDREnabled || m_HDRSceneEnabled));
13378 }
13379 
13380 /*===========================================================================
13381  * FUNCTION   : isAVTimerEnabled
13382  *
13383  * DESCRIPTION: if AVTimer is enabled
13384  *
13385  * PARAMETERS : none
13386  *
13387  * RETURN     : true: needed
13388  *              false: no need
13389  *==========================================================================*/
isAVTimerEnabled()13390 bool QCameraParameters::isAVTimerEnabled()
13391 {
13392     return m_bAVTimerEnabled;
13393 }
13394 
13395 /*===========================================================================
13396 * FUNCTION   : isDISEnabled
13397 *
13398 * DESCRIPTION: if DIS is enabled
13399 *
13400 * PARAMETERS : none
13401 *
13402 * RETURN    : true: needed
13403 *               false: no need
13404 *==========================================================================*/
isDISEnabled()13405 bool QCameraParameters::isDISEnabled()
13406 {
13407     return m_bDISEnabled;
13408 }
13409 
13410 /*===========================================================================
13411 * FUNCTION   : setISType
13412 *
13413 * DESCRIPTION: Set both Preview & Video IS type by reading the correspoding setprop's
13414 *
13415 * PARAMETERS : none
13416 *
13417 * RETURN     : IS type
13418 *
13419 *==========================================================================*/
setISType()13420 int32_t QCameraParameters::setISType()
13421 {
13422     bool eisSupported = false, eis3Supported = false;
13423     for (size_t i = 0; i < m_pCapability->supported_is_types_cnt; i++) {
13424         if ((m_pCapability->supported_is_types[i] == IS_TYPE_EIS_2_0) ||
13425                 (m_pCapability->supported_is_types[i] == IS_TYPE_EIS_3_0)) {
13426             eisSupported = true;
13427         }
13428         if (m_pCapability->supported_is_types[i] == IS_TYPE_EIS_3_0) {
13429             eis3Supported = TRUE;
13430         }
13431     }
13432     if (m_bDISEnabled && eisSupported) {
13433         char value[PROPERTY_VALUE_MAX];
13434         // Make default value for Video IS_TYPE as IS_TYPE_EIS_2_0
13435         property_get("persist.camera.is_type", value, "4");
13436         mIsTypeVideo = static_cast<cam_is_type_t>(atoi(value));
13437         if ( (mIsTypeVideo == IS_TYPE_EIS_3_0) && (eis3Supported == FALSE) ) {
13438             LOGW("EIS_3.0 is not supported and so setting EIS_2.0");
13439             mIsTypeVideo = IS_TYPE_EIS_2_0;
13440         }
13441         // Make default value for preview IS_TYPE as IS_TYPE_EIS_2_0
13442         property_get("persist.camera.is_type_preview", value, "4");
13443         mIsTypePreview = static_cast<cam_is_type_t>(atoi(value));
13444     } else if (m_bDISEnabled) {
13445         char value[PROPERTY_VALUE_MAX];
13446         // Make default value for Video IS_TYPE as IS_TYPE_DIS
13447         property_get("persist.camera.is_type", value, "2");
13448         mIsTypeVideo = static_cast<cam_is_type_t>(atoi(value));
13449         if (mIsTypeVideo >= IS_TYPE_DIS) {
13450             LOGW("EIS is not supported and so setting DIS");
13451             mIsTypeVideo = IS_TYPE_DIS;
13452         }
13453         // Make default value for preview IS_TYPE as IS_TYPE_DIS
13454         property_get("persist.camera.is_type_preview", value, "2");
13455         mIsTypePreview = static_cast<cam_is_type_t>(atoi(value));
13456         if (mIsTypePreview >= IS_TYPE_DIS) {
13457             LOGW("EIS is not supported and so setting DIS");
13458             mIsTypePreview = IS_TYPE_DIS;
13459         }
13460     } else {
13461         mIsTypeVideo = IS_TYPE_NONE;
13462         mIsTypePreview = IS_TYPE_NONE;
13463     }
13464     return NO_ERROR;
13465 }
13466 /*===========================================================================
13467 * FUNCTION   : setSmallJpegSize
13468 *
13469 * DESCRIPTION: Picture ratio greater than VFE down scale factor
13470 *              set SmallJpegSize flag
13471 *
13472 * PARAMETERS :
13473 *  @cam_dimension_t: sensor dimension
13474 *                    Snapshot sream dimension
13475 *
13476 * RETURN     : None
13477 *==========================================================================*/
setSmallJpegSize(cam_dimension_t sensor_dim,cam_dimension_t snap_dim)13478 void QCameraParameters::setSmallJpegSize(cam_dimension_t sensor_dim, cam_dimension_t snap_dim)
13479 {
13480     uint32_t width_ratio;
13481     uint32_t height_ratio;
13482 
13483     //Picture ratio is greater than max downscale factor set small jpeg flag
13484     width_ratio = CEIL_DIVISION(sensor_dim.width,snap_dim.width);
13485     height_ratio = CEIL_DIVISION(sensor_dim.height,snap_dim.height);
13486     FATAL_IF(m_pCapability->max_downscale_factor == 0,
13487             "FATAL: max_downscale_factor cannot be zero and so assert");
13488     if ( (width_ratio > m_pCapability->max_downscale_factor) ||
13489           (height_ratio > m_pCapability->max_downscale_factor)) {
13490           LOGH("Setting small jpeg size flag to true");
13491           m_bSmallJpegSize = true;
13492     } else {
13493           m_bSmallJpegSize = false;
13494     }
13495 }
13496 
13497 /*===========================================================================
13498 * FUNCTION   : updateSnapshotPpMask
13499 *
13500 * DESCRIPTION: Update PP mask for sanpshot stream
13501 *
13502 * PARAMETERS :
13503 *  @stream_config_info: Stream config information
13504 *
13505 * RETURN     : int32_t type of status
13506 *              NO_ERROR  -- success
13507 *              none-zero failure code
13508 *==========================================================================*/
updateSnapshotPpMask(cam_stream_size_info_t & stream_config_info)13509 int32_t QCameraParameters::updateSnapshotPpMask(cam_stream_size_info_t &stream_config_info)
13510 
13511 {
13512     int32_t rc = NO_ERROR;
13513     cam_dimension_t sensor_dim, snap_dim;
13514     cam_dimension_t max_dim = {0,0};
13515 
13516     // Find the Maximum dimension among all the streams
13517     for (uint32_t j = 0; j < stream_config_info.num_streams; j++) {
13518          if (stream_config_info.stream_sizes[j].width > max_dim.width) {
13519                max_dim.width = stream_config_info.stream_sizes[j].width;
13520          }
13521          if (stream_config_info.stream_sizes[j].height > max_dim.height) {
13522                max_dim.height = stream_config_info.stream_sizes[j].height;
13523          }
13524     }
13525     LOGH("Max Dimension = %d X %d", max_dim.width, max_dim.height);
13526     getSensorOutputSize(max_dim,sensor_dim);
13527     getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT, snap_dim);
13528     setSmallJpegSize(sensor_dim,snap_dim);
13529 
13530     //Picture ratio is greater than VFE downscale factor.So, link CPP
13531     if ( isSmallJpegSizeEnabled() ) {
13532          for (uint32_t k = 0; k < stream_config_info.num_streams; k++) {
13533               if( stream_config_info.type[k] == CAM_STREAM_TYPE_SNAPSHOT) {
13534                   updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
13535                   stream_config_info.postprocess_mask[k] =
13536                       mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
13537                   LOGI("STREAM INFO : type %d, wxh: %d x %d, pp_mask: 0x%llx \
13538                         Format = %d, dt =%d cid =%d subformat =%d, is_type %d",
13539                         stream_config_info.type[k],
13540                         stream_config_info.stream_sizes[k].width,
13541                         stream_config_info.stream_sizes[k].height,
13542                         stream_config_info.postprocess_mask[k],
13543                         stream_config_info.format[k],
13544                         stream_config_info.dt[k],
13545                         stream_config_info.vc[k],
13546                         stream_config_info.sub_format_type[k],
13547                         stream_config_info.is_type[k]);
13548                   rc = sendStreamConfigInfo(stream_config_info);
13549               }
13550          }
13551     }
13552 
13553     return rc;
13554 }
13555 
13556 /*===========================================================================
13557 * FUNCTION   : getISType
13558 *
13559 * DESCRIPTION: returns IS type
13560 *
13561 * PARAMETERS : none
13562 *
13563 * RETURN     : IS type
13564 *
13565 *==========================================================================*/
getVideoISType()13566 cam_is_type_t QCameraParameters::getVideoISType()
13567 {
13568     return mIsTypeVideo;
13569 }
13570 
13571 /*===========================================================================
13572 * FUNCTION   : getPreviewISType
13573 *
13574 * DESCRIPTION: returns IS type for preview
13575 *
13576 * PARAMETERS : none
13577 *
13578 * RETURN     : IS type
13579 *
13580 *==========================================================================*/
getPreviewISType()13581 cam_is_type_t QCameraParameters::getPreviewISType()
13582 {
13583     return mIsTypePreview;
13584 }
13585 
13586 /*===========================================================================
13587  * FUNCTION   : MobicatMask
13588  *
13589  * DESCRIPTION: returns mobicat mask
13590  *
13591  * PARAMETERS : none
13592  *
13593  * RETURN     : mobicat mask
13594  *
13595  *==========================================================================*/
getMobicatMask()13596 uint8_t QCameraParameters::getMobicatMask()
13597 {
13598     return m_MobiMask;
13599 }
13600 
13601 /*===========================================================================
13602  * FUNCTION   : sendStreamConfigInfo
13603  *
13604  * DESCRIPTION: send Stream config info.
13605  *
13606  * PARAMETERS :
13607  *   @stream_config_info: Stream config information
13608  *
13609  * RETURN     : int32_t type of status
13610  *              NO_ERROR  -- success
13611  *              none-zero failure code
13612  *==========================================================================*/
sendStreamConfigInfo(cam_stream_size_info_t & stream_config_info)13613 bool QCameraParameters::sendStreamConfigInfo(cam_stream_size_info_t &stream_config_info) {
13614     int32_t rc = NO_ERROR;
13615     cam_dimension_t sensor_dim_main = {0,0};
13616     cam_dimension_t sensor_dim_aux  = {0,0};
13617 
13618     if (isDualCamera()) {
13619         // Get the sensor output dimensions for main and aux cameras.
13620         cam_dimension_t max_dim = {0,0};
13621         for (uint32_t i = 0; i < stream_config_info.num_streams; i++) {
13622             // Find the max dimension among all the streams
13623             if (stream_config_info.stream_sizes[i].width > max_dim.width) {
13624                max_dim.width = stream_config_info.stream_sizes[i].width;
13625             }
13626             if (stream_config_info.stream_sizes[i].height > max_dim.height) {
13627                max_dim.height = stream_config_info.stream_sizes[i].height;
13628             }
13629         }
13630         getSensorOutputSize(max_dim, sensor_dim_main, MM_CAMERA_TYPE_MAIN);
13631         getSensorOutputSize(max_dim, sensor_dim_aux,  MM_CAMERA_TYPE_AUX);
13632     }
13633 
13634     if(initBatchUpdate() < 0 ) {
13635         LOGE("Failed to initialize group update table");
13636         return BAD_TYPE;
13637     }
13638 
13639     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
13640             CAM_INTF_META_STREAM_INFO, stream_config_info)) {
13641         LOGE("Failed to update table");
13642         return BAD_VALUE;
13643     }
13644 
13645     rc = commitSetBatch();
13646     if (rc != NO_ERROR) {
13647         LOGE("Failed to set stream info parm");
13648         return rc;
13649     }
13650 
13651     if (isDualCamera()) {
13652 #if 0 // Update to 07.01.01.253.071
13653         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
13654                 CAM_INTF_PARM_RAW_DIMENSION, sensor_dim_main) ||
13655                 ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBufAux,
13656                     CAM_INTF_PARM_RAW_DIMENSION, sensor_dim_aux)) {
13657             LOGE("Failed to update table for CAM_INTF_PARM_RAW_DIMENSION");
13658             return BAD_VALUE;
13659         }
13660 #endif // Update to 07.01.01.253.071
13661 
13662         // Update FOV-control config settings due to the change in the configuration
13663         rc = m_pFovControl->updateConfigSettings(m_pParamBuf, m_pParamBufAux);
13664 
13665         if (rc != NO_ERROR) {
13666             LOGE("Failed to update FOV-control config settings");
13667             return rc;
13668         }
13669     }
13670 
13671     return rc;
13672 }
13673 
13674 /*===========================================================================
13675  * FUNCTION   : setStreamConfigure
13676  *
13677  * DESCRIPTION: set stream type, stream dimension for all configured streams.
13678  *
13679  * PARAMETERS :
13680  *   @isCapture: Whether this configureation is for an image capture
13681  *   @previewAsPostview: Use preview as postview
13682  *
13683  * RETURN     : int32_t type of status
13684  *              NO_ERROR  -- success
13685  *              none-zero failure code
13686  *==========================================================================*/
setStreamConfigure(bool isCapture,bool previewAsPostview,bool resetConfig)13687 bool QCameraParameters::setStreamConfigure(bool isCapture,
13688         bool previewAsPostview, bool resetConfig) {
13689 
13690     int32_t rc = NO_ERROR;
13691     cam_stream_size_info_t stream_config_info;
13692     char value[PROPERTY_VALUE_MAX];
13693     bool raw_yuv = false;
13694     bool raw_capture = false;
13695 
13696     if ( m_pParamBuf == NULL ) {
13697         return NO_INIT;
13698     }
13699 
13700     memset(&stream_config_info, 0, sizeof(stream_config_info));
13701     stream_config_info.num_streams = 0;
13702 
13703     if (resetConfig) {
13704         LOGH("Reset stream config!!");
13705         rc = sendStreamConfigInfo(stream_config_info);
13706         LOGH("Done Resetting stream config!!");
13707         return rc;
13708     }
13709 
13710     stream_config_info.hfr_mode       = static_cast<cam_hfr_mode_t>(mHfrMode);
13711     stream_config_info.buf_alignment  = m_pCapability->buf_alignment;
13712     stream_config_info.min_stride     = m_pCapability->min_stride;
13713     stream_config_info.min_scanline   = m_pCapability->min_scanline;
13714     stream_config_info.batch_size = getBufBatchCount();
13715     m_bSmallJpegSize = false;
13716 
13717     stream_config_info.is_secure = isSecureMode() ? 1 : 0;
13718 
13719     LOGH("buf_alignment=%d stride X scan=%dx%d batch size = %d\n",
13720             m_pCapability->buf_alignment,
13721             m_pCapability->min_stride,
13722             m_pCapability->min_scanline,
13723             stream_config_info.batch_size);
13724 
13725     property_get("persist.camera.raw_yuv", value, "0");
13726     raw_yuv = atoi(value) > 0 ? true : false;
13727 
13728     if (isZSLMode() && getRecordingHintValue() != true) {
13729         stream_config_info.type[stream_config_info.num_streams] =
13730             CAM_STREAM_TYPE_PREVIEW;
13731         getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
13732                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
13733         updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
13734         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13735                 mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
13736         getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
13737                 stream_config_info.format[stream_config_info.num_streams]);
13738         stream_config_info.rotation[stream_config_info.num_streams] =
13739                 getStreamRotation(CAM_STREAM_TYPE_PREVIEW);
13740         stream_config_info.num_streams++;
13741 
13742         stream_config_info.type[stream_config_info.num_streams] =
13743                 CAM_STREAM_TYPE_ANALYSIS;
13744         updatePpFeatureMask(CAM_STREAM_TYPE_ANALYSIS);
13745         getStreamDimension(CAM_STREAM_TYPE_ANALYSIS,
13746                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
13747         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13748                 mStreamPpMask[CAM_STREAM_TYPE_ANALYSIS];
13749         getStreamFormat(CAM_STREAM_TYPE_ANALYSIS,
13750                 stream_config_info.format[stream_config_info.num_streams]);
13751         stream_config_info.rotation[stream_config_info.num_streams] =
13752                 getStreamRotation(CAM_STREAM_TYPE_ANALYSIS);
13753         stream_config_info.num_streams++;
13754 
13755         stream_config_info.type[stream_config_info.num_streams] =
13756                 CAM_STREAM_TYPE_SNAPSHOT;
13757         getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
13758                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
13759         updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
13760         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13761                 mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
13762         getStreamFormat(CAM_STREAM_TYPE_SNAPSHOT,
13763                 stream_config_info.format[stream_config_info.num_streams]);
13764         stream_config_info.rotation[stream_config_info.num_streams] =
13765                 getStreamRotation(CAM_STREAM_TYPE_SNAPSHOT);
13766         stream_config_info.num_streams++;
13767 
13768         if (isUBWCEnabled() && getRecordingHintValue() != true) {
13769             cam_format_t fmt;
13770             getStreamFormat(CAM_STREAM_TYPE_PREVIEW,fmt);
13771             if (fmt == CAM_FORMAT_YUV_420_NV12_UBWC) {
13772                 stream_config_info.type[stream_config_info.num_streams] =
13773                         CAM_STREAM_TYPE_CALLBACK;
13774                 getStreamDimension(CAM_STREAM_TYPE_CALLBACK,
13775                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
13776                 updatePpFeatureMask(CAM_STREAM_TYPE_CALLBACK);
13777                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13778                         mStreamPpMask[CAM_STREAM_TYPE_CALLBACK];
13779                 getStreamFormat(CAM_STREAM_TYPE_CALLBACK,
13780                         stream_config_info.format[stream_config_info.num_streams]);
13781                 stream_config_info.rotation[stream_config_info.num_streams] =
13782                         getStreamRotation(CAM_STREAM_TYPE_CALLBACK);
13783                 stream_config_info.num_streams++;
13784             }
13785         }
13786     }  else if(isSecureMode()) {
13787         if (mSecureStraemType == CAM_STREAM_TYPE_RAW) {
13788             raw_capture = true;
13789             cam_dimension_t max_dim = {0,0};
13790             updateRAW(max_dim);
13791             stream_config_info.type[stream_config_info.num_streams] =
13792                     CAM_STREAM_TYPE_RAW;
13793             getStreamDimension(CAM_STREAM_TYPE_RAW,
13794                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
13795             updatePpFeatureMask(CAM_STREAM_TYPE_RAW);
13796             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13797                     mStreamPpMask[CAM_STREAM_TYPE_RAW];
13798             getStreamFormat(CAM_STREAM_TYPE_RAW,
13799                     stream_config_info.format[stream_config_info.num_streams]);
13800         }else {
13801             stream_config_info.type[stream_config_info.num_streams] =
13802                     CAM_STREAM_TYPE_PREVIEW;
13803             getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
13804                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
13805             setStreamPpMask(CAM_STREAM_TYPE_PREVIEW, CAM_QCOM_FEATURE_NONE);
13806             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13807                     mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
13808             getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
13809                     stream_config_info.format[stream_config_info.num_streams]);
13810             stream_config_info.is_type[stream_config_info.num_streams] = mIsTypePreview;
13811         }
13812         stream_config_info.num_streams++;
13813     } else if (!isCapture) {
13814         if (m_bRecordingHint) {
13815             setISType();
13816             mIsTypeVideo = getVideoISType();
13817             mIsTypePreview = getPreviewISType();
13818             stream_config_info.is_type[stream_config_info.num_streams] = IS_TYPE_NONE;
13819             stream_config_info.type[stream_config_info.num_streams] =
13820                     CAM_STREAM_TYPE_SNAPSHOT;
13821             getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
13822                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
13823             updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
13824             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13825                     mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
13826             getStreamFormat(CAM_STREAM_TYPE_SNAPSHOT,
13827                         stream_config_info.format[stream_config_info.num_streams]);
13828             stream_config_info.rotation[stream_config_info.num_streams] =
13829                         getStreamRotation(CAM_STREAM_TYPE_SNAPSHOT);
13830             stream_config_info.num_streams++;
13831 
13832             stream_config_info.is_type[stream_config_info.num_streams] = mIsTypeVideo;
13833             stream_config_info.type[stream_config_info.num_streams] =
13834                     CAM_STREAM_TYPE_VIDEO;
13835             getStreamDimension(CAM_STREAM_TYPE_VIDEO,
13836                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
13837             updatePpFeatureMask(CAM_STREAM_TYPE_VIDEO);
13838             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13839                     mStreamPpMask[CAM_STREAM_TYPE_VIDEO];
13840             getStreamFormat(CAM_STREAM_TYPE_VIDEO,
13841                     stream_config_info.format[stream_config_info.num_streams]);
13842             stream_config_info.rotation[stream_config_info.num_streams] =
13843                         getStreamRotation(CAM_STREAM_TYPE_VIDEO);
13844             stream_config_info.num_streams++;
13845         }
13846 
13847         /* Analysis stream is needed by DCRF regardless of recording hint */
13848         if ((getDcrf() == true) ||
13849                 (getRecordingHintValue() != true) ||
13850                 (fdModeInVideo())) {
13851             stream_config_info.type[stream_config_info.num_streams] =
13852                     CAM_STREAM_TYPE_ANALYSIS;
13853             updatePpFeatureMask(CAM_STREAM_TYPE_ANALYSIS);
13854             getStreamDimension(CAM_STREAM_TYPE_ANALYSIS,
13855                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
13856             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13857                     mStreamPpMask[CAM_STREAM_TYPE_ANALYSIS];
13858             getStreamFormat(CAM_STREAM_TYPE_ANALYSIS,
13859                     stream_config_info.format[stream_config_info.num_streams]);
13860             stream_config_info.rotation[stream_config_info.num_streams] =
13861                     getStreamRotation(CAM_STREAM_TYPE_ANALYSIS);
13862             stream_config_info.num_streams++;
13863         }
13864 
13865         stream_config_info.type[stream_config_info.num_streams] =
13866                 CAM_STREAM_TYPE_PREVIEW;
13867         getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
13868                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
13869         updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
13870         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13871                 mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
13872         getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
13873                     stream_config_info.format[stream_config_info.num_streams]);
13874         stream_config_info.is_type[stream_config_info.num_streams] = mIsTypePreview;
13875         stream_config_info.rotation[stream_config_info.num_streams] =
13876                 getStreamRotation(CAM_STREAM_TYPE_PREVIEW);
13877         stream_config_info.num_streams++;
13878 
13879         if (isUBWCEnabled() && getRecordingHintValue() != true) {
13880             cam_format_t fmt;
13881             getStreamFormat(CAM_STREAM_TYPE_PREVIEW,fmt);
13882             if (fmt == CAM_FORMAT_YUV_420_NV12_UBWC) {
13883                 stream_config_info.type[stream_config_info.num_streams] =
13884                         CAM_STREAM_TYPE_CALLBACK;
13885                 getStreamDimension(CAM_STREAM_TYPE_CALLBACK,
13886                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
13887                 updatePpFeatureMask(CAM_STREAM_TYPE_CALLBACK);
13888                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13889                         mStreamPpMask[CAM_STREAM_TYPE_CALLBACK];
13890                 getStreamFormat(CAM_STREAM_TYPE_CALLBACK,
13891                         stream_config_info.format[stream_config_info.num_streams]);
13892                 stream_config_info.is_type[stream_config_info.num_streams] = IS_TYPE_NONE;
13893                 stream_config_info.rotation[stream_config_info.num_streams] =
13894                         getStreamRotation(CAM_STREAM_TYPE_CALLBACK);
13895                 stream_config_info.num_streams++;
13896             }
13897         }
13898 
13899     } else {
13900         if (isJpegPictureFormat() || isNV16PictureFormat() || isNV21PictureFormat()) {
13901             if (!getofflineRAW()) {
13902                 stream_config_info.type[stream_config_info.num_streams] =
13903                         CAM_STREAM_TYPE_SNAPSHOT;
13904                 getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
13905                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
13906                 updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
13907                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13908                         mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
13909                 getStreamFormat(CAM_STREAM_TYPE_SNAPSHOT,
13910                         stream_config_info.format[stream_config_info.num_streams]);
13911                 stream_config_info.is_type[stream_config_info.num_streams] = IS_TYPE_NONE;
13912                 stream_config_info.rotation[stream_config_info.num_streams] =
13913                         getStreamRotation(CAM_STREAM_TYPE_SNAPSHOT);
13914                 stream_config_info.num_streams++;
13915             }
13916 
13917             if (previewAsPostview) {
13918                 stream_config_info.type[stream_config_info.num_streams] =
13919                         CAM_STREAM_TYPE_PREVIEW;
13920                 getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
13921                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
13922                 updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
13923                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13924                         mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
13925                 getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
13926                         stream_config_info.format[stream_config_info.num_streams]);
13927                 stream_config_info.is_type[stream_config_info.num_streams] = IS_TYPE_NONE;
13928                 stream_config_info.rotation[stream_config_info.num_streams] =
13929                         getStreamRotation(CAM_STREAM_TYPE_PREVIEW);
13930                 stream_config_info.num_streams++;
13931             } else if(!getQuadraCfa()) {
13932                 stream_config_info.type[stream_config_info.num_streams] =
13933                         CAM_STREAM_TYPE_POSTVIEW;
13934                 getStreamDimension(CAM_STREAM_TYPE_POSTVIEW,
13935                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
13936                 updatePpFeatureMask(CAM_STREAM_TYPE_POSTVIEW);
13937                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13938                         mStreamPpMask[CAM_STREAM_TYPE_POSTVIEW];
13939                 getStreamFormat(CAM_STREAM_TYPE_POSTVIEW,
13940                         stream_config_info.format[stream_config_info.num_streams]);
13941                 stream_config_info.is_type[stream_config_info.num_streams] = IS_TYPE_NONE;
13942                 stream_config_info.rotation[stream_config_info.num_streams] =
13943                         getStreamRotation(CAM_STREAM_TYPE_POSTVIEW);
13944                 stream_config_info.num_streams++;
13945             }
13946         } else {
13947             raw_capture = true;
13948             stream_config_info.type[stream_config_info.num_streams] =
13949                     CAM_STREAM_TYPE_RAW;
13950             getStreamDimension(CAM_STREAM_TYPE_RAW,
13951                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
13952             updatePpFeatureMask(CAM_STREAM_TYPE_RAW);
13953             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
13954                     mStreamPpMask[CAM_STREAM_TYPE_RAW];
13955             getStreamFormat(CAM_STREAM_TYPE_RAW,
13956                     stream_config_info.format[stream_config_info.num_streams]);
13957             stream_config_info.is_type[stream_config_info.num_streams] = IS_TYPE_NONE;
13958             stream_config_info.rotation[stream_config_info.num_streams] =
13959                         getStreamRotation(CAM_STREAM_TYPE_RAW);
13960             stream_config_info.num_streams++;
13961         }
13962     }
13963 
13964     if ((!raw_capture) && ((getofflineRAW() && !getRecordingHintValue())
13965             || (raw_yuv))) {
13966         cam_dimension_t max_dim = {0,0};
13967 
13968         if (!getQuadraCfa()) {
13969             // Find the Maximum dimension admong all the streams
13970             for (uint32_t j = 0; j < stream_config_info.num_streams; j++) {
13971                 if (stream_config_info.stream_sizes[j].width > max_dim.width) {
13972                     max_dim.width = stream_config_info.stream_sizes[j].width;
13973                 }
13974                 if (stream_config_info.stream_sizes[j].height > max_dim.height) {
13975                     max_dim.height = stream_config_info.stream_sizes[j].height;
13976                 }
13977             }
13978         } else {
13979             max_dim.width = m_pCapability->quadra_cfa_dim[0].width;
13980             max_dim.height = m_pCapability->quadra_cfa_dim[0].height;
13981         }
13982         LOGH("Max Dimension = %d X %d", max_dim.width, max_dim.height);
13983         stream_config_info.type[stream_config_info.num_streams] =
13984             CAM_STREAM_TYPE_RAW;
13985         getStreamFormat(CAM_STREAM_TYPE_RAW,
13986                 stream_config_info.format[stream_config_info.num_streams]);
13987         if (CAM_FORMAT_META_RAW_10BIT ==
13988             stream_config_info.format[stream_config_info.num_streams]) {
13989             int32_t dt = 0;
13990             int32_t vc = 0;
13991             cam_stream_size_info_t temp_stream_config_info;
13992             getStreamSubFormat(CAM_STREAM_TYPE_RAW,
13993                 stream_config_info.sub_format_type[
13994                 stream_config_info.num_streams]);
13995             /* Sending separate meta_stream_info so that other modules do
13996              * not confuse with original sendStreamConfigInfo(). This is only
13997              * for sensor where sensor can run pick resolusion for meta raw.
13998              */
13999             updateDtVc(&dt, &vc);
14000             stream_config_info.dt[stream_config_info.num_streams] = dt;
14001             stream_config_info.vc[stream_config_info.num_streams] = vc;
14002             memcpy(&temp_stream_config_info, &stream_config_info,
14003                 sizeof(temp_stream_config_info));
14004             temp_stream_config_info.num_streams++;
14005             sendStreamConfigForPickRes(temp_stream_config_info);
14006             getMetaRawInfo();
14007         } else {
14008             updateRAW(max_dim);
14009         }
14010         getStreamDimension(CAM_STREAM_TYPE_RAW, stream_config_info.stream_sizes[
14011                 stream_config_info.num_streams]);
14012         updatePpFeatureMask(CAM_STREAM_TYPE_RAW);
14013         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
14014                 mStreamPpMask[CAM_STREAM_TYPE_RAW];
14015         stream_config_info.num_streams++;
14016     }
14017 
14018     //For dual camera.
14019     stream_config_info.sync_type = CAM_TYPE_MAIN;
14020 
14021     for (uint32_t k = 0; k < stream_config_info.num_streams; k++) {
14022         LOGI("STREAM INFO : type %d, wxh: %d x %d, pp_mask: 0x%llx \
14023                 Format = %d, dt =%d cid =%d subformat =%d, is_type %d",
14024                 stream_config_info.type[k],
14025                 stream_config_info.stream_sizes[k].width,
14026                 stream_config_info.stream_sizes[k].height,
14027                 stream_config_info.postprocess_mask[k],
14028                 stream_config_info.format[k],
14029                 stream_config_info.dt[k],
14030                 stream_config_info.vc[k],
14031                 stream_config_info.sub_format_type[k],
14032                 stream_config_info.is_type[k]);
14033     }
14034 
14035     if (rc == NO_ERROR && isDualCamera()) {
14036         //Trigger dual camera Link command before Meta info
14037         cam_3a_sync_mode_t sync_3a_mode = CAM_3A_SYNC_FOLLOW;
14038         char prop[PROPERTY_VALUE_MAX];
14039         memset(prop, 0, sizeof(prop));
14040         cam_dual_camera_bundle_info_t bundle_info[MM_CAMERA_MAX_CAM_CNT];
14041         uint8_t num_cam = 0;
14042         uint32_t sessionID = 0;
14043 
14044         property_get("persist.camera.stats.test.2outs", prop, "0");
14045         sync_3a_mode = (atoi(prop) > 0) ? CAM_3A_SYNC_ALGO_CTRL : sync_3a_mode;
14046 
14047         bundle_info[num_cam].sync_control = CAM_SYNC_RELATED_SENSORS_ON;
14048         bundle_info[num_cam].type = CAM_TYPE_MAIN;
14049         bundle_info[num_cam].mode = CAM_MODE_PRIMARY;
14050         bundle_info[num_cam].cam_role = CAM_ROLE_WIDE;
14051         bundle_info[num_cam].sync_3a_mode = sync_3a_mode;
14052         m_pCamOpsTbl->ops->get_session_id(
14053                 get_aux_camera_handle(m_pCamOpsTbl->camera_handle),
14054                 &sessionID);
14055         bundle_info[num_cam].related_sensor_session_id = sessionID;
14056         bundle_info[num_cam].perf_mode = getLowPowerMode(CAM_TYPE_MAIN);
14057         bundle_info[num_cam].is_hw_sync_enabled = DUALCAM_HW_SYNC_ENABLED;
14058         num_cam++;
14059         bundle_info[num_cam].sync_control = CAM_SYNC_RELATED_SENSORS_ON;
14060         bundle_info[num_cam].type = CAM_TYPE_AUX;
14061         bundle_info[num_cam].mode = CAM_MODE_SECONDARY;
14062         bundle_info[num_cam].cam_role = CAM_ROLE_TELE;
14063         bundle_info[num_cam].sync_3a_mode = sync_3a_mode;
14064         m_pCamOpsTbl->ops->get_session_id(
14065                 get_main_camera_handle(m_pCamOpsTbl->camera_handle),
14066                 &sessionID);
14067         bundle_info[num_cam].related_sensor_session_id = sessionID;
14068         bundle_info[num_cam].perf_mode = getLowPowerMode(CAM_TYPE_AUX);
14069         bundle_info[num_cam].is_hw_sync_enabled = DUALCAM_HW_SYNC_ENABLED;
14070         num_cam++;
14071         rc = sendDualCamCmd(CAM_DUAL_CAMERA_BUNDLE_INFO,
14072                 num_cam, &bundle_info[0]);
14073 
14074         // Send dual cam cmd for master camera info
14075         setSwitchCamera(mMasterCamera);
14076     }
14077 
14078     rc = sendStreamConfigInfo(stream_config_info);
14079     updateSnapshotPpMask(stream_config_info);
14080 
14081     return rc;
14082 }
14083 
14084 /*===========================================================================
14085  * FUNCTION   : addOnlineRotation
14086  *
14087  * DESCRIPTION: send additional rotation information for specific stream
14088  *
14089  * PARAMETERS :
14090  *   @rotation: rotation
14091  *   @streamId: internal stream id
14092  *   @device_rotation: device rotation
14093  *
14094  * RETURN     : int32_t type of status
14095  *              NO_ERROR  -- success
14096  *              none-zero failure code
14097  *==========================================================================*/
addOnlineRotation(uint32_t rotation,uint32_t streamId,int32_t device_rotation)14098 int32_t QCameraParameters::addOnlineRotation(uint32_t rotation, uint32_t streamId,
14099         int32_t device_rotation)
14100 {
14101     int32_t rc = NO_ERROR;
14102     cam_rotation_info_t rotation_info;
14103     memset(&rotation_info, 0, sizeof(cam_rotation_info_t));
14104 
14105     /* Add jpeg rotation information */
14106     if (rotation == 0) {
14107         rotation_info.rotation = ROTATE_0;
14108     } else if (rotation == 90) {
14109         rotation_info.rotation = ROTATE_90;
14110     } else if (rotation == 180) {
14111         rotation_info.rotation = ROTATE_180;
14112     } else if (rotation == 270) {
14113         rotation_info.rotation = ROTATE_270;
14114     } else {
14115         rotation_info.rotation = ROTATE_0;
14116     }
14117     rotation_info.streamId = streamId;
14118 
14119     /* Add device rotation information */
14120     if (device_rotation == 0) {
14121         rotation_info.device_rotation = ROTATE_0;
14122     } else if (device_rotation == 90) {
14123         rotation_info.device_rotation = ROTATE_90;
14124     } else if (device_rotation == 180) {
14125         rotation_info.device_rotation = ROTATE_180;
14126     } else if (device_rotation == 270) {
14127         rotation_info.device_rotation = ROTATE_270;
14128     } else {
14129         rotation_info.device_rotation = ROTATE_0;
14130     }
14131 
14132     if(initBatchUpdate() < 0 ) {
14133         LOGE("Failed to initialize group update table");
14134         return BAD_TYPE;
14135     }
14136 
14137     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ROTATION, rotation_info)) {
14138         LOGE("Failed to update table");
14139         return BAD_VALUE;
14140     }
14141 
14142     rc = commitSetBatch();
14143     if (rc != NO_ERROR) {
14144         LOGE("Failed to set stream info parm");
14145         return rc;
14146     }
14147 
14148     return rc;
14149 }
14150 
14151 /*===========================================================================
14152  * FUNCTION   : needThumbnailReprocess
14153  *
14154  * DESCRIPTION: Check if thumbnail reprocessing is needed
14155  *
14156  * PARAMETERS : @pFeatureMask - feature mask
14157  *
14158  * RETURN     : true: needed
14159  *              false: no need
14160  *==========================================================================*/
needThumbnailReprocess(cam_feature_mask_t * pFeatureMask)14161 bool QCameraParameters::needThumbnailReprocess(cam_feature_mask_t *pFeatureMask)
14162 {
14163     if (isUbiFocusEnabled() || isChromaFlashEnabled() ||
14164             isOptiZoomEnabled() || isUbiRefocus() ||
14165             isStillMoreEnabled() ||
14166             (isHDREnabled() && !isHDRThumbnailProcessNeeded())
14167             || isUBWCEnabled()|| getQuadraCfa() ||
14168             isDualCamera()) {
14169         *pFeatureMask &= ~CAM_QCOM_FEATURE_CHROMA_FLASH;
14170         *pFeatureMask &= ~CAM_QCOM_FEATURE_UBIFOCUS;
14171         *pFeatureMask &= ~CAM_QCOM_FEATURE_REFOCUS;
14172         *pFeatureMask &= ~CAM_QCOM_FEATURE_OPTIZOOM;
14173         *pFeatureMask &= ~CAM_QCOM_FEATURE_STILLMORE;
14174         *pFeatureMask &= ~CAM_QCOM_FEATURE_HDR;
14175         return false;
14176     } else {
14177         cam_dimension_t thumb_dim;
14178         getThumbnailSize(&(thumb_dim.width), &(thumb_dim.height));
14179         if (thumb_dim.width == 0 || thumb_dim.height == 0) {
14180             return false;
14181         }
14182         else {
14183             return true;
14184         }
14185     }
14186 }
14187 
14188 /*===========================================================================
14189  * FUNCTION   : getNumOfExtraBuffersForImageProc
14190  *
14191  * DESCRIPTION: get number of extra input buffers needed by image processing
14192  *
14193  * PARAMETERS : none
14194  *
14195  * RETURN     : number of extra buffers needed by ImageProc;
14196  *              0 if not ImageProc enabled
14197  *==========================================================================*/
getNumOfExtraBuffersForImageProc()14198 uint8_t QCameraParameters::getNumOfExtraBuffersForImageProc()
14199 {
14200     int numOfBufs = 0;
14201 
14202     if (isUbiRefocus()) {
14203         return (uint8_t)(m_pCapability->refocus_af_bracketing_need.burst_count - 1);
14204     } else if (isUbiFocusEnabled()) {
14205         numOfBufs += m_pCapability->ubifocus_af_bracketing_need.burst_count - 1;
14206     } else if (m_bOptiZoomOn) {
14207         numOfBufs += m_pCapability->opti_zoom_settings_need.burst_count - 1;
14208     } else if (isChromaFlashEnabled()) {
14209         numOfBufs += m_pCapability->chroma_flash_settings_need.burst_count - 1;
14210     } else if (isStillMoreEnabled()) {
14211         if (isSeeMoreEnabled()) {
14212             m_stillmore_config.burst_count = 1;
14213         } else if ((m_stillmore_config.burst_count >=
14214                 m_pCapability->stillmore_settings_need.min_burst_count) &&
14215                 (m_stillmore_config.burst_count <=
14216                 m_pCapability->stillmore_settings_need.max_burst_count)) {
14217             numOfBufs += m_stillmore_config.burst_count - 1;
14218         } else {
14219             numOfBufs += m_pCapability->stillmore_settings_need.burst_count - 1;
14220         }
14221     } else if (isOEMFeatEnabled()) {
14222         numOfBufs += 4;
14223     }
14224 
14225     if (getQuadraCfa()) {
14226         numOfBufs += 1;
14227     }
14228 
14229     return (uint8_t)(numOfBufs);
14230 }
14231 
14232 /*===========================================================================
14233  * FUNCTION   : getExifBufIndex
14234  *
14235  * DESCRIPTION: get index of metadata to be used for EXIF
14236  *
14237  * PARAMETERS : @captureIndex - index of current captured frame
14238  *
14239  * RETURN     : index of metadata to be used for EXIF
14240  *==========================================================================*/
getExifBufIndex(uint32_t captureIndex)14241 uint32_t QCameraParameters::getExifBufIndex(uint32_t captureIndex)
14242 {
14243     uint32_t index = captureIndex;
14244 
14245     if (isUbiRefocus()) {
14246         if (captureIndex < m_pCapability->refocus_af_bracketing_need.burst_count) {
14247             index = captureIndex;
14248         } else {
14249             index = 0;
14250         }
14251     } else if (isChromaFlashEnabled()) {
14252         index = m_pCapability->chroma_flash_settings_need.metadata_index;
14253     } else if (isHDREnabled()) {
14254         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
14255             index = m_pCapability->hdr_bracketing_setting.num_frames;
14256         } else {
14257             for (index = 0; index < m_pCapability->hdr_bracketing_setting.num_frames; index++) {
14258                 if (0 == m_pCapability->hdr_bracketing_setting.exp_val.values[index]) {
14259                     break;
14260                 }
14261             }
14262             if (index == m_pCapability->hdr_bracketing_setting.num_frames) {
14263                 index = captureIndex;
14264             }
14265         }
14266     }
14267 
14268     return index;
14269 }
14270 
14271 /*===========================================================================
14272  * FUNCTION   : getNumberInBufsForSingleShot
14273  *
14274  * DESCRIPTION: get number of input buffers for single shot
14275  *
14276  * PARAMETERS : none
14277  *
14278  * RETURN     : number of input buffers for single shot
14279  *==========================================================================*/
getNumberInBufsForSingleShot()14280 uint32_t QCameraParameters::getNumberInBufsForSingleShot()
14281 {
14282     uint32_t numOfBufs = 1;
14283 
14284     if (isUbiRefocus()) {
14285         numOfBufs = m_pCapability->refocus_af_bracketing_need.burst_count;
14286     } else if (isUbiFocusEnabled()) {
14287         numOfBufs = m_pCapability->ubifocus_af_bracketing_need.burst_count;
14288     } else if (m_bOptiZoomOn) {
14289         numOfBufs = m_pCapability->opti_zoom_settings_need.burst_count;
14290     } else if (isChromaFlashEnabled()) {
14291         numOfBufs = m_pCapability->chroma_flash_settings_need.burst_count;
14292     } else if (isHDREnabled()) {
14293         numOfBufs = m_pCapability->hdr_bracketing_setting.num_frames;
14294         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
14295             numOfBufs++;
14296         }
14297     } else if (isStillMoreEnabled()) {
14298         if (isSeeMoreEnabled()) {
14299             m_stillmore_config.burst_count = 1;
14300             numOfBufs = m_stillmore_config.burst_count;
14301         } else if ((m_stillmore_config.burst_count >=
14302                 m_pCapability->stillmore_settings_need.min_burst_count) &&
14303                 (m_stillmore_config.burst_count <=
14304                 m_pCapability->stillmore_settings_need.max_burst_count)) {
14305             numOfBufs = m_stillmore_config.burst_count;
14306         } else {
14307             numOfBufs = m_pCapability->stillmore_settings_need.burst_count;
14308         }
14309     }
14310 
14311     return numOfBufs;
14312 }
14313 
14314 /*===========================================================================
14315  * FUNCTION   : getNumberOutBufsForSingleShot
14316  *
14317  * DESCRIPTION: get number of output buffers for single shot
14318  *
14319  * PARAMETERS : none
14320  *
14321  * RETURN     : number of output buffers for single shot
14322  *==========================================================================*/
getNumberOutBufsForSingleShot()14323 uint32_t QCameraParameters::getNumberOutBufsForSingleShot()
14324 {
14325     uint32_t numOfBufs = 1;
14326 
14327     if (isUbiRefocus()) {
14328         numOfBufs = m_pCapability->refocus_af_bracketing_need.output_count;
14329     } else if (isHDREnabled()) {
14330         if (isHDR1xFrameEnabled()) {
14331             numOfBufs++;
14332         }
14333     }
14334 
14335     return numOfBufs;
14336 }
14337 
14338 /*===========================================================================
14339  * FUNCTION   : is4k2kVideoResolution
14340  *
14341  * DESCRIPTION: if resolution is 4k x 2k or true 4k x 2k
14342  *
14343  * PARAMETERS : none
14344  *
14345  * RETURN     : true: video resolution is 4k x 2k
14346  *              false: video resolution is not 4k x 2k
14347  *==========================================================================*/
is4k2kVideoResolution()14348 bool QCameraParameters::is4k2kVideoResolution()
14349 {
14350    bool enabled = false;
14351    cam_dimension_t resolution;
14352    getVideoSize(&resolution.width, &resolution.height);
14353    if (!(resolution.width < 3840 && resolution.height < 2160)) {
14354       enabled = true;
14355    }
14356 
14357    return enabled;
14358 }
14359 
14360 /*===========================================================================
14361  * FUNCTION   : isPreviewSeeMoreRequired
14362  *
14363  * DESCRIPTION: This function checks whether SeeMmore(SW TNR) needs to be applied for
14364  *              preview stream depending on video resoluion and setprop
14365  *
14366  * PARAMETERS : none
14367  *
14368  * RETURN     : true: If SeeMore needs to apply
14369  *              false: No need to apply
14370  *==========================================================================*/
isPreviewSeeMoreRequired()14371 bool QCameraParameters::isPreviewSeeMoreRequired()
14372 {
14373    cam_dimension_t dim;
14374    char prop[PROPERTY_VALUE_MAX];
14375 
14376    getVideoSize(&dim.width, &dim.height);
14377    memset(prop, 0, sizeof(prop));
14378    property_get("persist.camera.preview.seemore", prop, "0");
14379    int enable = atoi(prop);
14380 
14381    // Enable SeeMore for preview stream if :
14382    // 1. Video resolution <= (1920x1080)  (or)
14383    // 2. persist.camera.preview.seemore is set
14384    LOGD("width=%d, height=%d, enable=%d", dim.width, dim.height, enable);
14385    return (((dim.width * dim.height) <= (1920 * 1080)) || enable);
14386 }
14387 
14388 /*===========================================================================
14389  * FUNCTION   : updateDebugLevel
14390  *
14391  * DESCRIPTION: send CAM_INTF_PARM_UPDATE_DEBUG_LEVEL to backend
14392  *
14393  * PARAMETERS : none
14394  *
14395  * RETURN     : NO_ERROR --success
14396  *              int32_t type of status
14397  *==========================================================================*/
updateDebugLevel()14398 int32_t QCameraParameters::updateDebugLevel()
14399 {
14400     if ( m_pParamBuf == NULL ) {
14401         return NO_INIT;
14402     }
14403 
14404     int32_t rc = initBatchUpdate();
14405     if ( rc != NO_ERROR ) {
14406         LOGE("Failed to initialize group update table");
14407         return rc;
14408     }
14409 
14410     uint32_t dummyDebugLevel = 0;
14411     /* The value of dummyDebugLevel is irrelavent. On
14412      * CAM_INTF_PARM_UPDATE_DEBUG_LEVEL, read debug property */
14413     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_UPDATE_DEBUG_LEVEL, dummyDebugLevel)) {
14414         LOGE("Parameters batch failed");
14415         return BAD_VALUE;
14416     }
14417 
14418     rc = commitSetBatch();
14419     if ( rc != NO_ERROR ) {
14420         LOGE("Failed to commit batch parameters");
14421         return rc;
14422     }
14423 
14424     return NO_ERROR;
14425 }
14426 
14427 /*===========================================================================
14428  * FUNCTION   : setOfflineRAW
14429  *
14430  * DESCRIPTION: Function to decide Offline RAW feature.
14431  *
14432  * PARAMETERS :
14433  *  @raw_value: offline raw value to set.
14434  *
14435  * RETURN     : none
14436  *==========================================================================*/
setOfflineRAW(bool raw_value)14437 void QCameraParameters::setOfflineRAW(bool raw_value)
14438 {
14439     char value[PROPERTY_VALUE_MAX];
14440     bool raw_yuv = false;
14441     bool offlineRaw = false;
14442 
14443     if (raw_value) {
14444         mOfflineRAW = true;
14445         LOGH("Offline Raw  %d", mOfflineRAW);
14446         return;
14447     }
14448 
14449     property_get("persist.camera.raw_yuv", value, "0");
14450     raw_yuv = atoi(value) > 0 ? true : false;
14451     property_get("persist.camera.offlineraw", value, "0");
14452     offlineRaw = atoi(value) > 0 ? true : false;
14453     if ((raw_yuv || isRdiMode()) && offlineRaw) {
14454         mOfflineRAW = true;
14455     } else {
14456         mOfflineRAW = false;
14457     }
14458     LOGH("Offline Raw  %d", mOfflineRAW);
14459 }
14460 
14461 /*===========================================================================
14462  * FUNCTION   : updatePpFeatureMask
14463  *
14464  * DESCRIPTION: Updates the feature mask for a particular stream depending
14465  *              on current client configuration.
14466  *
14467  * PARAMETERS :
14468  *  @stream_type: Camera stream type
14469  *
14470  * RETURN     : NO_ERROR --success
14471  *              int32_t type of status
14472  *==========================================================================*/
updatePpFeatureMask(cam_stream_type_t stream_type)14473 int32_t QCameraParameters::updatePpFeatureMask(cam_stream_type_t stream_type) {
14474 
14475     cam_feature_mask_t feature_mask = 0;
14476 
14477     if (stream_type >= CAM_STREAM_TYPE_MAX) {
14478         LOGE("Error!! stream type: %d not valid", stream_type);
14479         return -1;
14480     }
14481 
14482     // Update feature mask for SeeMore in video and video preview
14483     if (isSeeMoreEnabled() && ((stream_type == CAM_STREAM_TYPE_VIDEO) ||
14484             (stream_type == CAM_STREAM_TYPE_PREVIEW && getRecordingHintValue() &&
14485             isPreviewSeeMoreRequired()))) {
14486        feature_mask |= CAM_QCOM_FEATURE_LLVD;
14487     }
14488 
14489     if (isHighQualityNoiseReductionMode() &&
14490             ((stream_type == CAM_STREAM_TYPE_VIDEO) ||
14491             (stream_type == CAM_STREAM_TYPE_PREVIEW && getRecordingHintValue() &&
14492             isPreviewSeeMoreRequired()))) {
14493         feature_mask |= CAM_QTI_FEATURE_SW_TNR;
14494     }
14495 
14496     // Do not enable feature mask for ZSL/non-ZSL/liveshot except for 4K2k case
14497     // Enable feature mask for small Jpeg resolutions
14498     if ((getRecordingHintValue() &&
14499             (stream_type == CAM_STREAM_TYPE_SNAPSHOT) && is4k2kVideoResolution()) ||
14500             (stream_type != CAM_STREAM_TYPE_SNAPSHOT) ||
14501             ((stream_type == CAM_STREAM_TYPE_SNAPSHOT) && isSmallJpegSizeEnabled())) {
14502         if ((m_nMinRequiredPpMask & CAM_QCOM_FEATURE_SHARPNESS) &&
14503                 !isOptiZoomEnabled()) {
14504             feature_mask |= CAM_QCOM_FEATURE_SHARPNESS;
14505         }
14506 
14507         if (m_nMinRequiredPpMask & CAM_QCOM_FEATURE_EFFECT) {
14508             feature_mask |= CAM_QCOM_FEATURE_EFFECT;
14509         }
14510         if (isWNREnabled()) {
14511             feature_mask |= CAM_QCOM_FEATURE_DENOISE2D;
14512         }
14513 
14514         //Set flip mode based on Stream type;
14515         int flipMode = getFlipMode(stream_type);
14516         if (flipMode > 0) {
14517             feature_mask |= CAM_QCOM_FEATURE_FLIP;
14518         }
14519     }
14520 
14521     if ((isTNRVideoEnabled() && (CAM_STREAM_TYPE_VIDEO == stream_type))
14522             || (isTNRPreviewEnabled() && (CAM_STREAM_TYPE_PREVIEW == stream_type))) {
14523         feature_mask |= CAM_QCOM_FEATURE_CPP_TNR;
14524     }
14525     if (isEztuneEnabled() &&
14526             ((CAM_STREAM_TYPE_PREVIEW == stream_type) ||
14527             (CAM_STREAM_TYPE_SNAPSHOT == stream_type))) {
14528         feature_mask |= CAM_QCOM_FEATURE_EZTUNE;
14529     }
14530 
14531     if ((getCDSMode() != CAM_CDS_MODE_OFF) &&
14532             ((CAM_STREAM_TYPE_PREVIEW == stream_type) ||
14533             (CAM_STREAM_TYPE_VIDEO == stream_type) ||
14534             (CAM_STREAM_TYPE_CALLBACK == stream_type) ||
14535             (CAM_STREAM_TYPE_POSTVIEW == stream_type) ||
14536             ((CAM_STREAM_TYPE_SNAPSHOT == stream_type) &&
14537             getRecordingHintValue() && is4k2kVideoResolution()))) {
14538          if (m_nMinRequiredPpMask & CAM_QCOM_FEATURE_DSDN) {
14539              feature_mask |= CAM_QCOM_FEATURE_DSDN;
14540          } else {
14541              feature_mask |= CAM_QCOM_FEATURE_CDS;
14542          }
14543     }
14544 
14545     if (isTNRSnapshotEnabled() && (CAM_STREAM_TYPE_SNAPSHOT == stream_type)
14546             && (isZSLMode() || getRecordingHintValue())) {
14547         feature_mask |= CAM_QCOM_FEATURE_CPP_TNR;
14548     }
14549 
14550     //Rotation could also have an effect on pp feature mask
14551     cam_pp_feature_config_t config;
14552     cam_dimension_t dim;
14553     memset(&config, 0, sizeof(cam_pp_feature_config_t));
14554     getStreamRotation(stream_type, config, dim);
14555     feature_mask |= config.feature_mask;
14556 
14557     // Dual Camera scenarios
14558     // all feature masks are disabled for preview and analysis streams for aux session
14559     // all required feature masks for aux session preview and analysis streams need
14560     // to be enabled explicitly here
14561     ///@note When aux camera is of bayer type, keep pp mask as is or we'd run
14562     ///      into stream mapping problems. YUV sensor is marked as interleaved and has
14563     ///      preferred mapping setup so we don't see any mapping issues.
14564     if (m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
14565         if (((CAM_STREAM_TYPE_ANALYSIS == stream_type) ||
14566                 (CAM_STREAM_TYPE_PREVIEW == stream_type)) &&
14567                 (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) &&
14568                 (m_pCapability->sensor_type.sens_type == CAM_SENSOR_YUV)) {
14569             LOGH("Disabling all pp feature masks for aux preview and "
14570                     "analysis streams");
14571             feature_mask = 0;
14572         }
14573 
14574         // all feature masks need to be enabled here
14575         // enable DCRF feature mask on analysis stream in case of dual camera
14576         if (m_bDcrfEnabled && (CAM_STREAM_TYPE_ANALYSIS == stream_type)) {
14577             feature_mask |= CAM_QCOM_FEATURE_DCRF;
14578         } else {
14579             feature_mask &= ~CAM_QCOM_FEATURE_DCRF;
14580         }
14581     }
14582 
14583     // Preview assisted autofocus needs to be supported for
14584     // callback, preview, or video streams
14585     cam_color_filter_arrangement_t filter_arrangement;
14586     filter_arrangement = m_pCapability->color_arrangement;
14587     switch (filter_arrangement) {
14588     case CAM_FILTER_ARRANGEMENT_RGGB:
14589     case CAM_FILTER_ARRANGEMENT_GRBG:
14590     case CAM_FILTER_ARRANGEMENT_GBRG:
14591     case CAM_FILTER_ARRANGEMENT_BGGR:
14592         if ((stream_type == CAM_STREAM_TYPE_CALLBACK) ||
14593             (stream_type == CAM_STREAM_TYPE_PREVIEW)) {
14594             feature_mask |= CAM_QCOM_FEATURE_PAAF;
14595         } else if (stream_type == CAM_STREAM_TYPE_VIDEO) {
14596             if (getVideoISType() != IS_TYPE_EIS_3_0)
14597                 feature_mask |= CAM_QCOM_FEATURE_PAAF;
14598         }
14599         break;
14600     case CAM_FILTER_ARRANGEMENT_Y:
14601         if (stream_type == CAM_STREAM_TYPE_ANALYSIS) {
14602             feature_mask |= CAM_QCOM_FEATURE_PAAF;
14603             LOGH("add PAAF mask to feature_mask for mono device");
14604         }
14605         break;
14606     default:
14607         break;
14608     }
14609 
14610     // Enable PPEISCORE for EIS 3.0
14611     if ((stream_type == CAM_STREAM_TYPE_VIDEO) &&
14612             (getVideoISType() == IS_TYPE_EIS_3_0)) {
14613         feature_mask |= CAM_QTI_FEATURE_PPEISCORE;
14614     }
14615 
14616     if(isDualCamera()) {
14617         char prop[PROPERTY_VALUE_MAX];
14618         bool satEnabledFlag = FALSE;
14619         bool sacEnabledFlag = FALSE;
14620         bool rtbdmEnabledFlag = FALSE;
14621         bool rtbEnabledFlag = FALSE;
14622         memset(prop, 0, sizeof(prop));
14623         property_get("persist.camera.sat.enable", prop, "0");
14624         satEnabledFlag = atoi(prop);
14625 
14626         if (satEnabledFlag) {
14627         LOGH("SAT flag enabled");
14628             if (stream_type == CAM_STREAM_TYPE_VIDEO &&
14629                 !is4k2kVideoResolution()) {
14630                 feature_mask |= CAM_QTI_FEATURE_SAT;
14631                 LOGH("SAT feature mask set");
14632             } else if ((stream_type == CAM_STREAM_TYPE_PREVIEW)||
14633                 (stream_type == CAM_STREAM_TYPE_CALLBACK)) {
14634                 feature_mask |= CAM_QTI_FEATURE_SAT;
14635                 LOGH("SAT feature mask set");
14636             }
14637         }
14638 
14639         memset(prop, 0, sizeof(prop));
14640         property_get("persist.camera.sac.enable", prop, "0");
14641         sacEnabledFlag = atoi(prop);
14642 
14643         if (sacEnabledFlag) {
14644         LOGH("SAC flag enabled");
14645             if (stream_type == CAM_STREAM_TYPE_ANALYSIS) {
14646                 feature_mask |= CAM_QTI_FEATURE_SAC;
14647                 LOGH("SAC feature mask set");
14648             }
14649         }
14650 
14651         memset(prop, 0, sizeof(prop));
14652         property_get("persist.camera.rtbdm.enable", prop, "0");
14653         rtbdmEnabledFlag = atoi(prop);
14654 
14655         if (rtbdmEnabledFlag) {
14656         LOGH("RTBDM flag enabled");
14657             if (stream_type == CAM_STREAM_TYPE_ANALYSIS) {
14658                 feature_mask |= CAM_QTI_FEATURE_RTBDM;
14659                 LOGH("RTBDM feature mask set");
14660             }
14661         }
14662 
14663         memset(prop, 0, sizeof(prop));
14664         property_get("persist.camera.rtb.enable", prop, "0");
14665         rtbEnabledFlag = atoi(prop);
14666 
14667         if (rtbEnabledFlag) {
14668         LOGH("RTB flag enabled");
14669             if ((stream_type == CAM_STREAM_TYPE_PREVIEW)||
14670                 (stream_type == CAM_STREAM_TYPE_CALLBACK)) {
14671                 feature_mask |= CAM_QTI_FEATURE_RTB;
14672                 LOGH("RTB feature mask set");
14673             }
14674         }
14675     }
14676 
14677     if (stream_type == CAM_STREAM_TYPE_VIDEO ||
14678         stream_type == CAM_STREAM_TYPE_PREVIEW) {
14679         char prop[PROPERTY_VALUE_MAX];
14680         memset(prop, 0, sizeof(prop));
14681         int32_t fixedFOVCenabled = FALSE;
14682         property_get("persist.camera.fovc.enable", prop, "0");
14683         fixedFOVCenabled = atoi(prop);
14684         if (fixedFOVCenabled == 1) {
14685             LOGH("Fixed FOVC feature mask set for stream type %d", stream_type);
14686             feature_mask |= CAM_QTI_FEATURE_FIXED_FOVC;
14687         }
14688     }
14689 
14690     // Store stream feature mask
14691     setStreamPpMask(stream_type, feature_mask);
14692     LOGH("stream type: %d, pp_mask: 0x%llx", stream_type, feature_mask);
14693 
14694     return NO_ERROR;
14695 }
14696 
14697 /*===========================================================================
14698  * FUNCTION   : setStreamPpMask
14699  *
14700  * DESCRIPTION: Stores a particular feature mask for a given camera stream
14701  *
14702  * PARAMETERS :
14703  *  @stream_type: Camera stream type
14704  *  @pp_mask  : Feature mask
14705  *
14706  * RETURN     : NO_ERROR --success
14707  *              int32_t type of status
14708  *==========================================================================*/
setStreamPpMask(cam_stream_type_t stream_type,cam_feature_mask_t pp_mask)14709 int32_t QCameraParameters::setStreamPpMask(cam_stream_type_t stream_type,
14710         cam_feature_mask_t pp_mask) {
14711 
14712     if(stream_type >= CAM_STREAM_TYPE_MAX) {
14713         return BAD_TYPE;
14714     }
14715 
14716     mStreamPpMask[stream_type] = pp_mask;
14717     return NO_ERROR;
14718 }
14719 
14720 /*===========================================================================
14721  * FUNCTION   : getStreamPpMask
14722  *
14723  * DESCRIPTION: Retrieves the feature mask for a given camera stream
14724  *
14725  * PARAMETERS :
14726  *  @stream_type: Camera stream type
14727  *  @pp_mask  : Feature mask
14728  *
14729  * RETURN     : NO_ERROR --success
14730  *              int32_t type of status
14731  *==========================================================================*/
getStreamPpMask(cam_stream_type_t stream_type,cam_feature_mask_t & pp_mask)14732 int32_t QCameraParameters::getStreamPpMask(cam_stream_type_t stream_type,
14733         cam_feature_mask_t &pp_mask) {
14734 
14735     if(stream_type >= CAM_STREAM_TYPE_MAX) {
14736         return BAD_TYPE;
14737     }
14738 
14739     pp_mask = mStreamPpMask[stream_type];
14740     return NO_ERROR;
14741 }
14742 
14743 /*===========================================================================
14744  * FUNCTION   : isMultiPassReprocessing
14745  *
14746  * DESCRIPTION: Read setprop to enable/disable multipass
14747  *
14748  * PARAMETERS : none
14749  *
14750  * RETURN     : TRUE  -- If enabled
14751  *              FALSE  -- disabled
14752  *==========================================================================*/
isMultiPassReprocessing()14753 bool QCameraParameters::isMultiPassReprocessing()
14754 {
14755     char value[PROPERTY_VALUE_MAX];
14756     int multpass = 0;
14757 
14758     if (getQuadraCfa()) {
14759         multpass = TRUE;
14760         return TRUE;
14761     }
14762 
14763     property_get("persist.camera.multi_pass", value, "0");
14764     multpass = atoi(value);
14765 
14766     return (multpass == 0)? FALSE : TRUE;
14767 }
14768 
14769 /*===========================================================================
14770  * FUNCTION   : setReprocCount
14771  *
14772  * DESCRIPTION: Set total reprocessing pass count
14773  *
14774  * PARAMETERS : none
14775  *
14776  * RETURN     : None
14777  *==========================================================================*/
setReprocCount()14778 void QCameraParameters::setReprocCount()
14779 {
14780     mTotalPPCount = 1; //Default reprocessing Pass count
14781 
14782     if (getManualCaptureMode() >=
14783             CAM_MANUAL_CAPTURE_TYPE_3) {
14784         LOGD("Additional post processing enabled for manual capture");
14785         mTotalPPCount++;
14786     }
14787 
14788     if (!isMultiPassReprocessing()) {
14789         return;
14790     }
14791 
14792     if ((getZoomLevel() != 0 && !getQuadraCfa())
14793             && (getBurstCountForAdvancedCapture()
14794             == getNumOfSnapshots())) {
14795         LOGD("2 Pass postprocessing enabled");
14796         mTotalPPCount++;
14797     }
14798 
14799     if (getQuadraCfa()) {
14800         mTotalPPCount++;
14801     }
14802 }
14803 
14804 /*===========================================================================
14805  * FUNCTION   : isUBWCEnabled
14806  *
14807  * DESCRIPTION: Function to get UBWC hardware support.
14808  *
14809  * PARAMETERS : None
14810  *
14811  * RETURN     : TRUE -- UBWC format supported
14812  *              FALSE -- UBWC is not supported.
14813  *==========================================================================*/
isUBWCEnabled()14814 bool QCameraParameters::isUBWCEnabled()
14815 {
14816 #ifdef UBWC_PRESENT
14817     char value[PROPERTY_VALUE_MAX];
14818     int prop_value = 0;
14819     memset(value, 0, sizeof(value));
14820     property_get("debug.gralloc.gfx_ubwc_disable", value, "0");
14821     prop_value = atoi(value);
14822     if (prop_value) {
14823         return FALSE;
14824     }
14825 
14826     //Disable UBWC if it is YUV sensor.
14827     if ((m_pCapability != NULL) &&
14828             (m_pCapability->sensor_type.sens_type == CAM_SENSOR_YUV)) {
14829         return FALSE;
14830     }
14831 
14832     //Disable UBWC if Eztune is enabled
14833     // Eztune works on CPP output and cannot understand UBWC buffer.
14834     memset(value, 0, sizeof(value));
14835     property_get("persist.camera.eztune.enable", value, "0");
14836     prop_value = atoi(value);
14837     if (prop_value) {
14838         return FALSE;
14839     }
14840     return TRUE;
14841 #else
14842     return FALSE;
14843 #endif
14844 }
14845 
14846 /*===========================================================================
14847  * FUNCTION   : isPostProcScaling
14848  *
14849  * DESCRIPTION: is scaling to be done by CPP?
14850  *
14851  * PARAMETERS : none
14852  *
14853  * RETURN     : TRUE  : If CPP scaling enabled
14854  *              FALSE : If VFE scaling enabled
14855  *==========================================================================*/
isPostProcScaling()14856 bool QCameraParameters::isPostProcScaling()
14857 {
14858     char value[PROPERTY_VALUE_MAX];
14859     bool cpp_scaling = FALSE;
14860 
14861     if (getRecordingHintValue()) {
14862         return FALSE;
14863     }
14864 
14865     property_get("persist.camera.pp_scaling", value, "0");
14866     cpp_scaling = atoi(value) > 0 ? TRUE : FALSE;
14867 
14868     LOGH("Post proc scaling enabled : %d",
14869              cpp_scaling);
14870     return cpp_scaling;
14871 }
14872 
14873 /*===========================================================================
14874  * FUNCTION   : isLLNoiseEnabled
14875  *
14876  * DESCRIPTION: Low light noise change
14877  *
14878  * PARAMETERS : none
14879  *
14880  * RETURN     : TRUE  : If low light noise enabled
14881  *              FALSE : If low light noise disabled
14882  *==========================================================================*/
isLLNoiseEnabled()14883 bool QCameraParameters::isLLNoiseEnabled()
14884 {
14885     char value[PROPERTY_VALUE_MAX];
14886     bool llnoise = FALSE;
14887 
14888     if (!isWNREnabled()) {
14889         return FALSE;
14890     }
14891 
14892     property_get("persist.camera.llnoise", value, "0");
14893     llnoise = atoi(value) > 0 ? TRUE : FALSE;
14894 
14895     LOGH("Low light noise enabled : %d",
14896              llnoise);
14897     return llnoise;
14898 }
14899 
14900 /*===========================================================================
14901  * FUNCTION   : setBufBatchCount
14902  *
14903  * DESCRIPTION: Function to configure batch buffer
14904  *
14905  * PARAMETERS : int8_t buf_cnt
14906  *                     Buffer batch count
14907  *
14908  * RETURN     :  None
14909  *==========================================================================*/
setBufBatchCount(int8_t buf_cnt)14910 void QCameraParameters::setBufBatchCount(int8_t buf_cnt)
14911 {
14912     mBufBatchCnt = 0;
14913     char value[PROPERTY_VALUE_MAX];
14914     int8_t count = 0;
14915 
14916     property_get("persist.camera.batchcount", value, "0");
14917     count = atoi(value);
14918 
14919     if (!(count != 0 || buf_cnt > CAMERA_MIN_BATCH_COUNT)) {
14920         LOGH("Buffer batch count = %d", mBufBatchCnt);
14921         set(KEY_QC_VIDEO_BATCH_SIZE, mBufBatchCnt);
14922         return;
14923     }
14924 
14925     while((m_pCapability->max_batch_bufs_supported != 0)
14926             && (m_pCapability->max_batch_bufs_supported < buf_cnt)) {
14927         buf_cnt = buf_cnt / 2;
14928     }
14929 
14930     if (count > 0) {
14931         mBufBatchCnt = count;
14932         LOGH("Buffer batch count = %d", mBufBatchCnt);
14933         set(KEY_QC_VIDEO_BATCH_SIZE, mBufBatchCnt);
14934         return;
14935     }
14936 
14937     if (buf_cnt > CAMERA_MIN_BATCH_COUNT) {
14938         mBufBatchCnt = buf_cnt;
14939         LOGH("Buffer batch count = %d", mBufBatchCnt);
14940         set(KEY_QC_VIDEO_BATCH_SIZE, mBufBatchCnt);
14941         return;
14942     }
14943 }
14944 
14945 /*===========================================================================
14946  * FUNCTION   : setVideoBatch()
14947  *
14948  * DESCRIPTION: Function to batching for video.
14949  *
14950  * PARAMETERS : none
14951  *
14952  * RETURN     :  None
14953  *==========================================================================*/
setVideoBatchSize()14954 void QCameraParameters::setVideoBatchSize()
14955 {
14956     char value[PROPERTY_VALUE_MAX];
14957     int8_t minBatchcnt = 2; //Batching enabled only if batch size if greater than 2;
14958     int32_t width = 0, height = 0;
14959     mVideoBatchSize = 0;
14960 
14961     if (getBufBatchCount()) {
14962         //We don't need HAL to HAL batching if camera batching enabled.
14963         return;
14964     }
14965 
14966     getVideoSize(&width, &height);
14967     if ((width > 1920) || (height > 1080)) {
14968         //Cannot enable batch mode for video size bigger than 1080p
14969         return;
14970     }
14971 
14972     //Batch size "6" is the recommended and gives optimal power saving.
14973     property_get("persist.camera.video.batchsize", value, "0");
14974     mVideoBatchSize = atoi(value);
14975 
14976     if (mVideoBatchSize > CAMERA_MAX_CONSUMER_BATCH_BUFFER_SIZE) {
14977         mVideoBatchSize = CAMERA_MAX_CONSUMER_BATCH_BUFFER_SIZE;
14978     } else if (mVideoBatchSize <= minBatchcnt) {
14979         //Batching enabled only if batch size is greater than 2.
14980         mVideoBatchSize = 0;
14981     }
14982     LOGD("mVideoBatchSize = %d", mVideoBatchSize);
14983     set(KEY_QC_VIDEO_BATCH_SIZE, mVideoBatchSize);
14984 }
14985 
14986 /*===========================================================================
14987  * FUNCTION   : setCustomParams
14988  *
14989  * DESCRIPTION: Function to update OEM specific custom parameter
14990  *
14991  * PARAMETERS : params: Input Parameter object
14992  *
14993  * RETURN     :  error value
14994  *==========================================================================*/
setCustomParams(__unused const QCameraParameters & params)14995 int32_t QCameraParameters::setCustomParams(__unused const QCameraParameters& params)
14996 {
14997     int32_t rc = NO_ERROR;
14998 
14999     /* Application specific parameter can be read from "params" and update m_pParamBuf
15000        We can also update internal OEM custom parameters in this funcion.
15001        "CAM_CUSTOM_PARM_EXAMPLE" is used as a example */
15002 
15003     /*Get the pointer of shared buffer for custom parameter*/
15004     custom_parm_buffer_t *customParam =
15005             (custom_parm_buffer_t *)POINTER_OF_META(CAM_INTF_PARM_CUSTOM, m_pParamBuf);
15006 
15007 
15008     /*start updating custom parameter values*/
15009     if (ADD_SET_PARAM_ENTRY_TO_BATCH(customParam, CAM_CUSTOM_PARM_EXAMPLE, 1)) {
15010         LOGE("Failed to update CAM_CUSTOM_PARM_DUMMY");
15011         return BAD_VALUE;
15012     }
15013 
15014     /*set custom parameter values to main parameter buffer. Update isvalid flag*/
15015     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CUSTOM);
15016 
15017     return rc;
15018 }
15019 
15020 /*===========================================================================
15021  * FUNCTION   : dump
15022  *
15023  * DESCRIPTION: Composes a string based on current configuration
15024  *
15025  * PARAMETERS : none
15026  *
15027  * RETURN     : Formatted string
15028  *==========================================================================*/
dump()15029 String8 QCameraParameters::dump()
15030 {
15031     String8 str("\n");
15032     char s[128];
15033 
15034     snprintf(s, 128, "Preview Pixel Fmt: %d\n", getPreviewHalPixelFormat());
15035     str += s;
15036 
15037     snprintf(s, 128, "ZSL Burst Interval: %d\n", getZSLBurstInterval());
15038     str += s;
15039 
15040     snprintf(s, 128, "ZSL Queue Depth: %d\n", getZSLQueueDepth());
15041     str += s;
15042 
15043     snprintf(s, 128, "ZSL Back Look Count %d\n", getZSLBackLookCount());
15044     str += s;
15045 
15046     snprintf(s, 128, "Max Unmatched Frames In Queue: %d\n",
15047         getMaxUnmatchedFramesInQueue());
15048     str += s;
15049 
15050     snprintf(s, 128, "Is ZSL Mode: %d\n", isZSLMode());
15051     str += s;
15052 
15053     snprintf(s, 128, "Is No Display Mode: %d\n", isNoDisplayMode());
15054     str += s;
15055 
15056     snprintf(s, 128, "Is WNR Enabled: %d\n", isWNREnabled());
15057     str += s;
15058 
15059     snprintf(s, 128, "isHfrMode: %d\n", isHfrMode());
15060     str += s;
15061 
15062     snprintf(s, 128, "getNumOfSnapshots: %d\n", getNumOfSnapshots());
15063     str += s;
15064 
15065     snprintf(s, 128, "getNumOfExtraHDRInBufsIfNeeded: %d\n",
15066         getNumOfExtraHDRInBufsIfNeeded());
15067     str += s;
15068 
15069     snprintf(s, 128, "getNumOfExtraHDROutBufsIfNeeded: %d\n",
15070         getNumOfExtraHDROutBufsIfNeeded());
15071     str += s;
15072 
15073     snprintf(s, 128, "getRecordingHintValue: %d\n", getRecordingHintValue());
15074     str += s;
15075 
15076     snprintf(s, 128, "getJpegQuality: %u\n", getJpegQuality());
15077     str += s;
15078 
15079     snprintf(s, 128, "getJpegRotation: %u\n", getJpegRotation());
15080     str += s;
15081 
15082     snprintf(s, 128, "isHistogramEnabled: %d\n", isHistogramEnabled());
15083     str += s;
15084 
15085     snprintf(s, 128, "isFaceDetectionEnabled: %d\n", isFaceDetectionEnabled());
15086     str += s;
15087 
15088     snprintf(s, 128, "isHDREnabled: %d\n", isHDREnabled());
15089     str += s;
15090 
15091     snprintf(s, 128, "isAutoHDREnabled: %d\n", isAutoHDREnabled());
15092     str += s;
15093 
15094     snprintf(s, 128, "isAVTimerEnabled: %d\n", isAVTimerEnabled());
15095     str += s;
15096 
15097     snprintf(s, 128, "getFocusMode: %d\n", getFocusMode());
15098     str += s;
15099 
15100     snprintf(s, 128, "isJpegPictureFormat: %d\n", isJpegPictureFormat());
15101     str += s;
15102 
15103     snprintf(s, 128, "isNV16PictureFormat: %d\n", isNV16PictureFormat());
15104     str += s;
15105 
15106     snprintf(s, 128, "isNV21PictureFormat: %d\n", isNV21PictureFormat());
15107     str += s;
15108 
15109     snprintf(s, 128, "isSnapshotFDNeeded: %d\n", isSnapshotFDNeeded());
15110     str += s;
15111 
15112     snprintf(s, 128, "isHDR1xFrameEnabled: %d\n", isHDR1xFrameEnabled());
15113     str += s;
15114 
15115     snprintf(s, 128, "isYUVFrameInfoNeeded: %d\n", isYUVFrameInfoNeeded());
15116     str += s;
15117 
15118     snprintf(s, 128, "isHDR1xExtraBufferNeeded: %d\n",
15119         isHDR1xExtraBufferNeeded());
15120     str += s;
15121 
15122     snprintf(s, 128, "isHDROutputCropEnabled: %d\n", isHDROutputCropEnabled());
15123     str += s;
15124 
15125     snprintf(s, 128, "isPreviewFlipChanged: %d\n", isPreviewFlipChanged());
15126     str += s;
15127 
15128     snprintf(s, 128, "isVideoFlipChanged: %d\n", isVideoFlipChanged());
15129     str += s;
15130 
15131     snprintf(s, 128, "isSnapshotFlipChanged: %d\n", isSnapshotFlipChanged());
15132     str += s;
15133 
15134     snprintf(s, 128, "isHDRThumbnailProcessNeeded: %d\n",
15135         isHDRThumbnailProcessNeeded());
15136     str += s;
15137 
15138     snprintf(s, 128, "getAutoFlickerMode: %d\n", getAutoFlickerMode());
15139     str += s;
15140 
15141     snprintf(s, 128, "getNumOfExtraBuffersForImageProc: %d\n",
15142         getNumOfExtraBuffersForImageProc());
15143     str += s;
15144 
15145     snprintf(s, 128, "isUbiFocusEnabled: %d\n", isUbiFocusEnabled());
15146     str += s;
15147 
15148     snprintf(s, 128, "isChromaFlashEnabled: %d\n", isChromaFlashEnabled());
15149     str += s;
15150 
15151     snprintf(s, 128, "isOptiZoomEnabled: %d\n", isOptiZoomEnabled());
15152     str += s;
15153 
15154     snprintf(s, 128, "isStillMoreEnabled: %d\n", isStillMoreEnabled());
15155     str += s;
15156 
15157     snprintf(s, 128, "getBurstCountForAdvancedCapture: %d\n",
15158         getBurstCountForAdvancedCapture());
15159     str += s;
15160 
15161     return str;
15162 }
15163 
15164 /*===========================================================================
15165  * FUNCTION   : getNumOfExtraBuffersForVideo
15166  *
15167  * DESCRIPTION: get number of extra buffers needed by image processing
15168  *
15169  * PARAMETERS : none
15170  *
15171  * RETURN     : number of extra buffers needed by ImageProc;
15172  *              0 if not ImageProc enabled
15173  *==========================================================================*/
getNumOfExtraBuffersForVideo()15174 uint8_t QCameraParameters::getNumOfExtraBuffersForVideo()
15175 {
15176     uint8_t numOfBufs = 0;
15177 
15178     if (isSeeMoreEnabled() || isHighQualityNoiseReductionMode()) {
15179         numOfBufs = 1;
15180     }
15181 
15182     return numOfBufs;
15183 }
15184 
15185 /*===========================================================================
15186  * FUNCTION   : getNumOfExtraBuffersForPreview
15187  *
15188  * DESCRIPTION: get number of extra buffers needed by image processing
15189  *
15190  * PARAMETERS : none
15191  *
15192  * RETURN     : number of extra buffers needed by ImageProc;
15193  *              0 if not ImageProc enabled
15194  *==========================================================================*/
getNumOfExtraBuffersForPreview()15195 uint8_t QCameraParameters::getNumOfExtraBuffersForPreview()
15196 {
15197     uint8_t numOfBufs = 0;
15198 
15199     if ((isSeeMoreEnabled() || isHighQualityNoiseReductionMode())
15200             && !isZSLMode() && getRecordingHintValue()) {
15201         numOfBufs = 1;
15202     }
15203 
15204     return numOfBufs;
15205 }
15206 
15207 /*===========================================================================
15208  * FUNCTION   : setToneMapMode
15209  *
15210  * DESCRIPTION: enable or disable tone map
15211  *
15212  * PARAMETERS :
15213  *   @enable : enable: 1; disable 0
15214  *   @initCommit: if configuration list needs to be initialized and commited
15215  *
15216  * RETURN     : int32_t type of status
15217  *              NO_ERROR  -- success
15218  *              none-zero failure code
15219  *==========================================================================*/
setToneMapMode(uint32_t enable,bool initCommit)15220 int32_t QCameraParameters::setToneMapMode(uint32_t enable, bool initCommit)
15221 {
15222     int32_t rc = NO_ERROR;
15223     LOGH("tone map mode %d ", enable);
15224 
15225     if (initCommit) {
15226         if (initBatchUpdate() < 0) {
15227             LOGE("Failed to initialize group update table");
15228             return FAILED_TRANSACTION;
15229         }
15230     }
15231 
15232     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TONE_MAP_MODE, enable)) {
15233         LOGE("Failed to update tone map mode");
15234         return BAD_VALUE;
15235     }
15236 
15237     if (initCommit) {
15238         rc = commitSetBatch();
15239         if (rc != NO_ERROR) {
15240             LOGE("Failed to commit tone map mode");
15241             return rc;
15242         }
15243     }
15244 
15245     return rc;
15246 }
15247 
15248 /*===========================================================================
15249  * FUNCTION   : getLongshotStages
15250  *
15251  * DESCRIPTION: get number of stages for longshot
15252  *
15253  * PARAMETERS : none
15254  *
15255  * RETURN     : number of stages
15256  *==========================================================================*/
getLongshotStages()15257 uint8_t QCameraParameters::getLongshotStages()
15258 {
15259     uint8_t numStages =
15260             isLowMemoryDevice() ? CAMERA_MIN_LONGSHOT_STAGES : CAMERA_DEFAULT_LONGSHOT_STAGES;
15261 
15262     char prop[PROPERTY_VALUE_MAX];
15263     memset(prop, 0, sizeof(prop));
15264     property_get("persist.camera.longshot.stages", prop, "0");
15265     uint8_t propStages = atoi(prop);
15266     if (propStages > 0 && propStages <= CAMERA_DEFAULT_LONGSHOT_STAGES) {
15267         numStages = propStages;
15268     }
15269     return numStages;
15270 }
15271 
15272 /*===========================================================================
15273  * FUNCTION   : setCDSMode
15274  *
15275  * DESCRIPTION: set CDS mode
15276  *
15277  * PARAMETERS :
15278  *   @cds_mode : cds mode
15279  *   @initCommit: if configuration list needs to be initialized and commited
15280  *
15281  * RETURN     : int32_t type of status
15282  *              NO_ERROR  -- success
15283  *              none-zero failure code
15284  *==========================================================================*/
setCDSMode(int32_t cds_mode,bool initCommit)15285 int32_t QCameraParameters::setCDSMode(int32_t cds_mode, bool initCommit)
15286 {
15287     if (initCommit) {
15288         if (initBatchUpdate() < 0) {
15289             LOGE("Failed to initialize group update table");
15290             return FAILED_TRANSACTION;
15291         }
15292     }
15293 
15294     int32_t rc = NO_ERROR;
15295     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
15296         LOGE("Failed to update cds mode");
15297         return BAD_VALUE;
15298     }
15299 
15300     if (initCommit) {
15301         rc = commitSetBatch();
15302         if (NO_ERROR != rc) {
15303             LOGE("Failed to set cds mode");
15304             return rc;
15305         }
15306     }
15307 
15308     LOGH("cds mode -> %d", cds_mode);
15309 
15310     return rc;
15311 }
15312 
15313 /*===========================================================================
15314  * FUNCTION   : setLowLightCapture
15315  *
15316  * DESCRIPTION: Function to enable low light capture
15317  *==========================================================================*/
setLowLightCapture()15318 void QCameraParameters::setLowLightCapture()
15319 {
15320     char prop[PROPERTY_VALUE_MAX];
15321     memset(prop, 0, sizeof(prop));
15322     property_get("persist.camera.llc", prop, "0");
15323     m_LLCaptureEnabled = (atoi(prop) > 0) ? TRUE : FALSE;
15324 
15325     if (!m_LLCaptureEnabled) {
15326         m_LowLightLevel = CAM_LOW_LIGHT_OFF;
15327     }
15328 }
15329 
15330 /*===========================================================================
15331  * FUNCTION   : fdModeInVideo
15332  *
15333  * DESCRIPTION: FD in Video change
15334  *
15335  * PARAMETERS : none
15336  *
15337  * RETURN     : FD Mode in Video
15338  *              0 : If FD in Video disabled
15339  *              1 : If FD in Video enabled for Detection, focus
15340  *              2 : If FD in Video enabled only for focus
15341  *==========================================================================*/
fdModeInVideo()15342 uint8_t QCameraParameters::fdModeInVideo()
15343 {
15344     char value[PROPERTY_VALUE_MAX];
15345     uint8_t fdvideo = 0;
15346 
15347     property_get("persist.camera.fdvideo", value, "0");
15348     fdvideo = (atoi(value) > 0) ? atoi(value) : 0;
15349 
15350     LOGD("FD mode in Video : %d", fdvideo);
15351     return fdvideo;
15352 }
15353 
15354 /*===========================================================================
15355  * FUNCTION   : isOEMFeatFrameSkipEnabled
15356  *
15357  * DESCRIPTION: If OEMFeat processcess alternate frame
15358  *
15359  * PARAMETERS : none
15360  *
15361  * RETURN     : boolean
15362  *==========================================================================*/
isOEMFeatFrameSkipEnabled()15363 uint8_t QCameraParameters::isOEMFeatFrameSkipEnabled()
15364 {
15365     char value[PROPERTY_VALUE_MAX];
15366     uint8_t oemfeatframeskipenabled = 0;
15367 
15368     property_get("persist.camera.imglib.of1.skip", value, "0");
15369     oemfeatframeskipenabled = (atoi(value) > 0) ? atoi(value) : 0;
15370 
15371     LOGD("isOEMFeatFrameSkipEnabled %d", oemfeatframeskipenabled);
15372     return oemfeatframeskipenabled;
15373 }
15374 
15375 /*===========================================================================
15376  * FUNCTION   : setManualCaptureMode
15377  *
15378  * DESCRIPTION: Function to set Manual capture modes
15379  *
15380  * PARAMETERS :
15381  *   @mode : Capture mode configured
15382  *
15383  * RETURN     : int32_t type of status
15384  *              NO_ERROR  -- success
15385  *              none-zero failure code
15386  *==========================================================================*/
setManualCaptureMode(QCameraManualCaptureModes mode)15387 int32_t QCameraParameters::setManualCaptureMode(QCameraManualCaptureModes mode)
15388 {
15389     int32_t rc = NO_ERROR;
15390     char value[PROPERTY_VALUE_MAX];
15391     int8_t count = 0;
15392 
15393     property_get("persist.camera.manual.capture", value, "0");
15394     count = atoi(value);
15395 
15396     if (count) {
15397         if (mode == CAM_MANUAL_CAPTURE_TYPE_OFF) {
15398             m_ManualCaptureMode = CAM_MANUAL_CAPTURE_TYPE_1;
15399         } else {
15400             m_ManualCaptureMode = mode;
15401         }
15402     } else {
15403         m_ManualCaptureMode = CAM_MANUAL_CAPTURE_TYPE_OFF;
15404     }
15405 
15406     if (m_ManualCaptureMode == CAM_MANUAL_CAPTURE_TYPE_2) {
15407         setOfflineRAW(FALSE);
15408     } else if (m_ManualCaptureMode >= CAM_MANUAL_CAPTURE_TYPE_3) {
15409         setOfflineRAW(TRUE);
15410     } else {
15411         setOfflineRAW(FALSE);
15412     }
15413     setReprocCount();
15414     LOGH("Manual capture mode - %d", m_ManualCaptureMode);
15415     return rc;
15416 }
15417 
15418 /*===========================================================================
15419  * FUNCTION   : isReprocScaleEnabled
15420  *
15421  * DESCRIPTION: Whether reprocess scale is enabled or not
15422  *
15423  * PARAMETERS : none
15424  *
15425  * RETURN     : TRUE  : Reprocess scale is enabled
15426  *              FALSE : Reprocess scale is not enabled
15427  *==========================================================================*/
isReprocScaleEnabled()15428 bool QCameraParameters::isReprocScaleEnabled()
15429 {
15430     return m_reprocScaleParam.isScaleEnabled();
15431 }
15432 
15433 /*===========================================================================
15434  * FUNCTION   : isUnderReprocScaling
15435  *
15436  * DESCRIPTION: Whether image is under reprocess scaling
15437  *
15438  * PARAMETERS : none
15439  *
15440  * RETURN     : TRUE  : Image is under reprocess scaling
15441  *              FALSE : Image is not under reprocess scaling
15442  *==========================================================================*/
isUnderReprocScaling()15443 bool QCameraParameters::isUnderReprocScaling()
15444 {
15445     return m_reprocScaleParam.isUnderScaling();
15446 }
15447 
15448 /*===========================================================================
15449  * FUNCTION   : getPicSizeFromAPK
15450  *
15451  * DESCRIPTION: Get picture size set from application.
15452  *
15453  * PARAMETERS :
15454  *   @width   : with set by application
15455  *   @height  : height set by application
15456  *
15457  * RETURN     : int32_t type of status
15458  *              NO_ERROR  -- success
15459  *              none-zero failure code
15460  *==========================================================================*/
getPicSizeFromAPK(int & width,int & height)15461 int32_t QCameraParameters::getPicSizeFromAPK(int &width, int &height)
15462 {
15463     return m_reprocScaleParam.getPicSizeFromAPK(width, height);
15464 }
15465 
15466 /*===========================================================================
15467  * FUNCTION   : setDualLedCalibration
15468  *
15469  * DESCRIPTION: set dual led calibration
15470  *
15471  * PARAMETERS :
15472  *   @params  : user setting parameters
15473  *
15474  * RETURN     : int32_t type of status
15475  *              NO_ERROR  -- success
15476  *              none-zero failure code
15477  *==========================================================================*/
setDualLedCalibration(const QCameraParameters & params)15478 int32_t QCameraParameters::setDualLedCalibration(const QCameraParameters& params)
15479 {
15480     const char *str = params.get(KEY_QC_LED_CALIBRATION);
15481     const char *prev_str = get(KEY_QC_LED_CALIBRATION);
15482     char prop[PROPERTY_VALUE_MAX];
15483 
15484     property_get("persist.camera.dualled_calib", prop, "");
15485     if (strlen(prop) > 0) {
15486         if (prev_str == NULL || strcmp(prop, prev_str) != 0) {
15487             return setDualLedCalibration(prop);
15488         }
15489     } else if (str != NULL) {
15490         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
15491             return setDualLedCalibration(str);
15492         }
15493     }
15494     return NO_ERROR;
15495 }
15496 
15497 /*===========================================================================
15498  * FUNCTION   : setDualLedCalibration
15499  *
15500  * DESCRIPTION: set Dual Led Calibration
15501  *
15502  * PARAMETERS :
15503  *   @calibration_mode : calibration enable string
15504  *
15505  * RETURN     : int32_t type of status
15506  *              NO_ERROR  -- success
15507  *              none-zero failure code
15508  *==========================================================================*/
setDualLedCalibration(const char * str)15509 int32_t QCameraParameters::setDualLedCalibration(const char *str)
15510 {
15511     if (str != NULL) {
15512         int32_t value = lookupAttr(ON_OFF_MODES_MAP,
15513             PARAM_MAP_SIZE(ON_OFF_MODES_MAP), str);
15514         if (value != NAME_NOT_FOUND) {
15515             LOGD("Setting led calibration mode %d", value);
15516             updateParamEntry(KEY_QC_LED_CALIBRATION, str);
15517 
15518             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
15519                     CAM_INTF_PARM_DUAL_LED_CALIBRATION, value)) {
15520                 LOGE("Failed to update led calibration param");
15521                 return BAD_VALUE;
15522             }
15523             m_dualLedCalibration = value;
15524             return NO_ERROR;
15525         }
15526     }
15527     LOGE("Invalid Calibraon Mode value: %s",
15528             (str == NULL) ? "NULL" : str);
15529     return BAD_VALUE;
15530 }
15531 
15532 /*===========================================================================
15533  * FUNCTION   : setinstantAEC
15534  *
15535  * DESCRIPTION: set instant AEC value to backend
15536  *
15537  * PARAMETERS :
15538  *   @value : instant aec enabled or not.
15539  *            0 - disable
15540  *            1 - Enable and set agressive AEC algo to the backend
15541  *            2 - Enable and set fast AEC algo to the backend
15542  *
15543  * RETURN     : int32_t type of status
15544  *              NO_ERROR  -- success
15545  *              none-zero failure code
15546  *==========================================================================*/
setInstantAEC(uint8_t value,bool initCommit)15547 int32_t QCameraParameters::setInstantAEC(uint8_t value, bool initCommit)
15548 {
15549     if (initCommit) {
15550         if (initBatchUpdate() < 0) {
15551             LOGE("Failed to initialize group update table");
15552             return FAILED_TRANSACTION;
15553         }
15554     }
15555 
15556     int32_t rc = NO_ERROR;
15557     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_INSTANT_AEC, value)) {
15558         LOGE("Failed to instant aec value");
15559         return BAD_VALUE;
15560     }
15561 
15562     if (initCommit) {
15563         rc = commitSetBatch();
15564         if (NO_ERROR != rc) {
15565             LOGE("Failed to instant aec value");
15566             return rc;
15567         }
15568     }
15569 
15570     LOGD(" Instant AEC value set to backend %d", value);
15571     m_bInstantAEC = value;
15572     return rc;
15573 }
15574 
15575 /*===========================================================================
15576  * FUNCTION   : setAdvancedCaptureMode
15577  *
15578  * DESCRIPTION: set advanced capture mode
15579  *
15580  * PARAMETERS : none
15581  *
15582  * RETURN     : int32_t type of status
15583  *              NO_ERROR  -- success
15584  *              none-zero failure code
15585  *==========================================================================*/
setAdvancedCaptureMode()15586 int32_t QCameraParameters::setAdvancedCaptureMode()
15587 {
15588     uint8_t value = isAdvCamFeaturesEnabled();
15589     LOGD("updating advanced capture mode value to %d",value);
15590     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
15591             CAM_INTF_PARM_ADV_CAPTURE_MODE, value)) {
15592         LOGE("Failed to set advanced capture mode param");
15593         return BAD_VALUE;
15594     }
15595     return NO_ERROR;
15596 }
15597 
15598 /*===========================================================================
15599  * FUNCTION   : getAnalysisInfo
15600  *
15601  * DESCRIPTION: Get the Analysis information based on
15602  *     current mode and feature mask
15603  *
15604  * PARAMETERS :
15605  *   @fdVideoEnabled : Whether fdVideo enabled currently
15606  *   @videoEnabled   : Whether hal3 or hal1
15607  *   @featureMask    : Feature mask
15608  *   @analysis_info  : Analysis info to be filled
15609  *
15610  * RETURN     : int32_t type of status
15611  *              NO_ERROR  -- success
15612  *              none-zero failure code
15613  *==========================================================================*/
getAnalysisInfo(bool fdVideoEnabled,cam_feature_mask_t featureMask,cam_analysis_info_t * pAnalysisInfo)15614 int32_t QCameraParameters::getAnalysisInfo(
15615         bool fdVideoEnabled,
15616         cam_feature_mask_t featureMask,
15617         cam_analysis_info_t *pAnalysisInfo)
15618 {
15619     return mCommon.getAnalysisInfo(fdVideoEnabled, featureMask, pAnalysisInfo);
15620 }
15621 
15622 /*===========================================================================
15623  * FUNCTION   : getMetaRawInfo
15624  *
15625  * DESCRIPTION: fetch meta raw dimension
15626  *
15627  * PARAMETERS :
15628  *   @dim  : get dimension for meta raw stream
15629  *
15630  * RETURN     : int32_t type of status
15631  *              NO_ERROR  -- success
15632  *              none-zero failure code
15633  *==========================================================================*/
getMetaRawInfo()15634 int32_t QCameraParameters::getMetaRawInfo()
15635 {
15636     int32_t rc = NO_ERROR;
15637     cam_dimension_t meta_stream_size;
15638 
15639     if(initBatchUpdate() < 0 ) {
15640         LOGE("Failed to initialize group update table");
15641         return BAD_TYPE;
15642     }
15643 
15644     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
15645             CAM_INTF_META_RAW);
15646 
15647     rc = commitGetBatch();
15648     if (rc != NO_ERROR) {
15649         LOGE("Failed to get extened RAW info");
15650         return rc;
15651     }
15652 
15653     READ_PARAM_ENTRY(m_pParamBuf,
15654             CAM_INTF_META_RAW, meta_stream_size);
15655 
15656     if (meta_stream_size.width == 0 || meta_stream_size.height == 0) {
15657         LOGE("Error getting RAW size. Setting to Capability value");
15658         meta_stream_size = m_pCapability->raw_meta_dim[0];
15659     }
15660     LOGH("RAW meta size. width =%d height =%d",
15661       meta_stream_size.width, meta_stream_size.height);
15662 
15663     setRawSize(meta_stream_size);
15664     m_bMetaRawEnabled = true;
15665     return rc;
15666 }
15667 /*===========================================================================
15668  * FUNCTION   : sendStreamConfigForPickRes
15669  *
15670  * DESCRIPTION: send Stream config info.
15671  *
15672  * PARAMETERS :
15673  *   @stream_config_info: Stream config information
15674  * RETURN     : int32_t type of status
15675  *              NO_ERROR  -- success
15676  *              none-zero failure code
15677  *==========================================================================*/
sendStreamConfigForPickRes(cam_stream_size_info_t & stream_config_info)15678 bool QCameraParameters::sendStreamConfigForPickRes
15679     (cam_stream_size_info_t &stream_config_info) {
15680     int32_t rc = NO_ERROR;
15681     if(initBatchUpdate() < 0 ) {
15682         LOGE("Failed to initialize group update table");
15683         return BAD_TYPE;
15684     }
15685 
15686     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
15687             CAM_INTF_META_STREAM_INFO_FOR_PIC_RES, stream_config_info)) {
15688         LOGE("%s:Failed to update table");
15689         return BAD_VALUE;
15690     }
15691 
15692     rc = commitSetBatch();
15693     if (rc != NO_ERROR) {
15694         LOGE("Failed to set stream info parm");
15695         return rc;
15696     }
15697     return rc;
15698 }
15699 
15700 /*===========================================================================
15701  * FUNCTION   : updateDtVc
15702  *
15703  * DESCRIPTION: Update DT and Vc from capabilities
15704  *
15705  * PARAMETERS :
15706  *
15707  * RETURN     : int32_t type of status
15708  *              NO_ERROR  -- success
15709  *              none-zero failure code
15710  *==========================================================================*/
updateDtVc(int32_t * dt,int32_t * vc)15711 int32_t QCameraParameters::updateDtVc(int32_t *dt, int32_t *vc)
15712 {
15713     int32_t rc = NO_ERROR;
15714     char prop[PROPERTY_VALUE_MAX];
15715 
15716     int dt_val = 0;
15717     int vc_val = 0;
15718 
15719     /* Setting Dt from setprop or capability */
15720     property_get("persist.camera.dt", prop, "0");
15721     dt_val = atoi(prop);
15722     if (dt_val == 0) {
15723         dt_val = m_pCapability->dt[0];
15724     }
15725     *dt = dt_val;
15726 
15727     /*Setting vc from setprop or capability */
15728     property_get("persist.camera.vc", prop, "-1");
15729     vc_val = atoi(prop);
15730     if (vc_val== -1) {
15731         vc_val = m_pCapability->vc[0];
15732     }
15733     *vc = vc_val;
15734 
15735     LOGH("dt=%d vc=%d",*dt, *vc);
15736     return rc;
15737 }
15738 /*===========================================================================
15739  * FUNCTION   : isLinkPreviewForLiveShot()
15740  *
15741  * DESCRIPTION: Function to check whether link preview for liveshot or not
15742  *
15743  * PARAMETERS : none
15744  *
15745  * RETURN     : true: Thumbnail is generated from Preview stream
15746  *              false: Thumbnail is generated from main image
15747  *==========================================================================*/
isLinkPreviewForLiveShot()15748 bool QCameraParameters::isLinkPreviewForLiveShot()
15749 {
15750 
15751    char prop[PROPERTY_VALUE_MAX];
15752 
15753    memset(prop, 0, sizeof(prop));
15754    // 0. Thumbnail is generated from main image  (or)
15755    // 1. Thumbnail is generated from Preview stream
15756    property_get("persist.camera.linkpreview", prop, "1");
15757    bool enable = atoi(prop) > 0 ? TRUE : FALSE;
15758 
15759    LOGD("Link preview for thumbnail %d", enable);
15760    return enable;
15761 }
15762 
15763 /*===========================================================================
15764  * FUNCTION   : SetDualCamera
15765  *
15766  * DESCRIPTION: set Dual Camera
15767  *
15768  * PARAMETERS : bool dual camera value
15769  *
15770  * RETURN     : NO_ERROR  -- success
15771  *              none-zero failure code
15772  *==========================================================================*/
SetDualCamera(bool value)15773 int32_t QCameraParameters::SetDualCamera(bool value)
15774 {
15775     LOGD("value = %d", value);
15776     m_bDualCamera = value;
15777     return NO_ERROR;
15778 }
15779 
15780 /*===========================================================================
15781  * FUNCTION   : setSwitchCamera
15782  *
15783  * DESCRIPTION: Trigger event to inform about camera role switch
15784  *
15785  * PARAMETERS :
15786  *         @camMaster : Master camera
15787  *
15788  * RETURN     : NO_ERROR  -- success
15789  *              none-zero failure code
15790  *==========================================================================*/
setSwitchCamera(uint32_t camMaster)15791 int32_t QCameraParameters::setSwitchCamera(uint32_t camMaster)
15792 {
15793     int32_t rc = NO_ERROR;
15794     cam_dual_camera_master_info_t camState[MM_CAMERA_MAX_CAM_CNT];
15795     uint8_t num_cam = 0;
15796 
15797     if (camMaster == MM_CAMERA_TYPE_MAIN) {
15798         camState[0].mode = CAM_MODE_PRIMARY;
15799         camState[1].mode = CAM_MODE_SECONDARY;
15800     } else if (camMaster == MM_CAMERA_TYPE_AUX) {
15801         camState[0].mode = CAM_MODE_SECONDARY;
15802         camState[1].mode = CAM_MODE_PRIMARY;
15803     } else {
15804         LOGW("Invalid master camera info");
15805         return rc;
15806     }
15807 
15808     // Update master camera
15809     mMasterCamera = camMaster;
15810 
15811     num_cam = MM_CAMERA_MAX_CAM_CNT;
15812     rc = sendDualCamCmd(CAM_DUAL_CAMERA_MASTER_INFO,
15813               num_cam, &camState[0]);
15814     return rc;
15815 }
15816 
15817 /*===========================================================================
15818  * FUNCTION   : setDeferCamera
15819  *
15820  * DESCRIPTION: configure camera in background for KPI in dual camera
15821  *
15822  * PARAMETERS :
15823  *         @type : Type of defer command
15824  *
15825  * RETURN     : NO_ERROR  -- success
15826  *              none-zero failure code
15827  *==========================================================================*/
setDeferCamera(cam_dual_camera_defer_cmd_t type)15828 int32_t QCameraParameters::setDeferCamera(cam_dual_camera_defer_cmd_t type)
15829 {
15830     int32_t rc = NO_ERROR;
15831     char prop[PROPERTY_VALUE_MAX];
15832     int value = 0;
15833 
15834     property_get("persist.dualcam.defer.cam", prop, "1");
15835     value = atoi(prop);
15836 
15837     cam_dual_camera_defer_cmd_t defer_val[MM_CAMERA_MAX_CAM_CNT];
15838     memset(&defer_val[0], 0, sizeof(defer_val));
15839 
15840     if (value >= 0 && value < MM_CAMERA_MAX_CAM_CNT) {
15841         defer_val[value] = type;
15842     }
15843     sendDualCamCmd(CAM_DUAL_CAMERA_DEFER_INFO,MM_CAMERA_MAX_CAM_CNT,
15844             &defer_val[0]);
15845     return rc;
15846 }
15847 
15848 /*===========================================================================
15849  * FUNCTION   : getLowPowerMode
15850  *
15851  * DESCRIPTION: Get Low Power Mode for the given camera
15852  *
15853  * PARAMETERS :
15854  * @cam       : Camera type for which Low Power Mode is queried
15855  *
15856  * RETURN     : Low Power Mode with type cam_dual_camera_perf_mode_t
15857  *==========================================================================*/
getLowPowerMode(cam_sync_type_t cam)15858 cam_dual_camera_perf_mode_t QCameraParameters::getLowPowerMode(cam_sync_type_t cam)
15859 {
15860     char prop[PROPERTY_VALUE_MAX];
15861     int32_t lpm = 0;
15862     int32_t lpmConfig = 0;
15863 
15864     if (cam == CAM_TYPE_MAIN) {
15865         property_get("persist.dualcam.lpm.main", prop, "0");
15866         lpm = atoi(prop);
15867         lpmConfig = DUALCAM_LPM_MAIN;
15868     } else if (cam == CAM_TYPE_AUX) {
15869         property_get("persist.dualcam.lpm.aux", prop, "0");
15870         lpm = atoi(prop);
15871         lpmConfig = DUALCAM_LPM_AUX;
15872     } else {
15873         LOGE("Invalid camera type queried for LPM");
15874         return CAM_PERF_NONE;
15875     }
15876 
15877     if (lpm == 0) {
15878         switch(lpmConfig) {
15879             case SENSOR_SLEEP:
15880                 lpm = CAM_PERF_SENSOR_SUSPEND;
15881                 break;
15882             case ISPIF_FRAME_DROP:
15883                 lpm = CAM_PERF_ISPIF_FRAME_DROP;
15884                 break;
15885             case NONE:
15886             default:
15887                 lpm = CAM_PERF_NONE;
15888                 break;
15889         }
15890     }
15891     LOGD("LPM for %s camera: %d", cam == CAM_TYPE_MAIN ? "main" : "aux", lpm);
15892     return (cam_dual_camera_perf_mode_t)lpm;
15893 }
15894 
15895 
15896 /*===========================================================================
15897  * FUNCTION   : setCameraControls
15898  *
15899  * DESCRIPTION: activate or deactive camera's
15900  *
15901  * PARAMETERS :
15902  *         @controls : Flag with camera bit field set in case of dual camera
15903  *
15904  * RETURN     : NO_ERROR  -- success
15905  *              none-zero failure code
15906  *==========================================================================*/
setCameraControls(int32_t state)15907 int32_t QCameraParameters::setCameraControls(int32_t state)
15908 {
15909     int32_t rc = NO_ERROR;
15910     int32_t cameraControl[MM_CAMERA_MAX_CAM_CNT] = {0};
15911     char prop[PROPERTY_VALUE_MAX];
15912     int lpmEnable = 1;
15913     cam_dual_camera_perf_mode_t lpmMain = CAM_PERF_NONE;
15914     cam_dual_camera_perf_mode_t lpmAux  = CAM_PERF_NONE;
15915 
15916     cam_dual_camera_perf_control_t perf_value[MM_CAMERA_MAX_CAM_CNT];
15917     uint8_t num_cam = 0;
15918 
15919     lpmMain = getLowPowerMode(CAM_TYPE_MAIN);
15920     lpmAux  = getLowPowerMode(CAM_TYPE_AUX);
15921 
15922     // Keep the camera active if indicated by the active state or if LPM is NONE
15923     if ((state & MM_CAMERA_TYPE_MAIN) ||
15924             (lpmMain == CAM_PERF_NONE)) {
15925         cameraControl[0] = 1;
15926     } else {
15927         cameraControl[0] = 0;
15928     }
15929 
15930     // Keep the camera active if indicated by the active state or if LPM is NONE
15931     if ((state & MM_CAMERA_TYPE_AUX)  ||
15932             (lpmAux == CAM_PERF_NONE)) {
15933         cameraControl[1] = 1;
15934     } else {
15935         cameraControl[1] = 0;
15936     }
15937 
15938     perf_value[num_cam].perf_mode = lpmMain;
15939     perf_value[num_cam].enable = cameraControl[0] ? 0 : 1;
15940     perf_value[num_cam].priority = 0;
15941     num_cam++;
15942     perf_value[num_cam].perf_mode = lpmAux;
15943     perf_value[num_cam].enable = cameraControl[1] ? 0 : 1;
15944     perf_value[num_cam].priority = 0;
15945     num_cam++;
15946 
15947     // LPM is enabled by default.
15948     // It can disabled at the compile time using DUALCAM_LPM_ENABLE from QCameraDualCamSettings.h
15949     // It can be disabled dynamically using the setprop persist.dualcam.lpm.enable.
15950     property_get("persist.dualcam.lpm.enable", prop, "1");
15951     lpmEnable = atoi(prop);
15952 
15953     if (DUALCAM_LPM_ENABLE == 0) {
15954         lpmEnable = 0;
15955     }
15956 
15957     if (lpmEnable == 0) {
15958         LOGD("Dual camera: Low Power Mode disabled");
15959         for (int i = 0; i < num_cam; ++i) {
15960             perf_value[i].enable = 0;
15961         }
15962     }
15963 
15964     rc = sendDualCamCmd(CAM_DUAL_CAMERA_LOW_POWER_MODE,
15965           num_cam, &perf_value[0]);
15966 
15967     mActiveCameras = state;
15968 
15969     return rc;
15970 }
15971 
15972 /*===========================================================================
15973  * FUNCTION   : setAsymmetricSnapMode
15974  *
15975  * DESCRIPTION: Function to detect Asymmetric Snapshot mode
15976  *
15977  * PARAMETERS :
15978  *
15979  * RETURN     :
15980  *==========================================================================*/
setAsymmetricSnapMode()15981 void QCameraParameters::setAsymmetricSnapMode()
15982 {
15983     int width, height, maxWidth, maxHeight;
15984 
15985     if (!isDualCamera()) {
15986         mAsymmetricSnapMode = false;
15987         return;
15988     }
15989 
15990     getPictureSize(&width, &height);
15991     maxWidth = m_pCapability->main_cam_cap->picture_sizes_tbl[0].width;
15992     maxHeight = m_pCapability->main_cam_cap->picture_sizes_tbl[0].height;
15993 
15994     if ((maxWidth * maxHeight) < (width * height)) {
15995         mAsymmetricSnapMode = true;
15996         return;
15997     }
15998 
15999     maxWidth = m_pCapability->aux_cam_cap->picture_sizes_tbl[0].width;
16000     maxHeight = m_pCapability->aux_cam_cap->picture_sizes_tbl[0].height;
16001     if ((maxWidth * maxHeight) < (width * height)) {
16002         mAsymmetricSnapMode = true;
16003         return;
16004     }
16005     mAsymmetricSnapMode = false;
16006 }
16007 
16008 }; // namespace qcamera
16009