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