QCameraParameters.cpp revision cbc47426e57bd30f5a00ec92e166f6e2681ecd4c
1/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 *     * Redistributions of source code must retain the above copyright
7 *       notice, this list of conditions and the following disclaimer.
8 *     * Redistributions in binary form must reproduce the above
9 *       copyright notice, this list of conditions and the following
10 *       disclaimer in the documentation and/or other materials provided
11 *       with the distribution.
12 *     * Neither the name of The Linux Foundation nor the names of its
13 *       contributors may be used to endorse or promote products derived
14 *       from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#define LOG_TAG "QCameraParameters"
31
32#include <cutils/properties.h>
33#include <math.h>
34#include <utils/Errors.h>
35#include <string.h>
36#include <stdlib.h>
37#include <gralloc_priv.h>
38#include "QCamera2HWI.h"
39#include "QCameraParameters.h"
40
41#define ASPECT_TOLERANCE 0.001
42#define FLIP_V_H (FLIP_H | FLIP_V)
43
44namespace qcamera {
45// Parameter keys to communicate between camera application and driver.
46const char QCameraParameters::KEY_QC_SUPPORTED_HFR_SIZES[] = "hfr-size-values";
47const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_MODE[] = "preview-frame-rate-mode";
48const char QCameraParameters::KEY_QC_SUPPORTED_PREVIEW_FRAME_RATE_MODES[] = "preview-frame-rate-modes";
49const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_AUTO_MODE[] = "frame-rate-auto";
50const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_FIXED_MODE[] = "frame-rate-fixed";
51const char QCameraParameters::KEY_QC_TOUCH_AF_AEC[] = "touch-af-aec";
52const char QCameraParameters::KEY_QC_SUPPORTED_TOUCH_AF_AEC[] = "touch-af-aec-values";
53const char QCameraParameters::KEY_QC_TOUCH_INDEX_AEC[] = "touch-index-aec";
54const char QCameraParameters::KEY_QC_TOUCH_INDEX_AF[] = "touch-index-af";
55const char QCameraParameters::KEY_QC_SCENE_DETECT[] = "scene-detect";
56const char QCameraParameters::KEY_QC_SUPPORTED_SCENE_DETECT[] = "scene-detect-values";
57const char QCameraParameters::KEY_QC_ISO_MODE[] = "iso";
58const char QCameraParameters::KEY_QC_SUPPORTED_ISO_MODES[] = "iso-values";
59const char QCameraParameters::KEY_QC_LENSSHADE[] = "lensshade";
60const char QCameraParameters::KEY_QC_SUPPORTED_LENSSHADE_MODES[] = "lensshade-values";
61const char QCameraParameters::KEY_QC_AUTO_EXPOSURE[] = "auto-exposure";
62const char QCameraParameters::KEY_QC_SUPPORTED_AUTO_EXPOSURE[] = "auto-exposure-values";
63const char QCameraParameters::KEY_QC_DENOISE[] = "denoise";
64const char QCameraParameters::KEY_QC_SUPPORTED_DENOISE[] = "denoise-values";
65const char QCameraParameters::KEY_QC_FOCUS_ALGO[] = "selectable-zone-af";
66const char QCameraParameters::KEY_QC_SUPPORTED_FOCUS_ALGOS[] = "selectable-zone-af-values";
67const char QCameraParameters::KEY_QC_FACE_DETECTION[] = "face-detection";
68const char QCameraParameters::KEY_QC_SUPPORTED_FACE_DETECTION[] = "face-detection-values";
69const char QCameraParameters::KEY_QC_FACE_RECOGNITION[] = "face-recognition";
70const char QCameraParameters::KEY_QC_SUPPORTED_FACE_RECOGNITION[] = "face-recognition-values";
71const char QCameraParameters::KEY_QC_MEMORY_COLOR_ENHANCEMENT[] = "mce";
72const char QCameraParameters::KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES[] = "mce-values";
73const char QCameraParameters::KEY_QC_DIS[] = "dis";
74const char QCameraParameters::KEY_QC_SUPPORTED_DIS_MODES[] = "dis-values";
75const char QCameraParameters::KEY_QC_VIDEO_HIGH_FRAME_RATE[] = "video-hfr";
76const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES[] = "video-hfr-values";
77const char QCameraParameters::KEY_QC_REDEYE_REDUCTION[] = "redeye-reduction";
78const char QCameraParameters::KEY_QC_SUPPORTED_REDEYE_REDUCTION[] = "redeye-reduction-values";
79const char QCameraParameters::KEY_QC_HIGH_DYNAMIC_RANGE_IMAGING[] = "hdr";
80const char QCameraParameters::KEY_QC_SUPPORTED_HDR_IMAGING_MODES[] = "hdr-values";
81const char QCameraParameters::KEY_QC_ZSL[] = "zsl";
82const char QCameraParameters::KEY_QC_SUPPORTED_ZSL_MODES[] = "zsl-values";
83const char QCameraParameters::KEY_QC_ZSL_BURST_INTERVAL[] = "capture-burst-interval";
84const char QCameraParameters::KEY_QC_ZSL_BURST_LOOKBACK[] = "capture-burst-retroactive";
85const char QCameraParameters::KEY_QC_ZSL_QUEUE_DEPTH[] = "capture-burst-queue-depth";
86const char QCameraParameters::KEY_QC_CAMERA_MODE[] = "camera-mode";
87const char QCameraParameters::KEY_QC_AE_BRACKET_HDR[] = "ae-bracket-hdr";
88const char QCameraParameters::KEY_QC_SUPPORTED_AE_BRACKET_MODES[] = "ae-bracket-hdr-values";
89const char QCameraParameters::KEY_QC_SUPPORTED_RAW_FORMATS[] = "raw-format-values";
90const char QCameraParameters::KEY_QC_RAW_FORMAT[] = "raw-format";
91const char QCameraParameters::KEY_QC_ORIENTATION[] = "orientation";
92const char QCameraParameters::KEY_QC_SELECTABLE_ZONE_AF[] = "selectable-zone-af";
93const char QCameraParameters::KEY_QC_CAPTURE_BURST_EXPOSURE[] = "capture-burst-exposures";
94const char QCameraParameters::KEY_QC_NUM_SNAPSHOT_PER_SHUTTER[] = "num-snaps-per-shutter";
95const char QCameraParameters::KEY_QC_NO_DISPLAY_MODE[] = "no-display-mode";
96const char QCameraParameters::KEY_QC_RAW_PICUTRE_SIZE[] = "raw-size";
97const char QCameraParameters::KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES[] = "skinToneEnhancement-values";
98const char QCameraParameters::KEY_QC_SUPPORTED_LIVESNAPSHOT_SIZES[] = "supported-live-snapshot-sizes";
99const char QCameraParameters::KEY_QC_HDR_NEED_1X[] = "hdr-need-1x";
100const char QCameraParameters::KEY_QC_PREVIEW_FLIP[] = "preview-flip";
101const char QCameraParameters::KEY_QC_VIDEO_FLIP[] = "video-flip";
102const char QCameraParameters::KEY_QC_SNAPSHOT_PICTURE_FLIP[] = "snapshot-picture-flip";
103const char QCameraParameters::KEY_QC_SUPPORTED_FLIP_MODES[] = "flip-mode-values";
104const char QCameraParameters::KEY_QC_VIDEO_HDR[] = "video-hdr";
105const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_HDR_MODES[] = "video-hdr-values";
106
107// Values for effect settings.
108const char QCameraParameters::EFFECT_EMBOSS[] = "emboss";
109const char QCameraParameters::EFFECT_SKETCH[] = "sketch";
110const char QCameraParameters::EFFECT_NEON[] = "neon";
111
112// Values for auto exposure settings.
113const char QCameraParameters::TOUCH_AF_AEC_OFF[] = "touch-off";
114const char QCameraParameters::TOUCH_AF_AEC_ON[] = "touch-on";
115
116// Values for scene mode settings.
117const char QCameraParameters::SCENE_MODE_ASD[] = "asd";   // corresponds to CAMERA_BESTSHOT_AUTO in HAL
118const char QCameraParameters::SCENE_MODE_BACKLIGHT[] = "backlight";
119const char QCameraParameters::SCENE_MODE_FLOWERS[] = "flowers";
120const char QCameraParameters::SCENE_MODE_AR[] = "AR";
121const char QCameraParameters::SCENE_MODE_HDR[] = "hdr";
122
123// Formats for setPreviewFormat and setPictureFormat.
124const char QCameraParameters::PIXEL_FORMAT_YUV420SP_ADRENO[] = "yuv420sp-adreno";
125const char QCameraParameters::PIXEL_FORMAT_YV12[] = "yuv420p";
126const char QCameraParameters::PIXEL_FORMAT_NV12[] = "nv12";
127
128// Values for raw image formats
129const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_YUYV[] = "yuv-raw8-yuyv";
130const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_YVYU[] = "yuv-raw8-yvyu";
131const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_UYVY[] = "yuv-raw8-uyvy";
132const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_VYUY[] = "yuv-raw8-vyuy";
133const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GBRG[] = "bayer-qcom-8gbrg";
134const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GRBG[] = "bayer-qcom-8grbg";
135const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8RGGB[] = "bayer-qcom-8rggb";
136const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8BGGR[] = "bayer-qcom-8bggr";
137const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GBRG[] = "bayer-qcom-10gbrg";
138const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GRBG[] = "bayer-qcom-10grbg";
139const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10RGGB[] = "bayer-qcom-10rggb";
140const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10BGGR[] = "bayer-qcom-10bggr";
141const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GBRG[] = "bayer-qcom-12gbrg";
142const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GRBG[] = "bayer-qcom-12grbg";
143const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12RGGB[] = "bayer-qcom-12rggb";
144const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12BGGR[] = "bayer-qcom-12bggr";
145const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GBRG[] = "bayer-mipi-8gbrg";
146const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GRBG[] = "bayer-mipi-8grbg";
147const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8RGGB[] = "bayer-mipi-8rggb";
148const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8BGGR[] = "bayer-mipi-8bggr";
149const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GBRG[] = "bayer-mipi-10gbrg";
150const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GRBG[] = "bayer-mipi-10grbg";
151const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10RGGB[] = "bayer-mipi-10rggb";
152const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10BGGR[] = "bayer-mipi-10bggr";
153const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GBRG[] = "bayer-mipi-12gbrg";
154const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GRBG[] = "bayer-mipi-12grbg";
155const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12RGGB[] = "bayer-mipi-12rggb";
156const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12BGGR[] = "bayer-mipi-12bggr";
157const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GBRG[] = "bayer-ideal-qcom-8gbrg";
158const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GRBG[] = "bayer-ideal-qcom-8grbg";
159const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8RGGB[] = "bayer-ideal-qcom-8rggb";
160const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8BGGR[] = "bayer-ideal-qcom-8bggr";
161const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GBRG[] = "bayer-ideal-qcom-10gbrg";
162const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GRBG[] = "bayer-ideal-qcom-10grbg";
163const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10RGGB[] = "bayer-ideal-qcom-10rggb";
164const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10BGGR[] = "bayer-ideal-qcom-10bggr";
165const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GBRG[] = "bayer-ideal-qcom-12gbrg";
166const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GRBG[] = "bayer-ideal-qcom-12grbg";
167const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12RGGB[] = "bayer-ideal-qcom-12rggb";
168const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12BGGR[] = "bayer-ideal-qcom-12bggr";
169const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GBRG[] = "bayer-ideal-mipi-8gbrg";
170const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GRBG[] = "bayer-ideal-mipi-8grbg";
171const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8RGGB[] = "bayer-ideal-mipi-8rggb";
172const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8BGGR[] = "bayer-ideal-mipi-8bggr";
173const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GBRG[] = "bayer-ideal-mipi-10gbrg";
174const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GRBG[] = "bayer-ideal-mipi-10grbg";
175const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10RGGB[] = "bayer-ideal-mipi-10rggb";
176const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10BGGR[] = "bayer-ideal-mipi-10bggr";
177const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GBRG[] = "bayer-ideal-mipi-12gbrg";
178const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GRBG[] = "bayer-ideal-mipi-12grbg";
179const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12RGGB[] = "bayer-ideal-mipi-12rggb";
180const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12BGGR[] = "bayer-ideal-mipi-12bggr";
181const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GBRG[] = "bayer-ideal-plain8-8gbrg";
182const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GRBG[] = "bayer-ideal-plain8-8grbg";
183const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8RGGB[] = "bayer-ideal-plain8-8rggb";
184const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8BGGR[] = "bayer-ideal-plain8-8bggr";
185const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GBRG[] = "bayer-ideal-plain16-8gbrg";
186const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GRBG[] = "bayer-ideal-plain16-8grbg";
187const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8RGGB[] = "bayer-ideal-plain16-8rggb";
188const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8BGGR[] = "bayer-ideal-plain16-8bggr";
189const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GBRG[] = "bayer-ideal-plain16-10gbrg";
190const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GRBG[] = "bayer-ideal-plain16-10grbg";
191const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10RGGB[] = "bayer-ideal-plain16-10rggb";
192const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10BGGR[] = "bayer-ideal-plain16-10bggr";
193const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GBRG[] = "bayer-ideal-plain16-12gbrg";
194const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GRBG[] = "bayer-ideal-plain16-12grbg";
195const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12RGGB[] = "bayer-ideal-plain16-12rggb";
196const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12BGGR[] = "bayer-ideal-plain16-12bggr";
197
198// Values for ISO Settings
199const char QCameraParameters::ISO_AUTO[] = "auto";
200const char QCameraParameters::ISO_HJR[] = "ISO_HJR";
201const char QCameraParameters::ISO_100[] = "ISO100";
202const char QCameraParameters::ISO_200[] = "ISO200";
203const char QCameraParameters::ISO_400[] = "ISO400";
204const char QCameraParameters::ISO_800[] = "ISO800";
205const char QCameraParameters::ISO_1600[] = "ISO1600";
206
207// Values for auto exposure settings.
208const char QCameraParameters::AUTO_EXPOSURE_FRAME_AVG[] = "frame-average";
209const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED[] = "center-weighted";
210const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING[] = "spot-metering";
211const char QCameraParameters::AUTO_EXPOSURE_SMART_METERING[] = "smart-metering";
212const char QCameraParameters::AUTO_EXPOSURE_USER_METERING[] = "user-metering";
213const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING_ADV[] = "spot-metering-adv";
214const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED_ADV[] = "center-weighted-adv";
215
216const char QCameraParameters::KEY_QC_GPS_LATITUDE_REF[] = "gps-latitude-ref";
217const char QCameraParameters::KEY_QC_GPS_LONGITUDE_REF[] = "gps-longitude-ref";
218const char QCameraParameters::KEY_QC_GPS_ALTITUDE_REF[] = "gps-altitude-ref";
219const char QCameraParameters::KEY_QC_GPS_STATUS[] = "gps-status";
220
221const char QCameraParameters::KEY_QC_HISTOGRAM[] = "histogram";
222const char QCameraParameters::KEY_QC_SUPPORTED_HISTOGRAM_MODES[] = "histogram-values";
223
224const char QCameraParameters::VALUE_ENABLE[] = "enable";
225const char QCameraParameters::VALUE_DISABLE[] = "disable";
226const char QCameraParameters::VALUE_OFF[] = "off";
227const char QCameraParameters::VALUE_ON[] = "on";
228const char QCameraParameters::VALUE_TRUE[] = "true";
229const char QCameraParameters::VALUE_FALSE[] = "false";
230
231const char QCameraParameters::KEY_QC_SHARPNESS[] = "sharpness";
232const char QCameraParameters::KEY_QC_MIN_SHARPNESS[] = "min-sharpness";
233const char QCameraParameters::KEY_QC_MAX_SHARPNESS[] = "max-sharpness";
234const char QCameraParameters::KEY_QC_SHARPNESS_STEP[] = "sharpness-step";
235const char QCameraParameters::KEY_QC_CONTRAST[] = "contrast";
236const char QCameraParameters::KEY_QC_MIN_CONTRAST[] = "min-contrast";
237const char QCameraParameters::KEY_QC_MAX_CONTRAST[] = "max-contrast";
238const char QCameraParameters::KEY_QC_CONTRAST_STEP[] = "contrast-step";
239const char QCameraParameters::KEY_QC_SATURATION[] = "saturation";
240const char QCameraParameters::KEY_QC_MIN_SATURATION[] = "min-saturation";
241const char QCameraParameters::KEY_QC_MAX_SATURATION[] = "max-saturation";
242const char QCameraParameters::KEY_QC_SATURATION_STEP[] = "saturation-step";
243const char QCameraParameters::KEY_QC_BRIGHTNESS[] = "luma-adaptation";
244const char QCameraParameters::KEY_QC_MIN_BRIGHTNESS[] = "min-brightness";
245const char QCameraParameters::KEY_QC_MAX_BRIGHTNESS[] = "max-brightness";
246const char QCameraParameters::KEY_QC_BRIGHTNESS_STEP[] = "brightness-step";
247const char QCameraParameters::KEY_QC_SCE_FACTOR[] = "skinToneEnhancement";
248const char QCameraParameters::KEY_QC_MIN_SCE_FACTOR[] = "min-sce-factor";
249const char QCameraParameters::KEY_QC_MAX_SCE_FACTOR[] = "max-sce-factor";
250const char QCameraParameters::KEY_QC_SCE_FACTOR_STEP[] = "sce-factor-step";
251
252const char QCameraParameters::KEY_QC_SUPPORTED_CAMERA_FEATURES[] = "qc-camera-features";
253const char QCameraParameters::KEY_QC_MAX_NUM_REQUESTED_FACES[] = "qc-max-num-requested-faces";
254
255//Values for DENOISE
256const char QCameraParameters::DENOISE_OFF[] = "denoise-off";
257const char QCameraParameters::DENOISE_ON[] = "denoise-on";
258
259// Values for selectable zone af Settings
260const char QCameraParameters::FOCUS_ALGO_AUTO[] = "auto";
261const char QCameraParameters::FOCUS_ALGO_SPOT_METERING[] = "spot-metering";
262const char QCameraParameters::FOCUS_ALGO_CENTER_WEIGHTED[] = "center-weighted";
263const char QCameraParameters::FOCUS_ALGO_FRAME_AVERAGE[] = "frame-average";
264
265// Values for HFR settings.
266const char QCameraParameters::VIDEO_HFR_OFF[] = "off";
267const char QCameraParameters::VIDEO_HFR_2X[] = "60";
268const char QCameraParameters::VIDEO_HFR_3X[] = "90";
269const char QCameraParameters::VIDEO_HFR_4X[] = "120";
270const char QCameraParameters::VIDEO_HFR_5X[] = "150";
271
272// Values for HDR Bracketing settings.
273const char QCameraParameters::AE_BRACKET_OFF[] = "Off";
274const char QCameraParameters::AE_BRACKET[] = "AE-Bracket";
275
276// Values for FLIP settings.
277const char QCameraParameters::FLIP_MODE_OFF[] = "off";
278const char QCameraParameters::FLIP_MODE_V[] = "flip-v";
279const char QCameraParameters::FLIP_MODE_H[] = "flip-h";
280const char QCameraParameters::FLIP_MODE_VH[] = "flip-vh";
281
282static const char* portrait = "portrait";
283static const char* landscape = "landscape";
284
285const cam_dimension_t QCameraParameters::THUMBNAIL_SIZES_MAP[] = {
286    { 512, 288 }, //1.777778
287    { 480, 288 }, //1.666667
288    { 256, 154 }, //1.66233
289    { 432, 288 }, //1.5
290    { 320, 240 }, //1.33333
291    { 176, 144 }, //1.222222
292    { 0, 0 }      // required by Android SDK
293};
294
295const QCameraParameters::QCameraMap QCameraParameters::AUTO_EXPOSURE_MAP[] = {
296    { AUTO_EXPOSURE_FRAME_AVG,           CAM_AEC_MODE_FRAME_AVERAGE },
297    { AUTO_EXPOSURE_CENTER_WEIGHTED,     CAM_AEC_MODE_CENTER_WEIGHTED },
298    { AUTO_EXPOSURE_SPOT_METERING,       CAM_AEC_MODE_SPOT_METERING },
299    { AUTO_EXPOSURE_SMART_METERING,      CAM_AEC_MODE_SMART_METERING },
300    { AUTO_EXPOSURE_USER_METERING,       CAM_AEC_MODE_USER_METERING },
301    { AUTO_EXPOSURE_SPOT_METERING_ADV,   CAM_AEC_MODE_SPOT_METERING_ADV },
302    { AUTO_EXPOSURE_CENTER_WEIGHTED_ADV, CAM_AEC_MODE_CENTER_WEIGHTED_ADV },
303};
304
305const QCameraParameters::QCameraMap QCameraParameters::PREVIEW_FORMATS_MAP[] = {
306    {PIXEL_FORMAT_YUV420SP,        CAM_FORMAT_YUV_420_NV21},
307    {PIXEL_FORMAT_YUV420P,         CAM_FORMAT_YUV_420_YV12},
308    {PIXEL_FORMAT_YUV420SP_ADRENO, CAM_FORMAT_YUV_420_NV21_ADRENO},
309    {PIXEL_FORMAT_YV12,            CAM_FORMAT_YUV_420_YV12},
310    {PIXEL_FORMAT_NV12,            CAM_FORMAT_YUV_420_NV12}
311};
312
313const QCameraParameters::QCameraMap QCameraParameters::PICTURE_TYPES_MAP[] = {
314    {PIXEL_FORMAT_JPEG,                          CAM_FORMAT_JPEG},
315    {PIXEL_FORMAT_YUV422SP,                      CAM_FORMAT_YUV_422_NV16},
316    {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YUYV,          CAM_FORMAT_YUV_RAW_8BIT_YUYV},
317    {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YVYU,          CAM_FORMAT_YUV_RAW_8BIT_YVYU},
318    {QC_PIXEL_FORMAT_YUV_RAW_8BIT_UYVY,          CAM_FORMAT_YUV_RAW_8BIT_UYVY},
319    {QC_PIXEL_FORMAT_YUV_RAW_8BIT_VYUY,          CAM_FORMAT_YUV_RAW_8BIT_VYUY},
320    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GBRG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GBRG},
321    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GRBG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GRBG},
322    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8RGGB,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_RGGB},
323    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8BGGR,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_BGGR},
324    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GBRG},
325    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GRBG},
326    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_RGGB},
327    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_BGGR},
328    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GBRG},
329    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GRBG},
330    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_RGGB},
331    {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_BGGR},
332    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GBRG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GBRG},
333    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GRBG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GRBG},
334    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8RGGB,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_RGGB},
335    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8BGGR,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_BGGR},
336    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GBRG},
337    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GRBG},
338    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_RGGB},
339    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_BGGR},
340    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GBRG},
341    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GRBG},
342    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_RGGB},
343    {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_BGGR},
344    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GBRG},
345    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GRBG},
346    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_RGGB},
347    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_BGGR},
348    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GBRG},
349    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GRBG},
350    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_RGGB},
351    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_BGGR},
352    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GBRG},
353    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GRBG},
354    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_RGGB},
355    {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_BGGR},
356    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GBRG},
357    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GRBG},
358    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_RGGB},
359    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_BGGR},
360    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GBRG},
361    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GRBG},
362    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_RGGB},
363    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_BGGR},
364    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GBRG},
365    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GRBG},
366    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_RGGB},
367    {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_BGGR},
368    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GBRG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GBRG},
369    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GRBG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GRBG},
370    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8RGGB,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_RGGB},
371    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8BGGR,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_BGGR},
372    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GBRG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GBRG},
373    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GRBG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GRBG},
374    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8RGGB,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_RGGB},
375    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8BGGR,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_BGGR},
376    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GBRG},
377    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GRBG},
378    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_RGGB},
379    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_BGGR},
380    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GBRG},
381    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GRBG},
382    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_RGGB},
383    {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_BGGR}
384};
385
386const QCameraParameters::QCameraMap QCameraParameters::RAW_FORMATS_MAP[] = {
387};
388
389const QCameraParameters::QCameraMap QCameraParameters::FOCUS_MODES_MAP[] = {
390    { FOCUS_MODE_AUTO,               CAM_FOCUS_MODE_AUTO },
391    { FOCUS_MODE_INFINITY,           CAM_FOCUS_MODE_INFINITY },
392    { FOCUS_MODE_MACRO,              CAM_FOCUS_MODE_MACRO },
393    { FOCUS_MODE_FIXED,              CAM_FOCUS_MODE_FIXED },
394    { FOCUS_MODE_EDOF,               CAM_FOCUS_MODE_EDOF },
395    { FOCUS_MODE_CONTINUOUS_PICTURE, CAM_FOCUS_MODE_CONTINOUS_PICTURE },
396    { FOCUS_MODE_CONTINUOUS_VIDEO,   CAM_FOCUS_MODE_CONTINOUS_VIDEO }
397};
398
399const QCameraParameters::QCameraMap QCameraParameters::EFFECT_MODES_MAP[] = {
400    { EFFECT_NONE,       CAM_EFFECT_MODE_OFF },
401    { EFFECT_MONO,       CAM_EFFECT_MODE_MONO },
402    { EFFECT_NEGATIVE,   CAM_EFFECT_MODE_NEGATIVE },
403    { EFFECT_SOLARIZE,   CAM_EFFECT_MODE_SOLARIZE },
404    { EFFECT_SEPIA,      CAM_EFFECT_MODE_SEPIA },
405    { EFFECT_POSTERIZE,  CAM_EFFECT_MODE_POSTERIZE },
406    { EFFECT_WHITEBOARD, CAM_EFFECT_MODE_WHITEBOARD },
407    { EFFECT_BLACKBOARD, CAM_EFFECT_MODE_BLACKBOARD },
408    { EFFECT_AQUA,       CAM_EFFECT_MODE_AQUA },
409    { EFFECT_EMBOSS,     CAM_EFFECT_MODE_EMBOSS },
410    { EFFECT_SKETCH,     CAM_EFFECT_MODE_SKETCH },
411    { EFFECT_NEON,       CAM_EFFECT_MODE_NEON }
412};
413
414const QCameraParameters::QCameraMap QCameraParameters::SCENE_MODES_MAP[] = {
415    { SCENE_MODE_AUTO,           CAM_SCENE_MODE_OFF },
416    { SCENE_MODE_ACTION,         CAM_SCENE_MODE_ACTION },
417    { SCENE_MODE_PORTRAIT,       CAM_SCENE_MODE_PORTRAIT },
418    { SCENE_MODE_LANDSCAPE,      CAM_SCENE_MODE_LANDSCAPE },
419    { SCENE_MODE_NIGHT,          CAM_SCENE_MODE_NIGHT },
420    { SCENE_MODE_NIGHT_PORTRAIT, CAM_SCENE_MODE_NIGHT_PORTRAIT },
421    { SCENE_MODE_THEATRE,        CAM_SCENE_MODE_THEATRE },
422    { SCENE_MODE_BEACH,          CAM_SCENE_MODE_BEACH },
423    { SCENE_MODE_SNOW,           CAM_SCENE_MODE_SNOW },
424    { SCENE_MODE_SUNSET,         CAM_SCENE_MODE_SUNSET },
425    { SCENE_MODE_STEADYPHOTO,    CAM_SCENE_MODE_ANTISHAKE },
426    { SCENE_MODE_FIREWORKS ,     CAM_SCENE_MODE_FIREWORKS },
427    { SCENE_MODE_SPORTS ,        CAM_SCENE_MODE_SPORTS },
428    { SCENE_MODE_PARTY,          CAM_SCENE_MODE_PARTY },
429    { SCENE_MODE_CANDLELIGHT,    CAM_SCENE_MODE_CANDLELIGHT },
430    { SCENE_MODE_ASD,            CAM_SCENE_MODE_AUTO },
431    { SCENE_MODE_BACKLIGHT,      CAM_SCENE_MODE_BACKLIGHT },
432    { SCENE_MODE_FLOWERS,        CAM_SCENE_MODE_FLOWERS },
433    { SCENE_MODE_AR,             CAM_SCENE_MODE_AR },
434    { SCENE_MODE_HDR,            CAM_SCENE_MODE_OFF },
435};
436
437const QCameraParameters::QCameraMap QCameraParameters::FLASH_MODES_MAP[] = {
438    { FLASH_MODE_OFF,   CAM_FLASH_MODE_OFF },
439    { FLASH_MODE_AUTO,  CAM_FLASH_MODE_AUTO },
440    { FLASH_MODE_ON,    CAM_FLASH_MODE_ON },
441    { FLASH_MODE_TORCH, CAM_FLASH_MODE_TORCH }
442};
443
444const QCameraParameters::QCameraMap QCameraParameters::FOCUS_ALGO_MAP[] = {
445    { FOCUS_ALGO_AUTO,            CAM_FOCUS_ALGO_AUTO },
446    { FOCUS_ALGO_SPOT_METERING,   CAM_FOCUS_ALGO_SPOT },
447    { FOCUS_ALGO_CENTER_WEIGHTED, CAM_FOCUS_ALGO_CENTER_WEIGHTED },
448    { FOCUS_ALGO_FRAME_AVERAGE,   CAM_FOCUS_ALGO_AVERAGE }
449};
450
451const QCameraParameters::QCameraMap QCameraParameters::WHITE_BALANCE_MODES_MAP[] = {
452    { WHITE_BALANCE_AUTO,            CAM_WB_MODE_AUTO },
453    { WHITE_BALANCE_INCANDESCENT,    CAM_WB_MODE_INCANDESCENT },
454    { WHITE_BALANCE_FLUORESCENT,     CAM_WB_MODE_FLUORESCENT },
455    { WHITE_BALANCE_WARM_FLUORESCENT,CAM_WB_MODE_WARM_FLUORESCENT},
456    { WHITE_BALANCE_DAYLIGHT,        CAM_WB_MODE_DAYLIGHT },
457    { WHITE_BALANCE_CLOUDY_DAYLIGHT, CAM_WB_MODE_CLOUDY_DAYLIGHT },
458    { WHITE_BALANCE_TWILIGHT,        CAM_WB_MODE_TWILIGHT },
459    { WHITE_BALANCE_SHADE,           CAM_WB_MODE_SHADE }
460};
461
462const QCameraParameters::QCameraMap QCameraParameters::ANTIBANDING_MODES_MAP[] = {
463    { ANTIBANDING_OFF,  CAM_ANTIBANDING_MODE_OFF },
464    { ANTIBANDING_50HZ, CAM_ANTIBANDING_MODE_50HZ },
465    { ANTIBANDING_60HZ, CAM_ANTIBANDING_MODE_60HZ },
466    { ANTIBANDING_AUTO, CAM_ANTIBANDING_MODE_AUTO }
467};
468
469const QCameraParameters::QCameraMap QCameraParameters::ISO_MODES_MAP[] = {
470    { ISO_AUTO,  CAM_ISO_MODE_AUTO },
471    { ISO_HJR,   CAM_ISO_MODE_DEBLUR },
472    { ISO_100,   CAM_ISO_MODE_100 },
473    { ISO_200,   CAM_ISO_MODE_200 },
474    { ISO_400,   CAM_ISO_MODE_400 },
475    { ISO_800,   CAM_ISO_MODE_800 },
476    { ISO_1600,  CAM_ISO_MODE_1600 }
477};
478
479const QCameraParameters::QCameraMap QCameraParameters::HFR_MODES_MAP[] = {
480    { VIDEO_HFR_OFF, CAM_HFR_MODE_OFF },
481    { VIDEO_HFR_2X,  CAM_HFR_MODE_60FPS },
482    { VIDEO_HFR_3X,  CAM_HFR_MODE_90FPS },
483    { VIDEO_HFR_4X,  CAM_HFR_MODE_120FPS },
484    { VIDEO_HFR_5X,  CAM_HFR_MODE_150FPS }
485};
486
487const QCameraParameters::QCameraMap QCameraParameters::BRACKETING_MODES_MAP[] = {
488    { AE_BRACKET_OFF, CAM_EXP_BRACKETING_OFF },
489    { AE_BRACKET,         CAM_EXP_BRACKETING_ON }
490};
491
492const QCameraParameters::QCameraMap QCameraParameters::ON_OFF_MODES_MAP[] = {
493    { VALUE_OFF, 0 },
494    { VALUE_ON,  1 }
495};
496
497const QCameraParameters::QCameraMap QCameraParameters::TOUCH_AF_AEC_MODES_MAP[] = {
498    { QCameraParameters::TOUCH_AF_AEC_OFF, 0 },
499    { QCameraParameters::TOUCH_AF_AEC_ON, 1 }
500};
501
502const QCameraParameters::QCameraMap QCameraParameters::ENABLE_DISABLE_MODES_MAP[] = {
503    { VALUE_ENABLE,  1 },
504    { VALUE_DISABLE, 0 }
505};
506
507const QCameraParameters::QCameraMap QCameraParameters::DENOISE_ON_OFF_MODES_MAP[] = {
508    { DENOISE_OFF, 0 },
509    { DENOISE_ON,  1 }
510};
511
512const QCameraParameters::QCameraMap QCameraParameters::TRUE_FALSE_MODES_MAP[] = {
513    { VALUE_FALSE, 0},
514    { VALUE_TRUE,  1}
515};
516
517const QCameraParameters::QCameraMap QCameraParameters::FLIP_MODES_MAP[] = {
518    {FLIP_MODE_OFF, 0},
519    {FLIP_MODE_V, FLIP_V},
520    {FLIP_MODE_H, FLIP_H},
521    {FLIP_MODE_VH, FLIP_V_H}
522};
523
524#define DEFAULT_CAMERA_AREA "(0, 0, 0, 0, 0)"
525#define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
526
527/*===========================================================================
528 * FUNCTION   : QCameraParameters
529 *
530 * DESCRIPTION: default constructor of QCameraParameters
531 *
532 * PARAMETERS : none
533 *
534 * RETURN     : None
535 *==========================================================================*/
536QCameraParameters::QCameraParameters()
537    : CameraParameters(),
538      m_pCapability(NULL),
539      m_pCamOpsTbl(NULL),
540      m_pParamHeap(NULL),
541      m_pParamBuf(NULL),
542      m_bZslMode(false),
543      m_bRecordingHint(false),
544      m_bHistogramEnabled(false),
545      m_nFaceProcMask(0),
546      m_bDebugFps(false),
547      mFocusMode(CAM_FOCUS_MODE_MAX),
548      mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
549      mPictureFormat(CAM_FORMAT_JPEG),
550      m_bNeedRestart(false),
551      m_bNoDisplayMode(false),
552      m_bWNROn(false),
553      m_bNeedLockCAF(false),
554      m_bCAFLocked(false),
555      m_bAFRunning(false),
556      m_tempMap()
557{
558    char value[32];
559    // TODO: may move to parameter instead of sysprop
560    property_get("persist.debug.sf.showfps", value, "0");
561    m_bDebugFps = atoi(value) > 0 ? true : false;
562
563    // For thermal mode, it should be set as system property
564    // because system property applies to all applications, while
565    // parameters only apply to specific app.
566    property_get("persist.camera.thermal.mode", value, "fps");
567    if (!strcmp(value, "frameskip")) {
568        m_ThermalMode = QCAMERA_THERMAL_ADJUST_FRAMESKIP;
569    } else {
570        if (strcmp(value, "fps"))
571            ALOGE("%s: Invalid camera thermal mode %s", __func__, value);
572        m_ThermalMode = QCAMERA_THERMAL_ADJUST_FPS;
573    }
574
575    memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
576}
577
578/*===========================================================================
579 * FUNCTION   : QCameraParameters
580 *
581 * DESCRIPTION: constructor of QCameraParameters
582 *
583 * PARAMETERS :
584 *   @params  : parameters in string
585 *
586 * RETURN     : None
587 *==========================================================================*/
588QCameraParameters::QCameraParameters(const String8 &params)
589    : CameraParameters(params),
590    m_pCapability(NULL),
591    m_pCamOpsTbl(NULL),
592    m_pParamHeap(NULL),
593    m_pParamBuf(NULL),
594    m_bZslMode(false),
595    m_bRecordingHint(false),
596    m_bHistogramEnabled(false),
597    m_nFaceProcMask(0),
598    m_bDebugFps(false),
599    mFocusMode(CAM_FOCUS_MODE_MAX),
600    mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
601    mPictureFormat(CAM_FORMAT_JPEG),
602    m_bNeedRestart(false),
603    m_bNoDisplayMode(false),
604    m_bWNROn(false),
605    m_bNeedLockCAF(false),
606    m_bCAFLocked(false),
607    m_bAFRunning(false),
608    m_tempMap()
609{
610    memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
611}
612
613/*===========================================================================
614 * FUNCTION   : ~QCameraParameters
615 *
616 * DESCRIPTION: deconstructor of QCameraParameters
617 *
618 * PARAMETERS : none
619 *
620 * RETURN     : None
621 *==========================================================================*/
622QCameraParameters::~QCameraParameters()
623{
624    deinit();
625}
626
627/*===========================================================================
628 * FUNCTION   : createSizesString
629 *
630 * DESCRIPTION: create string obj contains array of dimensions
631 *
632 * PARAMETERS :
633 *   @sizes   : array of dimensions
634 *   @len     : size of dimension array
635 *
636 * RETURN     : string obj
637 *==========================================================================*/
638String8 QCameraParameters::createSizesString(const cam_dimension_t *sizes, int len)
639{
640    String8 str;
641    char buffer[32];
642
643    if (len > 0) {
644        snprintf(buffer, sizeof(buffer), "%dx%d", sizes[0].width, sizes[0].height);
645        str.append(buffer);
646    }
647    for (int i = 1; i < len; i++) {
648        snprintf(buffer, sizeof(buffer), ",%dx%d", sizes[i].width, sizes[i].height);
649        str.append(buffer);
650    }
651    return str;
652}
653
654/*===========================================================================
655 * FUNCTION   : createValuesString
656 *
657 * DESCRIPTION: create string obj contains array of values from map when matched
658 *              from input values array
659 *
660 * PARAMETERS :
661 *   @values  : array of values
662 *   @len     : size of values array
663 *   @map     : map contains the mapping between values and enums
664 *   @map_len : size of the map
665 *
666 * RETURN     : string obj
667 *==========================================================================*/
668String8 QCameraParameters::createValuesString(const int *values,
669                                              int len,
670                                              const QCameraMap* map,
671                                              int map_len)
672{
673    String8 str;
674    int count = 0;
675
676    for (int i = 0; i < len; i++ ) {
677        for (int j = 0; j < map_len; j ++)
678            if (map[j].val == values[i]) {
679                if (NULL != map[j].desc) {
680                    if (count > 0) {
681                        str.append(",");
682                    }
683                    str.append(map[j].desc);
684                    count++;
685                    break; //loop j
686                }
687            }
688    }
689    return str;
690}
691
692/*===========================================================================
693 * FUNCTION   : createValuesStringFromMap
694 *
695 * DESCRIPTION: create string obj contains array of values directly from map
696 *
697 * PARAMETERS :
698 *   @map     : map contains the mapping between values and enums
699 *   @map_len : size of the map
700 *
701 * RETURN     : string obj
702 *==========================================================================*/
703String8 QCameraParameters::createValuesStringFromMap(const QCameraMap* map,
704                                                     int map_len)
705{
706    String8 str;
707
708    for (int i = 0; i < map_len; i++) {
709        if (NULL != map[i].desc) {
710            if (i > 0) {
711                str.append(",");
712            }
713            str.append(map[i].desc);
714        }
715    }
716    return str;
717}
718
719/*===========================================================================
720 * FUNCTION   : createZoomRatioValuesString
721 *
722 * DESCRIPTION: create string obj contains array of zoom ratio values
723 *
724 * PARAMETERS :
725 *   @zoomRaios  : array of zoom ratios
726 *   @length     : size of the array
727 *
728 * RETURN     : string obj
729 *==========================================================================*/
730String8 QCameraParameters::createZoomRatioValuesString(int *zoomRatios, int length)
731{
732    String8 str;
733    char buffer[32] = {0};
734
735    if(length > 0){
736        snprintf(buffer, sizeof(buffer), "%d", zoomRatios[0]);
737        str.append(buffer);
738    }
739
740    for (int i =1;i<length;i++){
741        memset(buffer, 0, sizeof(buffer));
742        snprintf(buffer, sizeof(buffer), ",%d", zoomRatios[i]);
743        str.append(buffer);
744    }
745    return str;
746}
747
748/*===========================================================================
749 * FUNCTION   : createHfrValuesString
750 *
751 * DESCRIPTION: create string obj contains array of hfr values from map when
752 *              matched from input hfr values
753 *
754 * PARAMETERS :
755 *   @values  : array of hfr info
756 *   @len     : size of the array
757 *   @map     : map of hfr string value and enum
758 *   map_len  : size of map
759 *
760 * RETURN     : string obj
761 *==========================================================================*/
762String8 QCameraParameters::createHfrValuesString(
763                                const cam_hfr_info_t *values,
764                                int len,
765                                const QCameraMap* map,
766                                int map_len)
767{
768    String8 str;
769    int count = 0;
770
771    for (int i = 0; i < len; i++ ) {
772        for (int j = 0; j < map_len; j ++)
773            if (map[j].val == (int)values[i].mode) {
774                if (NULL != map[j].desc) {
775                    if (count > 0) {
776                        str.append(",");
777                    }
778                     str.append(map[j].desc);
779                     count++;
780                     break; //loop j
781                }
782            }
783    }
784    return str;
785}
786
787/*===========================================================================
788 * FUNCTION   : createHfrSizesString
789 *
790 * DESCRIPTION: create string obj contains array of hfr sizes
791 *
792 * PARAMETERS :
793 *   @values  : array of hfr info
794 *   @len     : size of the array
795 *
796 * RETURN     : string obj
797 *==========================================================================*/
798String8 QCameraParameters::createHfrSizesString(
799                                const cam_hfr_info_t *values,
800                                int len)
801{
802    String8 str;
803    char buffer[32];
804
805    if (len > 0) {
806        snprintf(buffer, sizeof(buffer), "%dx%d",
807                 values[0].dim.width, values[0].dim.height);
808        str.append(buffer);
809    }
810    for (int i = 1; i < len; i++) {
811        snprintf(buffer, sizeof(buffer), ",%dx%d",
812                 values[i].dim.width, values[i].dim.height);
813        str.append(buffer);
814    }
815    return str;
816}
817
818/*===========================================================================
819 * FUNCTION   : createFpsString
820 *
821 * DESCRIPTION: create string obj contains array of FPS rates
822 *
823 * PARAMETERS :
824 *   @fps     : array of fps ranges
825 *   @len     : size of the array
826 *
827 * RETURN     : string obj
828 *==========================================================================*/
829String8 QCameraParameters::createFpsString(const cam_fps_range_t *fps, int len)
830{
831    String8 str;
832    char buffer[32];
833
834    for (int i = 0; i < len; i++ ) {
835        snprintf(buffer, sizeof(buffer), "%d", int(fps[i].max_fps * 1000));
836        str.append(buffer);
837        if (i < len-1)
838            str.append(",");
839    }
840    return str;
841}
842
843/*===========================================================================
844 * FUNCTION   : createFpsRangeString
845 *
846 * DESCRIPTION: create string obj contains array of FPS ranges
847 *
848 * PARAMETERS :
849 *   @fps     : array of fps ranges
850 *   @len     : size of the array
851 *   @default_fps_index : reference to index of default fps range
852 *
853 * RETURN     : string obj
854 *==========================================================================*/
855String8 QCameraParameters::createFpsRangeString(const cam_fps_range_t* fps,
856                                                int len,
857                                                int &default_fps_index)
858{
859    String8 str;
860    char buffer[32];
861    int max_range = 0;
862    int min_fps, max_fps;
863
864    if (len > 0) {
865        min_fps = int(fps[0].min_fps * 1000);
866        max_fps = int(fps[0].max_fps * 1000);
867        max_range = max_fps - min_fps;
868        default_fps_index = 0;
869        snprintf(buffer, sizeof(buffer), "(%d,%d)", min_fps, max_fps);
870        str.append(buffer);
871    }
872    for (int i = 1; i < len; i++) {
873        min_fps = int(fps[i].min_fps * 1000);
874        max_fps = int(fps[i].max_fps * 1000);
875        if (max_range < (max_fps - min_fps)) {
876            max_range = max_fps - min_fps;
877            default_fps_index = i;
878        }
879        snprintf(buffer, sizeof(buffer), ",(%d,%d)", min_fps, max_fps);
880        str.append(buffer);
881    }
882    return str;
883}
884
885/*===========================================================================
886 * FUNCTION   : lookupAttr
887 *
888 * DESCRIPTION: lookup a value by its name
889 *
890 * PARAMETERS :
891 *   @attr    : map contains <name, value>
892 *   @len     : size of the map
893 *   @name    : name to be looked up
894 *
895 * RETURN     : valid value if found
896 *              NAME_NOT_FOUND if not found
897 *==========================================================================*/
898int QCameraParameters::lookupAttr(const QCameraMap arr[], int len, const char *name)
899{
900    if (name) {
901        for (int i = 0; i < len; i++) {
902            if (!strcmp(arr[i].desc, name))
903                return arr[i].val;
904        }
905    }
906    return NAME_NOT_FOUND;
907}
908
909/*===========================================================================
910 * FUNCTION   : lookupNameByValue
911 *
912 * DESCRIPTION: lookup a name by its value
913 *
914 * PARAMETERS :
915 *   @attr    : map contains <name, value>
916 *   @len     : size of the map
917 *   @value   : value to be looked up
918 *
919 * RETURN     : name str or NULL if not found
920 *==========================================================================*/
921const char *QCameraParameters::lookupNameByValue(const QCameraMap arr[], int len, int value)
922{
923    for (int i = 0; i < len; i++) {
924        if (arr[i].val == value) {
925            return arr[i].desc;
926        }
927    }
928    return NULL;
929}
930
931/*===========================================================================
932 * FUNCTION   : setPreviewSize
933 *
934 * DESCRIPTION: set preview size from user setting
935 *
936 * PARAMETERS :
937 *   @params  : user setting parameters
938 *
939 * RETURN     : int32_t type of status
940 *              NO_ERROR  -- success
941 *              none-zero failure code
942 *==========================================================================*/
943int32_t QCameraParameters::setPreviewSize(const QCameraParameters& params)
944{
945    int width, height;
946    params.getPreviewSize(&width, &height);
947    ALOGV("Requested preview size %d x %d", width, height);
948
949    // Validate the preview size
950    for (size_t i = 0; i < m_pCapability->preview_sizes_tbl_cnt; ++i) {
951        if (width ==  m_pCapability->preview_sizes_tbl[i].width
952           && height ==  m_pCapability->preview_sizes_tbl[i].height) {
953            // check if need to restart preview in case of preview size change
954            int old_width, old_height;
955            CameraParameters::getPreviewSize(&old_width, &old_height);
956            if (width != old_width || height != old_height) {
957                m_bNeedRestart = true;
958            }
959
960            // set the new value
961            char val[32];
962            sprintf(val, "%dx%d", width, height);
963            updateParamEntry(KEY_PREVIEW_SIZE, val);
964            ALOGV("%s: %s", __func__, val);
965            return NO_ERROR;
966        }
967    }
968    ALOGE("Invalid preview size requested: %dx%d", width, height);
969    return BAD_VALUE;
970}
971
972/*===========================================================================
973 * FUNCTION   : setPictureSize
974 *
975 * DESCRIPTION: set picture size from user setting
976 *
977 * PARAMETERS :
978 *   @params  : user setting parameters
979 *
980 * RETURN     : int32_t type of status
981 *              NO_ERROR  -- success
982 *              none-zero failure code
983 *==========================================================================*/
984int32_t QCameraParameters::setPictureSize(const QCameraParameters& params)
985{
986    int width, height;
987    params.getPictureSize(&width, &height);
988    ALOGV("Requested picture size %d x %d", width, height);
989
990    // Validate the picture size
991    for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
992        if (width ==  m_pCapability->picture_sizes_tbl[i].width
993           && height ==  m_pCapability->picture_sizes_tbl[i].height) {
994            // check if need to restart preview in case of picture size change
995            int old_width, old_height;
996            CameraParameters::getPictureSize(&old_width, &old_height);
997            if ((m_bZslMode || m_bRecordingHint) &&
998                (width != old_width || height != old_height)) {
999                m_bNeedRestart = true;
1000            }
1001
1002            // set the new value
1003            char val[32];
1004            sprintf(val, "%dx%d", width, height);
1005            updateParamEntry(KEY_PICTURE_SIZE, val);
1006            ALOGV("%s: %s", __func__, val);
1007            return NO_ERROR;
1008        }
1009    }
1010    ALOGE("Invalid picture size requested: %dx%d", width, height);
1011    return BAD_VALUE;
1012}
1013
1014/*===========================================================================
1015 * FUNCTION   : setVideoSize
1016 *
1017 * DESCRIPTION: set video size from user setting
1018 *
1019 * PARAMETERS :
1020 *   @params  : user setting parameters
1021 *
1022 * RETURN     : int32_t type of status
1023 *              NO_ERROR  -- success
1024 *              none-zero failure code
1025 *==========================================================================*/
1026int32_t QCameraParameters::setVideoSize(const QCameraParameters& params)
1027{
1028    const char *str= NULL;
1029    int width, height;
1030    str = params.get(KEY_VIDEO_SIZE);
1031    if(!str) {
1032        //If application didn't set this parameter string, use the values from
1033        //getPreviewSize() as video dimensions.
1034        params.getPreviewSize(&width, &height);
1035        ALOGE("No Record Size requested, use the preview dimensions");
1036    } else {
1037        params.getVideoSize(&width, &height);
1038    }
1039
1040    // Validate the video size
1041    for (size_t i = 0; i < m_pCapability->video_sizes_tbl_cnt; ++i) {
1042        if (width ==  m_pCapability->video_sizes_tbl[i].width
1043                && height ==  m_pCapability->video_sizes_tbl[i].height) {
1044            // check if need to restart preview in case of video size change
1045            int old_width, old_height;
1046            CameraParameters::getVideoSize(&old_width, &old_height);
1047            if (m_bRecordingHint &&
1048               (width != old_width || height != old_height)) {
1049                m_bNeedRestart = true;
1050            }
1051
1052            // set the new value
1053            char val[32];
1054            sprintf(val, "%dx%d", width, height);
1055            updateParamEntry(KEY_VIDEO_SIZE, val);
1056            ALOGV("%s: %s", __func__, val);
1057            return NO_ERROR;
1058        }
1059    }
1060
1061    ALOGE("Invalid video size requested: %dx%d", width, height);
1062    return BAD_VALUE;
1063}
1064
1065/*===========================================================================
1066 * FUNCTION   : setLiveSnapshotSize
1067 *
1068 * DESCRIPTION: set live snapshot size
1069 *
1070 * PARAMETERS :
1071 *   @params  : user setting parameters
1072 *
1073 * RETURN     : int32_t type of status
1074 *              NO_ERROR  -- success
1075 *              none-zero failure code
1076 *==========================================================================*/
1077int32_t QCameraParameters::setLiveSnapshotSize(const QCameraParameters& params)
1078{
1079    char value[32];
1080    property_get("persist.camera.opt.livepic", value, "1");
1081    bool useOptimal = atoi(value) > 0 ? true : false;
1082
1083    // use picture size from user setting
1084    params.getPictureSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
1085
1086    uint8_t livesnapshot_sizes_tbl_cnt = m_pCapability->livesnapshot_sizes_tbl_cnt;
1087    cam_dimension_t *livesnapshot_sizes_tbl = &m_pCapability->livesnapshot_sizes_tbl[0];
1088
1089    // check if HFR is enabled
1090    const char *hfrStr = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
1091    cam_hfr_mode_t hfrMode = CAM_HFR_MODE_OFF;
1092    if (hfrStr != NULL) {
1093        int32_t value = lookupAttr(HFR_MODES_MAP,
1094                                   sizeof(HFR_MODES_MAP)/sizeof(QCameraMap),
1095                                   hfrStr);
1096        if (value != NAME_NOT_FOUND) {
1097            // if HFR is enabled, change live snapshot size
1098            if (value > CAM_HFR_MODE_OFF) {
1099                for (int i = 0; i < m_pCapability->hfr_tbl_cnt; i++) {
1100                    if (m_pCapability->hfr_tbl[i].mode == value) {
1101                        livesnapshot_sizes_tbl_cnt =
1102                            m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl_cnt;
1103                        livesnapshot_sizes_tbl =
1104                            &m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl[0];
1105                        hfrMode = m_pCapability->hfr_tbl[i].mode;
1106                        break;
1107                    }
1108                }
1109            }
1110        }
1111    }
1112
1113    if (useOptimal || hfrMode != CAM_HFR_MODE_OFF) {
1114        bool found = false;
1115
1116        // first check if picture size is within the list of supported sizes
1117        for (int i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
1118            if (m_LiveSnapshotSize.width == livesnapshot_sizes_tbl[i].width &&
1119                m_LiveSnapshotSize.height == livesnapshot_sizes_tbl[i].height) {
1120                found = true;
1121                break;
1122            }
1123        }
1124
1125        if (!found) {
1126            // use optimal live snapshot size from supported list,
1127            // that has same preview aspect ratio
1128            int width = 0, height = 0;
1129            params.getPreviewSize(&width, &height);
1130
1131            double previewAspectRatio = (double)width / height;
1132            for (int i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
1133                double ratio = (double)livesnapshot_sizes_tbl[i].width /
1134                                livesnapshot_sizes_tbl[i].height;
1135                if (fabs(previewAspectRatio - ratio) <= ASPECT_TOLERANCE) {
1136                    m_LiveSnapshotSize = livesnapshot_sizes_tbl[i];
1137                    found = true;
1138                    break;
1139                }
1140            }
1141
1142            if (!found && hfrMode != CAM_HFR_MODE_OFF) {
1143                // Cannot find matching aspect ration from supported live snapshot list
1144                // choose the max dim from preview and video size
1145                ALOGI("%s: Cannot find matching aspect ratio, choose max of preview or video size", __func__);
1146                params.getVideoSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
1147                if (m_LiveSnapshotSize.width < width && m_LiveSnapshotSize.height < height) {
1148                    m_LiveSnapshotSize.width = width;
1149                    m_LiveSnapshotSize.height = height;
1150                }
1151            }
1152        }
1153    }
1154    ALOGI("%s: live snapshot size %d x %d", __func__,
1155          m_LiveSnapshotSize.width, m_LiveSnapshotSize.height);
1156
1157    return NO_ERROR;
1158}
1159
1160/*===========================================================================
1161 * FUNCTION   : setPreviewFormat
1162 *
1163 * DESCRIPTION: set preview format from user setting
1164 *
1165 * PARAMETERS :
1166 *   @params  : user setting parameters
1167 *
1168 * RETURN     : int32_t type of status
1169 *              NO_ERROR  -- success
1170 *              none-zero failure code
1171 *==========================================================================*/
1172int32_t QCameraParameters::setPreviewFormat(const QCameraParameters& params)
1173{
1174    const char *str = params.getPreviewFormat();
1175    int32_t previewFormat =
1176        lookupAttr(PREVIEW_FORMATS_MAP,
1177                   sizeof(PREVIEW_FORMATS_MAP) / sizeof(QCameraMap),
1178                   str);
1179    if (previewFormat != NAME_NOT_FOUND) {
1180        mPreviewFormat = (cam_format_t)previewFormat;
1181
1182        updateParamEntry(KEY_PREVIEW_FORMAT, str);
1183        ALOGV("%s: format %d\n", __func__, mPreviewFormat);
1184        return NO_ERROR;
1185    }
1186    ALOGE("Invalid preview format value: %s", (str == NULL) ? "NULL" : str);
1187    return BAD_VALUE;
1188}
1189
1190/*===========================================================================
1191 * FUNCTION   : setPictureFormat
1192 *
1193 * DESCRIPTION: set picture format from user setting
1194 *
1195 * PARAMETERS :
1196 *   @params  : user setting parameters
1197 *
1198 * RETURN     : int32_t type of status
1199 *              NO_ERROR  -- success
1200 *              none-zero failure code
1201 *==========================================================================*/
1202int32_t QCameraParameters::setPictureFormat(const QCameraParameters& params)
1203{
1204    const char *str = params.getPictureFormat();
1205    int32_t pictureFormat =
1206        lookupAttr(PICTURE_TYPES_MAP,
1207                   sizeof(PICTURE_TYPES_MAP) / sizeof(QCameraMap),
1208                   str);
1209    if (pictureFormat != NAME_NOT_FOUND) {
1210        mPictureFormat = pictureFormat;
1211
1212        updateParamEntry(KEY_PICTURE_FORMAT, str);
1213        ALOGE("%s: format %d\n", __func__, mPictureFormat);
1214        return NO_ERROR;
1215    }
1216    ALOGE("Invalid picture format value: %s", (str == NULL) ? "NULL" : str);
1217    return BAD_VALUE;
1218}
1219
1220/*===========================================================================
1221 * FUNCTION   : setJpegThumbnailSize
1222 *
1223 * DESCRIPTION: set jpeg thumbnail size from user setting
1224 *
1225 * PARAMETERS :
1226 *   @params  : user setting parameters
1227 *
1228 * RETURN     : int32_t type of status
1229 *              NO_ERROR  -- success
1230 *              none-zero failure code
1231 *==========================================================================*/
1232int32_t QCameraParameters::setJpegThumbnailSize(const QCameraParameters& params)
1233{
1234    int width = params.getInt(KEY_JPEG_THUMBNAIL_WIDTH);
1235    int height = params.getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
1236
1237    ALOGV("requested jpeg thumbnail size %d x %d", width, height);
1238
1239    int sizes_cnt = sizeof(THUMBNAIL_SIZES_MAP) / sizeof(cam_dimension_t);
1240
1241    int pic_width = 0, pic_height = 0;
1242    params.getPictureSize(&pic_width, &pic_height);
1243    if (pic_height == 0) {
1244        ALOGE("%s: picture size is invalid (%d x %d)", __func__, pic_width, pic_height);
1245        return BAD_VALUE;
1246    }
1247    double picAspectRatio = (double)pic_width / pic_height;
1248
1249    int optimalWidth = 0, optimalHeight = 0;
1250    if (width != 0 || height != 0) {
1251        // If input jpeg thumnmail size is (0,0), meaning no thumbnail needed
1252        // hornor this setting.
1253        // Otherwise, find optimal jpeg thumbnail size that has same aspect ration
1254        // as picture size
1255
1256        // Try to find a size matches aspect ratio and has the largest width
1257        for (int i = 0; i < sizes_cnt; i++) {
1258            if (THUMBNAIL_SIZES_MAP[i].height == 0) {
1259                // No thumbnail case, just skip
1260                continue;
1261            }
1262            double ratio =
1263                (double)THUMBNAIL_SIZES_MAP[i].width / THUMBNAIL_SIZES_MAP[i].height;
1264            if (fabs(ratio - picAspectRatio) > ASPECT_TOLERANCE)  {
1265                continue;
1266            }
1267            if (THUMBNAIL_SIZES_MAP[i].width > optimalWidth) {
1268                optimalWidth = THUMBNAIL_SIZES_MAP[i].width;
1269                optimalHeight = THUMBNAIL_SIZES_MAP[i].height;
1270            }
1271        }
1272    }
1273
1274    char val[16];
1275    sprintf(val, "%d", optimalWidth);
1276    updateParamEntry(KEY_JPEG_THUMBNAIL_WIDTH, val);
1277    sprintf(val, "%d", optimalHeight);
1278    updateParamEntry(KEY_JPEG_THUMBNAIL_HEIGHT, val);
1279    return NO_ERROR;
1280}
1281
1282/*===========================================================================
1283 * FUNCTION   : setJpegQuality
1284 *
1285 * DESCRIPTION: set jpeg encpding quality from user setting
1286 *
1287 * PARAMETERS :
1288 *   @params  : user setting parameters
1289 *
1290 * RETURN     : int32_t type of status
1291 *              NO_ERROR  -- success
1292 *              none-zero failure code
1293 *==========================================================================*/
1294int32_t QCameraParameters::setJpegQuality(const QCameraParameters& params)
1295{
1296    int32_t rc = NO_ERROR;
1297    int quality = params.getInt(KEY_JPEG_QUALITY);
1298    if (quality >= 0 && quality <= 100) {
1299        set(KEY_JPEG_QUALITY, quality);
1300    } else {
1301        ALOGE("%s: Invalid jpeg quality=%d", __func__, quality);
1302        rc = BAD_VALUE;
1303    }
1304
1305    quality = params.getInt(KEY_JPEG_THUMBNAIL_QUALITY);
1306    if (quality >= 0 && quality <= 100) {
1307        char val[16];
1308        sprintf(val, "%d", quality);
1309        updateParamEntry(KEY_JPEG_THUMBNAIL_QUALITY, val);
1310    } else {
1311        ALOGE("%s: Invalid jpeg thumbnail quality=%d", __func__, quality);
1312        rc = BAD_VALUE;
1313    }
1314    return rc;
1315}
1316
1317/*===========================================================================
1318 * FUNCTION   : setOrientaion
1319 *
1320 * DESCRIPTION: set orientaion from user setting
1321 *
1322 * PARAMETERS :
1323 *   @params  : user setting parameters
1324 *
1325 * RETURN     : int32_t type of status
1326 *              NO_ERROR  -- success
1327 *              none-zero failure code
1328 *==========================================================================*/
1329int32_t QCameraParameters::setOrientation(const QCameraParameters& params)
1330{
1331    const char *str = params.get(KEY_QC_ORIENTATION);
1332
1333    if (str != NULL) {
1334        if (strcmp(str, portrait) == 0 || strcmp(str, landscape) == 0) {
1335            // Camera service needs this to decide if the preview frames and raw
1336            // pictures should be rotated.
1337            updateParamEntry(KEY_QC_ORIENTATION, str);
1338        } else {
1339            ALOGE("%s: Invalid orientation value: %s", __func__, str);
1340            return BAD_VALUE;
1341        }
1342    }
1343    return NO_ERROR;
1344}
1345
1346/*===========================================================================
1347 * FUNCTION   : setAutoExposure
1348 *
1349 * DESCRIPTION: set auto exposure value from user setting
1350 *
1351 * PARAMETERS :
1352 *   @params  : user setting parameters
1353 *
1354 * RETURN     : int32_t type of status
1355 *              NO_ERROR  -- success
1356 *              none-zero failure code
1357 *==========================================================================*/
1358int32_t QCameraParameters::setAutoExposure(const QCameraParameters& params)
1359{
1360    const char *str = params.get(KEY_QC_AUTO_EXPOSURE);
1361    const char *prev_str = get(KEY_QC_AUTO_EXPOSURE);
1362    if (str != NULL) {
1363        if (prev_str == NULL ||
1364            strcmp(str, prev_str) != 0) {
1365            return setAutoExposure(str);
1366        }
1367    }
1368    return NO_ERROR;
1369}
1370
1371/*===========================================================================
1372 * FUNCTION   : setPreviewFpsRange
1373 *
1374 * DESCRIPTION: set preview FPS range from user setting
1375 *
1376 * PARAMETERS :
1377 *   @params  : user setting parameters
1378 *
1379 * RETURN     : int32_t type of status
1380 *              NO_ERROR  -- success
1381 *              none-zero failure code
1382 *==========================================================================*/
1383int32_t QCameraParameters::setPreviewFpsRange(const QCameraParameters& params)
1384{
1385    int minFps,maxFps;
1386    int prevMinFps, prevMaxFps;
1387    int rc = NO_ERROR;
1388    bool found = false;
1389
1390    CameraParameters::getPreviewFpsRange(&prevMinFps, &prevMaxFps);
1391    ALOGV("%s: Existing FpsRange Values:(%d, %d)", __func__, prevMinFps, prevMaxFps);
1392    params.getPreviewFpsRange(&minFps, &maxFps);
1393    ALOGV("%s: Requested FpsRange Values:(%d, %d)", __func__, minFps, maxFps);
1394
1395    if(minFps == prevMinFps && maxFps == prevMaxFps) {
1396        ALOGV("%s: No change in FpsRange", __func__);
1397        rc = NO_ERROR;
1398        goto end;
1399    }
1400    for(int i = 0; i < m_pCapability->fps_ranges_tbl_cnt; i++) {
1401        // if the value is in the supported list
1402        if(minFps >= m_pCapability->fps_ranges_tbl[i].min_fps * 1000 &&
1403           maxFps <= m_pCapability->fps_ranges_tbl[i].max_fps * 1000) {
1404            found = true;
1405            ALOGV("%s: FPS i=%d : minFps = %d, maxFps = %d ", __func__, i, minFps, maxFps);
1406            setPreviewFpsRange(minFps, maxFps);
1407            break;
1408        }
1409    }
1410    if(found == false){
1411        ALOGE("%s: error: FPS range value not supported", __func__);
1412        rc = BAD_VALUE;
1413    }
1414end:
1415    return rc;
1416}
1417
1418/*===========================================================================
1419 * FUNCTION   : setPreviewFrameRate
1420 *
1421 * DESCRIPTION: set preview frame rate from user setting
1422 *
1423 * PARAMETERS :
1424 *   @params  : user setting parameters
1425 *
1426 * RETURN     : int32_t type of status
1427 *              NO_ERROR  -- success
1428 *              none-zero failure code
1429 *==========================================================================*/
1430int32_t QCameraParameters::setPreviewFrameRate(const QCameraParameters& params)
1431{
1432    uint16_t fps = (uint16_t)params.getPreviewFrameRate();
1433    ALOGV("%s: requested preview frame rate is %d", __func__, fps);
1434    CameraParameters::setPreviewFrameRate(fps);
1435    return NO_ERROR;
1436}
1437
1438/*===========================================================================
1439 * FUNCTION   : setEffect
1440 *
1441 * DESCRIPTION: set effect value from user setting
1442 *
1443 * PARAMETERS :
1444 *   @params  : user setting parameters
1445 *
1446 * RETURN     : int32_t type of status
1447 *              NO_ERROR  -- success
1448 *              none-zero failure code
1449 *==========================================================================*/
1450int32_t QCameraParameters::setEffect(const QCameraParameters& params)
1451{
1452    const char *str = params.get(KEY_EFFECT);
1453    const char *prev_str = get(KEY_EFFECT);
1454    if (str != NULL) {
1455        if (prev_str == NULL ||
1456            strcmp(str, prev_str) != 0) {
1457            return setEffect(str);
1458        }
1459    }
1460    return NO_ERROR;
1461}
1462
1463/*===========================================================================
1464 * FUNCTION   : setFocusMode
1465 *
1466 * DESCRIPTION: set focus mode from user setting
1467 *
1468 * PARAMETERS :
1469 *   @params  : user setting parameters
1470 *
1471 * RETURN     : int32_t type of status
1472 *              NO_ERROR  -- success
1473 *              none-zero failure code
1474 *==========================================================================*/
1475int32_t QCameraParameters::setFocusMode(const QCameraParameters& params)
1476{
1477    const char *str = params.get(KEY_FOCUS_MODE);
1478    const char *prev_str = get(KEY_FOCUS_MODE);
1479    if (str != NULL) {
1480        if (prev_str == NULL ||
1481            strcmp(str, prev_str) != 0) {
1482            return setFocusMode(str);
1483        }
1484    }
1485    return NO_ERROR;
1486}
1487
1488/*===========================================================================
1489 * FUNCTION   : setBrightness
1490 *
1491 * DESCRIPTION: set brightness control value from user setting
1492 *
1493 * PARAMETERS :
1494 *   @params  : user setting parameters
1495 *
1496 * RETURN     : int32_t type of status
1497 *              NO_ERROR  -- success
1498 *              none-zero failure code
1499 *==========================================================================*/
1500int32_t QCameraParameters::setBrightness(const QCameraParameters& params)
1501{
1502    int currentBrightness = getInt(KEY_QC_BRIGHTNESS);
1503    int brightness = params.getInt(KEY_QC_BRIGHTNESS);
1504    if (currentBrightness !=  brightness) {
1505        if (brightness >= m_pCapability->brightness_ctrl.min_value &&
1506            brightness <= m_pCapability->brightness_ctrl.max_value) {
1507            ALOGV(" new brightness value : %d ", brightness);
1508            return setBrightness(brightness);
1509        } else {
1510            ALOGE("%s: invalid value %d out of (%d, %d)",
1511                  __func__, brightness,
1512                  m_pCapability->brightness_ctrl.min_value,
1513                  m_pCapability->brightness_ctrl.max_value);
1514            return BAD_VALUE;
1515        }
1516    } else {
1517        ALOGV("%s: No brightness value changed.", __func__);
1518        return NO_ERROR;
1519    }
1520}
1521
1522/*===========================================================================
1523 * FUNCTION   : setSharpness
1524 *
1525 * DESCRIPTION: set sharpness control value from user setting
1526 *
1527 * PARAMETERS :
1528 *   @params  : user setting parameters
1529 *
1530 * RETURN     : int32_t type of status
1531 *              NO_ERROR  -- success
1532 *              none-zero failure code
1533 *==========================================================================*/
1534int32_t QCameraParameters::setSharpness(const QCameraParameters& params)
1535{
1536    int shaprness = params.getInt(KEY_QC_SHARPNESS);
1537    int prev_sharp = getInt(KEY_QC_SHARPNESS);
1538    if (prev_sharp !=  shaprness) {
1539        if((shaprness >= m_pCapability->sharpness_ctrl.min_value) &&
1540           (shaprness <= m_pCapability->sharpness_ctrl.max_value)) {
1541            ALOGV(" new sharpness value : %d ", shaprness);
1542            return setSharpness(shaprness);
1543        } else {
1544            ALOGE("%s: invalid value %d out of (%d, %d)",
1545                  __func__, shaprness,
1546                  m_pCapability->sharpness_ctrl.min_value,
1547                  m_pCapability->sharpness_ctrl.max_value);
1548            return BAD_VALUE;
1549        }
1550    } else {
1551        ALOGV("%s: No value change in shaprness", __func__);
1552        return NO_ERROR;
1553    }
1554}
1555
1556/*===========================================================================
1557 * FUNCTION   : setSkintoneEnahancement
1558 *
1559 * DESCRIPTION: set skin tone enhancement factor from user setting
1560 *
1561 * PARAMETERS :
1562 *   @params  : user setting parameters
1563 *
1564 * RETURN     : int32_t type of status
1565 *              NO_ERROR  -- success
1566 *              none-zero failure code
1567 *==========================================================================*/
1568int32_t QCameraParameters::setSkinToneEnhancement(const QCameraParameters& params)
1569{
1570    int sceFactor = params.getInt(KEY_QC_SCE_FACTOR);
1571    int prev_sceFactor = getInt(KEY_QC_SCE_FACTOR);
1572    if (prev_sceFactor !=  sceFactor) {
1573        if((sceFactor >= m_pCapability->sce_ctrl.min_value) &&
1574           (sceFactor <= m_pCapability->sce_ctrl.max_value)) {
1575            ALOGV(" new Skintone Enhancement value : %d ", sceFactor);
1576            return setSkinToneEnhancement(sceFactor);
1577        } else {
1578            ALOGE("%s: invalid value %d out of (%d, %d)",
1579                  __func__, sceFactor,
1580                  m_pCapability->sce_ctrl.min_value,
1581                  m_pCapability->sce_ctrl.max_value);
1582            return BAD_VALUE;
1583        }
1584    } else {
1585        ALOGV("%s: No value change in skintone enhancement factor", __func__);
1586        return NO_ERROR;
1587    }
1588}
1589
1590/*===========================================================================
1591 * FUNCTION   : setSaturation
1592 *
1593 * DESCRIPTION: set saturation control value from user setting
1594 *
1595 * PARAMETERS :
1596 *   @params  : user setting parameters
1597 *
1598 * RETURN     : int32_t type of status
1599 *              NO_ERROR  -- success
1600 *              none-zero failure code
1601 *==========================================================================*/
1602int32_t QCameraParameters::setSaturation(const QCameraParameters& params)
1603{
1604    int saturation = params.getInt(KEY_QC_SATURATION);
1605    int prev_sat = getInt(KEY_QC_SATURATION);
1606    if (prev_sat !=  saturation) {
1607        if((saturation >= m_pCapability->saturation_ctrl.min_value) &&
1608           (saturation <= m_pCapability->saturation_ctrl.max_value)) {
1609            ALOGV(" new saturation value : %d ", saturation);
1610            return setSaturation(saturation);
1611        } else {
1612            ALOGE("%s: invalid value %d out of (%d, %d)",
1613                  __func__, saturation,
1614                  m_pCapability->saturation_ctrl.min_value,
1615                  m_pCapability->saturation_ctrl.max_value);
1616            return BAD_VALUE;
1617        }
1618    } else {
1619        ALOGV("%s: No value change in saturation factor", __func__);
1620        return NO_ERROR;
1621    }
1622}
1623
1624/*===========================================================================
1625 * FUNCTION   : setContrast
1626 *
1627 * DESCRIPTION: set contrast control value from user setting
1628 *
1629 * PARAMETERS :
1630 *   @params  : user setting parameters
1631 *
1632 * RETURN     : int32_t type of status
1633 *              NO_ERROR  -- success
1634 *              none-zero failure code
1635 *==========================================================================*/
1636int32_t QCameraParameters::setContrast(const QCameraParameters& params)
1637{
1638    int contrast = params.getInt(KEY_QC_CONTRAST);
1639    int prev_contrast = getInt(KEY_QC_CONTRAST);
1640    if (prev_contrast !=  contrast) {
1641        if((contrast >= m_pCapability->contrast_ctrl.min_value) &&
1642           (contrast <= m_pCapability->contrast_ctrl.max_value)) {
1643            ALOGV(" new contrast value : %d ", contrast);
1644            int32_t rc = setContrast(contrast);
1645            return rc;
1646        } else {
1647            ALOGE("%s: invalid value %d out of (%d, %d)",
1648                  __func__, contrast,
1649                  m_pCapability->contrast_ctrl.min_value,
1650                  m_pCapability->contrast_ctrl.max_value);
1651            return BAD_VALUE;
1652        }
1653    } else {
1654        ALOGV("%s: No value change in contrast", __func__);
1655        return NO_ERROR;
1656    }
1657}
1658
1659/*===========================================================================
1660 * FUNCTION   : setExposureCompensation
1661 *
1662 * DESCRIPTION: set exposure compensation value from user setting
1663 *
1664 * PARAMETERS :
1665 *   @params  : user setting parameters
1666 *
1667 * RETURN     : int32_t type of status
1668 *              NO_ERROR  -- success
1669 *              none-zero failure code
1670 *==========================================================================*/
1671int32_t QCameraParameters::setExposureCompensation(const QCameraParameters & params)
1672{
1673    int expComp = params.getInt(KEY_EXPOSURE_COMPENSATION);
1674    int prev_expComp = getInt(KEY_EXPOSURE_COMPENSATION);
1675    if (prev_expComp !=  expComp) {
1676        if((expComp >= m_pCapability->exposure_compensation_min) &&
1677           (expComp <= m_pCapability->exposure_compensation_max)) {
1678            ALOGV(" new Exposure Compensation value : %d ", expComp);
1679            return setExposureCompensation(expComp);
1680        } else {
1681            ALOGE("%s: invalid value %d out of (%d, %d)",
1682                  __func__, expComp,
1683                  m_pCapability->exposure_compensation_min,
1684                  m_pCapability->exposure_compensation_max);
1685            return BAD_VALUE;
1686        }
1687    } else {
1688        ALOGV("%s: No value change in Exposure Compensation", __func__);
1689        return NO_ERROR;
1690    }
1691}
1692
1693/*===========================================================================
1694 * FUNCTION   : setWhiteBalance
1695 *
1696 * DESCRIPTION: set white balance value from user setting
1697 *
1698 * PARAMETERS :
1699 *   @params  : user setting parameters
1700 *
1701 * RETURN     : int32_t type of status
1702 *              NO_ERROR  -- success
1703 *              none-zero failure code
1704 *==========================================================================*/
1705int32_t QCameraParameters::setWhiteBalance(const QCameraParameters& params)
1706{
1707    const char *str = params.get(KEY_WHITE_BALANCE);
1708    const char *prev_str = get(KEY_WHITE_BALANCE);
1709    if (str != NULL) {
1710        if (prev_str == NULL ||
1711            strcmp(str, prev_str) != 0) {
1712            return setWhiteBalance(str);
1713        }
1714    }
1715    return NO_ERROR;
1716}
1717
1718/*===========================================================================
1719 * FUNCTION   : setAntibanding
1720 *
1721 * DESCRIPTION: set antibanding value from user setting
1722 *
1723 * PARAMETERS :
1724 *   @params  : user setting parameters
1725 *
1726 * RETURN     : int32_t type of status
1727 *              NO_ERROR  -- success
1728 *              none-zero failure code
1729 *==========================================================================*/
1730int32_t QCameraParameters::setAntibanding(const QCameraParameters& params)
1731{
1732    const char *str = params.get(KEY_ANTIBANDING);
1733    const char *prev_str = get(KEY_ANTIBANDING);
1734    if (str != NULL) {
1735        if (prev_str == NULL ||
1736            strcmp(str, prev_str) != 0) {
1737            return setAntibanding(str);
1738        }
1739    }
1740    return NO_ERROR;
1741}
1742
1743/*===========================================================================
1744 * FUNCTION   : setSceneDetect
1745 *
1746 * DESCRIPTION: set scenen detect value from user setting
1747 *
1748 * PARAMETERS :
1749 *   @params  : user setting parameters
1750 *
1751 * RETURN     : int32_t type of status
1752 *              NO_ERROR  -- success
1753 *              none-zero failure code
1754 *==========================================================================*/
1755int32_t QCameraParameters::setSceneDetect(const QCameraParameters& params)
1756{
1757    const char *str = params.get(KEY_QC_SCENE_DETECT);
1758    const char *prev_str = get(KEY_QC_SCENE_DETECT);
1759    if (str != NULL) {
1760        if (prev_str == NULL ||
1761            strcmp(str, prev_str) != 0) {
1762            return setSceneDetect(str);
1763        }
1764    }
1765    return NO_ERROR;
1766}
1767
1768/*===========================================================================
1769 * FUNCTION   : setVideoHDR
1770 *
1771 * DESCRIPTION: set video HDR value from user setting
1772 *
1773 * PARAMETERS :
1774 *   @params  : user setting parameters
1775 *
1776 * RETURN     : int32_t type of status
1777 *              NO_ERROR  -- success
1778 *              none-zero failure code
1779 *==========================================================================*/
1780int32_t QCameraParameters::setVideoHDR(const QCameraParameters& params)
1781{
1782    const char *str = params.get(KEY_QC_VIDEO_HDR);
1783    const char *prev_str = get(KEY_QC_VIDEO_HDR);
1784    if (str != NULL) {
1785        if (prev_str == NULL ||
1786            strcmp(str, prev_str) != 0) {
1787            return setVideoHDR(str);
1788        }
1789    }
1790    return NO_ERROR;
1791}
1792
1793/*===========================================================================
1794 * FUNCTION   : setFaceRecognition
1795 *
1796 * DESCRIPTION: set face recognition mode from user setting
1797 *
1798 * PARAMETERS :
1799 *   @params  : user setting parameters
1800 *
1801 * RETURN     : int32_t type of status
1802 *              NO_ERROR  -- success
1803 *              none-zero failure code
1804 *==========================================================================*/
1805int32_t QCameraParameters::setFaceRecognition(const QCameraParameters& params)
1806{
1807    const char *str = params.get(KEY_QC_FACE_RECOGNITION);
1808    const char *prev_str = get(KEY_QC_FACE_RECOGNITION);
1809    if (str != NULL) {
1810        if (prev_str == NULL ||
1811            strcmp(str, prev_str) != 0) {
1812            int maxFaces = params.getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
1813            return setFaceRecognition(str, maxFaces);
1814        }
1815    }
1816    return NO_ERROR;
1817}
1818
1819/*===========================================================================
1820 * FUNCTION   : setZoom
1821 *
1822 * DESCRIPTION: set zoom value from user setting
1823 *
1824 * PARAMETERS :
1825 *   @params  : user setting parameters
1826 *
1827 * RETURN     : int32_t type of status
1828 *              NO_ERROR  -- success
1829 *              none-zero failure code
1830 *==========================================================================*/
1831int32_t QCameraParameters::setZoom(const QCameraParameters& params)
1832{
1833    if ((m_pCapability->zoom_supported == 0 ||
1834         m_pCapability->zoom_ratio_tbl_cnt == 0)) {
1835        ALOGD("%s: no zoom support", __func__);
1836        return NO_ERROR;
1837    }
1838
1839    int zoomLevel = params.getInt(KEY_ZOOM);
1840    if((zoomLevel < 0) ||
1841       (zoomLevel >= m_pCapability->zoom_ratio_tbl_cnt)) {
1842        ALOGE("%s: invalid value %d out of (%d, %d)",
1843              __func__, zoomLevel,
1844              0, m_pCapability->zoom_ratio_tbl_cnt-1);
1845        return BAD_VALUE;
1846    }
1847
1848    int prevZoomLevel = getInt(KEY_ZOOM);
1849    if (prevZoomLevel == zoomLevel) {
1850        ALOGV("%s: No value change in contrast", __func__);
1851        return NO_ERROR;
1852    }
1853
1854    return setZoom(zoomLevel);
1855}
1856
1857/*===========================================================================
1858 * FUNCTION   : setISOValue
1859 *
1860 * DESCRIPTION: set ISO value from user setting
1861 *
1862 * PARAMETERS :
1863 *   @params  : user setting parameters
1864 *
1865 * RETURN     : int32_t type of status
1866 *              NO_ERROR  -- success
1867 *              none-zero failure code
1868 *==========================================================================*/
1869int32_t  QCameraParameters::setISOValue(const QCameraParameters& params)
1870{
1871    const char *str = params.get(KEY_QC_ISO_MODE);
1872    const char *prev_str = get(KEY_QC_ISO_MODE);
1873    if (str != NULL) {
1874        if (prev_str == NULL ||
1875            strcmp(str, prev_str) != 0) {
1876            return setISOValue(str);
1877        }
1878    }
1879    return NO_ERROR;
1880}
1881
1882/*===========================================================================
1883 * FUNCTION   : setRotation
1884 *
1885 * DESCRIPTION: set rotation value from user setting
1886 *
1887 * PARAMETERS :
1888 *   @params  : user setting parameters
1889 *
1890 * RETURN     : int32_t type of status
1891 *              NO_ERROR  -- success
1892 *              none-zero failure code
1893 *==========================================================================*/
1894int32_t QCameraParameters::setRotation(const QCameraParameters& params)
1895{
1896    int rotation = params.getInt(KEY_ROTATION);
1897    if (rotation != -1) {
1898        if (rotation == 0 || rotation == 90 ||
1899            rotation == 180 || rotation == 270) {
1900            set(KEY_ROTATION, rotation);
1901        } else {
1902            ALOGE("Invalid rotation value: %d", rotation);
1903            return BAD_VALUE;
1904        }
1905    }
1906    return NO_ERROR;
1907}
1908
1909/*===========================================================================
1910 * FUNCTION   : setFlash
1911 *
1912 * DESCRIPTION: set flash mode from user setting
1913 *
1914 * PARAMETERS :
1915 *   @params  : user setting parameters
1916 *
1917 * RETURN     : int32_t type of status
1918 *              NO_ERROR  -- success
1919 *              none-zero failure code
1920 *==========================================================================*/
1921int32_t QCameraParameters::setFlash(const QCameraParameters& params)
1922{
1923    const char *str = params.get(KEY_FLASH_MODE);
1924    const char *prev_str = get(KEY_FLASH_MODE);
1925    if (str != NULL) {
1926        if (prev_str == NULL ||
1927            strcmp(str, prev_str) != 0) {
1928            return setFlash(str);
1929        }
1930    }
1931    return NO_ERROR;
1932}
1933
1934/*===========================================================================
1935 * FUNCTION   : setAecLock
1936 *
1937 * DESCRIPTION: set AEC lock value from user setting
1938 *
1939 * PARAMETERS :
1940 *   @params  : user setting parameters
1941 *
1942 * RETURN     : int32_t type of status
1943 *              NO_ERROR  -- success
1944 *              none-zero failure code
1945 *==========================================================================*/
1946int32_t QCameraParameters::setAecLock(const QCameraParameters& params)
1947{
1948    const char *str = params.get(KEY_AUTO_EXPOSURE_LOCK);
1949    const char *prev_str = get(KEY_AUTO_EXPOSURE_LOCK);
1950    if (str != NULL) {
1951        if (prev_str == NULL ||
1952            strcmp(str, prev_str) != 0) {
1953            return setAecLock(str);
1954        }
1955    }
1956    return NO_ERROR;
1957}
1958
1959/*===========================================================================
1960 * FUNCTION   : setAwbLock
1961 *
1962 * DESCRIPTION: set AWB lock from user setting
1963 *
1964 * PARAMETERS :
1965 *   @params  : user setting parameters
1966 *
1967 * RETURN     : int32_t type of status
1968 *              NO_ERROR  -- success
1969 *              none-zero failure code
1970 *==========================================================================*/
1971int32_t QCameraParameters::setAwbLock(const QCameraParameters& params)
1972{
1973    const char *str = params.get(KEY_AUTO_WHITEBALANCE_LOCK);
1974    const char *prev_str = get(KEY_AUTO_WHITEBALANCE_LOCK);
1975    if (str != NULL) {
1976        if (prev_str == NULL ||
1977            strcmp(str, prev_str) != 0) {
1978            return setAwbLock(str);
1979        }
1980    }
1981    return NO_ERROR;
1982}
1983
1984/*===========================================================================
1985 * FUNCTION   : setMCEValue
1986 *
1987 * DESCRIPTION: set memory color enhancement value from user setting
1988 *
1989 * PARAMETERS :
1990 *   @params  : user setting parameters
1991 *
1992 * RETURN     : int32_t type of status
1993 *              NO_ERROR  -- success
1994 *              none-zero failure code
1995 *==========================================================================*/
1996int32_t QCameraParameters::setMCEValue(const QCameraParameters& params)
1997{
1998    const char *str = params.get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
1999    const char *prev_str = get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
2000    if (str != NULL) {
2001        if (prev_str == NULL ||
2002            strcmp(str, prev_str) != 0) {
2003            return setMCEValue(str);
2004        }
2005    }
2006    return NO_ERROR;
2007}
2008
2009/*===========================================================================
2010 * FUNCTION   : setDISValue
2011 *
2012 * DESCRIPTION: enable/disable DIS from user setting
2013 *
2014 * PARAMETERS :
2015 *   @params  : user setting parameters
2016 *
2017 * RETURN     : int32_t type of status
2018 *              NO_ERROR  -- success
2019 *              none-zero failure code
2020 *==========================================================================*/
2021int32_t QCameraParameters::setDISValue(const QCameraParameters& params)
2022{
2023    const char *str = params.get(KEY_QC_DIS);
2024    const char *prev_str = get(KEY_QC_DIS);
2025    if (str != NULL) {
2026        if (prev_str == NULL ||
2027            strcmp(str, prev_str) != 0) {
2028            return setDISValue(str);
2029        }
2030    }
2031    return NO_ERROR;
2032}
2033
2034/*===========================================================================
2035 * FUNCTION   : setHighFrameRate
2036 *
2037 * DESCRIPTION: set hight frame rate value from user setting
2038 *
2039 * PARAMETERS :
2040 *   @params  : user setting parameters
2041 *
2042 * RETURN     : int32_t type of status
2043 *              NO_ERROR  -- success
2044 *              none-zero failure code
2045 *==========================================================================*/
2046int32_t QCameraParameters::setHighFrameRate(const QCameraParameters& params)
2047{
2048    const char *str = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
2049    const char *prev_str = get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
2050    if (str != NULL) {
2051        if (prev_str == NULL ||
2052            strcmp(str, prev_str) != 0) {
2053            return setHighFrameRate(str);
2054        }
2055    }
2056    return NO_ERROR;
2057}
2058
2059/*===========================================================================
2060 * FUNCTION   : setLensShadeValue
2061 *
2062 * DESCRIPTION: set lens shade value from user setting
2063 *
2064 * PARAMETERS :
2065 *   @params  : user setting parameters
2066 *
2067 * RETURN     : int32_t type of status
2068 *              NO_ERROR  -- success
2069 *              none-zero failure code
2070 *==========================================================================*/
2071int32_t QCameraParameters::setLensShadeValue(const QCameraParameters& params)
2072{
2073    const char *str = params.get(KEY_QC_LENSSHADE);
2074    const char *prev_str = get(KEY_QC_LENSSHADE);
2075    if (str != NULL) {
2076        if (prev_str == NULL ||
2077            strcmp(str, prev_str) != 0) {
2078            return setLensShadeValue(str);
2079        }
2080    }
2081    return NO_ERROR;
2082}
2083
2084/*===========================================================================
2085 * FUNCTION   : setFocusAreas
2086 *
2087 * DESCRIPTION: set focus areas from user setting
2088 *
2089 * PARAMETERS :
2090 *   @params  : user setting parameters
2091 *
2092 * RETURN     : int32_t type of status
2093 *              NO_ERROR  -- success
2094 *              none-zero failure code
2095 *==========================================================================*/
2096int32_t QCameraParameters::setFocusAreas(const QCameraParameters& params)
2097{
2098    const char *str = params.get(KEY_FOCUS_AREAS);
2099    if (str != NULL) {
2100        int max_num_af_areas = getInt(KEY_MAX_NUM_FOCUS_AREAS);
2101        if(max_num_af_areas == 0) {
2102            ALOGE("%s: max num of AF area is 0, cannot set focus areas", __func__);
2103            return BAD_VALUE;
2104        }
2105
2106        const char *prev_str = get(KEY_FOCUS_AREAS);
2107        if (prev_str == NULL ||
2108            strcmp(str, prev_str) != 0) {
2109            return setFocusAreas(str);
2110        }
2111    }
2112    return NO_ERROR;
2113}
2114
2115/*===========================================================================
2116 * FUNCTION   : setMeteringAreas
2117 *
2118 * DESCRIPTION: set metering areas from user setting
2119 *
2120 * PARAMETERS :
2121 *   @params  : user setting parameters
2122 *
2123 * RETURN     : int32_t type of status
2124 *              NO_ERROR  -- success
2125 *              none-zero failure code
2126 *==========================================================================*/
2127int32_t QCameraParameters::setMeteringAreas(const QCameraParameters& params)
2128{
2129    const char *str = params.get(KEY_METERING_AREAS);
2130    if (str != NULL) {
2131        int max_num_mtr_areas = getInt(KEY_MAX_NUM_METERING_AREAS);
2132        if(max_num_mtr_areas == 0) {
2133            ALOGE("%s: max num of metering areas is 0, cannot set focus areas", __func__);
2134            return BAD_VALUE;
2135        }
2136
2137        const char *prev_str = get(KEY_METERING_AREAS);
2138        if (prev_str == NULL ||
2139            strcmp(str, prev_str) != 0) {
2140            return setMeteringAreas(str);
2141        }
2142    }
2143    return NO_ERROR;
2144}
2145
2146/*===========================================================================
2147 * FUNCTION   : setSceneMode
2148 *
2149 * DESCRIPTION: set scenen mode from user setting
2150 *
2151 * PARAMETERS :
2152 *   @params  : user setting parameters
2153 *
2154 * RETURN     : int32_t type of status
2155 *              NO_ERROR  -- success
2156 *              none-zero failure code
2157 *==========================================================================*/
2158int32_t QCameraParameters::setSceneMode(const QCameraParameters& params)
2159{
2160    const char *str = params.get(KEY_SCENE_MODE);
2161    const char *prev_str = get(KEY_SCENE_MODE);
2162    if (str != NULL) {
2163        if (prev_str == NULL ||
2164            strcmp(str, prev_str) != 0) {
2165            if ((strcmp(str, SCENE_MODE_HDR) == 0) ||
2166                ((prev_str != NULL) && (strcmp(prev_str, SCENE_MODE_HDR) == 0))) {
2167                ALOGD("%s: scene mode changed between HDR and non-HDR, need restart", __func__);
2168                m_bNeedRestart = true;
2169
2170                // set if hdr 1x image is needed
2171                const char *need_hdr_1x = params.get(KEY_QC_HDR_NEED_1X);
2172                int32_t value = 0;
2173                if (need_hdr_1x != NULL && strcmp(need_hdr_1x, VALUE_TRUE) == 0) {
2174                    value = 1;
2175                    updateParamEntry(KEY_QC_HDR_NEED_1X, need_hdr_1x);
2176                    AddSetParmEntryToBatch(m_pParamBuf,
2177                                           CAM_INTF_PARM_HDR_NEED_1X,
2178                                           sizeof(value),
2179                                           &value);
2180                }
2181            }
2182            return setSceneMode(str);
2183        }
2184    }
2185    return NO_ERROR;
2186}
2187
2188/*===========================================================================
2189 * FUNCTION   : setSelectableZoneAf
2190 *
2191 * DESCRIPTION: set selectable zone auto focus value from user setting
2192 *
2193 * PARAMETERS :
2194 *   @params  : user setting parameters
2195 *
2196 * RETURN     : int32_t type of status
2197 *              NO_ERROR  -- success
2198 *              none-zero failure code
2199 *==========================================================================*/
2200int32_t QCameraParameters::setSelectableZoneAf(const QCameraParameters& params)
2201{
2202    const char *str = params.get(KEY_QC_SELECTABLE_ZONE_AF);
2203    const char *prev_str = get(KEY_QC_SELECTABLE_ZONE_AF);
2204    if (str != NULL) {
2205        if (prev_str == NULL ||
2206            strcmp(str, prev_str) != 0) {
2207            return setSelectableZoneAf(str);
2208        }
2209    }
2210    return NO_ERROR;
2211}
2212
2213/*===========================================================================
2214 * FUNCTION   : setAEBracket
2215 *
2216 * DESCRIPTION: set AE bracket from user setting
2217 *
2218 * PARAMETERS :
2219 *   @params  : user setting parameters
2220 *
2221 * RETURN     : int32_t type of status
2222 *              NO_ERROR  -- success
2223 *              none-zero failure code
2224 *==========================================================================*/
2225int32_t QCameraParameters::setAEBracket(const QCameraParameters& params)
2226{
2227    const char *scene_mode = params.get(KEY_SCENE_MODE);
2228    if (scene_mode != NULL && strcmp(scene_mode, SCENE_MODE_HDR) == 0) {
2229        ALOGE("%s: scene mode is HDR, overwrite AE bracket setting to off", __func__);
2230        return setAEBracket(AE_BRACKET_OFF);
2231    }
2232
2233    const char *expStr = params.get(KEY_QC_CAPTURE_BURST_EXPOSURE);
2234    if (NULL != expStr && strlen(expStr) > 0) {
2235        set(KEY_QC_CAPTURE_BURST_EXPOSURE, expStr);
2236    } else {
2237        char prop[PROPERTY_VALUE_MAX];
2238        memset(prop, 0, sizeof(prop));
2239        property_get("persist.capture.burst.exposures", prop, "");
2240        if (strlen(prop) > 0) {
2241            set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
2242        } else {
2243            remove(KEY_QC_CAPTURE_BURST_EXPOSURE);
2244        }
2245    }
2246
2247    const char *str = params.get(KEY_QC_AE_BRACKET_HDR);
2248    const char *prev_str = get(KEY_QC_AE_BRACKET_HDR);
2249    if (str != NULL) {
2250        if (prev_str == NULL ||
2251            strcmp(str, prev_str) != 0) {
2252            return setAEBracket(str);
2253        }
2254    }
2255    return NO_ERROR;
2256}
2257
2258/*===========================================================================
2259 * FUNCTION   : setRedeyeReduction
2260 *
2261 * DESCRIPTION: set red eye reduction setting from user setting
2262 *
2263 * PARAMETERS :
2264 *   @params  : user setting parameters
2265 *
2266 * RETURN     : int32_t type of status
2267 *              NO_ERROR  -- success
2268 *              none-zero failure code
2269 *==========================================================================*/
2270int32_t QCameraParameters::setRedeyeReduction(const QCameraParameters& params)
2271{
2272    const char *str = params.get(KEY_QC_REDEYE_REDUCTION);
2273    const char *prev_str = get(KEY_QC_REDEYE_REDUCTION);
2274    if (str != NULL) {
2275        if (prev_str == NULL ||
2276            strcmp(str, prev_str) != 0) {
2277            return setRedeyeReduction(str);
2278        }
2279    }
2280    return NO_ERROR;
2281}
2282
2283/*===========================================================================
2284 * FUNCTION   : setGpsLocation
2285 *
2286 * DESCRIPTION: set GPS location information from user setting
2287 *
2288 * PARAMETERS :
2289 *   @params  : user setting parameters
2290 *
2291 * RETURN     : int32_t type of status
2292 *              NO_ERROR  -- success
2293 *              none-zero failure code
2294 *==========================================================================*/
2295int32_t QCameraParameters::setGpsLocation(const QCameraParameters& params)
2296{
2297    const char *method = params.get(KEY_GPS_PROCESSING_METHOD);
2298    if (method) {
2299        set(KEY_GPS_PROCESSING_METHOD, method);
2300    }else {
2301        remove(KEY_GPS_PROCESSING_METHOD);
2302    }
2303
2304    const char *latitude = params.get(KEY_GPS_LATITUDE);
2305    if (latitude) {
2306        set(KEY_GPS_LATITUDE, latitude);
2307    }else {
2308        remove(KEY_GPS_LATITUDE);
2309    }
2310
2311    const char *latitudeRef = params.get(KEY_QC_GPS_LATITUDE_REF);
2312    if (latitudeRef) {
2313        set(KEY_QC_GPS_LATITUDE_REF, latitudeRef);
2314    }else {
2315        remove(KEY_QC_GPS_LATITUDE_REF);
2316    }
2317
2318    const char *longitude = params.get(KEY_GPS_LONGITUDE);
2319    if (longitude) {
2320        set(KEY_GPS_LONGITUDE, longitude);
2321    }else {
2322        remove(KEY_GPS_LONGITUDE);
2323    }
2324
2325    const char *longitudeRef = params.get(KEY_QC_GPS_LONGITUDE_REF);
2326    if (longitudeRef) {
2327        set(KEY_QC_GPS_LONGITUDE_REF, longitudeRef);
2328    }else {
2329        remove(KEY_QC_GPS_LONGITUDE_REF);
2330    }
2331
2332    const char *altitudeRef = params.get(KEY_QC_GPS_ALTITUDE_REF);
2333    if (altitudeRef) {
2334        set(KEY_QC_GPS_ALTITUDE_REF, altitudeRef);
2335    }else {
2336        remove(KEY_QC_GPS_ALTITUDE_REF);
2337    }
2338
2339    const char *altitude = params.get(KEY_GPS_ALTITUDE);
2340    if (altitude) {
2341        set(KEY_GPS_ALTITUDE, altitude);
2342    }else {
2343        remove(KEY_GPS_ALTITUDE);
2344    }
2345
2346    const char *status = params.get(KEY_QC_GPS_STATUS);
2347    if (status) {
2348        set(KEY_QC_GPS_STATUS, status);
2349    } else {
2350        remove(KEY_QC_GPS_STATUS);
2351    }
2352
2353    const char *timestamp = params.get(KEY_GPS_TIMESTAMP);
2354    if (timestamp) {
2355        set(KEY_GPS_TIMESTAMP, timestamp);
2356    }else {
2357        remove(KEY_GPS_TIMESTAMP);
2358    }
2359    return NO_ERROR;
2360}
2361
2362/*===========================================================================
2363 * FUNCTION   : setNumOfSnapshot
2364 *
2365 * DESCRIPTION: set number of snapshot per shutter from user setting
2366 *
2367 * PARAMETERS : none
2368 *
2369 * RETURN     : int32_t type of status
2370 *              NO_ERROR  -- success
2371 *              none-zero failure code
2372 *==========================================================================*/
2373int32_t QCameraParameters::setNumOfSnapshot()
2374{
2375    int nBurstNum = getBurstNum();
2376    uint8_t nExpnum = 0;
2377
2378    const char *scene_mode = get(KEY_SCENE_MODE);
2379    if (scene_mode != NULL && strcmp(scene_mode, SCENE_MODE_HDR) == 0) {
2380        /* According to Android SDK, only one snapshot,
2381         * but OEM might have different requirement */
2382        const char *need_hdr_1x = get(KEY_QC_HDR_NEED_1X);
2383        if (need_hdr_1x != NULL && strcmp(need_hdr_1x, VALUE_TRUE) == 0) {
2384            nExpnum = 2; // HDR needs both 1X and processed img
2385        } else {
2386            nExpnum = 1; // HDR only needs processed img
2387        }
2388    } else {
2389        const char *bracket_str = get(KEY_QC_AE_BRACKET_HDR);
2390        if (bracket_str != NULL && strlen(bracket_str) > 0) {
2391            int value = lookupAttr(BRACKETING_MODES_MAP,
2392                                   sizeof(BRACKETING_MODES_MAP)/sizeof(QCameraMap),
2393                                   bracket_str);
2394            switch (value) {
2395            case CAM_EXP_BRACKETING_ON:
2396                {
2397                    nExpnum = 0;
2398                    const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
2399                    if ((str_val != NULL) && (strlen(str_val) > 0)) {
2400                        char prop[PROPERTY_VALUE_MAX];
2401                        memset(prop, 0, sizeof(prop));
2402                        strcpy(prop, str_val);
2403                        char *saveptr = NULL;
2404                        char *token = strtok_r(prop, ",", &saveptr);
2405                        while (token != NULL) {
2406                            token = strtok_r(NULL, ",", &saveptr);
2407                            nExpnum++;
2408                        }
2409                    }
2410                    if (nExpnum == 0) {
2411                        nExpnum = 1;
2412                    }
2413                }
2414                break;
2415            default:
2416                nExpnum = 1;
2417                break;
2418            }
2419        }
2420    }
2421
2422    ALOGD("%s: nBurstNum = %d, nExpnum = %d", __func__, nBurstNum, nExpnum);
2423    set(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER, nBurstNum * nExpnum);
2424    return NO_ERROR;
2425}
2426
2427/*===========================================================================
2428 * FUNCTION   : setRecordingHint
2429 *
2430 * DESCRIPTION: set recording hint value from user setting
2431 *
2432 * PARAMETERS :
2433 *   @params  : user setting parameters
2434 *
2435 * RETURN     : int32_t type of status
2436 *              NO_ERROR  -- success
2437 *              none-zero failure code
2438 *==========================================================================*/
2439int32_t QCameraParameters::setRecordingHint(const QCameraParameters& params)
2440{
2441    const char * str = params.get(KEY_RECORDING_HINT);
2442    const char *prev_str = get(KEY_RECORDING_HINT);
2443    if (str != NULL) {
2444        if (prev_str == NULL || strcmp(str, prev_str) != 0) {
2445            int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP,
2446                                       sizeof(TRUE_FALSE_MODES_MAP)/sizeof(QCameraMap),
2447                                       str);
2448            if(value != NAME_NOT_FOUND){
2449                updateParamEntry(KEY_RECORDING_HINT, str);
2450                setRecordingHintValue(value);
2451                return NO_ERROR;
2452            } else {
2453                ALOGE("Invalid recording hint value: %s", str);
2454                return BAD_VALUE;
2455            }
2456        }
2457    }
2458    return NO_ERROR;
2459}
2460
2461/*===========================================================================
2462 * FUNCTION   : setNoDisplayMode
2463 *
2464 * DESCRIPTION: set no display mode from user setting
2465 *
2466 * PARAMETERS :
2467 *   @params  : user setting parameters
2468 *
2469 * RETURN     : int32_t type of status
2470 *              NO_ERROR  -- success
2471 *              none-zero failure code
2472 *==========================================================================*/
2473int32_t QCameraParameters::setNoDisplayMode(const QCameraParameters& params)
2474{
2475    const char *str_val  = params.get(KEY_QC_NO_DISPLAY_MODE);
2476    const char *prev_str = get(KEY_QC_NO_DISPLAY_MODE);
2477    if(str_val && strlen(str_val) > 0) {
2478        if (prev_str == NULL || strcmp(str_val, prev_str) != 0) {
2479            m_bNoDisplayMode = atoi(str_val);
2480            updateParamEntry(KEY_QC_NO_DISPLAY_MODE, str_val);
2481            m_bNeedRestart = true;
2482        }
2483    } else {
2484        m_bNoDisplayMode = false;
2485    }
2486    ALOGD("Param m_bNoDisplayMode = %d", m_bNoDisplayMode);
2487    return NO_ERROR;
2488}
2489
2490/*===========================================================================
2491 * FUNCTION   : setZslMode
2492 *
2493 * DESCRIPTION: set ZSL mode from user setting
2494 *
2495 * PARAMETERS :
2496 *   @params  : user setting parameters
2497 *
2498 * RETURN     : int32_t type of status
2499 *              NO_ERROR  -- success
2500 *              none-zero failure code
2501 *==========================================================================*/
2502int32_t QCameraParameters::setZslMode(const QCameraParameters& params)
2503{
2504    const char *str_val  = params.get(KEY_QC_ZSL);
2505    const char *prev_val  = get(KEY_QC_ZSL);
2506
2507    if (str_val != NULL) {
2508        if (prev_val == NULL || strcmp(str_val, prev_val) != 0) {
2509            int32_t value = lookupAttr(ON_OFF_MODES_MAP,
2510                                       sizeof(ON_OFF_MODES_MAP)/sizeof(QCameraMap),
2511                                       str_val);
2512            if (value != NAME_NOT_FOUND) {
2513                updateParamEntry(KEY_QC_ZSL, str_val);
2514                m_bZslMode = (value > 0)? true : false;
2515
2516                // ZSL mode changed, need restart preview
2517                m_bNeedRestart = true;
2518
2519                return AddSetParmEntryToBatch(m_pParamBuf,
2520                                              CAM_INTF_PARM_ZSL_MODE,
2521                                              sizeof(value),
2522                                              &value);
2523            } else {
2524                ALOGE("Invalid ZSL mode value: %s", str_val);
2525                return BAD_VALUE;
2526            }
2527        }
2528    }
2529    return NO_ERROR;
2530}
2531
2532/*===========================================================================
2533 * FUNCTION   : setWaveletDenoise
2534 *
2535 * DESCRIPTION: set wavelet denoise value from user setting
2536 *
2537 * PARAMETERS :
2538 *   @params  : user setting parameters
2539 *
2540 * RETURN     : int32_t type of status
2541 *              NO_ERROR  -- success
2542 *              none-zero failure code
2543 *==========================================================================*/
2544int32_t QCameraParameters::setWaveletDenoise(const QCameraParameters& params)
2545{
2546    const char *str = params.get(KEY_QC_DENOISE);
2547    const char *prev_str = get(KEY_QC_DENOISE);
2548    if (str != NULL) {
2549        if (prev_str == NULL ||
2550            strcmp(str, prev_str) != 0) {
2551            return setWaveletDenoise(str);
2552        }
2553    }
2554    return NO_ERROR;
2555}
2556
2557/*===========================================================================
2558 * FUNCTION   : setCameraMode
2559 *
2560 * DESCRIPTION: set camera mode from user setting
2561 *
2562 * PARAMETERS :
2563 *   @params  : user setting parameters
2564 *
2565 * RETURN     : int32_t type of status
2566 *              NO_ERROR  -- success
2567 *              none-zero failure code
2568 *==========================================================================*/
2569int32_t QCameraParameters::setCameraMode(const QCameraParameters& params)
2570{
2571    const char *str = params.get(KEY_QC_CAMERA_MODE);
2572    if (str != NULL) {
2573        set(KEY_QC_CAMERA_MODE, str);
2574    } else {
2575        remove(KEY_QC_CAMERA_MODE);
2576    }
2577    return NO_ERROR;
2578}
2579
2580/*===========================================================================
2581 * FUNCTION   : setZslAttributes
2582 *
2583 * DESCRIPTION: set ZSL related attributes from user setting
2584 *
2585 * PARAMETERS :
2586 *   @params  : user setting parameters
2587 *
2588 * RETURN     : int32_t type of status
2589 *              NO_ERROR  -- success
2590 *              none-zero failure code
2591 *==========================================================================*/
2592int32_t QCameraParameters::setZslAttributes(const QCameraParameters& params)
2593{
2594    // TODO: may switch to pure param instead of sysprop
2595    char prop[32];
2596
2597    const char *str = params.get(KEY_QC_ZSL_BURST_INTERVAL);
2598    if (str != NULL) {
2599        set(KEY_QC_ZSL_BURST_INTERVAL, str);
2600    } else {
2601        memset(prop, 0, sizeof(prop));
2602        property_get("persist.camera.zsl.interval", prop, "1");
2603        set(KEY_QC_ZSL_BURST_INTERVAL, prop);
2604    }
2605
2606    str = params.get(KEY_QC_ZSL_BURST_LOOKBACK);
2607    if (str != NULL) {
2608        set(KEY_QC_ZSL_BURST_LOOKBACK, str);
2609    } else {
2610        memset(prop, 0, sizeof(prop));
2611        property_get("persist.camera.zsl.backlookcnt", prop, "2");
2612        set(KEY_QC_ZSL_BURST_LOOKBACK, prop);
2613    }
2614
2615    str = params.get(KEY_QC_ZSL_QUEUE_DEPTH);
2616    if (str != NULL) {
2617        set(KEY_QC_ZSL_QUEUE_DEPTH, str);
2618    } else {
2619        memset(prop, 0, sizeof(prop));
2620        property_get("persist.camera.zsl.queuedepth", prop, "2");
2621        set(KEY_QC_ZSL_QUEUE_DEPTH, prop);
2622    }
2623
2624    return NO_ERROR;
2625}
2626
2627/*===========================================================================
2628 * FUNCTION   : setFlip
2629 *
2630 * DESCRIPTION: set preview/ video/ picture flip mode from user setting
2631 *
2632 * PARAMETERS :
2633 *   @params  : user setting parameters
2634 *
2635 * RETURN     : int32_t type of status
2636 *              NO_ERROR  -- success
2637 *              none-zero failure code
2638 *==========================================================================*/
2639int32_t QCameraParameters::setFlip(const QCameraParameters& params)
2640{
2641    if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) == 0) {
2642        ALOGD("%s: flip is not supported.", __func__);
2643        return NO_ERROR;
2644    }
2645
2646    //check preview flip setting
2647    const char *str = params.get(KEY_QC_PREVIEW_FLIP);
2648    if(str != NULL){
2649        int32_t value = lookupAttr(FLIP_MODES_MAP,
2650                                   sizeof(FLIP_MODES_MAP)/sizeof(QCameraMap),
2651                                   str);
2652        if(value != NAME_NOT_FOUND){
2653            set(KEY_QC_PREVIEW_FLIP, str);
2654        }
2655    }
2656
2657    // check video filp setting
2658    str = params.get(KEY_QC_VIDEO_FLIP);
2659    if(str != NULL){
2660        int32_t value = lookupAttr(FLIP_MODES_MAP,
2661                                   sizeof(FLIP_MODES_MAP)/sizeof(QCameraMap),
2662                                   str);
2663        if(value != NAME_NOT_FOUND){
2664            set(KEY_QC_VIDEO_FLIP, str);
2665        }
2666    }
2667
2668    // check picture filp setting
2669    str = params.get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
2670    if(str != NULL){
2671        int32_t value = lookupAttr(FLIP_MODES_MAP,
2672                                   sizeof(FLIP_MODES_MAP)/sizeof(QCameraMap),
2673                                   str);
2674        if(value != NAME_NOT_FOUND){
2675            set(KEY_QC_SNAPSHOT_PICTURE_FLIP, str);
2676        }
2677    }
2678
2679    return NO_ERROR;
2680}
2681
2682/*===========================================================================
2683 * FUNCTION   : updateParameters
2684 *
2685 * DESCRIPTION: update parameters from user setting
2686 *
2687 * PARAMETERS :
2688 *   @params  : user setting parameters
2689 *   @needRestart : [output] if preview need restart upon setting changes
2690 *
2691 * RETURN     : int32_t type of status
2692 *              NO_ERROR  -- success
2693 *              none-zero failure code
2694 *==========================================================================*/
2695int32_t QCameraParameters::updateParameters(QCameraParameters& params,
2696                                            bool &needRestart)
2697{
2698    int32_t final_rc = NO_ERROR;
2699    int32_t rc;
2700    m_bNeedRestart = false;
2701
2702    if(initBatchUpdate(m_pParamBuf) < 0 ) {
2703        ALOGE("%s:Failed to initialize group update table",__func__);
2704        rc = BAD_TYPE;
2705        goto UPDATE_PARAM_DONE;
2706    }
2707
2708    if ((rc = setPreviewSize(params)))                  final_rc = rc;
2709    if ((rc = setVideoSize(params)))                    final_rc = rc;
2710    if ((rc = setPictureSize(params)))                  final_rc = rc;
2711    if ((rc = setPreviewFormat(params)))                final_rc = rc;
2712    if ((rc = setPictureFormat(params)))                final_rc = rc;
2713    if ((rc = setJpegThumbnailSize(params)))            final_rc = rc;
2714    if ((rc = setJpegQuality(params)))                  final_rc = rc;
2715    if ((rc = setOrientation(params)))                  final_rc = rc;
2716    if ((rc = setRotation(params)))                     final_rc = rc;
2717    if ((rc = setNoDisplayMode(params)))                final_rc = rc;
2718    if ((rc = setZslMode(params)))                      final_rc = rc;
2719    if ((rc = setZslAttributes(params)))                final_rc = rc;
2720    if ((rc = setCameraMode(params)))                   final_rc = rc;
2721    if ((rc = setRecordingHint(params)))                final_rc = rc;
2722
2723    if ((rc = setPreviewFpsRange(params)))              final_rc = rc;
2724    if ((rc = setPreviewFrameRate(params)))             final_rc = rc;
2725    if ((rc = setAutoExposure(params)))                 final_rc = rc;
2726    if ((rc = setEffect(params)))                       final_rc = rc;
2727    if ((rc = setBrightness(params)))                   final_rc = rc;
2728    if ((rc = setZoom(params)))                         final_rc = rc;
2729    if ((rc = setSharpness(params)))                    final_rc = rc;
2730    if ((rc = setSaturation(params)))                   final_rc = rc;
2731    if ((rc = setContrast(params)))                     final_rc = rc;
2732    if ((rc = setFocusMode(params)))                    final_rc = rc;
2733    if ((rc = setISOValue(params)))                     final_rc = rc;
2734    if ((rc = setSkinToneEnhancement(params)))          final_rc = rc;
2735    if ((rc = setFlash(params)))                        final_rc = rc;
2736    if ((rc = setAecLock(params)))                      final_rc = rc;
2737    if ((rc = setAwbLock(params)))                      final_rc = rc;
2738    if ((rc = setLensShadeValue(params)))               final_rc = rc;
2739    if ((rc = setMCEValue(params)))                     final_rc = rc;
2740    if ((rc = setDISValue(params)))                     final_rc = rc;
2741    if ((rc = setHighFrameRate(params)))                final_rc = rc;
2742    if ((rc = setAntibanding(params)))                  final_rc = rc;
2743    if ((rc = setExposureCompensation(params)))         final_rc = rc;
2744    if ((rc = setWhiteBalance(params)))                 final_rc = rc;
2745    if ((rc = setSceneMode(params)))                    final_rc = rc;
2746    if ((rc = setFocusAreas(params)))                   final_rc = rc;
2747    if ((rc = setMeteringAreas(params)))                final_rc = rc;
2748    if ((rc = setSelectableZoneAf(params)))             final_rc = rc;
2749    if ((rc = setRedeyeReduction(params)))              final_rc = rc;
2750    if ((rc = setAEBracket(params)))                    final_rc = rc;
2751    if ((rc = setGpsLocation(params)))                  final_rc = rc;
2752    if ((rc = setWaveletDenoise(params)))               final_rc = rc;
2753    if ((rc = setFaceRecognition(params)))              final_rc = rc;
2754    if ((rc = setFlip(params)))                         final_rc = rc;
2755    if ((rc = setVideoHDR(params)))                     final_rc = rc;
2756
2757    // update live snapshot size after all other parameters are set
2758    if ((rc = setLiveSnapshotSize(params)))             final_rc = rc;
2759
2760UPDATE_PARAM_DONE:
2761    needRestart = m_bNeedRestart;
2762    return final_rc;
2763}
2764
2765/*===========================================================================
2766 * FUNCTION   : commitParameters
2767 *
2768 * DESCRIPTION: commit parameter changes to backend
2769 *
2770 * PARAMETERS : none
2771 *
2772 * RETURN     : int32_t type of status
2773 *              NO_ERROR  -- success
2774 *              none-zero failure code
2775 *==========================================================================*/
2776int32_t QCameraParameters::commitParameters()
2777{
2778    return commitSetBatch();
2779}
2780
2781/*===========================================================================
2782 * FUNCTION   : initDefaultParameters
2783 *
2784 * DESCRIPTION: initialize default parameters for the first time
2785 *
2786 * PARAMETERS : none
2787 *
2788 * RETURN     : int32_t type of status
2789 *              NO_ERROR  -- success
2790 *              none-zero failure code
2791 *==========================================================================*/
2792int32_t QCameraParameters::initDefaultParameters()
2793{
2794    if(initBatchUpdate(m_pParamBuf) < 0 ) {
2795        ALOGE("%s:Failed to initialize group update table", __func__);
2796        return BAD_TYPE;
2797    }
2798
2799    /*************************Initialize Values******************************/
2800    // Set read only parameters from camera capability
2801    set(KEY_SMOOTH_ZOOM_SUPPORTED,
2802        m_pCapability->smooth_zoom_supported? VALUE_TRUE : VALUE_FALSE);
2803    set(KEY_ZOOM_SUPPORTED,
2804        m_pCapability->zoom_supported? VALUE_TRUE : VALUE_FALSE);
2805    set(KEY_VIDEO_SNAPSHOT_SUPPORTED,
2806        m_pCapability->video_snapshot_supported? VALUE_TRUE : VALUE_FALSE);
2807    set(KEY_VIDEO_STABILIZATION_SUPPORTED,
2808        m_pCapability->video_stablization_supported? VALUE_TRUE : VALUE_FALSE);
2809    set(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED,
2810        m_pCapability->auto_exposure_lock_supported? VALUE_TRUE : VALUE_FALSE);
2811    set(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED,
2812        m_pCapability->auto_wb_lock_supported? VALUE_TRUE : VALUE_FALSE);
2813    set(KEY_QC_SUPPORTED_CAMERA_FEATURES,
2814        m_pCapability->qcom_supported_feature_mask);
2815    set(KEY_MAX_NUM_DETECTED_FACES_HW, m_pCapability->max_num_roi);
2816    set(KEY_MAX_NUM_DETECTED_FACES_SW, m_pCapability->max_num_roi);
2817    set(KEY_QC_MAX_NUM_REQUESTED_FACES, m_pCapability->max_num_roi);
2818    // Set focal length, horizontal view angle, and vertical view angle
2819    setFloat(KEY_FOCAL_LENGTH, m_pCapability->focal_length);
2820    setFloat(KEY_HORIZONTAL_VIEW_ANGLE, m_pCapability->hor_view_angle);
2821    setFloat(KEY_VERTICAL_VIEW_ANGLE, m_pCapability->ver_view_angle);
2822
2823    // Set supported preview sizes
2824    if (m_pCapability->preview_sizes_tbl_cnt > 0 &&
2825        m_pCapability->preview_sizes_tbl_cnt <= MAX_SIZES_CNT) {
2826        String8 previewSizeValues = createSizesString(
2827                m_pCapability->preview_sizes_tbl, m_pCapability->preview_sizes_tbl_cnt);
2828        set(KEY_SUPPORTED_PREVIEW_SIZES, previewSizeValues.string());
2829        ALOGD("%s: supported preview sizes: %s", __func__, previewSizeValues.string());
2830        // Set default preview size
2831        CameraParameters::setPreviewSize(m_pCapability->preview_sizes_tbl[0].width,
2832                                         m_pCapability->preview_sizes_tbl[0].height);
2833    } else {
2834        ALOGE("%s: supported preview sizes cnt is 0 or exceeds max!!!", __func__);
2835    }
2836
2837    // Set supported video sizes
2838    if (m_pCapability->video_sizes_tbl_cnt > 0 &&
2839        m_pCapability->video_sizes_tbl_cnt <= MAX_SIZES_CNT) {
2840        String8 videoSizeValues = createSizesString(
2841                m_pCapability->video_sizes_tbl, m_pCapability->video_sizes_tbl_cnt);
2842        set(KEY_SUPPORTED_VIDEO_SIZES, videoSizeValues.string());
2843        ALOGD("%s: supported video sizes: %s", __func__, videoSizeValues.string());
2844        // Set default video size
2845        CameraParameters::setVideoSize(m_pCapability->video_sizes_tbl[0].width,
2846                                       m_pCapability->video_sizes_tbl[0].height);
2847
2848        //Set preferred Preview size for video
2849        String8 vSize = createSizesString(&m_pCapability->video_sizes_tbl[0], 1);
2850        set(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO, vSize.string());
2851    } else {
2852        ALOGE("%s: supported video sizes cnt is 0 or exceeds max!!!", __func__);
2853    }
2854
2855    // Set supported picture sizes
2856    if (m_pCapability->picture_sizes_tbl_cnt > 0 &&
2857        m_pCapability->picture_sizes_tbl_cnt <= MAX_SIZES_CNT) {
2858        String8 pictureSizeValues = createSizesString(
2859                m_pCapability->picture_sizes_tbl, m_pCapability->picture_sizes_tbl_cnt);
2860        set(KEY_SUPPORTED_PICTURE_SIZES, pictureSizeValues.string());
2861        ALOGD("%s: supported pic sizes: %s", __func__, pictureSizeValues.string());
2862        // Set default picture size to the smallest resolution
2863        CameraParameters::setPictureSize(
2864           m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].width,
2865           m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].height);
2866    } else {
2867        ALOGE("%s: supported picture sizes cnt is 0 or exceeds max!!!", __func__);
2868    }
2869
2870    // Set supported thumbnail sizes
2871    String8 thumbnailSizeValues = createSizesString(
2872            THUMBNAIL_SIZES_MAP,
2873            sizeof(THUMBNAIL_SIZES_MAP)/sizeof(cam_dimension_t));
2874    set(KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, thumbnailSizeValues.string());
2875    // Set default thumnail size
2876    set(KEY_JPEG_THUMBNAIL_WIDTH, THUMBNAIL_SIZES_MAP[0].width);
2877    set(KEY_JPEG_THUMBNAIL_HEIGHT, THUMBNAIL_SIZES_MAP[0].height);
2878
2879    // Set supported livesnapshot sizes
2880    if (m_pCapability->livesnapshot_sizes_tbl_cnt > 0 &&
2881        m_pCapability->livesnapshot_sizes_tbl_cnt <= MAX_SIZES_CNT) {
2882        String8 liveSnpashotSizeValues = createSizesString(
2883                m_pCapability->livesnapshot_sizes_tbl,
2884                m_pCapability->livesnapshot_sizes_tbl_cnt);
2885        set(KEY_QC_SUPPORTED_LIVESNAPSHOT_SIZES, liveSnpashotSizeValues.string());
2886        ALOGI("%s: supported live snapshot sizes: %s", __func__, liveSnpashotSizeValues.string());
2887        m_LiveSnapshotSize =
2888            m_pCapability->livesnapshot_sizes_tbl[m_pCapability->livesnapshot_sizes_tbl_cnt-1];
2889    }
2890
2891    // Set supported preview formats
2892    String8 previewFormatValues = createValuesString(
2893            (int *)m_pCapability->supported_preview_fmts,
2894            m_pCapability->supported_preview_fmt_cnt,
2895            PREVIEW_FORMATS_MAP,
2896            sizeof(PREVIEW_FORMATS_MAP)/sizeof(QCameraMap));
2897    set(KEY_SUPPORTED_PREVIEW_FORMATS, previewFormatValues.string());
2898    // Set default preview format
2899    CameraParameters::setPreviewFormat(PIXEL_FORMAT_YUV420SP);
2900
2901    // Set default Video Format
2902    set(KEY_VIDEO_FRAME_FORMAT, PIXEL_FORMAT_YUV420SP);
2903
2904    // Set supported picture formats
2905    String8 pictureTypeValues(PIXEL_FORMAT_JPEG);
2906    String8 str = createValuesString(
2907            (int *)m_pCapability->supported_raw_fmts,
2908            m_pCapability->supported_raw_fmt_cnt,
2909            PICTURE_TYPES_MAP,
2910            sizeof(PICTURE_TYPES_MAP)/sizeof(QCameraMap));
2911    if (str.string() != NULL) {
2912        pictureTypeValues.append(",");
2913        pictureTypeValues.append(str);
2914    }
2915
2916    set(KEY_SUPPORTED_PICTURE_FORMATS, pictureTypeValues.string());
2917    // Set default picture Format
2918    CameraParameters::setPictureFormat(PIXEL_FORMAT_JPEG);
2919    // Set raw image size
2920    char raw_size_str[32];
2921    snprintf(raw_size_str, sizeof(raw_size_str), "%dx%d",
2922             m_pCapability->raw_dim.width, m_pCapability->raw_dim.height);
2923    set(KEY_QC_RAW_PICUTRE_SIZE, raw_size_str);
2924
2925    //set default jpeg quality and thumbnail quality
2926    set(KEY_JPEG_QUALITY, 85);
2927    set(KEY_JPEG_THUMBNAIL_QUALITY, 85);
2928
2929    // Set FPS ranges
2930    if (m_pCapability->fps_ranges_tbl_cnt > 0 &&
2931        m_pCapability->fps_ranges_tbl_cnt <= MAX_SIZES_CNT) {
2932        int default_fps_index = 0;
2933        String8 fpsRangeValues = createFpsRangeString(m_pCapability->fps_ranges_tbl,
2934                                                      m_pCapability->fps_ranges_tbl_cnt,
2935                                                      default_fps_index);
2936        set(KEY_SUPPORTED_PREVIEW_FPS_RANGE, fpsRangeValues.string());
2937
2938        int min_fps =
2939            int(m_pCapability->fps_ranges_tbl[default_fps_index].min_fps * 1000);
2940        int max_fps =
2941            int(m_pCapability->fps_ranges_tbl[default_fps_index].max_fps * 1000);
2942        setPreviewFpsRange(min_fps, max_fps);
2943
2944        // Set legacy preview fps
2945        String8 fpsValues = createFpsString(m_pCapability->fps_ranges_tbl,
2946                                            m_pCapability->fps_ranges_tbl_cnt);
2947        set(KEY_SUPPORTED_PREVIEW_FRAME_RATES, fpsValues.string());
2948        CameraParameters::setPreviewFrameRate(max_fps);
2949    } else {
2950        ALOGE("%s: supported fps ranges cnt is 0 or exceeds max!!!", __func__);
2951    }
2952
2953    // Set supported focus modes
2954    if (m_pCapability->supported_focus_modes_cnt > 0) {
2955        String8 focusModeValues = createValuesString(
2956                (int *)m_pCapability->supported_focus_modes,
2957                m_pCapability->supported_focus_modes_cnt,
2958                FOCUS_MODES_MAP,
2959                sizeof(FOCUS_MODES_MAP)/sizeof(QCameraMap));
2960        set(KEY_SUPPORTED_FOCUS_MODES, focusModeValues);
2961
2962        // Set default focus mode and update corresponding parameter buf
2963        const char *focusMode = lookupNameByValue(FOCUS_MODES_MAP,
2964                                             sizeof(FOCUS_MODES_MAP)/sizeof(QCameraMap),
2965                                             m_pCapability->supported_focus_modes[0]);
2966        if (focusMode != NULL) {
2967            setFocusMode(focusMode);
2968        } else {
2969            setFocusMode(FOCUS_MODE_FIXED);
2970        }
2971    } else {
2972        ALOGE("%s: supported focus modes cnt is 0!!!", __func__);
2973    }
2974
2975    // Set focus areas
2976    if (m_pCapability->max_num_focus_areas > MAX_ROI) {
2977        m_pCapability->max_num_focus_areas = MAX_ROI;
2978    }
2979    set(KEY_MAX_NUM_FOCUS_AREAS, m_pCapability->max_num_focus_areas);
2980    if (m_pCapability->max_num_focus_areas > 0) {
2981        setFocusAreas(DEFAULT_CAMERA_AREA);
2982    }
2983
2984    // Set metering areas
2985    if (m_pCapability->max_num_metering_areas > MAX_ROI) {
2986        m_pCapability->max_num_metering_areas = MAX_ROI;
2987    }
2988    set(KEY_MAX_NUM_METERING_AREAS, m_pCapability->max_num_metering_areas);
2989    if (m_pCapability->max_num_metering_areas > 0) {
2990        setMeteringAreas(DEFAULT_CAMERA_AREA);
2991    }
2992
2993    // Set Saturation
2994    set(KEY_QC_MIN_SATURATION, m_pCapability->saturation_ctrl.min_value);
2995    set(KEY_QC_MAX_SATURATION, m_pCapability->saturation_ctrl.max_value);
2996    set(KEY_QC_SATURATION_STEP, m_pCapability->saturation_ctrl.step);
2997    setSaturation(m_pCapability->saturation_ctrl.def_value);
2998
2999    // Set Sharpness
3000    set(KEY_QC_MIN_SHARPNESS, m_pCapability->sharpness_ctrl.min_value);
3001    set(KEY_QC_MAX_SHARPNESS, m_pCapability->sharpness_ctrl.max_value);
3002    set(KEY_QC_SHARPNESS_STEP, m_pCapability->sharpness_ctrl.step);
3003    setSharpness(m_pCapability->sharpness_ctrl.def_value);
3004
3005    // Set Contrast
3006    set(KEY_QC_MIN_CONTRAST, m_pCapability->contrast_ctrl.min_value);
3007    set(KEY_QC_MAX_CONTRAST, m_pCapability->contrast_ctrl.max_value);
3008    set(KEY_QC_CONTRAST_STEP, m_pCapability->contrast_ctrl.step);
3009    setContrast(m_pCapability->contrast_ctrl.def_value);
3010
3011    // Set SCE factor
3012    set(KEY_QC_MIN_SCE_FACTOR, m_pCapability->sce_ctrl.min_value); // -100
3013    set(KEY_QC_MAX_SCE_FACTOR, m_pCapability->sce_ctrl.max_value); // 100
3014    set(KEY_QC_SCE_FACTOR_STEP, m_pCapability->sce_ctrl.step);     // 10
3015    setSkinToneEnhancement(m_pCapability->sce_ctrl.def_value);     // 0
3016
3017    // Set Brightness
3018    set(KEY_QC_MIN_BRIGHTNESS, m_pCapability->brightness_ctrl.min_value); // 0
3019    set(KEY_QC_MAX_BRIGHTNESS, m_pCapability->brightness_ctrl.max_value); // 6
3020    set(KEY_QC_BRIGHTNESS_STEP, m_pCapability->brightness_ctrl.step);     // 1
3021    setBrightness(m_pCapability->brightness_ctrl.def_value);
3022
3023    // Set Auto exposure
3024    String8 autoExposureValues = createValuesString(
3025            (int *)m_pCapability->supported_aec_modes,
3026            m_pCapability->supported_aec_modes_cnt,
3027            AUTO_EXPOSURE_MAP,
3028            sizeof(AUTO_EXPOSURE_MAP) / sizeof(QCameraMap));
3029    set(KEY_QC_SUPPORTED_AUTO_EXPOSURE, autoExposureValues.string());
3030    setAutoExposure(AUTO_EXPOSURE_FRAME_AVG);
3031
3032    // Set Exposure Compensation
3033    set(KEY_MAX_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_max); // 12
3034    set(KEY_MIN_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_min); // -12
3035    setFloat(KEY_EXPOSURE_COMPENSATION_STEP, m_pCapability->exposure_compensation_step); // 1/6
3036    setExposureCompensation(m_pCapability->exposure_compensation_default); // 0
3037
3038    // Set Antibanding
3039    String8 antibandingValues = createValuesString(
3040            (int *)m_pCapability->supported_antibandings,
3041            m_pCapability->supported_antibandings_cnt,
3042            ANTIBANDING_MODES_MAP,
3043            sizeof(ANTIBANDING_MODES_MAP) / sizeof(QCameraMap));
3044    set(KEY_SUPPORTED_ANTIBANDING, antibandingValues);
3045    setAntibanding(ANTIBANDING_OFF);
3046
3047    // Set Effect
3048    String8 effectValues = createValuesString(
3049            (int *)m_pCapability->supported_effects,
3050            m_pCapability->supported_effects_cnt,
3051            EFFECT_MODES_MAP,
3052            sizeof(EFFECT_MODES_MAP) / sizeof(QCameraMap));
3053    set(KEY_SUPPORTED_EFFECTS, effectValues);
3054    setEffect(EFFECT_NONE);
3055
3056    // Set WhiteBalance
3057    String8 whitebalanceValues = createValuesString(
3058            (int *)m_pCapability->supported_white_balances,
3059            m_pCapability->supported_white_balances_cnt,
3060            WHITE_BALANCE_MODES_MAP,
3061            sizeof(WHITE_BALANCE_MODES_MAP) / sizeof(QCameraMap));
3062    set(KEY_SUPPORTED_WHITE_BALANCE, whitebalanceValues);
3063    setWhiteBalance(WHITE_BALANCE_AUTO);
3064
3065    // Set Flash mode
3066    String8 flashValues = createValuesString(
3067            (int *)m_pCapability->supported_flash_modes,
3068            m_pCapability->supported_flash_modes_cnt,
3069            FLASH_MODES_MAP,
3070            sizeof(FLASH_MODES_MAP) / sizeof(QCameraMap));
3071    set(KEY_SUPPORTED_FLASH_MODES, flashValues);
3072    setFlash(FLASH_MODE_OFF);
3073
3074    // Set Scene Mode
3075    String8 sceneModeValues = createValuesString(
3076            (int *)m_pCapability->supported_scene_modes,
3077            m_pCapability->supported_scene_modes_cnt,
3078            SCENE_MODES_MAP,
3079            sizeof(SCENE_MODES_MAP) / sizeof(QCameraMap));
3080    set(KEY_SUPPORTED_SCENE_MODES, sceneModeValues);
3081    setSceneMode(SCENE_MODE_AUTO);
3082
3083    // Set ISO Mode
3084    String8 isoValues = createValuesString(
3085            (int *)m_pCapability->supported_iso_modes,
3086            m_pCapability->supported_iso_modes_cnt,
3087            ISO_MODES_MAP,
3088            sizeof(ISO_MODES_MAP) / sizeof(QCameraMap));
3089    set(KEY_QC_SUPPORTED_ISO_MODES, isoValues);
3090    setISOValue(ISO_AUTO);
3091
3092    // Set HFR
3093    String8 hfrValues = createHfrValuesString(
3094            m_pCapability->hfr_tbl,
3095            m_pCapability->hfr_tbl_cnt,
3096            HFR_MODES_MAP,
3097            sizeof(HFR_MODES_MAP) / sizeof(QCameraMap));
3098    set(KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES, hfrValues.string());
3099    String8 hfrSizeValues = createHfrSizesString(
3100            m_pCapability->hfr_tbl,
3101            m_pCapability->hfr_tbl_cnt);
3102    set(KEY_QC_SUPPORTED_HFR_SIZES, hfrSizeValues.string());
3103    setHighFrameRate(VIDEO_HFR_OFF);
3104
3105    // Set Focus algorithms
3106    String8 focusAlgoValues = createValuesString(
3107            (int *)m_pCapability->supported_focus_algos,
3108            m_pCapability->supported_focus_algos_cnt,
3109            FOCUS_ALGO_MAP,
3110            sizeof(FOCUS_ALGO_MAP) / sizeof(QCameraMap));
3111    set(KEY_QC_SUPPORTED_FOCUS_ALGOS, focusAlgoValues);
3112    setSelectableZoneAf(FOCUS_ALGO_AUTO);
3113
3114    // Set Zoom Ratios
3115    if (m_pCapability->zoom_supported > 0) {
3116        String8 zoomRatioValues = createZoomRatioValuesString(
3117                m_pCapability->zoom_ratio_tbl,
3118                m_pCapability->zoom_ratio_tbl_cnt);
3119        set(KEY_ZOOM_RATIOS, zoomRatioValues);
3120        set(KEY_MAX_ZOOM, m_pCapability->zoom_ratio_tbl_cnt - 1);
3121        setZoom(0);
3122    }
3123
3124    // Set Bracketing/HDR
3125    char prop[PROPERTY_VALUE_MAX];
3126    memset(prop, 0, sizeof(prop));
3127    property_get("persist.capture.burst.exposures", prop, "");
3128    if (strlen(prop) > 0) {
3129        set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
3130    }
3131    String8 bracketingValues = createValuesStringFromMap(
3132            BRACKETING_MODES_MAP,
3133            sizeof(BRACKETING_MODES_MAP) / sizeof(QCameraMap));
3134    set(KEY_QC_SUPPORTED_AE_BRACKET_MODES, bracketingValues);
3135    setAEBracket(AE_BRACKET_OFF);
3136
3137    // Set Denoise
3138    String8 denoiseValues = createValuesStringFromMap(
3139       DENOISE_ON_OFF_MODES_MAP, sizeof(DENOISE_ON_OFF_MODES_MAP) / sizeof(QCameraMap));
3140    set(KEY_QC_SUPPORTED_DENOISE, denoiseValues.string());
3141    setWaveletDenoise(DENOISE_OFF);
3142
3143    // Set feature enable/disable
3144    String8 enableDisableValues = createValuesStringFromMap(
3145        ENABLE_DISABLE_MODES_MAP, sizeof(ENABLE_DISABLE_MODES_MAP) / sizeof(QCameraMap));
3146
3147    // Set Lens Shading
3148    set(KEY_QC_SUPPORTED_LENSSHADE_MODES, enableDisableValues);
3149    setLensShadeValue(VALUE_ENABLE);
3150
3151    // Set MCE
3152    set(KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES, enableDisableValues);
3153    setMCEValue(VALUE_ENABLE);
3154
3155    // Set DIS
3156    set(KEY_QC_SUPPORTED_DIS_MODES, enableDisableValues);
3157    setDISValue(VALUE_DISABLE);
3158
3159    // Set Histogram
3160    set(KEY_QC_SUPPORTED_HISTOGRAM_MODES, enableDisableValues);
3161    set(KEY_QC_HISTOGRAM, VALUE_DISABLE);
3162
3163    //Set Red Eye Reduction
3164    set(KEY_QC_SUPPORTED_REDEYE_REDUCTION, enableDisableValues);
3165    setRedeyeReduction(VALUE_DISABLE);
3166
3167    //Set SkinTone Enhancement
3168    set(KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES, enableDisableValues);
3169
3170    // Set feature on/off
3171    String8 onOffValues = createValuesStringFromMap(
3172        ON_OFF_MODES_MAP, sizeof(ON_OFF_MODES_MAP) / sizeof(QCameraMap));
3173
3174    //Set Scene Detection
3175    set(KEY_QC_SUPPORTED_SCENE_DETECT, onOffValues);
3176    setSceneDetect(VALUE_OFF);
3177
3178    //Set Face Detection
3179    set(KEY_QC_SUPPORTED_FACE_DETECTION, onOffValues);
3180    set(KEY_QC_FACE_DETECTION, VALUE_OFF);
3181
3182    //Set Face Recognition
3183    set(KEY_QC_SUPPORTED_FACE_RECOGNITION, onOffValues);
3184    set(KEY_QC_FACE_RECOGNITION, VALUE_OFF);
3185
3186    //Set ZSL
3187    set(KEY_QC_SUPPORTED_ZSL_MODES, onOffValues);
3188#ifdef DEFAULT_ZSL_MODE_ON
3189    set(KEY_QC_ZSL, VALUE_ON);
3190    m_bZslMode = true;
3191#else
3192    set(KEY_QC_ZSL, VALUE_OFF);
3193    m_bZslMode = false;
3194#endif
3195
3196    //Set video HDR
3197    if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_VIDEO_HDR) > 0) {
3198        set(KEY_QC_SUPPORTED_VIDEO_HDR_MODES, onOffValues);
3199        set(KEY_QC_VIDEO_HDR, VALUE_OFF);
3200    }
3201
3202    //Set Touch AF/AEC
3203    String8 touchValues = createValuesStringFromMap(
3204       TOUCH_AF_AEC_MODES_MAP, sizeof(TOUCH_AF_AEC_MODES_MAP) / sizeof(QCameraMap));
3205
3206    set(KEY_QC_SUPPORTED_TOUCH_AF_AEC, touchValues);
3207    set(KEY_QC_TOUCH_AF_AEC, TOUCH_AF_AEC_OFF);
3208
3209    //set flip mode
3210    if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) > 0) {
3211        String8 flipModes = createValuesStringFromMap(
3212           FLIP_MODES_MAP, sizeof(FLIP_MODES_MAP) / sizeof(QCameraMap));
3213        set(KEY_QC_SUPPORTED_FLIP_MODES, flipModes);
3214        set(KEY_QC_PREVIEW_FLIP, FLIP_MODE_OFF);
3215        set(KEY_QC_VIDEO_FLIP, FLIP_MODE_OFF);
3216        set(KEY_QC_SNAPSHOT_PICTURE_FLIP, FLIP_MODE_OFF);
3217    }
3218
3219    // Set default Auto Exposure lock value
3220    setAecLock(VALUE_FALSE);
3221
3222    // Set default AWB_LOCK lock value
3223    setAwbLock(VALUE_FALSE);
3224
3225    // Set default Camera mode
3226    set(KEY_QC_CAMERA_MODE, 0);
3227
3228    // TODO: hardcode for now until mctl add support for min_num_pp_bufs
3229    m_pCapability->min_num_pp_bufs = 3;
3230
3231    int32_t rc = commitParameters();
3232    if (rc == NO_ERROR) {
3233        rc = setNumOfSnapshot();
3234    }
3235    return rc;
3236}
3237
3238/*===========================================================================
3239 * FUNCTION   : init
3240 *
3241 * DESCRIPTION: initialize parameter obj
3242 *
3243 * PARAMETERS :
3244 *   @capabilities  : ptr to camera capabilities
3245 *   @mmops         : ptr to memory ops table for mapping/unmapping
3246 *
3247 * RETURN     : int32_t type of status
3248 *              NO_ERROR  -- success
3249 *              none-zero failure code
3250 *==========================================================================*/
3251int32_t QCameraParameters::init(cam_capability_t *capabilities, mm_camera_vtbl_t *mmOps)
3252{
3253    int32_t rc = NO_ERROR;
3254
3255    m_pCapability = capabilities;
3256    m_pCamOpsTbl = mmOps;
3257
3258    //Allocate Set Param Buffer
3259    m_pParamHeap = new QCameraHeapMemory();
3260    rc = m_pParamHeap->allocate(1, sizeof(parm_buffer_t));
3261    if(rc != OK) {
3262        rc = NO_MEMORY;
3263        ALOGE("Failed to allocate SETPARM Heap memory");
3264        goto TRANS_INIT_ERROR1;
3265    }
3266
3267    //Map memory for parameters buffer
3268    rc = m_pCamOpsTbl->ops->map_buf(m_pCamOpsTbl->camera_handle,
3269                             CAM_MAPPING_BUF_TYPE_PARM_BUF,
3270                             m_pParamHeap->getFd(0),
3271                             sizeof(parm_buffer_t));
3272    if(rc < 0) {
3273        ALOGE("%s:failed to map SETPARM buffer",__func__);
3274        rc = FAILED_TRANSACTION;
3275        goto TRANS_INIT_ERROR2;
3276    }
3277    m_pParamBuf = (parm_buffer_t*) DATA_PTR(m_pParamHeap,0);
3278
3279    initDefaultParameters();
3280
3281    goto TRANS_INIT_DONE;
3282
3283TRANS_INIT_ERROR2:
3284    m_pParamHeap->deallocate();
3285
3286TRANS_INIT_ERROR1:
3287    delete m_pParamHeap;
3288    m_pParamHeap = NULL;
3289
3290TRANS_INIT_DONE:
3291    return rc;
3292}
3293
3294/*===========================================================================
3295 * FUNCTION   : deinit
3296 *
3297 * DESCRIPTION: deinitialize
3298 *
3299 * PARAMETERS : none
3300 *
3301 * RETURN     : none
3302 *==========================================================================*/
3303void QCameraParameters::deinit()
3304{
3305    //clear all entries in the map
3306    String8 emptyStr;
3307    QCameraParameters::unflatten(emptyStr);
3308
3309    if (NULL != m_pCamOpsTbl) {
3310        m_pCamOpsTbl->ops->unmap_buf(
3311                             m_pCamOpsTbl->camera_handle,
3312                             CAM_MAPPING_BUF_TYPE_PARM_BUF);
3313        m_pCamOpsTbl = NULL;
3314    }
3315    m_pCapability = NULL;
3316    if (NULL != m_pParamHeap) {
3317        m_pParamHeap->deallocate();
3318        delete m_pParamHeap;
3319        m_pParamHeap = NULL;
3320        m_pParamBuf = NULL;
3321    }
3322
3323    m_tempMap.clear();
3324}
3325
3326/*===========================================================================
3327 * FUNCTION   : parse_pair
3328 *
3329 * DESCRIPTION: helper function to parse string like "640x480" or "10000,20000"
3330 *
3331 * PARAMETERS :
3332 *   @str     : input string to be parse
3333 *   @first   : [output] first value of the pair
3334 *   @second  : [output]  second value of the pair
3335 *   @delim   : [input] delimeter to seperate the pair
3336 *   @endptr  : [output] ptr to the end of the pair string
3337 *
3338 * RETURN     : int32_t type of status
3339 *              NO_ERROR  -- success
3340 *              none-zero failure code
3341 *==========================================================================*/
3342int32_t QCameraParameters::parse_pair(const char *str,
3343                                      int *first,
3344                                      int *second,
3345                                      char delim,
3346                                      char **endptr = NULL)
3347{
3348    // Find the first integer.
3349    char *end;
3350    int w = (int)strtol(str, &end, 10);
3351    // If a delimeter does not immediately follow, give up.
3352    if (*end != delim) {
3353        ALOGE("Cannot find delimeter (%c) in str=%s", delim, str);
3354        return BAD_VALUE;
3355    }
3356
3357    // Find the second integer, immediately after the delimeter.
3358    int h = (int)strtol(end+1, &end, 10);
3359
3360    *first = w;
3361    *second = h;
3362
3363    if (endptr) {
3364        *endptr = end;
3365    }
3366
3367    return NO_ERROR;
3368}
3369
3370/*===========================================================================
3371 * FUNCTION   : parseSizesList
3372 *
3373 * DESCRIPTION: helper function to parse string containing sizes
3374 *
3375 * PARAMETERS :
3376 *   @sizesStr: [input] input string to be parse
3377 *   @sizes   : [output] reference to store parsed sizes
3378 *
3379 * RETURN     : none
3380 *==========================================================================*/
3381void QCameraParameters::parseSizesList(const char *sizesStr, Vector<Size> &sizes)
3382{
3383    if (sizesStr == 0) {
3384        return;
3385    }
3386
3387    char *sizeStartPtr = (char *)sizesStr;
3388
3389    while (true) {
3390        int width, height;
3391        int success = parse_pair(sizeStartPtr, &width, &height, 'x',
3392                                 &sizeStartPtr);
3393        if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
3394            ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
3395            return;
3396        }
3397        sizes.push(Size(width, height));
3398
3399        if (*sizeStartPtr == '\0') {
3400            return;
3401        }
3402        sizeStartPtr++;
3403    }
3404}
3405
3406/*===========================================================================
3407 * FUNCTION   : getSupportedHfrSizes
3408 *
3409 * DESCRIPTION: return supported HFR sizes
3410 *
3411 * PARAMETERS :
3412 *   @sizes  : [output] reference to a vector storing supported HFR sizes
3413 *
3414 * RETURN     : none
3415 *==========================================================================*/
3416void QCameraParameters::getSupportedHfrSizes(Vector<Size> &sizes)
3417{
3418    const char *hfrSizesStr = get(KEY_QC_SUPPORTED_HFR_SIZES);
3419    parseSizesList(hfrSizesStr, sizes);
3420}
3421
3422/*===========================================================================
3423 * FUNCTION   : adjustPreviewFpsRanges
3424 *
3425 * DESCRIPTION: adjust preview FPS ranges
3426 *              according to external events
3427 *
3428 * PARAMETERS :
3429 *   @minFPS  : min FPS value
3430 *   @maxFPS  : max FPS value
3431 *
3432 * RETURN     : int32_t type of status
3433 *              NO_ERROR  -- success
3434 *              none-zero failure code
3435 *==========================================================================*/
3436int32_t QCameraParameters::adjustPreviewFpsRange(cam_fps_range_t *fpsRange)
3437{
3438    if ( fpsRange == NULL ) {
3439        return BAD_VALUE;
3440    }
3441
3442    int32_t rc = initBatchUpdate(m_pParamBuf);
3443    if ( rc != NO_ERROR ) {
3444        ALOGE("%s:Failed to initialize group update table", __func__);
3445        return rc;
3446    }
3447
3448    rc = AddSetParmEntryToBatch(m_pParamBuf,
3449                                  CAM_INTF_PARM_FPS_RANGE,
3450                                  sizeof(cam_fps_range_t),
3451                                  fpsRange);
3452    if ( rc != NO_ERROR ) {
3453        ALOGE("%s: Parameters batch failed",__func__);
3454        return rc;
3455    }
3456
3457    rc = commitSetBatch();
3458    if ( rc != NO_ERROR ) {
3459        ALOGE("%s:Failed to commit batch parameters", __func__);
3460        return rc;
3461    }
3462
3463    return rc;
3464}
3465
3466/*===========================================================================
3467 * FUNCTION   : setPreviewFpsRanges
3468 *
3469 * DESCRIPTION: set preview FPS ranges
3470 *
3471 * PARAMETERS :
3472 *   @minFPS  : min FPS value
3473 *   @maxFPS  : max FPS value
3474 *
3475 * RETURN     : int32_t type of status
3476 *              NO_ERROR  -- success
3477 *              none-zero failure code
3478 *==========================================================================*/
3479int32_t QCameraParameters::setPreviewFpsRange(int minFPS, int maxFPS)
3480{
3481    char str[32];
3482    snprintf(str, sizeof(str), "%d,%d", minFPS, maxFPS);
3483    ALOGD("%s: Setting preview fps range %s", __func__, str);
3484    updateParamEntry(KEY_PREVIEW_FPS_RANGE, str);
3485    cam_fps_range_t fps_range = {(float)(minFPS / 1000.0), (float)(maxFPS / 1000.0)};
3486    return AddSetParmEntryToBatch(m_pParamBuf,
3487                                  CAM_INTF_PARM_FPS_RANGE,
3488                                  sizeof(cam_fps_range_t),
3489                                  &fps_range);
3490}
3491
3492/*===========================================================================
3493 * FUNCTION   : setAutoExposure
3494 *
3495 * DESCRIPTION: set auto exposure
3496 *
3497 * PARAMETERS :
3498 *   @autoExp : auto exposure value string
3499 *
3500 * RETURN     : int32_t type of status
3501 *              NO_ERROR  -- success
3502 *              none-zero failure code
3503 *==========================================================================*/
3504int32_t QCameraParameters::setAutoExposure(const char *autoExp)
3505{
3506    if (autoExp != NULL) {
3507        int32_t value = lookupAttr(AUTO_EXPOSURE_MAP,
3508                                   sizeof(AUTO_EXPOSURE_MAP)/sizeof(AUTO_EXPOSURE_MAP[0]),
3509                                   autoExp);
3510        if (value != NAME_NOT_FOUND) {
3511            ALOGD("%s: Setting auto exposure %s", __func__, autoExp);
3512            updateParamEntry(KEY_QC_AUTO_EXPOSURE, autoExp);
3513            return AddSetParmEntryToBatch(m_pParamBuf,
3514                                          CAM_INTF_PARM_AEC_ALGO_TYPE,
3515                                          sizeof(value),
3516                                          &value);
3517        }
3518    }
3519    ALOGE("Invalid auto exposure value: %s", (autoExp == NULL) ? "NULL" : autoExp);
3520    return BAD_VALUE;
3521}
3522
3523/*===========================================================================
3524 * FUNCTION   : setEffect
3525 *
3526 * DESCRIPTION: set effect
3527 *
3528 * PARAMETERS :
3529 *   @effect  : effect value string
3530 *
3531 * RETURN     : int32_t type of status
3532 *              NO_ERROR  -- success
3533 *              none-zero failure code
3534 *==========================================================================*/
3535int32_t QCameraParameters::setEffect(const char *effect)
3536{
3537    if (effect != NULL) {
3538        int32_t value = lookupAttr(EFFECT_MODES_MAP,
3539                                   sizeof(EFFECT_MODES_MAP)/sizeof(QCameraMap),
3540                                   effect);
3541        if (value != NAME_NOT_FOUND) {
3542            ALOGD("%s: Setting effect %s", __func__, effect);
3543            updateParamEntry(KEY_EFFECT, effect);
3544            return AddSetParmEntryToBatch(m_pParamBuf,
3545                                          CAM_INTF_PARM_EFFECT,
3546                                          sizeof(value),
3547                                          &value);
3548        }
3549    }
3550    ALOGE("Invalid effect value: %s", (effect == NULL) ? "NULL" : effect);
3551    return BAD_VALUE;
3552}
3553
3554/*===========================================================================
3555 * FUNCTION   : setBrightness
3556 *
3557 * DESCRIPTION: set brightness control value
3558 *
3559 * PARAMETERS :
3560 *   @brightness  : brightness control value
3561 *
3562 * RETURN     : int32_t type of status
3563 *              NO_ERROR  -- success
3564 *              none-zero failure code
3565 *==========================================================================*/
3566int32_t QCameraParameters::setBrightness(int brightness)
3567{
3568    char val[16];
3569    sprintf(val, "%d", brightness);
3570    updateParamEntry(KEY_QC_BRIGHTNESS, val);
3571
3572    int32_t value = brightness;
3573    ALOGD("%s: Setting brightness %s", __func__, val);
3574    return AddSetParmEntryToBatch(m_pParamBuf,
3575                                  CAM_INTF_PARM_BRIGHTNESS,
3576                                  sizeof(value),
3577                                  &value);
3578}
3579
3580/*===========================================================================
3581 * FUNCTION   : setFocusMode
3582 *
3583 * DESCRIPTION: set focus mode
3584 *
3585 * PARAMETERS :
3586 *   @focusMode  : focus mode value string
3587 *
3588 * RETURN     : int32_t type of status
3589 *              NO_ERROR  -- success
3590 *              none-zero failure code
3591 *==========================================================================*/
3592int32_t QCameraParameters::setFocusMode(const char *focusMode)
3593{
3594    if (focusMode != NULL) {
3595        int32_t value = lookupAttr(FOCUS_MODES_MAP,
3596                                   sizeof(FOCUS_MODES_MAP)/sizeof(QCameraMap),
3597                                   focusMode);
3598        if (value != NAME_NOT_FOUND) {
3599            ALOGD("%s: Setting focus mode %s", __func__, focusMode);
3600            mFocusMode = (cam_focus_mode_type)value;
3601
3602            // reset need lock CAF flag
3603            m_bNeedLockCAF = false;
3604            m_bCAFLocked = false;
3605            m_bAFRunning = false;
3606
3607            updateParamEntry(KEY_FOCUS_MODE, focusMode);
3608            return AddSetParmEntryToBatch(m_pParamBuf,
3609                                          CAM_INTF_PARM_FOCUS_MODE,
3610                                          sizeof(value),
3611                                          &value);
3612        }
3613    }
3614    ALOGE("Invalid focus mode value: %s", (focusMode == NULL) ? "NULL" : focusMode);
3615    return BAD_VALUE;
3616}
3617
3618/*===========================================================================
3619 * FUNCTION   : setSharpness
3620 *
3621 * DESCRIPTION: set sharpness control value
3622 *
3623 * PARAMETERS :
3624 *   @sharpness  : sharpness control value
3625 *
3626 * RETURN     : int32_t type of status
3627 *              NO_ERROR  -- success
3628 *              none-zero failure code
3629 *==========================================================================*/
3630int32_t QCameraParameters::setSharpness(int sharpness)
3631{
3632    char val[16];
3633    sprintf(val, "%d", sharpness);
3634    updateParamEntry(KEY_QC_SHARPNESS, val);
3635    ALOGD("%s: Setting sharpness %s", __func__, val);
3636
3637    int32_t value = sharpness;
3638    return AddSetParmEntryToBatch(m_pParamBuf,
3639                                  CAM_INTF_PARM_SHARPNESS,
3640                                  sizeof(value),
3641                                  &value);
3642}
3643
3644/*===========================================================================
3645 * FUNCTION   : setSkinToneEnhancement
3646 *
3647 * DESCRIPTION: set skin tone enhancement value
3648 *
3649 * PARAMETERS :
3650 *   @sceFactore  : skin tone enhancement factor value
3651 *
3652 * RETURN     : int32_t type of status
3653 *              NO_ERROR  -- success
3654 *              none-zero failure code
3655 *==========================================================================*/
3656int32_t QCameraParameters::setSkinToneEnhancement(int sceFactor)
3657{
3658    char val[16];
3659    sprintf(val, "%d", sceFactor);
3660    updateParamEntry(KEY_QC_SCE_FACTOR, val);
3661    ALOGD("%s: Setting skintone enhancement %s", __func__, val);
3662
3663    int32_t value = sceFactor;
3664    return AddSetParmEntryToBatch(m_pParamBuf,
3665                                  CAM_INTF_PARM_SCE_FACTOR,
3666                                  sizeof(value),
3667                                  &value);
3668}
3669
3670/*===========================================================================
3671 * FUNCTION   : setSaturation
3672 *
3673 * DESCRIPTION: set saturation control value
3674 *
3675 * PARAMETERS :
3676 *   @saturation : saturation control value
3677 *
3678 * RETURN     : int32_t type of status
3679 *              NO_ERROR  -- success
3680 *              none-zero failure code
3681 *==========================================================================*/
3682int32_t QCameraParameters::setSaturation(int saturation)
3683{
3684    char val[16];
3685    sprintf(val, "%d", saturation);
3686    updateParamEntry(KEY_QC_SATURATION, val);
3687    ALOGD("%s: Setting saturation %s", __func__, val);
3688
3689    int32_t value = saturation;
3690    return AddSetParmEntryToBatch(m_pParamBuf,
3691                                  CAM_INTF_PARM_SATURATION,
3692                                  sizeof(value),
3693                                  &value);
3694}
3695
3696/*===========================================================================
3697 * FUNCTION   : setContrast
3698 *
3699 * DESCRIPTION: set contrast control value
3700 *
3701 * PARAMETERS :
3702 *   @contrast : contrast control value
3703 *
3704 * RETURN     : int32_t type of status
3705 *              NO_ERROR  -- success
3706 *              none-zero failure code
3707 *==========================================================================*/
3708int32_t QCameraParameters::setContrast(int contrast)
3709{
3710    char val[16];
3711    sprintf(val, "%d", contrast);
3712    updateParamEntry(KEY_QC_CONTRAST, val);
3713    ALOGD("%s: Setting contrast %s", __func__, val);
3714
3715    int32_t value = contrast;
3716    return AddSetParmEntryToBatch(m_pParamBuf,
3717                                  CAM_INTF_PARM_CONTRAST,
3718                                  sizeof(value),
3719                                  &value);
3720}
3721
3722/*===========================================================================
3723 * FUNCTION   : setSceneDetect
3724 *
3725 * DESCRIPTION: set scenen detect value
3726 *
3727 * PARAMETERS :
3728 *   @sceneDetect  : scene detect value string
3729 *
3730 * RETURN     : int32_t type of status
3731 *              NO_ERROR  -- success
3732 *              none-zero failure code
3733 *==========================================================================*/
3734int32_t QCameraParameters::setSceneDetect(const char *sceneDetect)
3735{
3736    if (sceneDetect != NULL) {
3737        int32_t value = lookupAttr(ON_OFF_MODES_MAP,
3738                                   sizeof(ON_OFF_MODES_MAP)/sizeof(QCameraMap),
3739                                   sceneDetect);
3740        if (value != NAME_NOT_FOUND) {
3741            ALOGD("%s: Setting Scene Detect %s", __func__, sceneDetect);
3742            updateParamEntry(KEY_QC_SCENE_DETECT, sceneDetect);
3743            return AddSetParmEntryToBatch(m_pParamBuf,
3744                                          CAM_INTF_PARM_ASD_ENABLE,
3745                                          sizeof(value),
3746                                          &value);
3747        }
3748    }
3749    ALOGE("Invalid Scene Detect value: %s",
3750          (sceneDetect == NULL) ? "NULL" : sceneDetect);
3751    return BAD_VALUE;
3752}
3753
3754/*===========================================================================
3755 * FUNCTION   : setVideoHDR
3756 *
3757 * DESCRIPTION: set video HDR value
3758 *
3759 * PARAMETERS :
3760 *   @videoHDR  : svideo HDR value string
3761 *
3762 * RETURN     : int32_t type of status
3763 *              NO_ERROR  -- success
3764 *              none-zero failure code
3765 *==========================================================================*/
3766int32_t QCameraParameters::setVideoHDR(const char *videoHDR)
3767{
3768    if (videoHDR != NULL) {
3769        int32_t value = lookupAttr(ON_OFF_MODES_MAP,
3770                                   sizeof(ON_OFF_MODES_MAP)/sizeof(QCameraMap),
3771                                   videoHDR);
3772        if (value != NAME_NOT_FOUND) {
3773            ALOGD("%s: Setting Video HDR %s", __func__, videoHDR);
3774            updateParamEntry(KEY_QC_VIDEO_HDR, videoHDR);
3775            return AddSetParmEntryToBatch(m_pParamBuf,
3776                                          CAM_INTF_PARM_VIDEO_HDR,
3777                                          sizeof(value),
3778                                          &value);
3779        }
3780    }
3781    ALOGE("Invalid Video HDR value: %s",
3782          (videoHDR == NULL) ? "NULL" : videoHDR);
3783    return BAD_VALUE;
3784}
3785
3786/*===========================================================================
3787 * FUNCTION   : setFaceRecognition
3788 *
3789 * DESCRIPTION: set face recognition value
3790 *
3791 * PARAMETERS :
3792 *   @faceRecog  : face recognition value string
3793 *   @maxFaces   : number of max faces to be detected/recognized
3794 *
3795 * RETURN     : int32_t type of status
3796 *              NO_ERROR  -- success
3797 *              none-zero failure code
3798 *==========================================================================*/
3799int32_t QCameraParameters::setFaceRecognition(const char *faceRecog, int maxFaces)
3800{
3801    if (faceRecog != NULL) {
3802        int32_t value = lookupAttr(ON_OFF_MODES_MAP,
3803                                   sizeof(ON_OFF_MODES_MAP)/sizeof(QCameraMap),
3804                                   faceRecog);
3805        if (value != NAME_NOT_FOUND) {
3806            ALOGD("%s: Setting face recognition %s", __func__, faceRecog);
3807            updateParamEntry(KEY_QC_FACE_RECOGNITION, faceRecog);
3808
3809            int faceProcMask = m_nFaceProcMask;
3810            if (value > 0) {
3811                faceProcMask |= CAM_FACE_PROCESS_MASK_RECOGNITION;
3812            } else {
3813                faceProcMask &= ~CAM_FACE_PROCESS_MASK_RECOGNITION;
3814            }
3815
3816            if(m_nFaceProcMask == faceProcMask) {
3817                ALOGD("%s: face process mask not changed, no ops here", __func__);
3818                return NO_ERROR;
3819            }
3820            m_nFaceProcMask = faceProcMask;
3821            ALOGD("%s: FaceProcMask -> %d", __func__, m_nFaceProcMask);
3822
3823            // set parm for face process
3824            cam_fd_set_parm_t fd_set_parm;
3825            memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
3826            fd_set_parm.fd_mode = m_nFaceProcMask;
3827            fd_set_parm.num_fd = maxFaces;
3828
3829            return AddSetParmEntryToBatch(m_pParamBuf,
3830                                        CAM_INTF_PARM_FD,
3831                                        sizeof(fd_set_parm),
3832                                        &fd_set_parm);
3833        }
3834    }
3835    ALOGE("Invalid face recognition value: %s", (faceRecog == NULL) ? "NULL" : faceRecog);
3836    return BAD_VALUE;
3837}
3838
3839/*===========================================================================
3840 * FUNCTION   : setZoom
3841 *
3842 * DESCRIPTION: set zoom level
3843 *
3844 * PARAMETERS :
3845 *   @zoom_level : zoom level
3846 *
3847 * RETURN     : int32_t type of status
3848 *              NO_ERROR  -- success
3849 *              none-zero failure code
3850 *==========================================================================*/
3851int32_t QCameraParameters::setZoom(int zoom_level)
3852{
3853    char val[16];
3854    sprintf(val, "%d", zoom_level);
3855    updateParamEntry(KEY_ZOOM, val);
3856
3857    return AddSetParmEntryToBatch(m_pParamBuf,
3858                                  CAM_INTF_PARM_ZOOM,
3859                                  sizeof(zoom_level),
3860                                  &zoom_level);
3861}
3862
3863/*===========================================================================
3864 * FUNCTION   : setISOValue
3865 *
3866 * DESCRIPTION: set ISO value
3867 *
3868 * PARAMETERS :
3869 *   @isoValue : ISO value string
3870 *
3871 * RETURN     : int32_t type of status
3872 *              NO_ERROR  -- success
3873 *              none-zero failure code
3874 *==========================================================================*/
3875int32_t  QCameraParameters::setISOValue(const char *isoValue)
3876{
3877    if (isoValue != NULL) {
3878        int32_t value = lookupAttr(ISO_MODES_MAP,
3879                                   sizeof(ISO_MODES_MAP)/sizeof(QCameraMap),
3880                                   isoValue);
3881        if (value != NAME_NOT_FOUND) {
3882            ALOGD("%s: Setting ISO value %s", __func__, isoValue);
3883            updateParamEntry(KEY_QC_ISO_MODE, isoValue);
3884            return AddSetParmEntryToBatch(m_pParamBuf,
3885                                          CAM_INTF_PARM_ISO,
3886                                          sizeof(value),
3887                                          &value);
3888        }
3889    }
3890    ALOGE("Invalid ISO value: %s",
3891          (isoValue == NULL) ? "NULL" : isoValue);
3892    return BAD_VALUE;
3893}
3894
3895/*===========================================================================
3896 * FUNCTION   : setFlash
3897 *
3898 * DESCRIPTION: set f;ash mode
3899 *
3900 * PARAMETERS :
3901 *   @flashStr : LED flash mode value string
3902 *
3903 * RETURN     : int32_t type of status
3904 *              NO_ERROR  -- success
3905 *              none-zero failure code
3906 *==========================================================================*/
3907int32_t QCameraParameters::setFlash(const char *flashStr)
3908{
3909    if (flashStr != NULL) {
3910        int32_t value = lookupAttr(FLASH_MODES_MAP,
3911                                   sizeof(FLASH_MODES_MAP)/sizeof(QCameraMap),
3912                                   flashStr);
3913        if (value != NAME_NOT_FOUND) {
3914            ALOGD("%s: Setting Flash value %s", __func__, flashStr);
3915            updateParamEntry(KEY_FLASH_MODE, flashStr);
3916            return AddSetParmEntryToBatch(m_pParamBuf,
3917                                          CAM_INTF_PARM_LED_MODE,
3918                                          sizeof(value),
3919                                          &value);
3920        }
3921    }
3922    ALOGE("Invalid flash value: %s", (flashStr == NULL) ? "NULL" : flashStr);
3923    return BAD_VALUE;
3924}
3925
3926/*===========================================================================
3927 * FUNCTION   : setAecLock
3928 *
3929 * DESCRIPTION: set AEC lock value
3930 *
3931 * PARAMETERS :
3932 *   @aecLockStr : AEC lock value string
3933 *
3934 * RETURN     : int32_t type of status
3935 *              NO_ERROR  -- success
3936 *              none-zero failure code
3937 *==========================================================================*/
3938int32_t QCameraParameters::setAecLock(const char *aecLockStr)
3939{
3940    if (aecLockStr != NULL) {
3941        int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP,
3942                                   sizeof(TRUE_FALSE_MODES_MAP)/sizeof(QCameraMap),
3943                                   aecLockStr);
3944        if (value != NAME_NOT_FOUND) {
3945            ALOGD("%s: Setting AECLock value %s", __func__, aecLockStr);
3946            updateParamEntry(KEY_AUTO_EXPOSURE_LOCK, aecLockStr);
3947            return AddSetParmEntryToBatch(m_pParamBuf,
3948                                          CAM_INTF_PARM_AEC_LOCK,
3949                                          sizeof(value),
3950                                          &value);
3951        }
3952    }
3953    ALOGE("Invalid AECLock value: %s", (aecLockStr == NULL) ? "NULL" : aecLockStr);
3954    return BAD_VALUE;
3955}
3956
3957/*===========================================================================
3958 * FUNCTION   : setAwbLock
3959 *
3960 * DESCRIPTION: set AWB lock value
3961 *
3962 * PARAMETERS :
3963 *   @awbLockStr : AWB lock value string
3964 *
3965 * RETURN     : int32_t type of status
3966 *              NO_ERROR  -- success
3967 *              none-zero failure code
3968 *==========================================================================*/
3969int32_t QCameraParameters::setAwbLock(const char *awbLockStr)
3970{
3971    if (awbLockStr != NULL) {
3972        int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP,
3973                                   sizeof(TRUE_FALSE_MODES_MAP)/sizeof(QCameraMap),
3974                                   awbLockStr);
3975        if (value != NAME_NOT_FOUND) {
3976            ALOGD("%s: Setting AWBLock value %s", __func__, awbLockStr);
3977            updateParamEntry(KEY_AUTO_WHITEBALANCE_LOCK, awbLockStr);
3978            return AddSetParmEntryToBatch(m_pParamBuf,
3979                                          CAM_INTF_PARM_AWB_LOCK,
3980                                          sizeof(value),
3981                                          &value);
3982        }
3983    }
3984    ALOGE("Invalid AWBLock value: %s", (awbLockStr == NULL) ? "NULL" : awbLockStr);
3985    return BAD_VALUE;
3986}
3987
3988/*===========================================================================
3989 * FUNCTION   : setMCEValue
3990 *
3991 * DESCRIPTION: set memory color enhancement value
3992 *
3993 * PARAMETERS :
3994 *   @mceStr : MCE value string
3995 *
3996 * RETURN     : int32_t type of status
3997 *              NO_ERROR  -- success
3998 *              none-zero failure code
3999 *==========================================================================*/
4000int32_t QCameraParameters::setMCEValue(const char *mceStr)
4001{
4002    if (mceStr != NULL) {
4003        int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
4004                                   sizeof(ENABLE_DISABLE_MODES_MAP)/sizeof(QCameraMap),
4005                                   mceStr);
4006        if (value != NAME_NOT_FOUND) {
4007            ALOGD("%s: Setting AWBLock value %s", __func__, mceStr);
4008            updateParamEntry(KEY_QC_MEMORY_COLOR_ENHANCEMENT, mceStr);
4009            return AddSetParmEntryToBatch(m_pParamBuf,
4010                                          CAM_INTF_PARM_MCE,
4011                                          sizeof(value),
4012                                          &value);
4013        }
4014    }
4015    ALOGE("Invalid MCE value: %s", (mceStr == NULL) ? "NULL" : mceStr);
4016    return BAD_VALUE;
4017}
4018
4019/*===========================================================================
4020 * FUNCTION   : setDISValue
4021 *
4022 * DESCRIPTION: set DIS value
4023 *
4024 * PARAMETERS :
4025 *   @disStr : DIS value string
4026 *
4027 * RETURN     : int32_t type of status
4028 *              NO_ERROR  -- success
4029 *              none-zero failure code
4030 *==========================================================================*/
4031int32_t QCameraParameters::setDISValue(const char *disStr)
4032{
4033    if (disStr != NULL) {
4034        int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
4035                                   sizeof(ENABLE_DISABLE_MODES_MAP)/sizeof(QCameraMap),
4036                                   disStr);
4037        if (value != NAME_NOT_FOUND) {
4038            ALOGD("%s: Setting DIS value %s", __func__, disStr);
4039            updateParamEntry(KEY_QC_DIS, disStr);
4040            return AddSetParmEntryToBatch(m_pParamBuf,
4041                                          CAM_INTF_PARM_DIS_ENABLE,
4042                                          sizeof(value),
4043                                          &value);
4044        }
4045    }
4046    ALOGE("Invalid DIS value: %s", (disStr == NULL) ? "NULL" : disStr);
4047    return BAD_VALUE;
4048}
4049
4050/*===========================================================================
4051 * FUNCTION   : setHighFrameRate
4052 *
4053 * DESCRIPTION: set high frame rate
4054 *
4055 * PARAMETERS :
4056 *   @hfrStr : HFR value string
4057 *
4058 * RETURN     : int32_t type of status
4059 *              NO_ERROR  -- success
4060 *              none-zero failure code
4061 *==========================================================================*/
4062int32_t QCameraParameters::setHighFrameRate(const char *hfrStr)
4063{
4064    if (hfrStr != NULL) {
4065        int32_t value = lookupAttr(HFR_MODES_MAP,
4066                                   sizeof(HFR_MODES_MAP)/sizeof(QCameraMap),
4067                                   hfrStr);
4068        if (value != NAME_NOT_FOUND) {
4069            // HFR value changed, need to restart preview
4070            m_bNeedRestart = true;
4071            // Set HFR value
4072            ALOGD("%s: Setting HFR value %s", __func__, hfrStr);
4073            updateParamEntry(KEY_QC_VIDEO_HIGH_FRAME_RATE, hfrStr);
4074            return AddSetParmEntryToBatch(m_pParamBuf,
4075                                          CAM_INTF_PARM_HFR,
4076                                          sizeof(value),
4077                                          &value);
4078        }
4079    }
4080    ALOGE("Invalid HFR value: %s", (hfrStr == NULL) ? "NULL" : hfrStr);
4081    return BAD_VALUE;
4082}
4083
4084/*===========================================================================
4085 * FUNCTION   : setLensShadeValue
4086 *
4087 * DESCRIPTION: set lens shade value
4088 *
4089 * PARAMETERS :
4090 *   @lensSahdeStr : lens shade value string
4091 *
4092 * RETURN     : int32_t type of status
4093 *              NO_ERROR  -- success
4094 *              none-zero failure code
4095 *==========================================================================*/
4096int32_t QCameraParameters::setLensShadeValue(const char *lensShadeStr)
4097{
4098    if (lensShadeStr != NULL) {
4099        int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
4100                                   sizeof(ENABLE_DISABLE_MODES_MAP)/sizeof(QCameraMap),
4101                                   lensShadeStr);
4102        if (value != NAME_NOT_FOUND) {
4103            ALOGD("%s: Setting LensShade value %s", __func__, lensShadeStr);
4104            updateParamEntry(KEY_QC_LENSSHADE, lensShadeStr);
4105            return AddSetParmEntryToBatch(m_pParamBuf,
4106                                          CAM_INTF_PARM_ROLLOFF,
4107                                          sizeof(value),
4108                                          &value);
4109        }
4110    }
4111    ALOGE("Invalid LensShade value: %s",
4112          (lensShadeStr == NULL) ? "NULL" : lensShadeStr);
4113    return BAD_VALUE;
4114}
4115
4116/*===========================================================================
4117 * FUNCTION   : setExposureCompensation
4118 *
4119 * DESCRIPTION: set exposure compensation value
4120 *
4121 * PARAMETERS :
4122 *   @expComp : exposure compensation value
4123 *
4124 * RETURN     : int32_t type of status
4125 *              NO_ERROR  -- success
4126 *              none-zero failure code
4127 *==========================================================================*/
4128int32_t QCameraParameters::setExposureCompensation(int expComp)
4129{
4130    char val[16];
4131    sprintf(val, "%d", expComp);
4132    updateParamEntry(KEY_EXPOSURE_COMPENSATION, val);
4133
4134    // Don't need to pass step as part of setParameter because
4135    // camera daemon is already aware of it.
4136    return AddSetParmEntryToBatch(m_pParamBuf,
4137                                  CAM_INTF_PARM_EXPOSURE_COMPENSATION,
4138                                  sizeof(expComp),
4139                                  &expComp);
4140}
4141
4142/*===========================================================================
4143 * FUNCTION   : setWhiteBalance
4144 *
4145 * DESCRIPTION: set white balance mode
4146 *
4147 * PARAMETERS :
4148 *   @wbStr   : white balance mode value string
4149 *
4150 * RETURN     : int32_t type of status
4151 *              NO_ERROR  -- success
4152 *              none-zero failure code
4153 *==========================================================================*/
4154int32_t QCameraParameters::setWhiteBalance(const char *wbStr)
4155{
4156    if (wbStr != NULL) {
4157        int32_t value = lookupAttr(WHITE_BALANCE_MODES_MAP,
4158                                   sizeof(WHITE_BALANCE_MODES_MAP)/sizeof(QCameraMap),
4159                                   wbStr);
4160        if (value != NAME_NOT_FOUND) {
4161            ALOGD("%s: Setting WhiteBalance value %s", __func__, wbStr);
4162            updateParamEntry(KEY_WHITE_BALANCE, wbStr);
4163            return AddSetParmEntryToBatch(m_pParamBuf,
4164                                          CAM_INTF_PARM_WHITE_BALANCE,
4165                                          sizeof(value),
4166                                          &value);
4167        }
4168    }
4169    ALOGE("Invalid WhiteBalance value: %s", (wbStr == NULL) ? "NULL" : wbStr);
4170    return BAD_VALUE;
4171}
4172
4173/*===========================================================================
4174 * FUNCTION   : setAntibanding
4175 *
4176 * DESCRIPTION: set antibanding value
4177 *
4178 * PARAMETERS :
4179 *   @antiBandingStr : antibanding value string
4180 *
4181 * RETURN     : int32_t type of status
4182 *              NO_ERROR  -- success
4183 *              none-zero failure code
4184 *==========================================================================*/
4185int32_t QCameraParameters::setAntibanding(const char *antiBandingStr)
4186{
4187    if (antiBandingStr != NULL) {
4188        int32_t value = lookupAttr(ANTIBANDING_MODES_MAP,
4189                                   sizeof(ANTIBANDING_MODES_MAP)/sizeof(QCameraMap),
4190                                   antiBandingStr);
4191        if (value != NAME_NOT_FOUND) {
4192            ALOGD("%s: Setting AntiBanding value %s", __func__, antiBandingStr);
4193            updateParamEntry(KEY_ANTIBANDING, antiBandingStr);
4194            return AddSetParmEntryToBatch(m_pParamBuf,
4195                                          CAM_INTF_PARM_ANTIBANDING,
4196                                          sizeof(value),
4197                                          &value);
4198        }
4199    }
4200    ALOGE("Invalid AntiBanding value: %s",
4201          (antiBandingStr == NULL) ? "NULL" : antiBandingStr);
4202    return BAD_VALUE;
4203}
4204
4205/*===========================================================================
4206 * FUNCTION   : setFocusAreas
4207 *
4208 * DESCRIPTION: set focus areas
4209 *
4210 * PARAMETERS :
4211 *   @focusAreasStr : focus areas value string
4212 *
4213 * RETURN     : int32_t type of status
4214 *              NO_ERROR  -- success
4215 *              none-zero failure code
4216 *==========================================================================*/
4217int32_t QCameraParameters::setFocusAreas(const char *focusAreasStr)
4218{
4219    if (m_pCapability->max_num_focus_areas == 0 ||
4220        focusAreasStr == NULL) {
4221        ALOGI("%s: Parameter string is null", __func__);
4222        return NO_ERROR;
4223    }
4224
4225    cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
4226    if (NULL == areas) {
4227        ALOGE("%s: No memory for areas", __func__);
4228        return NO_MEMORY;
4229    }
4230    memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
4231    int num_areas_found = 0;
4232    if (parseCameraAreaString(focusAreasStr,
4233                              m_pCapability->max_num_focus_areas,
4234                              areas,
4235                              num_areas_found) != NO_ERROR) {
4236        ALOGE("%s: Failed to parse the string: %s", __func__, focusAreasStr);
4237        free(areas);
4238        return BAD_VALUE;
4239    }
4240
4241    if (validateCameraAreas(areas, num_areas_found) == false) {
4242        ALOGE("%s: invalid areas specified : %s", __func__, focusAreasStr);
4243        free(areas);
4244        return BAD_VALUE;
4245    }
4246
4247    updateParamEntry(KEY_FOCUS_AREAS, focusAreasStr);
4248
4249    //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
4250    //so no action is takenby the lower layer
4251    if (num_areas_found == 1 &&
4252        areas[0].rect.left == 0 &&
4253        areas[0].rect.top == 0 &&
4254        areas[0].rect.width == 0 &&
4255        areas[0].rect.height == 0 &&
4256        areas[0].weight == 0) {
4257        num_areas_found = 0;
4258    }
4259
4260    int previewWidth, previewHeight;
4261    getPreviewSize(&previewWidth, &previewHeight);
4262    cam_roi_info_t af_roi_value;
4263    memset(&af_roi_value, 0, sizeof(cam_roi_info_t));
4264    af_roi_value.num_roi = num_areas_found;
4265    for (int i = 0; i < num_areas_found; i++) {
4266        ALOGD("%s: FocusArea[%d] = (%d, %d, %d, %d)",
4267              __func__, i, (areas[i].rect.top), (areas[i].rect.left),
4268              (areas[i].rect.width), (areas[i].rect.height));
4269
4270        //transform the coords from (-1000, 1000) to (0, previewWidth or previewHeight)
4271        af_roi_value.roi[i].left = (int32_t)((areas[i].rect.left + 1000.0f) * (previewWidth / 2000.0f));
4272        af_roi_value.roi[i].top = (int32_t)((areas[i].rect.top + 1000.0f) * (previewHeight / 2000.0f));
4273        af_roi_value.roi[i].width = (int32_t)(areas[i].rect.width * previewWidth / 2000.0f);
4274        af_roi_value.roi[i].height = (int32_t)(areas[i].rect.height * previewHeight / 2000.0f);
4275        af_roi_value.weight[i] = areas[i].weight;
4276    }
4277    free(areas);
4278    return AddSetParmEntryToBatch(m_pParamBuf,
4279                                  CAM_INTF_PARM_AF_ROI,
4280                                  sizeof(af_roi_value),
4281                                  &af_roi_value);
4282}
4283
4284/*===========================================================================
4285 * FUNCTION   : setMeteringAreas
4286 *
4287 * DESCRIPTION: set metering areas value
4288 *
4289 * PARAMETERS :
4290 *   @meteringAreasStr : metering areas value string
4291 *
4292 * RETURN     : int32_t type of status
4293 *              NO_ERROR  -- success
4294 *              none-zero failure code
4295 *==========================================================================*/
4296int32_t QCameraParameters::setMeteringAreas(const char *meteringAreasStr)
4297{
4298    if (m_pCapability->max_num_metering_areas == 0 ||
4299        meteringAreasStr == NULL) {
4300        ALOGI("%s: Parameter string is null", __func__);
4301        return NO_ERROR;
4302    }
4303
4304    cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
4305    if (NULL == areas) {
4306        ALOGE("%s: No memory for areas", __func__);
4307        return NO_MEMORY;
4308    }
4309    memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
4310    int num_areas_found = 0;
4311    if (parseCameraAreaString(meteringAreasStr,
4312                              m_pCapability->max_num_metering_areas,
4313                              areas,
4314                              num_areas_found) < 0) {
4315        ALOGE("%s: Failed to parse the string: %s", __func__, meteringAreasStr);
4316        free(areas);
4317        return BAD_VALUE;
4318    }
4319
4320    if (validateCameraAreas(areas, num_areas_found) == false) {
4321        ALOGE("%s: invalid areas specified : %s", __func__, meteringAreasStr);
4322        free(areas);
4323        return BAD_VALUE;
4324    }
4325
4326    updateParamEntry(KEY_METERING_AREAS, meteringAreasStr);
4327
4328    //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
4329    //so no action is takenby the lower layer
4330    if (num_areas_found == 1 &&
4331        areas[0].rect.left == 0 &&
4332        areas[0].rect.top == 0 &&
4333        areas[0].rect.width == 0 &&
4334        areas[0].rect.height == 0 &&
4335        areas[0].weight == 0) {
4336        num_areas_found = 0;
4337    }
4338    cam_set_aec_roi_t aec_roi_value;
4339    int previewWidth, previewHeight;
4340    getPreviewSize(&previewWidth, &previewHeight);
4341
4342    memset(&aec_roi_value, 0, sizeof(cam_set_aec_roi_t));
4343    if (num_areas_found > 0) {
4344        aec_roi_value.aec_roi_enable = CAM_AEC_ROI_ON;
4345        aec_roi_value.aec_roi_type = CAM_AEC_ROI_BY_COORDINATE;
4346
4347        for (int i = 0; i < num_areas_found; i++) {
4348            ALOGD("%s: MeteringArea[%d] = (%d, %d, %d, %d)",
4349                  __func__, i, (areas[i].rect.top), (areas[i].rect.left),
4350                  (areas[i].rect.width), (areas[i].rect.height));
4351
4352            //transform the coords from (-1000, 1000) to (0, previewWidth or previewHeight)
4353            aec_roi_value.cam_aec_roi_position.coordinate[i].x =
4354                (uint32_t)(((areas[i].rect.left + areas[i].rect.width / 2) + 1000.0f) * previewWidth / 2000.0f) ;
4355            aec_roi_value.cam_aec_roi_position.coordinate[i].y =
4356                (uint32_t)(((areas[i].rect.top + areas[i].rect.height / 2) + 1000.0f) * previewHeight / 2000.0f) ;
4357        }
4358    } else {
4359        aec_roi_value.aec_roi_enable = CAM_AEC_ROI_OFF;
4360    }
4361    free(areas);
4362    return AddSetParmEntryToBatch(m_pParamBuf,
4363                                  CAM_INTF_PARM_AEC_ROI,
4364                                  sizeof(aec_roi_value),
4365                                  &aec_roi_value);
4366}
4367
4368/*===========================================================================
4369 * FUNCTION   : setSceneMode
4370 *
4371 * DESCRIPTION: set scene mode
4372 *
4373 * PARAMETERS :
4374 *   @sceneModeStr : scene mode value string
4375 *
4376 * RETURN     : int32_t type of status
4377 *              NO_ERROR  -- success
4378 *              none-zero failure code
4379 *==========================================================================*/
4380int32_t QCameraParameters::setSceneMode(const char *sceneModeStr)
4381{
4382    if (sceneModeStr != NULL) {
4383        int32_t value = lookupAttr(SCENE_MODES_MAP,
4384                                   sizeof(SCENE_MODES_MAP)/sizeof(QCameraMap),
4385                                   sceneModeStr);
4386        if (value != NAME_NOT_FOUND) {
4387            ALOGV("%s: Setting SceneMode %s", __func__, sceneModeStr);
4388            updateParamEntry(KEY_SCENE_MODE, sceneModeStr);
4389            int32_t rc = AddSetParmEntryToBatch(m_pParamBuf,
4390                                                CAM_INTF_PARM_BESTSHOT_MODE,
4391                                                sizeof(value),
4392                                                &value);
4393            return rc;
4394        }
4395    }
4396    ALOGE("%s: Invalid Secene Mode: %s",
4397          __func__, (sceneModeStr == NULL) ? "NULL" : sceneModeStr);
4398    return BAD_VALUE;
4399}
4400
4401/*===========================================================================
4402 * FUNCTION   : setSelectableZoneAf
4403 *
4404 * DESCRIPTION: set selectable zone AF algorithm
4405 *
4406 * PARAMETERS :
4407 *   @selZoneAFStr : selectable zone AF algorithm value string
4408 *
4409 * RETURN     : int32_t type of status
4410 *              NO_ERROR  -- success
4411 *              none-zero failure code
4412 *==========================================================================*/
4413int32_t QCameraParameters::setSelectableZoneAf(const char *selZoneAFStr)
4414{
4415    if (selZoneAFStr != NULL) {
4416        int32_t value = lookupAttr(FOCUS_ALGO_MAP,
4417                                   sizeof(FOCUS_ALGO_MAP)/sizeof(QCameraMap),
4418                                   selZoneAFStr);
4419        if (value != NAME_NOT_FOUND) {
4420            ALOGV("%s: Setting Selectable Zone AF value %s", __func__, selZoneAFStr);
4421            updateParamEntry(KEY_QC_SELECTABLE_ZONE_AF, selZoneAFStr);
4422            return AddSetParmEntryToBatch(m_pParamBuf,
4423                                          CAM_INTF_PARM_FOCUS_ALGO_TYPE,
4424                                          sizeof(value),
4425                                          &value);
4426        }
4427    }
4428    ALOGE("%s: Invalid selectable zone af value: %s",
4429          __func__, (selZoneAFStr == NULL) ? "NULL" : selZoneAFStr);
4430    return BAD_VALUE;
4431}
4432
4433/*===========================================================================
4434 * FUNCTION   : setAEBracket
4435 *
4436 * DESCRIPTION: set AE bracket value
4437 *
4438 * PARAMETERS :
4439 *   @aecBracketStr : AE bracket value string
4440 *
4441 * RETURN     : int32_t type of status
4442 *              NO_ERROR  -- success
4443 *              none-zero failure code
4444 *==========================================================================*/
4445int32_t QCameraParameters::setAEBracket(const char *aecBracketStr)
4446{
4447    if (aecBracketStr == NULL) {
4448        ALOGI("%s: setAEBracket with NULL value", __func__);
4449        return NO_ERROR;
4450    }
4451
4452    cam_exp_bracketing_t expBracket;
4453    memset(&expBracket, 0, sizeof(expBracket));
4454
4455    int value = lookupAttr(BRACKETING_MODES_MAP,
4456                           sizeof(BRACKETING_MODES_MAP)/sizeof(QCameraMap),
4457                           aecBracketStr);
4458    switch (value) {
4459    case CAM_EXP_BRACKETING_ON:
4460        {
4461            ALOGV("%s, EXP_BRACKETING_ON", __func__);
4462            const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
4463            if ((str_val != NULL) && (strlen(str_val)>0)) {
4464                expBracket.mode = CAM_EXP_BRACKETING_ON;
4465                strlcpy(expBracket.values, str_val, MAX_EXP_BRACKETING_LENGTH);
4466                ALOGI("%s: setting Exposure Bracketing value of %s",
4467                      __func__, expBracket.values);
4468            }
4469            else {
4470                /* Apps not set capture-burst-exposures, error case fall into bracketing off mode */
4471                ALOGI("%s: capture-burst-exposures not set, back to HDR OFF mode", __func__);
4472                expBracket.mode = CAM_EXP_BRACKETING_OFF;
4473            }
4474        }
4475        break;
4476    default:
4477        {
4478            ALOGD("%s, EXP_BRACKETING_OFF", __func__);
4479            expBracket.mode = CAM_EXP_BRACKETING_OFF;
4480        }
4481        break;
4482    }
4483
4484    /* save the value*/
4485    updateParamEntry(KEY_QC_AE_BRACKET_HDR, aecBracketStr);
4486    return AddSetParmEntryToBatch(m_pParamBuf,
4487                                  CAM_INTF_PARM_HDR,
4488                                  sizeof(expBracket),
4489                                  &expBracket);
4490}
4491
4492/*===========================================================================
4493 * FUNCTION   : setRedeyeReduction
4494 *
4495 * DESCRIPTION: set red eye reduction value
4496 *
4497 * PARAMETERS :
4498 *   @redeyeStr : red eye reduction value string
4499 *
4500 * RETURN     : int32_t type of status
4501 *              NO_ERROR  -- success
4502 *              none-zero failure code
4503 *==========================================================================*/
4504int32_t QCameraParameters::setRedeyeReduction(const char *redeyeStr)
4505{
4506    if (redeyeStr != NULL) {
4507        int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
4508                                   sizeof(ENABLE_DISABLE_MODES_MAP)/sizeof(QCameraMap),
4509                                   redeyeStr);
4510        if (value != NAME_NOT_FOUND) {
4511            ALOGV("%s: Setting RedEye Reduce value %s", __func__, redeyeStr);
4512            updateParamEntry(KEY_QC_REDEYE_REDUCTION, redeyeStr);
4513            return AddSetParmEntryToBatch(m_pParamBuf,
4514                                          CAM_INTF_PARM_REDEYE_REDUCTION,
4515                                          sizeof(value),
4516                                          &value);
4517        }
4518    }
4519    ALOGE("%s: Invalid RedEye Reduce value: %s",
4520          __func__, (redeyeStr == NULL) ? "NULL" : redeyeStr);
4521    return BAD_VALUE;
4522}
4523
4524/*===========================================================================
4525 * FUNCTION   : getWaveletDenoiseProcessPlate
4526 *
4527 * DESCRIPTION: query wavelet denoise process plate
4528 *
4529 * PARAMETERS : None
4530 *
4531 * RETURN     : WNR prcocess plate vlaue
4532 *==========================================================================*/
4533cam_denoise_process_type_t QCameraParameters::getWaveletDenoiseProcessPlate()
4534{
4535    char prop[PROPERTY_VALUE_MAX];
4536    memset(prop, 0, sizeof(prop));
4537    property_get("persist.denoise.process.plates", prop, "0");
4538    int processPlate = atoi(prop);
4539    switch(processPlate) {
4540    case 0:
4541        return CAM_WAVELET_DENOISE_YCBCR_PLANE;
4542    case 1:
4543        return CAM_WAVELET_DENOISE_CBCR_ONLY;
4544    case 2:
4545        return CAM_WAVELET_DENOISE_STREAMLINE_YCBCR;
4546    case 3:
4547        return CAM_WAVELET_DENOISE_STREAMLINED_CBCR;
4548    default:
4549        return CAM_WAVELET_DENOISE_STREAMLINE_YCBCR;
4550    }
4551}
4552
4553/*===========================================================================
4554 * FUNCTION   : setWaveletDenoise
4555 *
4556 * DESCRIPTION: set wavelet denoise value
4557 *
4558 * PARAMETERS :
4559 *   @wnrStr : wavelet denoise value string
4560 *
4561 * RETURN     : int32_t type of status
4562 *              NO_ERROR  -- success
4563 *              none-zero failure code
4564 *==========================================================================*/
4565int32_t QCameraParameters::setWaveletDenoise(const char *wnrStr)
4566{
4567    if (wnrStr != NULL) {
4568        int value = lookupAttr(DENOISE_ON_OFF_MODES_MAP,
4569                               sizeof(DENOISE_ON_OFF_MODES_MAP)/sizeof(QCameraMap),
4570                               wnrStr);
4571        if (value != NAME_NOT_FOUND) {
4572            updateParamEntry(KEY_QC_DENOISE, wnrStr);
4573
4574            cam_denoise_param_t temp;
4575            memset(&temp, 0, sizeof(temp));
4576            temp.denoise_enable = value;
4577            m_bWNROn = (value != 0);
4578            if (m_bWNROn) {
4579                temp.process_plates = getWaveletDenoiseProcessPlate();
4580            }
4581            ALOGI("%s: Denoise enable=%d, plates=%d",
4582                  __func__, temp.denoise_enable, temp.process_plates);
4583            return AddSetParmEntryToBatch(m_pParamBuf,
4584                                          CAM_INTF_PARM_WAVELET_DENOISE,
4585                                          sizeof(temp),
4586                                          &temp);
4587        }
4588    }
4589    ALOGE("%s: Invalid Denoise value: %s", __func__, (wnrStr == NULL) ? "NULL" : wnrStr);
4590    return BAD_VALUE;
4591}
4592
4593/*===========================================================================
4594 * FUNCTION   : setPreviewFrameRateMode
4595 *
4596 * DESCRIPTION: set preview frame rate mode
4597 *
4598 * PARAMETERS :
4599 *   @mode    : preview frame rate mode
4600 *
4601 * RETURN     : none
4602 *==========================================================================*/
4603void QCameraParameters::setPreviewFrameRateMode(const char *mode)
4604{
4605    set(KEY_QC_PREVIEW_FRAME_RATE_MODE, mode);
4606}
4607
4608/*===========================================================================
4609 * FUNCTION   : getPreviewFrameRateMode
4610 *
4611 * DESCRIPTION: get preview frame rate mode
4612 *
4613 * PARAMETERS : none
4614 *
4615 * RETURN     : preview frame rate mode string
4616 *==========================================================================*/
4617const char *QCameraParameters::getPreviewFrameRateMode() const
4618{
4619    return get(KEY_QC_PREVIEW_FRAME_RATE_MODE);
4620}
4621
4622/*===========================================================================
4623 * FUNCTION   : setTouchIndexAec
4624 *
4625 * DESCRIPTION: set touch index AEC
4626 *
4627 * PARAMETERS :
4628 *   @x,y     :
4629 *
4630 * RETURN     : none
4631 *==========================================================================*/
4632void QCameraParameters::setTouchIndexAec(int x, int y)
4633{
4634    char str[32];
4635    snprintf(str, sizeof(str), "%dx%d", x, y);
4636    set(KEY_QC_TOUCH_INDEX_AEC, str);
4637}
4638
4639/*===========================================================================
4640 * FUNCTION   : getTouchIndexAec
4641 *
4642 * DESCRIPTION: get touch index AEC
4643 *
4644 * PARAMETERS :
4645 *   @x,y     :
4646 *
4647 * RETURN     : none
4648 *==========================================================================*/
4649void QCameraParameters::getTouchIndexAec(int *x, int *y)
4650{
4651    *x = -1;
4652    *y = -1;
4653
4654    // Get the current string, if it doesn't exist, leave the -1x-1
4655    const char *p = get(KEY_QC_TOUCH_INDEX_AEC);
4656    if (p == 0)
4657        return;
4658
4659    int tempX, tempY;
4660    if (parse_pair(p, &tempX, &tempY, 'x') == 0) {
4661        *x = tempX;
4662        *y = tempY;
4663    }
4664}
4665
4666/*===========================================================================
4667 * FUNCTION   : setTouchIndexAf
4668 *
4669 * DESCRIPTION: set touch index AF
4670 *
4671 * PARAMETERS :
4672 *   @x,y     :
4673 *
4674 * RETURN     : none
4675 *==========================================================================*/
4676void QCameraParameters::setTouchIndexAf(int x, int y)
4677{
4678    char str[32];
4679    snprintf(str, sizeof(str), "%dx%d", x, y);
4680    set(KEY_QC_TOUCH_INDEX_AF, str);
4681}
4682
4683/*===========================================================================
4684 * FUNCTION   : getTouchIndexAf
4685 *
4686 * DESCRIPTION: get touch index AF
4687 *
4688 * PARAMETERS :
4689 *   @x,y     :
4690 *
4691 * RETURN     : none
4692 *==========================================================================*/
4693void QCameraParameters::getTouchIndexAf(int *x, int *y)
4694{
4695    *x = -1;
4696    *y = -1;
4697
4698    // Get the current string, if it doesn't exist, leave the -1x-1
4699    const char *p = get(KEY_QC_TOUCH_INDEX_AF);
4700    if (p == 0)
4701        return;
4702
4703    int tempX, tempY;
4704    if (parse_pair(p, &tempX, &tempY, 'x') == 0) {
4705        *x = tempX;
4706        *y = tempY;
4707	}
4708}
4709
4710/*===========================================================================
4711 * FUNCTION   : getStreamFormat
4712 *
4713 * DESCRIPTION: get stream format by its type
4714 *
4715 * PARAMETERS :
4716 *   @streamType : [input] stream type
4717 *   @format     : [output] stream format
4718 *
4719 * RETURN     : int32_t type of status
4720 *              NO_ERROR  -- success
4721 *              none-zero failure code
4722 *==========================================================================*/
4723int32_t QCameraParameters::getStreamFormat(cam_stream_type_t streamType,
4724                                            cam_format_t &format)
4725{
4726    int32_t ret = NO_ERROR;
4727
4728    format = CAM_FORMAT_MAX;
4729    switch (streamType) {
4730    case CAM_STREAM_TYPE_PREVIEW:
4731    case CAM_STREAM_TYPE_POSTVIEW:
4732        format = mPreviewFormat;
4733        break;
4734    case CAM_STREAM_TYPE_SNAPSHOT:
4735        if ( mPictureFormat == CAM_FORMAT_YUV_422_NV16 ) {
4736            format = CAM_FORMAT_YUV_422_NV16;
4737        } else {
4738            char prop[PROPERTY_VALUE_MAX];
4739            int snapshotFormat;
4740            memset(prop, 0, sizeof(prop));
4741            property_get("persist.camera.snap.format", prop, "0");
4742            snapshotFormat = atoi(prop);
4743            if(snapshotFormat == 1) {
4744                format = CAM_FORMAT_YUV_422_NV61;
4745            } else {
4746                format = CAM_FORMAT_YUV_420_NV21;
4747            }
4748        }
4749        break;
4750    case CAM_STREAM_TYPE_VIDEO:
4751        format = CAM_FORMAT_YUV_420_NV12;
4752        break;
4753    case CAM_STREAM_TYPE_RAW:
4754        if (mPictureFormat >= CAM_FORMAT_YUV_RAW_8BIT_YUYV) {
4755            format = (cam_format_t)mPictureFormat;
4756        } else {
4757            ALOGE("%s: invalid raw picture format: %d", __func__, mPictureFormat);
4758            ret = BAD_VALUE;
4759        }
4760        break;
4761    case CAM_STREAM_TYPE_METADATA:
4762    case CAM_STREAM_TYPE_OFFLINE_PROC:
4763    case CAM_STREAM_TYPE_DEFAULT:
4764    default:
4765        break;
4766    }
4767
4768    return ret;
4769}
4770
4771/*===========================================================================
4772 * FUNCTION   : getFlipMode
4773 *
4774 * DESCRIPTION: get flip mode
4775 *
4776 * PARAMETERS :
4777 *   @cam_intf_parm_type_t : [input] stream type
4778 *
4779 * RETURN     : int type of flip mode
4780 *              0 - no filp
4781 *              1 - FLIP_H
4782 *              2 - FLIP_V
4783 *              3 - FLIP_H | FLIP_V
4784 *==========================================================================*/
4785int QCameraParameters::getFlipMode(cam_stream_type_t type)
4786{
4787    const char *str = NULL;
4788    int flipMode = 0; // no flip
4789
4790    switch(type){
4791    case CAM_STREAM_TYPE_PREVIEW:
4792        str = get(KEY_QC_PREVIEW_FLIP);
4793        break;
4794    case CAM_STREAM_TYPE_VIDEO:
4795        str = get(KEY_QC_VIDEO_FLIP);
4796        break;
4797    case CAM_STREAM_TYPE_SNAPSHOT:
4798        str = get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
4799        break;
4800    default:
4801        ALOGI("%s: No flip mode for stream type %d", __func__, type);
4802        break;
4803    }
4804
4805    if(str != NULL){
4806        //Need give corresponding filp value based on flip mode strings
4807        int value = lookupAttr(FLIP_MODES_MAP,
4808                sizeof(FLIP_MODES_MAP)/sizeof(QCameraMap), str);
4809        if(value != NAME_NOT_FOUND)
4810            flipMode = value;
4811        }
4812
4813    ALOGD("%s: the filp mode of stream type %d is %d .", __func__, type, flipMode);
4814    return flipMode;
4815}
4816
4817/*===========================================================================
4818 * FUNCTION   : getStreamDimension
4819 *
4820 * DESCRIPTION: get stream dimension by its type
4821 *
4822 * PARAMETERS :
4823 *   @streamType : [input] stream type
4824 *   @dim        : [output] stream dimension
4825 *
4826 * RETURN     : int32_t type of status
4827 *              NO_ERROR  -- success
4828 *              none-zero failure code
4829 *==========================================================================*/
4830int32_t QCameraParameters::getStreamDimension(cam_stream_type_t streamType,
4831                                               cam_dimension_t &dim)
4832{
4833    int32_t ret = NO_ERROR;
4834    memset(&dim, 0, sizeof(cam_dimension_t));
4835
4836    switch (streamType) {
4837    case CAM_STREAM_TYPE_PREVIEW:
4838        getPreviewSize(&dim.width, &dim.height);
4839        break;
4840    case CAM_STREAM_TYPE_POSTVIEW:
4841        getPreviewSize(&dim.width, &dim.height);
4842        break;
4843    case CAM_STREAM_TYPE_SNAPSHOT:
4844        if (getRecordingHintValue() == true) {
4845            // live snapshot
4846            getLiveSnapshotSize(dim);
4847        } else {
4848            getPictureSize(&dim.width, &dim.height);
4849        }
4850        break;
4851    case CAM_STREAM_TYPE_VIDEO:
4852        getVideoSize(&dim.width, &dim.height);
4853        break;
4854    case CAM_STREAM_TYPE_RAW:
4855        dim = m_pCapability->raw_dim;
4856        break;
4857    case CAM_STREAM_TYPE_METADATA:
4858        dim.width = sizeof(cam_metadata_info_t);
4859        dim.height = 1;
4860        break;
4861    case CAM_STREAM_TYPE_OFFLINE_PROC:
4862        break;
4863    case CAM_STREAM_TYPE_DEFAULT:
4864    default:
4865        ALOGE("%s: no dimension for unsupported stream type %d",
4866              __func__, streamType);
4867        ret = BAD_VALUE;
4868        break;
4869    }
4870    return ret;
4871}
4872
4873/*===========================================================================
4874 * FUNCTION   : getPreviewHalPixelFormat
4875 *
4876 * DESCRIPTION: get preview HAL pixel format
4877 *
4878 * PARAMETERS : none
4879 *
4880 * RETURN     : HAL pixel format
4881 *==========================================================================*/
4882int QCameraParameters::getPreviewHalPixelFormat() const
4883{
4884    int32_t halPixelFormat;
4885
4886    switch (mPreviewFormat) {
4887    case CAM_FORMAT_YUV_420_NV12:
4888        halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP;
4889        break;
4890    case CAM_FORMAT_YUV_420_NV21:
4891        halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
4892        break;
4893    case CAM_FORMAT_YUV_420_NV21_ADRENO:
4894        halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO;
4895        break;
4896    case CAM_FORMAT_YUV_420_YV12:
4897        halPixelFormat = HAL_PIXEL_FORMAT_YV12;
4898        break;
4899    case CAM_FORMAT_YUV_422_NV16:
4900    case CAM_FORMAT_YUV_422_NV61:
4901    default:
4902        halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
4903        break;
4904    }
4905    ALOGE("%s: format %d\n", __func__, halPixelFormat);
4906    return halPixelFormat;
4907}
4908
4909/*===========================================================================
4910 * FUNCTION   : getthumbnailSize
4911 *
4912 * DESCRIPTION: get thumbnail size
4913 *
4914 * PARAMETERS :
4915 *   @width, height : [output] thumbnail width and height
4916 *
4917 * RETURN     : none
4918 *==========================================================================*/
4919void QCameraParameters::getThumbnailSize(int *width, int *height) const
4920{
4921    *width = getInt(KEY_JPEG_THUMBNAIL_WIDTH);
4922    *height = getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
4923}
4924
4925/*===========================================================================
4926 * FUNCTION   : getZSLBurstInterval
4927 *
4928 * DESCRIPTION: get ZSL burst interval setting
4929 *
4930 * PARAMETERS : none
4931 *
4932 * RETURN     : ZSL burst interval value
4933 *==========================================================================*/
4934int QCameraParameters::getZSLBurstInterval()
4935{
4936    int interval = getInt(KEY_QC_ZSL_BURST_INTERVAL);
4937    if (interval < 0) {
4938        interval = 1;
4939    }
4940    return interval;
4941}
4942
4943/*===========================================================================
4944 * FUNCTION   : getZSLQueueDepth
4945 *
4946 * DESCRIPTION: get ZSL queue depth
4947 *
4948 * PARAMETERS : none
4949 *
4950 * RETURN     : ZSL queue depth value
4951 *==========================================================================*/
4952int QCameraParameters::getZSLQueueDepth()
4953{
4954    int qdepth = getInt(KEY_QC_ZSL_QUEUE_DEPTH);
4955    if (qdepth < 0) {
4956        qdepth = 2;
4957    }
4958    return qdepth;
4959}
4960
4961/*===========================================================================
4962 * FUNCTION   : getZSLBackLookCount
4963 *
4964 * DESCRIPTION: get ZSL backlook count setting
4965 *
4966 * PARAMETERS : none
4967 *
4968 * RETURN     : ZSL backlook count value
4969 *==========================================================================*/
4970int QCameraParameters::getZSLBackLookCount()
4971{
4972    int look_back = getInt(KEY_QC_ZSL_BURST_LOOKBACK);
4973    if (look_back < 0) {
4974        look_back = 2;
4975    }
4976    return look_back;
4977}
4978
4979/*===========================================================================
4980 * FUNCTION   : getZSLMaxUnmatchedFrames
4981 *
4982 * DESCRIPTION: get allowed ZSL max unmatched frames number
4983 *
4984 * PARAMETERS : none
4985 *
4986 * RETURN     : ZSL backlook count value
4987 *==========================================================================*/
4988int QCameraParameters::getMaxUnmatchedFramesInQueue()
4989{
4990    return m_pCapability->min_num_pp_bufs;
4991}
4992
4993/*===========================================================================
4994 * FUNCTION   : setRecordingHintValue
4995 *
4996 * DESCRIPTION: set recording hint
4997 *
4998 * PARAMETERS :
4999 *   @value   : video hint value
5000 *
5001 * RETURN     : int32_t type of status
5002 *              NO_ERROR  -- success
5003 *              none-zero failure code
5004 *==========================================================================*/
5005int QCameraParameters::setRecordingHintValue(int32_t value)
5006{
5007    ALOGD("%s: VideoHint = %d", __func__, value);
5008    m_bRecordingHint = (value > 0)? true : false;
5009    return AddSetParmEntryToBatch(m_pParamBuf,
5010                                  CAM_INTF_PARM_RECORDING_HINT,
5011                                  sizeof(value),
5012                                  &value);
5013}
5014
5015/*===========================================================================
5016 * FUNCTION   : getNumOfSnapshots
5017 *
5018 * DESCRIPTION: get number of snapshot per shutter
5019 *
5020 * PARAMETERS : none
5021 *
5022 * RETURN     : number of snapshot per shutter
5023 *==========================================================================*/
5024uint8_t QCameraParameters::getNumOfSnapshots()
5025{
5026    int numOfSnapshot = getInt(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER);
5027    if (numOfSnapshot <= 0) {
5028        numOfSnapshot = 1; // set to default value
5029    }
5030    return (uint8_t)numOfSnapshot;
5031}
5032
5033/*===========================================================================
5034 * FUNCTION   : getNumOfExtraHDRBufsIfNeeded
5035 *
5036 * DESCRIPTION: get number of extra buffers needed by HDR if HDR is enabled
5037 *
5038 * PARAMETERS : none
5039 *
5040 * RETURN     : number of extra buffer needed by HDR; 0 if not HDR enabled
5041 *==========================================================================*/
5042uint8_t QCameraParameters::getNumOfExtraHDRBufsIfNeeded()
5043{
5044    uint8_t numOfBufs = 0;
5045    const char *scene_mode = get(KEY_SCENE_MODE);
5046    if (scene_mode != NULL && strcmp(scene_mode, SCENE_MODE_HDR) == 0) {
5047        // HDR mode
5048        numOfBufs = getBurstNum() * m_pCapability->min_num_hdr_bufs;
5049    }
5050    return numOfBufs;
5051}
5052
5053/*===========================================================================
5054 * FUNCTION   : getNumOfHDRBufsIfNeeded
5055 *
5056 * DESCRIPTION: get number of buffers needed by HDR if HDR is enabled
5057 *
5058 * PARAMETERS : none
5059 *
5060 * RETURN     : number of buffer needed by HDR; 0 if not HDR enabled
5061 *==========================================================================*/
5062uint8_t QCameraParameters::getNumOfHDRBufsIfNeeded()
5063{
5064    uint8_t numOfBufs = 0;
5065    const char *scene_mode = get(KEY_SCENE_MODE);
5066    if (scene_mode != NULL && strcmp(scene_mode, SCENE_MODE_HDR) == 0) {
5067        // HDR mode
5068        const char *need_hdr_1x = get(KEY_QC_HDR_NEED_1X);
5069        if (need_hdr_1x != NULL && strcmp(need_hdr_1x, VALUE_TRUE) == 0) {
5070            numOfBufs = 2; // HDR needs both 1X and processed img
5071        } else {
5072            numOfBufs = 1; // HDR only needs processed img
5073        }
5074
5075        numOfBufs += m_pCapability->min_num_hdr_bufs;
5076    }
5077    return numOfBufs;
5078}
5079
5080/*===========================================================================
5081 * FUNCTION   : getBurstNum
5082 *
5083 * DESCRIPTION: get burst number of snapshot
5084 *
5085 * PARAMETERS : none
5086 *
5087 * RETURN     : number of burst
5088 *==========================================================================*/
5089int QCameraParameters::getBurstNum()
5090{
5091    char prop[PROPERTY_VALUE_MAX];
5092    memset(prop, 0, sizeof(prop));
5093    property_get("persist.camera.snapshot.number", prop, "0");
5094    int nBurstNum = atoi(prop);
5095    if (nBurstNum > 0) {
5096        ALOGD("%s: Reading burst number = %d from properties",
5097              __func__, nBurstNum);
5098    } else {
5099        nBurstNum = 1;
5100    }
5101    return nBurstNum;
5102}
5103
5104/*===========================================================================
5105 * FUNCTION   : getJpegQuality
5106 *
5107 * DESCRIPTION: get jpeg encoding quality
5108 *
5109 * PARAMETERS : none
5110 *
5111 * RETURN     : jpeg encoding quality
5112 *==========================================================================*/
5113int QCameraParameters::getJpegQuality()
5114{
5115    int quality = getInt(KEY_JPEG_QUALITY);
5116    if (quality < 0) {
5117        quality = 85; // set to default quality value
5118    }
5119    return quality;
5120}
5121
5122/*===========================================================================
5123 * FUNCTION   : getJpegRotation
5124 *
5125 * DESCRIPTION: get rotation value
5126 *
5127 * PARAMETERS : none
5128 *
5129 * RETURN     : rotation value
5130 *==========================================================================*/
5131int QCameraParameters::getJpegRotation() {
5132    int rotation = getInt(KEY_ROTATION);
5133    if (rotation < 0) {
5134        rotation = 0;
5135    }
5136    return rotation;
5137}
5138
5139/*===========================================================================
5140 * FUNCTION   : parseGPSCoordinate
5141 *
5142 * DESCRIPTION: parse GPS coordinate string
5143 *
5144 * PARAMETERS :
5145 *   @coord_str : [input] coordinate string
5146 *   @coord     : [output]  ptr to struct to store coordinate
5147 *
5148 * RETURN     : int32_t type of status
5149 *              NO_ERROR  -- success
5150 *              none-zero failure code
5151 *==========================================================================*/
5152int QCameraParameters::parseGPSCoordinate(const char *coord_str, rat_t* coord)
5153{
5154    if(coord == NULL) {
5155        ALOGE("%s: error, invalid argument coord == NULL", __func__);
5156        return BAD_VALUE;
5157    }
5158    float degF = atof(coord_str);
5159    if (degF < 0) {
5160        degF = -degF;
5161    }
5162    float minF = (degF - (int) degF) * 60;
5163    float secF = (minF - (int) minF) * 60;
5164
5165    getRational(&coord[0], (int)degF, 1);
5166    getRational(&coord[1], (int)minF, 1);
5167    getRational(&coord[2], (int)(secF * 10000), 10000);
5168    return NO_ERROR;
5169}
5170
5171/*===========================================================================
5172 * FUNCTION   : getExifDateTime
5173 *
5174 * DESCRIPTION: query exif date time
5175 *
5176 * PARAMETERS :
5177 *   @dateTime : string to store exif date time
5178 *   @count    : lenght of the dateTime string
5179 *
5180 * RETURN     : int32_t type of status
5181 *              NO_ERROR  -- success
5182 *              none-zero failure code
5183 *==========================================================================*/
5184int32_t QCameraParameters::getExifDateTime(char *dateTime, uint32_t &count)
5185{
5186    //get time and date from system
5187    time_t rawtime;
5188    struct tm * timeinfo = NULL;
5189    memset(&rawtime, 0, sizeof(rawtime));
5190    time(&rawtime);
5191    timeinfo = localtime (&rawtime);
5192    if (timeinfo != NULL && count >= 20) {
5193        //Write datetime according to EXIF Spec
5194        //"YYYY:MM:DD HH:MM:SS" (20 chars including \0)
5195        snprintf(dateTime, 20, "%04d:%02d:%02d %02d:%02d:%02d",
5196                 timeinfo->tm_year + 1900, timeinfo->tm_mon + 1,
5197                 timeinfo->tm_mday, timeinfo->tm_hour,
5198                 timeinfo->tm_min, timeinfo->tm_sec);
5199        count = 20;
5200        return NO_ERROR;
5201    }
5202    return UNKNOWN_ERROR;
5203}
5204
5205/*===========================================================================
5206 * FUNCTION   : getRational
5207 *
5208 * DESCRIPTION: compose rational struct
5209 *
5210 * PARAMETERS :
5211 *   @rat     : ptr to struct to store rational info
5212 *   @num     :num of the rational
5213 *   @denom   : denom of the rational
5214 *
5215 * RETURN     : int32_t type of status
5216 *              NO_ERROR  -- success
5217 *              none-zero failure code
5218 *==========================================================================*/
5219int32_t QCameraParameters::getRational(rat_t *rat, int num, int denom)
5220{
5221    if (NULL == rat) {
5222        ALOGE("%s: NULL rat input", __func__);
5223        return BAD_VALUE;
5224    }
5225    rat->num = num;
5226    rat->denom = denom;
5227    return NO_ERROR;
5228}
5229
5230/*===========================================================================
5231 * FUNCTION   : getExifFocalLength
5232 *
5233 * DESCRIPTION: get exif focal lenght
5234 *
5235 * PARAMETERS :
5236 *   @focalLength : ptr to rational strcut to store focal lenght
5237 *
5238 * RETURN     : int32_t type of status
5239 *              NO_ERROR  -- success
5240 *              none-zero failure code
5241 *==========================================================================*/
5242int32_t QCameraParameters::getExifFocalLength(rat_t *focalLength)
5243{
5244    int focalLengthValue =
5245        (int)(getFloat(QCameraParameters::KEY_FOCAL_LENGTH) * FOCAL_LENGTH_DECIMAL_PRECISION);
5246    return getRational(focalLength, focalLengthValue, FOCAL_LENGTH_DECIMAL_PRECISION);
5247}
5248
5249/*===========================================================================
5250 * FUNCTION   : getExifIsoSpeed
5251 *
5252 * DESCRIPTION: get exif ISO speed
5253 *
5254 * PARAMETERS : none
5255 *
5256 * RETURN     : ISO speed value
5257 *==========================================================================*/
5258uint16_t QCameraParameters::getExifIsoSpeed()
5259{
5260    uint16_t isoSpeed = 0;
5261    const char *iso_str = get(QCameraParameters::KEY_QC_ISO_MODE);
5262    int iso_index = lookupAttr(ISO_MODES_MAP,
5263        sizeof(ISO_MODES_MAP)/sizeof(ISO_MODES_MAP[0]), iso_str);
5264    switch (iso_index) {
5265    case CAM_ISO_MODE_AUTO:
5266        isoSpeed = 0;
5267        break;
5268    case CAM_ISO_MODE_DEBLUR:
5269        isoSpeed = 1;
5270        break;
5271    case CAM_ISO_MODE_100:
5272        isoSpeed = 100;
5273        break;
5274    case CAM_ISO_MODE_200:
5275        isoSpeed = 200;
5276        break;
5277    case CAM_ISO_MODE_400:
5278        isoSpeed = 400;
5279        break;
5280    case CAM_ISO_MODE_800:
5281        isoSpeed = 800;
5282        break;
5283    case CAM_ISO_MODE_1600:
5284        isoSpeed = 1600;
5285        break;
5286    }
5287    return isoSpeed;
5288}
5289
5290/*===========================================================================
5291 * FUNCTION   : getExifGpsProcessingMethod
5292 *
5293 * DESCRIPTION: get GPS processing method
5294 *
5295 * PARAMETERS :
5296 *   @gpsProcessingMethod : string to store GPS process method
5297 *   @count               : lenght of the string
5298 *
5299 * RETURN     : int32_t type of status
5300 *              NO_ERROR  -- success
5301 *              none-zero failure code
5302 *==========================================================================*/
5303int32_t QCameraParameters::getExifGpsProcessingMethod(char *gpsProcessingMethod,
5304                                                      uint32_t &count)
5305{
5306    const char *str = get(KEY_GPS_PROCESSING_METHOD);
5307    if(str != NULL) {
5308        memcpy(gpsProcessingMethod, ExifAsciiPrefix, EXIF_ASCII_PREFIX_SIZE);
5309        count = EXIF_ASCII_PREFIX_SIZE;
5310        strncpy(gpsProcessingMethod + EXIF_ASCII_PREFIX_SIZE, str, strlen(str));
5311        count += strlen(str);
5312        gpsProcessingMethod[count++] = '\0'; // increase 1 for the last NULL char
5313        return NO_ERROR;
5314    } else {
5315        return BAD_VALUE;
5316    }
5317}
5318
5319/*===========================================================================
5320 * FUNCTION   : getExifLatitude
5321 *
5322 * DESCRIPTION: get exif latitude
5323 *
5324 * PARAMETERS :
5325 *   @latitude : ptr to rational struct to store latitude info
5326 *   @ladRef   : charater to indicate latitude reference
5327 *
5328 * RETURN     : int32_t type of status
5329 *              NO_ERROR  -- success
5330 *              none-zero failure code
5331 *==========================================================================*/
5332int32_t QCameraParameters::getExifLatitude(rat_t *latitude,
5333                                           char *latRef)
5334{
5335    const char *str = get(KEY_GPS_LATITUDE);
5336    if(str != NULL) {
5337        parseGPSCoordinate(str, latitude);
5338
5339        //set Latitude Ref
5340        float latitudeValue = getFloat(KEY_GPS_LATITUDE);
5341        if(latitudeValue < 0.0f) {
5342            latRef[0] = 'S';
5343        } else {
5344            latRef[0] = 'N';
5345        }
5346        latRef[1] = '\0';
5347        return NO_ERROR;
5348    }else{
5349        return BAD_VALUE;
5350    }
5351}
5352
5353/*===========================================================================
5354 * FUNCTION   : getExifLongitude
5355 *
5356 * DESCRIPTION: get exif longitude
5357 *
5358 * PARAMETERS :
5359 *   @longitude : ptr to rational struct to store longitude info
5360 *   @lonRef    : charater to indicate longitude reference
5361 *
5362 * RETURN     : int32_t type of status
5363 *              NO_ERROR  -- success
5364 *              none-zero failure code
5365 *==========================================================================*/
5366int32_t QCameraParameters::getExifLongitude(rat_t *longitude,
5367                                            char *lonRef)
5368{
5369    const char *str = get(KEY_GPS_LONGITUDE);
5370    if(str != NULL) {
5371        parseGPSCoordinate(str, longitude);
5372
5373        //set Longitude Ref
5374        float longitudeValue = getFloat(KEY_GPS_LONGITUDE);
5375        if(longitudeValue < 0.0f) {
5376            lonRef[0] = 'W';
5377        } else {
5378            lonRef[0] = 'E';
5379        }
5380        lonRef[1] = '\0';
5381        return NO_ERROR;
5382    }else{
5383        return BAD_VALUE;
5384    }
5385}
5386
5387/*===========================================================================
5388 * FUNCTION   : getExifAltitude
5389 *
5390 * DESCRIPTION: get exif altitude
5391 *
5392 * PARAMETERS :
5393 *   @altitude : ptr to rational struct to store altitude info
5394 *   @altRef   : charater to indicate altitude reference
5395 *
5396 * RETURN     : int32_t type of status
5397 *              NO_ERROR  -- success
5398 *              none-zero failure code
5399 *==========================================================================*/
5400int32_t QCameraParameters::getExifAltitude(rat_t *altitude,
5401                                           char *altRef)
5402{
5403    const char *str = get(KEY_GPS_ALTITUDE);
5404    if(str != NULL) {
5405        double value = atof(str);
5406        *altRef = 0;
5407        if(value < 0){
5408            *altRef = 1;
5409            value = -value;
5410        }
5411        return getRational(altitude, value*1000, 1000);
5412    }else{
5413        return BAD_VALUE;
5414    }
5415}
5416
5417/*===========================================================================
5418 * FUNCTION   : getExifGpsDateTimeStamp
5419 *
5420 * DESCRIPTION: get exif GPS date time stamp
5421 *
5422 * PARAMETERS :
5423 *   @gpsDateStamp : GPS date time stamp string
5424 *   @bufLen       : length of the string
5425 *   @gpsTimeStamp : ptr to rational struct to store time stamp info
5426 *
5427 * RETURN     : int32_t type of status
5428 *              NO_ERROR  -- success
5429 *              none-zero failure code
5430 *==========================================================================*/
5431int32_t QCameraParameters::getExifGpsDateTimeStamp(char *gpsDateStamp,
5432                                                   uint32_t bufLen,
5433                                                   rat_t *gpsTimeStamp)
5434{
5435    const char *str = get(KEY_GPS_TIMESTAMP);
5436    if(str != NULL) {
5437        time_t unixTime = (time_t)atol(str);
5438        struct tm *UTCTimestamp = gmtime(&unixTime);
5439
5440        strftime(gpsDateStamp, bufLen, "%Y:%m:%d", UTCTimestamp);
5441
5442        getRational(&gpsTimeStamp[0], UTCTimestamp->tm_hour, 1);
5443        getRational(&gpsTimeStamp[1], UTCTimestamp->tm_min, 1);
5444        getRational(&gpsTimeStamp[2], UTCTimestamp->tm_sec, 1);
5445
5446        return NO_ERROR;
5447    } else {
5448        return BAD_VALUE;
5449    }
5450}
5451
5452/*===========================================================================
5453 * FUNCTION   : updateFocusDistances
5454 *
5455 * DESCRIPTION: update focus distances
5456 *
5457 * PARAMETERS :
5458 *   @focusDistances : ptr to focus distance info
5459 *
5460 * RETURN     : int32_t type of status
5461 *              NO_ERROR  -- success
5462 *              none-zero failure code
5463 *==========================================================================*/
5464int32_t QCameraParameters::updateFocusDistances(cam_focus_distances_info_t *focusDistances)
5465{
5466    String8 str;
5467    char buffer[32] = {0};
5468    //set all distances to infinity if focus mode is infinity
5469    if(mFocusMode == CAM_FOCUS_MODE_INFINITY) {
5470        str.append("Infinity,Infinity,Infinity");
5471    } else {
5472        snprintf(buffer, sizeof(buffer), "%f", focusDistances->focus_distance[0]);
5473        str.append(buffer);
5474        snprintf(buffer, sizeof(buffer), ",%f", focusDistances->focus_distance[1]);
5475        str.append(buffer);
5476        snprintf(buffer, sizeof(buffer), ",%f", focusDistances->focus_distance[2]);
5477        str.append(buffer);
5478    }
5479    ALOGD("%s: setting KEY_FOCUS_DISTANCES as %s", __FUNCTION__, str.string());
5480    set(QCameraParameters::KEY_FOCUS_DISTANCES, str.string());
5481    return NO_ERROR;
5482}
5483
5484/*===========================================================================
5485 * FUNCTION   : setHistogram
5486 *
5487 * DESCRIPTION: set histogram
5488 *
5489 * PARAMETERS :
5490 *   @enabled : if histogram is enabled
5491 *
5492 * RETURN     : int32_t type of status
5493 *              NO_ERROR  -- success
5494 *              none-zero failure code
5495 *==========================================================================*/
5496int32_t QCameraParameters::setHistogram(bool enabled)
5497{
5498    if(m_bHistogramEnabled == enabled) {
5499        ALOGD("%s: histogram flag not changed, no ops here", __func__);
5500        return NO_ERROR;
5501    }
5502
5503    // set parm for histogram
5504    if(initBatchUpdate(m_pParamBuf) < 0 ) {
5505        ALOGE("%s:Failed to initialize group update table", __func__);
5506        return BAD_TYPE;
5507    }
5508
5509    int32_t value = enabled;
5510    int32_t rc = NO_ERROR;
5511    rc = AddSetParmEntryToBatch(m_pParamBuf,
5512                                CAM_INTF_PARM_HISTOGRAM,
5513                                sizeof(value),
5514                                &value);
5515    if (rc != NO_ERROR) {
5516        ALOGE("%s:Failed to update table", __func__);
5517        return rc;
5518    }
5519
5520    rc = commitSetBatch();
5521    if (rc != NO_ERROR) {
5522        ALOGE("%s:Failed to set histogram", __func__);
5523        return rc;
5524    }
5525
5526    m_bHistogramEnabled = enabled;
5527
5528    ALOGD(" Histogram -> %s", m_bHistogramEnabled ? "Enabled" : "Disabled");
5529
5530    return rc;
5531}
5532
5533/*===========================================================================
5534 * FUNCTION   : setFaceDetection
5535 *
5536 * DESCRIPTION: set face detection
5537 *
5538 * PARAMETERS :
5539 *   @enabled : if face detection is enabled
5540 *
5541 * RETURN     : int32_t type of status
5542 *              NO_ERROR  -- success
5543 *              none-zero failure code
5544 *==========================================================================*/
5545int32_t QCameraParameters::setFaceDetection(bool enabled)
5546{
5547    int faceProcMask = m_nFaceProcMask;
5548    // set face detection mask
5549    if (enabled) {
5550        faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
5551    } else {
5552        faceProcMask &= ~CAM_FACE_PROCESS_MASK_DETECTION;
5553    }
5554
5555    if(m_nFaceProcMask == faceProcMask) {
5556        ALOGD("%s: face process mask not changed, no ops here", __func__);
5557        return NO_ERROR;
5558    }
5559
5560    // set parm for face detection
5561    int requested_faces = getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
5562    cam_fd_set_parm_t fd_set_parm;
5563    memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
5564    fd_set_parm.fd_mode = faceProcMask;
5565    fd_set_parm.num_fd = requested_faces;
5566
5567    if(initBatchUpdate(m_pParamBuf) < 0 ) {
5568        ALOGE("%s:Failed to initialize group update table", __func__);
5569        return BAD_TYPE;
5570    }
5571    int32_t rc = NO_ERROR;
5572
5573    rc = AddSetParmEntryToBatch(m_pParamBuf,
5574                                CAM_INTF_PARM_FD,
5575                                sizeof(fd_set_parm),
5576                                &fd_set_parm);
5577    if (rc != NO_ERROR) {
5578        ALOGE("%s:Failed to update table", __func__);
5579        return rc;
5580    }
5581
5582    rc = commitSetBatch();
5583    if (rc != NO_ERROR) {
5584        ALOGE("%s:Failed to set face detection parm", __func__);
5585        return rc;
5586    }
5587
5588    m_nFaceProcMask = faceProcMask;
5589    ALOGD("%s: FaceProcMask -> %d", __func__, m_nFaceProcMask);
5590
5591    return rc;
5592}
5593
5594/*===========================================================================
5595 * FUNCTION   : setLockCAF
5596 *
5597 * DESCRIPTION: Lock CAF
5598 *
5599 * PARAMETERS :
5600 *   @bLock : if CAF needs to be locked
5601 *
5602 * RETURN     : int32_t type of status
5603 *              NO_ERROR  -- success
5604 *              none-zero failure code
5605 *==========================================================================*/
5606int32_t QCameraParameters::setLockCAF(bool bLock)
5607{
5608    if(initBatchUpdate(m_pParamBuf) < 0 ) {
5609        ALOGE("%s:Failed to initialize group update table", __func__);
5610        return BAD_TYPE;
5611    }
5612    int32_t rc = NO_ERROR;
5613    int32_t value = bLock;
5614
5615    rc = AddSetParmEntryToBatch(m_pParamBuf,
5616                                CAM_INTF_PARM_LOCK_CAF,
5617                                sizeof(value),
5618                                &value);
5619    if (rc != NO_ERROR) {
5620        ALOGE("%s:Failed to update table", __func__);
5621        return rc;
5622    }
5623
5624    rc = commitSetBatch();
5625    if (rc != NO_ERROR) {
5626        ALOGE("%s:Failed to set lock CAF parm", __func__);
5627        return rc;
5628    } else {
5629        m_bCAFLocked = bLock;
5630        return NO_ERROR;
5631    }
5632}
5633
5634/*===========================================================================
5635 * FUNCTION   : setBundleInfo
5636 *
5637 * DESCRIPTION: send bundle info of a channel to backend
5638 *
5639 * PARAMETERS :
5640 *   @bundle_info : reference to bundle info struct
5641 *
5642 * RETURN     : int32_t type of status
5643 *              NO_ERROR  -- success
5644 *              none-zero failure code
5645 *==========================================================================*/
5646int32_t QCameraParameters::setBundleInfo(cam_bundle_config_t &bundle_info)
5647{
5648    int32_t rc = NO_ERROR;
5649
5650    if(initBatchUpdate(m_pParamBuf) < 0 ) {
5651        ALOGE("%s:Failed to initialize group update table", __func__);
5652        return BAD_TYPE;
5653    }
5654
5655    rc = AddSetParmEntryToBatch(m_pParamBuf,
5656                                CAM_INTF_PARM_SET_BUNDLE,
5657                                sizeof(cam_bundle_config_t),
5658                                &bundle_info);
5659    if (rc != NO_ERROR) {
5660        ALOGE("%s:Failed to update table", __func__);
5661        return rc;
5662    }
5663
5664    rc = commitSetBatch();
5665    if (rc != NO_ERROR) {
5666        ALOGE("%s:Failed to set bundle info parm", __func__);
5667        return rc;
5668    }
5669
5670    return rc;
5671}
5672
5673/*===========================================================================
5674 * FUNCTION   : setFrameSkip
5675 *
5676 * DESCRIPTION: send ISP frame skip pattern to camera daemon
5677 *
5678 * PARAMETERS :
5679 *   @pattern : skip pattern for ISP
5680 *
5681 * RETURN     : int32_t type of status
5682 *              NO_ERROR  -- success
5683 *              none-zero failure code
5684 *==========================================================================*/
5685int32_t QCameraParameters::setFrameSkip(enum msm_vfe_frame_skip_pattern pattern)
5686{
5687    int32_t rc = NO_ERROR;
5688    int32_t value = (int32_t)pattern;
5689
5690    if(initBatchUpdate(m_pParamBuf) < 0 ) {
5691        ALOGE("%s:Failed to initialize group update table", __func__);
5692        return BAD_TYPE;
5693    }
5694
5695    rc = AddSetParmEntryToBatch(m_pParamBuf,
5696                                CAM_INTF_PARM_FRAMESKIP,
5697                                sizeof(value),
5698                                &value);
5699    if (rc != NO_ERROR) {
5700        ALOGE("%s:Failed to update table", __func__);
5701        return rc;
5702    }
5703
5704    rc = commitSetBatch();
5705    if (rc != NO_ERROR) {
5706        ALOGE("%s:Failed to set frameskip info parm", __func__);
5707        return rc;
5708    }
5709
5710    return rc;
5711}
5712
5713/*===========================================================================
5714 * FUNCTION   : parseNDimVector
5715 *
5716 * DESCRIPTION: helper function to parse a string like "(1, 2, 3, 4, ..., N)"
5717 *              into N-dimension vector
5718 *
5719 * PARAMETERS :
5720 *   @str     : string to be parsed
5721 *   @num     : output array of size N to store vector element values
5722 *   @N       : number of dimension
5723 *   @delim   : delimeter to seperete string
5724 *
5725 * RETURN     : int32_t type of status
5726 *              NO_ERROR  -- success
5727 *              none-zero failure code
5728 *==========================================================================*/
5729int32_t QCameraParameters::parseNDimVector(const char *str, int *num, int N, char delim = ',')
5730{
5731    char *start, *end;
5732    if (num == NULL) {
5733        ALOGE("%s: Invalid output array (num == NULL)", __func__);
5734        return BAD_VALUE;
5735    }
5736
5737    //check if string starts and ends with parantheses
5738    if(str[0] != '(' || str[strlen(str)-1] != ')') {
5739        ALOGE("%s: Invalid format of string %s, valid format is (n1, n2, n3, n4 ...)",
5740              __func__, str);
5741        return BAD_VALUE;
5742    }
5743    start = (char*) str;
5744    start++;
5745    for(int i=0; i<N; i++) {
5746        *(num+i) = (int) strtol(start, &end, 10);
5747        if(*end != delim && i < N-1) {
5748            ALOGE("%s: Cannot find delimeter '%c' in string \"%s\". end = %c",
5749                  __func__, delim, str, *end);
5750            return -1;
5751        }
5752        start = end+1;
5753    }
5754    return NO_ERROR;
5755}
5756
5757/*===========================================================================
5758 * FUNCTION   : parseCameraAreaString
5759 *
5760 * DESCRIPTION: helper function to parse a string of camera areas like
5761 *              "(1, 2, 3, 4, 5),(1, 2, 3, 4, 5),..."
5762 *
5763 * PARAMETERS :
5764 *   @str             : string to be parsed
5765 *   @max_num_areas   : max number of areas
5766 *   @pAreas          : ptr to struct to store areas
5767 *   @num_areas_found : number of areas found
5768 *
5769 * RETURN     : int32_t type of status
5770 *              NO_ERROR  -- success
5771 *              none-zero failure code
5772 *==========================================================================*/
5773int32_t QCameraParameters::parseCameraAreaString(const char *str,
5774                                                 int max_num_areas,
5775                                                 cam_area_t *pAreas,
5776                                                 int& num_areas_found)
5777{
5778    char area_str[32];
5779    const char *start, *end, *p;
5780    start = str; end = NULL;
5781    int values[5], index=0;
5782    num_areas_found = 0;
5783
5784    memset(values, 0, sizeof(values));
5785    while(start != NULL) {
5786       if(*start != '(') {
5787            ALOGE("%s: error: Ill formatted area string: %s", __func__, str);
5788            return BAD_VALUE;
5789       }
5790       end = strchr(start, ')');
5791       if(end == NULL) {
5792            ALOGE("%s: error: Ill formatted area string: %s", __func__, str);
5793            return BAD_VALUE;
5794       }
5795       int i;
5796       for (i=0,p=start; p<=end; p++, i++) {
5797           area_str[i] = *p;
5798       }
5799       area_str[i] = '\0';
5800       if(parseNDimVector(area_str, values, 5) < 0){
5801            ALOGE("%s: error: Failed to parse the area string: %s", __func__, area_str);
5802            return BAD_VALUE;
5803       }
5804       // no more areas than max_num_areas are accepted.
5805       if(index >= max_num_areas) {
5806            ALOGE("%s: error: too many areas specified %s", __func__, str);
5807            return BAD_VALUE;
5808       }
5809       pAreas[index].rect.left = values[0];
5810       pAreas[index].rect.top = values[1];
5811       pAreas[index].rect.width = values[2] - values[0];
5812       pAreas[index].rect.height = values[3] - values[1];
5813       pAreas[index].weight = values[4];
5814
5815       index++;
5816       start = strchr(end, '('); // serach for next '('
5817    }
5818    num_areas_found = index;
5819    return 0;
5820}
5821
5822/*===========================================================================
5823 * FUNCTION   : validateCameraAreas
5824 *
5825 * DESCRIPTION: helper function to validate camera areas within (-1000, 1000)
5826 *
5827 * PARAMETERS :
5828 *   @areas     : ptr to array of areas
5829 *   @num_areas : number of areas
5830 *
5831 * RETURN     : true --  area is in valid range
5832 *              false -- not valid
5833 *==========================================================================*/
5834bool QCameraParameters::validateCameraAreas(cam_area_t *areas, int num_areas)
5835{
5836    // special case: default area
5837    if (num_areas == 1 &&
5838        areas[0].rect.left == 0 &&
5839        areas[0].rect.top == 0 &&
5840        areas[0].rect.width == 0 &&
5841        areas[0].rect.height == 0 &&
5842        areas[0].weight == 0) {
5843        return true;
5844    }
5845
5846    for(int i = 0; i < num_areas; i++) {
5847        // left should be >= -1000
5848        if(areas[i].rect.left < -1000) {
5849            return false;
5850        }
5851
5852        // top  should be >= -1000
5853        if(areas[i].rect.top < -1000) {
5854            return false;
5855        }
5856
5857        // width or height should be > 0
5858        if (areas[i].rect.width <= 0 || areas[i].rect.height <= 0) {
5859            return false;
5860        }
5861
5862        // right  should be <= 1000
5863        if(areas[i].rect.left + areas[i].rect.width > 1000) {
5864            return false;
5865        }
5866
5867        // bottom should be <= 1000
5868        if(areas[i].rect.top + areas[i].rect.height > 1000) {
5869            return false;
5870        }
5871
5872        // weight should be within (1, 1000)
5873        if (areas[i].weight < 1 || areas[i].weight > 1000) {
5874            return false;
5875        }
5876    }
5877    return true;
5878}
5879
5880/*===========================================================================
5881 * FUNCTION   : initBatchUpdate
5882 *
5883 * DESCRIPTION: init camera parameters buf entries
5884 *
5885 * PARAMETERS :
5886 *   @p_table : ptr to parameter buffer
5887 *
5888 * RETURN     : int32_t type of status
5889 *              NO_ERROR  -- success
5890 *              none-zero failure code
5891 *==========================================================================*/
5892int32_t QCameraParameters::initBatchUpdate(parm_buffer_t *p_table)
5893{
5894    m_tempMap.clear();
5895
5896    memset(p_table, 0, sizeof(parm_buffer_t));
5897    p_table->first_flagged_entry = CAM_INTF_PARM_MAX;
5898    return NO_ERROR;
5899}
5900
5901/*===========================================================================
5902 * FUNCTION   : AddSetParmEntryToBatch
5903 *
5904 * DESCRIPTION: add set parameter entry into batch
5905 *
5906 * PARAMETERS :
5907 *   @p_table     : ptr to parameter buffer
5908 *   @paramType   : parameter type
5909 *   @paramLength : length of parameter value
5910 *   @paramValue  : ptr to parameter value
5911 *
5912 * RETURN     : int32_t type of status
5913 *              NO_ERROR  -- success
5914 *              none-zero failure code
5915 *==========================================================================*/
5916int32_t QCameraParameters::AddSetParmEntryToBatch(parm_buffer_t *p_table,
5917                                                  cam_intf_parm_type_t paramType,
5918                                                  uint32_t paramLength,
5919                                                  void *paramValue)
5920{
5921    int position = paramType;
5922    int current, next;
5923
5924    /*************************************************************************
5925    *                 Code to take care of linking next flags                *
5926    *************************************************************************/
5927    current = GET_FIRST_PARAM_ID(p_table);
5928    if (position == current){
5929        //DO NOTHING
5930    } else if (position < current){
5931        SET_NEXT_PARAM_ID(position, p_table, current);
5932        SET_FIRST_PARAM_ID(p_table, position);
5933    } else {
5934        /* Search for the position in the linked list where we need to slot in*/
5935        while (position > GET_NEXT_PARAM_ID(current, p_table))
5936            current = GET_NEXT_PARAM_ID(current, p_table);
5937
5938        /*If node already exists no need to alter linking*/
5939        if (position != GET_NEXT_PARAM_ID(current, p_table)) {
5940            next = GET_NEXT_PARAM_ID(current, p_table);
5941            SET_NEXT_PARAM_ID(current, p_table, position);
5942            SET_NEXT_PARAM_ID(position, p_table, next);
5943        }
5944    }
5945
5946    /*************************************************************************
5947    *                   Copy contents into entry                             *
5948    *************************************************************************/
5949
5950    if (paramLength > sizeof(parm_type_t)) {
5951        ALOGE("%s:Size of input larger than max entry size",__func__);
5952        return BAD_VALUE;
5953    }
5954    memcpy(POINTER_OF(paramType,p_table), paramValue, paramLength);
5955    return NO_ERROR;
5956}
5957
5958/*===========================================================================
5959 * FUNCTION   : AddGetParmEntryToBatch
5960 *
5961 * DESCRIPTION: add get parameter entry into batch
5962 *
5963 * PARAMETERS :
5964 *   @p_table     : ptr to parameter buffer
5965 *   @paramType   : parameter type
5966 *
5967 * RETURN     : int32_t type of status
5968 *              NO_ERROR  -- success
5969 *              none-zero failure code
5970 *==========================================================================*/
5971int32_t QCameraParameters::AddGetParmEntryToBatch(parm_buffer_t *p_table,
5972                                                  cam_intf_parm_type_t paramType)
5973{
5974    int position = paramType;
5975    int current, next;
5976
5977    /*************************************************************************
5978    *                 Code to take care of linking next flags                *
5979    *************************************************************************/
5980    current = GET_FIRST_PARAM_ID(p_table);
5981    if (position == current){
5982        //DO NOTHING
5983    } else if (position < current){
5984        SET_NEXT_PARAM_ID(position, p_table, current);
5985        SET_FIRST_PARAM_ID(p_table, position);
5986    } else {
5987        /* Search for the position in the linked list where we need to slot in*/
5988        while (position > GET_NEXT_PARAM_ID(current, p_table))
5989            current = GET_NEXT_PARAM_ID(current, p_table);
5990
5991        /*If node already exists no need to alter linking*/
5992        if (position != GET_NEXT_PARAM_ID(current, p_table)) {
5993            next=GET_NEXT_PARAM_ID(current, p_table);
5994            SET_NEXT_PARAM_ID(current, p_table, position);
5995            SET_NEXT_PARAM_ID(position, p_table, next);
5996        }
5997    }
5998
5999    return NO_ERROR;
6000}
6001
6002/*===========================================================================
6003 * FUNCTION   : commitSetBatch
6004 *
6005 * DESCRIPTION: commit all set parameters in the batch work to backend
6006 *
6007 * PARAMETERS : none
6008 *
6009 * RETURN     : int32_t type of status
6010 *              NO_ERROR  -- success
6011 *              none-zero failure code
6012 *==========================================================================*/
6013int32_t QCameraParameters::commitSetBatch()
6014{
6015    int32_t rc = NO_ERROR;
6016    if (m_pParamBuf->first_flagged_entry < CAM_INTF_PARM_MAX) {
6017        rc = m_pCamOpsTbl->ops->set_parms(m_pCamOpsTbl->camera_handle, m_pParamBuf);
6018    }
6019    if (rc == NO_ERROR) {
6020        // commit change from temp storage into param map
6021        rc = commitParamChanges();
6022    }
6023    return rc;
6024}
6025
6026/*===========================================================================
6027 * FUNCTION   : commitGetBatch
6028 *
6029 * DESCRIPTION: commit all get parameters in the batch work to backend
6030 *
6031 * PARAMETERS : none
6032 *
6033 * RETURN     : int32_t type of status
6034 *              NO_ERROR  -- success
6035 *              none-zero failure code
6036 *==========================================================================*/
6037int32_t QCameraParameters::commitGetBatch()
6038{
6039    if (m_pParamBuf->first_flagged_entry < CAM_INTF_PARM_MAX) {
6040        return m_pCamOpsTbl->ops->get_parms(m_pCamOpsTbl->camera_handle, m_pParamBuf);
6041    } else {
6042        return NO_ERROR;
6043    }
6044}
6045
6046/*===========================================================================
6047 * FUNCTION   : updateParamEntry
6048 *
6049 * DESCRIPTION: update a parameter entry in the local temp map obj
6050 *
6051 * PARAMETERS :
6052 *   @key     : key of the entry
6053 *   @value   : value of the entry
6054 *
6055 * RETURN     : int32_t type of status
6056 *              NO_ERROR  -- success
6057 *              none-zero failure code
6058 *==========================================================================*/
6059int32_t QCameraParameters::updateParamEntry(const char *key, const char *value)
6060{
6061    m_tempMap.replaceValueFor(String8(key), String8(value));
6062    return NO_ERROR;
6063}
6064
6065/*===========================================================================
6066 * FUNCTION   : commitParamChanges
6067 *
6068 * DESCRIPTION: commit all changes in local temp map obj into parameter obj
6069 *
6070 * PARAMETERS : none
6071 *
6072 * RETURN     : int32_t type of status
6073 *              NO_ERROR  -- success
6074 *              none-zero failure code
6075 *==========================================================================*/
6076int32_t QCameraParameters::commitParamChanges()
6077{
6078    size_t size = m_tempMap.size();
6079    for (size_t i = 0; i < size; i++) {
6080        String8 k, v;
6081        k = m_tempMap.keyAt(i);
6082        v = m_tempMap.valueAt(i);
6083        set(k, v);
6084    }
6085    m_tempMap.clear();
6086    return NO_ERROR;
6087}
6088
6089}; // namespace qcamera
6090