Home | History | Annotate | Download | only in HAL
      1 /* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
      2  *
      3  * Redistribution and use in source and binary forms, with or without
      4  * modification, are permitted provided that the following conditions are
      5  * met:
      6  *     * Redistributions of source code must retain the above copyright
      7  *       notice, this list of conditions and the following disclaimer.
      8  *     * Redistributions in binary form must reproduce the above
      9  *       copyright notice, this list of conditions and the following
     10  *       disclaimer in the documentation and/or other materials provided
     11  *       with the distribution.
     12  *     * Neither the name of The Linux Foundation nor the names of its
     13  *       contributors may be used to endorse or promote products derived
     14  *       from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  *
     28  */
     29 
     30 #define LOG_TAG "QCameraParameters"
     31 
     32 // To remove
     33 #include <cutils/properties.h>
     34 
     35 // System dependencies
     36 #include <math.h>
     37 #include <string.h>
     38 #include <stdlib.h>
     39 #include <utils/Errors.h>
     40 #define SYSINFO_H <SYSTEM_HEADER_PREFIX/sysinfo.h>
     41 #include SYSINFO_H
     42 #include "gralloc_priv.h"
     43 #include "graphics.h"
     44 
     45 // Camera dependencies
     46 #include "QCameraBufferMaps.h"
     47 #include "QCamera2HWI.h"
     48 #include "QCameraParameters.h"
     49 #include "QCameraTrace.h"
     50 
     51 extern "C" {
     52 #include "mm_camera_dbg.h"
     53 }
     54 
     55 #define PI 3.14159265
     56 #define ASPECT_TOLERANCE 0.001
     57 #define CAMERA_DEFAULT_LONGSHOT_STAGES 4
     58 #define CAMERA_MIN_LONGSHOT_STAGES 2
     59 #define FOCUS_PERCISION 0.0000001
     60 
     61 
     62 namespace qcamera {
     63 // Parameter keys to communicate between camera application and driver.
     64 const char QCameraParameters::KEY_QC_SUPPORTED_HFR_SIZES[] = "hfr-size-values";
     65 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_MODE[] = "preview-frame-rate-mode";
     66 const char QCameraParameters::KEY_QC_SUPPORTED_PREVIEW_FRAME_RATE_MODES[] = "preview-frame-rate-modes";
     67 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_AUTO_MODE[] = "frame-rate-auto";
     68 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_FIXED_MODE[] = "frame-rate-fixed";
     69 const char QCameraParameters::KEY_QC_TOUCH_AF_AEC[] = "touch-af-aec";
     70 const char QCameraParameters::KEY_QC_SUPPORTED_TOUCH_AF_AEC[] = "touch-af-aec-values";
     71 const char QCameraParameters::KEY_QC_TOUCH_INDEX_AEC[] = "touch-index-aec";
     72 const char QCameraParameters::KEY_QC_TOUCH_INDEX_AF[] = "touch-index-af";
     73 const char QCameraParameters::KEY_QC_SCENE_DETECT[] = "scene-detect";
     74 const char QCameraParameters::KEY_QC_SUPPORTED_SCENE_DETECT[] = "scene-detect-values";
     75 const char QCameraParameters::KEY_QC_ISO_MODE[] = "iso";
     76 const char QCameraParameters::KEY_QC_CONTINUOUS_ISO[] = "continuous-iso";
     77 const char QCameraParameters::KEY_QC_MIN_ISO[] = "min-iso";
     78 const char QCameraParameters::KEY_QC_MAX_ISO[] = "max-iso";
     79 const char QCameraParameters::KEY_QC_SUPPORTED_ISO_MODES[] = "iso-values";
     80 const char QCameraParameters::KEY_QC_EXPOSURE_TIME[] = "exposure-time";
     81 const char QCameraParameters::KEY_QC_MIN_EXPOSURE_TIME[] = "min-exposure-time";
     82 const char QCameraParameters::KEY_QC_MAX_EXPOSURE_TIME[] = "max-exposure-time";
     83 const char QCameraParameters::KEY_QC_CURRENT_EXPOSURE_TIME[] = "cur-exposure-time";
     84 const char QCameraParameters::KEY_QC_CURRENT_ISO[] = "cur-iso";
     85 const char QCameraParameters::KEY_QC_LENSSHADE[] = "lensshade";
     86 const char QCameraParameters::KEY_QC_SUPPORTED_LENSSHADE_MODES[] = "lensshade-values";
     87 const char QCameraParameters::KEY_QC_AUTO_EXPOSURE[] = "auto-exposure";
     88 const char QCameraParameters::KEY_QC_SUPPORTED_AUTO_EXPOSURE[] = "auto-exposure-values";
     89 const char QCameraParameters::KEY_QC_DENOISE[] = "denoise";
     90 const char QCameraParameters::KEY_QC_SUPPORTED_DENOISE[] = "denoise-values";
     91 const char QCameraParameters::KEY_QC_FOCUS_ALGO[] = "selectable-zone-af";
     92 const char QCameraParameters::KEY_QC_SUPPORTED_FOCUS_ALGOS[] = "selectable-zone-af-values";
     93 const char QCameraParameters::KEY_QC_MANUAL_FOCUS_POSITION[] = "manual-focus-position";
     94 const char QCameraParameters::KEY_QC_MANUAL_FOCUS_POS_TYPE[] = "manual-focus-pos-type";
     95 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_INDEX[] = "min-focus-pos-index";
     96 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_INDEX[] = "max-focus-pos-index";
     97 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_DAC[] = "min-focus-pos-dac";
     98 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_DAC[] = "max-focus-pos-dac";
     99 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_RATIO[] = "min-focus-pos-ratio";
    100 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_RATIO[] = "max-focus-pos-ratio";
    101 const char QCameraParameters::KEY_QC_FOCUS_POSITION_SCALE[] = "cur-focus-scale";
    102 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_DIOPTER[] = "min-focus-pos-diopter";
    103 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_DIOPTER[] = "max-focus-pos-diopter";
    104 const char QCameraParameters::KEY_QC_FOCUS_POSITION_DIOPTER[] = "cur-focus-diopter";
    105 const char QCameraParameters::KEY_QC_FACE_DETECTION[] = "face-detection";
    106 const char QCameraParameters::KEY_QC_SUPPORTED_FACE_DETECTION[] = "face-detection-values";
    107 const char QCameraParameters::KEY_QC_FACE_RECOGNITION[] = "face-recognition";
    108 const char QCameraParameters::KEY_QC_SUPPORTED_FACE_RECOGNITION[] = "face-recognition-values";
    109 const char QCameraParameters::KEY_QC_MEMORY_COLOR_ENHANCEMENT[] = "mce";
    110 const char QCameraParameters::KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES[] = "mce-values";
    111 const char QCameraParameters::KEY_QC_DIS[] = "dis";
    112 const char QCameraParameters::KEY_QC_OIS[] = "ois";
    113 const char QCameraParameters::KEY_QC_SUPPORTED_DIS_MODES[] = "dis-values";
    114 const char QCameraParameters::KEY_QC_SUPPORTED_OIS_MODES[] = "ois-values";
    115 const char QCameraParameters::KEY_QC_VIDEO_HIGH_FRAME_RATE[] = "video-hfr";
    116 const char QCameraParameters::KEY_QC_VIDEO_HIGH_SPEED_RECORDING[] = "video-hsr";
    117 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES[] = "video-hfr-values";
    118 const char QCameraParameters::KEY_QC_REDEYE_REDUCTION[] = "redeye-reduction";
    119 const char QCameraParameters::KEY_QC_SUPPORTED_REDEYE_REDUCTION[] = "redeye-reduction-values";
    120 const char QCameraParameters::KEY_QC_HIGH_DYNAMIC_RANGE_IMAGING[] = "hdr";
    121 const char QCameraParameters::KEY_QC_SUPPORTED_HDR_IMAGING_MODES[] = "hdr-values";
    122 const char QCameraParameters::KEY_QC_ZSL[] = "zsl";
    123 const char QCameraParameters::KEY_QC_SUPPORTED_ZSL_MODES[] = "zsl-values";
    124 const char QCameraParameters::KEY_QC_ZSL_BURST_INTERVAL[] = "capture-burst-interval";
    125 const char QCameraParameters::KEY_QC_ZSL_BURST_LOOKBACK[] = "capture-burst-retroactive";
    126 const char QCameraParameters::KEY_QC_ZSL_QUEUE_DEPTH[] = "capture-burst-queue-depth";
    127 const char QCameraParameters::KEY_QC_CAMERA_MODE[] = "camera-mode";
    128 const char QCameraParameters::KEY_QC_AE_BRACKET_HDR[] = "ae-bracket-hdr";
    129 const char QCameraParameters::KEY_QC_SUPPORTED_AE_BRACKET_MODES[] = "ae-bracket-hdr-values";
    130 const char QCameraParameters::KEY_QC_SUPPORTED_RAW_FORMATS[] = "raw-format-values";
    131 const char QCameraParameters::KEY_QC_RAW_FORMAT[] = "raw-format";
    132 const char QCameraParameters::KEY_QC_ORIENTATION[] = "orientation";
    133 const char QCameraParameters::KEY_QC_SELECTABLE_ZONE_AF[] = "selectable-zone-af";
    134 const char QCameraParameters::KEY_QC_CAPTURE_BURST_EXPOSURE[] = "capture-burst-exposures";
    135 const char QCameraParameters::KEY_QC_NUM_SNAPSHOT_PER_SHUTTER[] = "num-snaps-per-shutter";
    136 const char QCameraParameters::KEY_QC_NUM_RETRO_BURST_PER_SHUTTER[] = "num-retro-burst-per-shutter";
    137 const char QCameraParameters::KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD[] = "zsl-burst-led-on-period";
    138 const char QCameraParameters::KEY_QC_NO_DISPLAY_MODE[] = "no-display-mode";
    139 const char QCameraParameters::KEY_QC_RAW_PICUTRE_SIZE[] = "raw-size";
    140 const char QCameraParameters::KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES[] = "skinToneEnhancement-values";
    141 const char QCameraParameters::KEY_QC_SUPPORTED_LIVESNAPSHOT_SIZES[] = "supported-live-snapshot-sizes";
    142 const char QCameraParameters::KEY_QC_SUPPORTED_HDR_NEED_1X[] = "hdr-need-1x-values";
    143 const char QCameraParameters::KEY_QC_HDR_NEED_1X[] = "hdr-need-1x";
    144 const char QCameraParameters::KEY_QC_PREVIEW_FLIP[] = "preview-flip";
    145 const char QCameraParameters::KEY_QC_VIDEO_FLIP[] = "video-flip";
    146 const char QCameraParameters::KEY_QC_SNAPSHOT_PICTURE_FLIP[] = "snapshot-picture-flip";
    147 const char QCameraParameters::KEY_QC_SUPPORTED_FLIP_MODES[] = "flip-mode-values";
    148 const char QCameraParameters::KEY_QC_VIDEO_HDR[] = "video-hdr";
    149 const char QCameraParameters::KEY_QC_SENSOR_HDR[] = "sensor-hdr";
    150 const char QCameraParameters::KEY_QC_VT_ENABLE[] = "avtimer";
    151 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_HDR_MODES[] = "video-hdr-values";
    152 const char QCameraParameters::KEY_QC_SUPPORTED_SENSOR_HDR_MODES[] = "sensor-hdr-values";
    153 const char QCameraParameters::KEY_QC_AUTO_HDR_ENABLE [] = "auto-hdr-enable";
    154 const char QCameraParameters::KEY_QC_SNAPSHOT_BURST_NUM[] = "snapshot-burst-num";
    155 const char QCameraParameters::KEY_QC_SNAPSHOT_FD_DATA[] = "snapshot-fd-data-enable";
    156 const char QCameraParameters::KEY_QC_TINTLESS_ENABLE[] = "tintless";
    157 const char QCameraParameters::KEY_QC_SCENE_SELECTION[] = "scene-selection";
    158 const char QCameraParameters::KEY_QC_CDS_MODE[] = "cds-mode";
    159 const char QCameraParameters::KEY_QC_VIDEO_CDS_MODE[] = "video-cds-mode";
    160 const char QCameraParameters::KEY_QC_SUPPORTED_CDS_MODES[] = "cds-mode-values";
    161 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_CDS_MODES[] = "video-cds-mode-values";
    162 const char QCameraParameters::KEY_QC_TNR_MODE[] = "tnr-mode";
    163 const char QCameraParameters::KEY_QC_VIDEO_TNR_MODE[] = "video-tnr-mode";
    164 const char QCameraParameters::KEY_QC_SUPPORTED_TNR_MODES[] = "tnr-mode-values";
    165 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_TNR_MODES[] = "video-tnr-mode-values";
    166 const char QCameraParameters::KEY_QC_VIDEO_ROTATION[] = "video-rotation";
    167 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_ROTATION_VALUES[] = "video-rotation-values";
    168 const char QCameraParameters::KEY_QC_AF_BRACKET[] = "af-bracket";
    169 const char QCameraParameters::KEY_QC_SUPPORTED_AF_BRACKET_MODES[] = "af-bracket-values";
    170 const char QCameraParameters::KEY_QC_RE_FOCUS[] = "re-focus";
    171 const char QCameraParameters::KEY_QC_SUPPORTED_RE_FOCUS_MODES[] = "re-focus-values";
    172 const char QCameraParameters::KEY_QC_CHROMA_FLASH[] = "chroma-flash";
    173 const char QCameraParameters::KEY_QC_SUPPORTED_CHROMA_FLASH_MODES[] = "chroma-flash-values";
    174 const char QCameraParameters::KEY_QC_OPTI_ZOOM[] = "opti-zoom";
    175 const char QCameraParameters::KEY_QC_SEE_MORE[] = "see-more";
    176 const char QCameraParameters::KEY_QC_STILL_MORE[] = "still-more";
    177 const char QCameraParameters::KEY_QC_SUPPORTED_OPTI_ZOOM_MODES[] = "opti-zoom-values";
    178 const char QCameraParameters::KEY_QC_HDR_MODE[] = "hdr-mode";
    179 const char QCameraParameters::KEY_QC_SUPPORTED_KEY_QC_HDR_MODES[] = "hdr-mode-values";
    180 const char QCameraParameters::KEY_QC_TRUE_PORTRAIT[] = "true-portrait";
    181 const char QCameraParameters::KEY_QC_SUPPORTED_TRUE_PORTRAIT_MODES[] = "true-portrait-values";
    182 const char QCameraParameters::KEY_QC_SUPPORTED_SEE_MORE_MODES[] = "see-more-values";
    183 const char QCameraParameters::KEY_QC_SUPPORTED_STILL_MORE_MODES[] = "still-more-values";
    184 const char QCameraParameters::KEY_INTERNAL_PERVIEW_RESTART[] = "internal-restart";
    185 const char QCameraParameters::KEY_QC_RDI_MODE[] = "rdi-mode";
    186 const char QCameraParameters::KEY_QC_SUPPORTED_RDI_MODES[] = "rdi-mode-values";
    187 const char QCameraParameters::KEY_QC_SECURE_MODE[] = "secure-mode";
    188 const char QCameraParameters::KEY_QC_SUPPORTED_SECURE_MODES[] = "secure-mode-values";
    189 const char QCameraParameters::ISO_HJR[] = "ISO_HJR";
    190 const char QCameraParameters::KEY_QC_AUTO_HDR_SUPPORTED[] = "auto-hdr-supported";
    191 const char QCameraParameters::KEY_QC_LONGSHOT_SUPPORTED[] = "longshot-supported";
    192 const char QCameraParameters::KEY_QC_ZSL_HDR_SUPPORTED[] = "zsl-hdr-supported";
    193 const char QCameraParameters::KEY_QC_WB_MANUAL_CCT[] = "wb-manual-cct";
    194 const char QCameraParameters::KEY_QC_MIN_WB_CCT[] = "min-wb-cct";
    195 const char QCameraParameters::KEY_QC_MAX_WB_CCT[] = "max-wb-cct";
    196 
    197 const char QCameraParameters::KEY_QC_MANUAL_WB_GAINS[] = "manual-wb-gains";
    198 const char QCameraParameters::KEY_QC_MIN_WB_GAIN[] = "min-wb-gain";
    199 const char QCameraParameters::KEY_QC_MAX_WB_GAIN[] = "max-wb-gain";
    200 
    201 const char QCameraParameters::KEY_QC_MANUAL_WB_TYPE[] = "manual-wb-type";
    202 const char QCameraParameters::KEY_QC_MANUAL_WB_VALUE[] = "manual-wb-value";
    203 
    204 const char QCameraParameters::WHITE_BALANCE_MANUAL[] = "manual";
    205 const char QCameraParameters::FOCUS_MODE_MANUAL_POSITION[] = "manual";
    206 const char QCameraParameters::KEY_QC_CACHE_VIDEO_BUFFERS[] = "cache-video-buffers";
    207 
    208 const char QCameraParameters::KEY_QC_LONG_SHOT[] = "long-shot";
    209 const char QCameraParameters::KEY_QC_INITIAL_EXPOSURE_INDEX[] = "initial-exp-index";
    210 const char QCameraParameters::KEY_QC_INSTANT_AEC[] = "instant-aec";
    211 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE[] = "instant-capture";
    212 const char QCameraParameters::KEY_QC_INSTANT_AEC_SUPPORTED_MODES[] = "instant-aec-values";
    213 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE_SUPPORTED_MODES[] = "instant-capture-values";
    214 
    215 // Values for effect settings.
    216 const char QCameraParameters::EFFECT_EMBOSS[] = "emboss";
    217 const char QCameraParameters::EFFECT_SKETCH[] = "sketch";
    218 const char QCameraParameters::EFFECT_NEON[] = "neon";
    219 const char QCameraParameters::EFFECT_BEAUTY[] = "beauty";
    220 
    221 
    222 // Values for auto exposure settings.
    223 const char QCameraParameters::TOUCH_AF_AEC_OFF[] = "touch-off";
    224 const char QCameraParameters::TOUCH_AF_AEC_ON[] = "touch-on";
    225 
    226 // Values for scene mode settings.
    227 const char QCameraParameters::SCENE_MODE_ASD[] = "asd";   // corresponds to CAMERA_BESTSHOT_AUTO in HAL
    228 const char QCameraParameters::SCENE_MODE_BACKLIGHT[] = "backlight";
    229 const char QCameraParameters::SCENE_MODE_FLOWERS[] = "flowers";
    230 const char QCameraParameters::SCENE_MODE_AR[] = "AR";
    231 const char QCameraParameters::SCENE_MODE_HDR[] = "hdr";
    232 
    233 // Formats for setPreviewFormat and setPictureFormat.
    234 const char QCameraParameters::PIXEL_FORMAT_YUV420SP_ADRENO[] = "yuv420sp-adreno";
    235 const char QCameraParameters::PIXEL_FORMAT_YV12[] = "yuv420p";
    236 const char QCameraParameters::PIXEL_FORMAT_NV12[] = "nv12";
    237 const char QCameraParameters::QC_PIXEL_FORMAT_NV12_VENUS[] = "nv12-venus";
    238 
    239 // Values for raw image formats
    240 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_YUYV[] = "yuv-raw8-yuyv";
    241 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_YVYU[] = "yuv-raw8-yvyu";
    242 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_UYVY[] = "yuv-raw8-uyvy";
    243 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_VYUY[] = "yuv-raw8-vyuy";
    244 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GBRG[] = "bayer-qcom-8gbrg";
    245 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GRBG[] = "bayer-qcom-8grbg";
    246 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8RGGB[] = "bayer-qcom-8rggb";
    247 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8BGGR[] = "bayer-qcom-8bggr";
    248 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GBRG[] = "bayer-qcom-10gbrg";
    249 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GRBG[] = "bayer-qcom-10grbg";
    250 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10RGGB[] = "bayer-qcom-10rggb";
    251 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10BGGR[] = "bayer-qcom-10bggr";
    252 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GBRG[] = "bayer-qcom-12gbrg";
    253 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GRBG[] = "bayer-qcom-12grbg";
    254 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12RGGB[] = "bayer-qcom-12rggb";
    255 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12BGGR[] = "bayer-qcom-12bggr";
    256 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GBRG[] = "bayer-qcom-14gbrg";
    257 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GRBG[] = "bayer-qcom-14grbg";
    258 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14RGGB[] = "bayer-qcom-14rggb";
    259 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14BGGR[] = "bayer-qcom-14bggr";
    260 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GBRG[] = "bayer-mipi-8gbrg";
    261 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GRBG[] = "bayer-mipi-8grbg";
    262 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8RGGB[] = "bayer-mipi-8rggb";
    263 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8BGGR[] = "bayer-mipi-8bggr";
    264 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GBRG[] = "bayer-mipi-10gbrg";
    265 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GRBG[] = "bayer-mipi-10grbg";
    266 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10RGGB[] = "bayer-mipi-10rggb";
    267 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10BGGR[] = "bayer-mipi-10bggr";
    268 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GBRG[] = "bayer-mipi-12gbrg";
    269 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GRBG[] = "bayer-mipi-12grbg";
    270 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12RGGB[] = "bayer-mipi-12rggb";
    271 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12BGGR[] = "bayer-mipi-12bggr";
    272 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GBRG[] = "bayer-mipi-14gbrg";
    273 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GRBG[] = "bayer-mipi-14grbg";
    274 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14RGGB[] = "bayer-mipi-14rggb";
    275 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14BGGR[] = "bayer-mipi-14bggr";
    276 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GBRG[] = "bayer-ideal-qcom-8gbrg";
    277 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GRBG[] = "bayer-ideal-qcom-8grbg";
    278 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8RGGB[] = "bayer-ideal-qcom-8rggb";
    279 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8BGGR[] = "bayer-ideal-qcom-8bggr";
    280 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GBRG[] = "bayer-ideal-qcom-10gbrg";
    281 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GRBG[] = "bayer-ideal-qcom-10grbg";
    282 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10RGGB[] = "bayer-ideal-qcom-10rggb";
    283 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10BGGR[] = "bayer-ideal-qcom-10bggr";
    284 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GBRG[] = "bayer-ideal-qcom-12gbrg";
    285 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GRBG[] = "bayer-ideal-qcom-12grbg";
    286 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12RGGB[] = "bayer-ideal-qcom-12rggb";
    287 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12BGGR[] = "bayer-ideal-qcom-12bggr";
    288 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GBRG[] = "bayer-ideal-qcom-14gbrg";
    289 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GRBG[] = "bayer-ideal-qcom-14grbg";
    290 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14RGGB[] = "bayer-ideal-qcom-14rggb";
    291 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14BGGR[] = "bayer-ideal-qcom-14bggr";
    292 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GBRG[] = "bayer-ideal-mipi-8gbrg";
    293 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GRBG[] = "bayer-ideal-mipi-8grbg";
    294 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8RGGB[] = "bayer-ideal-mipi-8rggb";
    295 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8BGGR[] = "bayer-ideal-mipi-8bggr";
    296 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GBRG[] = "bayer-ideal-mipi-10gbrg";
    297 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GRBG[] = "bayer-ideal-mipi-10grbg";
    298 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10RGGB[] = "bayer-ideal-mipi-10rggb";
    299 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10BGGR[] = "bayer-ideal-mipi-10bggr";
    300 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GBRG[] = "bayer-ideal-mipi-12gbrg";
    301 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GRBG[] = "bayer-ideal-mipi-12grbg";
    302 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12RGGB[] = "bayer-ideal-mipi-12rggb";
    303 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12BGGR[] = "bayer-ideal-mipi-12bggr";
    304 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GBRG[] = "bayer-ideal-mipi-14gbrg";
    305 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GRBG[] = "bayer-ideal-mipi-14grbg";
    306 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14RGGB[] = "bayer-ideal-mipi-14rggb";
    307 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14BGGR[] = "bayer-ideal-mipi-14bggr";
    308 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GBRG[] = "bayer-ideal-plain8-8gbrg";
    309 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GRBG[] = "bayer-ideal-plain8-8grbg";
    310 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8RGGB[] = "bayer-ideal-plain8-8rggb";
    311 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8BGGR[] = "bayer-ideal-plain8-8bggr";
    312 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GBRG[] = "bayer-ideal-plain16-8gbrg";
    313 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GRBG[] = "bayer-ideal-plain16-8grbg";
    314 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8RGGB[] = "bayer-ideal-plain16-8rggb";
    315 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8BGGR[] = "bayer-ideal-plain16-8bggr";
    316 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GBRG[] = "bayer-ideal-plain16-10gbrg";
    317 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GRBG[] = "bayer-ideal-plain16-10grbg";
    318 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10RGGB[] = "bayer-ideal-plain16-10rggb";
    319 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10BGGR[] = "bayer-ideal-plain16-10bggr";
    320 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GBRG[] = "bayer-ideal-plain16-12gbrg";
    321 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GRBG[] = "bayer-ideal-plain16-12grbg";
    322 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12RGGB[] = "bayer-ideal-plain16-12rggb";
    323 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12BGGR[] = "bayer-ideal-plain16-12bggr";
    324 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GBRG[] = "bayer-ideal-plain16-14gbrg";
    325 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GRBG[] = "bayer-ideal-plain16-14grbg";
    326 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14RGGB[] = "bayer-ideal-plain16-14rggb";
    327 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14BGGR[] = "bayer-ideal-plain16-14bggr";
    328 
    329 // Values for ISO Settings
    330 const char QCameraParameters::ISO_AUTO[] = "auto";
    331 const char QCameraParameters::ISO_100[] = "ISO100";
    332 const char QCameraParameters::ISO_200[] = "ISO200";
    333 const char QCameraParameters::ISO_400[] = "ISO400";
    334 const char QCameraParameters::ISO_800[] = "ISO800";
    335 const char QCameraParameters::ISO_1600[] = "ISO1600";
    336 const char QCameraParameters::ISO_3200[] = "ISO3200";
    337 const char QCameraParameters::ISO_MANUAL[] = "manual";
    338 
    339 
    340 // Values for auto exposure settings.
    341 const char QCameraParameters::AUTO_EXPOSURE_FRAME_AVG[] = "frame-average";
    342 const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED[] = "center-weighted";
    343 const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING[] = "spot-metering";
    344 const char QCameraParameters::AUTO_EXPOSURE_SMART_METERING[] = "smart-metering";
    345 const char QCameraParameters::AUTO_EXPOSURE_USER_METERING[] = "user-metering";
    346 const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING_ADV[] = "spot-metering-adv";
    347 const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED_ADV[] = "center-weighted-adv";
    348 
    349 // Values for instant AEC modes
    350 const char QCameraParameters::KEY_QC_INSTANT_AEC_DISABLE[] = "0";
    351 const char QCameraParameters::KEY_QC_INSTANT_AEC_AGGRESSIVE_AEC[] = "1";
    352 const char QCameraParameters::KEY_QC_INSTANT_AEC_FAST_AEC[] = "2";
    353 
    354 // Values for instant capture modes
    355 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE_DISABLE[] = "0";
    356 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE_AGGRESSIVE_AEC[] = "1";
    357 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE_FAST_AEC[] = "2";
    358 
    359 const char QCameraParameters::KEY_QC_GPS_LATITUDE_REF[] = "gps-latitude-ref";
    360 const char QCameraParameters::KEY_QC_GPS_LONGITUDE_REF[] = "gps-longitude-ref";
    361 const char QCameraParameters::KEY_QC_GPS_ALTITUDE_REF[] = "gps-altitude-ref";
    362 const char QCameraParameters::KEY_QC_GPS_STATUS[] = "gps-status";
    363 
    364 const char QCameraParameters::KEY_QC_HISTOGRAM[] = "histogram";
    365 const char QCameraParameters::KEY_QC_SUPPORTED_HISTOGRAM_MODES[] = "histogram-values";
    366 
    367 const char QCameraParameters::VALUE_ENABLE[] = "enable";
    368 const char QCameraParameters::VALUE_DISABLE[] = "disable";
    369 const char QCameraParameters::VALUE_OFF[] = "off";
    370 const char QCameraParameters::VALUE_ON[] = "on";
    371 const char QCameraParameters::VALUE_TRUE[] = "true";
    372 const char QCameraParameters::VALUE_FALSE[] = "false";
    373 
    374 const char QCameraParameters::VALUE_FAST[] = "fast";
    375 const char QCameraParameters::VALUE_HIGH_QUALITY[] = "high-quality";
    376 
    377 const char QCameraParameters::KEY_QC_SHARPNESS[] = "sharpness";
    378 const char QCameraParameters::KEY_QC_MIN_SHARPNESS[] = "min-sharpness";
    379 const char QCameraParameters::KEY_QC_MAX_SHARPNESS[] = "max-sharpness";
    380 const char QCameraParameters::KEY_QC_SHARPNESS_STEP[] = "sharpness-step";
    381 const char QCameraParameters::KEY_QC_CONTRAST[] = "contrast";
    382 const char QCameraParameters::KEY_QC_MIN_CONTRAST[] = "min-contrast";
    383 const char QCameraParameters::KEY_QC_MAX_CONTRAST[] = "max-contrast";
    384 const char QCameraParameters::KEY_QC_CONTRAST_STEP[] = "contrast-step";
    385 const char QCameraParameters::KEY_QC_SATURATION[] = "saturation";
    386 const char QCameraParameters::KEY_QC_MIN_SATURATION[] = "min-saturation";
    387 const char QCameraParameters::KEY_QC_MAX_SATURATION[] = "max-saturation";
    388 const char QCameraParameters::KEY_QC_SATURATION_STEP[] = "saturation-step";
    389 const char QCameraParameters::KEY_QC_BRIGHTNESS[] = "luma-adaptation";
    390 const char QCameraParameters::KEY_QC_MIN_BRIGHTNESS[] = "min-brightness";
    391 const char QCameraParameters::KEY_QC_MAX_BRIGHTNESS[] = "max-brightness";
    392 const char QCameraParameters::KEY_QC_BRIGHTNESS_STEP[] = "brightness-step";
    393 const char QCameraParameters::KEY_QC_SCE_FACTOR[] = "skinToneEnhancement";
    394 const char QCameraParameters::KEY_QC_MIN_SCE_FACTOR[] = "min-sce-factor";
    395 const char QCameraParameters::KEY_QC_MAX_SCE_FACTOR[] = "max-sce-factor";
    396 const char QCameraParameters::KEY_QC_SCE_FACTOR_STEP[] = "sce-factor-step";
    397 
    398 const char QCameraParameters::KEY_QC_MAX_NUM_REQUESTED_FACES[] = "qc-max-num-requested-faces";
    399 
    400 //Values for DENOISE
    401 const char QCameraParameters::DENOISE_OFF[] = "denoise-off";
    402 const char QCameraParameters::DENOISE_ON[] = "denoise-on";
    403 
    404 // Values for selectable zone af Settings
    405 const char QCameraParameters::FOCUS_ALGO_AUTO[] = "auto";
    406 const char QCameraParameters::FOCUS_ALGO_SPOT_METERING[] = "spot-metering";
    407 const char QCameraParameters::FOCUS_ALGO_CENTER_WEIGHTED[] = "center-weighted";
    408 const char QCameraParameters::FOCUS_ALGO_FRAME_AVERAGE[] = "frame-average";
    409 
    410 // Values for HFR settings.
    411 const char QCameraParameters::VIDEO_HFR_OFF[] = "off";
    412 const char QCameraParameters::VIDEO_HFR_2X[] = "60";
    413 const char QCameraParameters::VIDEO_HFR_3X[] = "90";
    414 const char QCameraParameters::VIDEO_HFR_4X[] = "120";
    415 const char QCameraParameters::VIDEO_HFR_5X[] = "150";
    416 const char QCameraParameters::VIDEO_HFR_6X[] = "180";
    417 const char QCameraParameters::VIDEO_HFR_7X[] = "210";
    418 const char QCameraParameters::VIDEO_HFR_8X[] = "240";
    419 const char QCameraParameters::VIDEO_HFR_9X[] = "480";
    420 
    421 // Values for HDR Bracketing settings.
    422 const char QCameraParameters::AE_BRACKET_OFF[] = "Off";
    423 const char QCameraParameters::AE_BRACKET[] = "AE-Bracket";
    424 
    425 // Values for AF Bracketing setting.
    426 const char QCameraParameters::AF_BRACKET_OFF[] = "af-bracket-off";
    427 const char QCameraParameters::AF_BRACKET_ON[] = "af-bracket-on";
    428 
    429 // Values for Refocus setting.
    430 const char QCameraParameters::RE_FOCUS_OFF[] = "re-focus-off";
    431 const char QCameraParameters::RE_FOCUS_ON[] = "re-focus-on";
    432 
    433 // Values for Chroma Flash setting.
    434 const char QCameraParameters::CHROMA_FLASH_OFF[] = "chroma-flash-off";
    435 const char QCameraParameters::CHROMA_FLASH_ON[] = "chroma-flash-on";
    436 
    437 // Values for Opti Zoom setting.
    438 const char QCameraParameters::OPTI_ZOOM_OFF[] = "opti-zoom-off";
    439 const char QCameraParameters::OPTI_ZOOM_ON[] = "opti-zoom-on";
    440 
    441 // Values for Still More setting.
    442 const char QCameraParameters::STILL_MORE_OFF[] = "still-more-off";
    443 const char QCameraParameters::STILL_MORE_ON[] = "still-more-on";
    444 
    445 // Values for HDR mode setting.
    446 const char QCameraParameters::HDR_MODE_SENSOR[] = "hdr-mode-sensor";
    447 const char QCameraParameters::HDR_MODE_MULTI_FRAME[] = "hdr-mode-multiframe";
    448 
    449 // Values for True Portrait setting.
    450 const char QCameraParameters::TRUE_PORTRAIT_OFF[] = "true-portrait-off";
    451 const char QCameraParameters::TRUE_PORTRAIT_ON[] = "true-portrait-on";
    452 
    453 // Values for FLIP settings.
    454 const char QCameraParameters::FLIP_MODE_OFF[] = "off";
    455 const char QCameraParameters::FLIP_MODE_V[] = "flip-v";
    456 const char QCameraParameters::FLIP_MODE_H[] = "flip-h";
    457 const char QCameraParameters::FLIP_MODE_VH[] = "flip-vh";
    458 
    459 const char QCameraParameters::CDS_MODE_OFF[] = "off";
    460 const char QCameraParameters::CDS_MODE_ON[] = "on";
    461 const char QCameraParameters::CDS_MODE_AUTO[] = "auto";
    462 
    463 // Values for video rotation settings.
    464 const char QCameraParameters::VIDEO_ROTATION_0[] = "0";
    465 const char QCameraParameters::VIDEO_ROTATION_90[] = "90";
    466 const char QCameraParameters::VIDEO_ROTATION_180[] = "180";
    467 const char QCameraParameters::VIDEO_ROTATION_270[] = "270";
    468 
    469 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_FOCUS_MODES[] = "manual-focus-modes";
    470 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_EXPOSURE_MODES[] = "manual-exposure-modes";
    471 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_WB_MODES[] = "manual-wb-modes";
    472 const char QCameraParameters::KEY_QC_FOCUS_SCALE_MODE[] = "scale-mode";
    473 const char QCameraParameters::KEY_QC_FOCUS_DIOPTER_MODE[] = "diopter-mode";
    474 const char QCameraParameters::KEY_QC_ISO_PRIORITY[] = "iso-priority";
    475 const char QCameraParameters::KEY_QC_EXP_TIME_PRIORITY[] = "exp-time-priority";
    476 const char QCameraParameters::KEY_QC_USER_SETTING[] = "user-setting";
    477 const char QCameraParameters::KEY_QC_WB_CCT_MODE[] = "color-temperature";
    478 const char QCameraParameters::KEY_QC_WB_GAIN_MODE[] = "rbgb-gains";
    479 const char QCameraParameters::KEY_QC_NOISE_REDUCTION_MODE[] = "noise-reduction-mode";
    480 const char QCameraParameters::KEY_QC_NOISE_REDUCTION_MODE_VALUES[] = "noise-reduction-mode-values";
    481 
    482 #ifdef TARGET_TS_MAKEUP
    483 const char QCameraParameters::KEY_TS_MAKEUP[] = "tsmakeup";
    484 const char QCameraParameters::KEY_TS_MAKEUP_WHITEN[] = "tsmakeup_whiten";
    485 const char QCameraParameters::KEY_TS_MAKEUP_CLEAN[] = "tsmakeup_clean";
    486 #endif
    487 
    488 //KEY to share HFR batch size with video encoder.
    489 const char QCameraParameters::KEY_QC_VIDEO_BATCH_SIZE[] = "video-batch-size";
    490 
    491 static const char* portrait = "portrait";
    492 static const char* landscape = "landscape";
    493 
    494 const cam_dimension_t QCameraParameters::THUMBNAIL_SIZES_MAP[] = {
    495     { 256, 154 }, //1.66233
    496     { 240, 160 }, //1.5
    497     { 320, 320 }, //1.0
    498     { 320, 240 }, //1.33333
    499     { 256, 144 }, //1.777778
    500     { 240, 144 }, //1.666667
    501     { 176, 144 }, //1.222222
    502     /*Thumbnail sizes to match portrait picture size aspect ratio*/
    503     { 240, 320 }, //to match 480X640 & 240X320 picture size
    504     { 144, 176 }, //to match 144X176  picture size
    505     { 0, 0 }      // required by Android SDK
    506 };
    507 
    508 const QCameraParameters::QCameraMap<cam_auto_exposure_mode_type>
    509         QCameraParameters::AUTO_EXPOSURE_MAP[] = {
    510     { AUTO_EXPOSURE_FRAME_AVG,           CAM_AEC_MODE_FRAME_AVERAGE },
    511     { AUTO_EXPOSURE_CENTER_WEIGHTED,     CAM_AEC_MODE_CENTER_WEIGHTED },
    512     { AUTO_EXPOSURE_SPOT_METERING,       CAM_AEC_MODE_SPOT_METERING },
    513     { AUTO_EXPOSURE_SMART_METERING,      CAM_AEC_MODE_SMART_METERING },
    514     { AUTO_EXPOSURE_USER_METERING,       CAM_AEC_MODE_USER_METERING },
    515     { AUTO_EXPOSURE_SPOT_METERING_ADV,   CAM_AEC_MODE_SPOT_METERING_ADV },
    516     { AUTO_EXPOSURE_CENTER_WEIGHTED_ADV, CAM_AEC_MODE_CENTER_WEIGHTED_ADV },
    517 };
    518 
    519 const QCameraParameters::QCameraMap<cam_aec_convergence_type>
    520         QCameraParameters::INSTANT_AEC_MODES_MAP[] = {
    521     { KEY_QC_INSTANT_AEC_DISABLE,        CAM_AEC_NORMAL_CONVERGENCE },
    522     { KEY_QC_INSTANT_AEC_AGGRESSIVE_AEC, CAM_AEC_AGGRESSIVE_CONVERGENCE },
    523     { KEY_QC_INSTANT_AEC_FAST_AEC,       CAM_AEC_FAST_CONVERGENCE },
    524 };
    525 
    526 const QCameraParameters::QCameraMap<cam_aec_convergence_type>
    527         QCameraParameters::INSTANT_CAPTURE_MODES_MAP[] = {
    528     { KEY_QC_INSTANT_CAPTURE_DISABLE,        CAM_AEC_NORMAL_CONVERGENCE },
    529     { KEY_QC_INSTANT_CAPTURE_AGGRESSIVE_AEC, CAM_AEC_AGGRESSIVE_CONVERGENCE },
    530     { KEY_QC_INSTANT_CAPTURE_FAST_AEC,       CAM_AEC_FAST_CONVERGENCE },
    531 };
    532 
    533 const QCameraParameters::QCameraMap<cam_format_t>
    534         QCameraParameters::PREVIEW_FORMATS_MAP[] = {
    535     {PIXEL_FORMAT_YUV420SP,        CAM_FORMAT_YUV_420_NV21},
    536     {PIXEL_FORMAT_YUV420P,         CAM_FORMAT_YUV_420_YV12},
    537     {PIXEL_FORMAT_YUV420SP_ADRENO, CAM_FORMAT_YUV_420_NV21_ADRENO},
    538     {PIXEL_FORMAT_YV12,            CAM_FORMAT_YUV_420_YV12},
    539     {PIXEL_FORMAT_NV12,            CAM_FORMAT_YUV_420_NV12},
    540     {QC_PIXEL_FORMAT_NV12_VENUS,   CAM_FORMAT_YUV_420_NV12_VENUS}
    541 };
    542 
    543 const QCameraParameters::QCameraMap<cam_format_t>
    544         QCameraParameters::PICTURE_TYPES_MAP[] = {
    545     {PIXEL_FORMAT_JPEG,                          CAM_FORMAT_JPEG},
    546     {PIXEL_FORMAT_YUV420SP,                      CAM_FORMAT_YUV_420_NV21},
    547     {PIXEL_FORMAT_YUV422SP,                      CAM_FORMAT_YUV_422_NV16},
    548     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YUYV,          CAM_FORMAT_YUV_RAW_8BIT_YUYV},
    549     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YVYU,          CAM_FORMAT_YUV_RAW_8BIT_YVYU},
    550     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_UYVY,          CAM_FORMAT_YUV_RAW_8BIT_UYVY},
    551     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_VYUY,          CAM_FORMAT_YUV_RAW_8BIT_VYUY},
    552     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GBRG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GBRG},
    553     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GRBG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GRBG},
    554     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8RGGB,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_RGGB},
    555     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8BGGR,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_BGGR},
    556     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GBRG},
    557     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GRBG},
    558     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_RGGB},
    559     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_BGGR},
    560     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GBRG},
    561     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GRBG},
    562     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_RGGB},
    563     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_BGGR},
    564     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_GBRG},
    565     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_GRBG},
    566     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_RGGB},
    567     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_BGGR},
    568     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GBRG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GBRG},
    569     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GRBG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GRBG},
    570     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8RGGB,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_RGGB},
    571     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8BGGR,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_BGGR},
    572     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GBRG},
    573     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GRBG},
    574     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_RGGB},
    575     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_BGGR},
    576     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GBRG},
    577     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GRBG},
    578     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_RGGB},
    579     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_BGGR},
    580     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_GBRG},
    581     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_GRBG},
    582     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_RGGB},
    583     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_BGGR},
    584     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GBRG},
    585     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GRBG},
    586     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_RGGB},
    587     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_BGGR},
    588     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GBRG},
    589     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GRBG},
    590     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_RGGB},
    591     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_BGGR},
    592     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GBRG},
    593     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GRBG},
    594     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_RGGB},
    595     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_BGGR},
    596     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_GBRG},
    597     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_GRBG},
    598     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_RGGB},
    599     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_BGGR},
    600     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GBRG},
    601     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GRBG},
    602     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_RGGB},
    603     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_BGGR},
    604     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GBRG},
    605     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GRBG},
    606     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_RGGB},
    607     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_BGGR},
    608     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GBRG},
    609     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GRBG},
    610     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_RGGB},
    611     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_BGGR},
    612     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_GBRG},
    613     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_GRBG},
    614     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_RGGB},
    615     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_BGGR},
    616     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GBRG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GBRG},
    617     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GRBG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GRBG},
    618     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8RGGB,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_RGGB},
    619     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8BGGR,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_BGGR},
    620     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GBRG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GBRG},
    621     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GRBG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GRBG},
    622     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8RGGB,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_RGGB},
    623     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8BGGR,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_BGGR},
    624     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GBRG},
    625     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GRBG},
    626     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_RGGB},
    627     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_BGGR},
    628     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GBRG},
    629     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GRBG},
    630     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_RGGB},
    631     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_BGGR},
    632     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_GBRG},
    633     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_GRBG},
    634     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_RGGB},
    635     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_BGGR}
    636 };
    637 
    638 const QCameraParameters::QCameraMap<cam_focus_mode_type>
    639         QCameraParameters::FOCUS_MODES_MAP[] = {
    640     { FOCUS_MODE_AUTO,               CAM_FOCUS_MODE_AUTO },
    641     { FOCUS_MODE_INFINITY,           CAM_FOCUS_MODE_INFINITY },
    642     { FOCUS_MODE_MACRO,              CAM_FOCUS_MODE_MACRO },
    643     { FOCUS_MODE_FIXED,              CAM_FOCUS_MODE_FIXED },
    644     { FOCUS_MODE_EDOF,               CAM_FOCUS_MODE_EDOF },
    645     { FOCUS_MODE_CONTINUOUS_PICTURE, CAM_FOCUS_MODE_CONTINOUS_PICTURE },
    646     { FOCUS_MODE_CONTINUOUS_VIDEO,   CAM_FOCUS_MODE_CONTINOUS_VIDEO },
    647     { FOCUS_MODE_MANUAL_POSITION,    CAM_FOCUS_MODE_MANUAL},
    648 };
    649 
    650 const QCameraParameters::QCameraMap<cam_effect_mode_type>
    651         QCameraParameters::EFFECT_MODES_MAP[] = {
    652     { EFFECT_NONE,       CAM_EFFECT_MODE_OFF },
    653     { EFFECT_MONO,       CAM_EFFECT_MODE_MONO },
    654     { EFFECT_NEGATIVE,   CAM_EFFECT_MODE_NEGATIVE },
    655     { EFFECT_SOLARIZE,   CAM_EFFECT_MODE_SOLARIZE },
    656     { EFFECT_SEPIA,      CAM_EFFECT_MODE_SEPIA },
    657     { EFFECT_POSTERIZE,  CAM_EFFECT_MODE_POSTERIZE },
    658     { EFFECT_WHITEBOARD, CAM_EFFECT_MODE_WHITEBOARD },
    659     { EFFECT_BLACKBOARD, CAM_EFFECT_MODE_BLACKBOARD },
    660     { EFFECT_AQUA,       CAM_EFFECT_MODE_AQUA },
    661     { EFFECT_EMBOSS,     CAM_EFFECT_MODE_EMBOSS },
    662     { EFFECT_SKETCH,     CAM_EFFECT_MODE_SKETCH },
    663     { EFFECT_NEON,       CAM_EFFECT_MODE_NEON },
    664     { EFFECT_BEAUTY,     CAM_EFFECT_MODE_BEAUTY }
    665 };
    666 
    667 const QCameraParameters::QCameraMap<cam_scene_mode_type>
    668         QCameraParameters::SCENE_MODES_MAP[] = {
    669     { SCENE_MODE_AUTO,           CAM_SCENE_MODE_OFF },
    670     { SCENE_MODE_ACTION,         CAM_SCENE_MODE_ACTION },
    671     { SCENE_MODE_PORTRAIT,       CAM_SCENE_MODE_PORTRAIT },
    672     { SCENE_MODE_LANDSCAPE,      CAM_SCENE_MODE_LANDSCAPE },
    673     { SCENE_MODE_NIGHT,          CAM_SCENE_MODE_NIGHT },
    674     { SCENE_MODE_NIGHT_PORTRAIT, CAM_SCENE_MODE_NIGHT_PORTRAIT },
    675     { SCENE_MODE_THEATRE,        CAM_SCENE_MODE_THEATRE },
    676     { SCENE_MODE_BEACH,          CAM_SCENE_MODE_BEACH },
    677     { SCENE_MODE_SNOW,           CAM_SCENE_MODE_SNOW },
    678     { SCENE_MODE_SUNSET,         CAM_SCENE_MODE_SUNSET },
    679     { SCENE_MODE_STEADYPHOTO,    CAM_SCENE_MODE_ANTISHAKE },
    680     { SCENE_MODE_FIREWORKS ,     CAM_SCENE_MODE_FIREWORKS },
    681     { SCENE_MODE_SPORTS ,        CAM_SCENE_MODE_SPORTS },
    682     { SCENE_MODE_PARTY,          CAM_SCENE_MODE_PARTY },
    683     { SCENE_MODE_CANDLELIGHT,    CAM_SCENE_MODE_CANDLELIGHT },
    684     { SCENE_MODE_ASD,            CAM_SCENE_MODE_AUTO },
    685     { SCENE_MODE_BACKLIGHT,      CAM_SCENE_MODE_BACKLIGHT },
    686     { SCENE_MODE_FLOWERS,        CAM_SCENE_MODE_FLOWERS },
    687     { SCENE_MODE_AR,             CAM_SCENE_MODE_AR },
    688     { SCENE_MODE_HDR,            CAM_SCENE_MODE_HDR },
    689 };
    690 
    691 const QCameraParameters::QCameraMap<cam_flash_mode_t>
    692         QCameraParameters::FLASH_MODES_MAP[] = {
    693     { FLASH_MODE_OFF,   CAM_FLASH_MODE_OFF },
    694     { FLASH_MODE_AUTO,  CAM_FLASH_MODE_AUTO },
    695     { FLASH_MODE_ON,    CAM_FLASH_MODE_ON },
    696     { FLASH_MODE_TORCH, CAM_FLASH_MODE_TORCH }
    697 };
    698 
    699 const QCameraParameters::QCameraMap<cam_focus_algorithm_type>
    700          QCameraParameters::FOCUS_ALGO_MAP[] = {
    701     { FOCUS_ALGO_AUTO,            CAM_FOCUS_ALGO_AUTO },
    702     { FOCUS_ALGO_SPOT_METERING,   CAM_FOCUS_ALGO_SPOT },
    703     { FOCUS_ALGO_CENTER_WEIGHTED, CAM_FOCUS_ALGO_CENTER_WEIGHTED },
    704     { FOCUS_ALGO_FRAME_AVERAGE,   CAM_FOCUS_ALGO_AVERAGE }
    705 };
    706 
    707 const QCameraParameters::QCameraMap<cam_wb_mode_type>
    708         QCameraParameters::WHITE_BALANCE_MODES_MAP[] = {
    709     { WHITE_BALANCE_AUTO,            CAM_WB_MODE_AUTO },
    710     { WHITE_BALANCE_INCANDESCENT,    CAM_WB_MODE_INCANDESCENT },
    711     { WHITE_BALANCE_FLUORESCENT,     CAM_WB_MODE_FLUORESCENT },
    712     { WHITE_BALANCE_WARM_FLUORESCENT,CAM_WB_MODE_WARM_FLUORESCENT},
    713     { WHITE_BALANCE_DAYLIGHT,        CAM_WB_MODE_DAYLIGHT },
    714     { WHITE_BALANCE_CLOUDY_DAYLIGHT, CAM_WB_MODE_CLOUDY_DAYLIGHT },
    715     { WHITE_BALANCE_TWILIGHT,        CAM_WB_MODE_TWILIGHT },
    716     { WHITE_BALANCE_SHADE,           CAM_WB_MODE_SHADE },
    717     { WHITE_BALANCE_MANUAL,          CAM_WB_MODE_MANUAL},
    718 };
    719 
    720 const QCameraParameters::QCameraMap<cam_antibanding_mode_type>
    721         QCameraParameters::ANTIBANDING_MODES_MAP[] = {
    722     { ANTIBANDING_OFF,  CAM_ANTIBANDING_MODE_OFF },
    723     { ANTIBANDING_50HZ, CAM_ANTIBANDING_MODE_50HZ },
    724     { ANTIBANDING_60HZ, CAM_ANTIBANDING_MODE_60HZ },
    725     { ANTIBANDING_AUTO, CAM_ANTIBANDING_MODE_AUTO }
    726 };
    727 
    728 const QCameraParameters::QCameraMap<cam_iso_mode_type>
    729         QCameraParameters::ISO_MODES_MAP[] = {
    730     { ISO_AUTO,  CAM_ISO_MODE_AUTO },
    731     { ISO_HJR,   CAM_ISO_MODE_DEBLUR },
    732     { ISO_100,   CAM_ISO_MODE_100 },
    733     { ISO_200,   CAM_ISO_MODE_200 },
    734     { ISO_400,   CAM_ISO_MODE_400 },
    735     { ISO_800,   CAM_ISO_MODE_800 },
    736     { ISO_1600,  CAM_ISO_MODE_1600 },
    737     { ISO_3200,  CAM_ISO_MODE_3200 }
    738 };
    739 
    740 const QCameraParameters::QCameraMap<cam_hfr_mode_t>
    741         QCameraParameters::HFR_MODES_MAP[] = {
    742     { VIDEO_HFR_OFF, CAM_HFR_MODE_OFF },
    743     { VIDEO_HFR_2X, CAM_HFR_MODE_60FPS },
    744     { VIDEO_HFR_3X, CAM_HFR_MODE_90FPS },
    745     { VIDEO_HFR_4X, CAM_HFR_MODE_120FPS },
    746     { VIDEO_HFR_5X, CAM_HFR_MODE_150FPS },
    747     { VIDEO_HFR_6X, CAM_HFR_MODE_180FPS },
    748     { VIDEO_HFR_7X, CAM_HFR_MODE_210FPS },
    749     { VIDEO_HFR_8X, CAM_HFR_MODE_240FPS },
    750     { VIDEO_HFR_9X, CAM_HFR_MODE_480FPS }
    751 };
    752 
    753 const QCameraParameters::QCameraMap<cam_bracket_mode>
    754         QCameraParameters::BRACKETING_MODES_MAP[] = {
    755     { AE_BRACKET_OFF, CAM_EXP_BRACKETING_OFF },
    756     { AE_BRACKET,     CAM_EXP_BRACKETING_ON }
    757 };
    758 
    759 const QCameraParameters::QCameraMap<int>
    760         QCameraParameters::ON_OFF_MODES_MAP[] = {
    761     { VALUE_OFF, 0 },
    762     { VALUE_ON,  1 }
    763 };
    764 
    765 const QCameraParameters::QCameraMap<int>
    766         QCameraParameters::TOUCH_AF_AEC_MODES_MAP[] = {
    767     { QCameraParameters::TOUCH_AF_AEC_OFF, 0 },
    768     { QCameraParameters::TOUCH_AF_AEC_ON, 1 }
    769 };
    770 
    771 const QCameraParameters::QCameraMap<int>
    772         QCameraParameters::ENABLE_DISABLE_MODES_MAP[] = {
    773     { VALUE_ENABLE,  1 },
    774     { VALUE_DISABLE, 0 }
    775 };
    776 
    777 const QCameraParameters::QCameraMap<int>
    778         QCameraParameters::DENOISE_ON_OFF_MODES_MAP[] = {
    779     { DENOISE_OFF, 0 },
    780     { DENOISE_ON,  1 }
    781 };
    782 
    783 const QCameraParameters::QCameraMap<int>
    784         QCameraParameters::TRUE_FALSE_MODES_MAP[] = {
    785     { VALUE_FALSE, 0},
    786     { VALUE_TRUE,  1}
    787 };
    788 
    789 const QCameraParameters::QCameraMap<cam_flip_t>
    790         QCameraParameters::FLIP_MODES_MAP[] = {
    791     {FLIP_MODE_OFF, FLIP_NONE},
    792     {FLIP_MODE_V, FLIP_V},
    793     {FLIP_MODE_H, FLIP_H},
    794     {FLIP_MODE_VH, FLIP_V_H}
    795 };
    796 
    797 const QCameraParameters::QCameraMap<int>
    798         QCameraParameters::AF_BRACKETING_MODES_MAP[] = {
    799     { AF_BRACKET_OFF, 0 },
    800     { AF_BRACKET_ON,  1 }
    801 };
    802 
    803 const QCameraParameters::QCameraMap<int>
    804         QCameraParameters::RE_FOCUS_MODES_MAP[] = {
    805     { RE_FOCUS_OFF, 0 },
    806     { RE_FOCUS_ON,  1 }
    807 };
    808 
    809 const QCameraParameters::QCameraMap<int>
    810         QCameraParameters::CHROMA_FLASH_MODES_MAP[] = {
    811     { CHROMA_FLASH_OFF, 0 },
    812     { CHROMA_FLASH_ON,  1 }
    813 };
    814 
    815 const QCameraParameters::QCameraMap<int>
    816         QCameraParameters::OPTI_ZOOM_MODES_MAP[] = {
    817     { OPTI_ZOOM_OFF, 0 },
    818     { OPTI_ZOOM_ON,  1 }
    819 };
    820 
    821 const QCameraParameters::QCameraMap<int>
    822         QCameraParameters::TRUE_PORTRAIT_MODES_MAP[] = {
    823     { TRUE_PORTRAIT_OFF, 0 },
    824     { TRUE_PORTRAIT_ON,  1 }
    825 };
    826 
    827 const QCameraParameters::QCameraMap<int>
    828         QCameraParameters::STILL_MORE_MODES_MAP[] = {
    829     { STILL_MORE_OFF, 0 },
    830     { STILL_MORE_ON,  1 }
    831 };
    832 
    833 const QCameraParameters::QCameraMap<cam_cds_mode_type_t>
    834         QCameraParameters::CDS_MODES_MAP[] = {
    835     { CDS_MODE_OFF, CAM_CDS_MODE_OFF },
    836     { CDS_MODE_ON, CAM_CDS_MODE_ON },
    837     { CDS_MODE_AUTO, CAM_CDS_MODE_AUTO}
    838 };
    839 
    840 const QCameraParameters::QCameraMap<int>
    841         QCameraParameters::HDR_MODES_MAP[] = {
    842     { HDR_MODE_SENSOR, 0 },
    843     { HDR_MODE_MULTI_FRAME, 1 }
    844 };
    845 
    846 const QCameraParameters::QCameraMap<int>
    847         QCameraParameters::VIDEO_ROTATION_MODES_MAP[] = {
    848     { VIDEO_ROTATION_0, 0 },
    849     { VIDEO_ROTATION_90, 90 },
    850     { VIDEO_ROTATION_180, 180 },
    851     { VIDEO_ROTATION_270, 270 }
    852 };
    853 
    854 const QCameraParameters::QCameraMap<int>
    855         QCameraParameters::NOISE_REDUCTION_MODES_MAP[] = {
    856     { VALUE_OFF, 0 },
    857     { VALUE_FAST,  1 },
    858     { VALUE_HIGH_QUALITY,  2 }
    859 };
    860 
    861 #define DEFAULT_CAMERA_AREA "(0, 0, 0, 0, 0)"
    862 #define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
    863 #define TOTAL_RAM_SIZE_512MB 536870912
    864 #define PARAM_MAP_SIZE(MAP) (sizeof(MAP)/sizeof(MAP[0]))
    865 
    866 /*===========================================================================
    867  * FUNCTION   : isOEMFeat1PropEnabled
    868  *
    869  * DESCRIPTION: inline function to check from property if custom feature
    870  *            is enabled
    871  *
    872  * PARAMETERS : none
    873  *
    874  * RETURN     : boolean true/false
    875  *==========================================================================*/
    876 static inline bool isOEMFeat1PropEnabled()
    877 {
    878     char value[PROPERTY_VALUE_MAX];
    879     property_get("persist.camera.imglib.oemfeat1", value, "0");
    880     return atoi(value) > 0 ? true : false;
    881 }
    882 
    883 /*===========================================================================
    884  * FUNCTION   : QCameraParameters
    885  *
    886  * DESCRIPTION: default constructor of QCameraParameters
    887  *
    888  * PARAMETERS : none
    889  *
    890  * RETURN     : None
    891  *==========================================================================*/
    892 QCameraParameters::QCameraParameters()
    893     : CameraParameters(),
    894       m_reprocScaleParam(),
    895       mCommon(),
    896       m_pCapability(NULL),
    897       m_pCamOpsTbl(NULL),
    898       m_pParamHeap(NULL),
    899       m_pParamBuf(NULL),
    900       m_pRelCamSyncHeap(NULL),
    901       m_pRelCamSyncBuf(NULL),
    902       m_bFrameSyncEnabled(false),
    903       mIsType(IS_TYPE_NONE),
    904       m_bZslMode(false),
    905       m_bZslMode_new(false),
    906       m_bForceZslMode(false),
    907       m_bRecordingHint(false),
    908       m_bRecordingHint_new(false),
    909       m_bHistogramEnabled(false),
    910       m_bLongshotEnabled(false),
    911       m_nFaceProcMask(0),
    912       m_bFaceDetectionOn(0),
    913       m_bDebugFps(false),
    914       mFocusMode(CAM_FOCUS_MODE_MAX),
    915       mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
    916       mAppPreviewFormat(CAM_FORMAT_YUV_420_NV21),
    917       mPictureFormat(CAM_FORMAT_JPEG),
    918       m_bNeedRestart(false),
    919       m_bNoDisplayMode(false),
    920       m_bWNROn(false),
    921       m_bTNRPreviewOn(false),
    922       m_bTNRVideoOn(false),
    923       m_bTNRSnapshotOn(false),
    924       m_bInited(false),
    925       m_nRetroBurstNum(0),
    926       m_nBurstLEDOnPeriod(100),
    927       m_bUpdateEffects(false),
    928       m_bSceneTransitionAuto(false),
    929       m_bPreviewFlipChanged(false),
    930       m_bVideoFlipChanged(false),
    931       m_bSnapshotFlipChanged(false),
    932       m_bFixedFrameRateSet(false),
    933       m_bHDREnabled(false),
    934       m_bLocalHDREnabled(false),
    935       m_bAVTimerEnabled(false),
    936       m_bDISEnabled(false),
    937       m_MobiMask(0),
    938       m_AdjustFPS(NULL),
    939       m_bHDR1xFrameEnabled(false),
    940       m_HDRSceneEnabled(false),
    941       m_bHDRThumbnailProcessNeeded(false),
    942       m_bHDR1xExtraBufferNeeded(true),
    943       m_bHDROutputCropEnabled(false),
    944       m_tempMap(),
    945       m_bAFBracketingOn(false),
    946       m_bReFocusOn(false),
    947       m_bChromaFlashOn(false),
    948       m_bOptiZoomOn(false),
    949       m_bSceneSelection(false),
    950       m_SelectedScene(CAM_SCENE_MODE_MAX),
    951       m_bSeeMoreOn(false),
    952       m_bStillMoreOn(false),
    953       m_bHighQualityNoiseReductionMode(false),
    954       m_bHfrMode(false),
    955       m_bSensorHDREnabled(false),
    956       m_bRdiMode(false),
    957       m_bSecureMode(false),
    958       m_bAeBracketingEnabled(false),
    959       mFlashValue(CAM_FLASH_MODE_OFF),
    960       mFlashDaemonValue(CAM_FLASH_MODE_OFF),
    961       mHfrMode(CAM_HFR_MODE_OFF),
    962       m_bHDRModeSensor(true),
    963       mOfflineRAW(false),
    964       m_bTruePortraitOn(false),
    965       m_bIsLowMemoryDevice(false),
    966       mCds_mode(CAM_CDS_MODE_OFF),
    967       m_LLCaptureEnabled(FALSE),
    968       m_LowLightLevel(CAM_LOW_LIGHT_OFF),
    969       m_bLtmForSeeMoreEnabled(false),
    970       m_expTime(0),
    971       m_isoValue(0),
    972       m_ManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF),
    973       m_dualLedCalibration(0),
    974       m_bInstantAEC(false),
    975       m_bInstantCapture(false),
    976       mAecFrameBound(0),
    977       mAecSkipDisplayFrameBound(0)
    978 {
    979     char value[PROPERTY_VALUE_MAX];
    980     // TODO: may move to parameter instead of sysprop
    981     property_get("persist.debug.sf.showfps", value, "0");
    982     m_bDebugFps = atoi(value) > 0 ? true : false;
    983 
    984     // For thermal mode, it should be set as system property
    985     // because system property applies to all applications, while
    986     // parameters only apply to specific app.
    987     property_get("persist.camera.thermal.mode", value, "fps");
    988     if (!strcmp(value, "frameskip")) {
    989         m_ThermalMode = QCAMERA_THERMAL_ADJUST_FRAMESKIP;
    990     } else {
    991         if (strcmp(value, "fps"))
    992             LOGW("Invalid camera thermal mode %s", value);
    993         m_ThermalMode = QCAMERA_THERMAL_ADJUST_FPS;
    994     }
    995 
    996     memset(value, 0, sizeof(value));
    997     // As per Power/Quality evaluation, LTM is enabled by default in SeeMore/StillMore usecase
    998     // to improve the quality as there is no much impact to power
    999     property_get("persist.camera.ltmforseemore", value, "1");
   1000     m_bLtmForSeeMoreEnabled = atoi(value);
   1001 
   1002     memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
   1003     memset(&m_default_fps_range, 0, sizeof(m_default_fps_range));
   1004     memset(&m_hfrFpsRange, 0, sizeof(m_hfrFpsRange));
   1005     memset(&m_stillmore_config, 0, sizeof(cam_still_more_t));
   1006     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
   1007     memset(&m_relCamSyncInfo, 0, sizeof(cam_sync_related_sensors_event_info_t));
   1008     mTotalPPCount = 1;
   1009     mZoomLevel = 0;
   1010     mParmZoomLevel = 0;
   1011     mCurPPCount = 0;
   1012     mBufBatchCnt = 0;
   1013     mRotation = 0;
   1014     mJpegRotation = 0;
   1015     mVideoBatchSize = 0;
   1016     m_bOEMFeatEnabled = isOEMFeat1PropEnabled();
   1017 }
   1018 
   1019 /*===========================================================================
   1020  * FUNCTION   : QCameraParameters
   1021  *
   1022  * DESCRIPTION: constructor of QCameraParameters
   1023  *
   1024  * PARAMETERS :
   1025  *   @params  : parameters in string
   1026  *
   1027  * RETURN     : None
   1028  *==========================================================================*/
   1029 QCameraParameters::QCameraParameters(const String8 &params)
   1030     : CameraParameters(params),
   1031     m_reprocScaleParam(),
   1032     m_pCapability(NULL),
   1033     m_pCamOpsTbl(NULL),
   1034     m_pParamHeap(NULL),
   1035     m_pParamBuf(NULL),
   1036     m_pRelCamSyncHeap(NULL),
   1037     m_pRelCamSyncBuf(NULL),
   1038     m_bFrameSyncEnabled(false),
   1039     m_bZslMode(false),
   1040     m_bZslMode_new(false),
   1041     m_bForceZslMode(false),
   1042     m_bRecordingHint(false),
   1043     m_bRecordingHint_new(false),
   1044     m_bHistogramEnabled(false),
   1045     m_bLongshotEnabled(false),
   1046     m_nFaceProcMask(0),
   1047     m_bDebugFps(false),
   1048     mFocusMode(CAM_FOCUS_MODE_MAX),
   1049     mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
   1050     mAppPreviewFormat(CAM_FORMAT_YUV_420_NV21),
   1051     mPictureFormat(CAM_FORMAT_JPEG),
   1052     m_bNeedRestart(false),
   1053     m_bNoDisplayMode(false),
   1054     m_bWNROn(false),
   1055     m_bTNRPreviewOn(false),
   1056     m_bTNRVideoOn(false),
   1057     m_bTNRSnapshotOn(false),
   1058     m_bInited(false),
   1059     m_nRetroBurstNum(0),
   1060     m_nBurstLEDOnPeriod(100),
   1061     m_bPreviewFlipChanged(false),
   1062     m_bVideoFlipChanged(false),
   1063     m_bSnapshotFlipChanged(false),
   1064     m_bFixedFrameRateSet(false),
   1065     m_bHDREnabled(false),
   1066     m_bLocalHDREnabled(false),
   1067     m_bAVTimerEnabled(false),
   1068     m_AdjustFPS(NULL),
   1069     m_bHDR1xFrameEnabled(false),
   1070     m_HDRSceneEnabled(false),
   1071     m_bHDRThumbnailProcessNeeded(false),
   1072     m_bHDR1xExtraBufferNeeded(true),
   1073     m_bHDROutputCropEnabled(false),
   1074     m_tempMap(),
   1075     m_bAFBracketingOn(false),
   1076     m_bReFocusOn(false),
   1077     m_bChromaFlashOn(false),
   1078     m_bOptiZoomOn(false),
   1079     m_bSceneSelection(false),
   1080     m_SelectedScene(CAM_SCENE_MODE_MAX),
   1081     m_bSeeMoreOn(false),
   1082     m_bStillMoreOn(false),
   1083     m_bHighQualityNoiseReductionMode(false),
   1084     m_bHfrMode(false),
   1085     m_bSensorHDREnabled(false),
   1086     m_bRdiMode(false),
   1087     m_bSecureMode(false),
   1088     m_bAeBracketingEnabled(false),
   1089     mFlashValue(CAM_FLASH_MODE_OFF),
   1090     mFlashDaemonValue(CAM_FLASH_MODE_OFF),
   1091     mHfrMode(CAM_HFR_MODE_OFF),
   1092     m_bHDRModeSensor(true),
   1093     mOfflineRAW(false),
   1094     m_bTruePortraitOn(false),
   1095     m_bIsLowMemoryDevice(false),
   1096     mCds_mode(CAM_CDS_MODE_OFF),
   1097     mParmEffect(CAM_EFFECT_MODE_OFF),
   1098     m_LLCaptureEnabled(FALSE),
   1099     m_LowLightLevel(CAM_LOW_LIGHT_OFF),
   1100     m_bLtmForSeeMoreEnabled(false),
   1101     m_expTime(0),
   1102     m_isoValue(0),
   1103     m_ManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF),
   1104     m_dualLedCalibration(0),
   1105     m_bInstantAEC(false),
   1106     m_bInstantCapture(false),
   1107     mAecFrameBound(0),
   1108     mAecSkipDisplayFrameBound(0)
   1109 {
   1110     memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
   1111     memset(&m_default_fps_range, 0, sizeof(m_default_fps_range));
   1112     memset(&m_hfrFpsRange, 0, sizeof(m_hfrFpsRange));
   1113     memset(&m_stillmore_config, 0, sizeof(cam_still_more_t));
   1114     memset(&m_relCamSyncInfo, 0, sizeof(cam_sync_related_sensors_event_info_t));
   1115     mTotalPPCount = 0;
   1116     mZoomLevel = 0;
   1117     mParmZoomLevel = 0;
   1118     mCurPPCount = 0;
   1119     mRotation = 0;
   1120     mJpegRotation = 0;
   1121     mBufBatchCnt = 0;
   1122     mVideoBatchSize = 0;
   1123     m_bOEMFeatEnabled = isOEMFeat1PropEnabled();
   1124 }
   1125 
   1126 /*===========================================================================
   1127  * FUNCTION   : ~QCameraParameters
   1128  *
   1129  * DESCRIPTION: deconstructor of QCameraParameters
   1130  *
   1131  * PARAMETERS : none
   1132  *
   1133  * RETURN     : None
   1134  *==========================================================================*/
   1135 QCameraParameters::~QCameraParameters()
   1136 {
   1137     deinit();
   1138 }
   1139 
   1140 /*===========================================================================
   1141  * FUNCTION   : createSizesString
   1142  *
   1143  * DESCRIPTION: create string obj contains array of dimensions
   1144  *
   1145  * PARAMETERS :
   1146  *   @sizes   : array of dimensions
   1147  *   @len     : size of dimension array
   1148  *
   1149  * RETURN     : string obj
   1150  *==========================================================================*/
   1151 String8 QCameraParameters::createSizesString(const cam_dimension_t *sizes, size_t len)
   1152 {
   1153     String8 str;
   1154     char buffer[32];
   1155 
   1156     if (len > 0) {
   1157         snprintf(buffer, sizeof(buffer), "%dx%d", sizes[0].width, sizes[0].height);
   1158         str.append(buffer);
   1159     }
   1160     for (size_t i = 1; i < len; i++) {
   1161         snprintf(buffer, sizeof(buffer), ",%dx%d",
   1162                 sizes[i].width, sizes[i].height);
   1163         str.append(buffer);
   1164     }
   1165     return str;
   1166 }
   1167 
   1168 /*===========================================================================
   1169  * FUNCTION   : createValuesString
   1170  *
   1171  * DESCRIPTION: create string obj contains array of values from map when matched
   1172  *              from input values array
   1173  *
   1174  * PARAMETERS :
   1175  *   @values  : array of values
   1176  *   @len     : size of values array
   1177  *   @map     : map contains the mapping between values and enums
   1178  *   @map_len : size of the map
   1179  *
   1180  * RETURN     : string obj
   1181  *==========================================================================*/
   1182 template <typename valuesType, class mapType> String8 createValuesString(
   1183         const valuesType *values, size_t len, const mapType *map, size_t map_len)
   1184 {
   1185     String8 str;
   1186     int count = 0;
   1187 
   1188     for (size_t i = 0; i < len; i++ ) {
   1189         for (size_t j = 0; j < map_len; j ++)
   1190             if (map[j].val == values[i]) {
   1191                 if (NULL != map[j].desc) {
   1192                     if (count > 0) {
   1193                         str.append(",");
   1194                     }
   1195                     str.append(map[j].desc);
   1196                     count++;
   1197                     break; //loop j
   1198                 }
   1199             }
   1200     }
   1201     return str;
   1202 }
   1203 
   1204 /*===========================================================================
   1205  * FUNCTION   : createValuesStringFromMap
   1206  *
   1207  * DESCRIPTION: create string obj contains array of values directly from map
   1208  *
   1209  * PARAMETERS :
   1210  *   @map     : map contains the mapping between values and enums
   1211  *   @map_len : size of the map
   1212  *
   1213  * RETURN     : string obj
   1214  *==========================================================================*/
   1215 template <class mapType> String8 createValuesStringFromMap(
   1216         const mapType *map, size_t map_len)
   1217 {
   1218     String8 str;
   1219 
   1220     for (size_t i = 0; i < map_len; i++) {
   1221         if (NULL != map[i].desc) {
   1222             if (i > 0) {
   1223                 str.append(",");
   1224             }
   1225             str.append(map[i].desc);
   1226         }
   1227     }
   1228     return str;
   1229 }
   1230 
   1231 /*===========================================================================
   1232  * FUNCTION   : createZoomRatioValuesString
   1233  *
   1234  * DESCRIPTION: create string obj contains array of zoom ratio values
   1235  *
   1236  * PARAMETERS :
   1237  *   @zoomRaios  : array of zoom ratios
   1238  *   @length     : size of the array
   1239  *
   1240  * RETURN     : string obj
   1241  *==========================================================================*/
   1242 String8 QCameraParameters::createZoomRatioValuesString(uint32_t *zoomRatios,
   1243         size_t length)
   1244 {
   1245     String8 str;
   1246     char buffer[32] = {0};
   1247 
   1248     if(length > 0){
   1249         snprintf(buffer, sizeof(buffer), "%d", zoomRatios[0]);
   1250         str.append(buffer);
   1251     }
   1252 
   1253     for (size_t i = 1; i < length; i++) {
   1254         memset(buffer, 0, sizeof(buffer));
   1255         snprintf(buffer, sizeof(buffer), ",%d", zoomRatios[i]);
   1256         str.append(buffer);
   1257     }
   1258     return str;
   1259 }
   1260 
   1261 /*===========================================================================
   1262  * FUNCTION   : createHfrValuesString
   1263  *
   1264  * DESCRIPTION: create string obj contains array of hfr values from map when
   1265  *              matched from input hfr values
   1266  *
   1267  * PARAMETERS :
   1268  *   @values  : array of hfr info
   1269  *   @len     : size of the array
   1270  *   @map     : map of hfr string value and enum
   1271  *   map_len  : size of map
   1272  *
   1273  * RETURN     : string obj
   1274  *==========================================================================*/
   1275 String8 QCameraParameters::createHfrValuesString(const cam_hfr_info_t *values,
   1276         size_t len, const QCameraMap<cam_hfr_mode_t> *map, size_t map_len)
   1277 {
   1278     String8 str;
   1279     int count = 0;
   1280 
   1281     char value[PROPERTY_VALUE_MAX];
   1282     int8_t batch_count = 0;
   1283 
   1284     property_get("persist.camera.batchcount", value, "0");
   1285     batch_count = atoi(value);
   1286 
   1287     for (size_t i = 0; i < len; i++ ) {
   1288         for (size_t j = 0; j < map_len; j ++) {
   1289             if ((batch_count < CAMERA_MIN_BATCH_COUNT)
   1290                     && (map[j].val > CAM_HFR_MODE_120FPS)) {
   1291                 /*TODO: Work around. Need to revert when we have
   1292                 complete 240fps support*/
   1293                 break;
   1294             }
   1295             if (map[j].val == (int)values[i].mode) {
   1296                 if (NULL != map[j].desc) {
   1297                     if (count > 0) {
   1298                         str.append(",");
   1299                     }
   1300                      str.append(map[j].desc);
   1301                      count++;
   1302                      break; //loop j
   1303                 }
   1304             }
   1305         }
   1306     }
   1307     if (count > 0) {
   1308         str.append(",");
   1309     }
   1310     str.append(VIDEO_HFR_OFF);
   1311     return str;
   1312 }
   1313 
   1314 /*===========================================================================
   1315  * FUNCTION   : createHfrSizesString
   1316  *
   1317  * DESCRIPTION: create string obj contains array of hfr sizes
   1318  *
   1319  * PARAMETERS :
   1320  *   @values  : array of hfr info
   1321  *   @len     : size of the array
   1322  *
   1323  * RETURN     : string obj
   1324  *==========================================================================*/
   1325 String8 QCameraParameters::createHfrSizesString(const cam_hfr_info_t *values, size_t len)
   1326 {
   1327     String8 str;
   1328     char buffer[32];
   1329 
   1330     if (len > 0) {
   1331         snprintf(buffer, sizeof(buffer), "%dx%d",
   1332                  values[0].dim[0].width, values[0].dim[0].height);
   1333         str.append(buffer);
   1334     }
   1335     for (size_t i = 1; i < len; i++) {
   1336         snprintf(buffer, sizeof(buffer), ",%dx%d",
   1337                  values[i].dim[0].width, values[i].dim[0].height);
   1338         str.append(buffer);
   1339     }
   1340     return str;
   1341 }
   1342 
   1343 /*===========================================================================
   1344  * FUNCTION   : createFpsString
   1345  *
   1346  * DESCRIPTION: create string obj contains array of FPS rates
   1347  *
   1348  * PARAMETERS :
   1349  *   @fps     : default fps range
   1350  *
   1351  * RETURN     : string obj
   1352  *==========================================================================*/
   1353 String8 QCameraParameters::createFpsString(cam_fps_range_t &fps)
   1354 {
   1355     char buffer[32];
   1356     String8 fpsValues;
   1357 
   1358     int min_fps = int(fps.min_fps);
   1359     int max_fps = int(fps.max_fps);
   1360 
   1361     if (min_fps < fps.min_fps){
   1362         min_fps++;
   1363     }
   1364     if (max_fps > fps.max_fps) {
   1365         max_fps--;
   1366     }
   1367     if (min_fps <= max_fps) {
   1368         snprintf(buffer, sizeof(buffer), "%d", min_fps);
   1369         fpsValues.append(buffer);
   1370     }
   1371 
   1372     for (int i = min_fps+1; i <= max_fps; i++) {
   1373         snprintf(buffer, sizeof(buffer), ",%d", i);
   1374         fpsValues.append(buffer);
   1375     }
   1376 
   1377     return fpsValues;
   1378 }
   1379 
   1380 /*===========================================================================
   1381  * FUNCTION   : createFpsRangeString
   1382  *
   1383  * DESCRIPTION: create string obj contains array of FPS ranges
   1384  *
   1385  * PARAMETERS :
   1386  *   @fps     : array of fps ranges
   1387  *   @len     : size of the array
   1388  *   @default_fps_index : reference to index of default fps range
   1389  *
   1390  * RETURN     : string obj
   1391  *==========================================================================*/
   1392 String8 QCameraParameters::createFpsRangeString(const cam_fps_range_t* fps,
   1393         size_t len, int &default_fps_index)
   1394 {
   1395     String8 str;
   1396     char buffer[32];
   1397     int max_range = 0;
   1398     int min_fps, max_fps;
   1399 
   1400     if (len > 0) {
   1401         min_fps = int(fps[0].min_fps * 1000);
   1402         max_fps = int(fps[0].max_fps * 1000);
   1403         max_range = max_fps - min_fps;
   1404         default_fps_index = 0;
   1405         snprintf(buffer, sizeof(buffer), "(%d,%d)", min_fps, max_fps);
   1406         str.append(buffer);
   1407     }
   1408     for (size_t i = 1; i < len; i++) {
   1409         min_fps = int(fps[i].min_fps * 1000);
   1410         max_fps = int(fps[i].max_fps * 1000);
   1411         if (max_range < (max_fps - min_fps)) {
   1412             max_range = max_fps - min_fps;
   1413             default_fps_index = (int)i;
   1414         }
   1415         snprintf(buffer, sizeof(buffer), ",(%d,%d)", min_fps, max_fps);
   1416         str.append(buffer);
   1417     }
   1418     return str;
   1419 }
   1420 
   1421 /*===========================================================================
   1422  * FUNCTION   : lookupAttr
   1423  *
   1424  * DESCRIPTION: lookup a value by its name
   1425  *
   1426  * PARAMETERS :
   1427  *   @attr    : map contains <name, value>
   1428  *   @len     : size of the map
   1429  *   @name    : name to be looked up
   1430  *
   1431  * RETURN     : valid value if found
   1432  *              NAME_NOT_FOUND if not found
   1433  *==========================================================================*/
   1434 template <class mapType> int lookupAttr(const mapType *arr,
   1435         size_t len, const char *name)
   1436 {
   1437     if (name) {
   1438         for (size_t i = 0; i < len; i++) {
   1439             if (!strcmp(arr[i].desc, name))
   1440                 return arr[i].val;
   1441         }
   1442     }
   1443     return NAME_NOT_FOUND;
   1444 }
   1445 
   1446 /*===========================================================================
   1447  * FUNCTION   : lookupNameByValue
   1448  *
   1449  * DESCRIPTION: lookup a name by its value
   1450  *
   1451  * PARAMETERS :
   1452  *   @attr    : map contains <name, value>
   1453  *   @len     : size of the map
   1454  *   @value   : value to be looked up
   1455  *
   1456  * RETURN     : name str or NULL if not found
   1457  *==========================================================================*/
   1458 template <class mapType> const char *lookupNameByValue(const mapType *arr,
   1459         size_t len, int value)
   1460 {
   1461     for (size_t i = 0; i < len; i++) {
   1462         if (arr[i].val == value) {
   1463             return arr[i].desc;
   1464         }
   1465     }
   1466     return NULL;
   1467 }
   1468 
   1469 /*===========================================================================
   1470  * FUNCTION   : setPreviewSize
   1471  *
   1472  * DESCRIPTION: set preview size from user setting
   1473  *
   1474  * PARAMETERS :
   1475  *   @params  : user setting parameters
   1476  *
   1477  * RETURN     : int32_t type of status
   1478  *              NO_ERROR  -- success
   1479  *              none-zero failure code
   1480  *==========================================================================*/
   1481 int32_t QCameraParameters::setPreviewSize(const QCameraParameters& params)
   1482 {
   1483     int width = 0, height = 0;
   1484     int old_width = 0, old_height = 0;
   1485     params.getPreviewSize(&width, &height);
   1486     CameraParameters::getPreviewSize(&old_width, &old_height);
   1487 
   1488     // Validate the preview size
   1489     for (size_t i = 0; i < m_pCapability->preview_sizes_tbl_cnt; ++i) {
   1490         if (width ==  m_pCapability->preview_sizes_tbl[i].width
   1491            && height ==  m_pCapability->preview_sizes_tbl[i].height) {
   1492             // check if need to restart preview in case of preview size change
   1493             if (width != old_width || height != old_height) {
   1494                 LOGI("Requested preview size %d x %d", width, height);
   1495                 m_bNeedRestart = true;
   1496             }
   1497             // set the new value
   1498             CameraParameters::setPreviewSize(width, height);
   1499             return NO_ERROR;
   1500         }
   1501     }
   1502     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
   1503         char prop[PROPERTY_VALUE_MAX];
   1504         // set prop to configure aux preview size
   1505         property_get("persist.camera.aux.preview.size", prop, "0");
   1506         parse_pair(prop, &width, &height, 'x', NULL);
   1507         bool foundMatch = false;
   1508         for (size_t i = 0; i < m_pCapability->preview_sizes_tbl_cnt; ++i) {
   1509             if (width ==  m_pCapability->preview_sizes_tbl[i].width &&
   1510                     height ==  m_pCapability->preview_sizes_tbl[i].height) {
   1511                foundMatch = true;
   1512             }
   1513         }
   1514         if (!foundMatch) {
   1515             width = m_pCapability->preview_sizes_tbl[0].width;
   1516             height = m_pCapability->preview_sizes_tbl[0].height;
   1517         }
   1518         // check if need to restart preview in case of preview size change
   1519         if (width != old_width || height != old_height) {
   1520             m_bNeedRestart = true;
   1521         }
   1522         CameraParameters::setPreviewSize(width, height);
   1523         LOGH("Secondary Camera: preview size %d x %d", width, height);
   1524         return NO_ERROR;
   1525     }
   1526 
   1527     LOGE("Invalid preview size requested: %dx%d", width, height);
   1528     return BAD_VALUE;
   1529 }
   1530 
   1531 /*===========================================================================
   1532  * FUNCTION   : setPictureSize
   1533  *
   1534  * DESCRIPTION: set picture size from user setting
   1535  *
   1536  * PARAMETERS :
   1537  *   @params  : user setting parameters
   1538  *
   1539  * RETURN     : int32_t type of status
   1540  *              NO_ERROR  -- success
   1541  *              none-zero failure code
   1542  *==========================================================================*/
   1543 int32_t QCameraParameters::setPictureSize(const QCameraParameters& params)
   1544 {
   1545     int width, height;
   1546     params.getPictureSize(&width, &height);
   1547     int old_width, old_height;
   1548     CameraParameters::getPictureSize(&old_width, &old_height);
   1549 
   1550     // Validate the picture size
   1551     if(!m_reprocScaleParam.isScaleEnabled()){
   1552         for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
   1553             if (width ==  m_pCapability->picture_sizes_tbl[i].width
   1554                && height ==  m_pCapability->picture_sizes_tbl[i].height) {
   1555                 // check if need to restart preview in case of picture size change
   1556                 if ((m_bZslMode || m_bRecordingHint) &&
   1557                     (width != old_width || height != old_height)) {
   1558                     LOGI("Requested picture size %d x %d", width, height);
   1559                     m_bNeedRestart = true;
   1560                 }
   1561                 // set the new value
   1562                 CameraParameters::setPictureSize(width, height);
   1563                 // Update View angles based on Picture Aspect ratio
   1564                 updateViewAngles();
   1565                 return NO_ERROR;
   1566             }
   1567         }
   1568     }else{
   1569         //should use scaled picture size table to validate
   1570         if(m_reprocScaleParam.setValidatePicSize(width, height) == NO_ERROR){
   1571             // check if need to restart preview in case of picture size change
   1572             if ((m_bZslMode || m_bRecordingHint) &&
   1573                 (width != old_width || height != old_height)) {
   1574                 m_bNeedRestart = true;
   1575             }
   1576             // set the new value
   1577             char val[32];
   1578             snprintf(val, sizeof(val), "%dx%d", width, height);
   1579             updateParamEntry(KEY_PICTURE_SIZE, val);
   1580             LOGH("%s", val);
   1581             // Update View angles based on Picture Aspect ratio
   1582             updateViewAngles();
   1583             return NO_ERROR;
   1584         }
   1585     }
   1586     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
   1587         char prop[PROPERTY_VALUE_MAX];
   1588         // set prop to configure aux preview size
   1589         property_get("persist.camera.aux.picture.size", prop, "0");
   1590         parse_pair(prop, &width, &height, 'x', NULL);
   1591         bool foundMatch = false;
   1592         for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
   1593             if (width ==  m_pCapability->picture_sizes_tbl[i].width &&
   1594                     height ==  m_pCapability->picture_sizes_tbl[i].height) {
   1595                foundMatch = true;
   1596             }
   1597         }
   1598         if (!foundMatch) {
   1599             width = m_pCapability->picture_sizes_tbl[0].width;
   1600             height = m_pCapability->picture_sizes_tbl[0].height;
   1601         }
   1602         // check if need to restart preview in case of preview size change
   1603         if (width != old_width || height != old_height) {
   1604             m_bNeedRestart = true;
   1605         }
   1606         char val[32];
   1607         snprintf(val, sizeof(val), "%dx%d", width, height);
   1608         set(KEY_PICTURE_SIZE, val);
   1609         LOGH("Secondary Camera: picture size %s", val);
   1610         return NO_ERROR;
   1611     }
   1612     LOGE("Invalid picture size requested: %dx%d", width, height);
   1613     return BAD_VALUE;
   1614 }
   1615 
   1616 /*===========================================================================
   1617  * FUNCTION   : updateViewAngles
   1618  *
   1619  * DESCRIPTION: Update the Horizontal & Vertical based on the Aspect ratio of Preview and
   1620  *                        Picture aspect ratio
   1621  *
   1622  * PARAMETERS : none
   1623  *
   1624  * RETURN     : none
   1625  *==========================================================================*/
   1626 void QCameraParameters::updateViewAngles()
   1627 {
   1628     double stillAspectRatio, maxPictureAspectRatio;
   1629     int stillWidth, stillHeight, maxWidth, maxHeight;
   1630     // The crop factors from the full sensor array to the still picture crop region
   1631     double horizCropFactor = 1.f,vertCropFactor = 1.f;
   1632     float horizViewAngle, vertViewAngle, maxHfov, maxVfov;
   1633 
   1634     // Get current Picture & max Snapshot sizes
   1635     getPictureSize(&stillWidth, &stillHeight);
   1636     maxWidth  = m_pCapability->picture_sizes_tbl[0].width;
   1637     maxHeight = m_pCapability->picture_sizes_tbl[0].height;
   1638 
   1639     // Get default maximum FOV from corresponding sensor driver
   1640     maxHfov = m_pCapability->hor_view_angle;
   1641     maxVfov = m_pCapability->ver_view_angle;
   1642 
   1643     stillAspectRatio = (double)stillWidth/stillHeight;
   1644     maxPictureAspectRatio = (double)maxWidth/maxHeight;
   1645     LOGD("Stillwidth: %d, height: %d", stillWidth, stillHeight);
   1646     LOGD("Max width: %d, height: %d", maxWidth, maxHeight);
   1647     LOGD("still aspect: %f, Max Pic Aspect: %f",
   1648             stillAspectRatio, maxPictureAspectRatio);
   1649 
   1650     // crop as per the Maximum Snapshot aspect ratio
   1651     if (stillAspectRatio < maxPictureAspectRatio)
   1652         horizCropFactor = stillAspectRatio/maxPictureAspectRatio;
   1653     else
   1654         vertCropFactor = maxPictureAspectRatio/stillAspectRatio;
   1655 
   1656     LOGD("horizCropFactor %f, vertCropFactor %f",
   1657              horizCropFactor, vertCropFactor);
   1658 
   1659     // Now derive the final FOV's based on field of view formula is i.e,
   1660     // angle of view = 2 * arctangent ( d / 2f )
   1661     // where d is the physical sensor dimension of interest, and f is
   1662     // the focal length. This only applies to rectilinear sensors, for focusing
   1663     // at distances >> f, etc.
   1664     // Here d/2f is nothing but the Maximum Horizontal or Veritical FOV
   1665     horizViewAngle = (180/PI)*2*atan(horizCropFactor*tan((maxHfov/2)*(PI/180)));
   1666     vertViewAngle = (180/PI)*2*atan(horizCropFactor*tan((maxVfov/2)*(PI/180)));
   1667 
   1668     setFloat(QCameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, horizViewAngle);
   1669     setFloat(QCameraParameters::KEY_VERTICAL_VIEW_ANGLE, vertViewAngle);
   1670     LOGH("Final horizViewAngle %f, vertViewAngle %f",
   1671             horizViewAngle, vertViewAngle);
   1672 }
   1673 
   1674 /*===========================================================================
   1675  * FUNCTION   : setVideoSize
   1676  *
   1677  * DESCRIPTION: set video size from user setting
   1678  *
   1679  * PARAMETERS :
   1680  *   @params  : user setting parameters
   1681  *
   1682  * RETURN     : int32_t type of status
   1683  *              NO_ERROR  -- success
   1684  *              none-zero failure code
   1685  *==========================================================================*/
   1686 int32_t QCameraParameters::setVideoSize(const QCameraParameters& params)
   1687 {
   1688     const char *str= NULL;
   1689     int width, height;
   1690     str = params.get(KEY_VIDEO_SIZE);
   1691     int old_width, old_height;
   1692     CameraParameters::getVideoSize(&old_width, &old_height);
   1693     if(!str) {
   1694         //If application didn't set this parameter string, use the values from
   1695         //getPreviewSize() as video dimensions.
   1696         params.getPreviewSize(&width, &height);
   1697         LOGW("No Record Size requested, use the preview dimensions");
   1698     } else {
   1699         params.getVideoSize(&width, &height);
   1700     }
   1701 
   1702     // Validate the video size
   1703     for (size_t i = 0; i < m_pCapability->video_sizes_tbl_cnt; ++i) {
   1704         if (width ==  m_pCapability->video_sizes_tbl[i].width
   1705                 && height ==  m_pCapability->video_sizes_tbl[i].height) {
   1706             // check if need to restart preview in case of video size change
   1707             if (m_bRecordingHint &&
   1708                (width != old_width || height != old_height)) {
   1709                 m_bNeedRestart = true;
   1710             }
   1711 
   1712             // set the new value
   1713             LOGH("Requested video size %d x %d", width, height);
   1714             CameraParameters::setVideoSize(width, height);
   1715             return NO_ERROR;
   1716         }
   1717     }
   1718     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
   1719         // Set the default preview size for secondary camera
   1720         width = m_pCapability->video_sizes_tbl[0].width;
   1721         height = m_pCapability->video_sizes_tbl[0].height;
   1722         // check if need to restart preview in case of preview size change
   1723         if (width != old_width || height != old_height) {
   1724             m_bNeedRestart = true;
   1725         }
   1726 
   1727         CameraParameters::setVideoSize(width, height);
   1728         LOGH("Secondary Camera: video size %d x %d",
   1729                  width, height);
   1730         return NO_ERROR;
   1731     }
   1732 
   1733     LOGE("Error !! Invalid video size requested: %dx%d", width, height);
   1734     return BAD_VALUE;
   1735 }
   1736 
   1737 /*===========================================================================
   1738  * FUNCTION   : getLiveSnapshotSize
   1739  *
   1740  * DESCRIPTION: get live snapshot size
   1741  *
   1742  * PARAMETERS : dim - Update dim with the liveshot size
   1743  *
   1744  *==========================================================================*/
   1745 void QCameraParameters::getLiveSnapshotSize(cam_dimension_t &dim)
   1746 {
   1747     if(is4k2kVideoResolution()) {
   1748         // We support maximum 8M liveshot @4K2K video resolution
   1749         cam_dimension_t resolution = {0, 0};
   1750         CameraParameters::getVideoSize(&resolution.width, &resolution.height);
   1751         if((m_LiveSnapshotSize.width > resolution.width) ||
   1752                 (m_LiveSnapshotSize.height > resolution.height)) {
   1753             m_LiveSnapshotSize.width = resolution.width;
   1754             m_LiveSnapshotSize.height = resolution.height;
   1755         }
   1756     }
   1757     dim = m_LiveSnapshotSize;
   1758     LOGH("w x h: %d x %d", dim.width, dim.height);
   1759 }
   1760 
   1761 /*===========================================================================
   1762  * FUNCTION   : setLiveSnapshotSize
   1763  *
   1764  * DESCRIPTION: set live snapshot size
   1765  *
   1766  * PARAMETERS :
   1767  *   @params  : user setting parameters
   1768  *
   1769  * RETURN     : int32_t type of status
   1770  *              NO_ERROR  -- success
   1771  *              none-zero failure code
   1772  *==========================================================================*/
   1773 int32_t QCameraParameters::setLiveSnapshotSize(const QCameraParameters& params)
   1774 {
   1775     char value[PROPERTY_VALUE_MAX];
   1776     property_get("persist.camera.opt.livepic", value, "1");
   1777     bool useOptimal = atoi(value) > 0 ? true : false;
   1778     bool vHdrOn;
   1779     int32_t liveSnapWidth = 0, liveSnapHeight = 0;
   1780     // use picture size from user setting
   1781     params.getPictureSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
   1782 
   1783     size_t livesnapshot_sizes_tbl_cnt =
   1784             m_pCapability->livesnapshot_sizes_tbl_cnt;
   1785     cam_dimension_t *livesnapshot_sizes_tbl =
   1786             &m_pCapability->livesnapshot_sizes_tbl[0];
   1787 
   1788     if(is4k2kVideoResolution()) {
   1789         // We support maximum 8M liveshot @4K2K video resolution
   1790         cam_dimension_t resolution = {0, 0};
   1791         CameraParameters::getVideoSize(&resolution.width, &resolution.height);
   1792         if((m_LiveSnapshotSize.width > resolution.width) ||
   1793                 (m_LiveSnapshotSize.height > resolution.height)) {
   1794             m_LiveSnapshotSize.width = resolution.width;
   1795             m_LiveSnapshotSize.height = resolution.height;
   1796         }
   1797     }
   1798 
   1799     // check if HFR is enabled
   1800     const char *hfrStr = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
   1801     cam_hfr_mode_t hfrMode = CAM_HFR_MODE_OFF;
   1802     const char *hsrStr = params.get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
   1803 
   1804     const char *vhdrStr = params.get(KEY_QC_VIDEO_HDR);
   1805     vHdrOn = (vhdrStr != NULL && (0 == strcmp(vhdrStr,"on"))) ? true : false;
   1806     if (vHdrOn) {
   1807         livesnapshot_sizes_tbl_cnt = m_pCapability->vhdr_livesnapshot_sizes_tbl_cnt;
   1808         livesnapshot_sizes_tbl = &m_pCapability->vhdr_livesnapshot_sizes_tbl[0];
   1809     }
   1810     if ((hsrStr != NULL) && strcmp(hsrStr, "off")) {
   1811         int32_t hsr = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hsrStr);
   1812         if ((hsr != NAME_NOT_FOUND) && (hsr > CAM_HFR_MODE_OFF)) {
   1813             // if HSR is enabled, change live snapshot size
   1814             for (size_t i = 0; i < m_pCapability->hfr_tbl_cnt; i++) {
   1815                 if (m_pCapability->hfr_tbl[i].mode == hsr) {
   1816                     livesnapshot_sizes_tbl_cnt =
   1817                             m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl_cnt;
   1818                     livesnapshot_sizes_tbl =
   1819                             &m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl[0];
   1820                     hfrMode = m_pCapability->hfr_tbl[i].mode;
   1821                     break;
   1822                 }
   1823             }
   1824         }
   1825     } else if ((hfrStr != NULL) && strcmp(hfrStr, "off")) {
   1826         int32_t hfr = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hfrStr);
   1827         if ((hfr != NAME_NOT_FOUND) && (hfr > CAM_HFR_MODE_OFF)) {
   1828             // if HFR is enabled, change live snapshot size
   1829             for (size_t i = 0; i < m_pCapability->hfr_tbl_cnt; i++) {
   1830                 if (m_pCapability->hfr_tbl[i].mode == hfr) {
   1831                     livesnapshot_sizes_tbl_cnt =
   1832                             m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl_cnt;
   1833                     livesnapshot_sizes_tbl =
   1834                             &m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl[0];
   1835                     hfrMode = m_pCapability->hfr_tbl[i].mode;
   1836                     break;
   1837                 }
   1838             }
   1839         }
   1840     }
   1841 
   1842     if (useOptimal || hfrMode != CAM_HFR_MODE_OFF || vHdrOn) {
   1843         bool found = false;
   1844 
   1845         // first check if picture size is within the list of supported sizes
   1846         for (size_t i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
   1847             if (m_LiveSnapshotSize.width == livesnapshot_sizes_tbl[i].width &&
   1848                 m_LiveSnapshotSize.height == livesnapshot_sizes_tbl[i].height) {
   1849                 found = true;
   1850                 break;
   1851             }
   1852         }
   1853 
   1854         if (!found) {
   1855             // use optimal live snapshot size from supported list,
   1856             // that has same preview aspect ratio
   1857             int width = 0, height = 0;
   1858             params.getPreviewSize(&width, &height);
   1859 
   1860             double previewAspectRatio = (double)width / height;
   1861             for (size_t i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
   1862                 double ratio = (double)livesnapshot_sizes_tbl[i].width /
   1863                                 livesnapshot_sizes_tbl[i].height;
   1864                 if (fabs(previewAspectRatio - ratio) <= ASPECT_TOLERANCE) {
   1865                     m_LiveSnapshotSize = livesnapshot_sizes_tbl[i];
   1866                     found = true;
   1867                     break;
   1868                 }
   1869             }
   1870 
   1871             if (!found && ((hfrMode != CAM_HFR_MODE_OFF) || vHdrOn)) {
   1872                 // Cannot find matching aspect ration from supported live snapshot list
   1873                 // choose the max dim from preview and video size
   1874                 LOGD("Cannot find matching aspect ratio, choose max of preview or video size");
   1875                 params.getVideoSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
   1876                 if (m_LiveSnapshotSize.width < width && m_LiveSnapshotSize.height < height) {
   1877                     m_LiveSnapshotSize.width = width;
   1878                     m_LiveSnapshotSize.height = height;
   1879                 }
   1880             }
   1881         }
   1882     }
   1883     //To read liveshot resolution from setprop instead of matching aspect ratio.
   1884     //The setprop resolution format should be WxH.
   1885     //e.g: adb shell setprop persist.camera.liveshot.size 1280x720
   1886     memset(value, 0, PROPERTY_VALUE_MAX);
   1887     property_get("persist.camera.liveshot.size", value, "");
   1888     if (strlen(value) > 0) {
   1889         char *saveptr = NULL;
   1890         char *token = strtok_r(value, "x", &saveptr);
   1891         if (token != NULL) {
   1892             liveSnapWidth = atoi(token);
   1893         }
   1894         token = strtok_r(NULL, "x", &saveptr);
   1895         if (token != NULL) {
   1896             liveSnapHeight = atoi(token);
   1897         }
   1898         if ((liveSnapWidth!=0) && (liveSnapHeight!=0)) {
   1899             for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
   1900                 if (liveSnapWidth ==  m_pCapability->picture_sizes_tbl[i].width
   1901                         && liveSnapHeight ==  m_pCapability->picture_sizes_tbl[i].height) {
   1902                    m_LiveSnapshotSize.width = liveSnapWidth;
   1903                    m_LiveSnapshotSize.height = liveSnapHeight;
   1904                    break;
   1905                 }
   1906             }
   1907         }
   1908     }
   1909     LOGH("live snapshot size %d x %d",
   1910           m_LiveSnapshotSize.width, m_LiveSnapshotSize.height);
   1911 
   1912     return NO_ERROR;
   1913 }
   1914 
   1915 
   1916 /*===========================================================================
   1917  * FUNCTION   : setRawSize
   1918  *
   1919  * DESCRIPTION: set live snapshot size
   1920  *
   1921  * PARAMETERS :
   1922  *   @params  : user setting parameters
   1923  *
   1924  * RETURN     : int32_t type of status
   1925  *              NO_ERROR  -- success
   1926  *              none-zero failure code
   1927  *==========================================================================*/
   1928 int32_t QCameraParameters::setRawSize(cam_dimension_t &dim)
   1929 {
   1930     m_rawSize = dim;
   1931     return NO_ERROR;
   1932 }
   1933 /*===========================================================================
   1934  * FUNCTION   : setPreviewFormat
   1935  *
   1936  * DESCRIPTION: set preview format from user setting
   1937  *
   1938  * PARAMETERS :
   1939  *   @params  : user setting parameters
   1940  *
   1941  * RETURN     : int32_t type of status
   1942  *              NO_ERROR  -- success
   1943  *              none-zero failure code
   1944  *==========================================================================*/
   1945 int32_t QCameraParameters::setPreviewFormat(const QCameraParameters& params)
   1946 {
   1947     const char *str = params.getPreviewFormat();
   1948     int32_t previewFormat = lookupAttr(PREVIEW_FORMATS_MAP,
   1949             PARAM_MAP_SIZE(PREVIEW_FORMATS_MAP), str);
   1950     if (previewFormat != NAME_NOT_FOUND) {
   1951         if (isUBWCEnabled()) {
   1952             char prop[PROPERTY_VALUE_MAX];
   1953             int pFormat;
   1954             memset(prop, 0, sizeof(prop));
   1955             property_get("persist.camera.preview.ubwc", prop, "1");
   1956 
   1957             pFormat = atoi(prop);
   1958             if (pFormat == 1) {
   1959                 mPreviewFormat = CAM_FORMAT_YUV_420_NV12_UBWC;
   1960                 mAppPreviewFormat = (cam_format_t)previewFormat;
   1961             } else {
   1962                 mPreviewFormat = (cam_format_t)previewFormat;
   1963                 mAppPreviewFormat = (cam_format_t)previewFormat;
   1964             }
   1965         } else {
   1966             mPreviewFormat = (cam_format_t)previewFormat;
   1967             mAppPreviewFormat = (cam_format_t)previewFormat;
   1968         }
   1969         CameraParameters::setPreviewFormat(str);
   1970         LOGH("format %d\n", mPreviewFormat);
   1971         return NO_ERROR;
   1972     }
   1973     LOGE("Invalid preview format value: %s", (str == NULL) ? "NULL" : str);
   1974     return BAD_VALUE;
   1975 }
   1976 
   1977 /*===========================================================================
   1978  * FUNCTION   : setPictureFormat
   1979  *
   1980  * DESCRIPTION: set picture format from user setting
   1981  *
   1982  * PARAMETERS :
   1983  *   @params  : user setting parameters
   1984  *
   1985  * RETURN     : int32_t type of status
   1986  *              NO_ERROR  -- success
   1987  *              none-zero failure code
   1988  *==========================================================================*/
   1989 int32_t QCameraParameters::setPictureFormat(const QCameraParameters& params)
   1990 {
   1991     const char *str = params.getPictureFormat();
   1992     int32_t pictureFormat = lookupAttr(PICTURE_TYPES_MAP, PARAM_MAP_SIZE(PICTURE_TYPES_MAP), str);
   1993     if (pictureFormat != NAME_NOT_FOUND) {
   1994         mPictureFormat = pictureFormat;
   1995 
   1996         CameraParameters::setPictureFormat(str);
   1997         LOGH("format %d\n", mPictureFormat);
   1998         return NO_ERROR;
   1999     }
   2000     LOGE("Invalid picture format value: %s", (str == NULL) ? "NULL" : str);
   2001     return BAD_VALUE;
   2002 }
   2003 
   2004 /*===========================================================================
   2005  * FUNCTION   : setJpegThumbnailSize
   2006  *
   2007  * DESCRIPTION: set jpeg thumbnail size from user setting
   2008  *
   2009  * PARAMETERS :
   2010  *   @params  : user setting parameters
   2011  *
   2012  * RETURN     : int32_t type of status
   2013  *              NO_ERROR  -- success
   2014  *              none-zero failure code
   2015  *==========================================================================*/
   2016 int32_t QCameraParameters::setJpegThumbnailSize(const QCameraParameters& params)
   2017 {
   2018     int width = params.getInt(KEY_JPEG_THUMBNAIL_WIDTH);
   2019     int height = params.getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
   2020 
   2021     LOGD("requested jpeg thumbnail size %d x %d", width, height);
   2022     int sizes_cnt = sizeof(THUMBNAIL_SIZES_MAP) / sizeof(cam_dimension_t);
   2023     // Validate thumbnail size
   2024     for (int i = 0; i < sizes_cnt; i++) {
   2025         if (width == THUMBNAIL_SIZES_MAP[i].width &&
   2026                 height == THUMBNAIL_SIZES_MAP[i].height) {
   2027            set(KEY_JPEG_THUMBNAIL_WIDTH, width);
   2028            set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
   2029            return NO_ERROR;
   2030         }
   2031     }
   2032     LOGE("error: setting jpeg thumbnail size (%d, %d)", width, height);
   2033     return BAD_VALUE;
   2034 }
   2035 
   2036 /*===========================================================================
   2037 
   2038  * FUNCTION   : setBurstLEDOnPeriod
   2039  *
   2040  * DESCRIPTION: set burst LED on period
   2041  *
   2042  * PARAMETERS :
   2043  *   @params  : user setting parameters
   2044  *
   2045  * RETURN     : int32_t type of status
   2046  *              NO_ERROR  -- success
   2047  *              none-zero failure code
   2048  *==========================================================================*/
   2049 int32_t QCameraParameters::setBurstLEDOnPeriod(const QCameraParameters& params)
   2050 {
   2051     int nBurstLEDOnPeriod = params.getInt(KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD);
   2052     //Check if the LED ON period is within limits
   2053     if ((nBurstLEDOnPeriod <= 0) || (nBurstLEDOnPeriod > 800)) {
   2054         // if burst led on period is not set in parameters,
   2055         // read from sys prop
   2056         char prop[PROPERTY_VALUE_MAX];
   2057         memset(prop, 0, sizeof(prop));
   2058         property_get("persist.camera.led.on.period", prop, "0");
   2059         nBurstLEDOnPeriod = atoi(prop);
   2060         if (nBurstLEDOnPeriod <= 0) {
   2061             nBurstLEDOnPeriod = 300;
   2062         }
   2063     }
   2064 
   2065     set(KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD, nBurstLEDOnPeriod);
   2066     m_nBurstLEDOnPeriod = nBurstLEDOnPeriod;
   2067     LOGH("Burst LED on period  %u", m_nBurstLEDOnPeriod);
   2068     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BURST_LED_ON_PERIOD,
   2069             (uint32_t)nBurstLEDOnPeriod)) {
   2070         return BAD_VALUE;
   2071     }
   2072 
   2073     return NO_ERROR;
   2074 }
   2075 
   2076 
   2077 
   2078 /*===========================================================================
   2079  * FUNCTION   : setRetroActiveBurstNum
   2080  *
   2081  * DESCRIPTION: set retro active burst num
   2082  *
   2083  * PARAMETERS :
   2084  *   @params  : user setting parameters
   2085  *
   2086  * RETURN     : int32_t type of status
   2087  *              NO_ERROR  -- success
   2088  *              none-zero failure code
   2089  *==========================================================================*/
   2090 int32_t QCameraParameters::setRetroActiveBurstNum(
   2091         const QCameraParameters& params)
   2092 {
   2093     int32_t nBurstNum = params.getInt(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER);
   2094     LOGH("m_nRetroBurstNum = %d", m_nRetroBurstNum);
   2095     if (nBurstNum <= 0) {
   2096         // if burst number is not set in parameters,
   2097         // read from sys prop
   2098         char prop[PROPERTY_VALUE_MAX];
   2099         memset(prop, 0, sizeof(prop));
   2100         property_get("persist.camera.retro.number", prop, "0");
   2101         nBurstNum = atoi(prop);
   2102         if (nBurstNum < 0) {
   2103             nBurstNum = 0;
   2104         }
   2105     }
   2106 
   2107     set(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER, nBurstNum);
   2108 
   2109     m_nRetroBurstNum = nBurstNum;
   2110     LOGH("m_nRetroBurstNum = %d", m_nRetroBurstNum);
   2111     return NO_ERROR;
   2112 }
   2113 
   2114 /*===========================================================================
   2115  * FUNCTION   : setJpegQuality
   2116  *
   2117  * DESCRIPTION: set jpeg encpding quality 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::setJpegQuality(const QCameraParameters& params)
   2127 {
   2128     int32_t rc = NO_ERROR;
   2129     int quality = params.getInt(KEY_JPEG_QUALITY);
   2130     if (quality >= 0 && quality <= 100) {
   2131         set(KEY_JPEG_QUALITY, quality);
   2132     } else {
   2133         LOGE("Invalid jpeg quality=%d", quality);
   2134         rc = BAD_VALUE;
   2135     }
   2136 
   2137     quality = params.getInt(KEY_JPEG_THUMBNAIL_QUALITY);
   2138     if (quality >= 0 && quality <= 100) {
   2139         set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
   2140     } else {
   2141         LOGE("Invalid jpeg thumbnail quality=%d", quality);
   2142         rc = BAD_VALUE;
   2143     }
   2144     return rc;
   2145 }
   2146 
   2147 /*===========================================================================
   2148  * FUNCTION   : setOrientaion
   2149  *
   2150  * DESCRIPTION: set orientaion from user setting
   2151  *
   2152  * PARAMETERS :
   2153  *   @params  : user setting parameters
   2154  *
   2155  * RETURN     : int32_t type of status
   2156  *              NO_ERROR  -- success
   2157  *              none-zero failure code
   2158  *==========================================================================*/
   2159 int32_t QCameraParameters::setOrientation(const QCameraParameters& params)
   2160 {
   2161     const char *str = params.get(KEY_QC_ORIENTATION);
   2162 
   2163     if (str != NULL) {
   2164         if (strcmp(str, portrait) == 0 || strcmp(str, landscape) == 0) {
   2165             // Camera service needs this to decide if the preview frames and raw
   2166             // pictures should be rotated.
   2167             set(KEY_QC_ORIENTATION, str);
   2168         } else {
   2169             LOGE("Invalid orientation value: %s", str);
   2170             return BAD_VALUE;
   2171         }
   2172     }
   2173     return NO_ERROR;
   2174 }
   2175 
   2176 /*===========================================================================
   2177  * FUNCTION   : setAutoExposure
   2178  *
   2179  * DESCRIPTION: set auto exposure value 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::setAutoExposure(const QCameraParameters& params)
   2189 {
   2190     const char *str = params.get(KEY_QC_AUTO_EXPOSURE);
   2191     const char *prev_str = get(KEY_QC_AUTO_EXPOSURE);
   2192     if (str != NULL) {
   2193         if (prev_str == NULL ||
   2194             strcmp(str, prev_str) != 0) {
   2195             return setAutoExposure(str);
   2196         }
   2197     }
   2198     return NO_ERROR;
   2199 }
   2200 
   2201 /*===========================================================================
   2202  * FUNCTION   : setPreviewFpsRange
   2203  *
   2204  * DESCRIPTION: set preview FPS range from user setting
   2205  *
   2206  * PARAMETERS :
   2207  *   @params  : user setting parameters
   2208  *
   2209  * RETURN     : int32_t type of status
   2210  *              NO_ERROR  -- success
   2211  *              none-zero failure code
   2212  *==========================================================================*/
   2213 int32_t QCameraParameters::setPreviewFpsRange(const QCameraParameters& params)
   2214 {
   2215     int minFps,maxFps;
   2216     int prevMinFps, prevMaxFps, vidMinFps, vidMaxFps;
   2217     int rc = NO_ERROR;
   2218     bool found = false, updateNeeded = false;
   2219 
   2220     CameraParameters::getPreviewFpsRange(&prevMinFps, &prevMaxFps);
   2221     params.getPreviewFpsRange(&minFps, &maxFps);
   2222 
   2223     LOGH("FpsRange Values:(%d, %d)", prevMinFps, prevMaxFps);
   2224     LOGH("Requested FpsRange Values:(%d, %d)", minFps, maxFps);
   2225 
   2226     //first check if we need to change fps because of HFR mode change
   2227     updateNeeded = UpdateHFRFrameRate(params);
   2228     if (updateNeeded) {
   2229         m_bNeedRestart = true;
   2230         rc = setHighFrameRate(mHfrMode);
   2231         if (rc != NO_ERROR) goto end;
   2232     }
   2233     LOGH("UpdateHFRFrameRate %d", updateNeeded);
   2234 
   2235     vidMinFps = (int)m_hfrFpsRange.video_min_fps;
   2236     vidMaxFps = (int)m_hfrFpsRange.video_max_fps;
   2237 
   2238     if(minFps == prevMinFps && maxFps == prevMaxFps) {
   2239         if ( m_bFixedFrameRateSet ) {
   2240             minFps = params.getPreviewFrameRate() * 1000;
   2241             maxFps = params.getPreviewFrameRate() * 1000;
   2242             m_bFixedFrameRateSet = false;
   2243         } else if (!updateNeeded) {
   2244             LOGH("No change in FpsRange");
   2245             rc = NO_ERROR;
   2246             goto end;
   2247         }
   2248     }
   2249     for(size_t i = 0; i < m_pCapability->fps_ranges_tbl_cnt; i++) {
   2250         // if the value is in the supported list
   2251         if (minFps >= m_pCapability->fps_ranges_tbl[i].min_fps * 1000 &&
   2252                 maxFps <= m_pCapability->fps_ranges_tbl[i].max_fps * 1000) {
   2253             found = true;
   2254             LOGH("FPS i=%d : minFps = %d, maxFps = %d"
   2255                     " vidMinFps = %d, vidMaxFps = %d",
   2256                      i, minFps, maxFps,
   2257                     (int)m_hfrFpsRange.video_min_fps,
   2258                     (int)m_hfrFpsRange.video_max_fps);
   2259             if ((0.0f >= m_hfrFpsRange.video_min_fps) ||
   2260                     (0.0f >= m_hfrFpsRange.video_max_fps)) {
   2261                 vidMinFps = minFps;
   2262                 vidMaxFps = maxFps;
   2263             }
   2264             else {
   2265                 vidMinFps = (int)m_hfrFpsRange.video_min_fps;
   2266                 vidMaxFps = (int)m_hfrFpsRange.video_max_fps;
   2267             }
   2268 
   2269             setPreviewFpsRange(minFps, maxFps, vidMinFps, vidMaxFps);
   2270             break;
   2271         }
   2272     }
   2273     if(found == false){
   2274         LOGE("error: FPS range value not supported");
   2275         rc = BAD_VALUE;
   2276     }
   2277 end:
   2278     return rc;
   2279 }
   2280 
   2281 /*===========================================================================
   2282  * FUNCTION   : UpdateHFRFrameRate
   2283  *
   2284  * DESCRIPTION: set preview FPS range based on HFR setting
   2285  *
   2286  * PARAMETERS :
   2287  *   @params  : user setting parameters
   2288  *
   2289  * RETURN     : bool true/false
   2290  *                  true -if HAL needs to overwrite FPS range set by app, false otherwise.
   2291  *==========================================================================*/
   2292 
   2293 bool QCameraParameters::UpdateHFRFrameRate(const QCameraParameters& params)
   2294 {
   2295     bool updateNeeded = false;
   2296     int min_fps, max_fps;
   2297     int32_t hfrMode = CAM_HFR_MODE_OFF;
   2298     int32_t newHfrMode = CAM_HFR_MODE_OFF;
   2299 
   2300     int parm_minfps,parm_maxfps;
   2301     int prevMinFps, prevMaxFps;
   2302     CameraParameters::getPreviewFpsRange(&prevMinFps, &prevMaxFps);
   2303     params.getPreviewFpsRange(&parm_minfps, &parm_maxfps);
   2304     LOGH("CameraParameters - : minFps = %d, maxFps = %d ",
   2305                  prevMinFps, prevMaxFps);
   2306     LOGH("Requested params - : minFps = %d, maxFps = %d ",
   2307                  parm_minfps, parm_maxfps);
   2308 
   2309     const char *hfrStr = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
   2310     const char *hsrStr = params.get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
   2311 
   2312     const char *prev_hfrStr = CameraParameters::get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
   2313     const char *prev_hsrStr = CameraParameters::get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
   2314 
   2315     if ((hfrStr != NULL) && (prev_hfrStr != NULL) && strcmp(hfrStr, prev_hfrStr)) {
   2316         updateParamEntry(KEY_QC_VIDEO_HIGH_FRAME_RATE, hfrStr);
   2317     }
   2318 
   2319     if ((hsrStr != NULL) && (prev_hsrStr != NULL) && strcmp(hsrStr, prev_hsrStr)) {
   2320         updateParamEntry(KEY_QC_VIDEO_HIGH_SPEED_RECORDING, hsrStr);
   2321 
   2322     }
   2323 
   2324     // check if HFR is enabled
   2325     if ((hfrStr != NULL) && strcmp(hfrStr, "off")) {
   2326         hfrMode = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hfrStr);
   2327         if (NAME_NOT_FOUND != hfrMode) newHfrMode = hfrMode;
   2328     }
   2329     // check if HSR is enabled
   2330     else if ((hsrStr != NULL) && strcmp(hsrStr, "off")) {
   2331         hfrMode = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hsrStr);
   2332         if (NAME_NOT_FOUND != hfrMode) newHfrMode = hfrMode;
   2333     }
   2334     LOGH("prevHfrMode - %d, currentHfrMode = %d ",
   2335                  mHfrMode, newHfrMode);
   2336 
   2337     if (mHfrMode != newHfrMode) {
   2338         updateNeeded = true;
   2339         mHfrMode = newHfrMode;
   2340         switch (mHfrMode) {
   2341             case CAM_HFR_MODE_60FPS:
   2342                 min_fps = 60000;
   2343                 max_fps = 60000;
   2344                 break;
   2345             case CAM_HFR_MODE_90FPS:
   2346                 min_fps = 90000;
   2347                 max_fps = 90000;
   2348                 break;
   2349             case CAM_HFR_MODE_120FPS:
   2350                 min_fps = 120000;
   2351                 max_fps = 120000;
   2352                 break;
   2353             case CAM_HFR_MODE_150FPS:
   2354                 min_fps = 150000;
   2355                 max_fps = 150000;
   2356                 break;
   2357             case CAM_HFR_MODE_180FPS:
   2358                 min_fps = 180000;
   2359                 max_fps = 180000;
   2360                 break;
   2361             case CAM_HFR_MODE_210FPS:
   2362                 min_fps = 210000;
   2363                 max_fps = 210000;
   2364                 break;
   2365             case CAM_HFR_MODE_240FPS:
   2366                 min_fps = 240000;
   2367                 max_fps = 240000;
   2368                 break;
   2369             case CAM_HFR_MODE_480FPS:
   2370                 min_fps = 480000;
   2371                 max_fps = 480000;
   2372                 break;
   2373             case CAM_HFR_MODE_OFF:
   2374             default:
   2375                 // Set Video Fps to zero
   2376                 min_fps = 0;
   2377                 max_fps = 0;
   2378                 break;
   2379         }
   2380         m_hfrFpsRange.video_min_fps = (float)min_fps;
   2381         m_hfrFpsRange.video_max_fps = (float)max_fps;
   2382 
   2383         LOGH("HFR mode (%d) Set video FPS : minFps = %d, maxFps = %d ",
   2384                  mHfrMode, min_fps, max_fps);
   2385     }
   2386 
   2387     // Remember if HFR mode is ON
   2388     if ((mHfrMode > CAM_HFR_MODE_OFF) && (mHfrMode < CAM_HFR_MODE_MAX)) {
   2389         LOGH("HFR mode is ON");
   2390         m_bHfrMode = true;
   2391     } else {
   2392         m_hfrFpsRange.video_min_fps = 0;
   2393         m_hfrFpsRange.video_max_fps = 0;
   2394         m_bHfrMode = false;
   2395         LOGH("HFR mode is OFF");
   2396     }
   2397     m_hfrFpsRange.min_fps = (float)parm_minfps;
   2398     m_hfrFpsRange.max_fps = (float)parm_maxfps;
   2399 
   2400     if (m_bHfrMode && (mHfrMode > CAM_HFR_MODE_120FPS)
   2401             && (parm_maxfps != 0)) {
   2402         //Configure buffer batch count to use batch mode for higher fps
   2403         setBufBatchCount((int8_t)(m_hfrFpsRange.video_max_fps / parm_maxfps));
   2404     } else {
   2405         //Reset batch count and update KEY for encoder
   2406         setBufBatchCount(0);
   2407     }
   2408     return updateNeeded;
   2409 }
   2410 
   2411 /*===========================================================================
   2412  * FUNCTION   : setPreviewFrameRate
   2413  *
   2414  * DESCRIPTION: set preview frame rate from user setting
   2415  *
   2416  * PARAMETERS :
   2417  *   @params  : user setting parameters
   2418  *
   2419  * RETURN     : int32_t type of status
   2420  *              NO_ERROR  -- success
   2421  *              none-zero failure code
   2422  *==========================================================================*/
   2423 int32_t QCameraParameters::setPreviewFrameRate(const QCameraParameters& params)
   2424 {
   2425     const char *str = params.get(KEY_PREVIEW_FRAME_RATE);
   2426     const char *prev_str = get(KEY_PREVIEW_FRAME_RATE);
   2427 
   2428     if ( str ) {
   2429         if ( prev_str &&
   2430              strcmp(str, prev_str)) {
   2431             LOGD("Requested Fixed Frame Rate %s", str);
   2432             updateParamEntry(KEY_PREVIEW_FRAME_RATE, str);
   2433             m_bFixedFrameRateSet = true;
   2434         }
   2435     }
   2436     return NO_ERROR;
   2437 }
   2438 
   2439 /*===========================================================================
   2440  * FUNCTION   : setEffect
   2441  *
   2442  * DESCRIPTION: set effect value from user setting
   2443  *
   2444  * PARAMETERS :
   2445  *   @params  : user setting parameters
   2446  *
   2447  * RETURN     : int32_t type of status
   2448  *              NO_ERROR  -- success
   2449  *              none-zero failure code
   2450  *==========================================================================*/
   2451 int32_t QCameraParameters::setEffect(const QCameraParameters& params)
   2452 {
   2453     const char *str = params.get(KEY_EFFECT);
   2454     const char *prev_str = get(KEY_EFFECT);
   2455 
   2456     char prop[PROPERTY_VALUE_MAX];
   2457     memset(prop, 0, sizeof(prop));
   2458     property_get("persist.camera.effect", prop, "none");
   2459 
   2460     if (strcmp(prop, "none")) {
   2461         if ((prev_str == NULL) ||
   2462                 (strcmp(prop, prev_str) != 0) ||
   2463                 (m_bUpdateEffects == true)) {
   2464             m_bUpdateEffects = false;
   2465             return setEffect(prop);
   2466         }
   2467     } else if (str != NULL) {
   2468         if ((prev_str == NULL) ||
   2469                 (strcmp(str, prev_str) != 0) ||
   2470                 (m_bUpdateEffects == true)) {
   2471             m_bUpdateEffects = false;
   2472             return setEffect(str);
   2473         }
   2474     }
   2475     return NO_ERROR;
   2476 }
   2477 
   2478 /*===========================================================================
   2479  * FUNCTION   : setFocusMode
   2480  *
   2481  * DESCRIPTION: set focus mode from user setting
   2482  *
   2483  * PARAMETERS :
   2484  *   @params  : user setting parameters
   2485  *
   2486  * RETURN     : int32_t type of status
   2487  *              NO_ERROR  -- success
   2488  *              none-zero failure code
   2489  *==========================================================================*/
   2490 int32_t QCameraParameters::setFocusMode(const QCameraParameters& params)
   2491 {
   2492     const char *str = params.get(KEY_FOCUS_MODE);
   2493     const char *prev_str = get(KEY_FOCUS_MODE);
   2494     if (str != NULL) {
   2495         if (prev_str == NULL ||
   2496             strcmp(str, prev_str) != 0) {
   2497             return setFocusMode(str);
   2498         }
   2499     }
   2500     return NO_ERROR;
   2501 }
   2502 
   2503 /*===========================================================================
   2504  * FUNCTION   : setFocusPosition
   2505  *
   2506  * DESCRIPTION: set focus position from user setting
   2507  *
   2508  * PARAMETERS :
   2509  *   @params  : user setting parameters
   2510  *
   2511  * RETURN     : int32_t type of status
   2512  *              NO_ERROR  -- success
   2513  *              none-zero failure code
   2514  *==========================================================================*/
   2515 int32_t  QCameraParameters::setFocusPosition(const QCameraParameters& params)
   2516 {
   2517     const char *focus_str = params.get(KEY_FOCUS_MODE);
   2518     const char *prev_focus_str = get(KEY_FOCUS_MODE);
   2519 
   2520     if (NULL == focus_str) {
   2521         return NO_ERROR;
   2522     }
   2523 
   2524     LOGD("current focus mode: %s", focus_str);
   2525     if (strcmp(focus_str, FOCUS_MODE_MANUAL_POSITION)) {
   2526         LOGH(", dont set focus pos to back-end!");
   2527         return NO_ERROR;
   2528     }
   2529 
   2530     const char *pos = params.get(KEY_QC_MANUAL_FOCUS_POSITION);
   2531     const char *prev_pos = get(KEY_QC_MANUAL_FOCUS_POSITION);
   2532     const char *type = params.get(KEY_QC_MANUAL_FOCUS_POS_TYPE);
   2533     const char *prev_type = get(KEY_QC_MANUAL_FOCUS_POS_TYPE);
   2534 
   2535     if ((pos != NULL) && (type != NULL) && (focus_str != NULL)) {
   2536         if (prev_pos  == NULL || (strcmp(pos, prev_pos) != 0) ||
   2537             prev_type == NULL || (strcmp(type, prev_type) != 0) ||
   2538             prev_focus_str == NULL || (strcmp(focus_str, prev_focus_str) != 0)) {
   2539             return setFocusPosition(type, pos);
   2540         }
   2541     }
   2542 
   2543     return NO_ERROR;
   2544 }
   2545 
   2546 /*===========================================================================
   2547  * FUNCTION   : setBrightness
   2548  *
   2549  * DESCRIPTION: set brightness control value from user setting
   2550  *
   2551  * PARAMETERS :
   2552  *   @params  : user setting parameters
   2553  *
   2554  * RETURN     : int32_t type of status
   2555  *              NO_ERROR  -- success
   2556  *              none-zero failure code
   2557  *==========================================================================*/
   2558 int32_t QCameraParameters::setBrightness(const QCameraParameters& params)
   2559 {
   2560     int currentBrightness = getInt(KEY_QC_BRIGHTNESS);
   2561     int brightness = params.getInt(KEY_QC_BRIGHTNESS);
   2562 
   2563     if(params.get(KEY_QC_BRIGHTNESS) == NULL) {
   2564        LOGH("Brigtness not set by App ");
   2565        return NO_ERROR;
   2566     }
   2567     if (currentBrightness !=  brightness) {
   2568         if (brightness >= m_pCapability->brightness_ctrl.min_value &&
   2569             brightness <= m_pCapability->brightness_ctrl.max_value) {
   2570             LOGD("new brightness value : %d ", brightness);
   2571             return setBrightness(brightness);
   2572         } else {
   2573             LOGE("invalid value %d out of (%d, %d)",
   2574                    brightness,
   2575                   m_pCapability->brightness_ctrl.min_value,
   2576                   m_pCapability->brightness_ctrl.max_value);
   2577             return BAD_VALUE;
   2578         }
   2579     } else {
   2580         LOGD("No brightness value changed.");
   2581         return NO_ERROR;
   2582     }
   2583 }
   2584 
   2585 /*===========================================================================
   2586  * FUNCTION   : getBrightness
   2587  *
   2588  * DESCRIPTION: get brightness control value from user setting
   2589  *
   2590  * PARAMETERS :
   2591  *   @params  : user setting parameters
   2592  *
   2593  * RETURN     : int32_t type of status
   2594  *              NO_ERROR  -- success
   2595  *              none-zero failure code
   2596  *==========================================================================*/
   2597 int QCameraParameters::getBrightness()
   2598 {
   2599     return getInt(KEY_QC_BRIGHTNESS);
   2600 }
   2601 
   2602 /*===========================================================================
   2603  * FUNCTION   : setSharpness
   2604  *
   2605  * DESCRIPTION: set sharpness control value from user setting
   2606  *
   2607  * PARAMETERS :
   2608  *   @params  : user setting parameters
   2609  *
   2610  * RETURN     : int32_t type of status
   2611  *              NO_ERROR  -- success
   2612  *              none-zero failure code
   2613  *==========================================================================*/
   2614 int32_t QCameraParameters::setSharpness(const QCameraParameters& params)
   2615 {
   2616     int shaprness = params.getInt(KEY_QC_SHARPNESS);
   2617     int prev_sharp = getInt(KEY_QC_SHARPNESS);
   2618 
   2619     if(params.get(KEY_QC_SHARPNESS) == NULL) {
   2620        LOGH("Sharpness not set by App ");
   2621        return NO_ERROR;
   2622     }
   2623     if (prev_sharp !=  shaprness) {
   2624         if((shaprness >= m_pCapability->sharpness_ctrl.min_value) &&
   2625            (shaprness <= m_pCapability->sharpness_ctrl.max_value)) {
   2626             LOGD("new sharpness value : %d ", shaprness);
   2627             return setSharpness(shaprness);
   2628         } else {
   2629             LOGE("invalid value %d out of (%d, %d)",
   2630                    shaprness,
   2631                   m_pCapability->sharpness_ctrl.min_value,
   2632                   m_pCapability->sharpness_ctrl.max_value);
   2633             return BAD_VALUE;
   2634         }
   2635     } else {
   2636         LOGD("No value change in shaprness");
   2637         return NO_ERROR;
   2638     }
   2639 }
   2640 
   2641 /*===========================================================================
   2642  * FUNCTION   : setSkintoneEnahancement
   2643  *
   2644  * DESCRIPTION: set skin tone enhancement factor from user setting
   2645  *
   2646  * PARAMETERS :
   2647  *   @params  : user setting parameters
   2648  *
   2649  * RETURN     : int32_t type of status
   2650  *              NO_ERROR  -- success
   2651  *              none-zero failure code
   2652  *==========================================================================*/
   2653 int32_t QCameraParameters::setSkinToneEnhancement(const QCameraParameters& params)
   2654 {
   2655     int sceFactor = params.getInt(KEY_QC_SCE_FACTOR);
   2656     int prev_sceFactor = getInt(KEY_QC_SCE_FACTOR);
   2657 
   2658     if(params.get(KEY_QC_SCE_FACTOR) == NULL) {
   2659        LOGH("Skintone enhancement not set by App ");
   2660        return NO_ERROR;
   2661     }
   2662     if (prev_sceFactor != sceFactor) {
   2663         if((sceFactor >= m_pCapability->sce_ctrl.min_value) &&
   2664            (sceFactor <= m_pCapability->sce_ctrl.max_value)) {
   2665             LOGD("new Skintone Enhancement value : %d ", sceFactor);
   2666             return setSkinToneEnhancement(sceFactor);
   2667         } else {
   2668             LOGE("invalid value %d out of (%d, %d)",
   2669                    sceFactor,
   2670                   m_pCapability->sce_ctrl.min_value,
   2671                   m_pCapability->sce_ctrl.max_value);
   2672             return BAD_VALUE;
   2673         }
   2674     } else {
   2675         LOGD("No value change in skintone enhancement factor");
   2676         return NO_ERROR;
   2677     }
   2678 }
   2679 
   2680 /*===========================================================================
   2681  * FUNCTION   : setSaturation
   2682  *
   2683  * DESCRIPTION: set saturation control value from user setting
   2684  *
   2685  * PARAMETERS :
   2686  *   @params  : user setting parameters
   2687  *
   2688  * RETURN     : int32_t type of status
   2689  *              NO_ERROR  -- success
   2690  *              none-zero failure code
   2691  *==========================================================================*/
   2692 int32_t QCameraParameters::setSaturation(const QCameraParameters& params)
   2693 {
   2694     int saturation = params.getInt(KEY_QC_SATURATION);
   2695     int prev_sat = getInt(KEY_QC_SATURATION);
   2696 
   2697     if(params.get(KEY_QC_SATURATION) == NULL) {
   2698        LOGH("Saturation not set by App ");
   2699        return NO_ERROR;
   2700     }
   2701     if (prev_sat !=  saturation) {
   2702         if((saturation >= m_pCapability->saturation_ctrl.min_value) &&
   2703            (saturation <= m_pCapability->saturation_ctrl.max_value)) {
   2704             LOGD("new saturation value : %d ", saturation);
   2705             return setSaturation(saturation);
   2706         } else {
   2707             LOGE("invalid value %d out of (%d, %d)",
   2708                    saturation,
   2709                   m_pCapability->saturation_ctrl.min_value,
   2710                   m_pCapability->saturation_ctrl.max_value);
   2711             return BAD_VALUE;
   2712         }
   2713     } else {
   2714         LOGD("No value change in saturation factor");
   2715         return NO_ERROR;
   2716     }
   2717 }
   2718 
   2719 /*===========================================================================
   2720  * FUNCTION   : setContrast
   2721  *
   2722  * DESCRIPTION: set contrast control value from user setting
   2723  *
   2724  * PARAMETERS :
   2725  *   @params  : user setting parameters
   2726  *
   2727  * RETURN     : int32_t type of status
   2728  *              NO_ERROR  -- success
   2729  *              none-zero failure code
   2730  *==========================================================================*/
   2731 int32_t QCameraParameters::setContrast(const QCameraParameters& params)
   2732 {
   2733     int contrast = params.getInt(KEY_QC_CONTRAST);
   2734     int prev_contrast = getInt(KEY_QC_CONTRAST);
   2735 
   2736     if(params.get(KEY_QC_CONTRAST) == NULL) {
   2737        LOGH("Contrast not set by App ");
   2738        return NO_ERROR;
   2739     }
   2740     if (prev_contrast !=  contrast) {
   2741         if((contrast >= m_pCapability->contrast_ctrl.min_value) &&
   2742            (contrast <= m_pCapability->contrast_ctrl.max_value)) {
   2743             LOGD("new contrast value : %d ", contrast);
   2744             int32_t rc = setContrast(contrast);
   2745             return rc;
   2746         } else {
   2747             LOGE("invalid value %d out of (%d, %d)",
   2748                    contrast,
   2749                   m_pCapability->contrast_ctrl.min_value,
   2750                   m_pCapability->contrast_ctrl.max_value);
   2751             return BAD_VALUE;
   2752         }
   2753     } else {
   2754         LOGD("No value change in contrast");
   2755         return NO_ERROR;
   2756     }
   2757 }
   2758 
   2759 /*===========================================================================
   2760  * FUNCTION   : setExposureCompensation
   2761  *
   2762  * DESCRIPTION: set exposure compensation value from user setting
   2763  *
   2764  * PARAMETERS :
   2765  *   @params  : user setting parameters
   2766  *
   2767  * RETURN     : int32_t type of status
   2768  *              NO_ERROR  -- success
   2769  *              none-zero failure code
   2770  *==========================================================================*/
   2771 int32_t QCameraParameters::setExposureCompensation(const QCameraParameters & params)
   2772 {
   2773     int expComp = params.getInt(KEY_EXPOSURE_COMPENSATION);
   2774     int prev_expComp = getInt(KEY_EXPOSURE_COMPENSATION);
   2775 
   2776     if(params.get(KEY_EXPOSURE_COMPENSATION) == NULL) {
   2777        LOGH("Exposure compensation not set by App ");
   2778        return NO_ERROR;
   2779     }
   2780     if (prev_expComp != expComp) {
   2781         if((expComp >= m_pCapability->exposure_compensation_min) &&
   2782            (expComp <= m_pCapability->exposure_compensation_max)) {
   2783             LOGD("new Exposure Compensation value : %d ", expComp);
   2784             return setExposureCompensation(expComp);
   2785         } else {
   2786             LOGE("invalid value %d out of (%d, %d)",
   2787                    expComp,
   2788                   m_pCapability->exposure_compensation_min,
   2789                   m_pCapability->exposure_compensation_max);
   2790             return BAD_VALUE;
   2791         }
   2792     } else {
   2793         LOGD("No value change in Exposure Compensation");
   2794         return NO_ERROR;
   2795     }
   2796 }
   2797 
   2798 /*===========================================================================
   2799  * FUNCTION   : setWhiteBalance
   2800  *
   2801  * DESCRIPTION: set white balance value from user setting
   2802  *
   2803  * PARAMETERS :
   2804  *   @params  : user setting parameters
   2805  *
   2806  * RETURN     : int32_t type of status
   2807  *              NO_ERROR  -- success
   2808  *              none-zero failure code
   2809  *==========================================================================*/
   2810 int32_t QCameraParameters::setWhiteBalance(const QCameraParameters& params)
   2811 {
   2812     const char *str = params.get(KEY_WHITE_BALANCE);
   2813     const char *prev_str = get(KEY_WHITE_BALANCE);
   2814     if (str != NULL) {
   2815         if (prev_str == NULL ||
   2816             strcmp(str, prev_str) != 0) {
   2817             return setWhiteBalance(str);
   2818         }
   2819     }
   2820     return NO_ERROR;
   2821 }
   2822 
   2823 /*===========================================================================
   2824  * FUNCTION   : setManualWhiteBalance
   2825  *
   2826  * DESCRIPTION: set manual white balance from user setting
   2827  *
   2828  * PARAMETERS :
   2829  *   @params  : user setting parameters
   2830  *
   2831  * RETURN     : int32_t type of status
   2832  *              NO_ERROR  -- success
   2833  *              none-zero failure code
   2834  *==========================================================================*/
   2835 int32_t  QCameraParameters::setManualWhiteBalance(const QCameraParameters& params)
   2836 {
   2837     int32_t rc = NO_ERROR;
   2838     const char *wb_str = params.get(KEY_WHITE_BALANCE);
   2839     const char *prev_wb_str = get(KEY_WHITE_BALANCE);
   2840     LOGD("current wb mode: %s", wb_str);
   2841 
   2842     if (wb_str != NULL) {
   2843         if (strcmp(wb_str, WHITE_BALANCE_MANUAL)) {
   2844             LOGD("dont set cct to back-end.");
   2845             return NO_ERROR;
   2846         }
   2847     }
   2848 
   2849     const char *value = params.get(KEY_QC_MANUAL_WB_VALUE);
   2850     const char *prev_value = get(KEY_QC_MANUAL_WB_VALUE);
   2851     const char *type = params.get(KEY_QC_MANUAL_WB_TYPE);
   2852     const char *prev_type = get(KEY_QC_MANUAL_WB_TYPE);
   2853 
   2854     if ((value != NULL) && (type != NULL) && (wb_str != NULL)) {
   2855         if (prev_value  == NULL || (strcmp(value, prev_value) != 0) ||
   2856             prev_type == NULL || (strcmp(type, prev_type) != 0) ||
   2857             prev_wb_str == NULL || (strcmp(wb_str, prev_wb_str) != 0)) {
   2858             updateParamEntry(KEY_QC_MANUAL_WB_TYPE, type);
   2859             updateParamEntry(KEY_QC_MANUAL_WB_VALUE, value);
   2860             int32_t wb_type = atoi(type);
   2861             if (wb_type == CAM_MANUAL_WB_MODE_CCT) {
   2862                 rc = setWBManualCCT(value);
   2863             } else if (wb_type == CAM_MANUAL_WB_MODE_GAIN) {
   2864                 rc = setManualWBGains(value);
   2865             } else {
   2866                 rc = BAD_VALUE;
   2867             }
   2868         }
   2869     }
   2870     return rc;
   2871 }
   2872 
   2873 /*===========================================================================
   2874  * FUNCTION   : setAntibanding
   2875  *
   2876  * DESCRIPTION: set antibanding value from user setting
   2877  *
   2878  * PARAMETERS :
   2879  *   @params  : user setting parameters
   2880  *
   2881  * RETURN     : int32_t type of status
   2882  *              NO_ERROR  -- success
   2883  *              none-zero failure code
   2884  *==========================================================================*/
   2885 int32_t QCameraParameters::setAntibanding(const QCameraParameters& params)
   2886 {
   2887     const char *str = params.get(KEY_ANTIBANDING);
   2888     const char *prev_str = get(KEY_ANTIBANDING);
   2889     if (str != NULL) {
   2890         if (prev_str == NULL ||
   2891             strcmp(str, prev_str) != 0) {
   2892             return setAntibanding(str);
   2893         }
   2894     }
   2895     return NO_ERROR;
   2896 }
   2897 
   2898 /*===========================================================================
   2899  * FUNCTION   : setStatsDebugMask
   2900  *
   2901  * DESCRIPTION: get the value from persist file in Stats module that will
   2902  *              control funtionality in the module
   2903  *
   2904  * PARAMETERS : none
   2905  *
   2906  * RETURN     : int32_t type of status
   2907  *              NO_ERROR  -- success
   2908  *              none-zero failure code
   2909  *==========================================================================*/
   2910 int32_t QCameraParameters::setStatsDebugMask()
   2911 {
   2912     uint32_t mask = 0;
   2913     char value[PROPERTY_VALUE_MAX];
   2914 
   2915     property_get("persist.camera.stats.debug.mask", value, "0");
   2916     mask = (uint32_t)atoi(value);
   2917 
   2918     LOGH("ctrl mask :%d", mask);
   2919 
   2920     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_STATS_DEBUG_MASK, mask)) {
   2921         return BAD_VALUE;
   2922     }
   2923 
   2924     return NO_ERROR;
   2925 }
   2926 
   2927 /*===========================================================================
   2928  * FUNCTION   : setPAAF
   2929  *
   2930  * DESCRIPTION: get the value from persist file in Stats module that will
   2931  *              control the preview assisted AF in the module
   2932  *
   2933  * PARAMETERS : none
   2934  *
   2935  * RETURN     : int32_t type of status
   2936  *              NO_ERROR  -- success
   2937  *              none-zero failure code
   2938  *==========================================================================*/
   2939 int32_t QCameraParameters::setPAAF()
   2940 {
   2941     uint32_t paaf = 0;
   2942     char value[PROPERTY_VALUE_MAX];
   2943 
   2944     property_get("persist.camera.stats.af.paaf", value, "1");
   2945     paaf = (uint32_t)atoi(value);
   2946 
   2947     LOGH("PAAF is: %s", paaf ? "ON": "OFF");
   2948 
   2949     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_STATS_AF_PAAF, paaf)) {
   2950         return BAD_VALUE;
   2951     }
   2952 
   2953     return NO_ERROR;
   2954 }
   2955 
   2956 /*===========================================================================
   2957  * FUNCTION   : setSceneDetect
   2958  *
   2959  * DESCRIPTION: set scenen detect value from user setting
   2960  *
   2961  * PARAMETERS :
   2962  *   @params  : user setting parameters
   2963  *
   2964  * RETURN     : int32_t type of status
   2965  *              NO_ERROR  -- success
   2966  *              none-zero failure code
   2967  *==========================================================================*/
   2968 int32_t QCameraParameters::setSceneDetect(const QCameraParameters& params)
   2969 {
   2970     const char *str = params.get(KEY_QC_SCENE_DETECT);
   2971     const char *prev_str = get(KEY_QC_SCENE_DETECT);
   2972     if (str != NULL) {
   2973         if (prev_str == NULL ||
   2974             strcmp(str, prev_str) != 0) {
   2975             return setSceneDetect(str);
   2976         }
   2977     }
   2978     return NO_ERROR;
   2979 }
   2980 
   2981 /*===========================================================================
   2982  * FUNCTION   : setVideoHDR
   2983  *
   2984  * DESCRIPTION: set video HDR value from user setting
   2985  *
   2986  * PARAMETERS :
   2987  *   @params  : user setting parameters
   2988  *
   2989  * RETURN     : int32_t type of status
   2990  *              NO_ERROR  -- success
   2991  *              none-zero failure code
   2992  *==========================================================================*/
   2993 int32_t QCameraParameters::setVideoHDR(const QCameraParameters& params)
   2994 {
   2995     const char *str = params.get(KEY_QC_VIDEO_HDR);
   2996     const char *prev_str = get(KEY_QC_VIDEO_HDR);
   2997     if (str != NULL) {
   2998         if (prev_str == NULL ||
   2999             strcmp(str, prev_str) != 0) {
   3000             return setVideoHDR(str);
   3001         }
   3002     }
   3003     return NO_ERROR;
   3004 }
   3005 
   3006 /*===========================================================================
   3007  * FUNCTION   : setVtEnable
   3008  *
   3009  * DESCRIPTION: set vt Time Stamp enable from user setting
   3010  *
   3011  * PARAMETERS :
   3012  *   @params  : user setting parameters
   3013  *
   3014  * RETURN     : int32_t type of status
   3015  *              NO_ERROR  -- success
   3016  *              none-zero failure code
   3017  *==========================================================================*/
   3018 int32_t QCameraParameters::setVtEnable(const QCameraParameters& params)
   3019 {
   3020     const char *str = params.get(KEY_QC_VT_ENABLE);
   3021     const char *prev_str = get(KEY_QC_VT_ENABLE);
   3022     if (str != NULL) {
   3023         if (prev_str == NULL ||
   3024             strcmp(str, prev_str) != 0) {
   3025             return setVtEnable(str);
   3026         }
   3027     }
   3028     return NO_ERROR;
   3029 }
   3030 
   3031 /*===========================================================================
   3032  * FUNCTION   : setFaceRecognition
   3033  *
   3034  * DESCRIPTION: set face recognition mode from user setting
   3035  *
   3036  * PARAMETERS :
   3037  *   @params  : user setting parameters
   3038  *
   3039  * RETURN     : int32_t type of status
   3040  *              NO_ERROR  -- success
   3041  *              none-zero failure code
   3042  *==========================================================================*/
   3043 int32_t QCameraParameters::setFaceRecognition(const QCameraParameters& params)
   3044 {
   3045     const char *str = params.get(KEY_QC_FACE_RECOGNITION);
   3046     const char *prev_str = get(KEY_QC_FACE_RECOGNITION);
   3047     if (str != NULL) {
   3048         if (prev_str == NULL ||
   3049             strcmp(str, prev_str) != 0) {
   3050             uint32_t maxFaces = (uint32_t)params.getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
   3051             return setFaceRecognition(str, maxFaces);
   3052         }
   3053     }
   3054     return NO_ERROR;
   3055 }
   3056 
   3057 /*===========================================================================
   3058  * FUNCTION   : setZoom
   3059  *
   3060  * DESCRIPTION: set zoom value from user setting
   3061  *
   3062  * PARAMETERS :
   3063  *   @params  : user setting parameters
   3064  *
   3065  * RETURN     : int32_t type of status
   3066  *              NO_ERROR  -- success
   3067  *              none-zero failure code
   3068  *==========================================================================*/
   3069 int32_t QCameraParameters::setZoom(const QCameraParameters& params)
   3070 {
   3071     if ((m_pCapability->zoom_supported == 0 ||
   3072          m_pCapability->zoom_ratio_tbl_cnt == 0)) {
   3073         LOGH("no zoom support");
   3074         return NO_ERROR;
   3075     }
   3076 
   3077     int zoomLevel = params.getInt(KEY_ZOOM);
   3078     mParmZoomLevel = zoomLevel;
   3079     if ((zoomLevel < 0) || (zoomLevel >= (int)m_pCapability->zoom_ratio_tbl_cnt)) {
   3080         LOGE("invalid value %d out of (%d, %d)",
   3081                zoomLevel,
   3082               0, m_pCapability->zoom_ratio_tbl_cnt-1);
   3083         return BAD_VALUE;
   3084     }
   3085 
   3086     int prevZoomLevel = getInt(KEY_ZOOM);
   3087     if (prevZoomLevel == zoomLevel) {
   3088         LOGD("No value change in zoom %d %d", prevZoomLevel, zoomLevel);
   3089         return NO_ERROR;
   3090     }
   3091 
   3092     return setZoom(zoomLevel);
   3093 }
   3094 
   3095 /*===========================================================================
   3096  * FUNCTION   : setISOValue
   3097  *
   3098  * DESCRIPTION: set ISO value from user setting
   3099  *
   3100  * PARAMETERS :
   3101  *   @params  : user setting parameters
   3102  *
   3103  * RETURN     : int32_t type of status
   3104  *              NO_ERROR  -- success
   3105  *              none-zero failure code
   3106  *==========================================================================*/
   3107 int32_t  QCameraParameters::setISOValue(const QCameraParameters& params)
   3108 {
   3109     const char *str = params.get(KEY_QC_ISO_MODE);
   3110     const char *prev_str = get(KEY_QC_ISO_MODE);
   3111 
   3112     if(getManualCaptureMode()) {
   3113         char iso_val[PROPERTY_VALUE_MAX];
   3114 
   3115         property_get("persist.camera.iso", iso_val, "");
   3116         if (strlen(iso_val) > 0) {
   3117             if (prev_str == NULL ||
   3118                     strcmp(iso_val, prev_str) != 0) {
   3119                 return setISOValue(iso_val);
   3120             }
   3121         }
   3122     } else if (str != NULL) {
   3123         if (prev_str == NULL ||
   3124             strcmp(str, prev_str) != 0) {
   3125             return setISOValue(str);
   3126         }
   3127     }
   3128     return NO_ERROR;
   3129 }
   3130 
   3131 /*===========================================================================
   3132  * FUNCTION   : setContinuousISO
   3133  *
   3134  * DESCRIPTION: set ISO value from user setting
   3135  *
   3136  * PARAMETERS :
   3137  *   @params  : user setting parameters
   3138  *
   3139  * RETURN     : int32_t type of status
   3140  *              NO_ERROR  -- success
   3141  *              none-zero failure code
   3142  *==========================================================================*/
   3143 int32_t  QCameraParameters::setContinuousISO(const char *isoValue)
   3144 {
   3145     char iso[PROPERTY_VALUE_MAX];
   3146     int32_t continous_iso = 0;
   3147 
   3148     // Check if continuous ISO is set through setproperty
   3149     property_get("persist.camera.continuous.iso", iso, "");
   3150     if (strlen(iso) > 0) {
   3151         continous_iso = atoi(iso);
   3152     } else {
   3153         continous_iso = atoi(isoValue);
   3154     }
   3155 
   3156     if ((continous_iso >= 0) &&
   3157             (continous_iso <= m_pCapability->sensitivity_range.max_sensitivity)) {
   3158         LOGH("Setting continuous ISO value %d", continous_iso);
   3159         updateParamEntry(KEY_QC_CONTINUOUS_ISO, isoValue);
   3160 
   3161         cam_intf_parm_manual_3a_t iso_settings;
   3162         memset(&iso_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
   3163         iso_settings.previewOnly = FALSE;
   3164         iso_settings.value = continous_iso;
   3165         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ISO, iso_settings)) {
   3166             return BAD_VALUE;
   3167         }
   3168         return NO_ERROR;
   3169     }
   3170     LOGE("Invalid iso value: %d", continous_iso);
   3171     return BAD_VALUE;
   3172 }
   3173 
   3174 /*===========================================================================
   3175  * FUNCTION   : setExposureTime
   3176  *
   3177  * DESCRIPTION: set exposure time from user setting
   3178  *
   3179  * PARAMETERS :
   3180  *   @params  : user setting parameters
   3181  *
   3182  * RETURN     : int32_t type of status
   3183  *              NO_ERROR  -- success
   3184  *              none-zero failure code
   3185  *==========================================================================*/
   3186 int32_t  QCameraParameters::setExposureTime(const QCameraParameters& params)
   3187 {
   3188     const char *str = params.get(KEY_QC_EXPOSURE_TIME);
   3189     const char *prev_str = get(KEY_QC_EXPOSURE_TIME);
   3190     if (str != NULL) {
   3191         if (prev_str == NULL ||
   3192                 strcmp(str, prev_str) != 0) {
   3193             return setExposureTime(str);
   3194         }
   3195     } else if(getManualCaptureMode()) {
   3196         char expTime[PROPERTY_VALUE_MAX];
   3197 
   3198         property_get("persist.camera.exposure.time", expTime, "");
   3199         if (strlen(expTime) > 0) {
   3200             if (prev_str == NULL ||
   3201                     strcmp(expTime, prev_str) != 0) {
   3202                 return setExposureTime(expTime);
   3203             }
   3204         }
   3205     }
   3206 
   3207     return NO_ERROR;
   3208 }
   3209 
   3210 /*===========================================================================
   3211  * FUNCTION   : setVideoRotation
   3212  *
   3213  * DESCRIPTION: set rotation value from user setting
   3214  *
   3215  * PARAMETERS :
   3216  *   @params  : user setting parameters
   3217  *
   3218  * RETURN     : int32_t type of status
   3219  *              NO_ERROR  -- success
   3220  *              none-zero failure code
   3221  *==========================================================================*/
   3222 int32_t QCameraParameters::setVideoRotation(const QCameraParameters& params)
   3223 {
   3224     const char *str = params.get(KEY_QC_VIDEO_ROTATION);
   3225     if(str != NULL) {
   3226         int value = lookupAttr(VIDEO_ROTATION_MODES_MAP,
   3227                 PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP), str);
   3228         if (value != NAME_NOT_FOUND) {
   3229             updateParamEntry(KEY_QC_VIDEO_ROTATION, str);
   3230             LOGL("setVideoRotation:   %d: ", str, value);
   3231         } else {
   3232             LOGE("Invalid rotation value: %d", value);
   3233             return BAD_VALUE;
   3234         }
   3235 
   3236     }
   3237     return NO_ERROR;
   3238 }
   3239 
   3240 /*===========================================================================
   3241  * FUNCTION   : setRotation
   3242  *
   3243  * DESCRIPTION: set rotation value from user setting
   3244  *
   3245  * PARAMETERS :
   3246  *   @params  : user setting parameters
   3247  *
   3248  * RETURN     : int32_t type of status
   3249  *              NO_ERROR  -- success
   3250  *              none-zero failure code
   3251  *==========================================================================*/
   3252 int32_t QCameraParameters::setRotation(const QCameraParameters& params)
   3253 {
   3254     int32_t rotation = params.getInt(KEY_ROTATION);
   3255     if (rotation != -1) {
   3256         if (rotation == 0 || rotation == 90 ||
   3257             rotation == 180 || rotation == 270) {
   3258             set(KEY_ROTATION, rotation);
   3259 
   3260             ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_META_JPEG_ORIENTATION,
   3261                     rotation);
   3262             mRotation = rotation;
   3263         } else {
   3264             LOGE("Invalid rotation value: %d", rotation);
   3265             return BAD_VALUE;
   3266         }
   3267     }
   3268     return NO_ERROR;
   3269 }
   3270 
   3271 /*===========================================================================
   3272  * FUNCTION   : setFlash
   3273  *
   3274  * DESCRIPTION: set flash mode from user setting
   3275  *
   3276  * PARAMETERS :
   3277  *   @params  : user setting parameters
   3278  *
   3279  * RETURN     : int32_t type of status
   3280  *              NO_ERROR  -- success
   3281  *              none-zero failure code
   3282  *==========================================================================*/
   3283 int32_t QCameraParameters::setFlash(const QCameraParameters& params)
   3284 {
   3285     const char *str = params.get(KEY_FLASH_MODE);
   3286     const char *prev_str = get(KEY_FLASH_MODE);
   3287     if (str != NULL) {
   3288         if (prev_str == NULL ||
   3289             strcmp(str, prev_str) != 0) {
   3290             return setFlash(str);
   3291         }
   3292     }
   3293     return NO_ERROR;
   3294 }
   3295 
   3296 /*===========================================================================
   3297  * FUNCTION   : setAecLock
   3298  *
   3299  * DESCRIPTION: set AEC lock value from user setting
   3300  *
   3301  * PARAMETERS :
   3302  *   @params  : user setting parameters
   3303  *
   3304  * RETURN     : int32_t type of status
   3305  *              NO_ERROR  -- success
   3306  *              none-zero failure code
   3307  *==========================================================================*/
   3308 int32_t QCameraParameters::setAecLock(const QCameraParameters& params)
   3309 {
   3310     const char *str = params.get(KEY_AUTO_EXPOSURE_LOCK);
   3311     const char *prev_str = get(KEY_AUTO_EXPOSURE_LOCK);
   3312     if (str != NULL) {
   3313         if (prev_str == NULL ||
   3314             strcmp(str, prev_str) != 0) {
   3315             return setAecLock(str);
   3316         }
   3317     }
   3318     return NO_ERROR;
   3319 }
   3320 
   3321 /*===========================================================================
   3322  * FUNCTION   : setAwbLock
   3323  *
   3324  * DESCRIPTION: set AWB lock from user setting
   3325  *
   3326  * PARAMETERS :
   3327  *   @params  : user setting parameters
   3328  *
   3329  * RETURN     : int32_t type of status
   3330  *              NO_ERROR  -- success
   3331  *              none-zero failure code
   3332  *==========================================================================*/
   3333 int32_t QCameraParameters::setAwbLock(const QCameraParameters& params)
   3334 {
   3335     const char *str = params.get(KEY_AUTO_WHITEBALANCE_LOCK);
   3336     const char *prev_str = get(KEY_AUTO_WHITEBALANCE_LOCK);
   3337     if (str != NULL) {
   3338         if (prev_str == NULL ||
   3339             strcmp(str, prev_str) != 0) {
   3340             return setAwbLock(str);
   3341         }
   3342     }
   3343     return NO_ERROR;
   3344 }
   3345 
   3346 /*===========================================================================
   3347  * FUNCTION   : setAutoHDR
   3348  *
   3349  * DESCRIPTION: Enable/disable auto HDR
   3350  *
   3351  * PARAMETERS :
   3352  *   @params  : user setting parameters
   3353  *
   3354  * RETURN     : int32_t type of status
   3355  *              NO_ERROR  -- success
   3356  *              none-zero failure code
   3357  *==========================================================================*/
   3358 int32_t QCameraParameters::setAutoHDR(const QCameraParameters& params)
   3359 {
   3360     const char *str = params.get(KEY_QC_AUTO_HDR_ENABLE);
   3361     const char *prev_str = get(KEY_QC_AUTO_HDR_ENABLE);
   3362     char prop[PROPERTY_VALUE_MAX];
   3363 
   3364     memset(prop, 0, sizeof(prop));
   3365     property_get("persist.camera.auto.hdr.enable", prop, VALUE_DISABLE);
   3366     if (str != NULL) {
   3367        if (prev_str == NULL ||
   3368            strcmp(str, prev_str) != 0) {
   3369            LOGH("Auto HDR set to: %s", str);
   3370            return updateParamEntry(KEY_QC_AUTO_HDR_ENABLE, str);
   3371        }
   3372     } else {
   3373        if (prev_str == NULL ||
   3374            strcmp(prev_str, prop) != 0 ) {
   3375            LOGH("Auto HDR set to: %s", prop);
   3376            updateParamEntry(KEY_QC_AUTO_HDR_ENABLE, prop);
   3377        }
   3378     }
   3379 
   3380        return NO_ERROR;
   3381 }
   3382 
   3383 /*===========================================================================
   3384 * FUNCTION   : isAutoHDREnabled
   3385 *
   3386 * DESCRIPTION: Query auto HDR status
   3387 *
   3388 * PARAMETERS : None
   3389 *
   3390 * RETURN     : bool true/false
   3391 *==========================================================================*/
   3392 bool QCameraParameters::isAutoHDREnabled()
   3393 {
   3394     const char *str = get(KEY_QC_AUTO_HDR_ENABLE);
   3395     if (str != NULL) {
   3396         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   3397                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
   3398         if (value == NAME_NOT_FOUND) {
   3399             LOGE("Invalid Auto HDR value %s", str);
   3400             return false;
   3401         }
   3402 
   3403         LOGH("Auto HDR status is: %d", value);
   3404         return value ? true : false;
   3405     }
   3406 
   3407     LOGH("Auto HDR status not set!");
   3408     return false;
   3409 }
   3410 
   3411 /*===========================================================================
   3412  * FUNCTION   : setMCEValue
   3413  *
   3414  * DESCRIPTION: set memory color enhancement value from user setting
   3415  *
   3416  * PARAMETERS :
   3417  *   @params  : user setting parameters
   3418  *
   3419  * RETURN     : int32_t type of status
   3420  *              NO_ERROR  -- success
   3421  *              none-zero failure code
   3422  *==========================================================================*/
   3423 int32_t QCameraParameters::setMCEValue(const QCameraParameters& params)
   3424 {
   3425     const char *str = params.get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
   3426     const char *prev_str = get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
   3427     if (str != NULL) {
   3428         if (prev_str == NULL ||
   3429             strcmp(str, prev_str) != 0) {
   3430             return setMCEValue(str);
   3431         }
   3432     }
   3433     return NO_ERROR;
   3434 }
   3435 
   3436 /*===========================================================================
   3437  * FUNCTION   : setDISValue
   3438  *
   3439  * DESCRIPTION: enable/disable DIS from user setting
   3440  *
   3441  * PARAMETERS :
   3442  *   @params  : user setting parameters
   3443  *
   3444  * RETURN     : int32_t type of status
   3445  *              NO_ERROR  -- success
   3446  *              none-zero failure code
   3447  *==========================================================================*/
   3448 int32_t QCameraParameters::setDISValue(const QCameraParameters& params)
   3449 {
   3450     const char *str = params.get(KEY_QC_DIS);
   3451     const char *prev_str = get(KEY_QC_DIS);
   3452     if (str != NULL) {
   3453         if (prev_str == NULL ||
   3454             strcmp(str, prev_str) != 0) {
   3455             return setDISValue(str);
   3456         }
   3457     }
   3458     return NO_ERROR;
   3459 }
   3460 
   3461 /*===========================================================================
   3462  * FUNCTION   : setLensShadeValue
   3463  *
   3464  * DESCRIPTION: set lens shade value from user setting
   3465  *
   3466  * PARAMETERS :
   3467  *   @params  : user setting parameters
   3468  *
   3469  * RETURN     : int32_t type of status
   3470  *              NO_ERROR  -- success
   3471  *              none-zero failure code
   3472  *==========================================================================*/
   3473 int32_t QCameraParameters::setLensShadeValue(const QCameraParameters& params)
   3474 {
   3475     const char *str = params.get(KEY_QC_LENSSHADE);
   3476     const char *prev_str = get(KEY_QC_LENSSHADE);
   3477     if (str != NULL) {
   3478         if (prev_str == NULL ||
   3479             strcmp(str, prev_str) != 0) {
   3480             return setLensShadeValue(str);
   3481         }
   3482     }
   3483     return NO_ERROR;
   3484 }
   3485 
   3486 /*===========================================================================
   3487  * FUNCTION   : setFocusAreas
   3488  *
   3489  * DESCRIPTION: set focus areas from user setting
   3490  *
   3491  * PARAMETERS :
   3492  *   @params  : user setting parameters
   3493  *
   3494  * RETURN     : int32_t type of status
   3495  *              NO_ERROR  -- success
   3496  *              none-zero failure code
   3497  *==========================================================================*/
   3498 int32_t QCameraParameters::setFocusAreas(const QCameraParameters& params)
   3499 {
   3500     const char *str = params.get(KEY_FOCUS_AREAS);
   3501 
   3502     if (getRelatedCamSyncInfo()->mode == CAM_MODE_SECONDARY) {
   3503         // Ignore focus areas for secondary camera
   3504         LOGH("Ignore focus areas for secondary camera!! ");
   3505         return NO_ERROR;
   3506     }
   3507     if (str != NULL) {
   3508         int max_num_af_areas = getInt(KEY_MAX_NUM_FOCUS_AREAS);
   3509         if(max_num_af_areas == 0) {
   3510             LOGE("max num of AF area is 0, cannot set focus areas");
   3511             return BAD_VALUE;
   3512         }
   3513 
   3514         const char *prev_str = get(KEY_FOCUS_AREAS);
   3515         if (prev_str == NULL ||
   3516             strcmp(str, prev_str) != 0) {
   3517             return setFocusAreas(str);
   3518         }
   3519     }
   3520     return NO_ERROR;
   3521 }
   3522 
   3523 /*===========================================================================
   3524  * FUNCTION   : setMeteringAreas
   3525  *
   3526  * DESCRIPTION: set metering areas from user setting
   3527  *
   3528  * PARAMETERS :
   3529  *   @params  : user setting parameters
   3530  *
   3531  * RETURN     : int32_t type of status
   3532  *              NO_ERROR  -- success
   3533  *              none-zero failure code
   3534  *==========================================================================*/
   3535 int32_t QCameraParameters::setMeteringAreas(const QCameraParameters& params)
   3536 {
   3537     const char *str = params.get(KEY_METERING_AREAS);
   3538     if (str != NULL) {
   3539         int max_num_mtr_areas = getInt(KEY_MAX_NUM_METERING_AREAS);
   3540         if(max_num_mtr_areas == 0) {
   3541             LOGE("max num of metering areas is 0, cannot set focus areas");
   3542             return BAD_VALUE;
   3543         }
   3544 
   3545         const char *prev_str = get(KEY_METERING_AREAS);
   3546         if (prev_str == NULL ||
   3547             strcmp(str, prev_str) != 0 ||
   3548             (m_bNeedRestart == true)) {
   3549             return setMeteringAreas(str);
   3550         }
   3551     }
   3552     return NO_ERROR;
   3553 }
   3554 
   3555 /*===========================================================================
   3556  * FUNCTION   : setSceneMode
   3557  *
   3558  * DESCRIPTION: set scenen mode from user setting
   3559  *
   3560  * PARAMETERS :
   3561  *   @params  : user setting parameters
   3562  *
   3563  * RETURN     : int32_t type of status
   3564  *              NO_ERROR  -- success
   3565  *              none-zero failure code
   3566  *==========================================================================*/
   3567 int32_t QCameraParameters::setSceneMode(const QCameraParameters& params)
   3568 {
   3569     const char *str = params.get(KEY_SCENE_MODE);
   3570     const char *prev_str = get(KEY_SCENE_MODE);
   3571     LOGH("str - %s, prev_str - %s", str, prev_str);
   3572 
   3573     // HDR & Recording are mutually exclusive and so disable HDR if recording hint is set
   3574     if (m_bRecordingHint_new && m_bHDREnabled) {
   3575         LOGH("Disable the HDR and set it to Auto");
   3576         str = SCENE_MODE_AUTO;
   3577         m_bLocalHDREnabled = true;
   3578     } else if (!m_bRecordingHint_new && m_bLocalHDREnabled) {
   3579         LOGH("Restore the HDR from Auto scene mode");
   3580         str = SCENE_MODE_HDR;
   3581         m_bLocalHDREnabled = false;
   3582     }
   3583 
   3584     if (str != NULL) {
   3585         if (prev_str == NULL ||
   3586             strcmp(str, prev_str) != 0) {
   3587 
   3588             if(strcmp(str, SCENE_MODE_AUTO) == 0) {
   3589                 m_bSceneTransitionAuto = true;
   3590             }
   3591             if (strcmp(str, SCENE_MODE_HDR) == 0) {
   3592 
   3593                 // If HDR is set from client  and the feature is not enabled in the backend, ignore it.
   3594                 if (m_bHDRModeSensor && isSupportedSensorHdrSize(params)) {
   3595                     m_bSensorHDREnabled = true;
   3596                     LOGH("Sensor HDR mode Enabled");
   3597                 } else {
   3598                     m_bHDREnabled = true;
   3599                     LOGH("S/W HDR Enabled");
   3600                 }
   3601             } else {
   3602                 m_bHDREnabled = false;
   3603                 if (m_bSensorHDREnabled) {
   3604                     m_bSensorHDREnabled = false;
   3605                     m_bNeedRestart = true;
   3606                     setSensorSnapshotHDR("off");
   3607                 }
   3608             }
   3609 
   3610             if (m_bSensorHDREnabled) {
   3611                 setSensorSnapshotHDR("on");
   3612                 m_bNeedRestart = true;
   3613             } else if ((m_bHDREnabled) ||
   3614                 ((prev_str != NULL) && (strcmp(prev_str, SCENE_MODE_HDR) == 0))) {
   3615                 LOGH("scene mode changed between HDR and non-HDR, need restart");
   3616                 m_bNeedRestart = true;
   3617             }
   3618 
   3619             return setSceneMode(str);
   3620         }
   3621     }
   3622     return NO_ERROR;
   3623 }
   3624 
   3625 /*===========================================================================
   3626  * FUNCTION   : setSelectableZoneAf
   3627  *
   3628  * DESCRIPTION: set selectable zone auto focus value from user setting
   3629  *
   3630  * PARAMETERS :
   3631  *   @params  : user setting parameters
   3632  *
   3633  * RETURN     : int32_t type of status
   3634  *              NO_ERROR  -- success
   3635  *              none-zero failure code
   3636  *==========================================================================*/
   3637 int32_t QCameraParameters::setSelectableZoneAf(const QCameraParameters& params)
   3638 {
   3639     const char *str = params.get(KEY_QC_SELECTABLE_ZONE_AF);
   3640     const char *prev_str = get(KEY_QC_SELECTABLE_ZONE_AF);
   3641     if (str != NULL) {
   3642         if (prev_str == NULL ||
   3643             strcmp(str, prev_str) != 0) {
   3644             return setSelectableZoneAf(str);
   3645         }
   3646     }
   3647     return NO_ERROR;
   3648 }
   3649 
   3650 /*===========================================================================
   3651  * FUNCTION   : setAEBracket
   3652  *
   3653  * DESCRIPTION: set AE bracket from user setting
   3654  *
   3655  * PARAMETERS :
   3656  *   @params  : user setting parameters
   3657  *
   3658  * RETURN     : int32_t type of status
   3659  *              NO_ERROR  -- success
   3660  *              none-zero failure code
   3661  *==========================================================================*/
   3662 int32_t QCameraParameters::setAEBracket(const QCameraParameters& params)
   3663 {
   3664     if (isHDREnabled()) {
   3665         LOGH("scene mode is HDR, overwrite AE bracket setting to off");
   3666         return setAEBracket(AE_BRACKET_OFF);
   3667     }
   3668 
   3669     const char *expStr = params.get(KEY_QC_CAPTURE_BURST_EXPOSURE);
   3670     if (NULL != expStr && strlen(expStr) > 0) {
   3671         set(KEY_QC_CAPTURE_BURST_EXPOSURE, expStr);
   3672     } else {
   3673         char prop[PROPERTY_VALUE_MAX];
   3674         memset(prop, 0, sizeof(prop));
   3675         property_get("persist.capture.burst.exposures", prop, "");
   3676         if (strlen(prop) > 0) {
   3677             set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
   3678         } else {
   3679             remove(KEY_QC_CAPTURE_BURST_EXPOSURE);
   3680         }
   3681     }
   3682 
   3683     const char *str = params.get(KEY_QC_AE_BRACKET_HDR);
   3684     const char *prev_str = get(KEY_QC_AE_BRACKET_HDR);
   3685     if (str != NULL) {
   3686         if (prev_str == NULL ||
   3687             strcmp(str, prev_str) != 0) {
   3688             return setAEBracket(str);
   3689         }
   3690     }
   3691     return NO_ERROR;
   3692 }
   3693 
   3694 /*===========================================================================
   3695  * FUNCTION   : setAFBracket
   3696  *
   3697  * DESCRIPTION: set AF bracket from user setting
   3698  *
   3699  * PARAMETERS :
   3700  *   @params  : user setting parameters
   3701  *
   3702  * RETURN     : int32_t type of status
   3703  *              NO_ERROR  -- success
   3704  *              none-zero failure code
   3705  *==========================================================================*/
   3706 int32_t QCameraParameters::setAFBracket(const QCameraParameters& params)
   3707 {
   3708     if ((m_pCapability->qcom_supported_feature_mask &
   3709             (CAM_QCOM_FEATURE_REFOCUS | CAM_QCOM_FEATURE_UBIFOCUS)) == 0) {
   3710         LOGH("AF Bracketing is not supported");
   3711         return NO_ERROR;
   3712     }
   3713     const char *str = params.get(KEY_QC_AF_BRACKET);
   3714     const char *prev_str = get(KEY_QC_AF_BRACKET);
   3715     LOGH("str =%s & prev_str =%s", str, prev_str);
   3716     if (str != NULL) {
   3717         if (prev_str == NULL ||
   3718             strcmp(str, prev_str) != 0) {
   3719             m_bNeedRestart = true;
   3720             return setAFBracket(str);
   3721         }
   3722     }
   3723     return NO_ERROR;
   3724 }
   3725 
   3726 /*===========================================================================
   3727  * FUNCTION   : setReFocus
   3728  *
   3729  * DESCRIPTION: set refocus from user setting
   3730  *
   3731  * PARAMETERS :
   3732  *   @params  : user setting parameters
   3733  *
   3734  * RETURN     : int32_t type of status
   3735  *              NO_ERROR  -- success
   3736  *              none-zero failure code
   3737  *==========================================================================*/
   3738 int32_t QCameraParameters::setReFocus(const QCameraParameters& params)
   3739 {
   3740     if ((m_pCapability->qcom_supported_feature_mask &
   3741             (CAM_QCOM_FEATURE_REFOCUS | CAM_QCOM_FEATURE_UBIFOCUS)) == 0) {
   3742         LOGD("AF Bracketing is not supported");
   3743         return NO_ERROR;
   3744     }
   3745     const char *str = params.get(KEY_QC_RE_FOCUS);
   3746     const char *prev_str = get(KEY_QC_RE_FOCUS);
   3747     LOGH("str =%s & prev_str =%s", str, prev_str);
   3748     if (str != NULL) {
   3749         if (prev_str == NULL ||
   3750             strcmp(str, prev_str) != 0) {
   3751             m_bNeedRestart = true;
   3752             return setReFocus(str);
   3753         }
   3754     }
   3755     return NO_ERROR;
   3756 }
   3757 
   3758 /*===========================================================================
   3759  * FUNCTION   : setChromaFlash
   3760  *
   3761  * DESCRIPTION: set chroma flash from user setting
   3762  *
   3763  * PARAMETERS :
   3764  *   @params  : user setting parameters
   3765  *
   3766  * RETURN     : int32_t type of status
   3767  *              NO_ERROR  -- success
   3768  *              none-zero failure code
   3769  *==========================================================================*/
   3770 int32_t QCameraParameters::setChromaFlash(const QCameraParameters& params)
   3771 {
   3772     if ((m_pCapability->qcom_supported_feature_mask &
   3773         CAM_QCOM_FEATURE_CHROMA_FLASH) == 0) {
   3774         LOGH("Chroma Flash is not supported");
   3775         return NO_ERROR;
   3776     }
   3777     const char *str = params.get(KEY_QC_CHROMA_FLASH);
   3778     const char *prev_str = get(KEY_QC_CHROMA_FLASH);
   3779     LOGH("str =%s & prev_str =%s", str, prev_str);
   3780     if (str != NULL) {
   3781         if (prev_str == NULL ||
   3782             strcmp(str, prev_str) != 0) {
   3783             m_bNeedRestart = true;
   3784             return setChromaFlash(str);
   3785         }
   3786     }
   3787     return NO_ERROR;
   3788 }
   3789 
   3790 /*===========================================================================
   3791  * FUNCTION   : setOptiZoom
   3792  *
   3793  * DESCRIPTION: set opti zoom from user setting
   3794  *
   3795  * PARAMETERS :
   3796  *   @params  : user setting parameters
   3797  *
   3798  * RETURN     : int32_t type of status
   3799  *              NO_ERROR  -- success
   3800  *              none-zero failure code
   3801  *==========================================================================*/
   3802 int32_t QCameraParameters::setOptiZoom(const QCameraParameters& params)
   3803 {
   3804     if ((m_pCapability->qcom_supported_feature_mask &
   3805         CAM_QCOM_FEATURE_OPTIZOOM) == 0){
   3806         LOGH("Opti Zoom is not supported");
   3807         return NO_ERROR;
   3808     }
   3809     const char *str = params.get(KEY_QC_OPTI_ZOOM);
   3810     const char *prev_str = get(KEY_QC_OPTI_ZOOM);
   3811     LOGH("str =%s & prev_str =%s", str, prev_str);
   3812     if (str != NULL) {
   3813         if (prev_str == NULL ||
   3814             strcmp(str, prev_str) != 0) {
   3815             m_bNeedRestart = true;
   3816             return setOptiZoom(str);
   3817         }
   3818     }
   3819     return NO_ERROR;
   3820 }
   3821 
   3822 /*===========================================================================
   3823  * FUNCTION   : setTruePortrait
   3824  *
   3825  * DESCRIPTION: set true portrait from user setting
   3826  *
   3827  * PARAMETERS :
   3828  *   @params  : user setting parameters
   3829  *
   3830  * RETURN     : int32_t type of status
   3831  *              NO_ERROR  -- success
   3832  *              none-zero failure code
   3833  *==========================================================================*/
   3834 int32_t QCameraParameters::setTruePortrait(const QCameraParameters& params)
   3835 {
   3836     if ((m_pCapability->qcom_supported_feature_mask &
   3837             CAM_QCOM_FEATURE_TRUEPORTRAIT) == 0) {
   3838         LOGD("True Portrait is not supported");
   3839         return NO_ERROR;
   3840     }
   3841     const char *str = params.get(KEY_QC_TRUE_PORTRAIT);
   3842     const char *prev_str = get(KEY_QC_TRUE_PORTRAIT);
   3843     LOGH("str =%s & prev_str =%s", str, prev_str);
   3844     if (str != NULL) {
   3845         if (prev_str == NULL ||
   3846             strcmp(str, prev_str) != 0) {
   3847             return setTruePortrait(str);
   3848         }
   3849     }
   3850     return NO_ERROR;
   3851 }
   3852 
   3853 /*===========================================================================
   3854  * FUNCTION   : setHDRMode
   3855  *
   3856  * DESCRIPTION: set HDR mode from user setting
   3857  *
   3858  * PARAMETERS :
   3859  *   @params  : user setting parameters
   3860  *
   3861  * RETURN     : int32_t type of status
   3862  *              NO_ERROR  -- success
   3863  *              none-zero failure code
   3864  *==========================================================================*/
   3865 int32_t QCameraParameters::setHDRMode(const QCameraParameters& params)
   3866 {
   3867     const char *str = params.get(KEY_QC_HDR_MODE);
   3868     const char *prev_str = get(KEY_QC_HDR_MODE);
   3869     uint32_t supported_hdr_modes = m_pCapability->qcom_supported_feature_mask &
   3870           (CAM_QCOM_FEATURE_SENSOR_HDR | CAM_QCOM_FEATURE_HDR);
   3871 
   3872     LOGH("str =%s & prev_str =%s", str, prev_str);
   3873     if (str != NULL) {
   3874         if ((CAM_QCOM_FEATURE_SENSOR_HDR == supported_hdr_modes) &&
   3875                 (strncmp(str, HDR_MODE_SENSOR, strlen(HDR_MODE_SENSOR)))) {
   3876             LOGH("Only sensor HDR is supported");
   3877             return NO_ERROR;
   3878         } else if  ((CAM_QCOM_FEATURE_HDR == supported_hdr_modes) &&
   3879                 (strncmp(str, HDR_MODE_SENSOR, strlen(HDR_MODE_MULTI_FRAME)))) {
   3880             LOGH("Only multi frame HDR is supported");
   3881             return NO_ERROR;
   3882         } else if (!supported_hdr_modes) {
   3883             LOGH("HDR is not supported");
   3884             return NO_ERROR;
   3885         }
   3886         if (prev_str == NULL ||
   3887                 strcmp(str, prev_str) != 0) {
   3888             return setHDRMode(str);
   3889         }
   3890     }
   3891 
   3892     return NO_ERROR;
   3893 }
   3894 
   3895 /*===========================================================================
   3896  * FUNCTION   : setHDRNeed1x
   3897  *
   3898  * DESCRIPTION: set HDR need 1x from user setting
   3899  *
   3900  * PARAMETERS :
   3901  *   @params  : user setting parameters
   3902  *
   3903  * RETURN     : int32_t type of status
   3904  *              NO_ERROR  -- success
   3905  *              none-zero failure code
   3906  *==========================================================================*/
   3907 int32_t QCameraParameters::setHDRNeed1x(const QCameraParameters& params)
   3908 {
   3909     const char *str = params.get(KEY_QC_HDR_NEED_1X);
   3910     const char *prev_str = get(KEY_QC_HDR_NEED_1X);
   3911 
   3912     LOGH("str =%s & prev_str =%s", str, prev_str);
   3913     if (str != NULL) {
   3914         if (m_bHDRModeSensor) {
   3915             LOGH("Only multi frame HDR supports 1x frame");
   3916             return NO_ERROR;
   3917         }
   3918         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
   3919             return setHDRNeed1x(str);
   3920         }
   3921     }
   3922     return NO_ERROR;
   3923 }
   3924 
   3925 /*===========================================================================
   3926  * FUNCTION   : setSeeMore
   3927  *
   3928  * DESCRIPTION: set see more (llvd) from user setting
   3929  *
   3930  * PARAMETERS :
   3931  *   @params  : user setting parameters
   3932  *
   3933  * RETURN     : int32_t type of status
   3934  *              NO_ERROR  -- success
   3935  *              none-zero failure code
   3936  *==========================================================================*/
   3937 int32_t QCameraParameters::setSeeMore(const QCameraParameters& params)
   3938 {
   3939     if ((m_pCapability->qcom_supported_feature_mask &
   3940             CAM_QCOM_FEATURE_LLVD) == 0) {
   3941         LOGD("See more is not supported");
   3942         return NO_ERROR;
   3943     }
   3944     const char *str = params.get(KEY_QC_SEE_MORE);
   3945     const char *prev_str = get(KEY_QC_SEE_MORE);
   3946     LOGH("str =%s & prev_str =%s", str, prev_str);
   3947     if (str != NULL) {
   3948         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
   3949             m_bNeedRestart = true;
   3950             return setSeeMore(str);
   3951         }
   3952     }
   3953     return NO_ERROR;
   3954 }
   3955 
   3956 /*===========================================================================
   3957  * FUNCTION   : setNoiseReductionMode
   3958  *
   3959  * DESCRIPTION: set noise reduction mode from user setting
   3960  *
   3961  * PARAMETERS :
   3962  *   @params  : user setting parameters
   3963  *
   3964  * RETURN     : int32_t type of status
   3965  *              NO_ERROR  -- success
   3966  *              none-zero failure code
   3967  *==========================================================================*/
   3968 int32_t QCameraParameters::setNoiseReductionMode(const QCameraParameters& params)
   3969 {
   3970     if ((m_pCapability->qcom_supported_feature_mask & CAM_QTI_FEATURE_SW_TNR) == 0) {
   3971         LOGD("SW TNR is not supported");
   3972         return NO_ERROR;
   3973     }
   3974     const char *str = params.get(KEY_QC_NOISE_REDUCTION_MODE);
   3975     const char *prev_str = get(KEY_QC_NOISE_REDUCTION_MODE);
   3976     LOGH("str =%s & prev_str =%s", str, prev_str);
   3977     if (str != NULL) {
   3978         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
   3979             m_bNeedRestart = true;
   3980             return setNoiseReductionMode(str);
   3981         }
   3982     }
   3983     return NO_ERROR;
   3984 }
   3985 
   3986 /*===========================================================================
   3987  * FUNCTION   : setStillMore
   3988  *
   3989  * DESCRIPTION: set stillmore from user setting
   3990  *
   3991  * PARAMETERS :
   3992  *   @params  : user setting parameters
   3993  *
   3994  * RETURN     : int32_t type of status
   3995  *              NO_ERROR  -- success
   3996  *              none-zero failure code
   3997  *==========================================================================*/
   3998 int32_t QCameraParameters::setStillMore(const QCameraParameters& params)
   3999 {
   4000     if ((m_pCapability->qcom_supported_feature_mask &
   4001             CAM_QCOM_FEATURE_STILLMORE) == 0) {
   4002         LOGD("Stillmore is not supported");
   4003         return NO_ERROR;
   4004     }
   4005     const char *str = params.get(KEY_QC_STILL_MORE);
   4006     const char *prev_str = get(KEY_QC_STILL_MORE);
   4007     LOGH("str =%s & prev_str =%s", str, prev_str);
   4008     if (str != NULL) {
   4009         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
   4010             m_bNeedRestart = true;
   4011             return setStillMore(str);
   4012         }
   4013     }
   4014     return NO_ERROR;
   4015 }
   4016 
   4017 /*===========================================================================
   4018  * FUNCTION   : setRedeyeReduction
   4019  *
   4020  * DESCRIPTION: set red eye reduction setting from user setting
   4021  *
   4022  * PARAMETERS :
   4023  *   @params  : user setting parameters
   4024  *
   4025  * RETURN     : int32_t type of status
   4026  *              NO_ERROR  -- success
   4027  *              none-zero failure code
   4028  *==========================================================================*/
   4029 int32_t QCameraParameters::setRedeyeReduction(const QCameraParameters& params)
   4030 {
   4031     const char *str = params.get(KEY_QC_REDEYE_REDUCTION);
   4032     const char *prev_str = get(KEY_QC_REDEYE_REDUCTION);
   4033     if (str != NULL) {
   4034         if (prev_str == NULL ||
   4035             strcmp(str, prev_str) != 0) {
   4036             return setRedeyeReduction(str);
   4037         }
   4038     }
   4039     return NO_ERROR;
   4040 }
   4041 
   4042 /*===========================================================================
   4043  * FUNCTION   : setGpsLocation
   4044  *
   4045  * DESCRIPTION: set GPS location information from user setting
   4046  *
   4047  * PARAMETERS :
   4048  *   @params  : user setting parameters
   4049  *
   4050  * RETURN     : int32_t type of status
   4051  *              NO_ERROR  -- success
   4052  *              none-zero failure code
   4053  *==========================================================================*/
   4054 int32_t QCameraParameters::setGpsLocation(const QCameraParameters& params)
   4055 {
   4056     const char *method = params.get(KEY_GPS_PROCESSING_METHOD);
   4057     if (method) {
   4058         set(KEY_GPS_PROCESSING_METHOD, method);
   4059     }else {
   4060         remove(KEY_GPS_PROCESSING_METHOD);
   4061     }
   4062 
   4063     const char *latitude = params.get(KEY_GPS_LATITUDE);
   4064     if (latitude) {
   4065         set(KEY_GPS_LATITUDE, latitude);
   4066     }else {
   4067         remove(KEY_GPS_LATITUDE);
   4068     }
   4069 
   4070     const char *latitudeRef = params.get(KEY_QC_GPS_LATITUDE_REF);
   4071     if (latitudeRef) {
   4072         set(KEY_QC_GPS_LATITUDE_REF, latitudeRef);
   4073     }else {
   4074         remove(KEY_QC_GPS_LATITUDE_REF);
   4075     }
   4076 
   4077     const char *longitude = params.get(KEY_GPS_LONGITUDE);
   4078     if (longitude) {
   4079         set(KEY_GPS_LONGITUDE, longitude);
   4080     }else {
   4081         remove(KEY_GPS_LONGITUDE);
   4082     }
   4083 
   4084     const char *longitudeRef = params.get(KEY_QC_GPS_LONGITUDE_REF);
   4085     if (longitudeRef) {
   4086         set(KEY_QC_GPS_LONGITUDE_REF, longitudeRef);
   4087     }else {
   4088         remove(KEY_QC_GPS_LONGITUDE_REF);
   4089     }
   4090 
   4091     const char *altitudeRef = params.get(KEY_QC_GPS_ALTITUDE_REF);
   4092     if (altitudeRef) {
   4093         set(KEY_QC_GPS_ALTITUDE_REF, altitudeRef);
   4094     }else {
   4095         remove(KEY_QC_GPS_ALTITUDE_REF);
   4096     }
   4097 
   4098     const char *altitude = params.get(KEY_GPS_ALTITUDE);
   4099     if (altitude) {
   4100         set(KEY_GPS_ALTITUDE, altitude);
   4101     }else {
   4102         remove(KEY_GPS_ALTITUDE);
   4103     }
   4104 
   4105     const char *status = params.get(KEY_QC_GPS_STATUS);
   4106     if (status) {
   4107         set(KEY_QC_GPS_STATUS, status);
   4108     } else {
   4109         remove(KEY_QC_GPS_STATUS);
   4110     }
   4111 
   4112     const char *timestamp = params.get(KEY_GPS_TIMESTAMP);
   4113     if (timestamp) {
   4114         set(KEY_GPS_TIMESTAMP, timestamp);
   4115     }else {
   4116         remove(KEY_GPS_TIMESTAMP);
   4117     }
   4118     return NO_ERROR;
   4119 }
   4120 
   4121 /*===========================================================================
   4122  * FUNCTION   : setNumOfSnapshot
   4123  *
   4124  * DESCRIPTION: set number of snapshot per shutter from user setting
   4125  *
   4126  * PARAMETERS : none
   4127  *
   4128  * RETURN     : int32_t type of status
   4129  *              NO_ERROR  -- success
   4130  *              none-zero failure code
   4131  *==========================================================================*/
   4132 int32_t QCameraParameters::setNumOfSnapshot()
   4133 {
   4134     int nBurstNum = 1;
   4135     int nExpnum = 0;
   4136 
   4137     const char *bracket_str = get(KEY_QC_AE_BRACKET_HDR);
   4138     if (bracket_str != NULL && strlen(bracket_str) > 0) {
   4139         int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
   4140                 bracket_str);
   4141         switch (value) {
   4142         case CAM_EXP_BRACKETING_ON:
   4143             {
   4144                 nExpnum = 0;
   4145                 const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
   4146                 if ((str_val != NULL) && (strlen(str_val) > 0)) {
   4147                     char prop[PROPERTY_VALUE_MAX];
   4148                     memset(prop, 0, sizeof(prop));
   4149                     strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
   4150                     char *saveptr = NULL;
   4151                     char *token = strtok_r(prop, ",", &saveptr);
   4152                     while (token != NULL) {
   4153                         token = strtok_r(NULL, ",", &saveptr);
   4154                         nExpnum++;
   4155                     }
   4156                 }
   4157                 if (nExpnum == 0) {
   4158                     nExpnum = 1;
   4159                 }
   4160             }
   4161             break;
   4162         default:
   4163             nExpnum = 1 + getNumOfExtraHDROutBufsIfNeeded();
   4164             break;
   4165         }
   4166     }
   4167 
   4168     if (isUbiRefocus()) {
   4169         nBurstNum = m_pCapability->refocus_af_bracketing_need.output_count + 1;
   4170     }
   4171 
   4172     LOGH("nBurstNum = %d, nExpnum = %d", nBurstNum, nExpnum);
   4173     set(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER, nBurstNum * nExpnum);
   4174     return NO_ERROR;
   4175 }
   4176 
   4177 /*===========================================================================
   4178  * FUNCTION   : setRecordingHint
   4179  *
   4180  * DESCRIPTION: set recording hint value from user setting
   4181  *
   4182  * PARAMETERS :
   4183  *   @params  : user setting parameters
   4184  *
   4185  * RETURN     : int32_t type of status
   4186  *              NO_ERROR  -- success
   4187  *              none-zero failure code
   4188  *==========================================================================*/
   4189 int32_t QCameraParameters::setRecordingHint(const QCameraParameters& params)
   4190 {
   4191     const char * str = params.get(KEY_RECORDING_HINT);
   4192     const char *prev_str = get(KEY_RECORDING_HINT);
   4193     if (str != NULL) {
   4194         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
   4195             int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
   4196                     str);
   4197             if(value != NAME_NOT_FOUND){
   4198                 updateParamEntry(KEY_RECORDING_HINT, str);
   4199                 setRecordingHintValue(value);
   4200                 if (getFaceDetectionOption() == true) {
   4201                     if (!fdModeInVideo()) {
   4202                         setFaceDetection(value > 0 ? false : true, false);
   4203                     } else {
   4204                         setFaceDetection(true, false);
   4205                     }
   4206                 }
   4207                 if (m_bDISEnabled) {
   4208                     LOGH("Setting DIS value again");
   4209                     setDISValue(VALUE_ENABLE);
   4210                 }
   4211                 return NO_ERROR;
   4212             } else {
   4213                 LOGE("Invalid recording hint value: %s", str);
   4214                 return BAD_VALUE;
   4215             }
   4216         }
   4217     }
   4218     return NO_ERROR;
   4219 }
   4220 
   4221 /*===========================================================================
   4222  * FUNCTION   : setNoDisplayMode
   4223  *
   4224  * DESCRIPTION: set no display mode from user setting
   4225  *
   4226  * PARAMETERS :
   4227  *   @params  : user setting parameters
   4228  *
   4229  * RETURN     : int32_t type of status
   4230  *              NO_ERROR  -- success
   4231  *              none-zero failure code
   4232  *==========================================================================*/
   4233 int32_t QCameraParameters::setNoDisplayMode(const QCameraParameters& params)
   4234 {
   4235     const char *str_val  = params.get(KEY_QC_NO_DISPLAY_MODE);
   4236     const char *prev_str = get(KEY_QC_NO_DISPLAY_MODE);
   4237     char prop[PROPERTY_VALUE_MAX];
   4238     LOGD("str_val: %s, prev_str: %s", str_val, prev_str);
   4239 
   4240     // Aux Camera Mode, set no display mode
   4241     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
   4242         if (!m_bNoDisplayMode) {
   4243             set(KEY_QC_NO_DISPLAY_MODE, 1);
   4244             m_bNoDisplayMode = true;
   4245             m_bNeedRestart = true;
   4246         }
   4247         return NO_ERROR;
   4248     }
   4249 
   4250     if(str_val && strlen(str_val) > 0) {
   4251         if (prev_str == NULL || strcmp(str_val, prev_str) != 0) {
   4252             m_bNoDisplayMode = atoi(str_val);
   4253             set(KEY_QC_NO_DISPLAY_MODE, str_val);
   4254             m_bNeedRestart = true;
   4255         }
   4256     } else {
   4257         memset(prop, 0, sizeof(prop));
   4258         property_get("persist.camera.no-display", prop, "0");
   4259         m_bNoDisplayMode = atoi(prop);
   4260     }
   4261     LOGH("Param m_bNoDisplayMode = %d", m_bNoDisplayMode);
   4262     return NO_ERROR;
   4263 }
   4264 
   4265 /*===========================================================================
   4266  * FUNCTION   : setZslMode
   4267  *
   4268  * DESCRIPTION: set ZSL mode from user setting
   4269  *
   4270  * PARAMETERS :
   4271  *   @params  : user setting parameters
   4272  *
   4273  * RETURN     : int32_t type of status
   4274  *              NO_ERROR  -- success
   4275  *              none-zero failure code
   4276  *==========================================================================*/
   4277 int32_t QCameraParameters::setZslMode(const QCameraParameters& params)
   4278 {
   4279     const char *str_val  = params.get(KEY_QC_ZSL);
   4280     const char *prev_val  = get(KEY_QC_ZSL);
   4281     int32_t rc = NO_ERROR;
   4282 
   4283     if(m_bForceZslMode) {
   4284         if (!m_bZslMode) {
   4285             // Force ZSL mode to ON
   4286             set(KEY_QC_ZSL, VALUE_ON);
   4287             setZslMode(TRUE);
   4288             LOGH("ZSL Mode forced to be enabled");
   4289         }
   4290     } else if (str_val != NULL) {
   4291         if (prev_val == NULL || strcmp(str_val, prev_val) != 0) {
   4292             int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
   4293                     str_val);
   4294             if (value != NAME_NOT_FOUND) {
   4295                 set(KEY_QC_ZSL, str_val);
   4296                 rc = setZslMode(value);
   4297                 // ZSL mode changed, need restart preview
   4298                 m_bNeedRestart = true;
   4299             } else {
   4300                 LOGE("Invalid ZSL mode value: %s", str_val);
   4301                 rc = BAD_VALUE;
   4302             }
   4303         }
   4304     }
   4305     return rc;
   4306 }
   4307 
   4308 /*===========================================================================
   4309  * FUNCTION   : setZslMode
   4310  *
   4311  * DESCRIPTION: set ZSL mode from user setting
   4312  *
   4313  * PARAMETERS :
   4314  *   @value  : ZSL mode value
   4315  *
   4316  * RETURN     : int32_t type of status
   4317  *              NO_ERROR  -- success
   4318  *              none-zero failure code
   4319  *==========================================================================*/
   4320 int32_t QCameraParameters::setZslMode(bool value)
   4321 {
   4322     int32_t rc = NO_ERROR;
   4323     if(m_bForceZslMode) {
   4324         if (!m_bZslMode) {
   4325             // Force ZSL mode to ON
   4326             set(KEY_QC_ZSL, VALUE_ON);
   4327             m_bZslMode_new = true;
   4328             m_bZslMode = true;
   4329             m_bNeedRestart = true;
   4330 
   4331             int32_t value = m_bForceZslMode;
   4332             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value)) {
   4333                 rc = BAD_VALUE;
   4334             }
   4335 
   4336             LOGI("ZSL Mode forced to be enabled");
   4337         }
   4338     } else {
   4339         LOGI("ZSL Mode  -> %s", m_bZslMode_new ? "Enabled" : "Disabled");
   4340         m_bZslMode_new = (value > 0)? true : false;
   4341         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value)) {
   4342             rc = BAD_VALUE;
   4343         }
   4344     }
   4345     LOGH("enabled: %d rc = %d", m_bZslMode_new, rc);
   4346     return rc;
   4347 }
   4348 
   4349 /*===========================================================================
   4350  * FUNCTION   : updateZSLModeValue
   4351  *
   4352  * DESCRIPTION: update zsl mode value locally and to daemon
   4353  *
   4354  * PARAMETERS :
   4355  *   @value   : zsl mode value
   4356  *
   4357  * RETURN     : int32_t type of status
   4358  *              NO_ERROR  -- success
   4359  *              none-zero failure code
   4360  *==========================================================================*/
   4361 int32_t QCameraParameters::updateZSLModeValue(bool value)
   4362 {
   4363     int32_t rc = NO_ERROR;
   4364     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   4365         LOGE("Failed to initialize group update table");
   4366         return BAD_TYPE;
   4367     }
   4368 
   4369     rc = setZslMode(value);
   4370     if (rc != NO_ERROR) {
   4371         LOGE("Failed to ZSL value");
   4372         return rc;
   4373     }
   4374 
   4375     rc = commitSetBatch();
   4376     if (rc != NO_ERROR) {
   4377         LOGE("Failed to update recording hint");
   4378         return rc;
   4379     }
   4380 
   4381     return rc;
   4382 }
   4383 
   4384 /*===========================================================================
   4385  * FUNCTION   : setWaveletDenoise
   4386  *
   4387  * DESCRIPTION: set wavelet denoise value from user setting
   4388  *
   4389  * PARAMETERS :
   4390  *   @params  : user setting parameters
   4391  *
   4392  * RETURN     : int32_t type of status
   4393  *              NO_ERROR  -- success
   4394  *              none-zero failure code
   4395  *==========================================================================*/
   4396 int32_t QCameraParameters::setWaveletDenoise(const QCameraParameters& params)
   4397 {
   4398     const char *str = params.get(KEY_QC_DENOISE);
   4399     const char *prev_str = get(KEY_QC_DENOISE);
   4400     if (str != NULL) {
   4401         if (prev_str == NULL ||
   4402             strcmp(str, prev_str) != 0) {
   4403             return setWaveletDenoise(str);
   4404         }
   4405     }
   4406     return NO_ERROR;
   4407 }
   4408 
   4409 /*===========================================================================
   4410  * FUNCTION   : setTemporalDenoise
   4411  *
   4412  * DESCRIPTION: set temporal denoise value from properties
   4413  *
   4414  * PARAMETERS : none
   4415  *
   4416  * RETURN     : int32_t type of status
   4417  *              NO_ERROR  -- success
   4418  *              none-zero failure code
   4419  *==========================================================================*/
   4420 int32_t QCameraParameters::setTemporalDenoise(const QCameraParameters& params)
   4421 {
   4422     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_CPP_TNR) == 0) {
   4423         LOGH("TNR is not supported");
   4424         return NO_ERROR;
   4425     }
   4426 
   4427     const char *str = params.get(KEY_QC_TNR_MODE);
   4428     const char *prev_str = get(KEY_QC_TNR_MODE);
   4429     const char *video_str = params.get(KEY_QC_VIDEO_TNR_MODE);
   4430     const char *video_prev_str = get(KEY_QC_VIDEO_TNR_MODE);
   4431     char video_value[PROPERTY_VALUE_MAX];
   4432     char preview_value[PROPERTY_VALUE_MAX];
   4433     bool prev_video_tnr = m_bTNRVideoOn;
   4434     bool prev_preview_tnr = m_bTNRPreviewOn;
   4435     bool prev_snap_tnr = m_bTNRSnapshotOn;
   4436 
   4437     char value[PROPERTY_VALUE_MAX];
   4438     memset(value, 0, sizeof(value));
   4439     property_get("persist.camera.tnr_cds", value, "0");
   4440     uint8_t tnr_cds = (uint8_t)atoi(value);
   4441 
   4442     if (m_bRecordingHint_new == true) {
   4443         if (video_str) {
   4444             if ((video_prev_str == NULL) || (strcmp(video_str, video_prev_str) != 0)) {
   4445                 if (!strcmp(video_str, VALUE_ON)) {
   4446                     m_bTNRVideoOn = true;
   4447                     m_bTNRPreviewOn = true;
   4448                 } else {
   4449                     m_bTNRVideoOn = false;
   4450                     m_bTNRPreviewOn = false;
   4451                 }
   4452                 updateParamEntry(KEY_QC_VIDEO_TNR_MODE, video_str);
   4453             } else {
   4454                 return NO_ERROR;
   4455             }
   4456         }
   4457     } else {
   4458         if (str) {
   4459             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
   4460                 if (!strcmp(str, VALUE_ON)) {
   4461                     m_bTNRPreviewOn = true;
   4462                 } else {
   4463                     m_bTNRPreviewOn = false;
   4464                 }
   4465                 updateParamEntry(KEY_QC_TNR_MODE, str);
   4466             } else {
   4467                 return NO_ERROR;
   4468             }
   4469         }
   4470     }
   4471 
   4472     //Read setprops only if UI is not present or disabled.
   4473     if ((m_bRecordingHint_new == true)
   4474             && ((video_str == NULL)
   4475             || (strcmp(video_str, VALUE_ON)))) {
   4476         memset(video_value, 0, sizeof(video_value));
   4477         property_get("persist.camera.tnr.video", video_value, VALUE_OFF);
   4478         if (!strcmp(video_value, VALUE_ON)) {
   4479             m_bTNRVideoOn = true;
   4480         } else {
   4481             m_bTNRVideoOn = false;
   4482         }
   4483         updateParamEntry(KEY_QC_VIDEO_TNR_MODE, video_value);
   4484 
   4485         memset(preview_value, 0, sizeof(preview_value));
   4486         property_get("persist.camera.tnr.preview", preview_value, VALUE_OFF);
   4487         if (!strcmp(preview_value, VALUE_ON)) {
   4488             m_bTNRPreviewOn = true;
   4489         } else {
   4490             m_bTNRPreviewOn = false;
   4491         }
   4492         updateParamEntry(KEY_QC_TNR_MODE, preview_value);
   4493     } else if ((m_bRecordingHint_new != true)
   4494             && ((str == NULL) || (strcmp(str, VALUE_ON)))) {
   4495         memset(preview_value, 0, sizeof(preview_value));
   4496         property_get("persist.camera.tnr.preview", preview_value, VALUE_OFF);
   4497         if (!strcmp(preview_value, VALUE_ON)) {
   4498             m_bTNRPreviewOn = true;
   4499         } else {
   4500             m_bTNRPreviewOn = false;
   4501         }
   4502         updateParamEntry(KEY_QC_TNR_MODE, preview_value);
   4503     }
   4504 
   4505     memset(value, 0, sizeof(value));
   4506     property_get("persist.camera.tnr.snapshot", value, VALUE_OFF);
   4507     if (!strcmp(value, VALUE_ON)) {
   4508         m_bTNRSnapshotOn = true;
   4509         LOGD("TNR enabled for SNAPSHOT stream");
   4510     } else {
   4511         m_bTNRSnapshotOn = false;
   4512     }
   4513 
   4514     cam_denoise_param_t temp;
   4515     memset(&temp, 0, sizeof(temp));
   4516     if (m_bTNRVideoOn || m_bTNRPreviewOn || m_bTNRSnapshotOn) {
   4517         temp.denoise_enable = 1;
   4518         temp.process_plates = getDenoiseProcessPlate(
   4519                 CAM_INTF_PARM_TEMPORAL_DENOISE);
   4520 
   4521         if (!tnr_cds) {
   4522             int32_t cds_mode = lookupAttr(CDS_MODES_MAP,
   4523                     PARAM_MAP_SIZE(CDS_MODES_MAP), CDS_MODE_OFF);
   4524 
   4525             if (cds_mode != NAME_NOT_FOUND) {
   4526                 updateParamEntry(KEY_QC_VIDEO_CDS_MODE, CDS_MODE_OFF);
   4527                 if (m_bTNRPreviewOn) {
   4528                     updateParamEntry(KEY_QC_CDS_MODE, CDS_MODE_OFF);
   4529                 }
   4530                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   4531                         CAM_INTF_PARM_CDS_MODE, cds_mode)) {
   4532                     LOGE("Failed CDS MODE to update table");
   4533                     return BAD_VALUE;
   4534                 }
   4535                 LOGD("CDS is set to = %s when TNR is enabled",
   4536                          CDS_MODE_OFF);
   4537                 mCds_mode = cds_mode;
   4538             } else {
   4539                 LOGE("Invalid argument for video CDS MODE %d",
   4540                          cds_mode);
   4541             }
   4542         } else {
   4543             LOGH("Enabled TNR with CDS");
   4544         }
   4545     }
   4546 
   4547     if ((m_bTNRVideoOn != prev_video_tnr)
   4548             || (m_bTNRPreviewOn != prev_preview_tnr)
   4549             || (prev_snap_tnr != m_bTNRSnapshotOn)) {
   4550         LOGD("TNR enabled = %d, plates = %d",
   4551                 temp.denoise_enable, temp.process_plates);
   4552         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   4553                 CAM_INTF_PARM_TEMPORAL_DENOISE, temp)) {
   4554             return BAD_VALUE;
   4555         }
   4556     }
   4557 
   4558     return NO_ERROR;
   4559 }
   4560 
   4561 /*===========================================================================
   4562  * FUNCTION   : setCameraMode
   4563  *
   4564  * DESCRIPTION: set camera mode from user setting
   4565  *
   4566  * PARAMETERS :
   4567  *   @params  : user setting parameters
   4568  *
   4569  * RETURN     : int32_t type of status
   4570  *              NO_ERROR  -- success
   4571  *              none-zero failure code
   4572  *==========================================================================*/
   4573 int32_t QCameraParameters::setCameraMode(const QCameraParameters& params)
   4574 {
   4575     const char *str = params.get(KEY_QC_CAMERA_MODE);
   4576     if (str != NULL) {
   4577         set(KEY_QC_CAMERA_MODE, str);
   4578     } else {
   4579         remove(KEY_QC_CAMERA_MODE);
   4580     }
   4581     return NO_ERROR;
   4582 }
   4583 
   4584 /*===========================================================================
   4585  * FUNCTION   : setSceneSelectionMode
   4586  *
   4587  * DESCRIPTION: set scene selection mode from user setting
   4588  *
   4589  * PARAMETERS :
   4590  *   @params  : user setting parameters
   4591  *
   4592  * RETURN     : int32_t type of status
   4593  *              NO_ERROR  -- success
   4594  *              none-zero failure code
   4595  *==========================================================================*/
   4596 int32_t QCameraParameters::setSceneSelectionMode(const QCameraParameters& params)
   4597 {
   4598     const char *str = params.get(KEY_QC_SCENE_SELECTION);
   4599     const char *prev_str = get(KEY_QC_SCENE_SELECTION);
   4600     if (NULL != str) {
   4601         if ((NULL == prev_str) || (strcmp(str, prev_str) != 0)) {
   4602             int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   4603                     PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
   4604             if (value != NAME_NOT_FOUND) {
   4605                 LOGD("Setting selection value %s", str);
   4606                 if (value && m_bZslMode_new) {
   4607                     updateParamEntry(KEY_QC_SCENE_SELECTION, str);
   4608                     m_bNeedRestart = true;
   4609                     m_bSceneSelection = true;
   4610                 } else if (!value) {
   4611                     updateParamEntry(KEY_QC_SCENE_SELECTION, str);
   4612                     m_bNeedRestart = true;
   4613                     m_bSceneSelection = false;
   4614                 } else {
   4615                     LOGE("Trying to enable scene selection in non ZSL mode!!!");
   4616                     return BAD_VALUE;
   4617                 }
   4618             } else {
   4619                 LOGE("Trying to configure invalid scene selection value: %s",
   4620                         str);
   4621                 return BAD_VALUE;
   4622             }
   4623         }
   4624     }
   4625 
   4626     return NO_ERROR;
   4627 }
   4628 
   4629 /*===========================================================================
   4630  * FUNCTION   : setSelectedScene
   4631  *
   4632  * DESCRIPTION: select specific scene
   4633  *
   4634  * PARAMETERS :
   4635  *   @scene   : scene mode
   4636  *
   4637  * RETURN     : int32_t type of status
   4638  *              NO_ERROR  -- success
   4639  *              none-zero failure code
   4640  *==========================================================================*/
   4641 int32_t QCameraParameters::setSelectedScene(cam_scene_mode_type scene)
   4642 {
   4643     Mutex::Autolock l(m_SceneSelectLock);
   4644     m_SelectedScene = scene;
   4645     return NO_ERROR;
   4646 }
   4647 
   4648 /*===========================================================================
   4649  * FUNCTION   : getSelectedScene
   4650  *
   4651  * DESCRIPTION: get selected scene
   4652  *
   4653  * PARAMETERS :
   4654  *
   4655  * RETURN     : currently selected scene
   4656  *==========================================================================*/
   4657 cam_scene_mode_type QCameraParameters::getSelectedScene()
   4658 {
   4659     Mutex::Autolock l(m_SceneSelectLock);
   4660     return m_SelectedScene;
   4661 }
   4662 
   4663 /*==========================================================
   4664  * FUNCTION   : setRdiMode
   4665  *
   4666  * DESCRIPTION: set Rdi mode from user setting
   4667  *
   4668  * PARAMETERS :
   4669  *   @params  : user setting parameters
   4670  *
   4671  * RETURN     : int32_t type of status
   4672  *              NO_ERROR  -- success
   4673  *              none-zero failure code
   4674  *===========================================================*/
   4675 int32_t QCameraParameters::setRdiMode(const QCameraParameters& params)
   4676 {
   4677     const char *str = params.get(KEY_QC_RDI_MODE);
   4678     const char *prev_str = get(KEY_QC_RDI_MODE);
   4679     char prop[PROPERTY_VALUE_MAX];
   4680     memset(prop, 0, sizeof(prop));
   4681 
   4682     property_get("persist.camera.rdi.mode", prop, VALUE_DISABLE);
   4683     if ((str != NULL) && (prev_str == NULL || strcmp(str, prev_str) != 0)) {
   4684         LOGD("RDI mode set to %s", str);
   4685         setRdiMode(str);
   4686     } else if (prev_str == NULL || strcmp(prev_str, prop) != 0 ) {
   4687         LOGD("RDI mode set to prop: %s", prop);
   4688         setRdiMode(prop);
   4689     }
   4690     return NO_ERROR;
   4691 }
   4692 
   4693 /*==========================================================
   4694  * FUNCTION   : setSecureMode
   4695  *
   4696  * DESCRIPTION: set secure mode from user setting
   4697  *
   4698  * PARAMETERS :
   4699  *   @params  : user setting parameters
   4700  *
   4701  * RETURN     : int32_t type of status
   4702  *              NO_ERROR  -- success
   4703  *              none-zero failure code
   4704  *===========================================================*/
   4705 
   4706 int32_t QCameraParameters::setSecureMode(const QCameraParameters& params)
   4707 {
   4708     const char *str = params.get(KEY_QC_SECURE_MODE);
   4709     const char *prev_str = get(KEY_QC_SECURE_MODE);
   4710     char prop[PROPERTY_VALUE_MAX];
   4711     memset(prop, 0, sizeof(prop));
   4712 
   4713     property_get("persist.camera.secure.mode", prop, VALUE_DISABLE);
   4714     if ((str != NULL) && (prev_str == NULL || strcmp(str, prev_str) != 0)) {
   4715         LOGD("Secure mode set to KEY: %s", str);
   4716         setSecureMode(str);
   4717     } else if (prev_str == NULL || strcmp(prev_str, prop) != 0 ) {
   4718         LOGD("Secure mode set to prop: %s", prop);
   4719         setSecureMode(prop);
   4720     }
   4721     return NO_ERROR;
   4722 }
   4723 
   4724 /*===========================================================================
   4725  * FUNCTION   : setZslAttributes
   4726  *
   4727  * DESCRIPTION: set ZSL related attributes from user setting
   4728  *
   4729  * PARAMETERS :
   4730  *   @params  : user setting parameters
   4731  *
   4732  * RETURN     : int32_t type of status
   4733  *              NO_ERROR  -- success
   4734  *              none-zero failure code
   4735  *==========================================================================*/
   4736 int32_t QCameraParameters::setZslAttributes(const QCameraParameters& params)
   4737 {
   4738     // TODO: may switch to pure param instead of sysprop
   4739     char prop[PROPERTY_VALUE_MAX];
   4740 
   4741     const char *str = params.get(KEY_QC_ZSL_BURST_INTERVAL);
   4742     if (str != NULL) {
   4743         set(KEY_QC_ZSL_BURST_INTERVAL, str);
   4744     } else {
   4745         memset(prop, 0, sizeof(prop));
   4746         property_get("persist.camera.zsl.interval", prop, "1");
   4747         set(KEY_QC_ZSL_BURST_INTERVAL, prop);
   4748         LOGH("burst interval: %s", prop);
   4749     }
   4750 
   4751     str = params.get(KEY_QC_ZSL_BURST_LOOKBACK);
   4752     if (str != NULL) {
   4753         set(KEY_QC_ZSL_BURST_LOOKBACK, str);
   4754     } else {
   4755         memset(prop, 0, sizeof(prop));
   4756         property_get("persist.camera.zsl.backlookcnt", prop, "2");
   4757         uint32_t look_back_cnt = atoi(prop);
   4758         if (m_bFrameSyncEnabled) {
   4759             look_back_cnt += EXTRA_FRAME_SYNC_BUFFERS;
   4760         }
   4761         set(KEY_QC_ZSL_BURST_LOOKBACK, look_back_cnt);
   4762         LOGH("look back count: %s", prop);
   4763     }
   4764 
   4765     str = params.get(KEY_QC_ZSL_QUEUE_DEPTH);
   4766     if (str != NULL) {
   4767         set(KEY_QC_ZSL_QUEUE_DEPTH, str);
   4768     } else {
   4769         memset(prop, 0, sizeof(prop));
   4770         property_get("persist.camera.zsl.queuedepth", prop, "2");
   4771         uint32_t queue_depth = atoi(prop);
   4772         if (m_bFrameSyncEnabled) {
   4773             queue_depth += EXTRA_FRAME_SYNC_BUFFERS;
   4774         }
   4775         set(KEY_QC_ZSL_QUEUE_DEPTH, queue_depth);
   4776         LOGH("queue depth: %s", prop);
   4777     }
   4778 
   4779     return NO_ERROR;
   4780 }
   4781 
   4782 /*===========================================================================
   4783  * FUNCTION   : setFlip
   4784  *
   4785  * DESCRIPTION: set preview/ video/ picture flip mode from user setting
   4786  *
   4787  * PARAMETERS :
   4788  *   @params  : user setting parameters
   4789  *
   4790  * RETURN     : int32_t type of status
   4791  *              NO_ERROR  -- success
   4792  *              none-zero failure code
   4793  *==========================================================================*/
   4794 int32_t QCameraParameters::setFlip(const QCameraParameters& params)
   4795 {
   4796     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) == 0) {
   4797         LOGH("flip is not supported.");
   4798         return NO_ERROR;
   4799     }
   4800 
   4801     //check preview flip setting
   4802     const char *str = params.get(KEY_QC_PREVIEW_FLIP);
   4803     const char *prev_val = get(KEY_QC_PREVIEW_FLIP);
   4804     if(str != NULL){
   4805         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
   4806             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
   4807             if(value != NAME_NOT_FOUND){
   4808                 set(KEY_QC_PREVIEW_FLIP, str);
   4809                 m_bPreviewFlipChanged = true;
   4810             }
   4811         }
   4812     }
   4813 
   4814     // check video filp setting
   4815     str = params.get(KEY_QC_VIDEO_FLIP);
   4816     prev_val = get(KEY_QC_VIDEO_FLIP);
   4817     if(str != NULL){
   4818         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
   4819             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
   4820             if(value != NAME_NOT_FOUND){
   4821                 set(KEY_QC_VIDEO_FLIP, str);
   4822                 m_bVideoFlipChanged = true;
   4823             }
   4824         }
   4825     }
   4826 
   4827     // check picture filp setting
   4828     str = params.get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
   4829     prev_val = get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
   4830     if(str != NULL){
   4831         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
   4832             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
   4833             if(value != NAME_NOT_FOUND){
   4834                 set(KEY_QC_SNAPSHOT_PICTURE_FLIP, str);
   4835                 m_bSnapshotFlipChanged = true;
   4836             }
   4837         }
   4838     }
   4839 
   4840     return NO_ERROR;
   4841 }
   4842 
   4843 /*===========================================================================
   4844  * FUNCTION   : setSnapshotFDReq
   4845  *
   4846  * DESCRIPTION: set requirement of Face Detection Metadata in Snapshot mode.
   4847  *
   4848  * PARAMETERS :
   4849  *   @params  : user setting parameters
   4850  *
   4851  * RETURN     : int32_t type of status
   4852  *              NO_ERROR  -- success
   4853  *              none-zero failure code
   4854  *==========================================================================*/
   4855 int32_t QCameraParameters::setSnapshotFDReq(const QCameraParameters& params)
   4856 {
   4857     char prop[PROPERTY_VALUE_MAX];
   4858     const char *str = params.get(KEY_QC_SNAPSHOT_FD_DATA);
   4859 
   4860     if(str != NULL){
   4861         set(KEY_QC_SNAPSHOT_FD_DATA, str);
   4862     }else{
   4863         memset(prop, 0, sizeof(prop));
   4864         property_get("persist.camera.snapshot.fd", prop, "0");
   4865         set(KEY_QC_SNAPSHOT_FD_DATA, prop);
   4866     }
   4867     return NO_ERROR;
   4868 }
   4869 
   4870 /*===========================================================================
   4871  * FUNCTION   : setMobicat
   4872  *
   4873  * DESCRIPTION: set Mobicat on/off.
   4874  *
   4875  * PARAMETERS :
   4876  *   @params  : user setting parameters
   4877  *
   4878  * RETURN     : int32_t type of status
   4879  *              NO_ERROR  -- success
   4880  *              none-zero failure code
   4881  *==========================================================================*/
   4882 int32_t QCameraParameters::setMobicat(const QCameraParameters& )
   4883 {
   4884     char value [PROPERTY_VALUE_MAX];
   4885     property_get("persist.camera.mobicat", value, "0");
   4886     int32_t ret = NO_ERROR;
   4887     uint8_t enableMobi = (uint8_t)atoi(value);
   4888 
   4889     if (enableMobi) {
   4890         tune_cmd_t tune_cmd;
   4891         tune_cmd.type = 2;
   4892         tune_cmd.module = 0;
   4893         tune_cmd.value = 1;
   4894         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SET_VFE_COMMAND, tune_cmd)) {
   4895             return BAD_VALUE;
   4896         }
   4897         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SET_PP_COMMAND, tune_cmd)) {
   4898             ret = BAD_VALUE;
   4899         }
   4900     }
   4901     m_MobiMask = enableMobi;
   4902 
   4903     return ret;
   4904 }
   4905 
   4906 /*===========================================================================
   4907  * FUNCTION   : setLongshotParam
   4908  *
   4909  * DESCRIPTION: set Longshot on/off.
   4910  *
   4911  * PARAMETERS :
   4912  *   @params  : user setting parameters
   4913  *
   4914  * RETURN     : int32_t type of status
   4915  *              NO_ERROR  -- success
   4916  *              none-zero failure code
   4917  *==========================================================================*/
   4918 int32_t QCameraParameters::setLongshotParam(const QCameraParameters& params)
   4919 {
   4920     const char *str = params.get(KEY_QC_LONG_SHOT);
   4921     const char *prev_str = get(KEY_QC_LONG_SHOT);
   4922 
   4923     if (str != NULL) {
   4924         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
   4925             set(KEY_QC_LONG_SHOT, str);
   4926             if (prev_str && !strcmp(str, "off") && !strcmp(prev_str, "on")) {
   4927                 // We restart here, to reset the FPS and no
   4928                 // of buffers as per the requirement of single snapshot usecase.
   4929                 // Here restart happens when continuous shot is changed to off from on.
   4930                 // In case of continuous shot on, restart is taken care when actual
   4931                 // longshot command is triggered through sendCommand.
   4932                 m_bNeedRestart = true;
   4933             }
   4934         }
   4935     }
   4936 
   4937     return NO_ERROR;
   4938 }
   4939 
   4940 /*===========================================================================
   4941  * FUNCTION   : checkFeatureConcurrency
   4942  *
   4943  * DESCRIPTION: check if there is a feature concurrency issue with advanced
   4944  *              camera features
   4945  *
   4946  * PARAMETERS : None
   4947  *
   4948  * RETURN     : int32_t type of status
   4949  *              NO_ERROR  -- success
   4950  *              none-zero failure code
   4951  *==========================================================================*/
   4952 int32_t QCameraParameters::checkFeatureConcurrency()
   4953 {
   4954     int32_t rc = NO_ERROR;
   4955     uint32_t advancedFeatEnableBit = 0;
   4956 
   4957     if (isStillMoreEnabled()) {
   4958         advancedFeatEnableBit |= CAM_QCOM_FEATURE_STILLMORE;
   4959     }
   4960     if (isHDREnabled()) {
   4961         advancedFeatEnableBit |= CAM_QCOM_FEATURE_HDR;
   4962     }
   4963     if (isChromaFlashEnabled()) {
   4964         advancedFeatEnableBit |= CAM_QCOM_FEATURE_CHROMA_FLASH;
   4965     }
   4966     if (isUbiFocusEnabled()) {
   4967         advancedFeatEnableBit |= CAM_QCOM_FEATURE_UBIFOCUS;
   4968     }
   4969     if (isTruePortraitEnabled()) {
   4970         advancedFeatEnableBit |= CAM_QCOM_FEATURE_TRUEPORTRAIT;
   4971     }
   4972     if (isOptiZoomEnabled()) {
   4973         advancedFeatEnableBit |= CAM_QCOM_FEATURE_OPTIZOOM;
   4974     }
   4975     if (isUbiRefocus()) {
   4976         advancedFeatEnableBit |= CAM_QCOM_FEATURE_REFOCUS;
   4977     }
   4978 
   4979    if (m_bLongshotEnabled && advancedFeatEnableBit) {
   4980         LOGE("Failed Longshot mode bit 0x%x",
   4981                     advancedFeatEnableBit);
   4982         rc = BAD_TYPE;
   4983         return rc;
   4984     }
   4985 
   4986     if(m_bRecordingHint_new) {
   4987         advancedFeatEnableBit &= ~CAM_QCOM_FEATURE_STILLMORE;
   4988 
   4989         if (advancedFeatEnableBit) {
   4990             LOGE("Failed recording mode bit 0x%x",
   4991                     advancedFeatEnableBit);
   4992             rc = BAD_TYPE;
   4993         }
   4994     } else if (m_bZslMode_new) {
   4995         /* ZSL mode check if 2 bits are set */
   4996         if (advancedFeatEnableBit & (advancedFeatEnableBit - 1)) {
   4997             LOGE("Failed ZSL mode bit 0x%x", advancedFeatEnableBit);
   4998             rc = BAD_TYPE;
   4999         }
   5000     } else { /* non-ZSL mode */
   5001         advancedFeatEnableBit &= ~CAM_QCOM_FEATURE_HDR;
   5002 
   5003         /* non-ZSL mode check if 1 bit is set */
   5004         if (advancedFeatEnableBit) {
   5005             LOGE("Failed non-ZSL mode bit 0x%x", advancedFeatEnableBit);
   5006             rc = BAD_TYPE;
   5007         }
   5008     }
   5009     LOGI("Advance feature enabled 0x%x", advancedFeatEnableBit);
   5010     return rc;
   5011 }
   5012 
   5013 /*===========================================================================
   5014  * FUNCTION   : updateParameters
   5015  *
   5016  * DESCRIPTION: update parameters from user setting
   5017  *
   5018  * PARAMETERS :
   5019  *   @params  : user setting parameters
   5020  *   @needRestart : [output] if preview need restart upon setting changes
   5021  *
   5022  * RETURN     : int32_t type of status
   5023  *              NO_ERROR  -- success
   5024  *              none-zero failure code
   5025  *==========================================================================*/
   5026 int32_t QCameraParameters::updateParameters(const String8& p,
   5027         bool &needRestart)
   5028 {
   5029     int32_t final_rc = NO_ERROR;
   5030     int32_t rc;
   5031     m_bNeedRestart = false;
   5032     QCameraParameters params(p);
   5033 
   5034     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   5035         LOGE("Failed to initialize group update table");
   5036         rc = BAD_TYPE;
   5037         goto UPDATE_PARAM_DONE;
   5038     }
   5039 
   5040     if ((rc = setPreviewSize(params)))                  final_rc = rc;
   5041     if ((rc = setVideoSize(params)))                    final_rc = rc;
   5042     if ((rc = setPictureSize(params)))                  final_rc = rc;
   5043     if ((rc = setPreviewFormat(params)))                final_rc = rc;
   5044     if ((rc = setPictureFormat(params)))                final_rc = rc;
   5045     if ((rc = setJpegQuality(params)))                  final_rc = rc;
   5046     if ((rc = setOrientation(params)))                  final_rc = rc;
   5047     if ((rc = setRotation(params)))                     final_rc = rc;
   5048     if ((rc = setVideoRotation(params)))                final_rc = rc;
   5049     if ((rc = setNoDisplayMode(params)))                final_rc = rc;
   5050     if ((rc = setZslMode(params)))                      final_rc = rc;
   5051     if ((rc = setZslAttributes(params)))                final_rc = rc;
   5052     if ((rc = setCameraMode(params)))                   final_rc = rc;
   5053     if ((rc = setSceneSelectionMode(params)))           final_rc = rc;
   5054     if ((rc = setRecordingHint(params)))                final_rc = rc;
   5055     if ((rc = setRdiMode(params)))                      final_rc = rc;
   5056     if ((rc = setSecureMode(params)))                   final_rc = rc;
   5057     if ((rc = setPreviewFrameRate(params)))             final_rc = rc;
   5058     if ((rc = setPreviewFpsRange(params)))              final_rc = rc;
   5059     if ((rc = setAutoExposure(params)))                 final_rc = rc;
   5060     if ((rc = setEffect(params)))                       final_rc = rc;
   5061     if ((rc = setBrightness(params)))                   final_rc = rc;
   5062     if ((rc = setZoom(params)))                         final_rc = rc;
   5063     if ((rc = setSharpness(params)))                    final_rc = rc;
   5064     if ((rc = setSaturation(params)))                   final_rc = rc;
   5065     if ((rc = setContrast(params)))                     final_rc = rc;
   5066     if ((rc = setFocusMode(params)))                    final_rc = rc;
   5067     if ((rc = setISOValue(params)))                     final_rc = rc;
   5068     if ((rc = setContinuousISO(params)))                final_rc = rc;
   5069     if ((rc = setExposureTime(params)))                 final_rc = rc;
   5070     if ((rc = setSkinToneEnhancement(params)))          final_rc = rc;
   5071     if ((rc = setFlash(params)))                        final_rc = rc;
   5072     if ((rc = setAecLock(params)))                      final_rc = rc;
   5073     if ((rc = setAwbLock(params)))                      final_rc = rc;
   5074     if ((rc = setLensShadeValue(params)))               final_rc = rc;
   5075     if ((rc = setMCEValue(params)))                     final_rc = rc;
   5076     if ((rc = setDISValue(params)))                     final_rc = rc;
   5077     if ((rc = setAntibanding(params)))                  final_rc = rc;
   5078     if ((rc = setExposureCompensation(params)))         final_rc = rc;
   5079     if ((rc = setWhiteBalance(params)))                 final_rc = rc;
   5080     if ((rc = setHDRMode(params)))                      final_rc = rc;
   5081     if ((rc = setHDRNeed1x(params)))                    final_rc = rc;
   5082     if ((rc = setManualWhiteBalance(params)))           final_rc = rc;
   5083     if ((rc = setSceneMode(params)))                    final_rc = rc;
   5084     if ((rc = setFocusAreas(params)))                   final_rc = rc;
   5085     if ((rc = setFocusPosition(params)))                final_rc = rc;
   5086     if ((rc = setMeteringAreas(params)))                final_rc = rc;
   5087     if ((rc = setSelectableZoneAf(params)))             final_rc = rc;
   5088     if ((rc = setRedeyeReduction(params)))              final_rc = rc;
   5089     if ((rc = setAEBracket(params)))                    final_rc = rc;
   5090     if ((rc = setAutoHDR(params)))                      final_rc = rc;
   5091     if ((rc = setGpsLocation(params)))                  final_rc = rc;
   5092     if ((rc = setWaveletDenoise(params)))               final_rc = rc;
   5093     if ((rc = setFaceRecognition(params)))              final_rc = rc;
   5094     if ((rc = setFlip(params)))                         final_rc = rc;
   5095     if ((rc = setVideoHDR(params)))                     final_rc = rc;
   5096     if ((rc = setVtEnable(params)))                     final_rc = rc;
   5097     if ((rc = setAFBracket(params)))                    final_rc = rc;
   5098     if ((rc = setReFocus(params)))                      final_rc = rc;
   5099     if ((rc = setChromaFlash(params)))                  final_rc = rc;
   5100     if ((rc = setTruePortrait(params)))                 final_rc = rc;
   5101     if ((rc = setOptiZoom(params)))                     final_rc = rc;
   5102     if ((rc = setBurstLEDOnPeriod(params)))             final_rc = rc;
   5103     if ((rc = setRetroActiveBurstNum(params)))          final_rc = rc;
   5104     if ((rc = setSnapshotFDReq(params)))                final_rc = rc;
   5105     if ((rc = setTintlessValue(params)))                final_rc = rc;
   5106     if ((rc = setCDSMode(params)))                      final_rc = rc;
   5107     if ((rc = setTemporalDenoise(params)))              final_rc = rc;
   5108     if ((rc = setCacheVideoBuffers(params)))            final_rc = rc;
   5109     if ((rc = setInitialExposureIndex(params)))         final_rc = rc;
   5110     if ((rc = setInstantCapture(params)))               final_rc = rc;
   5111     if ((rc = setInstantAEC(params)))                   final_rc = rc;
   5112 
   5113     // update live snapshot size after all other parameters are set
   5114     if ((rc = setLiveSnapshotSize(params)))             final_rc = rc;
   5115     if ((rc = setJpegThumbnailSize(params)))            final_rc = rc;
   5116     if ((rc = setStatsDebugMask()))                     final_rc = rc;
   5117     if ((rc = setPAAF()))                               final_rc = rc;
   5118     if ((rc = setMobicat(params)))                      final_rc = rc;
   5119     if ((rc = setSeeMore(params)))                      final_rc = rc;
   5120     if ((rc = setStillMore(params)))                    final_rc = rc;
   5121     if ((rc = setCustomParams(params)))                 final_rc = rc;
   5122     if ((rc = setNoiseReductionMode(params)))           final_rc = rc;
   5123 
   5124     if ((rc = setLongshotParam(params)))                final_rc = rc;
   5125     if ((rc = setDualLedCalibration(params)))           final_rc = rc;
   5126 
   5127     setVideoBatchSize();
   5128     setLowLightCapture();
   5129 
   5130     if ((rc = updateFlash(false)))                      final_rc = rc;
   5131 
   5132 #ifdef TARGET_TS_MAKEUP
   5133     if (params.get(KEY_TS_MAKEUP) != NULL) {
   5134         set(KEY_TS_MAKEUP,params.get(KEY_TS_MAKEUP));
   5135         final_rc = rc;
   5136     }
   5137     if (params.get(KEY_TS_MAKEUP_WHITEN) != NULL) {
   5138         set(KEY_TS_MAKEUP_WHITEN,params.get(KEY_TS_MAKEUP_WHITEN));
   5139         final_rc = rc;
   5140     }
   5141     if (params.get(KEY_TS_MAKEUP_CLEAN) != NULL) {
   5142         set(KEY_TS_MAKEUP_CLEAN,params.get(KEY_TS_MAKEUP_CLEAN));
   5143         final_rc = rc;
   5144     }
   5145 #endif
   5146 
   5147     if ((rc = setAdvancedCaptureMode()))                final_rc = rc;
   5148 UPDATE_PARAM_DONE:
   5149     needRestart = m_bNeedRestart;
   5150     return final_rc;
   5151 }
   5152 
   5153 /*===========================================================================
   5154  * FUNCTION   : commitParameters
   5155  *
   5156  * DESCRIPTION: commit parameter changes to backend
   5157  *
   5158  * PARAMETERS : none
   5159  *
   5160  * RETURN     : int32_t type of status
   5161  *              NO_ERROR  -- success
   5162  *              none-zero failure code
   5163  *==========================================================================*/
   5164 int32_t QCameraParameters::commitParameters()
   5165 {
   5166     return commitSetBatch();
   5167 }
   5168 
   5169 /*===========================================================================
   5170  * FUNCTION   : initDefaultParameters
   5171  *
   5172  * DESCRIPTION: initialize default parameters for the first time
   5173  *
   5174  * PARAMETERS : none
   5175  *
   5176  * RETURN     : int32_t type of status
   5177  *              NO_ERROR  -- success
   5178  *              none-zero failure code
   5179  *==========================================================================*/
   5180 int32_t QCameraParameters::initDefaultParameters()
   5181 {
   5182     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   5183         LOGE("Failed to initialize group update table");
   5184         return BAD_TYPE;
   5185     }
   5186     int32_t hal_version = CAM_HAL_V1;
   5187     ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HAL_VERSION, hal_version);
   5188 
   5189     /*************************Initialize Values******************************/
   5190     // Set read only parameters from camera capability
   5191     set(KEY_SMOOTH_ZOOM_SUPPORTED,
   5192         m_pCapability->smooth_zoom_supported? VALUE_TRUE : VALUE_FALSE);
   5193     set(KEY_ZOOM_SUPPORTED,
   5194         m_pCapability->zoom_supported? VALUE_TRUE : VALUE_FALSE);
   5195     set(KEY_VIDEO_SNAPSHOT_SUPPORTED,
   5196         m_pCapability->video_snapshot_supported? VALUE_TRUE : VALUE_FALSE);
   5197     set(KEY_VIDEO_STABILIZATION_SUPPORTED,
   5198         m_pCapability->video_stablization_supported? VALUE_TRUE : VALUE_FALSE);
   5199     set(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED,
   5200         m_pCapability->auto_exposure_lock_supported? VALUE_TRUE : VALUE_FALSE);
   5201     set(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED,
   5202         m_pCapability->auto_wb_lock_supported? VALUE_TRUE : VALUE_FALSE);
   5203     set(KEY_MAX_NUM_DETECTED_FACES_HW, m_pCapability->max_num_roi);
   5204     set(KEY_MAX_NUM_DETECTED_FACES_SW, m_pCapability->max_num_roi);
   5205     set(KEY_QC_MAX_NUM_REQUESTED_FACES, m_pCapability->max_num_roi);
   5206     // Set focal length, horizontal view angle, and vertical view angle
   5207     setFloat(KEY_FOCAL_LENGTH, m_pCapability->focal_length);
   5208     setFloat(KEY_HORIZONTAL_VIEW_ANGLE, m_pCapability->hor_view_angle);
   5209     setFloat(KEY_VERTICAL_VIEW_ANGLE, m_pCapability->ver_view_angle);
   5210     set(QCameraParameters::KEY_FOCUS_DISTANCES, "Infinity,Infinity,Infinity");
   5211     set(KEY_QC_AUTO_HDR_SUPPORTED,
   5212         (m_pCapability->auto_hdr_supported)? VALUE_TRUE : VALUE_FALSE);
   5213     // Set supported preview sizes
   5214     if (m_pCapability->preview_sizes_tbl_cnt > 0 &&
   5215         m_pCapability->preview_sizes_tbl_cnt <= MAX_SIZES_CNT) {
   5216         String8 previewSizeValues = createSizesString(
   5217                 m_pCapability->preview_sizes_tbl, m_pCapability->preview_sizes_tbl_cnt);
   5218         set(KEY_SUPPORTED_PREVIEW_SIZES, previewSizeValues.string());
   5219         LOGH("supported preview sizes: %s", previewSizeValues.string());
   5220         // Set default preview size
   5221         CameraParameters::setPreviewSize(m_pCapability->preview_sizes_tbl[0].width,
   5222                                          m_pCapability->preview_sizes_tbl[0].height);
   5223     } else {
   5224         LOGW("supported preview sizes cnt is 0 or exceeds max!!!");
   5225     }
   5226 
   5227     // Set supported video sizes
   5228     if (m_pCapability->video_sizes_tbl_cnt > 0 &&
   5229         m_pCapability->video_sizes_tbl_cnt <= MAX_SIZES_CNT) {
   5230         String8 videoSizeValues = createSizesString(
   5231                 m_pCapability->video_sizes_tbl, m_pCapability->video_sizes_tbl_cnt);
   5232         set(KEY_SUPPORTED_VIDEO_SIZES, videoSizeValues.string());
   5233         LOGH("supported video sizes: %s", videoSizeValues.string());
   5234         // Set default video size
   5235         CameraParameters::setVideoSize(m_pCapability->video_sizes_tbl[0].width,
   5236                                        m_pCapability->video_sizes_tbl[0].height);
   5237 
   5238         //Set preferred Preview size for video
   5239         String8 vSize = createSizesString(&m_pCapability->preview_sizes_tbl[0], 1);
   5240         set(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO, vSize.string());
   5241     } else {
   5242         LOGW("supported video sizes cnt is 0 or exceeds max!!!");
   5243     }
   5244 
   5245     // Set supported picture sizes
   5246     if (m_pCapability->picture_sizes_tbl_cnt > 0 &&
   5247         m_pCapability->picture_sizes_tbl_cnt <= MAX_SIZES_CNT) {
   5248         String8 pictureSizeValues = createSizesString(
   5249                 m_pCapability->picture_sizes_tbl, m_pCapability->picture_sizes_tbl_cnt);
   5250         set(KEY_SUPPORTED_PICTURE_SIZES, pictureSizeValues.string());
   5251         LOGH("supported pic sizes: %s", pictureSizeValues.string());
   5252         // Set default picture size to the smallest resolution
   5253         CameraParameters::setPictureSize(
   5254            m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].width,
   5255            m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].height);
   5256     } else {
   5257         LOGW("supported picture sizes cnt is 0 or exceeds max!!!");
   5258     }
   5259 
   5260     // Need check if scale should be enabled
   5261     if (m_pCapability->scale_picture_sizes_cnt > 0 &&
   5262         m_pCapability->scale_picture_sizes_cnt <= MAX_SCALE_SIZES_CNT){
   5263         //get scale size, enable scaling. And re-set picture size table with scale sizes
   5264         m_reprocScaleParam.setScaleEnable(true);
   5265         int rc_s = m_reprocScaleParam.setScaleSizeTbl(
   5266             m_pCapability->scale_picture_sizes_cnt, m_pCapability->scale_picture_sizes,
   5267             m_pCapability->picture_sizes_tbl_cnt, m_pCapability->picture_sizes_tbl);
   5268         if(rc_s == NO_ERROR){
   5269             cam_dimension_t *totalSizeTbl = m_reprocScaleParam.getTotalSizeTbl();
   5270             size_t totalSizeCnt = m_reprocScaleParam.getTotalSizeTblCnt();
   5271             String8 pictureSizeValues = createSizesString(totalSizeTbl, totalSizeCnt);
   5272             set(KEY_SUPPORTED_PICTURE_SIZES, pictureSizeValues.string());
   5273             LOGH("scaled supported pic sizes: %s", pictureSizeValues.string());
   5274         }else{
   5275             m_reprocScaleParam.setScaleEnable(false);
   5276             LOGW("reset scaled picture size table failed.");
   5277         }
   5278     }else{
   5279         m_reprocScaleParam.setScaleEnable(false);
   5280     }
   5281 
   5282     // Set supported thumbnail sizes
   5283     String8 thumbnailSizeValues = createSizesString(
   5284             THUMBNAIL_SIZES_MAP,
   5285             PARAM_MAP_SIZE(THUMBNAIL_SIZES_MAP));
   5286     set(KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, thumbnailSizeValues.string());
   5287     // Set default thumnail size
   5288     set(KEY_JPEG_THUMBNAIL_WIDTH, THUMBNAIL_SIZES_MAP[0].width);
   5289     set(KEY_JPEG_THUMBNAIL_HEIGHT, THUMBNAIL_SIZES_MAP[0].height);
   5290 
   5291     // Set supported livesnapshot sizes
   5292     if (m_pCapability->livesnapshot_sizes_tbl_cnt > 0 &&
   5293         m_pCapability->livesnapshot_sizes_tbl_cnt <= MAX_SIZES_CNT) {
   5294         String8 liveSnpashotSizeValues = createSizesString(
   5295                 m_pCapability->livesnapshot_sizes_tbl,
   5296                 m_pCapability->livesnapshot_sizes_tbl_cnt);
   5297         set(KEY_QC_SUPPORTED_LIVESNAPSHOT_SIZES, liveSnpashotSizeValues.string());
   5298         LOGD("supported live snapshot sizes: %s", liveSnpashotSizeValues.string());
   5299         m_LiveSnapshotSize =
   5300             m_pCapability->livesnapshot_sizes_tbl[m_pCapability->livesnapshot_sizes_tbl_cnt-1];
   5301     }
   5302 
   5303     // Set supported preview formats
   5304     String8 previewFormatValues = createValuesString(
   5305             m_pCapability->supported_preview_fmts,
   5306             m_pCapability->supported_preview_fmt_cnt,
   5307             PREVIEW_FORMATS_MAP,
   5308             PARAM_MAP_SIZE(PREVIEW_FORMATS_MAP));
   5309     set(KEY_SUPPORTED_PREVIEW_FORMATS, previewFormatValues.string());
   5310     // Set default preview format
   5311     CameraParameters::setPreviewFormat(PIXEL_FORMAT_YUV420SP);
   5312 
   5313     // Set default Video Format as OPAQUE
   5314     // Internally both Video and Camera subsystems use NV21_VENUS
   5315     set(KEY_VIDEO_FRAME_FORMAT, PIXEL_FORMAT_ANDROID_OPAQUE);
   5316 
   5317     // Set supported picture formats
   5318     String8 pictureTypeValues(PIXEL_FORMAT_JPEG);
   5319     String8 str = createValuesString(
   5320             m_pCapability->supported_raw_fmts,
   5321             m_pCapability->supported_raw_fmt_cnt,
   5322             PICTURE_TYPES_MAP,
   5323             PARAM_MAP_SIZE(PICTURE_TYPES_MAP));
   5324     if (str.string() != NULL) {
   5325         pictureTypeValues.append(",");
   5326         pictureTypeValues.append(str);
   5327     }
   5328 
   5329     set(KEY_SUPPORTED_PICTURE_FORMATS, pictureTypeValues.string());
   5330     // Set default picture Format
   5331     CameraParameters::setPictureFormat(PIXEL_FORMAT_JPEG);
   5332     // Set raw image size
   5333     char raw_size_str[32];
   5334     snprintf(raw_size_str, sizeof(raw_size_str), "%dx%d",
   5335              m_pCapability->raw_dim[0].width, m_pCapability->raw_dim[0].height);
   5336     set(KEY_QC_RAW_PICUTRE_SIZE, raw_size_str);
   5337     LOGD("KEY_QC_RAW_PICUTRE_SIZE: w: %d, h: %d ",
   5338        m_pCapability->raw_dim[0].width, m_pCapability->raw_dim[0].height);
   5339 
   5340     //set default jpeg quality and thumbnail quality
   5341     set(KEY_JPEG_QUALITY, 85);
   5342     set(KEY_JPEG_THUMBNAIL_QUALITY, 85);
   5343 
   5344     // Set FPS ranges
   5345     if (m_pCapability->fps_ranges_tbl_cnt > 0 &&
   5346         m_pCapability->fps_ranges_tbl_cnt <= MAX_SIZES_CNT) {
   5347         int default_fps_index = 0;
   5348         String8 fpsRangeValues = createFpsRangeString(m_pCapability->fps_ranges_tbl,
   5349                                                       m_pCapability->fps_ranges_tbl_cnt,
   5350                                                       default_fps_index);
   5351         set(KEY_SUPPORTED_PREVIEW_FPS_RANGE, fpsRangeValues.string());
   5352 
   5353         int min_fps =
   5354             int(m_pCapability->fps_ranges_tbl[default_fps_index].min_fps * 1000);
   5355         int max_fps =
   5356             int(m_pCapability->fps_ranges_tbl[default_fps_index].max_fps * 1000);
   5357         m_default_fps_range = m_pCapability->fps_ranges_tbl[default_fps_index];
   5358         //Set video fps same as preview fps
   5359         setPreviewFpsRange(min_fps, max_fps, min_fps, max_fps);
   5360 
   5361         // Set legacy preview fps
   5362         String8 fpsValues = createFpsString(m_pCapability->fps_ranges_tbl[default_fps_index]);
   5363         set(KEY_SUPPORTED_PREVIEW_FRAME_RATES, fpsValues.string());
   5364         LOGH("supported fps rates: %s", fpsValues.string());
   5365         CameraParameters::setPreviewFrameRate(int(m_pCapability->fps_ranges_tbl[default_fps_index].max_fps));
   5366     } else {
   5367         LOGW("supported fps ranges cnt is 0 or exceeds max!!!");
   5368     }
   5369 
   5370     // Set supported focus modes
   5371     if (m_pCapability->supported_focus_modes_cnt > 0) {
   5372         String8 focusModeValues = createValuesString(
   5373                 m_pCapability->supported_focus_modes,
   5374                 m_pCapability->supported_focus_modes_cnt,
   5375                 FOCUS_MODES_MAP,
   5376                 PARAM_MAP_SIZE(FOCUS_MODES_MAP));
   5377         set(KEY_SUPPORTED_FOCUS_MODES, focusModeValues);
   5378 
   5379         // Set default focus mode and update corresponding parameter buf
   5380         const char *focusMode = lookupNameByValue(FOCUS_MODES_MAP,
   5381                 PARAM_MAP_SIZE(FOCUS_MODES_MAP),
   5382                 m_pCapability->supported_focus_modes[0]);
   5383         if (focusMode != NULL) {
   5384             setFocusMode(focusMode);
   5385         } else {
   5386             setFocusMode(FOCUS_MODE_FIXED);
   5387         }
   5388     } else {
   5389         LOGW("supported focus modes cnt is 0!!!");
   5390     }
   5391 
   5392     // Set focus areas
   5393     if (m_pCapability->max_num_focus_areas > MAX_ROI) {
   5394         m_pCapability->max_num_focus_areas = MAX_ROI;
   5395     }
   5396     set(KEY_MAX_NUM_FOCUS_AREAS, m_pCapability->max_num_focus_areas);
   5397     if (m_pCapability->max_num_focus_areas > 0) {
   5398         setFocusAreas(DEFAULT_CAMERA_AREA);
   5399     }
   5400 
   5401     // Set metering areas
   5402     if (m_pCapability->max_num_metering_areas > MAX_ROI) {
   5403         m_pCapability->max_num_metering_areas = MAX_ROI;
   5404     }
   5405     set(KEY_MAX_NUM_METERING_AREAS, m_pCapability->max_num_metering_areas);
   5406     if (m_pCapability->max_num_metering_areas > 0) {
   5407         setMeteringAreas(DEFAULT_CAMERA_AREA);
   5408     }
   5409 
   5410     // set focus position, we should get them from m_pCapability
   5411     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX] = 0;
   5412     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX] = 1023;
   5413     set(KEY_QC_MIN_FOCUS_POS_INDEX,
   5414             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX]);
   5415     set(KEY_QC_MAX_FOCUS_POS_INDEX,
   5416             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX]);
   5417 
   5418     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE] = 0;
   5419     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE] = 1023;
   5420     set(KEY_QC_MIN_FOCUS_POS_DAC,
   5421             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE]);
   5422     set(KEY_QC_MAX_FOCUS_POS_DAC,
   5423             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE]);
   5424 
   5425     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO] = 0;
   5426     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO] = 100;
   5427     set(KEY_QC_MIN_FOCUS_POS_RATIO,
   5428             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO]);
   5429     set(KEY_QC_MAX_FOCUS_POS_RATIO,
   5430             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO]);
   5431 
   5432     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] = 0;
   5433     if (m_pCapability->min_focus_distance > 0) {
   5434         m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] =
   5435                 m_pCapability->min_focus_distance;
   5436     } else {
   5437         m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] = 0;
   5438     }
   5439     setFloat(KEY_QC_MIN_FOCUS_POS_DIOPTER,
   5440             m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER]);
   5441     setFloat(KEY_QC_MAX_FOCUS_POS_DIOPTER,
   5442             m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER]);
   5443 
   5444     //set supported manual focus modes
   5445     String8 manualFocusModes(VALUE_OFF);
   5446     if (m_pCapability->supported_focus_modes_cnt > 1 &&
   5447         m_pCapability->min_focus_distance > 0) {
   5448         manualFocusModes.append(",");
   5449         manualFocusModes.append(KEY_QC_FOCUS_SCALE_MODE);
   5450         manualFocusModes.append(",");
   5451         manualFocusModes.append(KEY_QC_FOCUS_DIOPTER_MODE);
   5452     }
   5453     set(KEY_QC_SUPPORTED_MANUAL_FOCUS_MODES, manualFocusModes.string());
   5454 
   5455     // Set Saturation
   5456     set(KEY_QC_MIN_SATURATION, m_pCapability->saturation_ctrl.min_value);
   5457     set(KEY_QC_MAX_SATURATION, m_pCapability->saturation_ctrl.max_value);
   5458     set(KEY_QC_SATURATION_STEP, m_pCapability->saturation_ctrl.step);
   5459     setSaturation(m_pCapability->saturation_ctrl.def_value);
   5460 
   5461     // Set Sharpness
   5462     set(KEY_QC_MIN_SHARPNESS, m_pCapability->sharpness_ctrl.min_value);
   5463     set(KEY_QC_MAX_SHARPNESS, m_pCapability->sharpness_ctrl.max_value);
   5464     set(KEY_QC_SHARPNESS_STEP, m_pCapability->sharpness_ctrl.step);
   5465     setSharpness(m_pCapability->sharpness_ctrl.def_value);
   5466 
   5467     // Set Contrast
   5468     set(KEY_QC_MIN_CONTRAST, m_pCapability->contrast_ctrl.min_value);
   5469     set(KEY_QC_MAX_CONTRAST, m_pCapability->contrast_ctrl.max_value);
   5470     set(KEY_QC_CONTRAST_STEP, m_pCapability->contrast_ctrl.step);
   5471     setContrast(m_pCapability->contrast_ctrl.def_value);
   5472 
   5473     // Set SCE factor
   5474     set(KEY_QC_MIN_SCE_FACTOR, m_pCapability->sce_ctrl.min_value); // -100
   5475     set(KEY_QC_MAX_SCE_FACTOR, m_pCapability->sce_ctrl.max_value); // 100
   5476     set(KEY_QC_SCE_FACTOR_STEP, m_pCapability->sce_ctrl.step);     // 10
   5477     setSkinToneEnhancement(m_pCapability->sce_ctrl.def_value);     // 0
   5478 
   5479     // Set Brightness
   5480     set(KEY_QC_MIN_BRIGHTNESS, m_pCapability->brightness_ctrl.min_value); // 0
   5481     set(KEY_QC_MAX_BRIGHTNESS, m_pCapability->brightness_ctrl.max_value); // 6
   5482     set(KEY_QC_BRIGHTNESS_STEP, m_pCapability->brightness_ctrl.step);     // 1
   5483     setBrightness(m_pCapability->brightness_ctrl.def_value);
   5484 
   5485     // Set Auto exposure
   5486     String8 autoExposureValues = createValuesString(
   5487             m_pCapability->supported_aec_modes,
   5488             m_pCapability->supported_aec_modes_cnt,
   5489             AUTO_EXPOSURE_MAP,
   5490             PARAM_MAP_SIZE(AUTO_EXPOSURE_MAP));
   5491     set(KEY_QC_SUPPORTED_AUTO_EXPOSURE, autoExposureValues.string());
   5492     setAutoExposure(AUTO_EXPOSURE_FRAME_AVG);
   5493 
   5494     // Set Exposure Compensation
   5495     set(KEY_MAX_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_max); // 12
   5496     set(KEY_MIN_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_min); // -12
   5497     setFloat(KEY_EXPOSURE_COMPENSATION_STEP, m_pCapability->exposure_compensation_step); // 1/6
   5498     setExposureCompensation(m_pCapability->exposure_compensation_default); // 0
   5499 
   5500     // Set Instant AEC modes
   5501     String8 instantAECModes = createValuesString(
   5502             m_pCapability->supported_instant_aec_modes,
   5503             m_pCapability->supported_instant_aec_modes_cnt,
   5504             INSTANT_AEC_MODES_MAP,
   5505             PARAM_MAP_SIZE(INSTANT_AEC_MODES_MAP));
   5506     set(KEY_QC_INSTANT_AEC_SUPPORTED_MODES, instantAECModes.string());
   5507 
   5508     // Set Instant Capture modes
   5509     String8 instantCaptureModes = createValuesString(
   5510             m_pCapability->supported_instant_aec_modes,
   5511             m_pCapability->supported_instant_aec_modes_cnt,
   5512             INSTANT_CAPTURE_MODES_MAP,
   5513             PARAM_MAP_SIZE(INSTANT_CAPTURE_MODES_MAP));
   5514     set(KEY_QC_INSTANT_CAPTURE_SUPPORTED_MODES, instantCaptureModes.string());
   5515 
   5516 
   5517     // Set Antibanding
   5518     String8 antibandingValues = createValuesString(
   5519             m_pCapability->supported_antibandings,
   5520             m_pCapability->supported_antibandings_cnt,
   5521             ANTIBANDING_MODES_MAP,
   5522             PARAM_MAP_SIZE(ANTIBANDING_MODES_MAP));
   5523     set(KEY_SUPPORTED_ANTIBANDING, antibandingValues);
   5524     setAntibanding(ANTIBANDING_OFF);
   5525 
   5526     // Set Effect
   5527     String8 effectValues = createValuesString(
   5528             m_pCapability->supported_effects,
   5529             m_pCapability->supported_effects_cnt,
   5530             EFFECT_MODES_MAP,
   5531             PARAM_MAP_SIZE(EFFECT_MODES_MAP));
   5532 
   5533     if (m_pCapability->supported_effects_cnt > 0) {
   5534         set(KEY_SUPPORTED_EFFECTS, effectValues);
   5535     } else {
   5536         LOGW("Color effects are not available");
   5537         set(KEY_SUPPORTED_EFFECTS, EFFECT_NONE);
   5538     }
   5539     setEffect(EFFECT_NONE);
   5540 
   5541     // Set WhiteBalance
   5542     String8 whitebalanceValues = createValuesString(
   5543             m_pCapability->supported_white_balances,
   5544             m_pCapability->supported_white_balances_cnt,
   5545             WHITE_BALANCE_MODES_MAP,
   5546             PARAM_MAP_SIZE(WHITE_BALANCE_MODES_MAP));
   5547     set(KEY_SUPPORTED_WHITE_BALANCE, whitebalanceValues);
   5548     setWhiteBalance(WHITE_BALANCE_AUTO);
   5549 
   5550     // set supported wb cct, we should get them from m_pCapability
   5551     m_pCapability->min_wb_cct = 2000;
   5552     m_pCapability->max_wb_cct = 8000;
   5553     set(KEY_QC_MIN_WB_CCT, m_pCapability->min_wb_cct);
   5554     set(KEY_QC_MAX_WB_CCT, m_pCapability->max_wb_cct);
   5555 
   5556     // set supported wb rgb gains, ideally we should get them from m_pCapability
   5557     //but for now hardcode.
   5558     m_pCapability->min_wb_gain = 1.0;
   5559     m_pCapability->max_wb_gain = 4.0;
   5560     setFloat(KEY_QC_MIN_WB_GAIN, m_pCapability->min_wb_gain);
   5561     setFloat(KEY_QC_MAX_WB_GAIN, m_pCapability->max_wb_gain);
   5562 
   5563     //set supported manual wb modes
   5564     String8 manualWBModes(VALUE_OFF);
   5565     if(m_pCapability->sensor_type.sens_type != CAM_SENSOR_YUV) {
   5566         manualWBModes.append(",");
   5567         manualWBModes.append(KEY_QC_WB_CCT_MODE);
   5568         manualWBModes.append(",");
   5569         manualWBModes.append(KEY_QC_WB_GAIN_MODE);
   5570     }
   5571     set(KEY_QC_SUPPORTED_MANUAL_WB_MODES, manualWBModes.string());
   5572 
   5573     // Set Flash mode
   5574     if(m_pCapability->supported_flash_modes_cnt > 0) {
   5575        String8 flashValues = createValuesString(
   5576                m_pCapability->supported_flash_modes,
   5577                m_pCapability->supported_flash_modes_cnt,
   5578                FLASH_MODES_MAP,
   5579                PARAM_MAP_SIZE(FLASH_MODES_MAP));
   5580        set(KEY_SUPPORTED_FLASH_MODES, flashValues);
   5581        setFlash(FLASH_MODE_OFF);
   5582     } else {
   5583         LOGW("supported flash modes cnt is 0!!!");
   5584     }
   5585 
   5586     // Set Scene Mode
   5587     String8 sceneModeValues = createValuesString(
   5588             m_pCapability->supported_scene_modes,
   5589             m_pCapability->supported_scene_modes_cnt,
   5590             SCENE_MODES_MAP,
   5591             PARAM_MAP_SIZE(SCENE_MODES_MAP));
   5592     set(KEY_SUPPORTED_SCENE_MODES, sceneModeValues);
   5593     setSceneMode(SCENE_MODE_AUTO);
   5594 
   5595     // Set CDS Mode
   5596     String8 cdsModeValues = createValuesStringFromMap(
   5597             CDS_MODES_MAP,
   5598             PARAM_MAP_SIZE(CDS_MODES_MAP));
   5599     set(KEY_QC_SUPPORTED_CDS_MODES, cdsModeValues);
   5600 
   5601     // Set video CDS Mode
   5602     String8 videoCdsModeValues = createValuesStringFromMap(
   5603             CDS_MODES_MAP,
   5604             PARAM_MAP_SIZE(CDS_MODES_MAP));
   5605     set(KEY_QC_SUPPORTED_VIDEO_CDS_MODES, videoCdsModeValues);
   5606 
   5607     // Set TNR Mode
   5608     String8 tnrModeValues = createValuesStringFromMap(
   5609             ON_OFF_MODES_MAP,
   5610             PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
   5611     set(KEY_QC_SUPPORTED_TNR_MODES, tnrModeValues);
   5612 
   5613     // Set video TNR Mode
   5614     String8 videoTnrModeValues = createValuesStringFromMap(
   5615             ON_OFF_MODES_MAP,
   5616             PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
   5617     set(KEY_QC_SUPPORTED_VIDEO_TNR_MODES, videoTnrModeValues);
   5618 
   5619     // Set ISO Mode
   5620     String8 isoValues = createValuesString(
   5621             m_pCapability->supported_iso_modes,
   5622             m_pCapability->supported_iso_modes_cnt,
   5623             ISO_MODES_MAP,
   5624             PARAM_MAP_SIZE(ISO_MODES_MAP));
   5625     set(KEY_QC_SUPPORTED_ISO_MODES, isoValues);
   5626     setISOValue(ISO_AUTO);
   5627 
   5628     // Set exposure time
   5629     String8 manualExpModes(VALUE_OFF);
   5630     bool expTimeSupported = false;
   5631     bool manualISOSupported = false;
   5632     //capability values are in nano sec, convert to milli sec for upper layers
   5633     char expTimeStr[20];
   5634     double min_exp_time = (double) m_pCapability->exposure_time_range[0] / 1000000.0;
   5635     double max_exp_time = (double) m_pCapability->exposure_time_range[1] / 1000000.0;
   5636     snprintf(expTimeStr, sizeof(expTimeStr), "%f", min_exp_time);
   5637     set(KEY_QC_MIN_EXPOSURE_TIME, expTimeStr);
   5638     snprintf(expTimeStr, sizeof(expTimeStr), "%f", max_exp_time);
   5639     set(KEY_QC_MAX_EXPOSURE_TIME, expTimeStr);
   5640     if ((min_exp_time > 0) && (max_exp_time > min_exp_time)) {
   5641         manualExpModes.append(",");
   5642         manualExpModes.append(KEY_QC_EXP_TIME_PRIORITY);
   5643         expTimeSupported = true;
   5644     }
   5645     LOGH(", Exposure time min %f ms, max %f ms",
   5646             min_exp_time, max_exp_time);
   5647 
   5648     // Set iso
   5649     set(KEY_QC_MIN_ISO, m_pCapability->sensitivity_range.min_sensitivity);
   5650     set(KEY_QC_MAX_ISO, m_pCapability->sensitivity_range.max_sensitivity);
   5651     LOGH(", ISO min %d, max %d",
   5652             m_pCapability->sensitivity_range.min_sensitivity,
   5653             m_pCapability->sensitivity_range.max_sensitivity);
   5654     if ((m_pCapability->sensitivity_range.min_sensitivity > 0) &&
   5655             (m_pCapability->sensitivity_range.max_sensitivity >
   5656                     m_pCapability->sensitivity_range.min_sensitivity)) {
   5657         manualExpModes.append(",");
   5658         manualExpModes.append(KEY_QC_ISO_PRIORITY);
   5659         manualISOSupported = true;
   5660     }
   5661     if (expTimeSupported && manualISOSupported) {
   5662         manualExpModes.append(",");
   5663         manualExpModes.append(KEY_QC_USER_SETTING);
   5664     }
   5665     //finally set supported manual exposure modes
   5666     set(KEY_QC_SUPPORTED_MANUAL_EXPOSURE_MODES, manualExpModes.string());
   5667 
   5668     // Set HFR
   5669     String8 hfrValues = createHfrValuesString(
   5670             m_pCapability->hfr_tbl,
   5671             m_pCapability->hfr_tbl_cnt,
   5672             HFR_MODES_MAP,
   5673             PARAM_MAP_SIZE(HFR_MODES_MAP));
   5674     set(KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES, hfrValues.string());
   5675     set(KEY_QC_VIDEO_HIGH_SPEED_RECORDING, "off");
   5676     set(KEY_QC_VIDEO_HIGH_FRAME_RATE, "off");
   5677     String8 hfrSizeValues = createHfrSizesString(
   5678             m_pCapability->hfr_tbl,
   5679             m_pCapability->hfr_tbl_cnt);
   5680     set(KEY_QC_SUPPORTED_HFR_SIZES, hfrSizeValues.string());
   5681     LOGD("HFR values = %s HFR Sizes = %s", hfrValues.string(), hfrSizeValues.string());
   5682     setHighFrameRate(CAM_HFR_MODE_OFF);
   5683 
   5684     // Set Focus algorithms
   5685     String8 focusAlgoValues = createValuesString(
   5686             m_pCapability->supported_focus_algos,
   5687             m_pCapability->supported_focus_algos_cnt,
   5688             FOCUS_ALGO_MAP,
   5689             PARAM_MAP_SIZE(FOCUS_ALGO_MAP));
   5690     set(KEY_QC_SUPPORTED_FOCUS_ALGOS, focusAlgoValues);
   5691     setSelectableZoneAf(FOCUS_ALGO_AUTO);
   5692 
   5693     // Set Zoom Ratios
   5694     if (m_pCapability->zoom_supported > 0) {
   5695         String8 zoomRatioValues = createZoomRatioValuesString(
   5696                 m_pCapability->zoom_ratio_tbl,
   5697                 m_pCapability->zoom_ratio_tbl_cnt);
   5698         set(KEY_ZOOM_RATIOS, zoomRatioValues);
   5699         set(KEY_MAX_ZOOM, (int)(m_pCapability->zoom_ratio_tbl_cnt - 1));
   5700         setZoom(0);
   5701     }
   5702 
   5703     // Set Bracketing/HDR
   5704     char prop[PROPERTY_VALUE_MAX];
   5705     memset(prop, 0, sizeof(prop));
   5706     property_get("persist.capture.burst.exposures", prop, "");
   5707     if (strlen(prop) > 0) {
   5708         set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
   5709     }
   5710     String8 bracketingValues = createValuesStringFromMap(
   5711             BRACKETING_MODES_MAP,
   5712             PARAM_MAP_SIZE(BRACKETING_MODES_MAP));
   5713     set(KEY_QC_SUPPORTED_AE_BRACKET_MODES, bracketingValues);
   5714     setAEBracket(AE_BRACKET_OFF);
   5715 
   5716     //Set AF Bracketing.
   5717     for (size_t i = 0; i < m_pCapability->supported_focus_modes_cnt; i++) {
   5718         if ((CAM_FOCUS_MODE_AUTO == m_pCapability->supported_focus_modes[i]) &&
   5719                 ((m_pCapability->qcom_supported_feature_mask &
   5720                         CAM_QCOM_FEATURE_UBIFOCUS) > 0)) {
   5721             String8 afBracketingValues = createValuesStringFromMap(
   5722                     AF_BRACKETING_MODES_MAP,
   5723                     PARAM_MAP_SIZE(AF_BRACKETING_MODES_MAP));
   5724             set(KEY_QC_SUPPORTED_AF_BRACKET_MODES, afBracketingValues);
   5725             setAFBracket(AF_BRACKET_OFF);
   5726             break;
   5727          }
   5728     }
   5729 
   5730     //Set Refocus.
   5731     //Re-use ubifocus flag for now.
   5732     for (size_t i = 0; i < m_pCapability->supported_focus_modes_cnt; i++) {
   5733         if ((CAM_FOCUS_MODE_AUTO == m_pCapability->supported_focus_modes[i]) &&
   5734                 (m_pCapability->qcom_supported_feature_mask &
   5735                     CAM_QCOM_FEATURE_REFOCUS) > 0) {
   5736             String8 reFocusValues = createValuesStringFromMap(
   5737                     RE_FOCUS_MODES_MAP,
   5738                     PARAM_MAP_SIZE(RE_FOCUS_MODES_MAP));
   5739             set(KEY_QC_SUPPORTED_RE_FOCUS_MODES, reFocusValues);
   5740             setReFocus(RE_FOCUS_OFF);
   5741         }
   5742     }
   5743 
   5744     //Set Chroma Flash.
   5745     if ((m_pCapability->supported_flash_modes_cnt > 0) &&
   5746             (m_pCapability->qcom_supported_feature_mask &
   5747             CAM_QCOM_FEATURE_CHROMA_FLASH) > 0) {
   5748         String8 chromaFlashValues = createValuesStringFromMap(
   5749                 CHROMA_FLASH_MODES_MAP,
   5750                 PARAM_MAP_SIZE(CHROMA_FLASH_MODES_MAP));
   5751         set(KEY_QC_SUPPORTED_CHROMA_FLASH_MODES, chromaFlashValues);
   5752         setChromaFlash(CHROMA_FLASH_OFF);
   5753     }
   5754 
   5755     //Set Opti Zoom.
   5756     if (m_pCapability->zoom_supported &&
   5757             (m_pCapability->qcom_supported_feature_mask &
   5758             CAM_QCOM_FEATURE_OPTIZOOM) > 0){
   5759         String8 optiZoomValues = createValuesStringFromMap(
   5760                 OPTI_ZOOM_MODES_MAP,
   5761                 PARAM_MAP_SIZE(OPTI_ZOOM_MODES_MAP));
   5762         set(KEY_QC_SUPPORTED_OPTI_ZOOM_MODES, optiZoomValues);
   5763         setOptiZoom(OPTI_ZOOM_OFF);
   5764     }
   5765 
   5766     //Set HDR Type
   5767     uint32_t supported_hdr_modes = m_pCapability->qcom_supported_feature_mask &
   5768             (CAM_QCOM_FEATURE_SENSOR_HDR | CAM_QCOM_FEATURE_HDR);
   5769     if (supported_hdr_modes) {
   5770         if (CAM_QCOM_FEATURE_SENSOR_HDR == supported_hdr_modes) {
   5771             String8 hdrModeValues;
   5772             hdrModeValues.append(HDR_MODE_SENSOR);
   5773             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
   5774             setHDRMode(HDR_MODE_SENSOR);
   5775         } else if (CAM_QCOM_FEATURE_HDR == supported_hdr_modes) {
   5776             String8 hdrModeValues;
   5777             hdrModeValues.append(HDR_MODE_MULTI_FRAME);
   5778             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
   5779             setHDRMode(HDR_MODE_MULTI_FRAME);
   5780         } else {
   5781             String8 hdrModeValues = createValuesStringFromMap(
   5782                     HDR_MODES_MAP,
   5783                     PARAM_MAP_SIZE(HDR_MODES_MAP));
   5784             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
   5785             setHDRMode(HDR_MODE_MULTI_FRAME);
   5786         }
   5787     }
   5788 
   5789     //Set HDR need 1x
   5790     String8 hdrNeed1xValues;
   5791     if (!m_bHDRModeSensor) {
   5792         hdrNeed1xValues = createValuesStringFromMap(TRUE_FALSE_MODES_MAP,
   5793                 PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP));
   5794     } else {
   5795         hdrNeed1xValues.append(VALUE_FALSE);
   5796     }
   5797     setHDRNeed1x(VALUE_FALSE);
   5798     set(KEY_QC_SUPPORTED_HDR_NEED_1X, hdrNeed1xValues);
   5799 
   5800     //Set True Portrait
   5801     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_TRUEPORTRAIT) > 0) {
   5802         String8 truePortraitValues = createValuesStringFromMap(
   5803                 TRUE_PORTRAIT_MODES_MAP,
   5804                 PARAM_MAP_SIZE(TRUE_PORTRAIT_MODES_MAP));
   5805         set(KEY_QC_SUPPORTED_TRUE_PORTRAIT_MODES, truePortraitValues);
   5806     }
   5807 
   5808     // Set Denoise
   5809     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_DENOISE2D) > 0){
   5810     String8 denoiseValues = createValuesStringFromMap(
   5811         DENOISE_ON_OFF_MODES_MAP, PARAM_MAP_SIZE(DENOISE_ON_OFF_MODES_MAP));
   5812     set(KEY_QC_SUPPORTED_DENOISE, denoiseValues.string());
   5813 #ifdef DEFAULT_DENOISE_MODE_ON
   5814     setWaveletDenoise(DENOISE_ON);
   5815 #else
   5816     setWaveletDenoise(DENOISE_OFF);
   5817 #endif
   5818     }
   5819 
   5820     // Set feature enable/disable
   5821     String8 enableDisableValues = createValuesStringFromMap(
   5822             ENABLE_DISABLE_MODES_MAP, PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP));
   5823 
   5824     // Set Lens Shading
   5825     set(KEY_QC_SUPPORTED_LENSSHADE_MODES, enableDisableValues);
   5826     setLensShadeValue(VALUE_ENABLE);
   5827     // Set MCE
   5828     set(KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES, enableDisableValues);
   5829     setMCEValue(VALUE_ENABLE);
   5830 
   5831     // Set DIS
   5832     set(KEY_QC_SUPPORTED_DIS_MODES, enableDisableValues);
   5833     setDISValue(VALUE_DISABLE);
   5834 
   5835     // Set Histogram
   5836     set(KEY_QC_SUPPORTED_HISTOGRAM_MODES,
   5837         m_pCapability->histogram_supported ? enableDisableValues : "");
   5838     set(KEY_QC_HISTOGRAM, VALUE_DISABLE);
   5839 
   5840     //Set Red Eye Reduction
   5841     set(KEY_QC_SUPPORTED_REDEYE_REDUCTION, enableDisableValues);
   5842     setRedeyeReduction(VALUE_DISABLE);
   5843 
   5844     //Set SkinTone Enhancement
   5845     set(KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES, enableDisableValues);
   5846 
   5847     // Enable LTM by default and disable it in HDR & SeeMore usecases
   5848     setToneMapMode(true, false);
   5849 
   5850     // Set feature on/off
   5851     String8 onOffValues = createValuesStringFromMap(
   5852             ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
   5853 
   5854     //Set See more (LLVD)
   5855     if (m_pCapability->qcom_supported_feature_mask &
   5856             CAM_QCOM_FEATURE_LLVD) {
   5857         set(KEY_QC_SUPPORTED_SEE_MORE_MODES, onOffValues);
   5858         setSeeMore(VALUE_OFF);
   5859     }
   5860 
   5861     //Set Still more
   5862     if (m_pCapability->qcom_supported_feature_mask &
   5863             CAM_QCOM_FEATURE_STILLMORE) {
   5864         String8 stillMoreValues = createValuesStringFromMap(
   5865                 STILL_MORE_MODES_MAP,
   5866                 PARAM_MAP_SIZE(STILL_MORE_MODES_MAP));
   5867         set(KEY_QC_SUPPORTED_STILL_MORE_MODES, stillMoreValues);
   5868         setStillMore(STILL_MORE_OFF);
   5869     }
   5870 
   5871     //Set Noise Reduction mode
   5872     if (m_pCapability->qcom_supported_feature_mask &
   5873             CAM_QTI_FEATURE_SW_TNR) {
   5874         String8 noiseReductionModesValues = createValuesStringFromMap(
   5875                 NOISE_REDUCTION_MODES_MAP, PARAM_MAP_SIZE(NOISE_REDUCTION_MODES_MAP));
   5876         set(KEY_QC_NOISE_REDUCTION_MODE_VALUES, noiseReductionModesValues);
   5877         setNoiseReductionMode(VALUE_OFF);
   5878     }
   5879 
   5880     //Set Scene Detection
   5881     set(KEY_QC_SUPPORTED_SCENE_DETECT, onOffValues);
   5882     setSceneDetect(VALUE_OFF);
   5883     m_bHDREnabled = false;
   5884     m_bHDR1xFrameEnabled = false;
   5885 
   5886     m_bHDRThumbnailProcessNeeded = false;
   5887     m_bHDR1xExtraBufferNeeded = true;
   5888     for (uint32_t i=0; i<m_pCapability->hdr_bracketing_setting.num_frames; i++) {
   5889         if (0 == m_pCapability->hdr_bracketing_setting.exp_val.values[i]) {
   5890             m_bHDR1xExtraBufferNeeded = false;
   5891             break;
   5892         }
   5893     }
   5894 
   5895     // Set HDR output scaling
   5896     char value[PROPERTY_VALUE_MAX];
   5897 
   5898     property_get("persist.camera.hdr.outcrop", value, VALUE_DISABLE);
   5899     if (strncmp(VALUE_ENABLE, value, sizeof(VALUE_ENABLE))) {
   5900       m_bHDROutputCropEnabled = false;
   5901     } else {
   5902       m_bHDROutputCropEnabled = true;
   5903     }
   5904 
   5905     //Set Face Detection
   5906     set(KEY_QC_SUPPORTED_FACE_DETECTION, onOffValues);
   5907     set(KEY_QC_FACE_DETECTION, VALUE_OFF);
   5908 
   5909     //Set Face Recognition
   5910     //set(KEY_QC_SUPPORTED_FACE_RECOGNITION, onOffValues);
   5911     //set(KEY_QC_FACE_RECOGNITION, VALUE_OFF);
   5912 
   5913     //Set ZSL
   5914     set(KEY_QC_SUPPORTED_ZSL_MODES, onOffValues);
   5915 #ifdef DEFAULT_ZSL_MODE_ON
   5916     set(KEY_QC_ZSL, VALUE_ON);
   5917     m_bZslMode = true;
   5918 #else
   5919     set(KEY_QC_ZSL, VALUE_OFF);
   5920     m_bZslMode = false;
   5921 #endif
   5922 
   5923     // Check if zsl mode property is enabled.
   5924     // If yes, force the camera to be in zsl mode
   5925     // and force zsl mode to be enabled in dual camera mode.
   5926     memset(value, 0x0, PROPERTY_VALUE_MAX);
   5927     property_get("persist.camera.zsl.mode", value, "0");
   5928     int32_t zsl_mode = atoi(value);
   5929     if((zsl_mode == 1) ||
   5930             (m_bZslMode == true) ||
   5931             (m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON)) {
   5932         LOGH("%d: Forcing Camera to ZSL mode enabled");
   5933         set(KEY_QC_ZSL, VALUE_ON);
   5934         m_bForceZslMode = true;
   5935         m_bZslMode = true;
   5936         int32_t value = m_bForceZslMode;
   5937         ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value);
   5938     }
   5939     m_bZslMode_new = m_bZslMode;
   5940 
   5941     set(KEY_QC_SCENE_SELECTION, VALUE_DISABLE);
   5942 
   5943     // Rdi mode
   5944     set(KEY_QC_SUPPORTED_RDI_MODES, enableDisableValues);
   5945     setRdiMode(VALUE_DISABLE);
   5946 
   5947     // Secure mode
   5948     set(KEY_QC_SUPPORTED_SECURE_MODES, enableDisableValues);
   5949     setSecureMode(VALUE_DISABLE);
   5950 
   5951     //Set video HDR
   5952     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_VIDEO_HDR) > 0) {
   5953         set(KEY_QC_SUPPORTED_VIDEO_HDR_MODES, onOffValues);
   5954         set(KEY_QC_VIDEO_HDR, VALUE_OFF);
   5955     }
   5956 
   5957     //Set HW Sensor Snapshot HDR
   5958     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_SENSOR_HDR)> 0) {
   5959         set(KEY_QC_SUPPORTED_SENSOR_HDR_MODES, onOffValues);
   5960         set(KEY_QC_SENSOR_HDR, VALUE_OFF);
   5961         m_bSensorHDREnabled = false;
   5962     }
   5963 
   5964     // Set VT TimeStamp
   5965     set(KEY_QC_VT_ENABLE, VALUE_DISABLE);
   5966     //Set Touch AF/AEC
   5967     String8 touchValues = createValuesStringFromMap(
   5968             TOUCH_AF_AEC_MODES_MAP, PARAM_MAP_SIZE(TOUCH_AF_AEC_MODES_MAP));
   5969 
   5970     set(KEY_QC_SUPPORTED_TOUCH_AF_AEC, touchValues);
   5971     set(KEY_QC_TOUCH_AF_AEC, TOUCH_AF_AEC_OFF);
   5972 
   5973     //set flip mode
   5974     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) > 0) {
   5975         String8 flipModes = createValuesStringFromMap(
   5976                 FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP));
   5977         set(KEY_QC_SUPPORTED_FLIP_MODES, flipModes);
   5978         set(KEY_QC_PREVIEW_FLIP, FLIP_MODE_OFF);
   5979         set(KEY_QC_VIDEO_FLIP, FLIP_MODE_OFF);
   5980         set(KEY_QC_SNAPSHOT_PICTURE_FLIP, FLIP_MODE_OFF);
   5981     }
   5982 
   5983     // Set default Auto Exposure lock value
   5984     setAecLock(VALUE_FALSE);
   5985 
   5986     // Set default AWB_LOCK lock value
   5987     setAwbLock(VALUE_FALSE);
   5988 
   5989     // Set default Camera mode
   5990     set(KEY_QC_CAMERA_MODE, 0);
   5991 
   5992     // Add support for internal preview restart
   5993     set(KEY_INTERNAL_PERVIEW_RESTART, VALUE_TRUE);
   5994     // Set default burst number
   5995     set(KEY_QC_SNAPSHOT_BURST_NUM, 0);
   5996     set(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER, 0);
   5997 
   5998     //Get RAM size and disable features which are memory rich
   5999     struct sysinfo info;
   6000     sysinfo(&info);
   6001 
   6002     LOGH("totalram = %ld, freeram = %ld ", info.totalram,
   6003         info.freeram);
   6004     if (info.totalram > TOTAL_RAM_SIZE_512MB) {
   6005         set(KEY_QC_ZSL_HDR_SUPPORTED, VALUE_TRUE);
   6006     } else {
   6007         m_bIsLowMemoryDevice = true;
   6008         set(KEY_QC_ZSL_HDR_SUPPORTED, VALUE_FALSE);
   6009     }
   6010 
   6011     setOfflineRAW();
   6012     memset(mStreamPpMask, 0, sizeof(cam_feature_mask_t)*CAM_STREAM_TYPE_MAX);
   6013     //Set video buffers as uncached by default
   6014     set(KEY_QC_CACHE_VIDEO_BUFFERS, VALUE_DISABLE);
   6015 
   6016     // Set default longshot mode
   6017     set(KEY_QC_LONG_SHOT, "off");
   6018     //Enable longshot by default
   6019     set(KEY_QC_LONGSHOT_SUPPORTED, VALUE_TRUE);
   6020 
   6021     int32_t rc = commitParameters();
   6022     if (rc == NO_ERROR) {
   6023         rc = setNumOfSnapshot();
   6024     }
   6025 
   6026     //Set Video Rotation
   6027     String8 videoRotationValues = createValuesStringFromMap(VIDEO_ROTATION_MODES_MAP,
   6028             PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP));
   6029 
   6030     set(KEY_QC_SUPPORTED_VIDEO_ROTATION_VALUES, videoRotationValues.string());
   6031     set(KEY_QC_VIDEO_ROTATION, VIDEO_ROTATION_0);
   6032 
   6033     //Check for EZTune
   6034     setEztune();
   6035     //Default set for video batch size
   6036     set(KEY_QC_VIDEO_BATCH_SIZE, 0);
   6037 
   6038     //Setup dual-camera
   6039     setDcrf();
   6040 
   6041     // For Aux Camera of dual camera Mode,
   6042     // by default set no display mode
   6043     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
   6044         set(KEY_QC_NO_DISPLAY_MODE, 1);
   6045         m_bNoDisplayMode = true;
   6046     }
   6047 
   6048     cam_dimension_t pic_dim;
   6049     pic_dim.width = 0;
   6050     pic_dim.height = 0;
   6051 
   6052     for(uint32_t i = 0;
   6053             i < (m_pCapability->picture_sizes_tbl_cnt - 1);
   6054             i++) {
   6055         if ((pic_dim.width * pic_dim.height) <
   6056                 (int32_t)(m_pCapability->picture_sizes_tbl[i].width *
   6057                 m_pCapability->picture_sizes_tbl[i].height)) {
   6058             pic_dim.width =
   6059                     m_pCapability->picture_sizes_tbl[i].width;
   6060             pic_dim.height =
   6061                     m_pCapability->picture_sizes_tbl[i].height;
   6062         }
   6063     }
   6064     LOGD("max pic size = %d %d", pic_dim.width,
   6065             pic_dim.height);
   6066     setMaxPicSize(pic_dim);
   6067 
   6068     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF);
   6069 
   6070     return rc;
   6071 }
   6072 
   6073 /*===========================================================================
   6074  * FUNCTION   : allocate
   6075  *
   6076  * DESCRIPTION: Allocate buffer memory for parameter obj (if necessary)
   6077  *
   6078  * PARAMETERS : none
   6079  *
   6080  * RETURN     : int32_t type of status
   6081  *              NO_ERROR  -- success
   6082  *              none-zero failure code
   6083  *==========================================================================*/
   6084 int32_t QCameraParameters::allocate()
   6085 {
   6086     int32_t rc = NO_ERROR;
   6087 
   6088     if (m_pParamHeap != NULL) {
   6089         return rc;
   6090     }
   6091 
   6092     //Allocate Set Param Buffer
   6093     m_pParamHeap = new QCameraHeapMemory(QCAMERA_ION_USE_CACHE);
   6094     if (m_pParamHeap == NULL) {
   6095         return NO_MEMORY;
   6096     }
   6097 
   6098     rc = m_pParamHeap->allocate(1, sizeof(parm_buffer_t), NON_SECURE);
   6099     if(rc != OK) {
   6100         rc = NO_MEMORY;
   6101         LOGE("Error!! Param buffers have not been allocated");
   6102         delete m_pParamHeap;
   6103         m_pParamHeap = NULL;
   6104     }
   6105 
   6106     return rc;
   6107 }
   6108 
   6109 /*===========================================================================
   6110  * FUNCTION   : init
   6111  *
   6112  * DESCRIPTION: initialize parameter obj
   6113  *
   6114  * PARAMETERS :
   6115  *   @capabilities  : ptr to camera capabilities
   6116  *   @mmops         : ptr to memory ops table for mapping/unmapping
   6117  *   @adjustFPS     : object reference for additional (possibly thermal)
   6118  *                    framerate adjustment
   6119  *
   6120  * RETURN     : int32_t type of status
   6121  *              NO_ERROR  -- success
   6122  *              none-zero failure code
   6123  *==========================================================================*/
   6124 int32_t QCameraParameters::init(cam_capability_t *capabilities,
   6125         mm_camera_vtbl_t *mmOps, QCameraAdjustFPS *adjustFPS)
   6126 {
   6127     int32_t rc = NO_ERROR;
   6128 
   6129     m_pCapability = capabilities;
   6130     m_pCamOpsTbl = mmOps;
   6131     m_AdjustFPS = adjustFPS;
   6132 
   6133     if (m_pParamHeap == NULL) {
   6134         LOGE("Parameter buffers have not been allocated");
   6135         rc = UNKNOWN_ERROR;
   6136         goto TRANS_INIT_ERROR1;
   6137     }
   6138 
   6139     //Map memory for parameters buffer
   6140     cam_buf_map_type_list bufMapList;
   6141     rc = QCameraBufferMaps::makeSingletonBufMapList(
   6142             CAM_MAPPING_BUF_TYPE_PARM_BUF, 0 /*stream id*/,
   6143             0 /*buffer index*/, -1 /*plane index*/, 0 /*cookie*/,
   6144             m_pParamHeap->getFd(0), sizeof(parm_buffer_t), bufMapList,
   6145                     m_pParamHeap->getPtr(0));
   6146 
   6147     if (rc == NO_ERROR) {
   6148         rc = m_pCamOpsTbl->ops->map_bufs(m_pCamOpsTbl->camera_handle,
   6149                 &bufMapList);
   6150     }
   6151 
   6152     if(rc < 0) {
   6153         LOGE("failed to map SETPARM buffer");
   6154         rc = FAILED_TRANSACTION;
   6155         goto TRANS_INIT_ERROR2;
   6156     }
   6157     m_pParamBuf = (parm_buffer_t*) DATA_PTR(m_pParamHeap,0);
   6158 
   6159     // Check if it is dual camera mode
   6160     if(m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
   6161         //Allocate related cam sync buffer
   6162         //this is needed for the payload that goes along with bundling cmd for related
   6163         //camera use cases
   6164         m_pRelCamSyncHeap = new QCameraHeapMemory(QCAMERA_ION_USE_CACHE);
   6165         rc = m_pRelCamSyncHeap->allocate(1,
   6166                 sizeof(cam_sync_related_sensors_event_info_t), NON_SECURE);
   6167         if(rc != OK) {
   6168             rc = NO_MEMORY;
   6169             LOGE("Failed to allocate Related cam sync Heap memory");
   6170             goto TRANS_INIT_ERROR3;
   6171         }
   6172 
   6173         //Map memory for related cam sync buffer
   6174         rc = m_pCamOpsTbl->ops->map_buf(m_pCamOpsTbl->camera_handle,
   6175                 CAM_MAPPING_BUF_TYPE_SYNC_RELATED_SENSORS_BUF,
   6176                 m_pRelCamSyncHeap->getFd(0),
   6177                 sizeof(cam_sync_related_sensors_event_info_t),
   6178                 (cam_sync_related_sensors_event_info_t*)DATA_PTR(m_pRelCamSyncHeap,0));
   6179         if(rc < 0) {
   6180             LOGE("failed to map Related cam sync buffer");
   6181             rc = FAILED_TRANSACTION;
   6182             goto TRANS_INIT_ERROR4;
   6183         }
   6184         m_pRelCamSyncBuf =
   6185                 (cam_sync_related_sensors_event_info_t*) DATA_PTR(m_pRelCamSyncHeap,0);
   6186     }
   6187     initDefaultParameters();
   6188     mCommon.init(capabilities);
   6189     m_bInited = true;
   6190 
   6191     goto TRANS_INIT_DONE;
   6192 
   6193 TRANS_INIT_ERROR4:
   6194     m_pRelCamSyncHeap->deallocate();
   6195 
   6196 TRANS_INIT_ERROR3:
   6197     delete m_pRelCamSyncHeap;
   6198     m_pRelCamSyncHeap = NULL;
   6199 
   6200 TRANS_INIT_ERROR2:
   6201     m_pParamHeap->deallocate();
   6202     delete m_pParamHeap;
   6203     m_pParamHeap = NULL;
   6204 
   6205 TRANS_INIT_ERROR1:
   6206     m_pCapability = NULL;
   6207     m_pCamOpsTbl = NULL;
   6208     m_AdjustFPS = NULL;
   6209 
   6210 TRANS_INIT_DONE:
   6211     return rc;
   6212 }
   6213 
   6214 /*===========================================================================
   6215  * FUNCTION   : deinit
   6216  *
   6217  * DESCRIPTION: deinitialize
   6218  *
   6219  * PARAMETERS : none
   6220  *
   6221  * RETURN     : none
   6222  *==========================================================================*/
   6223 void QCameraParameters::deinit()
   6224 {
   6225     if (!m_bInited) {
   6226         return;
   6227     }
   6228 
   6229     //clear all entries in the map
   6230     String8 emptyStr;
   6231     QCameraParameters::unflatten(emptyStr);
   6232 
   6233     if ((NULL != m_pCamOpsTbl) && (m_pCamOpsTbl->ops != NULL)) {
   6234         m_pCamOpsTbl->ops->unmap_buf(
   6235                              m_pCamOpsTbl->camera_handle,
   6236                              CAM_MAPPING_BUF_TYPE_PARM_BUF);
   6237 
   6238         if (m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
   6239             m_pCamOpsTbl->ops->unmap_buf(
   6240                     m_pCamOpsTbl->camera_handle,
   6241                     CAM_MAPPING_BUF_TYPE_SYNC_RELATED_SENSORS_BUF);
   6242         }
   6243     }
   6244 
   6245     m_pCapability = NULL;
   6246     if (NULL != m_pParamHeap) {
   6247         m_pParamHeap->deallocate();
   6248         delete m_pParamHeap;
   6249         m_pParamHeap = NULL;
   6250         m_pParamBuf = NULL;
   6251     }
   6252     if (NULL != m_pRelCamSyncHeap) {
   6253         m_pRelCamSyncHeap->deallocate();
   6254         delete m_pRelCamSyncHeap;
   6255         m_pRelCamSyncHeap = NULL;
   6256         m_pRelCamSyncBuf = NULL;
   6257     }
   6258 
   6259     m_AdjustFPS = NULL;
   6260     m_tempMap.clear();
   6261     m_pCamOpsTbl = NULL;
   6262     m_AdjustFPS = NULL;
   6263 
   6264     m_bInited = false;
   6265 }
   6266 
   6267 /*===========================================================================
   6268  * FUNCTION   : parse_pair
   6269  *
   6270  * DESCRIPTION: helper function to parse string like "640x480" or "10000,20000"
   6271  *
   6272  * PARAMETERS :
   6273  *   @str     : input string to be parse
   6274  *   @first   : [output] first value of the pair
   6275  *   @second  : [output]  second value of the pair
   6276  *   @delim   : [input] delimeter to seperate the pair
   6277  *   @endptr  : [output] ptr to the end of the pair string
   6278  *
   6279  * RETURN     : int32_t type of status
   6280  *              NO_ERROR  -- success
   6281  *              none-zero failure code
   6282  *==========================================================================*/
   6283 int32_t QCameraParameters::parse_pair(const char *str,
   6284                                       int *first,
   6285                                       int *second,
   6286                                       char delim,
   6287                                       char **endptr = NULL)
   6288 {
   6289     // Find the first integer.
   6290     char *end;
   6291     int w = (int)strtol(str, &end, 10);
   6292     // If a delimeter does not immediately follow, give up.
   6293     if (*end != delim) {
   6294         LOGE("Cannot find delimeter (%c) in str=%s", delim, str);
   6295         return BAD_VALUE;
   6296     }
   6297 
   6298     // Find the second integer, immediately after the delimeter.
   6299     int h = (int)strtol(end+1, &end, 10);
   6300 
   6301     *first = w;
   6302     *second = h;
   6303 
   6304     if (endptr) {
   6305         *endptr = end;
   6306     }
   6307 
   6308     return NO_ERROR;
   6309 }
   6310 
   6311 /*===========================================================================
   6312  * FUNCTION   : parseSizesList
   6313  *
   6314  * DESCRIPTION: helper function to parse string containing sizes
   6315  *
   6316  * PARAMETERS :
   6317  *   @sizesStr: [input] input string to be parse
   6318  *   @sizes   : [output] reference to store parsed sizes
   6319  *
   6320  * RETURN     : none
   6321  *==========================================================================*/
   6322 void QCameraParameters::parseSizesList(const char *sizesStr, Vector<Size> &sizes)
   6323 {
   6324     if (sizesStr == 0) {
   6325         return;
   6326     }
   6327 
   6328     char *sizeStartPtr = (char *)sizesStr;
   6329 
   6330     while (true) {
   6331         int width, height;
   6332         int success = parse_pair(sizeStartPtr, &width, &height, 'x',
   6333                                  &sizeStartPtr);
   6334         if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
   6335             LOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
   6336             return;
   6337         }
   6338         sizes.push(Size(width, height));
   6339 
   6340         if (*sizeStartPtr == '\0') {
   6341             return;
   6342         }
   6343         sizeStartPtr++;
   6344     }
   6345 }
   6346 
   6347 /*===========================================================================
   6348  * FUNCTION   : adjustPreviewFpsRange
   6349  *
   6350  * DESCRIPTION: adjust preview FPS ranges
   6351  *              according to external events
   6352  *
   6353  * PARAMETERS :
   6354  *   @minFPS  : min FPS value
   6355  *   @maxFPS  : max FPS value
   6356  *
   6357  * RETURN     : int32_t type of status
   6358  *              NO_ERROR  -- success
   6359  *              none-zero failure code
   6360  *==========================================================================*/
   6361 int32_t QCameraParameters::adjustPreviewFpsRange(cam_fps_range_t *fpsRange)
   6362 {
   6363     if ( fpsRange == NULL ) {
   6364         return BAD_VALUE;
   6365     }
   6366 
   6367     if ( m_pParamBuf == NULL ) {
   6368         return NO_INIT;
   6369     }
   6370 
   6371     int32_t rc = initBatchUpdate(m_pParamBuf);
   6372     if ( rc != NO_ERROR ) {
   6373         LOGE("Failed to initialize group update table");
   6374         return rc;
   6375     }
   6376 
   6377     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FPS_RANGE, *fpsRange)) {
   6378         LOGE("Parameters batch failed");
   6379         return BAD_VALUE;
   6380     }
   6381 
   6382     rc = commitSetBatch();
   6383     if ( rc != NO_ERROR ) {
   6384         LOGE("Failed to commit batch parameters");
   6385         return rc;
   6386     }
   6387 
   6388     return rc;
   6389 }
   6390 
   6391 /*===========================================================================
   6392  * FUNCTION   : setPreviewFpsRanges
   6393  *
   6394  * DESCRIPTION: set preview FPS ranges
   6395  *
   6396  * PARAMETERS :
   6397  *   @minFPS  : min FPS value
   6398  *   @maxFPS  : max FPS value
   6399  *
   6400  * RETURN     : int32_t type of status
   6401  *              NO_ERROR  -- success
   6402  *              none-zero failure code
   6403  *==========================================================================*/
   6404 int32_t QCameraParameters::setPreviewFpsRange(int min_fps,
   6405         int max_fps, int vid_min_fps,int vid_max_fps)
   6406 {
   6407     char str[32];
   6408     char value[PROPERTY_VALUE_MAX];
   6409     int fixedFpsValue;
   6410     /*This property get value should be the fps that user needs*/
   6411     property_get("persist.debug.set.fixedfps", value, "0");
   6412     fixedFpsValue = atoi(value);
   6413 
   6414     LOGD("E minFps = %d, maxFps = %d , vid minFps = %d, vid maxFps = %d",
   6415                  min_fps, max_fps, vid_min_fps, vid_max_fps);
   6416 
   6417     if(fixedFpsValue != 0) {
   6418         min_fps = max_fps = fixedFpsValue*1000;
   6419         if (!isHfrMode()) {
   6420              vid_min_fps = vid_max_fps = fixedFpsValue*1000;
   6421         }
   6422     }
   6423     snprintf(str, sizeof(str), "%d,%d", min_fps, max_fps);
   6424     LOGH("Setting preview fps range %s", str);
   6425     updateParamEntry(KEY_PREVIEW_FPS_RANGE, str);
   6426     cam_fps_range_t fps_range;
   6427     memset(&fps_range, 0x00, sizeof(cam_fps_range_t));
   6428     fps_range.min_fps = (float)min_fps / 1000.0f;
   6429     fps_range.max_fps = (float)max_fps / 1000.0f;
   6430     fps_range.video_min_fps = (float)vid_min_fps / 1000.0f;
   6431     fps_range.video_max_fps = (float)vid_max_fps / 1000.0f;
   6432 
   6433     LOGH("Updated: minFps = %d, maxFps = %d ,"
   6434             " vid minFps = %d, vid maxFps = %d",
   6435              min_fps, max_fps, vid_min_fps, vid_max_fps);
   6436 
   6437     if ( NULL != m_AdjustFPS ) {
   6438         if (m_ThermalMode == QCAMERA_THERMAL_ADJUST_FPS &&
   6439                 !m_bRecordingHint) {
   6440             float minVideoFps = min_fps, maxVideoFps = max_fps;
   6441             if (isHfrMode()) {
   6442                 minVideoFps = m_hfrFpsRange.video_min_fps;
   6443                 maxVideoFps = m_hfrFpsRange.video_max_fps;
   6444             }
   6445             m_AdjustFPS->recalcFPSRange(min_fps, max_fps, minVideoFps, maxVideoFps, fps_range);
   6446             LOGH("Thermal adjusted Preview fps range %3.2f,%3.2f, %3.2f, %3.2f",
   6447                    fps_range.min_fps, fps_range.max_fps,
   6448                   fps_range.video_min_fps, fps_range.video_max_fps);
   6449         }
   6450     }
   6451 
   6452     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FPS_RANGE, fps_range)) {
   6453         return BAD_VALUE;
   6454     }
   6455 
   6456     return NO_ERROR;
   6457 }
   6458 
   6459 
   6460 
   6461 /*===========================================================================
   6462  * FUNCTION   : setAutoExposure
   6463  *
   6464  * DESCRIPTION: set auto exposure
   6465  *
   6466  * PARAMETERS :
   6467  *   @autoExp : auto exposure value string
   6468  *
   6469  * RETURN     : int32_t type of status
   6470  *              NO_ERROR  -- success
   6471  *              none-zero failure code
   6472  *==========================================================================*/
   6473 int32_t QCameraParameters::setAutoExposure(const char *autoExp)
   6474 {
   6475     if (autoExp != NULL) {
   6476         int32_t value = lookupAttr(AUTO_EXPOSURE_MAP, PARAM_MAP_SIZE(AUTO_EXPOSURE_MAP), autoExp);
   6477         if (value != NAME_NOT_FOUND) {
   6478             LOGH("Setting auto exposure %s", autoExp);
   6479             updateParamEntry(KEY_QC_AUTO_EXPOSURE, autoExp);
   6480             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_ALGO_TYPE, value)) {
   6481                 return BAD_VALUE;
   6482             }
   6483             return NO_ERROR;
   6484         }
   6485     }
   6486     LOGE("Invalid auto exposure value: %s", (autoExp == NULL) ? "NULL" : autoExp);
   6487     return BAD_VALUE;
   6488 }
   6489 
   6490 /*===========================================================================
   6491  * FUNCTION   : setEffect
   6492  *
   6493  * DESCRIPTION: set effect
   6494  *
   6495  * PARAMETERS :
   6496  *   @effect  : effect value string
   6497  *
   6498  * RETURN     : int32_t type of status
   6499  *              NO_ERROR  -- success
   6500  *              none-zero failure code
   6501  *==========================================================================*/
   6502 int32_t QCameraParameters::setEffect(const char *effect)
   6503 {
   6504     if (effect != NULL) {
   6505         int32_t value = lookupAttr(EFFECT_MODES_MAP, PARAM_MAP_SIZE(EFFECT_MODES_MAP), effect);
   6506         if (value != NAME_NOT_FOUND) {
   6507             LOGH("Setting effect %s", effect);
   6508             updateParamEntry(KEY_EFFECT, effect);
   6509             uint8_t prmEffect = static_cast<uint8_t>(value);
   6510             mParmEffect = prmEffect;
   6511             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EFFECT, prmEffect)) {
   6512                 return BAD_VALUE;
   6513             }
   6514             return NO_ERROR;
   6515         }
   6516     }
   6517     LOGE("Invalid effect value: %s", (effect == NULL) ? "NULL" : effect);
   6518     return BAD_VALUE;
   6519 }
   6520 
   6521 /*===========================================================================
   6522  * FUNCTION   : setBrightness
   6523  *
   6524  * DESCRIPTION: set brightness control value
   6525  *
   6526  * PARAMETERS :
   6527  *   @brightness  : brightness control value
   6528  *
   6529  * RETURN     : int32_t type of status
   6530  *              NO_ERROR  -- success
   6531  *              none-zero failure code
   6532  *==========================================================================*/
   6533 int32_t QCameraParameters::setBrightness(int brightness)
   6534 {
   6535     char val[16];
   6536     snprintf(val, sizeof(val), "%d", brightness);
   6537     updateParamEntry(KEY_QC_BRIGHTNESS, val);
   6538 
   6539     LOGH("Setting brightness %s", val);
   6540     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BRIGHTNESS, brightness)) {
   6541         return BAD_VALUE;
   6542     }
   6543 
   6544     return NO_ERROR;
   6545 }
   6546 
   6547 /*===========================================================================
   6548  * FUNCTION   : setFocusMode
   6549  *
   6550  * DESCRIPTION: set focus mode
   6551  *
   6552  * PARAMETERS :
   6553  *   @focusMode  : focus mode value string
   6554  *
   6555  * RETURN     : int32_t type of status
   6556  *              NO_ERROR  -- success
   6557  *              none-zero failure code
   6558  *==========================================================================*/
   6559 int32_t QCameraParameters::setFocusMode(const char *focusMode)
   6560 {
   6561     if (focusMode != NULL) {
   6562         int32_t value = lookupAttr(FOCUS_MODES_MAP, PARAM_MAP_SIZE(FOCUS_MODES_MAP), focusMode);
   6563         if (value != NAME_NOT_FOUND) {
   6564             int32_t rc = NO_ERROR;
   6565             LOGH("Setting focus mode %s", focusMode);
   6566             mFocusMode = (cam_focus_mode_type)value;
   6567 
   6568             updateParamEntry(KEY_FOCUS_MODE, focusMode);
   6569             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   6570                     CAM_INTF_PARM_FOCUS_MODE, (uint8_t)value)) {
   6571                 rc = BAD_VALUE;
   6572             }
   6573             if (strcmp(focusMode,"infinity")==0){
   6574                 set(QCameraParameters::KEY_FOCUS_DISTANCES, "Infinity,Infinity,Infinity");
   6575             }
   6576             return rc;
   6577         }
   6578     }
   6579     LOGE("Invalid focus mode value: %s", (focusMode == NULL) ? "NULL" : focusMode);
   6580     return BAD_VALUE;
   6581 }
   6582 
   6583 /*===========================================================================
   6584  * FUNCTION   : setFocusPosition
   6585  *
   6586  * DESCRIPTION: set focus position
   6587  *
   6588  * PARAMETERS :
   6589  *   @typeStr : focus position type, index or dac_code
   6590  *   @posStr : focus positon.
   6591  *
   6592  * RETURN     : int32_t type of status
   6593  *              NO_ERROR  -- success
   6594  *              none-zero failure code
   6595  *==========================================================================*/
   6596 int32_t  QCameraParameters::setFocusPosition(const char *typeStr, const char *posStr)
   6597 {
   6598     LOGH(", type:%s, pos: %s", typeStr, posStr);
   6599     int32_t type = atoi(typeStr);
   6600     float pos = (float) atof(posStr);
   6601 
   6602     if ((type >= CAM_MANUAL_FOCUS_MODE_INDEX) &&
   6603             (type < CAM_MANUAL_FOCUS_MODE_MAX)) {
   6604         // get max and min focus position from m_pCapability
   6605         float minFocusPos = m_pCapability->min_focus_pos[type];
   6606         float maxFocusPos = m_pCapability->max_focus_pos[type];
   6607         LOGH(", focusPos min: %f, max: %f", minFocusPos, maxFocusPos);
   6608 
   6609         if (pos >= minFocusPos && pos <= maxFocusPos) {
   6610             updateParamEntry(KEY_QC_MANUAL_FOCUS_POS_TYPE, typeStr);
   6611             updateParamEntry(KEY_QC_MANUAL_FOCUS_POSITION, posStr);
   6612 
   6613             cam_manual_focus_parm_t manual_focus;
   6614             manual_focus.flag = (cam_manual_focus_mode_type)type;
   6615             if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_DIOPTER) {
   6616                 manual_focus.af_manual_diopter = pos;
   6617             } else if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_RATIO) {
   6618                 manual_focus.af_manual_lens_position_ratio = (int32_t) pos;
   6619             } else if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_INDEX) {
   6620                 manual_focus.af_manual_lens_position_index = (int32_t) pos;
   6621             } else {
   6622                 manual_focus.af_manual_lens_position_dac = (int32_t) pos;
   6623             }
   6624 
   6625             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MANUAL_FOCUS_POS,
   6626                     manual_focus)) {
   6627                 return BAD_VALUE;
   6628             }
   6629             return NO_ERROR;
   6630         }
   6631     }
   6632 
   6633     LOGE("invalid params, type:%d, pos: %f", type, pos);
   6634     return BAD_VALUE;
   6635 }
   6636 
   6637 /*===========================================================================
   6638  * FUNCTION   : updateAEInfo
   6639  *
   6640  * DESCRIPTION: update exposure information from metadata callback
   6641  *
   6642  * PARAMETERS :
   6643  *   @ae_params : auto exposure params
   6644  *
   6645  * RETURN     : void
   6646  *==========================================================================*/
   6647 void  QCameraParameters::updateAEInfo(cam_3a_params_t &ae_params)
   6648 {
   6649     const char *prevExpTime = get(KEY_QC_CURRENT_EXPOSURE_TIME);
   6650     char newExpTime[15];
   6651     snprintf(newExpTime, sizeof(newExpTime), "%f", ae_params.exp_time*1000.0);
   6652 
   6653     if (prevExpTime == NULL || strcmp(prevExpTime, newExpTime)) {
   6654         LOGD("update exposure time: old: %s, new: %s", prevExpTime, newExpTime);
   6655         set(KEY_QC_CURRENT_EXPOSURE_TIME, newExpTime);
   6656     }
   6657 
   6658     int32_t prevISO = getInt(KEY_QC_CURRENT_ISO);
   6659     int32_t newISO = ae_params.iso_value;
   6660     if (prevISO != newISO) {
   6661         LOGD("update iso: old:%d, new:%d", prevISO, newISO);
   6662         set(KEY_QC_CURRENT_ISO, newISO);
   6663     }
   6664 }
   6665 
   6666 /*===========================================================================
   6667  * FUNCTION   : updateCurrentFocusPosition
   6668  *
   6669  * DESCRIPTION: update current focus position from metadata callback
   6670  *
   6671  * PARAMETERS :
   6672  *   @pos : current focus position
   6673  *
   6674  * RETURN     : void
   6675  *==========================================================================*/
   6676 void  QCameraParameters::updateCurrentFocusPosition(cam_focus_pos_info_t &cur_pos_info)
   6677 {
   6678     int prevScalePos = getInt(KEY_QC_FOCUS_POSITION_SCALE);
   6679     int newScalePos = (int) cur_pos_info.scale;
   6680     if (prevScalePos != newScalePos) {
   6681         LOGD("update focus scale: old:%d, new:%d", prevScalePos, newScalePos);
   6682         set(KEY_QC_FOCUS_POSITION_SCALE, newScalePos);
   6683     }
   6684 
   6685     float prevDiopterPos = getFloat(KEY_QC_FOCUS_POSITION_DIOPTER);
   6686     float newDiopterPos = cur_pos_info.diopter;
   6687     if (prevDiopterPos != newDiopterPos) {
   6688         LOGD("update focus diopter: old:%f, new:%f", prevDiopterPos, newDiopterPos);
   6689         setFloat(KEY_QC_FOCUS_POSITION_DIOPTER, newDiopterPos);
   6690     }
   6691 }
   6692 
   6693 /*===========================================================================
   6694  * FUNCTION   : setSharpness
   6695  *
   6696  * DESCRIPTION: set sharpness control value
   6697  *
   6698  * PARAMETERS :
   6699  *   @sharpness  : sharpness control value
   6700  *
   6701  * RETURN     : int32_t type of status
   6702  *              NO_ERROR  -- success
   6703  *              none-zero failure code
   6704  *==========================================================================*/
   6705 int32_t QCameraParameters::setSharpness(int sharpness)
   6706 {
   6707     char val[16];
   6708     snprintf(val, sizeof(val), "%d", sharpness);
   6709     updateParamEntry(KEY_QC_SHARPNESS, val);
   6710     LOGH("Setting sharpness %s", val);
   6711     m_nSharpness = sharpness;
   6712     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SHARPNESS, m_nSharpness)) {
   6713         return BAD_VALUE;
   6714     }
   6715 
   6716     return NO_ERROR;
   6717 }
   6718 
   6719 /*===========================================================================
   6720  * FUNCTION   : setSkinToneEnhancement
   6721  *
   6722  * DESCRIPTION: set skin tone enhancement value
   6723  *
   6724  * PARAMETERS :
   6725  *   @sceFactore  : skin tone enhancement factor value
   6726  *
   6727  * RETURN     : int32_t type of status
   6728  *              NO_ERROR  -- success
   6729  *              none-zero failure code
   6730  *==========================================================================*/
   6731 int32_t QCameraParameters::setSkinToneEnhancement(int sceFactor)
   6732 {
   6733     char val[16];
   6734     snprintf(val, sizeof(val), "%d", sceFactor);
   6735     updateParamEntry(KEY_QC_SCE_FACTOR, val);
   6736     LOGH("Setting skintone enhancement %s", val);
   6737 
   6738     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SCE_FACTOR, sceFactor)) {
   6739         return BAD_VALUE;
   6740     }
   6741 
   6742     return NO_ERROR;
   6743 }
   6744 
   6745 /*===========================================================================
   6746  * FUNCTION   : setSaturation
   6747  *
   6748  * DESCRIPTION: set saturation control value
   6749  *
   6750  * PARAMETERS :
   6751  *   @saturation : saturation control value
   6752  *
   6753  * RETURN     : int32_t type of status
   6754  *              NO_ERROR  -- success
   6755  *              none-zero failure code
   6756  *==========================================================================*/
   6757 int32_t QCameraParameters::setSaturation(int saturation)
   6758 {
   6759     char val[16];
   6760     snprintf(val, sizeof(val), "%d", saturation);
   6761     updateParamEntry(KEY_QC_SATURATION, val);
   6762     LOGH("Setting saturation %s", val);
   6763 
   6764     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SATURATION, saturation)) {
   6765         return BAD_VALUE;
   6766     }
   6767 
   6768     return NO_ERROR;
   6769 }
   6770 
   6771 /*===========================================================================
   6772  * FUNCTION   : setContrast
   6773  *
   6774  * DESCRIPTION: set contrast control value
   6775  *
   6776  * PARAMETERS :
   6777  *   @contrast : contrast control value
   6778  *
   6779  * RETURN     : int32_t type of status
   6780  *              NO_ERROR  -- success
   6781  *              none-zero failure code
   6782  *==========================================================================*/
   6783 int32_t QCameraParameters::setContrast(int contrast)
   6784 {
   6785     char val[16];
   6786     snprintf(val, sizeof(val), "%d", contrast);
   6787     updateParamEntry(KEY_QC_CONTRAST, val);
   6788     LOGH("Setting contrast %s", val);
   6789 
   6790     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CONTRAST, contrast)) {
   6791         return BAD_VALUE;
   6792     }
   6793 
   6794     return NO_ERROR;
   6795 }
   6796 
   6797 /*===========================================================================
   6798  * FUNCTION   : setSceneDetect
   6799  *
   6800  * DESCRIPTION: set scenen detect value
   6801  *
   6802  * PARAMETERS :
   6803  *   @sceneDetect  : scene detect value string
   6804  *
   6805  * RETURN     : int32_t type of status
   6806  *              NO_ERROR  -- success
   6807  *              none-zero failure code
   6808  *==========================================================================*/
   6809 int32_t QCameraParameters::setSceneDetect(const char *sceneDetect)
   6810 {
   6811     if (sceneDetect != NULL) {
   6812         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
   6813                 sceneDetect);
   6814         if (value != NAME_NOT_FOUND) {
   6815             LOGH("Setting Scene Detect %s", sceneDetect);
   6816             updateParamEntry(KEY_QC_SCENE_DETECT, sceneDetect);
   6817             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ASD_ENABLE, value)) {
   6818                 return BAD_VALUE;
   6819             }
   6820             return NO_ERROR;
   6821         }
   6822     }
   6823     LOGE("Invalid Scene Detect value: %s",
   6824           (sceneDetect == NULL) ? "NULL" : sceneDetect);
   6825     return BAD_VALUE;
   6826 }
   6827 
   6828 /*===========================================================================
   6829  * FUNCTION   : setSensorSnapshotHDR
   6830  *
   6831  * DESCRIPTION: set snapshot HDR value
   6832  *
   6833  * PARAMETERS :
   6834  *   @snapshotHDR  : snapshot HDR value string
   6835  *
   6836  * RETURN     : int32_t type of status
   6837  *              NO_ERROR  -- success
   6838  *              none-zero failure code
   6839  *==========================================================================*/
   6840 int32_t QCameraParameters::setSensorSnapshotHDR(const char *snapshotHDR)
   6841 {
   6842     if (snapshotHDR != NULL) {
   6843         int32_t value = (cam_sensor_hdr_type_t) lookupAttr(ON_OFF_MODES_MAP,
   6844                 PARAM_MAP_SIZE(ON_OFF_MODES_MAP), snapshotHDR);
   6845         if (value != NAME_NOT_FOUND) {
   6846             LOGH("Setting Sensor Snapshot HDR %s", snapshotHDR);
   6847             updateParamEntry(KEY_QC_SENSOR_HDR, snapshotHDR);
   6848 
   6849             char zz_prop[PROPERTY_VALUE_MAX];
   6850             memset(zz_prop, 0, sizeof(zz_prop));
   6851             property_get("persist.camera.zzhdr.enable", zz_prop, "0");
   6852             uint8_t zzhdr_enable = (uint8_t)atoi(zz_prop);
   6853 
   6854             if (zzhdr_enable && (value != CAM_SENSOR_HDR_OFF)) {
   6855                 value = CAM_SENSOR_HDR_ZIGZAG;
   6856                 LOGH("%s: Overriding to ZZ HDR Mode", __func__);
   6857             }
   6858 
   6859             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SENSOR_HDR, (cam_sensor_hdr_type_t)value)) {
   6860                 return BAD_VALUE;
   6861             }
   6862             return NO_ERROR;
   6863         }
   6864     }
   6865     LOGE("Invalid Snapshot HDR value: %s",
   6866           (snapshotHDR == NULL) ? "NULL" : snapshotHDR);
   6867     return BAD_VALUE;
   6868 
   6869 }
   6870 
   6871 
   6872 /*===========================================================================
   6873  * FUNCTION   : setVideoHDR
   6874  *
   6875  * DESCRIPTION: set video HDR value
   6876  *
   6877  * PARAMETERS :
   6878  *   @videoHDR  : svideo HDR value string
   6879  *
   6880  * RETURN     : int32_t type of status
   6881  *              NO_ERROR  -- success
   6882  *              none-zero failure code
   6883  *==========================================================================*/
   6884 int32_t QCameraParameters::setVideoHDR(const char *videoHDR)
   6885 {
   6886     if (videoHDR != NULL) {
   6887         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP), videoHDR);
   6888         if (value != NAME_NOT_FOUND) {
   6889 
   6890             char zz_prop[PROPERTY_VALUE_MAX];
   6891             memset(zz_prop, 0, sizeof(zz_prop));
   6892             property_get("persist.camera.zzhdr.video", zz_prop, "0");
   6893             uint8_t use_zzhdr_video = (uint8_t)atoi(zz_prop);
   6894 
   6895             if (use_zzhdr_video) {
   6896                 LOGH("%s: Using ZZ HDR for video mode", __func__);
   6897                 if (value)
   6898                     value = CAM_SENSOR_HDR_ZIGZAG;
   6899                 else
   6900                     value = CAM_SENSOR_HDR_OFF;
   6901                 LOGH("%s: Overriding to sensor HDR Mode to:%d", __func__, value);
   6902                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SENSOR_HDR, (cam_sensor_hdr_type_t) value)) {
   6903                     LOGE("%s: Override to sensor HDR mode for video HDR failed", __func__);
   6904                     return BAD_VALUE;
   6905                 }
   6906                 updateParamEntry(KEY_QC_VIDEO_HDR, videoHDR);
   6907             } else {
   6908                 LOGH("%s: Setting Video HDR %s", __func__, videoHDR);
   6909                 updateParamEntry(KEY_QC_VIDEO_HDR, videoHDR);
   6910                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_VIDEO_HDR, value)) {
   6911                     return BAD_VALUE;
   6912                 }
   6913             }
   6914 
   6915             return NO_ERROR;
   6916         }
   6917     }
   6918     LOGE("Invalid Video HDR value: %s",
   6919           (videoHDR == NULL) ? "NULL" : videoHDR);
   6920     return BAD_VALUE;
   6921 }
   6922 
   6923 
   6924 
   6925 /*===========================================================================
   6926  * FUNCTION   : setVtEnable
   6927  *
   6928  * DESCRIPTION: set vt Enable value
   6929  *
   6930  * PARAMETERS :
   6931  *   @videoHDR  : svtEnable value string
   6932  *
   6933  * RETURN     : int32_t type of status
   6934  *              NO_ERROR  -- success
   6935  *              none-zero failure code
   6936  *==========================================================================*/
   6937 int32_t QCameraParameters::setVtEnable(const char *vtEnable)
   6938 {
   6939     if (vtEnable != NULL) {
   6940         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   6941                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), vtEnable);
   6942         if (value != NAME_NOT_FOUND) {
   6943             LOGH("Setting Vt Enable %s", vtEnable);
   6944             m_bAVTimerEnabled = true;
   6945             updateParamEntry(KEY_QC_VT_ENABLE, vtEnable);
   6946             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_VT, value)) {
   6947                 return BAD_VALUE;
   6948             }
   6949             return NO_ERROR;
   6950         }
   6951     }
   6952     LOGE("Invalid Vt Enable value: %s",
   6953           (vtEnable == NULL) ? "NULL" : vtEnable);
   6954     m_bAVTimerEnabled = false;
   6955     return BAD_VALUE;
   6956 }
   6957 
   6958 /*===========================================================================
   6959  * FUNCTION   : setFaceRecognition
   6960  *
   6961  * DESCRIPTION: set face recognition value
   6962  *
   6963  * PARAMETERS :
   6964  *   @faceRecog  : face recognition value string
   6965  *   @maxFaces   : number of max faces to be detected/recognized
   6966  *
   6967  * RETURN     : int32_t type of status
   6968  *              NO_ERROR  -- success
   6969  *              none-zero failure code
   6970  *==========================================================================*/
   6971 int32_t QCameraParameters::setFaceRecognition(const char *faceRecog,
   6972         uint32_t maxFaces)
   6973 {
   6974     if (faceRecog != NULL) {
   6975         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP), faceRecog);
   6976         if (value != NAME_NOT_FOUND) {
   6977             LOGH("Setting face recognition %s", faceRecog);
   6978             updateParamEntry(KEY_QC_FACE_RECOGNITION, faceRecog);
   6979 
   6980             uint32_t faceProcMask = m_nFaceProcMask;
   6981             if (value > 0) {
   6982                 faceProcMask |= CAM_FACE_PROCESS_MASK_RECOGNITION;
   6983             } else {
   6984                 faceProcMask &= (uint32_t)(~CAM_FACE_PROCESS_MASK_RECOGNITION);
   6985             }
   6986 
   6987             if(m_nFaceProcMask == faceProcMask) {
   6988                 LOGH("face process mask not changed, no ops here");
   6989                 return NO_ERROR;
   6990             }
   6991             m_nFaceProcMask = faceProcMask;
   6992             LOGH("FaceProcMask -> %d", m_nFaceProcMask);
   6993 
   6994             // set parm for face process
   6995             cam_fd_set_parm_t fd_set_parm;
   6996             memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
   6997             fd_set_parm.fd_mode = m_nFaceProcMask;
   6998             fd_set_parm.num_fd = maxFaces;
   6999 
   7000             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FD, fd_set_parm)) {
   7001                 return BAD_VALUE;
   7002             }
   7003             return NO_ERROR;
   7004         }
   7005     }
   7006     LOGE("Invalid face recognition value: %s", (faceRecog == NULL) ? "NULL" : faceRecog);
   7007     return BAD_VALUE;
   7008 }
   7009 
   7010 /*===========================================================================
   7011  * FUNCTION   : setZoom
   7012  *
   7013  * DESCRIPTION: set zoom level
   7014  *
   7015  * PARAMETERS :
   7016  *   @zoom_level : zoom level
   7017  *
   7018  * RETURN     : int32_t type of status
   7019  *              NO_ERROR  -- success
   7020  *              none-zero failure code
   7021  *==========================================================================*/
   7022 int32_t QCameraParameters::setZoom(int zoom_level)
   7023 {
   7024     char val[16];
   7025     snprintf(val, sizeof(val), "%d", zoom_level);
   7026     updateParamEntry(KEY_ZOOM, val);
   7027     LOGH("zoom level: %d", zoom_level);
   7028     mZoomLevel = zoom_level;
   7029     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZOOM, zoom_level)) {
   7030         return BAD_VALUE;
   7031     }
   7032 
   7033     return NO_ERROR;
   7034 }
   7035 
   7036 /*===========================================================================
   7037  * FUNCTION   : setISOValue
   7038  *
   7039  * DESCRIPTION: set ISO value
   7040  *
   7041  * PARAMETERS :
   7042  *   @isoValue : ISO value string
   7043  *
   7044  * RETURN     : int32_t type of status
   7045  *              NO_ERROR  -- success
   7046  *              none-zero failure code
   7047  *==========================================================================*/
   7048 int32_t  QCameraParameters::setISOValue(const char *isoValue)
   7049 {
   7050     if (isoValue != NULL) {
   7051         if (!strcmp(isoValue, ISO_MANUAL)) {
   7052             LOGD("iso manual mode - use continuous iso");
   7053             updateParamEntry(KEY_QC_ISO_MODE, isoValue);
   7054             return NO_ERROR;
   7055         }
   7056         int32_t value = lookupAttr(ISO_MODES_MAP, PARAM_MAP_SIZE(ISO_MODES_MAP), isoValue);
   7057         if (value != NAME_NOT_FOUND) {
   7058             LOGH("Setting ISO value %s", isoValue);
   7059             updateParamEntry(KEY_QC_ISO_MODE, isoValue);
   7060 
   7061             cam_intf_parm_manual_3a_t iso_settings;
   7062             memset(&iso_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
   7063             iso_settings.previewOnly = FALSE;
   7064             iso_settings.value = value;
   7065             if (getManualCaptureMode() != CAM_MANUAL_CAPTURE_TYPE_OFF) {
   7066                 iso_settings.previewOnly = TRUE;
   7067             }
   7068 
   7069             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ISO, iso_settings)) {
   7070                 return BAD_VALUE;
   7071             }
   7072             m_isoValue = value;
   7073             return NO_ERROR;
   7074         }
   7075     }
   7076     LOGE("Invalid ISO value: %s",
   7077           (isoValue == NULL) ? "NULL" : isoValue);
   7078     return BAD_VALUE;
   7079 }
   7080 
   7081 
   7082 /*===========================================================================
   7083  * FUNCTION   : setContinuousISO
   7084  *
   7085  * DESCRIPTION: set continuous ISO value
   7086  *
   7087  * PARAMETERS :
   7088  *   @params : ISO value parameter
   7089  *
   7090  * RETURN     : int32_t type of status
   7091  *              NO_ERROR  -- success
   7092  *              none-zero failure code
   7093  *==========================================================================*/
   7094 int32_t  QCameraParameters::setContinuousISO(const QCameraParameters& params)
   7095 {
   7096     const char *iso = params.get(KEY_QC_ISO_MODE);
   7097     LOGD("current iso mode: %s", iso);
   7098 
   7099     if (iso != NULL) {
   7100         if (strcmp(iso, ISO_MANUAL)) {
   7101             LOGD("dont set iso to back-end.");
   7102             return NO_ERROR;
   7103         }
   7104     }
   7105 
   7106     const char *str = params.get(KEY_QC_CONTINUOUS_ISO);
   7107     const char *prev_str = get(KEY_QC_CONTINUOUS_ISO);
   7108     if (str != NULL) {
   7109         if (prev_str == NULL ||
   7110             strcmp(str, prev_str) != 0) {
   7111             return setContinuousISO(str);
   7112         }
   7113     }
   7114     return NO_ERROR;
   7115 }
   7116 
   7117 /*===========================================================================
   7118  * FUNCTION   : setExposureTime
   7119  *
   7120  * DESCRIPTION: set exposure time
   7121  *
   7122  * PARAMETERS :
   7123  *   @expTimeStr : string of exposure time in ms
   7124  *
   7125  * RETURN     : int32_t type of status
   7126  *              NO_ERROR  -- success
   7127  *              none-zero failure code
   7128  *==========================================================================*/
   7129 int32_t  QCameraParameters::setExposureTime(const char *expTimeStr)
   7130 {
   7131     if (expTimeStr != NULL) {
   7132         double expTimeMs = atof(expTimeStr);
   7133         //input is in milli seconds. Convert to nano sec for backend
   7134         int64_t expTimeNs = (int64_t)(expTimeMs*1000000L);
   7135 
   7136         // expTime == 0 means not to use manual exposure time.
   7137         if ((0 <= expTimeNs) &&
   7138                 ((expTimeNs == 0) ||
   7139                 ((expTimeNs >= m_pCapability->exposure_time_range[0]) &&
   7140                 (expTimeNs <= m_pCapability->exposure_time_range[1])))) {
   7141             LOGH(", exposure time: %f ms", expTimeMs);
   7142             updateParamEntry(KEY_QC_EXPOSURE_TIME, expTimeStr);
   7143 
   7144             cam_intf_parm_manual_3a_t exp_settings;
   7145             memset(&exp_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
   7146             if (getManualCaptureMode() != CAM_MANUAL_CAPTURE_TYPE_OFF) {
   7147                 exp_settings.previewOnly = TRUE;
   7148                 if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL1) {
   7149                     exp_settings.value = expTimeNs;
   7150                 } else {
   7151                     exp_settings.value =
   7152                             (int64_t)(QCAMERA_MAX_EXP_TIME_LEVEL1*1000000L);
   7153                 }
   7154             } else {
   7155                 exp_settings.previewOnly = FALSE;
   7156                 exp_settings.value = expTimeNs;
   7157             }
   7158 
   7159             //Based on exposure values we can decide the capture type here
   7160             if (getManualCaptureMode() != CAM_MANUAL_CAPTURE_TYPE_OFF) {
   7161                 if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL1) {
   7162                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_1);
   7163                 } else if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL2) {
   7164                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_2);
   7165                 } else if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL4) {
   7166                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_3);
   7167                 } else {
   7168                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF);
   7169                 }
   7170             }
   7171 
   7172             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EXPOSURE_TIME,
   7173                     exp_settings)) {
   7174                 return BAD_VALUE;
   7175             }
   7176             m_expTime = expTimeNs;
   7177 
   7178             return NO_ERROR;
   7179         }
   7180     }
   7181 
   7182     LOGE("Invalid exposure time, value: %s",
   7183           (expTimeStr == NULL) ? "NULL" : expTimeStr);
   7184     return BAD_VALUE;
   7185 }
   7186 
   7187 /*===========================================================================
   7188  * FUNCTION   : setLongshotEnable
   7189  *
   7190  * DESCRIPTION: set a flag indicating longshot mode
   7191  *
   7192  * PARAMETERS :
   7193  *   @enable  : true - Longshot enabled
   7194  *              false - Longshot disabled
   7195  *
   7196  * RETURN     : int32_t type of status
   7197  *              NO_ERROR  -- success
   7198  *              none-zero failure code
   7199  *==========================================================================*/
   7200 int32_t QCameraParameters::setLongshotEnable(bool enable)
   7201 {
   7202     int32_t rc = NO_ERROR;
   7203     int8_t value = enable ? 1 : 0;
   7204 
   7205     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   7206         LOGE("Failed to initialize group update table");
   7207         return BAD_TYPE;
   7208     }
   7209 
   7210     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LONGSHOT_ENABLE, value)) {
   7211         LOGE("Failed to update table");
   7212         return BAD_VALUE;
   7213     }
   7214 
   7215     rc = commitSetBatch();
   7216     if (rc != NO_ERROR) {
   7217         LOGE("Failed to parameter changes");
   7218         return rc;
   7219     }
   7220 
   7221     m_bLongshotEnabled = enable;
   7222 
   7223     return rc;
   7224 }
   7225 
   7226 /*===========================================================================
   7227  * FUNCTION   : setFlash
   7228  *
   7229  * DESCRIPTION: set flash mode
   7230  *
   7231  * PARAMETERS :
   7232  *   @flashStr : LED flash mode value string
   7233  *
   7234  * RETURN     : int32_t type of status
   7235  *              NO_ERROR  -- success
   7236  *              none-zero failure code
   7237  *==========================================================================*/
   7238 int32_t QCameraParameters::setFlash(const char *flashStr)
   7239 {
   7240     if (flashStr != NULL) {
   7241         int32_t value = lookupAttr(FLASH_MODES_MAP, PARAM_MAP_SIZE(FLASH_MODES_MAP), flashStr);
   7242         if (value != NAME_NOT_FOUND) {
   7243             LOGH("Setting Flash value %s", flashStr);
   7244             updateParamEntry(KEY_FLASH_MODE, flashStr);
   7245             mFlashValue = value;
   7246             return NO_ERROR;
   7247         }
   7248     }
   7249     LOGE("Invalid flash value: %s", (flashStr == NULL) ? "NULL" : flashStr);
   7250     return BAD_VALUE;
   7251 }
   7252 
   7253 /*===========================================================================
   7254  * FUNCTION   : updateFlashMode
   7255  *
   7256  * DESCRIPTION: update flash mode
   7257  *
   7258  * PARAMETERS :
   7259  *   @flashStr : LED flash mode value
   7260  *
   7261  * RETURN     : int32_t type of status
   7262  *              NO_ERROR  -- success
   7263  *              none-zero failure code
   7264  *==========================================================================*/
   7265 int32_t QCameraParameters::updateFlashMode(cam_flash_mode_t flash_mode)
   7266 {
   7267     int32_t rc = NO_ERROR;
   7268     if (flash_mode >= CAM_FLASH_MODE_MAX) {
   7269         LOGH("Error!! Invalid flash mode (%d)", flash_mode);
   7270         return BAD_VALUE;
   7271     }
   7272     LOGH("Setting Flash mode from EZTune %d", flash_mode);
   7273 
   7274     const char *flash_mode_str = lookupNameByValue(FLASH_MODES_MAP,
   7275             PARAM_MAP_SIZE(FLASH_MODES_MAP), flash_mode);
   7276     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   7277         LOGE("Failed to initialize group update table");
   7278         return BAD_TYPE;
   7279     }
   7280     rc = setFlash(flash_mode_str);
   7281     if (rc != NO_ERROR) {
   7282         LOGE("Failed to update Flash mode");
   7283         return rc;
   7284     }
   7285 
   7286     LOGH("Setting Flash mode %d", mFlashValue);
   7287     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LED_MODE, mFlashValue)) {
   7288         LOGE("Failed to set led mode");
   7289         return BAD_VALUE;
   7290     }
   7291 
   7292     rc = commitSetBatch();
   7293     if (rc != NO_ERROR) {
   7294         LOGE("Failed to commit parameters");
   7295         return rc;
   7296     }
   7297 
   7298     return NO_ERROR;
   7299 }
   7300 
   7301 
   7302 /*===========================================================================
   7303  * FUNCTION   : configureFlash
   7304  *
   7305  * DESCRIPTION: configure Flash Bracketing.
   7306  *
   7307  * PARAMETERS :
   7308  *    @frame_config : output configuration structure to fill in.
   7309  *
   7310  * RETURN     : int32_t type of status
   7311  *              NO_ERROR  -- success
   7312  *              none-zero failure code
   7313  *==========================================================================*/
   7314 int32_t QCameraParameters::configureFlash(cam_capture_frame_config_t &frame_config)
   7315 {
   7316     LOGH("E");
   7317     int32_t rc = NO_ERROR;
   7318     uint32_t i = 0;
   7319 
   7320     if (isChromaFlashEnabled()) {
   7321 
   7322         rc = setToneMapMode(false, false);
   7323         if (rc != NO_ERROR) {
   7324             LOGE("Failed to configure tone map");
   7325             return rc;
   7326         }
   7327 
   7328         rc = setCDSMode(CAM_CDS_MODE_OFF, false);
   7329         if (rc != NO_ERROR) {
   7330             LOGE("Failed to configure csd mode");
   7331             return rc;
   7332         }
   7333 
   7334         LOGH("Enable Chroma Flash capture");
   7335         cam_flash_mode_t flash_mode = CAM_FLASH_MODE_OFF;
   7336         frame_config.num_batch =
   7337                 m_pCapability->chroma_flash_settings_need.burst_count;
   7338         if (frame_config.num_batch > CAM_MAX_FLASH_BRACKETING) {
   7339             frame_config.num_batch = CAM_MAX_FLASH_BRACKETING;
   7340         }
   7341         for (i = 0; i < frame_config.num_batch; i++) {
   7342             flash_mode = (m_pCapability->chroma_flash_settings_need.flash_bracketing[i]) ?
   7343                     CAM_FLASH_MODE_ON:CAM_FLASH_MODE_OFF;
   7344             frame_config.configs[i].num_frames = 1;
   7345             frame_config.configs[i].type = CAM_CAPTURE_FLASH;
   7346             frame_config.configs[i].flash_mode = flash_mode;
   7347         }
   7348     } else if (mFlashValue != CAM_FLASH_MODE_OFF) {
   7349         frame_config.num_batch = 1;
   7350         for (i = 0; i < frame_config.num_batch; i++) {
   7351             frame_config.configs[i].num_frames = getNumOfSnapshots();
   7352             frame_config.configs[i].type = CAM_CAPTURE_FLASH;
   7353             frame_config.configs[i].flash_mode =(cam_flash_mode_t)mFlashValue;
   7354         }
   7355     }
   7356 
   7357     LOGD("Flash frame batch cnt = %d",frame_config.num_batch);
   7358     return rc;
   7359 }
   7360 
   7361 /*===========================================================================
   7362  * FUNCTION   : configureHDRBracketing
   7363  *
   7364  * DESCRIPTION: configure HDR Bracketing.
   7365  *
   7366  * PARAMETERS :
   7367  *    @frame_config : output configuration structure to fill in.
   7368  *
   7369  * RETURN     : int32_t type of status
   7370  *              NO_ERROR  -- success
   7371  *              none-zero failure code
   7372  *==========================================================================*/
   7373 int32_t QCameraParameters::configureHDRBracketing(cam_capture_frame_config_t &frame_config)
   7374 {
   7375     LOGH("E");
   7376     int32_t rc = NO_ERROR;
   7377     uint32_t i = 0;
   7378 
   7379     uint32_t hdrFrameCount = m_pCapability->hdr_bracketing_setting.num_frames;
   7380     LOGH("HDR values %d, %d frame count: %u",
   7381           (int8_t) m_pCapability->hdr_bracketing_setting.exp_val.values[0],
   7382           (int8_t) m_pCapability->hdr_bracketing_setting.exp_val.values[1],
   7383           hdrFrameCount);
   7384 
   7385     frame_config.num_batch = hdrFrameCount;
   7386 
   7387     cam_bracket_mode mode =
   7388             m_pCapability->hdr_bracketing_setting.exp_val.mode;
   7389     if (mode == CAM_EXP_BRACKETING_ON) {
   7390         rc = setToneMapMode(false, true);
   7391         if (rc != NO_ERROR) {
   7392             LOGW("Failed to disable tone map during HDR");
   7393         }
   7394     }
   7395     for (i = 0; i < frame_config.num_batch; i++) {
   7396         frame_config.configs[i].num_frames = 1;
   7397         frame_config.configs[i].type = CAM_CAPTURE_BRACKETING;
   7398         frame_config.configs[i].hdr_mode.mode = mode;
   7399         frame_config.configs[i].hdr_mode.values =
   7400                 m_pCapability->hdr_bracketing_setting.exp_val.values[i];
   7401         LOGD("exp values %d",
   7402                 (int)frame_config.configs[i].hdr_mode.values);
   7403     }
   7404     return rc;
   7405 }
   7406 
   7407 /*===========================================================================
   7408  * FUNCTION   : configureAEBracketing
   7409  *
   7410  * DESCRIPTION: configure AE Bracketing.
   7411  *
   7412  * PARAMETERS :
   7413  *    @frame_config : output configuration structure to fill in.
   7414  *
   7415  * RETURN     : int32_t type of status
   7416  *              NO_ERROR  -- success
   7417  *              none-zero failure code
   7418  *==========================================================================*/
   7419 int32_t QCameraParameters::configureAEBracketing(cam_capture_frame_config_t &frame_config)
   7420 {
   7421     LOGH("E");
   7422     int32_t rc = NO_ERROR;
   7423     uint32_t i = 0;
   7424     char exp_value[MAX_EXP_BRACKETING_LENGTH];
   7425 
   7426     rc = setToneMapMode(false, true);
   7427     if (rc != NO_ERROR) {
   7428         LOGH("Failed to disable tone map during AEBracketing");
   7429     }
   7430 
   7431     uint32_t burstCount = 0;
   7432     const char *str_val = m_AEBracketingClient.values;
   7433     if ((str_val != NULL) && (strlen(str_val) > 0)) {
   7434         char prop[PROPERTY_VALUE_MAX];
   7435         memset(prop, 0, sizeof(prop));
   7436         strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
   7437         char *saveptr = NULL;
   7438         char *token = strtok_r(prop, ",", &saveptr);
   7439         if (token != NULL) {
   7440             exp_value[burstCount++] = (char)atoi(token);
   7441             while (token != NULL) {
   7442                 token = strtok_r(NULL, ",", &saveptr);
   7443                 if (token != NULL) {
   7444                     exp_value[burstCount++] = (char)atoi(token);
   7445                 }
   7446             }
   7447         }
   7448     }
   7449 
   7450     frame_config.num_batch = burstCount;
   7451     cam_bracket_mode mode = m_AEBracketingClient.mode;
   7452 
   7453     for (i = 0; i < frame_config.num_batch; i++) {
   7454         frame_config.configs[i].num_frames = 1;
   7455         frame_config.configs[i].type = CAM_CAPTURE_BRACKETING;
   7456         frame_config.configs[i].hdr_mode.mode = mode;
   7457         frame_config.configs[i].hdr_mode.values =
   7458                 m_AEBracketingClient.values[i];
   7459         LOGD("exp values %d", (int)m_AEBracketingClient.values[i]);
   7460     }
   7461 
   7462     LOGH("num_frame = %d X", burstCount);
   7463     return rc;
   7464 }
   7465 
   7466 /*===========================================================================
   7467  * FUNCTION   : configureLowLight
   7468  *
   7469  * DESCRIPTION: configure low light frame capture use case.
   7470  *
   7471  * PARAMETERS :
   7472  *    @frame_config : output configuration structure to fill in.
   7473  *
   7474  * RETURN     : int32_t type of status
   7475  *              NO_ERROR  -- success
   7476  *              none-zero failure code
   7477  *==========================================================================*/
   7478 int32_t QCameraParameters::configureLowLight(cam_capture_frame_config_t &frame_config)
   7479 {
   7480     int32_t rc = NO_ERROR;
   7481 
   7482     frame_config.num_batch = 1;
   7483     frame_config.configs[0].num_frames = getNumOfSnapshots();
   7484     frame_config.configs[0].type = CAM_CAPTURE_LOW_LIGHT;
   7485     frame_config.configs[0].low_light_mode = CAM_LOW_LIGHT_ON;
   7486     LOGH("Snapshot Count: %d", frame_config.configs[0].num_frames);
   7487     return rc;
   7488 }
   7489 
   7490 /*===========================================================================
   7491  * FUNCTION   : configureManualCapture
   7492  *
   7493  * DESCRIPTION: configure manual capture.
   7494  *
   7495  * PARAMETERS :
   7496  *    @frame_config : output configaration structure to fill in.
   7497  *
   7498  * RETURN     : int32_t type of status
   7499  *              NO_ERROR  -- success
   7500  *              none-zero failure code
   7501  *==========================================================================*/
   7502 int32_t QCameraParameters::configureManualCapture(cam_capture_frame_config_t &frame_config)
   7503 {
   7504     int32_t rc = NO_ERROR;
   7505     uint32_t i = 0;
   7506 
   7507     LOGD("E");
   7508     if (getManualCaptureMode()) {
   7509         frame_config.num_batch = 1;
   7510         for (i = 0; i < frame_config.num_batch; i++) {
   7511             frame_config.configs[i].num_frames = getNumOfSnapshots();
   7512             frame_config.configs[i].type = CAM_CAPTURE_MANUAL_3A;
   7513             if (m_expTime != 0) {
   7514                 frame_config.configs[i].manual_3A_mode.exp_mode = CAM_SETTINGS_TYPE_ON;
   7515                 frame_config.configs[i].manual_3A_mode.exp_time = m_expTime;
   7516             } else {
   7517                 frame_config.configs[i].manual_3A_mode.exp_mode = CAM_SETTINGS_TYPE_AUTO;
   7518                 frame_config.configs[i].manual_3A_mode.exp_time = 0;
   7519             }
   7520 
   7521             if (m_isoValue != 0) {
   7522                 frame_config.configs[i].manual_3A_mode.iso_mode = CAM_SETTINGS_TYPE_ON;
   7523                 frame_config.configs[i].manual_3A_mode.iso_value = m_isoValue;
   7524             } else {
   7525                 frame_config.configs[i].manual_3A_mode.iso_mode = CAM_SETTINGS_TYPE_AUTO;
   7526                 frame_config.configs[i].manual_3A_mode.iso_value = 0;
   7527             }
   7528         }
   7529     }
   7530     LOGD("X: batch cnt = %d", frame_config.num_batch);
   7531     return rc;
   7532 }
   7533 
   7534 /*===========================================================================
   7535  * FUNCTION   : configFrameCapture
   7536  *
   7537  * DESCRIPTION: configuration for ZSL special captures (FLASH/HDR etc)
   7538  *
   7539  * PARAMETERS :
   7540  *   @commitSettings : flag to enable or disable commit this this settings
   7541  *
   7542  * RETURN     : int32_t type of status
   7543  *              NO_ERROR  -- success
   7544  *              none-zero failure code
   7545  *==========================================================================*/
   7546 int32_t QCameraParameters::configFrameCapture(bool commitSettings)
   7547 {
   7548     int32_t rc = NO_ERROR;
   7549     int32_t value;
   7550 
   7551     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
   7552 
   7553     if (commitSettings) {
   7554         if(initBatchUpdate(m_pParamBuf) < 0 ) {
   7555             LOGE("Failed to initialize group update table");
   7556             return BAD_TYPE;
   7557         }
   7558     }
   7559 
   7560     if (isHDREnabled() || m_bAeBracketingEnabled || m_bAFBracketingOn ||
   7561           m_bOptiZoomOn || m_bReFocusOn || m_LowLightLevel
   7562           || getManualCaptureMode()) {
   7563         value = CAM_FLASH_MODE_OFF;
   7564     } else if (isChromaFlashEnabled()) {
   7565         value = CAM_FLASH_MODE_ON;
   7566     } else {
   7567         value = mFlashValue;
   7568     }
   7569 
   7570     if (value != CAM_FLASH_MODE_OFF) {
   7571         configureFlash(m_captureFrameConfig);
   7572     } else if(isHDREnabled()) {
   7573         configureHDRBracketing (m_captureFrameConfig);
   7574     } else if(isAEBracketEnabled()) {
   7575         configureAEBracketing (m_captureFrameConfig);
   7576     } else if (m_LowLightLevel) {
   7577         configureLowLight (m_captureFrameConfig);
   7578 
   7579         //Added reset capture type as a last batch for back-end to restore settings.
   7580         int32_t batch_count = m_captureFrameConfig.num_batch;
   7581         m_captureFrameConfig.configs[batch_count].type = CAM_CAPTURE_RESET;
   7582         m_captureFrameConfig.configs[batch_count].num_frames = 0;
   7583         m_captureFrameConfig.num_batch++;
   7584     } else if (getManualCaptureMode() >= CAM_MANUAL_CAPTURE_TYPE_2){
   7585         rc = configureManualCapture (m_captureFrameConfig);
   7586         //Added reset capture type as a last batch for back-end to restore settings.
   7587         int32_t batch_count = m_captureFrameConfig.num_batch;
   7588         m_captureFrameConfig.configs[batch_count].type = CAM_CAPTURE_RESET;
   7589         m_captureFrameConfig.configs[batch_count].num_frames = 0;
   7590         m_captureFrameConfig.num_batch++;
   7591     }
   7592 
   7593     rc = ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CAPTURE_FRAME_CONFIG,
   7594             (cam_capture_frame_config_t)m_captureFrameConfig);
   7595     if (rc != NO_ERROR) {
   7596         rc = BAD_VALUE;
   7597         LOGE("Failed to set capture settings");
   7598         return rc;
   7599     }
   7600 
   7601     if (commitSettings) {
   7602         rc = commitSetBatch();
   7603         if (rc != NO_ERROR) {
   7604             LOGE("Failed to commit parameters");
   7605             return rc;
   7606         }
   7607     }
   7608     return rc;
   7609 }
   7610 
   7611 /*===========================================================================
   7612  * FUNCTION   : resetFrameCapture
   7613  *
   7614  * DESCRIPTION: reset special captures settings(FLASH/HDR etc)
   7615  *
   7616  * PARAMETERS :
   7617  *   @commitSettings : flag to enable or disable commit this this settings
   7618  *
   7619  * RETURN     : int32_t type of status
   7620  *              NO_ERROR  -- success
   7621  *              none-zero failure code
   7622  *==========================================================================*/
   7623 int32_t QCameraParameters::resetFrameCapture(bool commitSettings)
   7624 {
   7625     int32_t rc = NO_ERROR;
   7626     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
   7627 
   7628     if (commitSettings) {
   7629         if(initBatchUpdate(m_pParamBuf) < 0 ) {
   7630             LOGE("Failed to initialize group update table");
   7631             return BAD_TYPE;
   7632         }
   7633     }
   7634 
   7635     if (isHDREnabled() || isAEBracketEnabled()) {
   7636         rc = setToneMapMode(true, true);
   7637         if (rc != NO_ERROR) {
   7638             LOGH("Failed to enable tone map during HDR/AEBracketing");
   7639         }
   7640         rc = stopAEBracket();
   7641     } else if ((isChromaFlashEnabled()) || (mFlashValue != CAM_FLASH_MODE_OFF)
   7642             || (getLowLightLevel() != CAM_LOW_LIGHT_OFF)) {
   7643         rc = setToneMapMode(true, false);
   7644         if (rc != NO_ERROR) {
   7645             LOGH("Failed to enable tone map during chroma flash");
   7646         }
   7647 
   7648         rc = setCDSMode(mCds_mode, false);
   7649         if (rc != NO_ERROR) {
   7650             LOGE("Failed to configure csd mode");
   7651             return rc;
   7652         }
   7653     }
   7654 
   7655     rc = ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CAPTURE_FRAME_CONFIG,
   7656             (cam_capture_frame_config_t)m_captureFrameConfig);
   7657     if (rc != NO_ERROR) {
   7658         rc = BAD_VALUE;
   7659         LOGE("Failed to set capture settings");
   7660         return rc;
   7661     }
   7662 
   7663     if (commitSettings) {
   7664         rc = commitSetBatch();
   7665         if (rc != NO_ERROR) {
   7666             LOGE("Failed to commit parameters");
   7667             return rc;
   7668         }
   7669     }
   7670     return rc;
   7671 }
   7672 
   7673 /*===========================================================================
   7674  * FUNCTION   : setAecLock
   7675  *
   7676  * DESCRIPTION: set AEC lock value
   7677  *
   7678  * PARAMETERS :
   7679  *   @aecLockStr : AEC lock value string
   7680  *
   7681  * RETURN     : int32_t type of status
   7682  *              NO_ERROR  -- success
   7683  *              none-zero failure code
   7684  *==========================================================================*/
   7685 int32_t QCameraParameters::setAecLock(const char *aecLockStr)
   7686 {
   7687     if (aecLockStr != NULL) {
   7688         int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
   7689                 aecLockStr);
   7690         if (value != NAME_NOT_FOUND) {
   7691             LOGH("Setting AECLock value %s", aecLockStr);
   7692             updateParamEntry(KEY_AUTO_EXPOSURE_LOCK, aecLockStr);
   7693             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   7694                     CAM_INTF_PARM_AEC_LOCK, (uint32_t)value)) {
   7695                 return BAD_VALUE;
   7696             }
   7697             return NO_ERROR;
   7698         }
   7699     }
   7700     LOGE("Invalid AECLock value: %s",
   7701         (aecLockStr == NULL) ? "NULL" : aecLockStr);
   7702     return BAD_VALUE;
   7703 }
   7704 
   7705 /*===========================================================================
   7706  * FUNCTION   : setAwbLock
   7707  *
   7708  * DESCRIPTION: set AWB lock value
   7709  *
   7710  * PARAMETERS :
   7711  *   @awbLockStr : AWB lock value string
   7712  *
   7713  * RETURN     : int32_t type of status
   7714  *              NO_ERROR  -- success
   7715  *              none-zero failure code
   7716  *==========================================================================*/
   7717 int32_t QCameraParameters::setAwbLock(const char *awbLockStr)
   7718 {
   7719     if (awbLockStr != NULL) {
   7720         int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
   7721                 awbLockStr);
   7722         if (value != NAME_NOT_FOUND) {
   7723             LOGH("Setting AWBLock value %s", awbLockStr);
   7724             updateParamEntry(KEY_AUTO_WHITEBALANCE_LOCK, awbLockStr);
   7725             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   7726                     CAM_INTF_PARM_AWB_LOCK, (uint32_t)value)) {
   7727                 return BAD_VALUE;
   7728             }
   7729             return NO_ERROR;
   7730         }
   7731     }
   7732     LOGE("Invalid AWBLock value: %s", (awbLockStr == NULL) ? "NULL" : awbLockStr);
   7733     return BAD_VALUE;
   7734 }
   7735 
   7736 /*===========================================================================
   7737  * FUNCTION   : setMCEValue
   7738  *
   7739  * DESCRIPTION: set memory color enhancement value
   7740  *
   7741  * PARAMETERS :
   7742  *   @mceStr : MCE value string
   7743  *
   7744  * RETURN     : int32_t type of status
   7745  *              NO_ERROR  -- success
   7746  *              none-zero failure code
   7747  *==========================================================================*/
   7748 int32_t QCameraParameters::setMCEValue(const char *mceStr)
   7749 {
   7750     if (mceStr != NULL) {
   7751         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   7752                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), mceStr);
   7753         if (value != NAME_NOT_FOUND) {
   7754             LOGH("Setting AWBLock value %s", mceStr);
   7755             updateParamEntry(KEY_QC_MEMORY_COLOR_ENHANCEMENT, mceStr);
   7756             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MCE, value)) {
   7757                 return BAD_VALUE;
   7758             }
   7759             return NO_ERROR;
   7760         }
   7761     }
   7762     LOGE("Invalid MCE value: %s", (mceStr == NULL) ? "NULL" : mceStr);
   7763     return BAD_VALUE;
   7764 }
   7765 
   7766 /*===========================================================================
   7767  * FUNCTION   : setTintlessValue
   7768  *
   7769  * DESCRIPTION: enable/disable tintless from user setting
   7770  *
   7771  * PARAMETERS :
   7772  *   @params  : user setting parameters
   7773  *
   7774  * RETURN     : int32_t type of status
   7775  *              NO_ERROR  -- success
   7776  *              none-zero failure code
   7777  *==========================================================================*/
   7778 int32_t QCameraParameters::setTintlessValue(const QCameraParameters& params)
   7779 {
   7780     const char *str = params.get(KEY_QC_TINTLESS_ENABLE);
   7781     const char *prev_str = get(KEY_QC_TINTLESS_ENABLE);
   7782     char prop[PROPERTY_VALUE_MAX];
   7783 
   7784     memset(prop, 0, sizeof(prop));
   7785     property_get("persist.camera.tintless", prop, VALUE_ENABLE);
   7786     if (str != NULL) {
   7787         if (prev_str == NULL ||
   7788             strcmp(str, prev_str) != 0) {
   7789             return setTintlessValue(str);
   7790         }
   7791     } else {
   7792         if (prev_str == NULL ||
   7793             strcmp(prev_str, prop) != 0 ) {
   7794             setTintlessValue(prop);
   7795         }
   7796     }
   7797 
   7798     return NO_ERROR;
   7799 }
   7800 
   7801 /*===========================================================================
   7802  * FUNCTION   : setTintless
   7803  *
   7804  * DESCRIPTION: set tintless mode
   7805  *
   7806  * PARAMETERS :
   7807  *   @enable : 1 = enable, 0 = disable
   7808  *
   7809  * RETURN     : int32_t type of status
   7810  *              NO_ERROR  -- success
   7811  *              none-zero failure code
   7812  *==========================================================================*/
   7813 void QCameraParameters::setTintless(bool enable)
   7814 {
   7815     if (enable) {
   7816         setTintlessValue(VALUE_ENABLE);
   7817     } else {
   7818         setTintlessValue(VALUE_DISABLE);
   7819     }
   7820 }
   7821 
   7822 /*===========================================================================
   7823  * FUNCTION   : setTintlessValue
   7824  *
   7825  * DESCRIPTION: set tintless value
   7826  *
   7827  * PARAMETERS :
   7828  *   @tintStr : Tintless value string
   7829  *
   7830  * RETURN     : int32_t type of status
   7831  *              NO_ERROR  -- success
   7832  *              none-zero failure code
   7833  *==========================================================================*/
   7834 int32_t QCameraParameters::setTintlessValue(const char *tintStr)
   7835 {
   7836     if (tintStr != NULL) {
   7837         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   7838                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), tintStr);
   7839         if (value != NAME_NOT_FOUND) {
   7840             LOGH("Setting Tintless value %s", tintStr);
   7841             updateParamEntry(KEY_QC_TINTLESS_ENABLE, tintStr);
   7842             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TINTLESS, value)) {
   7843                 return BAD_VALUE;
   7844             }
   7845             return NO_ERROR;
   7846         }
   7847     }
   7848     LOGE("Invalid Tintless value: %s", (tintStr == NULL) ? "NULL" : tintStr);
   7849     return BAD_VALUE;
   7850 }
   7851 
   7852 /*===========================================================================
   7853  * FUNCTION   : setCDSMode
   7854  *
   7855  * DESCRIPTION: Set CDS mode
   7856  *
   7857  * PARAMETERS :
   7858  *   @params  : user setting parameters
   7859  *
   7860  * RETURN     : int32_t type of status
   7861  *              NO_ERROR  -- success
   7862  *              none-zero failure code
   7863  *==========================================================================*/
   7864 int32_t QCameraParameters::setCDSMode(const QCameraParameters& params)
   7865 {
   7866     const char *str = params.get(KEY_QC_CDS_MODE);
   7867     const char *prev_str = get(KEY_QC_CDS_MODE);
   7868     const char *video_str = params.get(KEY_QC_VIDEO_CDS_MODE);
   7869     const char *video_prev_str = get(KEY_QC_VIDEO_CDS_MODE);
   7870     int32_t rc = NO_ERROR;
   7871 
   7872     if (m_bRecordingHint_new == true) {
   7873         if (video_str) {
   7874             if ((video_prev_str == NULL) || (strcmp(video_str, video_prev_str) != 0)) {
   7875                 int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
   7876                         video_str);
   7877                 if (cds_mode != NAME_NOT_FOUND) {
   7878                     updateParamEntry(KEY_QC_VIDEO_CDS_MODE, video_str);
   7879                     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
   7880                         LOGE("Failed CDS MODE to update table");
   7881                         rc = BAD_VALUE;
   7882                     } else {
   7883                         LOGD("Set CDS in video mode = %d", cds_mode);
   7884                         mCds_mode = cds_mode;
   7885                         m_bNeedRestart = true;
   7886                     }
   7887                 } else {
   7888                     LOGE("Invalid argument for video CDS MODE %d",  cds_mode);
   7889                     rc = BAD_VALUE;
   7890                 }
   7891             }
   7892         } else {
   7893             char video_prop[PROPERTY_VALUE_MAX];
   7894             memset(video_prop, 0, sizeof(video_prop));
   7895             property_get("persist.camera.video.CDS", video_prop, CDS_MODE_ON);
   7896             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
   7897                     video_prop);
   7898             if (cds_mode != NAME_NOT_FOUND) {
   7899                 updateParamEntry(KEY_QC_VIDEO_CDS_MODE, video_prop);
   7900                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
   7901                     LOGE("Failed CDS MODE to update table");
   7902                     rc = BAD_VALUE;
   7903                 } else {
   7904                     LOGD("Set CDS in video mode from setprop = %d", cds_mode);
   7905                     mCds_mode = cds_mode;
   7906                 }
   7907             } else {
   7908                 LOGE("Invalid prop for video CDS MODE %d",  cds_mode);
   7909                 rc = BAD_VALUE;
   7910             }
   7911         }
   7912     } else {
   7913         if (str) {
   7914             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
   7915                 int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
   7916                         str);
   7917                 if (cds_mode != NAME_NOT_FOUND) {
   7918                     updateParamEntry(KEY_QC_CDS_MODE, str);
   7919                     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
   7920                         LOGE("Failed CDS MODE to update table");
   7921                         rc = BAD_VALUE;
   7922                     } else {
   7923                         LOGD("Set CDS in capture mode = %d", cds_mode);
   7924                         mCds_mode = cds_mode;
   7925                         m_bNeedRestart = true;
   7926                     }
   7927                 } else {
   7928                     LOGE("Invalid argument for snapshot CDS MODE %d",  cds_mode);
   7929                     rc = BAD_VALUE;
   7930                 }
   7931             }
   7932         } else {
   7933             char prop[PROPERTY_VALUE_MAX];
   7934             memset(prop, 0, sizeof(prop));
   7935             property_get("persist.camera.CDS", prop, CDS_MODE_ON);
   7936             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
   7937                     prop);
   7938             if (cds_mode != NAME_NOT_FOUND) {
   7939                 updateParamEntry(KEY_QC_CDS_MODE, prop);
   7940                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
   7941                     LOGE("Failed CDS MODE to update table");
   7942                     rc = BAD_VALUE;
   7943                 } else {
   7944                     LOGD("Set CDS in snapshot mode from setprop = %d", cds_mode);
   7945                     mCds_mode = cds_mode;
   7946                 }
   7947             } else {
   7948                 LOGE("Invalid prop for snapshot CDS MODE %d",  cds_mode);
   7949                 rc = BAD_VALUE;
   7950             }
   7951         }
   7952     }
   7953 
   7954     return rc;
   7955 }
   7956 
   7957 /*===========================================================================
   7958  * FUNCTION   : setInitialExposureIndex
   7959  *
   7960  * DESCRIPTION: Set initial exposure index value
   7961  *
   7962  * PARAMETERS :
   7963  *   @params  : user setting parameters
   7964  *
   7965  * RETURN     : int32_t type of status
   7966  *              NO_ERROR  -- success
   7967  *              none-zero failure code
   7968  *==========================================================================*/
   7969 int32_t QCameraParameters::setInitialExposureIndex(const QCameraParameters& params)
   7970 {
   7971     int32_t rc = NO_ERROR;
   7972     int value = -1;
   7973     const char *str = params.get(KEY_QC_INITIAL_EXPOSURE_INDEX);
   7974     const char *prev_str = get(KEY_QC_INITIAL_EXPOSURE_INDEX);
   7975     if (str) {
   7976         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
   7977             value = atoi(str);
   7978             LOGD("Set initial exposure index value from param = %d", value);
   7979             if (value >= 0) {
   7980                 updateParamEntry(KEY_QC_INITIAL_EXPOSURE_INDEX, str);
   7981             }
   7982         }
   7983     } else {
   7984         char prop[PROPERTY_VALUE_MAX];
   7985         memset(prop, 0, sizeof(prop));
   7986         property_get("persist.camera.initial.exp.val", prop, "");
   7987         if ((strlen(prop) > 0) &&
   7988                 ( (prev_str == NULL) || (strcmp(prop, prev_str) != 0))) {
   7989             value = atoi(prop);
   7990             LOGD("Set initial exposure index value from setprop = %d", value);
   7991             if (value >= 0) {
   7992                 updateParamEntry(KEY_QC_INITIAL_EXPOSURE_INDEX, prop);
   7993             }
   7994         }
   7995     }
   7996 
   7997     if (value >= 0) {
   7998         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   7999                 CAM_INTF_PARM_INITIAL_EXPOSURE_INDEX, (uint32_t)value)) {
   8000             LOGE("Failed to update initial exposure index value");
   8001             rc = BAD_VALUE;
   8002         }
   8003     } else {
   8004         LOGD("Invalid value for initial exposure index value %d", value);
   8005     }
   8006 
   8007     return rc;
   8008 }
   8009 
   8010 /*===========================================================================
   8011  * FUNCTION   : setInstantCapture
   8012  *
   8013  * DESCRIPTION: Set Instant Capture related params
   8014  *
   8015  * PARAMETERS :
   8016  *   @params  : user setting parameters
   8017  *
   8018  * RETURN     : int32_t type of status
   8019  *              NO_ERROR  -- success
   8020  *              none-zero failure code
   8021  *==========================================================================*/
   8022 int32_t QCameraParameters::setInstantCapture(const QCameraParameters& params)
   8023 {
   8024     int32_t rc = NO_ERROR;
   8025     int value = -1;
   8026     // Check for instant capture, this will enable instant AEC as well.
   8027     // This param will trigger the instant AEC param to backend
   8028     // And also will be useful for instant capture.
   8029     const char *str = params.get(KEY_QC_INSTANT_CAPTURE);
   8030     const char *prev_str = get(KEY_QC_INSTANT_CAPTURE);
   8031     if (str) {
   8032         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
   8033             value = lookupAttr(INSTANT_CAPTURE_MODES_MAP,
   8034                     PARAM_MAP_SIZE(INSTANT_CAPTURE_MODES_MAP), str);
   8035             LOGD("Set instant Capture from param = %d", value);
   8036             if(value != NAME_NOT_FOUND) {
   8037                 updateParamEntry(KEY_QC_INSTANT_CAPTURE, str);
   8038             }
   8039         }
   8040     } else {
   8041         char prop[PROPERTY_VALUE_MAX];
   8042         memset(prop, 0, sizeof(prop));
   8043         property_get("persist.camera.instant.capture", prop, KEY_QC_INSTANT_CAPTURE_DISABLE);
   8044         if ((prev_str == NULL) || (strcmp(prop, prev_str) != 0)) {
   8045             value = lookupAttr(INSTANT_CAPTURE_MODES_MAP,
   8046                     PARAM_MAP_SIZE(INSTANT_CAPTURE_MODES_MAP), prop);
   8047             LOGD("Set instant capture from setprop = %d", value);
   8048             if (value != NAME_NOT_FOUND) {
   8049                 updateParamEntry(KEY_QC_INSTANT_CAPTURE, prop);
   8050             }
   8051         }
   8052     }
   8053 
   8054     // Set instant AEC param to the backend for either instant capture or instant AEC
   8055     // 0 - disbale (normal AEC)
   8056     // 1 - Aggressive AEC (algo used in backend)
   8057     // 2 - Fast AEC (algo used in backend)
   8058     if (value != NAME_NOT_FOUND && value != -1) {
   8059         m_bInstantCapture = (value > 0)? true : false;
   8060         setInstantAEC((uint8_t)value, false);
   8061     }
   8062 
   8063 
   8064     // get frame aec bound value from setprop.
   8065     // This value indicates the number of frames, camera interface
   8066     // will wait for getting the instant capture frame.
   8067     // Default value set to 7.
   8068     // This value also indicates the number of frames, that HAL
   8069     // will not display and will not send preview frames to app
   8070     // This will be applicable only if instant capture is set.
   8071     if (m_bInstantCapture) {
   8072         char prop[PROPERTY_VALUE_MAX];
   8073         memset(prop, 0, sizeof(prop));
   8074         property_get("persist.camera.ae.capture.bound", prop, "7");
   8075         int32_t frame_bound = atoi(prop);
   8076         if (frame_bound >= 0) {
   8077             mAecFrameBound = (uint8_t)frame_bound;
   8078         } else {
   8079             LOGE("Invalid prop for aec frame bound %d", frame_bound);
   8080             rc = BAD_VALUE;
   8081         }
   8082     }
   8083     return rc;
   8084 }
   8085 
   8086 /*===========================================================================
   8087  * FUNCTION   : setInstantAEC
   8088  *
   8089  * DESCRIPTION: Set Instant AEC related params
   8090  *
   8091  * PARAMETERS :
   8092  *   @params  : user setting parameters
   8093  *
   8094  * RETURN     : int32_t type of status
   8095  *              NO_ERROR  -- success
   8096  *              none-zero failure code
   8097  *==========================================================================*/
   8098 int32_t QCameraParameters::setInstantAEC(const QCameraParameters& params)
   8099 {
   8100     int32_t rc = NO_ERROR;
   8101     int value = -1;
   8102 
   8103     // Check for instant AEC only when instant capture is not enabled.
   8104     // Instant capture already takes care of the instant AEC as well.
   8105     if (!m_bInstantCapture) {
   8106         // Check for instant AEC. Instant AEC will only enable fast AEC.
   8107         // It will not enable instant capture.
   8108         // This param will trigger the instant AEC param to backend
   8109         const char *str = params.get(KEY_QC_INSTANT_AEC);
   8110         const char *prev_str = get(KEY_QC_INSTANT_AEC);
   8111         if (str) {
   8112             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
   8113                 value = lookupAttr(INSTANT_AEC_MODES_MAP,
   8114                         PARAM_MAP_SIZE(INSTANT_AEC_MODES_MAP), str);
   8115                 LOGD("Set instant AEC from param = %d", value);
   8116             }
   8117         } else {
   8118             char prop[PROPERTY_VALUE_MAX];
   8119             memset(prop, 0, sizeof(prop));
   8120             property_get("persist.camera.instant.aec", prop, KEY_QC_INSTANT_AEC_DISABLE);
   8121             if ((prev_str == NULL) || (strcmp(prop, prev_str) != 0)) {
   8122                 value = lookupAttr(INSTANT_AEC_MODES_MAP,
   8123                         PARAM_MAP_SIZE(INSTANT_AEC_MODES_MAP), prop);
   8124                 LOGD("Set instant AEC from setprop = %d", value);
   8125             }
   8126         }
   8127 
   8128         // Set instant AEC param to the backend for either instant capture or instant AEC
   8129         // 0 - disbale (normal AEC)
   8130         // 1 - Aggressive AEC (algo used in backend)
   8131         // 2 - Fast AEC (algo used in backend)
   8132         if (value != NAME_NOT_FOUND && value != -1) {
   8133             setInstantAEC((uint8_t)value, false);
   8134         }
   8135 
   8136     }
   8137 
   8138     // get frame aec preview skip count from setprop.
   8139     // This value indicates the number of frames, that HAL
   8140     // will not display and will not send preview frames to app
   8141     // Default value set to 7.
   8142     // This will be applicable only if instant aec is set.
   8143     if (m_bInstantAEC) {
   8144         char prop[PROPERTY_VALUE_MAX];
   8145         memset(prop, 0, sizeof(prop));
   8146         property_get("persist.camera.ae.instant.bound", prop, "7");
   8147         int32_t aec_frame_skip_cnt = atoi(prop);
   8148         if (aec_frame_skip_cnt >= 0) {
   8149             mAecSkipDisplayFrameBound = (uint8_t)aec_frame_skip_cnt;
   8150         } else {
   8151             LOGE("Invalid prop for aec frame bound %d", aec_frame_skip_cnt);
   8152             rc = BAD_VALUE;
   8153         }
   8154     }
   8155     return rc;
   8156 }
   8157 
   8158 /*===========================================================================
   8159  * FUNCTION   : setDISValue
   8160  *
   8161  * DESCRIPTION: set DIS value
   8162  *
   8163  * PARAMETERS :
   8164  *   @disStr : DIS value string
   8165  *
   8166  * RETURN     : int32_t type of status
   8167  *              NO_ERROR  -- success
   8168  *              none-zero failure code
   8169  *==========================================================================*/
   8170 int32_t QCameraParameters::setDISValue(const char *disStr)
   8171 {
   8172     if (disStr != NULL) {
   8173         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   8174                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), disStr);
   8175         if (value != NAME_NOT_FOUND) {
   8176             //For some IS types (like EIS 2.0), when DIS value is changed, we need to restart
   8177             //preview because of topology change in backend. But, for now, restart preview
   8178             //for all IS types.
   8179             m_bNeedRestart = true;
   8180             LOGH("Setting DIS value %s", disStr);
   8181             updateParamEntry(KEY_QC_DIS, disStr);
   8182             if (!(strcmp(disStr,"enable"))) {
   8183                 m_bDISEnabled = true;
   8184             } else {
   8185                 m_bDISEnabled = false;
   8186             }
   8187             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_DIS_ENABLE, value)) {
   8188                 return BAD_VALUE;
   8189             }
   8190             return NO_ERROR;
   8191         }
   8192     }
   8193     LOGE("Invalid DIS value: %s", (disStr == NULL) ? "NULL" : disStr);
   8194     m_bDISEnabled = false;
   8195     return BAD_VALUE;
   8196 }
   8197 
   8198 /*===========================================================================
   8199  * FUNCTION   : updateOisValue
   8200  *
   8201  * DESCRIPTION: update OIS value
   8202  *
   8203  * PARAMETERS :
   8204  *   @oisValue : OIS value TRUE/FALSE
   8205  *
   8206  * RETURN     : int32_t type of status
   8207  *              NO_ERROR  -- success
   8208  *              none-zero failure code
   8209  *==========================================================================*/
   8210 int32_t QCameraParameters::updateOisValue(bool oisValue)
   8211 {
   8212     uint8_t enable = 0;
   8213     int32_t rc = NO_ERROR;
   8214 
   8215     // Check for OIS disable
   8216     char ois_prop[PROPERTY_VALUE_MAX];
   8217     memset(ois_prop, 0, sizeof(ois_prop));
   8218     property_get("persist.camera.ois.disable", ois_prop, "0");
   8219     uint8_t ois_disable = (uint8_t)atoi(ois_prop);
   8220 
   8221     //Enable OIS if it is camera mode or Camcoder 4K mode
   8222     if (!m_bRecordingHint || (is4k2kVideoResolution() && m_bRecordingHint)) {
   8223         enable = 1;
   8224         LOGH("Valid OIS mode!! ");
   8225     }
   8226     // Disable OIS if setprop is set
   8227     if (ois_disable || !oisValue) {
   8228         //Disable OIS
   8229         enable = 0;
   8230         LOGH("Disable OIS mode!! ois_disable(%d) oisValue(%d)",
   8231                  ois_disable, oisValue);
   8232 
   8233     }
   8234     m_bOISEnabled = enable;
   8235     if (m_bOISEnabled) {
   8236         updateParamEntry(KEY_QC_OIS, VALUE_ENABLE);
   8237     } else {
   8238         updateParamEntry(KEY_QC_OIS, VALUE_DISABLE);
   8239     }
   8240 
   8241     if (initBatchUpdate(m_pParamBuf) < 0 ) {
   8242         LOGE("Failed to initialize group update table");
   8243         return BAD_TYPE;
   8244     }
   8245 
   8246     LOGH("Sending OIS mode (%d)", enable);
   8247     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_META_LENS_OPT_STAB_MODE, enable)) {
   8248         LOGE("Failed to update table");
   8249         return BAD_VALUE;
   8250     }
   8251 
   8252     rc = commitSetBatch();
   8253     if (rc != NO_ERROR) {
   8254         LOGE("Failed to parameter changes");
   8255         return rc;
   8256     }
   8257 
   8258     return rc;
   8259 }
   8260 
   8261 /*===========================================================================
   8262  * FUNCTION   : setHighFrameRate
   8263  *
   8264  * DESCRIPTION: set high frame rate
   8265  *
   8266  * PARAMETERS :
   8267  *   @hfrMode : HFR mode
   8268  *
   8269  * RETURN     : int32_t type of status
   8270  *              NO_ERROR  -- success
   8271  *              none-zero failure code
   8272  *==========================================================================*/
   8273 int32_t QCameraParameters::setHighFrameRate(const int32_t hfrMode)
   8274 {
   8275     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HFR, hfrMode)) {
   8276         return BAD_VALUE;
   8277     }
   8278 
   8279     return NO_ERROR;
   8280 }
   8281 
   8282 /*===========================================================================
   8283  * FUNCTION   : setLensShadeValue
   8284  *
   8285  * DESCRIPTION: set lens shade value
   8286  *
   8287  * PARAMETERS :
   8288  *   @lensSahdeStr : lens shade value string
   8289  *
   8290  * RETURN     : int32_t type of status
   8291  *              NO_ERROR  -- success
   8292  *              none-zero failure code
   8293  *==========================================================================*/
   8294 int32_t QCameraParameters::setLensShadeValue(const char *lensShadeStr)
   8295 {
   8296     if (lensShadeStr != NULL) {
   8297         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   8298                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), lensShadeStr);
   8299         if (value != NAME_NOT_FOUND) {
   8300             LOGH("Setting LensShade value %s", lensShadeStr);
   8301             updateParamEntry(KEY_QC_LENSSHADE, lensShadeStr);
   8302             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ROLLOFF, value)) {
   8303                 return BAD_VALUE;
   8304             }
   8305             return NO_ERROR;
   8306         }
   8307     }
   8308     LOGE("Invalid LensShade value: %s",
   8309           (lensShadeStr == NULL) ? "NULL" : lensShadeStr);
   8310     return BAD_VALUE;
   8311 }
   8312 
   8313 /*===========================================================================
   8314  * FUNCTION   : setExposureCompensation
   8315  *
   8316  * DESCRIPTION: set exposure compensation value
   8317  *
   8318  * PARAMETERS :
   8319  *   @expComp : exposure compensation value
   8320  *
   8321  * RETURN     : int32_t type of status
   8322  *              NO_ERROR  -- success
   8323  *              none-zero failure code
   8324  *==========================================================================*/
   8325 int32_t QCameraParameters::setExposureCompensation(int expComp)
   8326 {
   8327     char val[16];
   8328     snprintf(val, sizeof(val), "%d", expComp);
   8329     updateParamEntry(KEY_EXPOSURE_COMPENSATION, val);
   8330 
   8331     // Don't need to pass step as part of setParameter because
   8332     // camera daemon is already aware of it.
   8333     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EXPOSURE_COMPENSATION, expComp)) {
   8334         return BAD_VALUE;
   8335     }
   8336 
   8337     return NO_ERROR;
   8338 }
   8339 
   8340 /*===========================================================================
   8341  * FUNCTION   : setWhiteBalance
   8342  *
   8343  * DESCRIPTION: set white balance mode
   8344  *
   8345  * PARAMETERS :
   8346  *   @wbStr   : white balance mode value string
   8347  *
   8348  * RETURN     : int32_t type of status
   8349  *              NO_ERROR  -- success
   8350  *              none-zero failure code
   8351  *==========================================================================*/
   8352 int32_t QCameraParameters::setWhiteBalance(const char *wbStr)
   8353 {
   8354     if (wbStr != NULL) {
   8355         int32_t value = lookupAttr(WHITE_BALANCE_MODES_MAP,
   8356                 PARAM_MAP_SIZE(WHITE_BALANCE_MODES_MAP), wbStr);
   8357         if (value != NAME_NOT_FOUND) {
   8358             LOGH("Setting WhiteBalance value %s", wbStr);
   8359             updateParamEntry(KEY_WHITE_BALANCE, wbStr);
   8360             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WHITE_BALANCE, value)) {
   8361                 return BAD_VALUE;
   8362             }
   8363             return NO_ERROR;
   8364         }
   8365     }
   8366     LOGE("Invalid WhiteBalance value: %s", (wbStr == NULL) ? "NULL" : wbStr);
   8367     return BAD_VALUE;
   8368 }
   8369 
   8370 /*===========================================================================
   8371  * FUNCTION   : setWBManualCCT
   8372  *
   8373  * DESCRIPTION: set setWBManualCCT time
   8374  *
   8375  * PARAMETERS :
   8376  *   @cctStr : string of wb cct, range (2000, 8000) in K.
   8377  *
   8378  * RETURN     : int32_t type of status
   8379  *              NO_ERROR  -- success
   8380  *              none-zero failure code
   8381  *==========================================================================*/
   8382 int32_t  QCameraParameters::setWBManualCCT(const char *cctStr)
   8383 {
   8384     if (cctStr != NULL) {
   8385         int32_t cctVal = atoi(cctStr);
   8386         int32_t minCct = m_pCapability->min_wb_cct; /* 2000K */
   8387         int32_t maxCct = m_pCapability->max_wb_cct; /* 8000K */
   8388 
   8389         if (cctVal >= minCct && cctVal <= maxCct) {
   8390             LOGH(", cct value: %d", cctVal);
   8391             updateParamEntry(KEY_QC_WB_MANUAL_CCT, cctStr);
   8392             cam_manual_wb_parm_t manual_wb;
   8393             manual_wb.type = CAM_MANUAL_WB_MODE_CCT;
   8394             manual_wb.cct = cctVal;
   8395             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WB_MANUAL, manual_wb)) {
   8396                 return BAD_VALUE;
   8397             }
   8398             return NO_ERROR;
   8399         }
   8400     }
   8401 
   8402     LOGE("Invalid cct, value: %s",
   8403             (cctStr == NULL) ? "NULL" : cctStr);
   8404     return BAD_VALUE;
   8405 }
   8406 
   8407 /*===========================================================================
   8408  * FUNCTION   : updateAWBParams
   8409  *
   8410  * DESCRIPTION: update CCT parameters key
   8411  *
   8412  * PARAMETERS :
   8413  *   @awb_params : WB parameters
   8414  *
   8415  * RETURN     : int32_t type of status
   8416  *              NO_ERROR  -- success
   8417  *              none-zero failure code
   8418  *==========================================================================*/
   8419 int32_t QCameraParameters::updateAWBParams(cam_awb_params_t &awb_params)
   8420 {
   8421     //check and update CCT
   8422     int32_t prev_cct = getInt(KEY_QC_WB_MANUAL_CCT);
   8423     if (prev_cct != awb_params.cct_value) {
   8424         LOGD("update current cct value. old:%d, now:%d",
   8425                 prev_cct, awb_params.cct_value);
   8426         set(KEY_QC_WB_MANUAL_CCT, awb_params.cct_value);
   8427     }
   8428 
   8429     //check and update WB gains
   8430     const char *prev_gains = get(KEY_QC_MANUAL_WB_GAINS);
   8431     char gainStr[30];
   8432     snprintf(gainStr, sizeof(gainStr), "%f,%f,%f", awb_params.rgb_gains.r_gain,
   8433         awb_params.rgb_gains.g_gain, awb_params.rgb_gains.b_gain);
   8434 
   8435     if (prev_gains == NULL || strcmp(prev_gains, gainStr)) {
   8436         set(KEY_QC_MANUAL_WB_GAINS, gainStr);
   8437         LOGD("update currernt RGB gains: old %s new %s", prev_gains, gainStr);
   8438     }
   8439     return NO_ERROR;
   8440 }
   8441 
   8442 /*===========================================================================
   8443  * FUNCTION   : parseGains
   8444  *
   8445  * DESCRIPTION: parse WB gains
   8446  *
   8447  * PARAMETERS :
   8448  *   @gainStr : WB result string
   8449  *   @r_gain  : WB red gain
   8450  *   @g_gain  : WB green gain
   8451  *   @b_gain  : WB blue gain
   8452  *
   8453  * RETURN     : int32_t type of status
   8454  *              NO_ERROR  -- success
   8455  *              none-zero failure code
   8456  *==========================================================================*/
   8457 int32_t QCameraParameters::parseGains(const char *gainStr, double &r_gain,
   8458                                           double &g_gain, double &b_gain)
   8459 {
   8460     int32_t rc = NO_ERROR;
   8461     char *saveptr = NULL;
   8462     size_t gains_size = strlen(gainStr) + 1;
   8463     char* gains = (char*) calloc(1, gains_size);
   8464     if (NULL == gains) {
   8465         LOGE("No memory for gains");
   8466         return NO_MEMORY;
   8467     }
   8468     strlcpy(gains, gainStr, gains_size);
   8469     char *token = strtok_r(gains, ",", &saveptr);
   8470 
   8471     if (NULL != token) {
   8472         r_gain = (float) atof(token);
   8473         token = strtok_r(NULL, ",", &saveptr);
   8474     }
   8475 
   8476     if (NULL != token) {
   8477         g_gain = (float) atof(token);
   8478         token = strtok_r(NULL, ",", &saveptr);
   8479     }
   8480 
   8481     if (NULL != token) {
   8482         b_gain = (float) atof(token);
   8483     } else {
   8484         LOGE("Malformed string for gains");
   8485         rc = BAD_VALUE;
   8486     }
   8487 
   8488     free(gains);
   8489     return rc;
   8490 }
   8491 
   8492 /*===========================================================================
   8493  * FUNCTION   : setManualWBGains
   8494  *
   8495  * DESCRIPTION: set manual wb gains for r,g,b
   8496  *
   8497  * PARAMETERS :
   8498  *   @cctStr : string of wb gains, range (1.0, 4.0).
   8499  *
   8500  * RETURN     : int32_t type of status
   8501  *              NO_ERROR  -- success
   8502  *              none-zero failure code
   8503  *==========================================================================*/
   8504 int32_t QCameraParameters::setManualWBGains(const char *gainStr)
   8505 {
   8506     int32_t rc = NO_ERROR;
   8507     if (gainStr != NULL) {
   8508         double r_gain,g_gain,b_gain;
   8509         rc = parseGains(gainStr, r_gain, g_gain, b_gain);
   8510         if (rc != NO_ERROR) {
   8511             return rc;
   8512         }
   8513 
   8514         double minGain = m_pCapability->min_wb_gain;
   8515         double maxGain = m_pCapability->max_wb_gain;
   8516 
   8517         if (r_gain >= minGain && r_gain <= maxGain &&
   8518             g_gain >= minGain && g_gain <= maxGain &&
   8519             b_gain >= minGain && b_gain <= maxGain) {
   8520             LOGH(", setting rgb gains: r = %lf g = %lf b = %lf",
   8521                      r_gain, g_gain, b_gain);
   8522             updateParamEntry(KEY_QC_MANUAL_WB_GAINS, gainStr);
   8523             cam_manual_wb_parm_t manual_wb;
   8524             manual_wb.type = CAM_MANUAL_WB_MODE_GAIN;
   8525             manual_wb.gains.r_gain = r_gain;
   8526             manual_wb.gains.g_gain = g_gain;
   8527             manual_wb.gains.b_gain = b_gain;
   8528             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WB_MANUAL, manual_wb)) {
   8529                 return BAD_VALUE;
   8530             }
   8531             return NO_ERROR;
   8532         }
   8533     }
   8534 
   8535     LOGH("Invalid manual wb gains: %s",
   8536           (gainStr == NULL) ? "NULL" : gainStr);
   8537     return BAD_VALUE;
   8538 }
   8539 
   8540 int QCameraParameters::getAutoFlickerMode()
   8541 {
   8542     /* Enable Advanced Auto Antibanding where we can set
   8543        any of the following option
   8544        ie. CAM_ANTIBANDING_MODE_AUTO
   8545            CAM_ANTIBANDING_MODE_AUTO_50HZ
   8546            CAM_ANTIBANDING_MODE_AUTO_60HZ
   8547       Currently setting it to default    */
   8548     char prop[PROPERTY_VALUE_MAX];
   8549     memset(prop, 0, sizeof(prop));
   8550     property_get("persist.camera.set.afd", prop, "3");
   8551     return atoi(prop);
   8552 }
   8553 
   8554 /*===========================================================================
   8555  * FUNCTION   : setAntibanding
   8556  *
   8557  * DESCRIPTION: set antibanding value
   8558  *
   8559  * PARAMETERS :
   8560  *   @antiBandingStr : antibanding value string
   8561  *
   8562  * RETURN     : int32_t type of status
   8563  *              NO_ERROR  -- success
   8564  *              none-zero failure code
   8565  *==========================================================================*/
   8566 int32_t QCameraParameters::setAntibanding(const char *antiBandingStr)
   8567 {
   8568     if (antiBandingStr != NULL) {
   8569         int32_t value = lookupAttr(ANTIBANDING_MODES_MAP, PARAM_MAP_SIZE(ANTIBANDING_MODES_MAP),
   8570                 antiBandingStr);
   8571         if (value != NAME_NOT_FOUND) {
   8572             LOGH("Setting AntiBanding value %s", antiBandingStr);
   8573             updateParamEntry(KEY_ANTIBANDING, antiBandingStr);
   8574             if(value == CAM_ANTIBANDING_MODE_AUTO) {
   8575                value = getAutoFlickerMode();
   8576             }
   8577             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   8578                     CAM_INTF_PARM_ANTIBANDING, (uint32_t)value)) {
   8579                 return BAD_VALUE;
   8580             }
   8581             return NO_ERROR;
   8582         }
   8583     }
   8584     LOGE("Invalid AntiBanding value: %s",
   8585           (antiBandingStr == NULL) ? "NULL" : antiBandingStr);
   8586     return BAD_VALUE;
   8587 }
   8588 
   8589 /*===========================================================================
   8590  * FUNCTION   : setFocusAreas
   8591  *
   8592  * DESCRIPTION: set focus areas
   8593  *
   8594  * PARAMETERS :
   8595  *   @focusAreasStr : focus areas value string
   8596  *
   8597  * RETURN     : int32_t type of status
   8598  *              NO_ERROR  -- success
   8599  *              none-zero failure code
   8600  *==========================================================================*/
   8601 int32_t QCameraParameters::setFocusAreas(const char *focusAreasStr)
   8602 {
   8603     if (m_pCapability->max_num_focus_areas == 0 ||
   8604         focusAreasStr == NULL) {
   8605         LOGD("Parameter string is null");
   8606         return NO_ERROR;
   8607     }
   8608 
   8609     cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
   8610     if (NULL == areas) {
   8611         LOGE("No memory for areas");
   8612         return NO_MEMORY;
   8613     }
   8614     memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
   8615     int num_areas_found = 0;
   8616     if (parseCameraAreaString(focusAreasStr,
   8617                               m_pCapability->max_num_focus_areas,
   8618                               areas,
   8619                               num_areas_found) != NO_ERROR) {
   8620         LOGE("Failed to parse the string: %s", focusAreasStr);
   8621         free(areas);
   8622         return BAD_VALUE;
   8623     }
   8624 
   8625     if (validateCameraAreas(areas, num_areas_found) == false) {
   8626         LOGE("invalid areas specified : %s", focusAreasStr);
   8627         free(areas);
   8628         return BAD_VALUE;
   8629     }
   8630 
   8631     updateParamEntry(KEY_FOCUS_AREAS, focusAreasStr);
   8632 
   8633     //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
   8634     //so no action is takenby the lower layer
   8635     if (num_areas_found == 1 &&
   8636         areas[0].rect.left == 0 &&
   8637         areas[0].rect.top == 0 &&
   8638         areas[0].rect.width == 0 &&
   8639         areas[0].rect.height == 0 &&
   8640         areas[0].weight == 0) {
   8641         num_areas_found = 0;
   8642     }
   8643 
   8644     int previewWidth, previewHeight;
   8645     getPreviewSize(&previewWidth, &previewHeight);
   8646     cam_roi_info_t af_roi_value;
   8647     memset(&af_roi_value, 0, sizeof(cam_roi_info_t));
   8648     af_roi_value.num_roi = (uint8_t)num_areas_found;
   8649     for (int i = 0; i < num_areas_found; i++) {
   8650         LOGH("FocusArea[%d] = (%d, %d, %d, %d)",
   8651                i, (areas[i].rect.top), (areas[i].rect.left),
   8652               (areas[i].rect.width), (areas[i].rect.height));
   8653 
   8654         // Transform the coords from (-1000, 1000)
   8655         // to (0, previewWidth or previewHeight).
   8656         af_roi_value.roi[i].left =
   8657                 (int32_t)(((double)areas[i].rect.left + 1000.0) *
   8658                     ((double)previewWidth / 2000.0));
   8659         af_roi_value.roi[i].top =
   8660                 (int32_t)(((double)areas[i].rect.top + 1000.0) *
   8661                     ((double)previewHeight / 2000.0));
   8662         af_roi_value.roi[i].width =
   8663                 (int32_t)((double)areas[i].rect.width *
   8664                     (double)previewWidth / 2000.0);
   8665         af_roi_value.roi[i].height =
   8666                 (int32_t)((double)areas[i].rect.height *
   8667                     (double)previewHeight / 2000.0);
   8668         af_roi_value.weight[i] = areas[i].weight;
   8669     }
   8670     free(areas);
   8671     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AF_ROI, af_roi_value)) {
   8672         return BAD_VALUE;
   8673     }
   8674 
   8675     return NO_ERROR;
   8676 }
   8677 
   8678 /*===========================================================================
   8679  * FUNCTION   : setMeteringAreas
   8680  *
   8681  * DESCRIPTION: set metering areas value
   8682  *
   8683  * PARAMETERS :
   8684  *   @meteringAreasStr : metering areas value string
   8685  *
   8686  * RETURN     : int32_t type of status
   8687  *              NO_ERROR  -- success
   8688  *              none-zero failure code
   8689  *==========================================================================*/
   8690 int32_t QCameraParameters::setMeteringAreas(const char *meteringAreasStr)
   8691 {
   8692     if (m_pCapability->max_num_metering_areas == 0 ||
   8693         meteringAreasStr == NULL) {
   8694         LOGD("Parameter string is null");
   8695         return NO_ERROR;
   8696     }
   8697 
   8698     cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
   8699     if (NULL == areas) {
   8700         LOGE("No memory for areas");
   8701         return NO_MEMORY;
   8702     }
   8703     memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
   8704     int num_areas_found = 0;
   8705     if (parseCameraAreaString(meteringAreasStr,
   8706                               m_pCapability->max_num_metering_areas,
   8707                               areas,
   8708                               num_areas_found) < 0) {
   8709         LOGE("Failed to parse the string: %s", meteringAreasStr);
   8710         free(areas);
   8711         return BAD_VALUE;
   8712     }
   8713 
   8714     if (validateCameraAreas(areas, num_areas_found) == false) {
   8715         LOGE("invalid areas specified : %s", meteringAreasStr);
   8716         free(areas);
   8717         return BAD_VALUE;
   8718     }
   8719 
   8720     updateParamEntry(KEY_METERING_AREAS, meteringAreasStr);
   8721 
   8722     //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
   8723     //so no action is takenby the lower layer
   8724     if (num_areas_found == 1 &&
   8725         areas[0].rect.left == 0 &&
   8726         areas[0].rect.top == 0 &&
   8727         areas[0].rect.width == 0 &&
   8728         areas[0].rect.height == 0 &&
   8729         areas[0].weight == 0) {
   8730         num_areas_found = 0;
   8731     }
   8732     cam_set_aec_roi_t aec_roi_value;
   8733     int previewWidth, previewHeight;
   8734     getPreviewSize(&previewWidth, &previewHeight);
   8735 
   8736     memset(&aec_roi_value, 0, sizeof(cam_set_aec_roi_t));
   8737     if (num_areas_found > 0) {
   8738         aec_roi_value.aec_roi_enable = CAM_AEC_ROI_ON;
   8739         aec_roi_value.aec_roi_type = CAM_AEC_ROI_BY_COORDINATE;
   8740 
   8741         for (int i = 0; i < num_areas_found; i++) {
   8742             LOGH("MeteringArea[%d] = (%d, %d, %d, %d)",
   8743                    i, (areas[i].rect.top), (areas[i].rect.left),
   8744                   (areas[i].rect.width), (areas[i].rect.height));
   8745 
   8746             // Transform the coords from (-1000, 1000) to
   8747             // (0, previewWidth or previewHeight).
   8748             aec_roi_value.cam_aec_roi_position.coordinate[i].x =
   8749                     (uint32_t)((((double)areas[i].rect.left +
   8750                         (double)areas[i].rect.width / 2.0) + 1000.0) *
   8751                             (double)previewWidth / 2000.0);
   8752             aec_roi_value.cam_aec_roi_position.coordinate[i].y =
   8753                     (uint32_t)((((double)areas[i].rect.top +
   8754                         (double)areas[i].rect.height / 2.0) + 1000.0) *
   8755                             (double)previewHeight / 2000.0);
   8756         }
   8757     } else {
   8758         aec_roi_value.aec_roi_enable = CAM_AEC_ROI_OFF;
   8759     }
   8760     free(areas);
   8761     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_ROI, aec_roi_value)) {
   8762         return BAD_VALUE;
   8763     }
   8764 
   8765     return NO_ERROR;
   8766 }
   8767 
   8768 
   8769 /*===========================================================================
   8770  * FUNCTION   : isSupportedSensorHdrSize
   8771  *
   8772  * DESCRIPTION: Checks if the requested snapshot size is compatible with currently
   8773  *              configured HDR mode, currently primary target for validation is
   8774  *              zzhdr however this function can be extended in the future to vet
   8775  *              all sensor based HDR configs
   8776  *
   8777  * PARAMETERS :
   8778  *   @params  : CameraParameters object
   8779  *
   8780  * RETURN     : boolean type
   8781  *              True  -- indicates supported config
   8782  *              False -- indicated unsupported config should fallback to other
   8783  *              available HDR modes
   8784  *==========================================================================*/
   8785 bool QCameraParameters::isSupportedSensorHdrSize(const QCameraParameters& params)
   8786 {
   8787     char value[PROPERTY_VALUE_MAX];
   8788     memset(value, 0, sizeof(value));
   8789     property_get("persist.camera.zzhdr.enable", value, "0");
   8790     uint8_t zzhdr_enable = (uint8_t)atoi(value);
   8791 
   8792     if (zzhdr_enable) {
   8793 
   8794         int req_w, req_h;
   8795         params.getPictureSize(&req_w, &req_h);
   8796 
   8797         // Check if requested w x h is in zzhdr supported list
   8798         for (size_t i = 0; i< m_pCapability->zzhdr_sizes_tbl_cnt; ++i) {
   8799 
   8800             if (req_w == m_pCapability->zzhdr_sizes_tbl[i].width &&
   8801                     req_h == m_pCapability->zzhdr_sizes_tbl[i].height) {
   8802                 LOGD("%s: Found match for %d x %d", __func__, req_w, req_h);
   8803                 return true;
   8804             }
   8805         }
   8806         LOGH("%s: %d x %d is not supported for zzhdr mode", __func__, req_w, req_h);
   8807         return false;
   8808     }
   8809 
   8810     return true;
   8811 }
   8812 
   8813 /*===========================================================================
   8814  * FUNCTION   : setSceneMode
   8815  *
   8816  * DESCRIPTION: set scene mode
   8817  *
   8818  * PARAMETERS :
   8819  *   @sceneModeStr : scene mode value string
   8820  *
   8821  * RETURN     : int32_t type of status
   8822  *              NO_ERROR  -- success
   8823  *              none-zero failure code
   8824  *==========================================================================*/
   8825 int32_t QCameraParameters::setSceneMode(const char *sceneModeStr)
   8826 {
   8827     if (sceneModeStr != NULL) {
   8828         int32_t value = lookupAttr(SCENE_MODES_MAP, PARAM_MAP_SIZE(SCENE_MODES_MAP), sceneModeStr);
   8829         if (value != NAME_NOT_FOUND) {
   8830             LOGD("Setting SceneMode %s", sceneModeStr);
   8831             updateParamEntry(KEY_SCENE_MODE, sceneModeStr);
   8832             if (m_bSensorHDREnabled) {
   8833               // Incase of HW HDR mode, we do not update the same as Best shot mode.
   8834               LOGH("H/W HDR mode enabled. Do not set Best Shot Mode");
   8835               return NO_ERROR;
   8836             }
   8837             if (m_bSceneSelection) {
   8838                 setSelectedScene((cam_scene_mode_type) value);
   8839             }
   8840             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BESTSHOT_MODE,
   8841                     (uint32_t)value)) {
   8842                 return BAD_VALUE;
   8843             }
   8844             return NO_ERROR;
   8845         }
   8846     }
   8847     LOGE("Invalid Secene Mode: %s",
   8848            (sceneModeStr == NULL) ? "NULL" : sceneModeStr);
   8849     return BAD_VALUE;
   8850 }
   8851 
   8852 /*===========================================================================
   8853  * FUNCTION   : setSelectableZoneAf
   8854  *
   8855  * DESCRIPTION: set selectable zone AF algorithm
   8856  *
   8857  * PARAMETERS :
   8858  *   @selZoneAFStr : selectable zone AF algorithm value string
   8859  *
   8860  * RETURN     : int32_t type of status
   8861  *              NO_ERROR  -- success
   8862  *              none-zero failure code
   8863  *==========================================================================*/
   8864 int32_t QCameraParameters::setSelectableZoneAf(const char *selZoneAFStr)
   8865 {
   8866     if (selZoneAFStr != NULL) {
   8867         int32_t value = lookupAttr(FOCUS_ALGO_MAP, PARAM_MAP_SIZE(FOCUS_ALGO_MAP), selZoneAFStr);
   8868         if (value != NAME_NOT_FOUND) {
   8869             LOGD("Setting Selectable Zone AF value %s", selZoneAFStr);
   8870             updateParamEntry(KEY_QC_SELECTABLE_ZONE_AF, selZoneAFStr);
   8871             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_ALGO_TYPE, value)) {
   8872                 return BAD_VALUE;
   8873             }
   8874             return NO_ERROR;
   8875         }
   8876     }
   8877     LOGE("Invalid selectable zone af value: %s",
   8878            (selZoneAFStr == NULL) ? "NULL" : selZoneAFStr);
   8879     return BAD_VALUE;
   8880 }
   8881 
   8882 /*===========================================================================
   8883  * FUNCTION   : isAEBracketEnabled
   8884  *
   8885  * DESCRIPTION: checks if AE bracketing is enabled
   8886  *
   8887  * PARAMETERS :
   8888  *
   8889  * RETURN     : TRUE/FALSE
   8890  *==========================================================================*/
   8891 bool QCameraParameters::isAEBracketEnabled()
   8892 {
   8893     const char *str = get(KEY_QC_AE_BRACKET_HDR);
   8894     if (str != NULL) {
   8895         if (strcmp(str, AE_BRACKET_OFF) != 0) {
   8896             return true;
   8897         }
   8898     }
   8899     return false;
   8900 }
   8901 
   8902 /*===========================================================================
   8903  * FUNCTION   : setAEBracket
   8904  *
   8905  * DESCRIPTION: set AE bracket value
   8906  *
   8907  * PARAMETERS :
   8908  *   @aecBracketStr : AE bracket value string
   8909  *
   8910  * RETURN     : int32_t type of status
   8911  *              NO_ERROR  -- success
   8912  *              none-zero failure code
   8913  *==========================================================================*/
   8914 int32_t QCameraParameters::setAEBracket(const char *aecBracketStr)
   8915 {
   8916     if (aecBracketStr == NULL) {
   8917         LOGD("setAEBracket with NULL value");
   8918         return NO_ERROR;
   8919     }
   8920 
   8921     cam_exp_bracketing_t expBracket;
   8922     memset(&expBracket, 0, sizeof(expBracket));
   8923 
   8924     int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
   8925             aecBracketStr);
   8926     switch (value) {
   8927     case CAM_EXP_BRACKETING_ON:
   8928         {
   8929             LOGD("EXP_BRACKETING_ON");
   8930             const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
   8931             if ((str_val != NULL) && (strlen(str_val)>0)) {
   8932                 expBracket.mode = CAM_EXP_BRACKETING_ON;
   8933                 m_bAeBracketingEnabled = true;
   8934                 strlcpy(expBracket.values, str_val, MAX_EXP_BRACKETING_LENGTH);
   8935                 LOGD("setting Exposure Bracketing value of %s",
   8936                        expBracket.values);
   8937             }
   8938             else {
   8939                 /* Apps not set capture-burst-exposures, error case fall into bracketing off mode */
   8940                 LOGD("capture-burst-exposures not set, back to HDR OFF mode");
   8941                 m_bAeBracketingEnabled = false;
   8942                 expBracket.mode = CAM_EXP_BRACKETING_OFF;
   8943             }
   8944         }
   8945         break;
   8946     default:
   8947         {
   8948             m_bAeBracketingEnabled = false;
   8949             LOGH(", EXP_BRACKETING_OFF");
   8950             expBracket.mode = CAM_EXP_BRACKETING_OFF;
   8951         }
   8952         break;
   8953     }
   8954 
   8955     // Cache client AE bracketing configuration
   8956     memcpy(&m_AEBracketingClient, &expBracket, sizeof(cam_exp_bracketing_t));
   8957 
   8958     /* save the value*/
   8959     updateParamEntry(KEY_QC_AE_BRACKET_HDR, aecBracketStr);
   8960     return NO_ERROR;
   8961 }
   8962 
   8963 /*===========================================================================
   8964  * FUNCTION   : set3ALock
   8965  *
   8966  * DESCRIPTION: enable/disable 3A lock.
   8967  *
   8968  * PARAMETERS :
   8969  *   @lock3A  : lock or unlock
   8970  *
   8971  * RETURN     : int32_t type of status
   8972  *              NO_ERROR  -- success
   8973  *              none-zero failure code
   8974  *==========================================================================*/
   8975 int32_t QCameraParameters::set3ALock(bool lock3A)
   8976 {
   8977     int32_t rc = NO_ERROR;
   8978     LOGH("Setting Lock %d", lock3A);
   8979     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   8980         LOGE("Failed to initialize group update table");
   8981         return BAD_TYPE;
   8982     }
   8983     uint32_t focus_mode = CAM_FOCUS_MODE_AUTO;
   8984     if (lock3A) {
   8985         if (isUbiFocusEnabled() || isUbiRefocus()) {
   8986             //For Ubi focus move focus to infinity.
   8987             focus_mode = CAM_FOCUS_MODE_INFINITY;
   8988         } else if (isOptiZoomEnabled() || isStillMoreEnabled()) {
   8989             //For optizoom and stillmore, set focus as fixed.
   8990             focus_mode = CAM_FOCUS_MODE_FIXED;
   8991         }
   8992     } else {
   8993         // retrieve previous focus value.
   8994         const char *focus = get(KEY_FOCUS_MODE);
   8995         int val = lookupAttr(FOCUS_MODES_MAP, PARAM_MAP_SIZE(FOCUS_MODES_MAP), focus);
   8996         if (val != NAME_NOT_FOUND) {
   8997             focus_mode = (uint32_t) val;
   8998             LOGD("focus mode %s", focus);
   8999         }
   9000     }
   9001     //Lock AWB
   9002     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AWB_LOCK, (uint32_t)lock3A)) {
   9003         return BAD_VALUE;
   9004     }
   9005     //Lock AEC
   9006     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_LOCK, (uint32_t)lock3A)) {
   9007         return BAD_VALUE;
   9008     }
   9009     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_MODE, focus_mode)) {
   9010         return BAD_VALUE;
   9011     }
   9012 
   9013     rc = commitSetBatch();
   9014     if (rc != NO_ERROR) {
   9015         LOGE("Failed to commit batch");
   9016     }
   9017     return rc;
   9018 }
   9019 
   9020 /*===========================================================================
   9021  * FUNCTION   : setAndCommitZoom
   9022  *
   9023  * DESCRIPTION: set zoom.
   9024  *
   9025  * PARAMETERS :
   9026  *     @zoom_level : zoom level to set.
   9027  *
   9028  * RETURN     : int32_t type of status
   9029  *              NO_ERROR  -- success
   9030  *              none-zero failure code
   9031  *==========================================================================*/
   9032 int32_t QCameraParameters::setAndCommitZoom(int zoom_level)
   9033 {
   9034     LOGH("E");
   9035     int32_t rc = NO_ERROR;
   9036     if (initBatchUpdate(m_pParamBuf) < 0 ) {
   9037         LOGE("Failed to initialize group update table");
   9038         return BAD_TYPE;
   9039     }
   9040 
   9041     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZOOM, zoom_level)) {
   9042         LOGE("Failed to update table");
   9043         return BAD_VALUE;
   9044     }
   9045 
   9046     rc = commitSetBatch();
   9047     if (rc != NO_ERROR) {
   9048         LOGE("Failed to set Flash value");
   9049     }
   9050 
   9051     mZoomLevel = zoom_level;
   9052     LOGH("X");
   9053 
   9054     return rc;
   9055 }
   9056 
   9057 /*===========================================================================
   9058  * FUNCTION   : isOptiZoomEnabled
   9059  *
   9060  * DESCRIPTION: checks whether optizoom is enabled
   9061  *
   9062  * PARAMETERS :
   9063  *
   9064  * RETURN     : true - enabled, false - disabled
   9065  *
   9066  *==========================================================================*/
   9067 bool QCameraParameters::isOptiZoomEnabled()
   9068 {
   9069     if (m_bOptiZoomOn && (0 <= mParmZoomLevel)) {
   9070         uint32_t zoom_level = (uint32_t) mParmZoomLevel;
   9071         cam_opti_zoom_t *opti_zoom_settings_need =
   9072                 &(m_pCapability->opti_zoom_settings_need);
   9073         uint32_t zoom_threshold = (uint32_t) opti_zoom_settings_need->zoom_threshold;
   9074         LOGH("current zoom level =%u & zoom_threshold =%u",
   9075                  zoom_level, zoom_threshold);
   9076 
   9077         if (zoom_level >= zoom_threshold) {
   9078             return true;
   9079         }
   9080     }
   9081 
   9082     return false;
   9083 }
   9084 
   9085 /*===========================================================================
   9086  * FUNCTION   : setNoiseReductionMode
   9087  *
   9088  * DESCRIPTION: set noise reduction mode
   9089  *
   9090  * PARAMETERS :
   9091  *   @noiseReductionModeStr : noise reduction mode
   9092  *
   9093  * RETURN     : int32_t type of status
   9094  *              NO_ERROR  -- success
   9095  *              none-zero failure code
   9096  *==========================================================================*/
   9097 int32_t QCameraParameters::setNoiseReductionMode(const char *noiseReductionModeStr)
   9098 {
   9099     LOGH("noiseReductionModeStr = %s", noiseReductionModeStr);
   9100     if (noiseReductionModeStr != NULL) {
   9101         int value = lookupAttr(NOISE_REDUCTION_MODES_MAP, PARAM_MAP_SIZE(NOISE_REDUCTION_MODES_MAP),
   9102                 noiseReductionModeStr);
   9103         if (value != NAME_NOT_FOUND) {
   9104             m_bHighQualityNoiseReductionMode =
   9105                     !strncmp(VALUE_HIGH_QUALITY, noiseReductionModeStr, strlen(VALUE_HIGH_QUALITY));
   9106             updateParamEntry(KEY_QC_NOISE_REDUCTION_MODE, noiseReductionModeStr);
   9107             return NO_ERROR;
   9108         }
   9109     }
   9110     LOGE("Invalid noise reduction mode value: %s",
   9111             (noiseReductionModeStr == NULL) ? "NULL" : noiseReductionModeStr);
   9112     return BAD_VALUE;
   9113 }
   9114 
   9115 /*===========================================================================
   9116  * FUNCTION   : commitAFBracket
   9117  *
   9118  * DESCRIPTION: commit AF Bracket.
   9119  *
   9120  * PARAMETERS :
   9121  *   @AFBracket : AF bracketing configuration
   9122  *
   9123  * RETURN     : int32_t type of status
   9124  *              NO_ERROR  -- success
   9125  *              none-zero failure code
   9126  *==========================================================================*/
   9127 int32_t QCameraParameters::commitAFBracket(cam_af_bracketing_t afBracket)
   9128 {
   9129 
   9130     int32_t rc = NO_ERROR;
   9131     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   9132         LOGE("Failed to initialize group update table");
   9133         return BAD_TYPE;
   9134     }
   9135 
   9136     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_BRACKETING, afBracket)) {
   9137         LOGE("Failed to update table");
   9138         return BAD_VALUE;
   9139     }
   9140 
   9141     rc = commitSetBatch();
   9142     if (rc != NO_ERROR) {
   9143         LOGE("Failed to commit batch");
   9144         return rc;
   9145     }
   9146 
   9147     return rc;
   9148 }
   9149 
   9150 /*===========================================================================
   9151  * FUNCTION   : setAFBracket
   9152  *
   9153  * DESCRIPTION: set AF bracket value
   9154  *
   9155  * PARAMETERS :
   9156  *   @afBracketStr : AF bracket value string
   9157  *
   9158  * RETURN     : int32_t type of status
   9159  *              NO_ERROR  -- success
   9160  *              none-zero failure code
   9161  *==========================================================================*/
   9162 int32_t QCameraParameters::setAFBracket(const char *afBracketStr)
   9163 {
   9164     LOGH("afBracketStr =%s",afBracketStr);
   9165 
   9166     if(afBracketStr != NULL) {
   9167         int value = lookupAttr(AF_BRACKETING_MODES_MAP, PARAM_MAP_SIZE(AF_BRACKETING_MODES_MAP),
   9168                 afBracketStr);
   9169         if (value != NAME_NOT_FOUND) {
   9170             m_bAFBracketingOn = (value != 0);
   9171             updateParamEntry(KEY_QC_AF_BRACKET, afBracketStr);
   9172 
   9173             return NO_ERROR;
   9174         }
   9175     }
   9176 
   9177     LOGE("Invalid af bracket value: %s",
   9178         (afBracketStr == NULL) ? "NULL" : afBracketStr);
   9179     return BAD_VALUE;
   9180 }
   9181 
   9182 /*===========================================================================
   9183  * FUNCTION   : setReFocus
   9184  *
   9185  * DESCRIPTION: set refocus value
   9186  *
   9187  * PARAMETERS :
   9188  *   @afBracketStr : refocus value string
   9189  *
   9190  * RETURN     : int32_t type of status
   9191  *              NO_ERROR  -- success
   9192  *              none-zero failure code
   9193  *==========================================================================*/
   9194 int32_t QCameraParameters::setReFocus(const char *reFocusStr)
   9195 {
   9196     LOGH("reFocusStr =%s",reFocusStr);
   9197 
   9198     if (reFocusStr != NULL) {
   9199         int value = lookupAttr(RE_FOCUS_MODES_MAP, PARAM_MAP_SIZE(RE_FOCUS_MODES_MAP),
   9200                 reFocusStr);
   9201         if (value != NAME_NOT_FOUND) {
   9202             m_bReFocusOn = (value != 0);
   9203             updateParamEntry(KEY_QC_RE_FOCUS, reFocusStr);
   9204             return NO_ERROR;
   9205         }
   9206     }
   9207 
   9208     return NO_ERROR;
   9209 }
   9210 
   9211 /*===========================================================================
   9212  * FUNCTION   : setChromaFlash
   9213  *
   9214  * DESCRIPTION: set chroma flash value
   9215  *
   9216  * PARAMETERS :
   9217  *   @aecBracketStr : chroma flash value string
   9218  *
   9219  * RETURN     : int32_t type of status
   9220  *              NO_ERROR  -- success
   9221  *              none-zero failure code
   9222  *==========================================================================*/
   9223 int32_t QCameraParameters::setChromaFlash(const char *chromaFlashStr)
   9224 {
   9225     LOGH("chromaFlashStr =%s",chromaFlashStr);
   9226     if(chromaFlashStr != NULL) {
   9227         int value = lookupAttr(CHROMA_FLASH_MODES_MAP, PARAM_MAP_SIZE(CHROMA_FLASH_MODES_MAP),
   9228                 chromaFlashStr);
   9229         if(value != NAME_NOT_FOUND) {
   9230             m_bChromaFlashOn = (value != 0);
   9231             updateParamEntry(KEY_QC_CHROMA_FLASH, chromaFlashStr);
   9232 
   9233             return NO_ERROR;
   9234         }
   9235     }
   9236 
   9237     LOGE("Invalid chroma flash value: %s",
   9238         (chromaFlashStr == NULL) ? "NULL" : chromaFlashStr);
   9239     return BAD_VALUE;
   9240 }
   9241 
   9242 /*===========================================================================
   9243  * FUNCTION   : setOptiZoom
   9244  *
   9245  * DESCRIPTION: set opti zoom value
   9246  *
   9247  * PARAMETERS :
   9248  *   @optiZoomStr : opti zoom value string
   9249  *
   9250  * RETURN     : int32_t type of status
   9251  *              NO_ERROR  -- success
   9252  *              none-zero failure code
   9253  *==========================================================================*/
   9254 int32_t QCameraParameters::setOptiZoom(const char *optiZoomStr)
   9255 {
   9256     LOGH("optiZoomStr =%s",optiZoomStr);
   9257     if(optiZoomStr != NULL) {
   9258         int value = lookupAttr(OPTI_ZOOM_MODES_MAP, PARAM_MAP_SIZE(OPTI_ZOOM_MODES_MAP),
   9259                 optiZoomStr);
   9260         if(value != NAME_NOT_FOUND) {
   9261             m_bOptiZoomOn = (value != 0);
   9262             updateParamEntry(KEY_QC_OPTI_ZOOM, optiZoomStr);
   9263 
   9264             return NO_ERROR;
   9265         }
   9266     }
   9267     LOGE("Invalid opti zoom value: %s",
   9268         (optiZoomStr == NULL) ? "NULL" : optiZoomStr);
   9269     return BAD_VALUE;
   9270 }
   9271 
   9272 /*===========================================================================
   9273  * FUNCTION   : setTruePortrait
   9274  *
   9275  * DESCRIPTION: set true portrait value
   9276  *
   9277  * PARAMETERS :
   9278  *   @optiZoomStr : true portrait value string
   9279  *
   9280  * RETURN     : int32_t type of status
   9281  *              NO_ERROR  -- success
   9282  *              none-zero failure code
   9283  *==========================================================================*/
   9284 int32_t QCameraParameters::setTruePortrait(const char *truePortraitStr)
   9285 {
   9286     LOGH("truePortraitStr =%s", truePortraitStr);
   9287     if (truePortraitStr != NULL) {
   9288         int value = lookupAttr(TRUE_PORTRAIT_MODES_MAP,
   9289                 PARAM_MAP_SIZE(TRUE_PORTRAIT_MODES_MAP),
   9290                 truePortraitStr);
   9291         if (value != NAME_NOT_FOUND) {
   9292             m_bTruePortraitOn = (value != 0);
   9293             updateParamEntry(KEY_QC_TRUE_PORTRAIT, truePortraitStr);
   9294             setFaceDetection(m_bFaceDetectionOn, false);
   9295             return NO_ERROR;
   9296         }
   9297     }
   9298     LOGH("Invalid true portrait value: %s",
   9299             (truePortraitStr == NULL) ? "NULL" : truePortraitStr);
   9300     return BAD_VALUE;
   9301 }
   9302 
   9303 /*===========================================================================
   9304  * FUNCTION   : setHDRMode
   9305  *
   9306  * DESCRIPTION: set hdr mode value
   9307  *
   9308  * PARAMETERS :
   9309  *   @hdrModeStr : hdr mode value string
   9310  *
   9311  * RETURN     : int32_t type of status
   9312  *              NO_ERROR  -- success
   9313  *              none-zero failure code
   9314  *==========================================================================*/
   9315 int32_t QCameraParameters::setHDRMode(const char *hdrModeStr)
   9316 {
   9317     LOGH("hdrModeStr =%s", hdrModeStr);
   9318     if (hdrModeStr != NULL) {
   9319         int value = lookupAttr(HDR_MODES_MAP, PARAM_MAP_SIZE(HDR_MODES_MAP), hdrModeStr);
   9320         if (value != NAME_NOT_FOUND) {
   9321             const char *str = get(KEY_SCENE_MODE);
   9322 
   9323             m_bHDRModeSensor = !strncmp(hdrModeStr, HDR_MODE_SENSOR, strlen(HDR_MODE_SENSOR));
   9324 
   9325             updateParamEntry(KEY_QC_HDR_MODE, hdrModeStr);
   9326 
   9327             // If hdr is already selected, need to deselect it in local cache
   9328             // So the new hdr mode will be applied
   9329             if (str && !strncmp(str, SCENE_MODE_HDR, strlen(SCENE_MODE_HDR))) {
   9330                 updateParamEntry(KEY_SCENE_MODE, SCENE_MODE_AUTO);
   9331                 m_bNeedRestart = true;
   9332             }
   9333 
   9334             return NO_ERROR;
   9335         }
   9336     }
   9337     LOGH("Invalid hdr mode value: %s",
   9338             (hdrModeStr == NULL) ? "NULL" : hdrModeStr);
   9339     return BAD_VALUE;
   9340 }
   9341 
   9342 /*===========================================================================
   9343  * FUNCTION   : setSeeMore
   9344  *
   9345  * DESCRIPTION: set see more value
   9346  *
   9347  * PARAMETERS :
   9348  *   @seeMoreStr : see more value string
   9349  *
   9350  * RETURN     : int32_t type of status
   9351  *              NO_ERROR  -- success
   9352  *              none-zero failure code
   9353  *==========================================================================*/
   9354 int32_t QCameraParameters::setSeeMore(const char *seeMoreStr)
   9355 {
   9356     int32_t rc = NO_ERROR;
   9357 
   9358     LOGH("seeMoreStr =%s", seeMoreStr);
   9359     if (seeMoreStr != NULL) {
   9360         int value = lookupAttr(ON_OFF_MODES_MAP,
   9361                 PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
   9362                 seeMoreStr);
   9363         if (value != NAME_NOT_FOUND) {
   9364             m_bSeeMoreOn = (value != 0);
   9365 
   9366             // If SeeMore is enabled, enable StillMore for live snapshot
   9367             // and disable tone map
   9368             if (m_bSeeMoreOn) {
   9369                 m_bStillMoreOn = TRUE;
   9370                 if (!m_bLtmForSeeMoreEnabled) {
   9371                     rc = setToneMapMode(false, false);
   9372                 }
   9373                 if (rc != NO_ERROR) {
   9374                     LOGH("Failed to disable tone map during SeeMore");
   9375                 }
   9376             } else {
   9377                 m_bStillMoreOn = FALSE;
   9378                 if (!m_bLtmForSeeMoreEnabled) {
   9379                     rc = setToneMapMode(true, false);
   9380                 }
   9381                 if (rc != NO_ERROR) {
   9382                     LOGH("Failed to enable tone map during SeeMore");
   9383                 }
   9384             }
   9385             updateParamEntry(KEY_QC_SEE_MORE, seeMoreStr);
   9386             return NO_ERROR;
   9387         }
   9388     }
   9389     LOGE("Invalid see more value: %s",
   9390             (seeMoreStr == NULL) ? "NULL" : seeMoreStr);
   9391     return BAD_VALUE;
   9392 }
   9393 
   9394 /*===========================================================================
   9395  * FUNCTION   : setStillMore
   9396  *
   9397  * DESCRIPTION: set still more value
   9398  *
   9399  * PARAMETERS :
   9400  *   @seeMoreStr : still more value string
   9401  *
   9402  * RETURN     : int32_t type of status
   9403  *              NO_ERROR  -- success
   9404  *              none-zero failure code
   9405  *==========================================================================*/
   9406 int32_t QCameraParameters::setStillMore(const char *stillMoreStr)
   9407 {
   9408     LOGH("stillMoreStr =%s", stillMoreStr);
   9409     if (stillMoreStr != NULL) {
   9410         int value = lookupAttr(STILL_MORE_MODES_MAP, PARAM_MAP_SIZE(STILL_MORE_MODES_MAP),
   9411                 stillMoreStr);
   9412         if (value != NAME_NOT_FOUND) {
   9413             m_bStillMoreOn = (value != 0);
   9414             updateParamEntry(KEY_QC_STILL_MORE, stillMoreStr);
   9415 
   9416             return NO_ERROR;
   9417         }
   9418     }
   9419     LOGE("Invalid still more value: %s",
   9420             (stillMoreStr == NULL) ? "NULL" : stillMoreStr);
   9421     return BAD_VALUE;
   9422 }
   9423 
   9424 /*===========================================================================
   9425  * FUNCTION   : setHDRNeed1x
   9426  *
   9427  * DESCRIPTION: set hdr need 1x value
   9428  *
   9429  * PARAMETERS :
   9430  *   @hdrModeStr : hdr need 1x value string
   9431  *
   9432  * RETURN     : int32_t type of status
   9433  *              NO_ERROR  -- success
   9434  *              none-zero failure code
   9435  *==========================================================================*/
   9436 int32_t QCameraParameters::setHDRNeed1x(const char *hdrNeed1xStr)
   9437 {
   9438     LOGH("hdrNeed1xStr =%s", hdrNeed1xStr);
   9439     if (hdrNeed1xStr != NULL) {
   9440         int value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
   9441                 hdrNeed1xStr);
   9442         if (value != NAME_NOT_FOUND) {
   9443             updateParamEntry(KEY_QC_HDR_NEED_1X, hdrNeed1xStr);
   9444             m_bHDR1xFrameEnabled = !strncmp(hdrNeed1xStr, VALUE_TRUE, strlen(VALUE_TRUE));
   9445             m_bNeedRestart = true;
   9446 
   9447             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR_NEED_1X,
   9448                     m_bHDR1xFrameEnabled)) {
   9449                 return BAD_VALUE;
   9450             }
   9451             return NO_ERROR;
   9452         }
   9453     }
   9454 
   9455     LOGH("Invalid hdr need 1x value: %s",
   9456             (hdrNeed1xStr == NULL) ? "NULL" : hdrNeed1xStr);
   9457     return BAD_VALUE;
   9458 }
   9459 
   9460 /*===========================================================================
   9461  * FUNCTION   : setAEBracketing
   9462  *
   9463  * DESCRIPTION: enables AE bracketing
   9464  *
   9465  * PARAMETERS :
   9466  *
   9467  * RETURN     : int32_t type of status
   9468  *              NO_ERROR  -- success
   9469  *              none-zero failure code
   9470  *==========================================================================*/
   9471 int32_t QCameraParameters::setAEBracketing()
   9472 {
   9473     int32_t rc = NO_ERROR;
   9474     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   9475         LOGE("Failed to initialize group update table");
   9476         return BAD_TYPE;
   9477     }
   9478 
   9479     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR, m_AEBracketingClient)) {
   9480         LOGE("Failed to update AE bracketing");
   9481         return BAD_VALUE;
   9482     }
   9483 
   9484     rc = commitSetBatch();
   9485     if (rc != NO_ERROR) {
   9486         LOGE("Failed to configure AE bracketing");
   9487         return rc;
   9488     }
   9489 
   9490     return rc;
   9491 }
   9492 
   9493 /*===========================================================================
   9494  * FUNCTION   : setHDRAEBracket
   9495  *
   9496  * DESCRIPTION: enables AE bracketing for HDR
   9497  *
   9498  * PARAMETERS :
   9499  *   @hdrBracket : HDR bracketing configuration
   9500  *
   9501  * RETURN     : int32_t type of status
   9502  *              NO_ERROR  -- success
   9503  *              none-zero failure code
   9504  *==========================================================================*/
   9505 int32_t QCameraParameters::setHDRAEBracket(cam_exp_bracketing_t hdrBracket)
   9506 {
   9507     int32_t rc = NO_ERROR;
   9508     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   9509         LOGE("Failed to initialize group update table");
   9510         return BAD_TYPE;
   9511     }
   9512 
   9513     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR, hdrBracket)) {
   9514         LOGE("Failed to update table");
   9515         return BAD_TYPE;
   9516     }
   9517 
   9518     rc = commitSetBatch();
   9519     if (rc != NO_ERROR) {
   9520         LOGE("Failed to configure HDR bracketing");
   9521         return rc;
   9522     }
   9523 
   9524     return rc;
   9525 }
   9526 
   9527 /*===========================================================================
   9528  * FUNCTION   : setCacheVideoBuffers
   9529  *
   9530  * DESCRIPTION: set cache video buffers value
   9531  *
   9532  * PARAMETERS :
   9533  *   @cacheVideoStr : cache video buffer value string
   9534  *
   9535  * RETURN     : int32_t type of status
   9536  *              NO_ERROR  -- success
   9537  *              none-zero failure code
   9538  *==========================================================================*/
   9539 int32_t QCameraParameters::setCacheVideoBuffers(const char *cacheVideoBufStr)
   9540 {
   9541     if (cacheVideoBufStr != NULL) {
   9542         int8_t cacheVideoBuf = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   9543                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), cacheVideoBufStr);
   9544         char prop[PROPERTY_VALUE_MAX];
   9545         memset(prop, 0, sizeof(prop));
   9546         property_get("persist.camera.mem.usecache", prop, "");
   9547         if (strlen(prop) > 0) {
   9548             cacheVideoBuf = atoi(prop);
   9549         }
   9550         if (cacheVideoBuf != NAME_NOT_FOUND) {
   9551             const char *cacheStr = (strlen(prop)>0) ? prop : cacheVideoBufStr;
   9552             LOGD("Setting video buffer %s",
   9553                     (cacheVideoBuf == 0) ? "UnCached" : "Cached");
   9554             return updateParamEntry(KEY_QC_CACHE_VIDEO_BUFFERS, cacheStr);
   9555         }
   9556         LOGE("Cache video buffers not set correctly");
   9557     }
   9558     return BAD_VALUE;
   9559 }
   9560 
   9561 
   9562 /*===========================================================================
   9563  * FUNCTION   : setCacheVideoBuffers
   9564  *
   9565  * DESCRIPTION: Set buffers as Cache/Uncache Memory
   9566  *
   9567  * PARAMETERS :
   9568  *   @params  : user setting parameters
   9569  *
   9570  * RETURN     : int32_t type of status
   9571  *              NO_ERROR  -- success
   9572  *              none-zero failure code
   9573  *==========================================================================*/
   9574 int32_t QCameraParameters::setCacheVideoBuffers(const QCameraParameters& params)
   9575 {
   9576     const char *str = params.get(KEY_QC_CACHE_VIDEO_BUFFERS);;
   9577     const char *prev_str = get(KEY_QC_CACHE_VIDEO_BUFFERS);
   9578 
   9579     if (str != NULL) {
   9580         if (prev_str == NULL ||
   9581                 strcmp(str, prev_str) != 0) {
   9582             return setCacheVideoBuffers(str);
   9583         }
   9584     }
   9585     return NO_ERROR;
   9586 }
   9587 
   9588 /*===========================================================================
   9589  * FUNCTION   : restoreAEBracket
   9590  *
   9591  * DESCRIPTION: restores client AE bracketing configuration after HDR is done
   9592  *
   9593  * PARAMETERS :
   9594  *
   9595  * RETURN     : int32_t type of status
   9596  *              NO_ERROR  -- success
   9597  *              none-zero failure code
   9598  *==========================================================================*/
   9599 int32_t QCameraParameters::stopAEBracket()
   9600 {
   9601   cam_exp_bracketing_t bracketing;
   9602 
   9603   bracketing.mode = CAM_EXP_BRACKETING_OFF;
   9604 
   9605   return setHDRAEBracket(bracketing);
   9606 }
   9607 
   9608 /*===========================================================================
   9609  * FUNCTION   : updateFlash
   9610  *
   9611  * DESCRIPTION: restores client flash configuration or disables flash
   9612  *
   9613  * PARAMETERS :
   9614  *   @commitSettings : flag indicating whether settings need to be commited
   9615  *
   9616  * RETURN     : int32_t type of status
   9617  *              NO_ERROR  -- success
   9618  *              none-zero failure code
   9619  *==========================================================================*/
   9620 int32_t QCameraParameters::updateFlash(bool commitSettings)
   9621 {
   9622     int32_t rc = NO_ERROR;
   9623     int32_t value;
   9624 
   9625     if (commitSettings) {
   9626       if(initBatchUpdate(m_pParamBuf) < 0 ) {
   9627           LOGE("Failed to initialize group update table");
   9628           return BAD_TYPE;
   9629       }
   9630     }
   9631 
   9632     if (isHDREnabled() || m_bAeBracketingEnabled || m_bAFBracketingOn ||
   9633           m_bOptiZoomOn || m_bReFocusOn || m_LowLightLevel) {
   9634         value = CAM_FLASH_MODE_OFF;
   9635     } else if (m_bChromaFlashOn) {
   9636         value = CAM_FLASH_MODE_ON;
   9637     } else {
   9638         value = mFlashValue;
   9639     }
   9640 
   9641     if (value != mFlashDaemonValue) {
   9642         LOGD("Setting Flash value %d", value);
   9643         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LED_MODE, value)) {
   9644             LOGE("Failed to set led mode");
   9645             return BAD_VALUE;
   9646         }
   9647         mFlashDaemonValue = value;
   9648     } else {
   9649         rc = NO_ERROR;
   9650     }
   9651 
   9652     if (commitSettings) {
   9653         rc = commitSetBatch();
   9654         if (rc != NO_ERROR) {
   9655             LOGE("Failed to configure HDR bracketing");
   9656             return rc;
   9657         }
   9658     }
   9659 
   9660     return rc;
   9661 }
   9662 
   9663 /*===========================================================================
   9664  * FUNCTION   : setRedeyeReduction
   9665  *
   9666  * DESCRIPTION: set red eye reduction value
   9667  *
   9668  * PARAMETERS :
   9669  *   @redeyeStr : red eye reduction value string
   9670  *
   9671  * RETURN     : int32_t type of status
   9672  *              NO_ERROR  -- success
   9673  *              none-zero failure code
   9674  *==========================================================================*/
   9675 int32_t QCameraParameters::setRedeyeReduction(const char *redeyeStr)
   9676 {
   9677     if (redeyeStr != NULL) {
   9678         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   9679                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), redeyeStr);
   9680         if (value != NAME_NOT_FOUND) {
   9681             LOGD("Setting RedEye Reduce value %s", redeyeStr);
   9682             updateParamEntry(KEY_QC_REDEYE_REDUCTION, redeyeStr);
   9683             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   9684                     CAM_INTF_PARM_REDEYE_REDUCTION, value)) {
   9685                 return BAD_VALUE;
   9686             }
   9687             return NO_ERROR;
   9688         }
   9689     }
   9690     LOGE("Invalid RedEye Reduce value: %s",
   9691            (redeyeStr == NULL) ? "NULL" : redeyeStr);
   9692     return BAD_VALUE;
   9693 }
   9694 
   9695 /*===========================================================================
   9696  * FUNCTION   : getDenoiseProcessPlate
   9697  *
   9698  * DESCRIPTION: query denoise process plate
   9699  *
   9700  * PARAMETERS : None
   9701  *
   9702  * RETURN     : NR process plate vlaue
   9703  *==========================================================================*/
   9704 cam_denoise_process_type_t
   9705         QCameraParameters::getDenoiseProcessPlate(cam_intf_parm_type_t type)
   9706 {
   9707     char prop[PROPERTY_VALUE_MAX];
   9708     memset(prop, 0, sizeof(prop));
   9709     cam_denoise_process_type_t processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
   9710     if (CAM_INTF_PARM_WAVELET_DENOISE == type) {
   9711         property_get("persist.denoise.process.plates", prop, "");
   9712     } else if (CAM_INTF_PARM_TEMPORAL_DENOISE == type) {
   9713         property_get("persist.tnr.process.plates", prop, "");
   9714     } else {
   9715         LOGW("Type not supported");
   9716         prop[0] = '\0';
   9717     }
   9718     if (strlen(prop) > 0) {
   9719         switch(atoi(prop)) {
   9720         case 0:
   9721             processPlate = CAM_WAVELET_DENOISE_YCBCR_PLANE;
   9722             break;
   9723         case 1:
   9724             processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
   9725             break;
   9726         case 2:
   9727             processPlate = CAM_WAVELET_DENOISE_STREAMLINE_YCBCR;
   9728             break;
   9729         case 3:
   9730             processPlate = CAM_WAVELET_DENOISE_STREAMLINED_CBCR;
   9731             break;
   9732         default:
   9733             processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
   9734             break;
   9735         }
   9736     }
   9737     return processPlate;
   9738 }
   9739 
   9740 /*===========================================================================
   9741  * FUNCTION   : setWaveletDenoise
   9742  *
   9743  * DESCRIPTION: set wavelet denoise value
   9744  *
   9745  * PARAMETERS :
   9746  *   @wnrStr : wavelet denoise value string
   9747  *
   9748  * RETURN     : int32_t type of status
   9749  *              NO_ERROR  -- success
   9750  *              none-zero failure code
   9751  *==========================================================================*/
   9752 int32_t QCameraParameters::setWaveletDenoise(const char *wnrStr)
   9753 {
   9754     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_DENOISE2D) == 0){
   9755         LOGH("WNR is not supported");
   9756         return NO_ERROR;
   9757     }
   9758 
   9759     if (wnrStr != NULL) {
   9760         int value = lookupAttr(DENOISE_ON_OFF_MODES_MAP,
   9761                 PARAM_MAP_SIZE(DENOISE_ON_OFF_MODES_MAP), wnrStr);
   9762         if (value != NAME_NOT_FOUND) {
   9763             updateParamEntry(KEY_QC_DENOISE, wnrStr);
   9764 
   9765             cam_denoise_param_t temp;
   9766             memset(&temp, 0, sizeof(temp));
   9767             temp.denoise_enable = (uint8_t)value;
   9768             m_bWNROn = (value != 0);
   9769             if (m_bWNROn) {
   9770                 temp.process_plates = getDenoiseProcessPlate(CAM_INTF_PARM_WAVELET_DENOISE);
   9771             }
   9772             LOGD("Denoise enable=%d, plates=%d",
   9773                    temp.denoise_enable, temp.process_plates);
   9774             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WAVELET_DENOISE, temp)) {
   9775                 return BAD_VALUE;
   9776             }
   9777             return NO_ERROR;
   9778         }
   9779     }
   9780     LOGE("Invalid Denoise value: %s", (wnrStr == NULL) ? "NULL" : wnrStr);
   9781     return BAD_VALUE;
   9782 }
   9783 
   9784 /*===========================================================================
   9785  * FUNCTION   : setRdiMode
   9786  *
   9787  * DESCRIPTION: set rdi mode value
   9788  *
   9789  * PARAMETERS :
   9790  *   @str     : rdi mode value string
   9791  *
   9792  * RETURN     : int32_t type of status
   9793  *              NO_ERROR  -- success
   9794  *              none-zero failure code
   9795  *==========================================================================*/
   9796 int32_t QCameraParameters::setRdiMode(const char *str)
   9797 {
   9798     LOGD("RDI_DEBUG  rdi mode value: %s", str);
   9799 
   9800     if (str != NULL) {
   9801         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   9802                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
   9803         if (value != NAME_NOT_FOUND) {
   9804             updateParamEntry(KEY_QC_RDI_MODE, str);
   9805             m_bRdiMode = (value == 0) ? false : true;
   9806             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RDI_MODE, value)) {
   9807                 return BAD_VALUE;
   9808             }
   9809             return NO_ERROR;
   9810         }
   9811     }
   9812     LOGE("Invalid rdi mode value: %s", (str == NULL) ? "NULL" : str);
   9813     return BAD_VALUE;
   9814 }
   9815 
   9816 
   9817 /*===========================================================================
   9818  * FUNCTION   : setSecureMode
   9819  *
   9820  * DESCRIPTION: set secure mode value
   9821  *
   9822  * PARAMETERS :
   9823  *   @str     : secure mode value string
   9824  *
   9825  * RETURN     : int32_t type of status
   9826  *              NO_ERROR  -- success
   9827  *              none-zero failure code
   9828  *==========================================================================*/
   9829 int32_t QCameraParameters::setSecureMode(const char *str)
   9830 {
   9831   LOGD("Secure mode value: %s", str);
   9832 
   9833   if (str != NULL) {
   9834     int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
   9835             PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
   9836     if (value != NAME_NOT_FOUND) {
   9837         updateParamEntry(KEY_QC_SECURE_MODE, str);
   9838         m_bSecureMode = (value == 0)? false : true;
   9839         return NO_ERROR;
   9840     }
   9841   }
   9842   LOGE("Invalid Secure mode value: %s",
   9843      (str == NULL) ? "NULL" : str);
   9844   return BAD_VALUE;
   9845 }
   9846 
   9847 /*===========================================================================
   9848  * FUNCTION   : getStreamRotation
   9849  *
   9850  * DESCRIPTION: get stream rotation by its type
   9851  *
   9852  * PARAMETERS :
   9853  *   @streamType        : stream type
   9854  *   @featureConfig     : stream feature config structure
   9855  *   @dim               : stream dimension
   9856  *
   9857  * RETURN     : int32_t type of status
   9858  *              NO_ERROR  -- success
   9859  *              none-zero failure code
   9860  *==========================================================================*/
   9861 int32_t QCameraParameters::getStreamRotation(cam_stream_type_t streamType,
   9862                                             cam_pp_feature_config_t &featureConfig,
   9863                                             cam_dimension_t &dim)
   9864 {
   9865     int32_t ret = NO_ERROR;
   9866     const char *str = get(KEY_QC_VIDEO_ROTATION);
   9867     int rotationParam = lookupAttr(VIDEO_ROTATION_MODES_MAP,
   9868             PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP), str);
   9869     featureConfig.rotation = ROTATE_0;
   9870     int swapDim = 0;
   9871     switch (streamType) {
   9872         case CAM_STREAM_TYPE_VIDEO:
   9873             switch(rotationParam) {
   9874                 case 90:
   9875                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
   9876                     featureConfig.rotation = ROTATE_90;
   9877                     swapDim = 1;
   9878                     break;
   9879                 case 180:
   9880                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
   9881                     featureConfig.rotation = ROTATE_180;
   9882                     break;
   9883                 case 270:
   9884                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
   9885                     featureConfig.rotation = ROTATE_270;
   9886                     swapDim = 1;
   9887                     break;
   9888                 default:
   9889                     featureConfig.rotation = ROTATE_0;
   9890             }
   9891             break;
   9892         case CAM_STREAM_TYPE_PREVIEW:
   9893         case CAM_STREAM_TYPE_POSTVIEW:
   9894         case CAM_STREAM_TYPE_SNAPSHOT:
   9895         case CAM_STREAM_TYPE_RAW:
   9896         case CAM_STREAM_TYPE_METADATA:
   9897         case CAM_STREAM_TYPE_OFFLINE_PROC:
   9898         case CAM_STREAM_TYPE_DEFAULT:
   9899         default:
   9900             break;
   9901     }
   9902 
   9903     if (swapDim > 0) {
   9904         int w = 0;
   9905         w = dim.width;
   9906         dim.width = dim.height;
   9907         dim.height = w;
   9908     }
   9909     return ret;
   9910 }
   9911 
   9912 /*===========================================================================
   9913  * FUNCTION   : getStreamFormat
   9914  *
   9915  * DESCRIPTION: get stream format by its type
   9916  *
   9917  * PARAMETERS :
   9918  *   @streamType : [input] stream type
   9919  *   @format     : [output] stream format
   9920  *
   9921  * RETURN     : int32_t type of status
   9922  *              NO_ERROR  -- success
   9923  *              none-zero failure code
   9924  *==========================================================================*/
   9925 int32_t QCameraParameters::getStreamFormat(cam_stream_type_t streamType,
   9926                                             cam_format_t &format)
   9927 {
   9928     int32_t ret = NO_ERROR;
   9929     format = CAM_FORMAT_MAX;
   9930     switch (streamType) {
   9931     case CAM_STREAM_TYPE_PREVIEW:
   9932         if (!isUBWCEnabled()) {
   9933 #if VENUS_PRESENT
   9934             cam_dimension_t preview;
   9935             cam_dimension_t video;
   9936             getStreamDimension(CAM_STREAM_TYPE_VIDEO , video);
   9937             getStreamDimension(CAM_STREAM_TYPE_PREVIEW, preview);
   9938             if (getRecordingHintValue() == true &&
   9939                     video.width == preview.width &&
   9940                     video.height == preview.height &&
   9941                     mPreviewFormat == CAM_FORMAT_YUV_420_NV21) {
   9942                 format = CAM_FORMAT_YUV_420_NV21_VENUS;
   9943             } else
   9944 #endif
   9945             format = mPreviewFormat;
   9946         } else {
   9947             format = mPreviewFormat;
   9948         }
   9949         break;
   9950     case CAM_STREAM_TYPE_POSTVIEW:
   9951     case CAM_STREAM_TYPE_CALLBACK:
   9952         format = mAppPreviewFormat;
   9953         break;
   9954     case CAM_STREAM_TYPE_ANALYSIS:
   9955         cam_analysis_info_t analysisInfo;
   9956         cam_feature_mask_t featureMask;
   9957 
   9958         featureMask = 0;
   9959         getStreamPpMask(CAM_STREAM_TYPE_ANALYSIS, featureMask);
   9960         ret = getAnalysisInfo(
   9961                 ((getRecordingHintValue() == true) && fdModeInVideo()),
   9962                 FALSE,
   9963                 featureMask,
   9964                 &analysisInfo);
   9965         if (ret != NO_ERROR) {
   9966             LOGE("getAnalysisInfo failed, ret = %d", ret);
   9967             return ret;
   9968         }
   9969 
   9970         if (analysisInfo.hw_analysis_supported &&
   9971                 analysisInfo.analysis_format == CAM_FORMAT_Y_ONLY) {
   9972             format = analysisInfo.analysis_format;
   9973         } else {
   9974             if (analysisInfo.hw_analysis_supported) {
   9975                 LOGW("Invalid analysis_format %d\n",
   9976                         analysisInfo.analysis_format);
   9977             }
   9978             format = mAppPreviewFormat;
   9979         }
   9980         break;
   9981     case CAM_STREAM_TYPE_SNAPSHOT:
   9982         if ( mPictureFormat == CAM_FORMAT_YUV_422_NV16 ) {
   9983             format = CAM_FORMAT_YUV_422_NV16;
   9984         } else {
   9985             char prop[PROPERTY_VALUE_MAX];
   9986             int snapshotFormat;
   9987             memset(prop, 0, sizeof(prop));
   9988             property_get("persist.camera.snap.format", prop, "0");
   9989             snapshotFormat = atoi(prop);
   9990             if(snapshotFormat == 1) {
   9991                 format = CAM_FORMAT_YUV_422_NV61;
   9992             } else {
   9993                 format = CAM_FORMAT_YUV_420_NV21;
   9994             }
   9995         }
   9996         break;
   9997     case CAM_STREAM_TYPE_VIDEO:
   9998         if (isUBWCEnabled()) {
   9999             char prop[PROPERTY_VALUE_MAX];
   10000             int pFormat;
   10001             memset(prop, 0, sizeof(prop));
   10002             property_get("persist.camera.video.ubwc", prop, "1");
   10003             pFormat = atoi(prop);
   10004             if (pFormat == 1) {
   10005                 format = CAM_FORMAT_YUV_420_NV12_UBWC;
   10006             } else {
   10007                 format = CAM_FORMAT_YUV_420_NV21_VENUS;
   10008             }
   10009         } else {
   10010 #if VENUS_PRESENT
   10011             format = CAM_FORMAT_YUV_420_NV21_VENUS;
   10012 #else
   10013             format = CAM_FORMAT_YUV_420_NV21;
   10014 #endif
   10015         }
   10016         break;
   10017     case CAM_STREAM_TYPE_RAW:
   10018         if ((isRdiMode()) || (getofflineRAW())) {
   10019             format = m_pCapability->rdi_mode_stream_fmt;
   10020         } else if (mPictureFormat >= CAM_FORMAT_YUV_RAW_8BIT_YUYV) {
   10021             format = (cam_format_t)mPictureFormat;
   10022         } else {
   10023             char raw_format[PROPERTY_VALUE_MAX];
   10024             int rawFormat;
   10025             memset(raw_format, 0, sizeof(raw_format));
   10026             /*Default value is CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GBRG*/
   10027             property_get("persist.camera.raw.format", raw_format, "17");
   10028             rawFormat = atoi(raw_format);
   10029             format = (cam_format_t)rawFormat;
   10030             LOGH("Raw stream format %d bundled with snapshot",
   10031                     format);
   10032         }
   10033         break;
   10034     case CAM_STREAM_TYPE_METADATA:
   10035     case CAM_STREAM_TYPE_OFFLINE_PROC:
   10036     case CAM_STREAM_TYPE_DEFAULT:
   10037     default:
   10038         break;
   10039     }
   10040 
   10041     LOGD("Stream type = %d Stream Format = %d", streamType, format);
   10042     return ret;
   10043 }
   10044 
   10045 /*===========================================================================
   10046  * FUNCTION   : getFlipMode
   10047  *
   10048  * DESCRIPTION: get flip mode
   10049  *
   10050  * PARAMETERS :
   10051  *   @cam_intf_parm_type_t : [input] stream type
   10052  *
   10053  * RETURN     : int type of flip mode
   10054  *              0 - no filp
   10055  *              1 - FLIP_H
   10056  *              2 - FLIP_V
   10057  *              3 - FLIP_H | FLIP_V
   10058  *==========================================================================*/
   10059 int QCameraParameters::getFlipMode(cam_stream_type_t type)
   10060 {
   10061     const char *str = NULL;
   10062     int flipMode = 0; // no flip
   10063 
   10064     switch(type){
   10065     case CAM_STREAM_TYPE_PREVIEW:
   10066         if (!isRdiMode()) {
   10067             str = get(KEY_QC_PREVIEW_FLIP);
   10068         }
   10069         break;
   10070     case CAM_STREAM_TYPE_VIDEO:
   10071         str = get(KEY_QC_VIDEO_FLIP);
   10072         break;
   10073     case CAM_STREAM_TYPE_SNAPSHOT:
   10074     case CAM_STREAM_TYPE_POSTVIEW:
   10075         str = get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
   10076         break;
   10077     default:
   10078         LOGD("No flip mode for stream type %d", type);
   10079         break;
   10080     }
   10081 
   10082     if(str != NULL){
   10083         //Need give corresponding filp value based on flip mode strings
   10084         int value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
   10085         if(value != NAME_NOT_FOUND)
   10086             flipMode = value;
   10087         }
   10088 
   10089     LOGH("the filp mode of stream type %d is %d .", type, flipMode);
   10090     return flipMode;
   10091 }
   10092 
   10093 /*===========================================================================
   10094  * FUNCTION   : isSnapshotFDNeeded
   10095  *
   10096  * DESCRIPTION: check whether Face Detection Metadata is needed
   10097  *
   10098  * PARAMETERS : none
   10099  *
   10100  * RETURN     : bool type of status
   10101  *              0 - need
   10102  *              1 - not need
   10103  *==========================================================================*/
   10104 bool QCameraParameters::isSnapshotFDNeeded()
   10105 {
   10106     return getInt(KEY_QC_SNAPSHOT_FD_DATA);
   10107 }
   10108 
   10109 /*===========================================================================
   10110  * FUNCTION   : getStreamDimension
   10111  *
   10112  * DESCRIPTION: get stream dimension by its type
   10113  *
   10114  * PARAMETERS :
   10115  *   @streamType : [input] stream type
   10116  *   @dim        : [output] stream dimension
   10117  *
   10118  * RETURN     : int32_t type of status
   10119  *              NO_ERROR  -- success
   10120  *              none-zero failure code
   10121  *==========================================================================*/
   10122 int32_t QCameraParameters::getStreamDimension(cam_stream_type_t streamType,
   10123                                                cam_dimension_t &dim)
   10124 {
   10125     int32_t ret = NO_ERROR;
   10126     memset(&dim, 0, sizeof(cam_dimension_t));
   10127 
   10128     switch (streamType) {
   10129     case CAM_STREAM_TYPE_PREVIEW:
   10130     case CAM_STREAM_TYPE_CALLBACK:
   10131         getPreviewSize(&dim.width, &dim.height);
   10132         break;
   10133     case CAM_STREAM_TYPE_POSTVIEW:
   10134         getPreviewSize(&dim.width, &dim.height);
   10135         break;
   10136     case CAM_STREAM_TYPE_SNAPSHOT:
   10137         if (isPostProcScaling()) {
   10138             getMaxPicSize(dim);
   10139         } else if (getRecordingHintValue()) {
   10140             // live snapshot
   10141             getLiveSnapshotSize(dim);
   10142         } else {
   10143             getPictureSize(&dim.width, &dim.height);
   10144         }
   10145         break;
   10146     case CAM_STREAM_TYPE_VIDEO:
   10147         getVideoSize(&dim.width, &dim.height);
   10148         break;
   10149     case CAM_STREAM_TYPE_RAW:
   10150         //dim = m_pCapability->raw_dim;
   10151         getRawSize(dim);
   10152         break;
   10153     case CAM_STREAM_TYPE_METADATA:
   10154         dim.width = (int32_t)sizeof(metadata_buffer_t);
   10155         dim.height = 1;
   10156         break;
   10157     case CAM_STREAM_TYPE_OFFLINE_PROC:
   10158         if (isPostProcScaling()) {
   10159             if (getRecordingHintValue()) {
   10160                 // live snapshot
   10161                 getLiveSnapshotSize(dim);
   10162             } else {
   10163                 getPictureSize(&dim.width, &dim.height);
   10164             }
   10165         }
   10166         break;
   10167     case CAM_STREAM_TYPE_ANALYSIS:
   10168         cam_dimension_t prv_dim, max_dim;
   10169 
   10170         /* Analysis stream need aspect ratio as preview stream */
   10171         getPreviewSize(&prv_dim.width, &prv_dim.height);
   10172 
   10173         cam_analysis_info_t analysisInfo;
   10174         cam_feature_mask_t featureMask;
   10175 
   10176         featureMask = 0;
   10177         getStreamPpMask(CAM_STREAM_TYPE_ANALYSIS, featureMask);
   10178         ret = getAnalysisInfo(
   10179                 ((getRecordingHintValue() == true) && fdModeInVideo()),
   10180                 FALSE,
   10181                 featureMask,
   10182                 &analysisInfo);
   10183         if (ret != NO_ERROR) {
   10184             LOGE("getAnalysisInfo failed, ret = %d", ret);
   10185             return ret;
   10186         }
   10187 
   10188         max_dim.width = analysisInfo.analysis_max_res.width;
   10189         max_dim.height = analysisInfo.analysis_max_res.height;
   10190 
   10191         if (prv_dim.width > max_dim.width || prv_dim.height > max_dim.height) {
   10192             double max_ratio, requested_ratio;
   10193 
   10194             max_ratio = (double)max_dim.width / (double)max_dim.height;
   10195             requested_ratio = (double)prv_dim.width / (double)prv_dim.height;
   10196 
   10197             if (max_ratio < requested_ratio) {
   10198                 dim.width = max_dim.width;
   10199                 dim.height = (int32_t)((double)dim.width / requested_ratio);
   10200             } else {
   10201                 dim.height = max_dim.height;
   10202                 dim.width = (int32_t)((double)max_dim.height * requested_ratio);
   10203             }
   10204             dim.width &= ~0x1;
   10205             dim.height &= ~0x1;
   10206         } else {
   10207             dim.width = prv_dim.width;
   10208             dim.height = prv_dim.height;
   10209         }
   10210       break;
   10211     case CAM_STREAM_TYPE_DEFAULT:
   10212     default:
   10213         LOGE("no dimension for unsupported stream type %d",
   10214                streamType);
   10215         ret = BAD_VALUE;
   10216         break;
   10217     }
   10218 
   10219     LOGD("Stream type = %d Stream Dimension = %d X %d",
   10220              streamType, dim.width, dim.height);
   10221     return ret;
   10222 }
   10223 
   10224 /*===========================================================================
   10225  * FUNCTION   : getParameters
   10226  *
   10227  * DESCRIPTION: Return a C string containing the parameters
   10228  *
   10229  * PARAMETERS : none
   10230  *
   10231  * RETURN     : a string containing parameter pairs
   10232  *==========================================================================*/
   10233 char* QCameraParameters::getParameters()
   10234 {
   10235     char* strParams = NULL;
   10236     String8 str;
   10237 
   10238     int cur_width, cur_height;
   10239     //Need take care Scale picture size
   10240     if(m_reprocScaleParam.isScaleEnabled() &&
   10241         m_reprocScaleParam.isUnderScaling()){
   10242         int scale_width, scale_height;
   10243 
   10244         m_reprocScaleParam.getPicSizeFromAPK(scale_width,scale_height);
   10245         getPictureSize(&cur_width, &cur_height);
   10246 
   10247         String8 pic_size;
   10248         char buffer[32];
   10249         snprintf(buffer, sizeof(buffer), "%dx%d", scale_width, scale_height);
   10250         pic_size.append(buffer);
   10251         set(CameraParameters::KEY_PICTURE_SIZE, pic_size);
   10252     }
   10253 
   10254     str = flatten();
   10255     strParams = (char *)malloc(sizeof(char)*(str.length()+1));
   10256     if(strParams != NULL){
   10257         memset(strParams, 0, sizeof(char)*(str.length()+1));
   10258         strlcpy(strParams, str.string(), str.length()+1);
   10259         strParams[str.length()] = 0;
   10260     }
   10261 
   10262     if(m_reprocScaleParam.isScaleEnabled() &&
   10263         m_reprocScaleParam.isUnderScaling()){
   10264         //need set back picture size
   10265         String8 pic_size;
   10266         char buffer[32];
   10267         snprintf(buffer, sizeof(buffer), "%dx%d", cur_width, cur_height);
   10268         pic_size.append(buffer);
   10269         set(CameraParameters::KEY_PICTURE_SIZE, pic_size);
   10270     }
   10271     return strParams;
   10272 }
   10273 
   10274 #ifdef TARGET_TS_MAKEUP
   10275 /*===========================================================================
   10276  * FUNCTION   : getTsMakeupInfo
   10277  *
   10278  * DESCRIPTION: get TsMakeup info
   10279  *
   10280  * PARAMETERS :
   10281  *   @whiteLevel : [output] white level
   10282  *   @cleanLevel : [output] clean level
   10283 
   10284  * RETURN     : Whether makeup is enabled or not
   10285  *==========================================================================*/
   10286 bool QCameraParameters::getTsMakeupInfo(int &whiteLevel, int &cleanLevel) const
   10287 {
   10288     const char* pch_makeup_enable = get(QCameraParameters::KEY_TS_MAKEUP);
   10289     if (pch_makeup_enable == NULL) {
   10290         LOGH("pch_makeup_enable = null");
   10291         return false;
   10292     }
   10293     bool enableMakeup =
   10294             (strcmp(pch_makeup_enable,"On") == 0);
   10295     if (enableMakeup) {
   10296         whiteLevel = getInt(QCameraParameters::KEY_TS_MAKEUP_WHITEN);
   10297         cleanLevel = getInt(QCameraParameters::KEY_TS_MAKEUP_CLEAN);
   10298     }
   10299     return enableMakeup;
   10300 }
   10301 #endif
   10302 
   10303 /*===========================================================================
   10304  * FUNCTION   : getPreviewHalPixelFormat
   10305  *
   10306  * DESCRIPTION: get preview HAL pixel format
   10307  *
   10308  * PARAMETERS : none
   10309  *
   10310  * RETURN     : HAL pixel format
   10311  *==========================================================================*/
   10312 int QCameraParameters::getPreviewHalPixelFormat()
   10313 {
   10314     int32_t halPixelFormat;
   10315     cam_format_t fmt;
   10316     getStreamFormat(CAM_STREAM_TYPE_PREVIEW,fmt);
   10317 
   10318     switch (fmt) {
   10319     case CAM_FORMAT_YUV_420_NV12:
   10320         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP;
   10321         break;
   10322     case CAM_FORMAT_YUV_420_NV21:
   10323         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
   10324         break;
   10325     case CAM_FORMAT_YUV_420_NV21_ADRENO:
   10326         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO;
   10327         break;
   10328     case CAM_FORMAT_YUV_420_YV12:
   10329         halPixelFormat = HAL_PIXEL_FORMAT_YV12;
   10330         break;
   10331     case CAM_FORMAT_YUV_420_NV12_VENUS:
   10332         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS;
   10333         break;
   10334     case CAM_FORMAT_YUV_420_NV21_VENUS:
   10335         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS;
   10336         break;
   10337     case CAM_FORMAT_YUV_420_NV12_UBWC:
   10338         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC;
   10339         break;
   10340     case CAM_FORMAT_YUV_422_NV16:
   10341     case CAM_FORMAT_YUV_422_NV61:
   10342     default:
   10343         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
   10344         break;
   10345     }
   10346     LOGH("format %d\n", halPixelFormat);
   10347     return halPixelFormat;
   10348 }
   10349 
   10350 /*===========================================================================
   10351  * FUNCTION   : getthumbnailSize
   10352  *
   10353  * DESCRIPTION: get thumbnail size
   10354  *
   10355  * PARAMETERS :
   10356  *   @width, height : [output] thumbnail width and height
   10357  *
   10358  * RETURN     : none
   10359  *==========================================================================*/
   10360 void QCameraParameters::getThumbnailSize(int *width, int *height) const
   10361 {
   10362     *width = getInt(KEY_JPEG_THUMBNAIL_WIDTH);
   10363     *height = getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
   10364 }
   10365 
   10366 /*===========================================================================
   10367  * FUNCTION   : getZSLBurstInterval
   10368  *
   10369  * DESCRIPTION: get ZSL burst interval setting
   10370  *
   10371  * PARAMETERS : none
   10372  *
   10373  * RETURN     : ZSL burst interval value
   10374  *==========================================================================*/
   10375 uint8_t QCameraParameters::getZSLBurstInterval()
   10376 {
   10377     int interval = getInt(KEY_QC_ZSL_BURST_INTERVAL);
   10378     if (interval < 0) {
   10379         interval = 1;
   10380     }
   10381     return (uint8_t)interval;
   10382 }
   10383 
   10384 /*===========================================================================
   10385  * FUNCTION   : getZSLQueueDepth
   10386  *
   10387  * DESCRIPTION: get ZSL queue depth
   10388  *
   10389  * PARAMETERS : none
   10390  *
   10391  * RETURN     : ZSL queue depth value
   10392  *==========================================================================*/
   10393 uint8_t QCameraParameters::getZSLQueueDepth()
   10394 {
   10395     int qdepth = getInt(KEY_QC_ZSL_QUEUE_DEPTH);
   10396     if (qdepth < 0) {
   10397         qdepth = 2;
   10398     }
   10399     if (isLowMemoryDevice()) {
   10400         qdepth = 1;
   10401     }
   10402     return (uint8_t)qdepth;
   10403 }
   10404 
   10405 /*===========================================================================
   10406  * FUNCTION   : getZSLBackLookCount
   10407  *
   10408  * DESCRIPTION: get ZSL backlook count setting
   10409  *
   10410  * PARAMETERS : none
   10411  *
   10412  * RETURN     : ZSL backlook count value
   10413  *==========================================================================*/
   10414 uint8_t QCameraParameters::getZSLBackLookCount()
   10415 {
   10416     int look_back = getInt(KEY_QC_ZSL_BURST_LOOKBACK);
   10417     if (look_back < 0) {
   10418         look_back = 2;
   10419     }
   10420     if (isLowMemoryDevice()) {
   10421         look_back = 1;
   10422     }
   10423     return (uint8_t)look_back;
   10424 }
   10425 /*===========================================================================
   10426  * FUNCTION   : isVideoBuffersCached
   10427  *
   10428  * DESCRIPTION: Query buffers are cached /un cached
   10429  *
   10430  * PARAMETERS : None
   10431  *
   10432  * RETURN     : buffers are cached /un cached
   10433  *==========================================================================*/
   10434 bool QCameraParameters::isVideoBuffersCached()
   10435 {
   10436     const char *cached_mem  = get(KEY_QC_CACHE_VIDEO_BUFFERS);
   10437     if (cached_mem != NULL) {
   10438         if (strcmp(cached_mem, VALUE_DISABLE) != 0) {
   10439             return true;
   10440         }
   10441     }
   10442     return false;
   10443 }
   10444 /*===========================================================================
   10445  * FUNCTION   : getZSLMaxUnmatchedFrames
   10446  *
   10447  * DESCRIPTION: get allowed ZSL max unmatched frames number
   10448  *
   10449  * PARAMETERS : none
   10450  *
   10451  * RETURN     : ZSL backlook count value
   10452  *==========================================================================*/
   10453 uint8_t QCameraParameters::getMaxUnmatchedFramesInQueue()
   10454 {
   10455     return (uint8_t)(m_pCapability->min_num_pp_bufs);
   10456 }
   10457 
   10458 /*===========================================================================
   10459  * FUNCTION   : setRecordingHintValue
   10460  *
   10461  * DESCRIPTION: set recording hint
   10462  *
   10463  * PARAMETERS :
   10464  *   @value   : video hint value
   10465  *
   10466  * RETURN     : int32_t type of status
   10467  *              NO_ERROR  -- success
   10468  *              none-zero failure code
   10469  *==========================================================================*/
   10470 int QCameraParameters::setRecordingHintValue(int32_t value)
   10471 {
   10472     LOGH("VideoHint = %d", value);
   10473     bool newValue = (value > 0)? true : false;
   10474 
   10475     if ( m_bRecordingHint != newValue ) {
   10476         m_bNeedRestart = true;
   10477         m_bRecordingHint_new = newValue;
   10478     } else {
   10479         m_bRecordingHint_new = m_bRecordingHint;
   10480     }
   10481     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RECORDING_HINT, value)) {
   10482         return BAD_VALUE;
   10483     }
   10484 
   10485     return NO_ERROR;
   10486 }
   10487 
   10488 /*===========================================================================
   10489  * FUNCTION   : getNumOfSnapshots
   10490  *
   10491  * DESCRIPTION: get number of snapshot per shutter
   10492  *
   10493  * PARAMETERS : none
   10494  *
   10495  * RETURN     : number of snapshot per shutter
   10496  *==========================================================================*/
   10497 uint8_t QCameraParameters::getNumOfSnapshots()
   10498 {
   10499     uint8_t numOfSnapshot = 1;
   10500     int val = getInt(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER);
   10501     if (0 < val) {
   10502         numOfSnapshot = (uint8_t)val;
   10503     }
   10504 
   10505     return (uint8_t)numOfSnapshot;
   10506 }
   10507 
   10508 /*===========================================================================
   10509  * FUNCTION   : getBurstCountForAdvancedCapture
   10510  *
   10511  * DESCRIPTION: get burst count for advanced capture.
   10512  *
   10513  * PARAMETERS : none
   10514  *
   10515  * RETURN     : number of snapshot required for advanced capture.
   10516  *==========================================================================*/
   10517 uint8_t QCameraParameters::getBurstCountForAdvancedCapture()
   10518 {
   10519     uint32_t burstCount = 0;
   10520     if (isUbiFocusEnabled()) {
   10521         //number of snapshots required for Ubi Focus.
   10522         burstCount = m_pCapability->ubifocus_af_bracketing_need.burst_count;
   10523     } else if (isUbiRefocus()) {
   10524         //number of snapshots required for Opti Zoom.
   10525         burstCount = m_pCapability->refocus_af_bracketing_need.burst_count;
   10526     } else if (isOptiZoomEnabled()) {
   10527         //number of snapshots required for Opti Zoom.
   10528         burstCount = m_pCapability->opti_zoom_settings_need.burst_count;
   10529     } else if (isChromaFlashEnabled()) {
   10530         //number of snapshots required for Chroma Flash.
   10531         burstCount = m_pCapability->chroma_flash_settings_need.burst_count;
   10532     } else if (isStillMoreEnabled()) {
   10533         //number of snapshots required for Still More.
   10534         if (isSeeMoreEnabled()) {
   10535             burstCount = 1;
   10536         } else if ((m_stillmore_config.burst_count >=
   10537                 m_pCapability->stillmore_settings_need.min_burst_count) &&
   10538                 (m_stillmore_config.burst_count <=
   10539                 m_pCapability->stillmore_settings_need.max_burst_count)) {
   10540             burstCount = m_stillmore_config.burst_count;
   10541         } else {
   10542             burstCount = m_pCapability->stillmore_settings_need.burst_count;
   10543         }
   10544     } else if (isHDREnabled()) {
   10545         //number of snapshots required for HDR.
   10546         burstCount = m_pCapability->hdr_bracketing_setting.num_frames;
   10547     } else if (isAEBracketEnabled()) {
   10548       burstCount = 0;
   10549       const char *str_val = m_AEBracketingClient.values;
   10550       if ((str_val != NULL) && (strlen(str_val) > 0)) {
   10551           char prop[PROPERTY_VALUE_MAX];
   10552           memset(prop, 0, sizeof(prop));
   10553           strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
   10554           char *saveptr = NULL;
   10555           char *token = strtok_r(prop, ",", &saveptr);
   10556           while (token != NULL) {
   10557               token = strtok_r(NULL, ",", &saveptr);
   10558               burstCount++;
   10559           }
   10560       }
   10561     }
   10562 
   10563     if (burstCount <= 0) {
   10564         burstCount = getNumOfSnapshots();
   10565     }
   10566 
   10567     LOGH("Snapshot burst count = %d", burstCount);
   10568     return (uint8_t)burstCount;
   10569 }
   10570 
   10571 /*===========================================================================
   10572  * FUNCTION   : getNumOfRetroSnapshots
   10573  *
   10574  * DESCRIPTION: get number of retro active snapshots per shutter
   10575  *
   10576  * PARAMETERS : none
   10577  *
   10578  * RETURN     : number of retro active snapshots per shutter
   10579  *==========================================================================*/
   10580 uint8_t QCameraParameters::getNumOfRetroSnapshots()
   10581 {
   10582     int numOfRetroSnapshots = getInt(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER);
   10583     if (numOfRetroSnapshots < 0) {
   10584         numOfRetroSnapshots = 0;
   10585     }
   10586     LOGH("numOfRetroSnaps - %d", numOfRetroSnapshots);
   10587     return (uint8_t)numOfRetroSnapshots;
   10588 }
   10589 
   10590 /*===========================================================================
   10591  * FUNCTION   : getNumOfExtraHDRInBufsIfNeeded
   10592  *
   10593  * DESCRIPTION: get number of extra input buffers needed by HDR
   10594  *
   10595  * PARAMETERS : none
   10596  *
   10597  * RETURN     : number of extra buffers needed by HDR; 0 if not HDR enabled
   10598  *==========================================================================*/
   10599 uint8_t QCameraParameters::getNumOfExtraHDRInBufsIfNeeded()
   10600 {
   10601     unsigned int numOfBufs = 0;
   10602 
   10603     if (isHDREnabled()) {
   10604         numOfBufs += m_pCapability->hdr_bracketing_setting.num_frames;
   10605         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
   10606             numOfBufs++;
   10607         }
   10608         numOfBufs--; // Only additional buffers need to be returned
   10609     }
   10610 
   10611     return (uint8_t)(numOfBufs);
   10612 }
   10613 
   10614 /*===========================================================================
   10615  * FUNCTION   : getNumOfExtraHDROutBufsIfNeeded
   10616  *
   10617  * DESCRIPTION: get number of extra output buffers needed by HDR
   10618  *
   10619  * PARAMETERS : none
   10620  *
   10621  * RETURN     : number of extra buffers needed by HDR; 0 if not HDR enabled
   10622  *==========================================================================*/
   10623 uint8_t QCameraParameters::getNumOfExtraHDROutBufsIfNeeded()
   10624 {
   10625     int numOfBufs = 0;
   10626 
   10627     if (isHDREnabled() && isHDR1xFrameEnabled()) {
   10628         numOfBufs++;
   10629     }
   10630 
   10631     return (uint8_t)(numOfBufs);
   10632 }
   10633 
   10634 /*===========================================================================
   10635  * FUNCTION   : getJpegQuality
   10636  *
   10637  * DESCRIPTION: get jpeg encoding quality
   10638  *
   10639  * PARAMETERS : none
   10640  *
   10641  * RETURN     : jpeg encoding quality
   10642  *==========================================================================*/
   10643 uint32_t QCameraParameters::getJpegQuality()
   10644 {
   10645     int quality = getInt(KEY_JPEG_QUALITY);
   10646     if (quality < 0) {
   10647         quality = 85; // set to default quality value
   10648     }
   10649     return (uint32_t)quality;
   10650 }
   10651 
   10652 /*===========================================================================
   10653  * FUNCTION   : getRotation
   10654  *
   10655  * DESCRIPTION: get application configured rotation
   10656  *
   10657  * PARAMETERS : none
   10658  *
   10659  * RETURN     : rotation value
   10660  *==========================================================================*/
   10661 uint32_t QCameraParameters::getRotation() {
   10662     int rotation = 0;
   10663 
   10664     //If exif rotation is set, do not rotate captured image
   10665     if (!useJpegExifRotation()) {
   10666         rotation = mRotation;
   10667         if (rotation < 0) {
   10668             rotation = 0;
   10669         }
   10670     }
   10671     return (uint32_t)rotation;
   10672 }
   10673 
   10674 /*===========================================================================
   10675  * FUNCTION   : setJpegRotation
   10676  *
   10677  * DESCRIPTION: set jpeg rotation value configured internally
   10678  *
   10679  * PARAMETERS : none
   10680  *
   10681  * RETURN     : jpeg rotation value
   10682  *==========================================================================*/
   10683 void QCameraParameters::setJpegRotation(int rotation) {
   10684     if (rotation == 0 || rotation == 90 ||
   10685             rotation == 180 || rotation == 270) {
   10686         mJpegRotation = (uint32_t)rotation;
   10687     }
   10688 }
   10689 
   10690 /*===========================================================================
   10691  * FUNCTION   : getDeviceRotation
   10692  *
   10693  * DESCRIPTION: get device rotation value
   10694  *
   10695  * PARAMETERS : none
   10696  *
   10697  * RETURN     : device rotation value
   10698  *==========================================================================*/
   10699 uint32_t QCameraParameters::getDeviceRotation() {
   10700     int rotation = 0;
   10701 
   10702     rotation = mRotation;
   10703     if (rotation < 0) {
   10704         rotation = 0;
   10705     }
   10706 
   10707     return (uint32_t)rotation;
   10708 }
   10709 
   10710 /*===========================================================================
   10711  * FUNCTION   : getJpegExifRotation
   10712  *
   10713  * DESCRIPTION: get exif rotation value
   10714  *
   10715  * PARAMETERS : none
   10716  *
   10717  * RETURN     : rotation value
   10718  *==========================================================================*/
   10719 uint32_t QCameraParameters::getJpegExifRotation() {
   10720     int rotation = 0;
   10721 
   10722     if (useJpegExifRotation()) {
   10723         rotation = mRotation;
   10724         if (rotation < 0) {
   10725             rotation = 0;
   10726         }
   10727     }
   10728     return (uint32_t)rotation;
   10729 }
   10730 
   10731 /*===========================================================================
   10732  * FUNCTION   : useJpegExifRotation
   10733  *
   10734  * DESCRIPTION: Check if jpeg exif rotation need to be used
   10735  *
   10736  * PARAMETERS : none
   10737  *
   10738  * RETURN     : true if jpeg exif rotation need to be used
   10739  *==========================================================================*/
   10740 bool QCameraParameters::useJpegExifRotation() {
   10741     char exifRotation[PROPERTY_VALUE_MAX];
   10742 
   10743     property_get("persist.camera.exif.rotation", exifRotation, "off");
   10744 
   10745     if (!strcmp(exifRotation, "on")) {
   10746         return true;
   10747     }
   10748 
   10749     if (!(m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_ROTATION)) {
   10750         return true;
   10751     }
   10752 
   10753     return false;
   10754 }
   10755 
   10756 /*===========================================================================
   10757  * FUNCTION   : getEffectValue
   10758  *
   10759  * DESCRIPTION: get effect value
   10760  *
   10761  * PARAMETERS : none
   10762  *
   10763  * RETURN     : effect value
   10764  *==========================================================================*/
   10765 int32_t QCameraParameters::getEffectValue()
   10766 {
   10767     uint32_t cnt = 0;
   10768     const char *effect = get(KEY_EFFECT);
   10769     if (effect) {
   10770         while (NULL != EFFECT_MODES_MAP[cnt].desc) {
   10771             if (!strcmp(EFFECT_MODES_MAP[cnt].desc, effect)) {
   10772                 return EFFECT_MODES_MAP[cnt].val;
   10773             }
   10774             cnt++;
   10775         }
   10776     } else {
   10777         LOGW("Missing effect value");
   10778     }
   10779     return CAM_EFFECT_MODE_OFF;
   10780 }
   10781 
   10782 /*===========================================================================
   10783  * FUNCTION   : parseGPSCoordinate
   10784  *
   10785  * DESCRIPTION: parse GPS coordinate string
   10786  *
   10787  * PARAMETERS :
   10788  *   @coord_str : [input] coordinate string
   10789  *   @coord     : [output]  ptr to struct to store coordinate
   10790  *
   10791  * RETURN     : int32_t type of status
   10792  *              NO_ERROR  -- success
   10793  *              none-zero failure code
   10794  *==========================================================================*/
   10795 int QCameraParameters::parseGPSCoordinate(const char *coord_str, rat_t* coord)
   10796 {
   10797     if(coord == NULL) {
   10798         LOGE("error, invalid argument coord == NULL");
   10799         return BAD_VALUE;
   10800     }
   10801     double degF = atof(coord_str);
   10802     if (degF < 0) {
   10803         degF = -degF;
   10804     }
   10805     double minF = (degF - (double)(int) degF) * 60.0;
   10806     double secF = (minF - (double)(int) minF) * 60.0;
   10807 
   10808     getRational(&coord[0], (int)degF, 1);
   10809     getRational(&coord[1], (int)minF, 1);
   10810     getRational(&coord[2], (int)(secF * 10000.0), 10000);
   10811     return NO_ERROR;
   10812 }
   10813 
   10814 /*===========================================================================
   10815  * FUNCTION   : getExifDateTime
   10816  *
   10817  * DESCRIPTION: query exif date time
   10818  *
   10819  * PARAMETERS :
   10820  *   @dateTime    : String to store exif date time.
   10821  *                  Should be leaved unchanged in case of error.
   10822  *   @subsecTime  : String to store exif time nanoseconds.
   10823  *                  Should be leaved unchanged in case of error.
   10824  *
   10825  * RETURN     : int32_t type of status
   10826  *              NO_ERROR  -- success
   10827  *              none-zero failure code
   10828  *==========================================================================*/
   10829 int32_t QCameraParameters::getExifDateTime(String8 &dateTime, String8 &subsecTime)
   10830 {
   10831     int32_t ret = NO_ERROR;
   10832 
   10833     //get time and date from system
   10834     struct timeval tv;
   10835     struct tm timeinfo_data;
   10836 
   10837     int res = gettimeofday(&tv, NULL);
   10838     if (0 == res) {
   10839         struct tm *timeinfo = localtime_r(&tv.tv_sec, &timeinfo_data);
   10840         if (NULL != timeinfo) {
   10841             //Write datetime according to EXIF Spec
   10842             //"YYYY:MM:DD HH:MM:SS" (20 chars including \0)
   10843             dateTime = String8::format("%04d:%02d:%02d %02d:%02d:%02d",
   10844                     timeinfo->tm_year + 1900, timeinfo->tm_mon + 1,
   10845                     timeinfo->tm_mday, timeinfo->tm_hour,
   10846                     timeinfo->tm_min, timeinfo->tm_sec);
   10847             //Write subsec according to EXIF Sepc
   10848             subsecTime = String8::format("%06ld", tv.tv_usec);
   10849         } else {
   10850             LOGE("localtime_r() error");
   10851             ret = UNKNOWN_ERROR;
   10852         }
   10853     } else if (-1 == res) {
   10854         LOGE("gettimeofday() error: %s", strerror(errno));
   10855         ret = UNKNOWN_ERROR;
   10856     } else {
   10857         LOGE("gettimeofday() unexpected return code: %d", res);
   10858         ret = UNKNOWN_ERROR;
   10859     }
   10860 
   10861     return ret;
   10862 }
   10863 
   10864 /*===========================================================================
   10865  * FUNCTION   : getRational
   10866  *
   10867  * DESCRIPTION: compose rational struct
   10868  *
   10869  * PARAMETERS :
   10870  *   @rat     : ptr to struct to store rational info
   10871  *   @num     :num of the rational
   10872  *   @denom   : denom of the rational
   10873  *
   10874  * RETURN     : int32_t type of status
   10875  *              NO_ERROR  -- success
   10876  *              none-zero failure code
   10877  *==========================================================================*/
   10878 int32_t QCameraParameters::getRational(rat_t *rat, int num, int denom)
   10879 {
   10880     if ((0 > num) || (0 > denom)) {
   10881         LOGE("Negative values");
   10882         return BAD_VALUE;
   10883     }
   10884     if (NULL == rat) {
   10885         LOGE("NULL rat input");
   10886         return BAD_VALUE;
   10887     }
   10888     rat->num = (uint32_t)num;
   10889     rat->denom = (uint32_t)denom;
   10890     return NO_ERROR;
   10891 }
   10892 
   10893 /*===========================================================================
   10894  * FUNCTION   : getExifFocalLength
   10895  *
   10896  * DESCRIPTION: get exif focal lenght
   10897  *
   10898  * PARAMETERS :
   10899  *   @focalLength : ptr to rational strcut to store focal lenght
   10900  *
   10901  * RETURN     : int32_t type of status
   10902  *              NO_ERROR  -- success
   10903  *              none-zero failure code
   10904  *==========================================================================*/
   10905 int32_t QCameraParameters::getExifFocalLength(rat_t *focalLength)
   10906 {
   10907     int focalLengthValue =
   10908         (int)(getFloat(QCameraParameters::KEY_FOCAL_LENGTH) * FOCAL_LENGTH_DECIMAL_PRECISION);
   10909     return getRational(focalLength, focalLengthValue, FOCAL_LENGTH_DECIMAL_PRECISION);
   10910 }
   10911 
   10912 /*===========================================================================
   10913  * FUNCTION   : getExifIsoSpeed
   10914  *
   10915  * DESCRIPTION: get exif ISO speed
   10916  *
   10917  * PARAMETERS : none
   10918  *
   10919  * RETURN     : ISO speed value
   10920  *==========================================================================*/
   10921 uint16_t QCameraParameters::getExifIsoSpeed()
   10922 {
   10923     uint16_t isoSpeed = 0;
   10924     const char *iso_str = get(QCameraParameters::KEY_QC_ISO_MODE);
   10925     int iso_index = lookupAttr(ISO_MODES_MAP, PARAM_MAP_SIZE(ISO_MODES_MAP), iso_str);
   10926     switch (iso_index) {
   10927     case CAM_ISO_MODE_AUTO:
   10928         isoSpeed = 0;
   10929         break;
   10930     case CAM_ISO_MODE_DEBLUR:
   10931         isoSpeed = 1;
   10932         break;
   10933     case CAM_ISO_MODE_100:
   10934         isoSpeed = 100;
   10935         break;
   10936     case CAM_ISO_MODE_200:
   10937         isoSpeed = 200;
   10938         break;
   10939     case CAM_ISO_MODE_400:
   10940         isoSpeed = 400;
   10941         break;
   10942     case CAM_ISO_MODE_800:
   10943         isoSpeed = 800;
   10944         break;
   10945     case CAM_ISO_MODE_1600:
   10946         isoSpeed = 1600;
   10947         break;
   10948     case CAM_ISO_MODE_3200:
   10949         isoSpeed = 3200;
   10950         break;
   10951     }
   10952     return isoSpeed;
   10953 }
   10954 
   10955 /*===========================================================================
   10956  * FUNCTION   : getExifGpsProcessingMethod
   10957  *
   10958  * DESCRIPTION: get GPS processing method
   10959  *
   10960  * PARAMETERS :
   10961  *   @gpsProcessingMethod : string to store GPS process method
   10962  *   @count               : lenght of the string
   10963  *
   10964  * RETURN     : int32_t type of status
   10965  *              NO_ERROR  -- success
   10966  *              none-zero failure code
   10967  *==========================================================================*/
   10968 int32_t QCameraParameters::getExifGpsProcessingMethod(char *gpsProcessingMethod,
   10969                                                       uint32_t &count)
   10970 {
   10971     const char *str = get(KEY_GPS_PROCESSING_METHOD);
   10972     if(str != NULL) {
   10973         memcpy(gpsProcessingMethod, ExifAsciiPrefix, EXIF_ASCII_PREFIX_SIZE);
   10974         count = EXIF_ASCII_PREFIX_SIZE;
   10975         strlcpy(gpsProcessingMethod + EXIF_ASCII_PREFIX_SIZE, str, GPS_PROCESSING_METHOD_SIZE);
   10976         count += (uint32_t)strlen(str);
   10977         gpsProcessingMethod[count++] = '\0'; // increase 1 for the last NULL char
   10978         return NO_ERROR;
   10979     } else {
   10980         return BAD_VALUE;
   10981     }
   10982 }
   10983 
   10984 /*===========================================================================
   10985  * FUNCTION   : getExifLatitude
   10986  *
   10987  * DESCRIPTION: get exif latitude
   10988  *
   10989  * PARAMETERS :
   10990  *   @latitude : ptr to rational struct to store latitude info
   10991  *   @ladRef   : charater to indicate latitude reference
   10992  *
   10993  * RETURN     : int32_t type of status
   10994  *              NO_ERROR  -- success
   10995  *              none-zero failure code
   10996  *==========================================================================*/
   10997 int32_t QCameraParameters::getExifLatitude(rat_t *latitude,
   10998                                            char *latRef)
   10999 {
   11000     const char *str = get(KEY_GPS_LATITUDE);
   11001     if(str != NULL) {
   11002         parseGPSCoordinate(str, latitude);
   11003 
   11004         //set Latitude Ref
   11005         float latitudeValue = getFloat(KEY_GPS_LATITUDE);
   11006         if(latitudeValue < 0.0f) {
   11007             latRef[0] = 'S';
   11008         } else {
   11009             latRef[0] = 'N';
   11010         }
   11011         latRef[1] = '\0';
   11012         return NO_ERROR;
   11013     }else{
   11014         return BAD_VALUE;
   11015     }
   11016 }
   11017 
   11018 /*===========================================================================
   11019  * FUNCTION   : getExifLongitude
   11020  *
   11021  * DESCRIPTION: get exif longitude
   11022  *
   11023  * PARAMETERS :
   11024  *   @longitude : ptr to rational struct to store longitude info
   11025  *   @lonRef    : charater to indicate longitude reference
   11026  *
   11027  * RETURN     : int32_t type of status
   11028  *              NO_ERROR  -- success
   11029  *              none-zero failure code
   11030  *==========================================================================*/
   11031 int32_t QCameraParameters::getExifLongitude(rat_t *longitude,
   11032                                             char *lonRef)
   11033 {
   11034     const char *str = get(KEY_GPS_LONGITUDE);
   11035     if(str != NULL) {
   11036         parseGPSCoordinate(str, longitude);
   11037 
   11038         //set Longitude Ref
   11039         float longitudeValue = getFloat(KEY_GPS_LONGITUDE);
   11040         if(longitudeValue < 0.0f) {
   11041             lonRef[0] = 'W';
   11042         } else {
   11043             lonRef[0] = 'E';
   11044         }
   11045         lonRef[1] = '\0';
   11046         return NO_ERROR;
   11047     }else{
   11048         return BAD_VALUE;
   11049     }
   11050 }
   11051 
   11052 /*===========================================================================
   11053  * FUNCTION   : getExifAltitude
   11054  *
   11055  * DESCRIPTION: get exif altitude
   11056  *
   11057  * PARAMETERS :
   11058  *   @altitude : ptr to rational struct to store altitude info
   11059  *   @altRef   : charater to indicate altitude reference
   11060  *
   11061  * RETURN     : int32_t type of status
   11062  *              NO_ERROR  -- success
   11063  *              none-zero failure code
   11064  *==========================================================================*/
   11065 int32_t QCameraParameters::getExifAltitude(rat_t *altitude,
   11066                                            char *altRef)
   11067 {
   11068     const char *str = get(KEY_GPS_ALTITUDE);
   11069     if(str != NULL) {
   11070         double value = atof(str);
   11071         *altRef = 0;
   11072         if(value < 0){
   11073             *altRef = 1;
   11074             value = -value;
   11075         }
   11076         return getRational(altitude, (int)(value*1000), 1000);
   11077     }else{
   11078         return BAD_VALUE;
   11079     }
   11080 }
   11081 
   11082 /*===========================================================================
   11083  * FUNCTION   : getExifGpsDateTimeStamp
   11084  *
   11085  * DESCRIPTION: get exif GPS date time stamp
   11086  *
   11087  * PARAMETERS :
   11088  *   @gpsDateStamp : GPS date time stamp string
   11089  *   @bufLen       : length of the string
   11090  *   @gpsTimeStamp : ptr to rational struct to store time stamp info
   11091  *
   11092  * RETURN     : int32_t type of status
   11093  *              NO_ERROR  -- success
   11094  *              none-zero failure code
   11095  *==========================================================================*/
   11096 int32_t QCameraParameters::getExifGpsDateTimeStamp(char *gpsDateStamp,
   11097                                                    uint32_t bufLen,
   11098                                                    rat_t *gpsTimeStamp)
   11099 {
   11100     const char *str = get(KEY_GPS_TIMESTAMP);
   11101     if(str != NULL) {
   11102         time_t unixTime = (time_t)atol(str);
   11103         struct tm *UTCTimestamp = gmtime(&unixTime);
   11104 
   11105         if(!UTCTimestamp) {
   11106             LOGE("UTCTimestamp is null\n");
   11107             return BAD_VALUE;
   11108         }
   11109 
   11110         strftime(gpsDateStamp, bufLen, "%Y:%m:%d", UTCTimestamp);
   11111 
   11112         getRational(&gpsTimeStamp[0], UTCTimestamp->tm_hour, 1);
   11113         getRational(&gpsTimeStamp[1], UTCTimestamp->tm_min, 1);
   11114         getRational(&gpsTimeStamp[2], UTCTimestamp->tm_sec, 1);
   11115 
   11116         return NO_ERROR;
   11117     } else {
   11118         return BAD_VALUE;
   11119     }
   11120 }
   11121 
   11122 /*===========================================================================
   11123  * FUNCTION   : updateFocusDistances
   11124  *
   11125  * DESCRIPTION: update focus distances
   11126  *
   11127  * PARAMETERS :
   11128  *   @focusDistances : ptr to focus distance info
   11129  *
   11130  * RETURN     : int32_t type of status
   11131  *              NO_ERROR  -- success
   11132  *              none-zero failure code
   11133  *==========================================================================*/
   11134 int32_t QCameraParameters::updateFocusDistances(cam_focus_distances_info_t *focusDistances)
   11135 {
   11136     String8 str;
   11137     char buffer[32] = {0};
   11138     //set all distances to infinity if focus mode is infinity
   11139     if(mFocusMode == CAM_FOCUS_MODE_INFINITY) {
   11140         str.append("Infinity,Infinity,Infinity");
   11141     } else {
   11142         if (focusDistances->focus_distance[0] < FOCUS_PERCISION) {
   11143             str.append("Infinity");
   11144         } else {
   11145             snprintf(buffer, sizeof(buffer), "%f", 1.0/focusDistances->focus_distance[0]);
   11146             str.append(buffer);
   11147         }
   11148         if (focusDistances->focus_distance[1] < FOCUS_PERCISION) {
   11149             str.append(",Infinity");
   11150         } else {
   11151             snprintf(buffer, sizeof(buffer), ",%f", 1.0/focusDistances->focus_distance[1]);
   11152             str.append(buffer);
   11153         }
   11154         if (focusDistances->focus_distance[2] < FOCUS_PERCISION) {
   11155             str.append(",Infinity");
   11156         } else {
   11157             snprintf(buffer, sizeof(buffer), ",%f", 1.0/focusDistances->focus_distance[2]);
   11158             str.append(buffer);
   11159         }
   11160     }
   11161     LOGH("setting KEY_FOCUS_DISTANCES as %s", __FUNCTION__, str.string());
   11162     set(QCameraParameters::KEY_FOCUS_DISTANCES, str.string());
   11163     return NO_ERROR;
   11164 }
   11165 
   11166 /*===========================================================================
   11167  * FUNCTION   : updateRecordingHintValue
   11168  *
   11169  * DESCRIPTION: update recording hint locally and to daemon
   11170  *
   11171  * PARAMETERS :
   11172  *   @value   : video hint value
   11173  *
   11174  * RETURN     : int32_t type of status
   11175  *              NO_ERROR  -- success
   11176  *              none-zero failure code
   11177  *==========================================================================*/
   11178 int32_t QCameraParameters::updateRecordingHintValue(int32_t value)
   11179 {
   11180     int32_t rc = NO_ERROR;
   11181     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   11182         LOGE("Failed to initialize group update table");
   11183         return BAD_TYPE;
   11184     }
   11185 
   11186     rc = setRecordingHintValue(value);
   11187     if (rc != NO_ERROR) {
   11188         LOGE("Failed to update table");
   11189         return rc;
   11190     }
   11191 
   11192     if(m_bDISEnabled && (value==1)) {
   11193         LOGH("%d: Setting DIS value again!!");
   11194         setDISValue(VALUE_ENABLE);
   11195     }
   11196 
   11197     rc = commitSetBatch();
   11198     if (rc != NO_ERROR) {
   11199         LOGE("Failed to update recording hint");
   11200         return rc;
   11201     }
   11202 
   11203     return rc;
   11204 }
   11205 
   11206 /*===========================================================================
   11207  * FUNCTION   : setHistogram
   11208  *
   11209  * DESCRIPTION: set histogram
   11210  *
   11211  * PARAMETERS :
   11212  *   @enabled : if histogram is enabled
   11213  *
   11214  * RETURN     : int32_t type of status
   11215  *              NO_ERROR  -- success
   11216  *              none-zero failure code
   11217  *==========================================================================*/
   11218 int32_t QCameraParameters::setHistogram(bool enabled)
   11219 {
   11220     if(m_bHistogramEnabled == enabled) {
   11221         LOGH("histogram flag not changed, no ops here");
   11222         return NO_ERROR;
   11223     }
   11224 
   11225     // set parm for histogram
   11226     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   11227         LOGE("Failed to initialize group update table");
   11228         return BAD_TYPE;
   11229     }
   11230 
   11231     int32_t value = enabled ? 1 : 0;
   11232     int32_t rc = NO_ERROR;
   11233     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HISTOGRAM, value)) {
   11234         LOGE("Failed to update table");
   11235         return BAD_VALUE;
   11236     }
   11237 
   11238     rc = commitSetBatch();
   11239     if (rc != NO_ERROR) {
   11240         LOGE("Failed to set histogram");
   11241         return rc;
   11242     }
   11243 
   11244     m_bHistogramEnabled = enabled;
   11245 
   11246     LOGH("Histogram -> %s", m_bHistogramEnabled ? "Enabled" : "Disabled");
   11247 
   11248     return rc;
   11249 }
   11250 
   11251 /*===========================================================================
   11252  * FUNCTION   : setIntEvent
   11253  *
   11254  * DESCRIPTION: set setIntEvent
   11255  *
   11256  * PARAMETERS :
   11257  *   @params : image size and dimensions
   11258  *
   11259  * RETURN     : int32_t type of status
   11260  *              NO_ERROR  -- success
   11261  *              none-zero failure code
   11262  *==========================================================================*/
   11263 int32_t QCameraParameters::setIntEvent(cam_int_evt_params_t params)
   11264 {
   11265     int32_t rc = NO_ERROR;
   11266 
   11267     if ( m_pParamBuf == NULL ) {
   11268         return NO_INIT;
   11269     }
   11270 
   11271     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   11272         LOGE("Failed to initialize group update table");
   11273         return BAD_TYPE;
   11274     }
   11275 
   11276     //Sending snapshot taken notification back to Eztune"
   11277     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_INT_EVT, params)) {
   11278         LOGE("Failed to update table");
   11279         return BAD_VALUE;
   11280     }
   11281 
   11282     rc = commitSetBatch();
   11283     if (rc != NO_ERROR) {
   11284         LOGE("Failed to set frameskip info parm");
   11285         return rc;
   11286     }
   11287 
   11288     return rc;
   11289 }
   11290 
   11291 /*===========================================================================
   11292  * FUNCTION   : setFaceDetectionOption
   11293  *
   11294  * DESCRIPTION: set if face detection is enabled by SendCommand
   11295  *
   11296  * PARAMETERS :
   11297  *   @enabled : bool flag if face detection should be enabled
   11298  *
   11299  * RETURN     : int32_t type of status
   11300  *              NO_ERROR  -- success
   11301  *              none-zero failure code
   11302  *==========================================================================*/
   11303  int32_t QCameraParameters::setFaceDetectionOption(bool enabled)
   11304 {
   11305     m_bFaceDetectionOn = enabled;
   11306     return NO_ERROR;
   11307 }
   11308 
   11309 /*===========================================================================
   11310  * FUNCTION   : setFaceDetection
   11311  *
   11312  * DESCRIPTION: set face detection
   11313  *
   11314  * PARAMETERS :
   11315  *   @enabled : if face detection is enabled
   11316  *   @initCommit : if configuration list need to be initialized and commited
   11317  *
   11318  * RETURN     : int32_t type of status
   11319  *              NO_ERROR  -- success
   11320  *              none-zero failure code
   11321  *==========================================================================*/
   11322 int32_t QCameraParameters::setFaceDetection(bool enabled, bool initCommit)
   11323 {
   11324     uint32_t faceProcMask = m_nFaceProcMask;
   11325     // set face detection mask
   11326     if (enabled) {
   11327         faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
   11328         if (getRecordingHintValue() > 0) {
   11329             faceProcMask = 0;
   11330             faceProcMask |= CAM_FACE_PROCESS_MASK_FOCUS;
   11331             if (fdModeInVideo() == CAM_FACE_PROCESS_MASK_DETECTION) {
   11332                 faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
   11333             }
   11334         } else {
   11335             faceProcMask |= CAM_FACE_PROCESS_MASK_FOCUS;
   11336             faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
   11337         }
   11338         if (isTruePortraitEnabled()) {
   11339             LOGL("QCameraParameters::setFaceDetection trueportrait enabled");
   11340             faceProcMask |= CAM_FACE_PROCESS_MASK_GAZE;
   11341         } else {
   11342             LOGL("QCameraParameters::setFaceDetection trueportrait disabled");
   11343             faceProcMask &= ~CAM_FACE_PROCESS_MASK_GAZE;
   11344         }
   11345     } else {
   11346         faceProcMask &= ~(CAM_FACE_PROCESS_MASK_DETECTION
   11347                 | CAM_FACE_PROCESS_MASK_FOCUS
   11348                 | CAM_FACE_PROCESS_MASK_GAZE);
   11349     }
   11350 
   11351     if(m_nFaceProcMask == faceProcMask) {
   11352         LOGH("face process mask not changed, no ops here");
   11353         return NO_ERROR;
   11354     }
   11355 
   11356     m_nFaceProcMask = faceProcMask;
   11357 
   11358     // set parm for face detection
   11359     uint32_t requested_faces = (uint32_t)getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
   11360     cam_fd_set_parm_t fd_set_parm;
   11361     memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
   11362     fd_set_parm.fd_mode = faceProcMask;
   11363     fd_set_parm.num_fd = requested_faces;
   11364 
   11365     LOGH("[KPI Perf]: PROFILE_FACE_DETECTION_VALUE = %d num_fd = %d",
   11366            faceProcMask,requested_faces);
   11367 
   11368     if (initCommit) {
   11369         if(initBatchUpdate(m_pParamBuf) < 0 ) {
   11370             LOGE("Failed to initialize group update table");
   11371             return BAD_TYPE;
   11372         }
   11373     }
   11374 
   11375     int32_t rc = NO_ERROR;
   11376 
   11377     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FD, fd_set_parm)) {
   11378         LOGE("Failed to update table");
   11379         return BAD_VALUE;
   11380     }
   11381 
   11382     if (initCommit) {
   11383         rc = commitSetBatch();
   11384         if (rc != NO_ERROR) {
   11385             LOGE("Failed to set face detection parm");
   11386             return rc;
   11387         }
   11388     }
   11389 
   11390     LOGH("FaceProcMask -> %d", m_nFaceProcMask);
   11391 
   11392     return rc;
   11393 }
   11394 
   11395 /*===========================================================================
   11396  * FUNCTION   : setFrameSkip
   11397  *
   11398  * DESCRIPTION: send ISP frame skip pattern to camera daemon
   11399  *
   11400  * PARAMETERS :
   11401  *   @pattern : skip pattern for ISP
   11402  *
   11403  * RETURN     : int32_t type of status
   11404  *              NO_ERROR  -- success
   11405  *              none-zero failure code
   11406  *==========================================================================*/
   11407 int32_t QCameraParameters::setFrameSkip(enum msm_vfe_frame_skip_pattern pattern)
   11408 {
   11409     int32_t rc = NO_ERROR;
   11410 
   11411     if ( m_pParamBuf == NULL ) {
   11412         return NO_INIT;
   11413     }
   11414 
   11415     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   11416         LOGE("Failed to initialize group update table");
   11417         return BAD_TYPE;
   11418     }
   11419 
   11420     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FRAMESKIP, (int32_t)pattern)) {
   11421         LOGE("Failed to update table");
   11422         return BAD_VALUE;
   11423     }
   11424 
   11425     rc = commitSetBatch();
   11426     if (rc != NO_ERROR) {
   11427         LOGE("Failed to set frameskip info parm");
   11428         return rc;
   11429     }
   11430 
   11431     return rc;
   11432 }
   11433 
   11434 /*===========================================================================
   11435  * FUNCTION   : updateRAW
   11436  *
   11437  * DESCRIPTION: Query sensor output size based on maximum stream dimension
   11438  *
   11439  * PARAMETERS :
   11440  *   @max_dim : maximum stream dimension
   11441  *
   11442  * RETURN     : int32_t type of status
   11443  *              NO_ERROR  -- success
   11444  *              none-zero failure code
   11445  *==========================================================================*/
   11446 int32_t QCameraParameters::updateRAW(cam_dimension_t max_dim)
   11447 {
   11448     int32_t rc = NO_ERROR;
   11449     cam_dimension_t raw_dim, pic_dim;
   11450 
   11451     // If offline raw is enabled, check the dimensions from Picture size since snapshot
   11452     // stream is not added but final JPEG is required of snapshot size
   11453     if (getofflineRAW()) {
   11454         getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT, pic_dim);
   11455         if (pic_dim.width > max_dim.width) {
   11456             max_dim.width = pic_dim.width;
   11457         }
   11458         if (pic_dim.height > max_dim.height) {
   11459             max_dim.height = pic_dim.height;
   11460         }
   11461     }
   11462 
   11463     if (max_dim.width == 0 || max_dim.height == 0) {
   11464         max_dim = m_pCapability->raw_dim[0];
   11465     }
   11466 
   11467     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   11468         LOGE("Failed to initialize group update table");
   11469         return BAD_TYPE;
   11470     }
   11471 
   11472     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MAX_DIMENSION, max_dim)) {
   11473         LOGE("Failed to update table for CAM_INTF_PARM_MAX_DIMENSION ");
   11474         return BAD_VALUE;
   11475     }
   11476 
   11477     rc = commitSetBatch();
   11478     if (rc != NO_ERROR) {
   11479         LOGE("Failed to set lock CAM_INTF_PARM_MAX_DIMENSION parm");
   11480         return rc;
   11481     }
   11482 
   11483     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   11484         LOGE("Failed to initialize group update table");
   11485         return BAD_TYPE;
   11486     }
   11487 
   11488     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RAW_DIMENSION);
   11489 
   11490     rc = commitGetBatch();
   11491     if (rc != NO_ERROR) {
   11492         LOGE("Failed to get commit CAM_INTF_PARM_RAW_DIMENSION");
   11493         return rc;
   11494     }
   11495 
   11496     READ_PARAM_ENTRY(m_pParamBuf, CAM_INTF_PARM_RAW_DIMENSION, raw_dim);
   11497 
   11498     LOGH("RAW Dimension = %d X %d",raw_dim.width,raw_dim.height);
   11499     if (raw_dim.width == 0 || raw_dim.height == 0) {
   11500         LOGW("Error getting RAW size. Setting to Capability value");
   11501         raw_dim = m_pCapability->raw_dim[0];
   11502     }
   11503     setRawSize(raw_dim);
   11504     return rc;
   11505 }
   11506 
   11507 /*===========================================================================
   11508  * FUNCTION   : setHDRSceneEnable
   11509  *
   11510  * DESCRIPTION: sets hdr scene deteced flag
   11511  *
   11512  * PARAMETERS :
   11513  *   @bflag : hdr scene deteced
   11514  *
   11515  * RETURN     : nothing
   11516  *==========================================================================*/
   11517 void QCameraParameters::setHDRSceneEnable(bool bflag)
   11518 {
   11519     bool bupdate = false;
   11520     if (m_HDRSceneEnabled != bflag) {
   11521         bupdate = true;
   11522     }
   11523     m_HDRSceneEnabled = bflag;
   11524 
   11525     if (bupdate) {
   11526         updateFlash(true);
   11527     }
   11528 }
   11529 
   11530 /*===========================================================================
   11531  * FUNCTION   : getASDStateString
   11532  *
   11533  * DESCRIPTION: get ASD result in string format
   11534  *
   11535  * PARAMETERS :
   11536  *   @scene : selected scene mode
   11537  *
   11538  * RETURN     : int32_t type of status
   11539  *              NO_ERROR  -- success
   11540  *              none-zero failure code
   11541  *==========================================================================*/
   11542  const char *QCameraParameters::getASDStateString(cam_auto_scene_t scene)
   11543 {
   11544     switch (scene) {
   11545       case S_NORMAL :
   11546         return "Normal";
   11547       case S_SCENERY:
   11548         return "Scenery";
   11549       case S_PORTRAIT:
   11550         return "Portrait";
   11551       case S_PORTRAIT_BACKLIGHT:
   11552         return "Portrait-Backlight";
   11553       case S_SCENERY_BACKLIGHT:
   11554         return "Scenery-Backlight";
   11555       case S_BACKLIGHT:
   11556         return "Backlight";
   11557       default:
   11558         return "<Unknown!>";
   11559       }
   11560 }
   11561 
   11562 /*===========================================================================
   11563  * FUNCTION   : parseNDimVector
   11564  *
   11565  * DESCRIPTION: helper function to parse a string like "(1, 2, 3, 4, ..., N)"
   11566  *              into N-dimension vector
   11567  *
   11568  * PARAMETERS :
   11569  *   @str     : string to be parsed
   11570  *   @num     : output array of size N to store vector element values
   11571  *   @N       : number of dimension
   11572  *   @delim   : delimeter to seperete string
   11573  *
   11574  * RETURN     : int32_t type of status
   11575  *              NO_ERROR  -- success
   11576  *              none-zero failure code
   11577  *==========================================================================*/
   11578 int32_t QCameraParameters::parseNDimVector(const char *str, int *num, int N, char delim = ',')
   11579 {
   11580     char *start, *end;
   11581     if (num == NULL) {
   11582         LOGE("Invalid output array (num == NULL)");
   11583         return BAD_VALUE;
   11584     }
   11585 
   11586     //check if string starts and ends with parantheses
   11587     if(str[0] != '(' || str[strlen(str)-1] != ')') {
   11588         LOGE("Invalid format of string %s, valid format is (n1, n2, n3, n4 ...)",
   11589                str);
   11590         return BAD_VALUE;
   11591     }
   11592     start = (char*) str;
   11593     start++;
   11594     for(int i=0; i<N; i++) {
   11595         *(num+i) = (int) strtol(start, &end, 10);
   11596         if(*end != delim && i < N-1) {
   11597             LOGE("Cannot find delimeter '%c' in string \"%s\". end = %c",
   11598                    delim, str, *end);
   11599             return -1;
   11600         }
   11601         start = end+1;
   11602     }
   11603     return NO_ERROR;
   11604 }
   11605 
   11606 /*===========================================================================
   11607  * FUNCTION   : parseCameraAreaString
   11608  *
   11609  * DESCRIPTION: helper function to parse a string of camera areas like
   11610  *              "(1, 2, 3, 4, 5),(1, 2, 3, 4, 5),..."
   11611  *
   11612  * PARAMETERS :
   11613  *   @str             : string to be parsed
   11614  *   @max_num_areas   : max number of areas
   11615  *   @pAreas          : ptr to struct to store areas
   11616  *   @num_areas_found : number of areas found
   11617  *
   11618  * RETURN     : int32_t type of status
   11619  *              NO_ERROR  -- success
   11620  *              none-zero failure code
   11621  *==========================================================================*/
   11622 int32_t QCameraParameters::parseCameraAreaString(const char *str,
   11623                                                  int max_num_areas,
   11624                                                  cam_area_t *pAreas,
   11625                                                  int& num_areas_found)
   11626 {
   11627     char area_str[32];
   11628     const char *start, *end, *p;
   11629     start = str; end = NULL;
   11630     int values[5], index=0;
   11631     num_areas_found = 0;
   11632 
   11633     memset(values, 0, sizeof(values));
   11634     while(start != NULL) {
   11635        if(*start != '(') {
   11636             LOGE("error: Ill formatted area string: %s", str);
   11637             return BAD_VALUE;
   11638        }
   11639        end = strchr(start, ')');
   11640        if(end == NULL) {
   11641             LOGE("error: Ill formatted area string: %s", str);
   11642             return BAD_VALUE;
   11643        }
   11644        int i;
   11645        for (i=0,p=start; p<=end; p++, i++) {
   11646            area_str[i] = *p;
   11647        }
   11648        area_str[i] = '\0';
   11649        if(parseNDimVector(area_str, values, 5) < 0){
   11650             LOGE("error: Failed to parse the area string: %s", area_str);
   11651             return BAD_VALUE;
   11652        }
   11653        // no more areas than max_num_areas are accepted.
   11654        if(index >= max_num_areas) {
   11655             LOGE("error: too many areas specified %s", str);
   11656             return BAD_VALUE;
   11657        }
   11658        pAreas[index].rect.left = values[0];
   11659        pAreas[index].rect.top = values[1];
   11660        pAreas[index].rect.width = values[2] - values[0];
   11661        pAreas[index].rect.height = values[3] - values[1];
   11662        pAreas[index].weight = values[4];
   11663 
   11664        index++;
   11665        start = strchr(end, '('); // serach for next '('
   11666     }
   11667     num_areas_found = index;
   11668     return 0;
   11669 }
   11670 
   11671 /*===========================================================================
   11672  * FUNCTION   : validateCameraAreas
   11673  *
   11674  * DESCRIPTION: helper function to validate camera areas within (-1000, 1000)
   11675  *
   11676  * PARAMETERS :
   11677  *   @areas     : ptr to array of areas
   11678  *   @num_areas : number of areas
   11679  *
   11680  * RETURN     : true --  area is in valid range
   11681  *              false -- not valid
   11682  *==========================================================================*/
   11683 bool QCameraParameters::validateCameraAreas(cam_area_t *areas, int num_areas)
   11684 {
   11685     // special case: default area
   11686     if (num_areas == 1 &&
   11687         areas[0].rect.left == 0 &&
   11688         areas[0].rect.top == 0 &&
   11689         areas[0].rect.width == 0 &&
   11690         areas[0].rect.height == 0 &&
   11691         areas[0].weight == 0) {
   11692         return true;
   11693     }
   11694 
   11695     for(int i = 0; i < num_areas; i++) {
   11696         // left should be >= -1000
   11697         if(areas[i].rect.left < -1000) {
   11698             return false;
   11699         }
   11700 
   11701         // top  should be >= -1000
   11702         if(areas[i].rect.top < -1000) {
   11703             return false;
   11704         }
   11705 
   11706         // width or height should be > 0
   11707         if (areas[i].rect.width <= 0 || areas[i].rect.height <= 0) {
   11708             return false;
   11709         }
   11710 
   11711         // right  should be <= 1000
   11712         if(areas[i].rect.left + areas[i].rect.width > 1000) {
   11713             return false;
   11714         }
   11715 
   11716         // bottom should be <= 1000
   11717         if(areas[i].rect.top + areas[i].rect.height > 1000) {
   11718             return false;
   11719         }
   11720 
   11721         // weight should be within (1, 1000)
   11722         if (areas[i].weight < 1 || areas[i].weight > 1000) {
   11723             return false;
   11724         }
   11725     }
   11726     return true;
   11727 }
   11728 
   11729 /*===========================================================================
   11730  * FUNCTION   : isYUVFrameInfoNeeded
   11731  *
   11732  * DESCRIPTION: In AE-Bracket mode, we need set yuv buffer information for up-layer
   11733  *
   11734  * PARAMETERS : none
   11735  *
   11736  * RETURN     : true: needed
   11737  *              false: no need
   11738  *==========================================================================*/
   11739 bool QCameraParameters::isYUVFrameInfoNeeded()
   11740 {
   11741     //In AE-Bracket mode, we need set raw buffer information for up-layer
   11742     if(!isNV21PictureFormat() && !isNV16PictureFormat()){
   11743         return false;
   11744     }
   11745     const char *aecBracketStr =  get(KEY_QC_AE_BRACKET_HDR);
   11746 
   11747     int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
   11748             aecBracketStr);
   11749     LOGH("aecBracketStr=%s, value=%d.", aecBracketStr, value);
   11750     return (value == CAM_EXP_BRACKETING_ON);
   11751 }
   11752 
   11753 /*===========================================================================
   11754  * FUNCTION   : getFrameFmtString
   11755  *
   11756  * DESCRIPTION: get string name of frame format
   11757  *
   11758  * PARAMETERS :
   11759  *   @frame   : frame format
   11760  *
   11761  * RETURN     : string name of frame format
   11762  *==========================================================================*/
   11763 const char *QCameraParameters::getFrameFmtString(cam_format_t fmt)
   11764 {
   11765     return lookupNameByValue(PICTURE_TYPES_MAP, PARAM_MAP_SIZE(PICTURE_TYPES_MAP), fmt);
   11766 }
   11767 
   11768 /*===========================================================================
   11769  * FUNCTION   : setDcrf
   11770  *
   11771  * DESCRIPTION: Enable/Disable DCRF (dual-camera-range-finding)
   11772  *
   11773  * RETURN     : none
   11774  *==========================================================================*/
   11775 void QCameraParameters::setDcrf()
   11776 {
   11777     char prop[PROPERTY_VALUE_MAX];
   11778     memset(prop, 0, sizeof(prop));
   11779 
   11780     // Set DCRF to off by default (assuming single-camera mode)
   11781     m_bDcrfEnabled = 0;
   11782 
   11783     // In dual-cam mode, get sysprop and set it to on by default
   11784     if(m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
   11785         property_get("persist.camera.dcrf.enable", prop, "1");
   11786         m_bDcrfEnabled = atoi(prop);
   11787     }
   11788 }
   11789 
   11790 /*===========================================================================
   11791  * FUNCTION   : setRelatedCamSyncInfo
   11792  *
   11793  * DESCRIPTION: set the related cam info parameters
   11794  * the related cam info is cached into params to make some decisions beforehand
   11795  *
   11796  * PARAMETERS :
   11797  *   @info  : ptr to related cam info parameters
   11798  *
   11799  * RETURN     : int32_t type of status
   11800  *              NO_ERROR  -- success
   11801  *              none-zero failure code
   11802  *==========================================================================*/
   11803 int32_t QCameraParameters::setRelatedCamSyncInfo(
   11804         cam_sync_related_sensors_event_info_t* info)
   11805 {
   11806     if(info != NULL){
   11807         memcpy(&m_relCamSyncInfo, info,
   11808                 sizeof(cam_sync_related_sensors_event_info_t));
   11809         return NO_ERROR;
   11810     } else {
   11811         LOGE("info buffer is null");
   11812         return UNKNOWN_ERROR;
   11813     }
   11814 }
   11815 
   11816 /*===========================================================================
   11817  * FUNCTION   : getRelatedCamSyncInfo
   11818  *
   11819  * DESCRIPTION:returns the related cam sync info for this HWI instance
   11820  *
   11821  * PARAMETERS :none
   11822  *
   11823  * RETURN     : const pointer to cam_sync_related_sensors_event_info_t
   11824  *==========================================================================*/
   11825 const cam_sync_related_sensors_event_info_t*
   11826         QCameraParameters::getRelatedCamSyncInfo(void)
   11827 {
   11828     return &m_relCamSyncInfo;
   11829 }
   11830 
   11831 /*===========================================================================
   11832  * FUNCTION   : setFrameSyncEnabled
   11833  *
   11834  * DESCRIPTION: sets whether frame sync is enabled
   11835  *
   11836  * PARAMETERS :
   11837  *   @enable  : flag whether to enable or disable frame sync
   11838  *
   11839  * RETURN     : int32_t type of status
   11840  *              NO_ERROR  -- success
   11841  *              none-zero failure code
   11842  *==========================================================================*/
   11843 int32_t QCameraParameters::setFrameSyncEnabled(bool enable)
   11844 {
   11845     m_bFrameSyncEnabled = enable;
   11846     return NO_ERROR;
   11847 }
   11848 
   11849 /*===========================================================================
   11850  * FUNCTION   : isFrameSyncEnabled
   11851  *
   11852  * DESCRIPTION: returns whether frame sync is enabled
   11853  *
   11854  * PARAMETERS :none
   11855  *
   11856  * RETURN     : bool indicating whether frame sync is enabled
   11857  *==========================================================================*/
   11858 bool QCameraParameters::isFrameSyncEnabled(void)
   11859 {
   11860     return m_bFrameSyncEnabled;
   11861 }
   11862 
   11863 /*===========================================================================
   11864  * FUNCTION   : bundleRelatedCameras
   11865  *
   11866  * DESCRIPTION: send trigger for bundling related camera sessions in the server
   11867  *
   11868  * PARAMETERS :
   11869  *   @sync        :indicates whether syncing is On or Off
   11870  *   @sessionid  :session id for other camera session
   11871  *
   11872  * RETURN     : int32_t type of status
   11873  *              NO_ERROR  -- success
   11874  *              none-zero failure code
   11875  *==========================================================================*/
   11876 int32_t QCameraParameters::bundleRelatedCameras(bool sync,
   11877         uint32_t sessionid)
   11878 {
   11879     int32_t rc = NO_ERROR;
   11880 
   11881     if (NULL == m_pCamOpsTbl) {
   11882         LOGE("Ops not initialized");
   11883         return NO_INIT;
   11884     }
   11885 
   11886     LOGD("Sending Bundling cmd sync %d, SessionId %d ",
   11887             sync, sessionid);
   11888 
   11889     if(m_pRelCamSyncBuf) {
   11890         if(sync) {
   11891             m_pRelCamSyncBuf->sync_control = CAM_SYNC_RELATED_SENSORS_ON;
   11892         }
   11893         else {
   11894             m_pRelCamSyncBuf->sync_control = CAM_SYNC_RELATED_SENSORS_OFF;
   11895         }
   11896         m_pRelCamSyncBuf->mode = m_relCamSyncInfo.mode;
   11897         m_pRelCamSyncBuf->type = m_relCamSyncInfo.type;
   11898         m_pRelCamSyncBuf->related_sensor_session_id = sessionid;
   11899         rc = m_pCamOpsTbl->ops->sync_related_sensors(
   11900                 m_pCamOpsTbl->camera_handle, m_pRelCamSyncBuf);
   11901     } else {
   11902         LOGE("Related Cam SyncBuffer not allocated", rc);
   11903         return NO_INIT;
   11904     }
   11905 
   11906     return rc;
   11907 }
   11908 
   11909 /*===========================================================================
   11910  * FUNCTION   : getRelatedCamCalibration
   11911  *
   11912  * DESCRIPTION: fetch the related camera subsystem calibration data
   11913  *
   11914  * PARAMETERS :
   11915  *   @calib  : calibration data fetched
   11916  *
   11917  * RETURN     : int32_t type of status
   11918  *              NO_ERROR  -- success
   11919  *              none-zero failure code
   11920  *==========================================================================*/
   11921 int32_t QCameraParameters::getRelatedCamCalibration(
   11922         cam_related_system_calibration_data_t* calib)
   11923 {
   11924     int32_t rc = NO_ERROR;
   11925 
   11926     if(!calib) {
   11927         return BAD_TYPE;
   11928     }
   11929 
   11930     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   11931         LOGE("Failed to initialize group update table");
   11932         return BAD_TYPE;
   11933     }
   11934 
   11935     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   11936             CAM_INTF_PARM_RELATED_SENSORS_CALIBRATION);
   11937 
   11938     rc = commitGetBatch();
   11939     if (rc != NO_ERROR) {
   11940         LOGE("Failed to get related cam calibration info");
   11941         return rc;
   11942     }
   11943 
   11944     READ_PARAM_ENTRY(m_pParamBuf,
   11945             CAM_INTF_PARM_RELATED_SENSORS_CALIBRATION, *calib);
   11946 
   11947     LOGD("CALIB version %d ", calib->calibration_format_version);
   11948     LOGD("CALIB normalized_focal_length %f ",
   11949             calib->main_cam_specific_calibration.normalized_focal_length);
   11950     LOGD("CALIB native_sensor_resolution_width %d ",
   11951             calib->main_cam_specific_calibration.native_sensor_resolution_width);
   11952     LOGD("CALIB native_sensor_resolution_height %d ",
   11953             calib->main_cam_specific_calibration.native_sensor_resolution_height);
   11954     LOGD("CALIB sensor_resolution_width %d ",
   11955             calib->main_cam_specific_calibration.calibration_sensor_resolution_width);
   11956     LOGD("CALIB sensor_resolution_height %d ",
   11957             calib->main_cam_specific_calibration.calibration_sensor_resolution_height);
   11958     LOGD("CALIB focal_length_ratio %f ",
   11959             calib->main_cam_specific_calibration.focal_length_ratio);
   11960 
   11961     return rc;
   11962 }
   11963 
   11964 /*===========================================================================
   11965  * FUNCTION   : initBatchUpdate
   11966  *
   11967  * DESCRIPTION: init camera parameters buf entries
   11968  *
   11969  * PARAMETERS :
   11970  *   @p_table : ptr to parameter buffer
   11971  *
   11972  * RETURN     : int32_t type of status
   11973  *              NO_ERROR  -- success
   11974  *              none-zero failure code
   11975  *==========================================================================*/
   11976 int32_t QCameraParameters::initBatchUpdate(parm_buffer_t *p_table)
   11977 {
   11978     m_tempMap.clear();
   11979     clear_metadata_buffer(p_table);
   11980     return NO_ERROR;
   11981 }
   11982 
   11983 /*===========================================================================
   11984  * FUNCTION   : commitSetBatch
   11985  *
   11986  * DESCRIPTION: commit all set parameters in the batch work to backend
   11987  *
   11988  * PARAMETERS : none
   11989  *
   11990  * RETURN     : int32_t type of status
   11991  *              NO_ERROR  -- success
   11992  *              none-zero failure code
   11993  *==========================================================================*/
   11994 int32_t QCameraParameters::commitSetBatch()
   11995 {
   11996     int32_t rc = NO_ERROR;
   11997     int32_t i = 0;
   11998 
   11999     if (NULL == m_pParamBuf) {
   12000         LOGE("Params not initialized");
   12001         return NO_INIT;
   12002     }
   12003 
   12004     /* Loop to check if atleast one entry is valid */
   12005     for(i = 0; i < CAM_INTF_PARM_MAX; i++){
   12006         if(m_pParamBuf->is_valid[i])
   12007             break;
   12008     }
   12009 
   12010     if (NULL == m_pCamOpsTbl) {
   12011         LOGE("Ops not initialized");
   12012         return NO_INIT;
   12013     }
   12014 
   12015     if (i < CAM_INTF_PARM_MAX) {
   12016         rc = m_pCamOpsTbl->ops->set_parms(m_pCamOpsTbl->camera_handle, m_pParamBuf);
   12017     }
   12018     if (rc == NO_ERROR) {
   12019         // commit change from temp storage into param map
   12020         rc = commitParamChanges();
   12021     }
   12022     return rc;
   12023 }
   12024 
   12025 /*===========================================================================
   12026  * FUNCTION   : commitGetBatch
   12027  *
   12028  * DESCRIPTION: commit all get parameters in the batch work to backend
   12029  *
   12030  * PARAMETERS : none
   12031  *
   12032  * RETURN     : int32_t type of status
   12033  *              NO_ERROR  -- success
   12034  *              none-zero failure code
   12035  *==========================================================================*/
   12036 int32_t QCameraParameters::commitGetBatch()
   12037 {
   12038     int32_t rc = NO_ERROR;
   12039     int32_t i = 0;
   12040 
   12041     if (NULL == m_pParamBuf) {
   12042         LOGE("Params not initialized");
   12043         return NO_INIT;
   12044     }
   12045 
   12046     /* Loop to check if atleast one entry is valid */
   12047     for(i = 0; i < CAM_INTF_PARM_MAX; i++){
   12048         if(m_pParamBuf->is_valid[i])
   12049             break;
   12050     }
   12051 
   12052     if (NULL == m_pCamOpsTbl) {
   12053         LOGE("Ops not initialized");
   12054         return NO_INIT;
   12055     }
   12056 
   12057     if (i < CAM_INTF_PARM_MAX) {
   12058         return m_pCamOpsTbl->ops->get_parms(m_pCamOpsTbl->camera_handle, m_pParamBuf);
   12059     } else {
   12060         return NO_ERROR;
   12061     }
   12062     return rc;
   12063 }
   12064 
   12065 /*===========================================================================
   12066  * FUNCTION   : updateParamEntry
   12067  *
   12068  * DESCRIPTION: update a parameter entry in the local temp map obj
   12069  *
   12070  * PARAMETERS :
   12071  *   @key     : key of the entry
   12072  *   @value   : value of the entry
   12073  *
   12074  * RETURN     : int32_t type of status
   12075  *              NO_ERROR  -- success
   12076  *              none-zero failure code
   12077  *==========================================================================*/
   12078 int32_t QCameraParameters::updateParamEntry(const char *key, const char *value)
   12079 {
   12080     m_tempMap.replaceValueFor(String8(key), String8(value));
   12081     return NO_ERROR;
   12082 }
   12083 
   12084 /*===========================================================================
   12085  * FUNCTION   : commitParamChanges
   12086  *
   12087  * DESCRIPTION: commit all changes in local temp map obj into parameter obj
   12088  *
   12089  * PARAMETERS : none
   12090  *
   12091  * RETURN     : int32_t type of status
   12092  *              NO_ERROR  -- success
   12093  *              none-zero failure code
   12094  *==========================================================================*/
   12095 int32_t QCameraParameters::commitParamChanges()
   12096 {
   12097     size_t size = m_tempMap.size();
   12098     for (size_t i = 0; i < size; i++) {
   12099         String8 k, v;
   12100         k = m_tempMap.keyAt(i);
   12101         v = m_tempMap.valueAt(i);
   12102         set(k, v);
   12103     }
   12104     m_tempMap.clear();
   12105 
   12106     // update local changes
   12107     m_bRecordingHint = m_bRecordingHint_new;
   12108     m_bZslMode = m_bZslMode_new;
   12109 
   12110     /* After applying scene mode auto,
   12111       Camera effects need to be reapplied */
   12112     if ( m_bSceneTransitionAuto ) {
   12113         m_bUpdateEffects = true;
   12114         m_bSceneTransitionAuto = false;
   12115     }
   12116 
   12117 
   12118     return NO_ERROR;
   12119 }
   12120 
   12121 /*===========================================================================
   12122  * FUNCTION   : QCameraReprocScaleParam
   12123  *
   12124  * DESCRIPTION: constructor of QCameraReprocScaleParam
   12125  *
   12126  * PARAMETERS : none
   12127  *
   12128  * RETURN     : none
   12129  *==========================================================================*/
   12130 QCameraParameters::QCameraReprocScaleParam::QCameraReprocScaleParam()
   12131   : mScaleEnabled(false),
   12132     mIsUnderScaling(false),
   12133     mNeedScaleCnt(0),
   12134     mSensorSizeTblCnt(0),
   12135     mSensorSizeTbl(NULL),
   12136     mTotalSizeTblCnt(0)
   12137 {
   12138     mPicSizeFromAPK.width = 0;
   12139     mPicSizeFromAPK.height = 0;
   12140     mPicSizeSetted.width = 0;
   12141     mPicSizeSetted.height = 0;
   12142     memset(mNeedScaledSizeTbl, 0, sizeof(mNeedScaledSizeTbl));
   12143     memset(mTotalSizeTbl, 0, sizeof(mTotalSizeTbl));
   12144 }
   12145 
   12146 /*===========================================================================
   12147  * FUNCTION   : ~~QCameraReprocScaleParam
   12148  *
   12149  * DESCRIPTION: destructor of QCameraReprocScaleParam
   12150  *
   12151  * PARAMETERS : none
   12152  *
   12153  * RETURN     : none
   12154  *==========================================================================*/
   12155 QCameraParameters::QCameraReprocScaleParam::~QCameraReprocScaleParam()
   12156 {
   12157     //do nothing now.
   12158 }
   12159 
   12160 /*===========================================================================
   12161  * FUNCTION   : setScaledSizeTbl
   12162  *
   12163  * DESCRIPTION: re-set picture size table with dimensions that need scaling if Reproc Scale is enabled
   12164  *
   12165  * PARAMETERS :
   12166  *   @scale_cnt   : count of picture sizes that want scale
   12167  *   @scale_tbl    : picture size table that want scale
   12168  *   @org_cnt     : sensor supported picture size count
   12169  *   @org_tbl      : sensor supported picture size table
   12170  *
   12171  * RETURN     : int32_t type of status
   12172  *              NO_ERROR  -- success
   12173  *              none-zero failure code
   12174  *==========================================================================*/
   12175 int32_t QCameraParameters::QCameraReprocScaleParam::setScaleSizeTbl(size_t scale_cnt,
   12176         cam_dimension_t *scale_tbl, size_t org_cnt, cam_dimension_t *org_tbl)
   12177 {
   12178     int32_t rc = NO_ERROR;
   12179     size_t i;
   12180     mNeedScaleCnt = 0;
   12181 
   12182     if(!mScaleEnabled || scale_cnt <=0 || scale_tbl == NULL || org_cnt <=0 || org_tbl == NULL){
   12183         return BAD_VALUE;    // Do not need scale, so also need not reset picture size table
   12184     }
   12185 
   12186     mSensorSizeTblCnt = org_cnt;
   12187     mSensorSizeTbl = org_tbl;
   12188     mNeedScaleCnt = checkScaleSizeTable(scale_cnt, scale_tbl, org_cnt, org_tbl);
   12189     if(mNeedScaleCnt <= 0){
   12190         LOGE("do not have picture sizes need scaling.");
   12191         return BAD_VALUE;
   12192     }
   12193 
   12194     if(mNeedScaleCnt + org_cnt > MAX_SIZES_CNT){
   12195         LOGE("picture size list exceed the max count.");
   12196         return BAD_VALUE;
   12197     }
   12198 
   12199     //get the total picture size table
   12200     mTotalSizeTblCnt = mNeedScaleCnt + org_cnt;
   12201 
   12202     if (mNeedScaleCnt > MAX_SCALE_SIZES_CNT) {
   12203         LOGE("Error!! mNeedScaleCnt (%d) is more than MAX_SCALE_SIZES_CNT",
   12204                  mNeedScaleCnt);
   12205         return BAD_VALUE;
   12206     }
   12207 
   12208     for(i = 0; i < mNeedScaleCnt; i++){
   12209         mTotalSizeTbl[i].width = mNeedScaledSizeTbl[i].width;
   12210         mTotalSizeTbl[i].height = mNeedScaledSizeTbl[i].height;
   12211         LOGH("scale picture size: i =%d, width=%d, height=%d.",
   12212             i, mTotalSizeTbl[i].width, mTotalSizeTbl[i].height);
   12213     }
   12214     for(; i < mTotalSizeTblCnt; i++){
   12215         mTotalSizeTbl[i].width = org_tbl[i-mNeedScaleCnt].width;
   12216         mTotalSizeTbl[i].height = org_tbl[i-mNeedScaleCnt].height;
   12217         LOGH("sensor supportted picture size: i =%d, width=%d, height=%d.",
   12218             i, mTotalSizeTbl[i].width, mTotalSizeTbl[i].height);
   12219     }
   12220     return rc;
   12221 }
   12222 
   12223 /*===========================================================================
   12224  * FUNCTION   : getScaledSizeTblCnt
   12225  *
   12226  * DESCRIPTION: get picture size cnt that need scale
   12227  *
   12228  * PARAMETERS : none
   12229  *
   12230  * RETURN     : uint8_t type of picture size count
   12231  *==========================================================================*/
   12232 size_t QCameraParameters::QCameraReprocScaleParam::getScaleSizeTblCnt()
   12233 {
   12234     return mNeedScaleCnt;
   12235 }
   12236 
   12237 /*===========================================================================
   12238  * FUNCTION   : getScaledSizeTbl
   12239  *
   12240  * DESCRIPTION: get picture size table that need scale
   12241  *
   12242  * PARAMETERS :  none
   12243  *
   12244  * RETURN     : cam_dimension_t list of picture size table
   12245  *==========================================================================*/
   12246 cam_dimension_t *QCameraParameters::QCameraReprocScaleParam::getScaledSizeTbl()
   12247 {
   12248     if(!mScaleEnabled)
   12249         return NULL;
   12250 
   12251     return mNeedScaledSizeTbl;
   12252 }
   12253 
   12254 /*===========================================================================
   12255  * FUNCTION   : setScaleEnable
   12256  *
   12257  * DESCRIPTION: enable or disable Reproc Scale
   12258  *
   12259  * PARAMETERS :
   12260  *   @enabled : enable: 1; disable 0
   12261  *
   12262  * RETURN     : none
   12263  *==========================================================================*/
   12264 void QCameraParameters::QCameraReprocScaleParam::setScaleEnable(bool enabled)
   12265 {
   12266     mScaleEnabled = enabled;
   12267 }
   12268 
   12269 /*===========================================================================
   12270  * FUNCTION   : isScaleEnabled
   12271  *
   12272  * DESCRIPTION: check if Reproc Scale is enabled
   12273  *
   12274  * PARAMETERS :  none
   12275  *
   12276  * RETURN     : bool type of status
   12277  *==========================================================================*/
   12278 bool QCameraParameters::QCameraReprocScaleParam::isScaleEnabled()
   12279 {
   12280     return mScaleEnabled;
   12281 }
   12282 
   12283 /*===========================================================================
   12284  * FUNCTION   : isScalePicSize
   12285  *
   12286  * DESCRIPTION: check if current picture size is from Scale Table
   12287  *
   12288  * PARAMETERS :
   12289  *   @width     : current picture width
   12290  *   @height    : current picture height
   12291  *
   12292  * RETURN     : bool type of status
   12293  *==========================================================================*/
   12294 bool QCameraParameters::QCameraReprocScaleParam::isScalePicSize(int width, int height)
   12295 {
   12296     //Check if the picture size is in scale table
   12297     if(mNeedScaleCnt <= 0)
   12298         return FALSE;
   12299 
   12300     for (size_t i = 0; i < mNeedScaleCnt; i++) {
   12301         if ((mNeedScaledSizeTbl[i].width == width) && (mNeedScaledSizeTbl[i].height == height)) {
   12302             //found match
   12303             return TRUE;
   12304         }
   12305     }
   12306 
   12307     LOGE("Not in scale picture size table.");
   12308     return FALSE;
   12309 }
   12310 
   12311 /*===========================================================================
   12312  * FUNCTION   : isValidatePicSize
   12313  *
   12314  * DESCRIPTION: check if current picture size is validate
   12315  *
   12316  * PARAMETERS :
   12317  *   @width     : current picture width
   12318  *   @height    : current picture height
   12319  *
   12320  * RETURN     : bool type of status
   12321  *==========================================================================*/
   12322 bool QCameraParameters::QCameraReprocScaleParam::isValidatePicSize(int width, int height)
   12323 {
   12324     size_t i = 0;
   12325 
   12326     for(i = 0; i < mSensorSizeTblCnt; i++){
   12327         if(mSensorSizeTbl[i].width == width
   12328             && mSensorSizeTbl[i].height== height){
   12329             return TRUE;
   12330         }
   12331     }
   12332 
   12333     for(i = 0; i < mNeedScaleCnt; i++){
   12334         if(mNeedScaledSizeTbl[i].width == width
   12335             && mNeedScaledSizeTbl[i].height== height){
   12336             return TRUE;
   12337         }
   12338     }
   12339 
   12340     LOGE("Invalidate input picture size.");
   12341     return FALSE;
   12342 }
   12343 
   12344 /*===========================================================================
   12345  * FUNCTION   : setSensorSupportedPicSize
   12346  *
   12347  * DESCRIPTION: set sensor supported picture size.
   12348  *    For Snapshot stream size configuration, we need use sensor supported size.
   12349  *    We will use CPP to do Scaling based on output Snapshot stream.
   12350  *
   12351  * PARAMETERS : none
   12352  *
   12353  * RETURN     : int32_t type of status
   12354  *              NO_ERROR  -- success
   12355  *              none-zero failure code
   12356  *==========================================================================*/
   12357 int32_t QCameraParameters::QCameraReprocScaleParam::setSensorSupportedPicSize()
   12358 {
   12359     //will find a suitable picture size (here we leave a prossibility to add other scale requirement)
   12360     //Currently we only focus on upscaling, and checkScaleSizeTable() has guaranteed the dimension ratio.
   12361 
   12362     if(!mIsUnderScaling || mSensorSizeTblCnt <= 0)
   12363         return BAD_VALUE;
   12364 
   12365     //We just get the max sensor supported size here.
   12366     mPicSizeSetted.width = mSensorSizeTbl[0].width;
   12367     mPicSizeSetted.height = mSensorSizeTbl[0].height;
   12368 
   12369     return NO_ERROR;
   12370 }
   12371 
   12372 
   12373 /*===========================================================================
   12374  * FUNCTION   : setValidatePicSize
   12375  *
   12376  * DESCRIPTION: set sensor supported size and change scale status.
   12377  *
   12378  * PARAMETERS :
   12379  *   @width    : input picture width
   12380  *   @height   : input picture height
   12381  *
   12382  * RETURN     : int32_t type of status
   12383  *              NO_ERROR  -- success
   12384  *              none-zero failure code
   12385  *==========================================================================*/
   12386 int32_t QCameraParameters::QCameraReprocScaleParam::setValidatePicSize(int &width,int &height)
   12387 {
   12388     if(!mScaleEnabled)
   12389         return BAD_VALUE;
   12390 
   12391     mIsUnderScaling = FALSE; //default: not under scale
   12392 
   12393     if(isScalePicSize(width, height)){
   12394         // input picture size need scaling operation. Record size from APK and setted
   12395         mIsUnderScaling = TRUE;
   12396         mPicSizeFromAPK.width = width;
   12397         mPicSizeFromAPK.height = height;
   12398 
   12399         if(setSensorSupportedPicSize() != NO_ERROR)
   12400             return BAD_VALUE;
   12401 
   12402         //re-set picture size to sensor supported size
   12403         width = mPicSizeSetted.width;
   12404         height = mPicSizeSetted.height;
   12405         LOGH("mPicSizeFromAPK- with=%d, height=%d, mPicSizeSetted- with =%d, height=%d.",
   12406              mPicSizeFromAPK.width, mPicSizeFromAPK.height, mPicSizeSetted.width, mPicSizeSetted.height);
   12407     }else{
   12408         mIsUnderScaling = FALSE;
   12409         //no scale is needed for input picture size
   12410         if(!isValidatePicSize(width, height)){
   12411             LOGE("invalidate input picture size.");
   12412             return BAD_VALUE;
   12413         }
   12414         mPicSizeSetted.width = width;
   12415         mPicSizeSetted.height = height;
   12416     }
   12417 
   12418     LOGH("X. mIsUnderScaling=%d, width=%d, height=%d.", mIsUnderScaling, width, height);
   12419     return NO_ERROR;
   12420 }
   12421 
   12422 /*===========================================================================
   12423  * FUNCTION   : getPicSizeFromAPK
   12424  *
   12425  * DESCRIPTION: get picture size that get from APK
   12426  *
   12427  * PARAMETERS :
   12428  *   @width     : input width
   12429  *   @height    : input height
   12430  *
   12431  * RETURN     : int32_t type of status
   12432  *              NO_ERROR  -- success
   12433  *              none-zero failure code
   12434  *==========================================================================*/
   12435 int32_t QCameraParameters::QCameraReprocScaleParam::getPicSizeFromAPK(int &width, int &height)
   12436 {
   12437     if(!mIsUnderScaling)
   12438         return BAD_VALUE;
   12439 
   12440     width = mPicSizeFromAPK.width;
   12441     height = mPicSizeFromAPK.height;
   12442     return NO_ERROR;
   12443 }
   12444 
   12445 /*===========================================================================
   12446  * FUNCTION   : getPicSizeSetted
   12447  *
   12448  * DESCRIPTION: get picture size that setted into mm-camera
   12449  *
   12450  * PARAMETERS :
   12451  *   @width     : input width
   12452  *   @height    : input height
   12453  *
   12454  * RETURN     : int32_t type of status
   12455  *              NO_ERROR  -- success
   12456  *              none-zero failure code
   12457  *==========================================================================*/
   12458 int32_t QCameraParameters::QCameraReprocScaleParam::getPicSizeSetted(int &width, int &height)
   12459 {
   12460     width = mPicSizeSetted.width;
   12461     height = mPicSizeSetted.height;
   12462     return NO_ERROR;
   12463 }
   12464 
   12465 /*===========================================================================
   12466  * FUNCTION   : isUnderScaling
   12467  *
   12468  * DESCRIPTION: check if we are in Reproc Scaling requirment
   12469  *
   12470  * PARAMETERS :  none
   12471  *
   12472  * RETURN     : bool type of status
   12473  *==========================================================================*/
   12474 bool QCameraParameters::QCameraReprocScaleParam::isUnderScaling()
   12475 {
   12476     return mIsUnderScaling;
   12477 }
   12478 
   12479 /*===========================================================================
   12480  * FUNCTION   : checkScaleSizeTable
   12481  *
   12482  * DESCRIPTION: check PICTURE_SIZE_NEED_SCALE to choose
   12483  *
   12484  * PARAMETERS :
   12485  *   @scale_cnt   : count of picture sizes that want scale
   12486  *   @scale_tbl    : picture size table that want scale
   12487  *   @org_cnt     : sensor supported picture size count
   12488  *   @org_tbl      : sensor supported picture size table
   12489  *
   12490  * RETURN     : bool type of status
   12491  *==========================================================================*/
   12492 size_t QCameraParameters::QCameraReprocScaleParam::checkScaleSizeTable(size_t scale_cnt,
   12493         cam_dimension_t *scale_tbl, size_t org_cnt, cam_dimension_t *org_tbl)
   12494 {
   12495     size_t stbl_cnt = 0;
   12496     size_t temp_cnt = 0;
   12497     ssize_t i = 0;
   12498     if(scale_cnt <=0 || scale_tbl == NULL || org_tbl == NULL || org_cnt <= 0)
   12499         return stbl_cnt;
   12500 
   12501     //get validate scale size table. Currently we only support:
   12502     // 1. upscale. The scale size must larger than max sensor supported size
   12503     // 2. Scale dimension ratio must be same as the max sensor supported size.
   12504     temp_cnt = scale_cnt;
   12505     for (i = (ssize_t)(scale_cnt - 1); i >= 0; i--) {
   12506         if (scale_tbl[i].width > org_tbl[0].width ||
   12507                 (scale_tbl[i].width == org_tbl[0].width &&
   12508                     scale_tbl[i].height > org_tbl[0].height)) {
   12509             //get the smallest scale size
   12510             break;
   12511         }
   12512         temp_cnt--;
   12513     }
   12514 
   12515     //check dimension ratio
   12516     double supported_ratio = (double)org_tbl[0].width / (double)org_tbl[0].height;
   12517     for (i = 0; i < (ssize_t)temp_cnt; i++) {
   12518         double cur_ratio = (double)scale_tbl[i].width / (double)scale_tbl[i].height;
   12519         if (fabs(supported_ratio - cur_ratio) > ASPECT_TOLERANCE) {
   12520             continue;
   12521         }
   12522         mNeedScaledSizeTbl[stbl_cnt].width = scale_tbl[i].width;
   12523         mNeedScaledSizeTbl[stbl_cnt].height= scale_tbl[i].height;
   12524         stbl_cnt++;
   12525     }
   12526 
   12527     return stbl_cnt;
   12528 }
   12529 
   12530 /*===========================================================================
   12531  * FUNCTION   : getTotalSizeTblCnt
   12532  *
   12533  * DESCRIPTION: get total picture size count after adding dimensions that need scaling
   12534  *
   12535  * PARAMETERS : none
   12536  *
   12537  * RETURN     : uint8_t type of picture size count
   12538  *==========================================================================*/
   12539 size_t QCameraParameters::QCameraReprocScaleParam::getTotalSizeTblCnt()
   12540 {
   12541     return mTotalSizeTblCnt;
   12542 }
   12543 
   12544 /*===========================================================================
   12545  * FUNCTION   : getTotalSizeTbl
   12546  *
   12547  * DESCRIPTION: get picture size table after adding dimensions that need scaling
   12548  *
   12549  * PARAMETERS :  none
   12550  *
   12551  * RETURN     : cam_dimension_t list of picture size table
   12552  *==========================================================================*/
   12553 cam_dimension_t *QCameraParameters::QCameraReprocScaleParam::getTotalSizeTbl()
   12554 {
   12555     if(!mScaleEnabled)
   12556         return NULL;
   12557 
   12558     return mTotalSizeTbl;
   12559 }
   12560 
   12561 /*===========================================================================
   12562  * FUNCTION   : setEztune
   12563  *
   12564  * DESCRIPTION: Enable/Disable EZtune
   12565  *
   12566  *==========================================================================*/
   12567 int32_t QCameraParameters::setEztune()
   12568 {
   12569     char prop[PROPERTY_VALUE_MAX];
   12570     memset(prop, 0, sizeof(prop));
   12571     property_get("persist.camera.eztune.enable", prop, "0");
   12572     m_bEztuneEnabled = atoi(prop);
   12573     return NO_ERROR;
   12574 }
   12575 
   12576 /*===========================================================================
   12577  * FUNCTION   : isHDREnabled
   12578  *
   12579  * DESCRIPTION: if HDR is enabled
   12580  *
   12581  * PARAMETERS : none
   12582  *
   12583  * RETURN     : true: needed
   12584  *              false: no need
   12585  *==========================================================================*/
   12586 bool QCameraParameters::isHDREnabled()
   12587 {
   12588     return ((m_bHDREnabled || m_HDRSceneEnabled));
   12589 }
   12590 
   12591 /*===========================================================================
   12592  * FUNCTION   : isAVTimerEnabled
   12593  *
   12594  * DESCRIPTION: if AVTimer is enabled
   12595  *
   12596  * PARAMETERS : none
   12597  *
   12598  * RETURN     : true: needed
   12599  *              false: no need
   12600  *==========================================================================*/
   12601 bool QCameraParameters::isAVTimerEnabled()
   12602 {
   12603     return m_bAVTimerEnabled;
   12604 }
   12605 
   12606 /*===========================================================================
   12607 * FUNCTION   : isDISEnabled
   12608 *
   12609 * DESCRIPTION: if DIS is enabled
   12610 *
   12611 * PARAMETERS : none
   12612 *
   12613 * RETURN    : true: needed
   12614 *               false: no need
   12615 *==========================================================================*/
   12616 bool QCameraParameters::isDISEnabled()
   12617 {
   12618     return m_bDISEnabled;
   12619 }
   12620 
   12621 /*===========================================================================
   12622 * FUNCTION   : getISType
   12623 *
   12624 * DESCRIPTION: returns IS type
   12625 *
   12626 * PARAMETERS : none
   12627 *
   12628 * RETURN     : IS type
   12629 *
   12630 *==========================================================================*/
   12631 cam_is_type_t QCameraParameters::getISType()
   12632 {
   12633     return mIsType;
   12634 }
   12635 
   12636 /*===========================================================================
   12637  * FUNCTION   : MobicatMask
   12638  *
   12639  * DESCRIPTION: returns mobicat mask
   12640  *
   12641  * PARAMETERS : none
   12642  *
   12643  * RETURN     : mobicat mask
   12644  *
   12645  *==========================================================================*/
   12646 uint8_t QCameraParameters::getMobicatMask()
   12647 {
   12648     return m_MobiMask;
   12649 }
   12650 
   12651 /*===========================================================================
   12652  * FUNCTION   : sendStreamConfigInfo
   12653  *
   12654  * DESCRIPTION: send Stream config info.
   12655  *
   12656  * PARAMETERS :
   12657  *   @stream_config_info: Stream config information
   12658  *
   12659  * RETURN     : int32_t type of status
   12660  *              NO_ERROR  -- success
   12661  *              none-zero failure code
   12662  *==========================================================================*/
   12663 bool QCameraParameters::sendStreamConfigInfo(cam_stream_size_info_t &stream_config_info) {
   12664     int32_t rc = NO_ERROR;
   12665     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   12666         LOGE("Failed to initialize group update table");
   12667         return BAD_TYPE;
   12668     }
   12669 
   12670     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   12671             CAM_INTF_META_STREAM_INFO, stream_config_info)) {
   12672         LOGE("Failed to update table");
   12673         return BAD_VALUE;
   12674     }
   12675 
   12676     rc = commitSetBatch();
   12677     if (rc != NO_ERROR) {
   12678         LOGE("Failed to set stream info parm");
   12679         return rc;
   12680     }
   12681 
   12682     return rc;
   12683 }
   12684 
   12685 /*===========================================================================
   12686  * FUNCTION   : setStreamConfigure
   12687  *
   12688  * DESCRIPTION: set stream type, stream dimension for all configured streams.
   12689  *
   12690  * PARAMETERS :
   12691  *   @isCapture: Whether this configureation is for an image capture
   12692  *   @previewAsPostview: Use preview as postview
   12693  *
   12694  * RETURN     : int32_t type of status
   12695  *              NO_ERROR  -- success
   12696  *              none-zero failure code
   12697  *==========================================================================*/
   12698 bool QCameraParameters::setStreamConfigure(bool isCapture,
   12699         bool previewAsPostview, bool resetConfig) {
   12700 
   12701     int32_t rc = NO_ERROR;
   12702     cam_stream_size_info_t stream_config_info;
   12703     char value[PROPERTY_VALUE_MAX];
   12704     bool raw_yuv = false;
   12705     bool raw_capture = false;
   12706 
   12707     if ( m_pParamBuf == NULL ) {
   12708         return NO_INIT;
   12709     }
   12710 
   12711     memset(&stream_config_info, 0, sizeof(stream_config_info));
   12712     stream_config_info.num_streams = 0;
   12713 
   12714     if (resetConfig) {
   12715         LOGH("Reset stream config!!");
   12716         rc = sendStreamConfigInfo(stream_config_info);
   12717         LOGH("Done Resetting stream config!!");
   12718         return rc;
   12719     }
   12720 
   12721     stream_config_info.hfr_mode       = static_cast<cam_hfr_mode_t>(mHfrMode);
   12722     stream_config_info.buf_alignment  = m_pCapability->buf_alignment;
   12723     stream_config_info.min_stride     = m_pCapability->min_stride;
   12724     stream_config_info.min_scanline   = m_pCapability->min_scanline;
   12725     stream_config_info.batch_size = getBufBatchCount();
   12726 
   12727     property_get("persist.camera.raw_yuv", value, "0");
   12728     raw_yuv = atoi(value) > 0 ? true : false;
   12729 
   12730     if (isZSLMode() && getRecordingHintValue() != true) {
   12731         stream_config_info.type[stream_config_info.num_streams] =
   12732             CAM_STREAM_TYPE_PREVIEW;
   12733         getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
   12734                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12735         updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
   12736         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12737                 mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
   12738         getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
   12739                 stream_config_info.format[stream_config_info.num_streams]);
   12740         stream_config_info.num_streams++;
   12741 
   12742         stream_config_info.type[stream_config_info.num_streams] =
   12743                 CAM_STREAM_TYPE_ANALYSIS;
   12744         getStreamDimension(CAM_STREAM_TYPE_ANALYSIS,
   12745                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12746         updatePpFeatureMask(CAM_STREAM_TYPE_ANALYSIS);
   12747         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12748                 mStreamPpMask[CAM_STREAM_TYPE_ANALYSIS];
   12749         getStreamFormat(CAM_STREAM_TYPE_ANALYSIS,
   12750                 stream_config_info.format[stream_config_info.num_streams]);
   12751         stream_config_info.num_streams++;
   12752 
   12753         stream_config_info.type[stream_config_info.num_streams] =
   12754                 CAM_STREAM_TYPE_SNAPSHOT;
   12755         getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
   12756                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12757         updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
   12758         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12759                 mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
   12760         getStreamFormat(CAM_STREAM_TYPE_SNAPSHOT,
   12761                 stream_config_info.format[stream_config_info.num_streams]);
   12762         stream_config_info.num_streams++;
   12763 
   12764         if (isUBWCEnabled() && getRecordingHintValue() != true) {
   12765             cam_format_t fmt;
   12766             getStreamFormat(CAM_STREAM_TYPE_PREVIEW,fmt);
   12767             if (fmt == CAM_FORMAT_YUV_420_NV12_UBWC) {
   12768                 stream_config_info.type[stream_config_info.num_streams] =
   12769                         CAM_STREAM_TYPE_CALLBACK;
   12770                 getStreamDimension(CAM_STREAM_TYPE_CALLBACK,
   12771                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12772                 updatePpFeatureMask(CAM_STREAM_TYPE_CALLBACK);
   12773                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12774                         mStreamPpMask[CAM_STREAM_TYPE_CALLBACK];
   12775                 getStreamFormat(CAM_STREAM_TYPE_CALLBACK,
   12776                         stream_config_info.format[stream_config_info.num_streams]);
   12777                 stream_config_info.num_streams++;
   12778             }
   12779         }
   12780 
   12781     } else if (!isCapture) {
   12782         if (m_bRecordingHint) {
   12783             if (m_bDISEnabled) {
   12784                 char value[PROPERTY_VALUE_MAX];
   12785                 // Make default value for IS_TYPE as IS_TYPE_EIS_2_0
   12786                 property_get("persist.camera.is_type", value, "4");
   12787                 mIsType = static_cast<cam_is_type_t>(atoi(value));
   12788             } else {
   12789                 mIsType = IS_TYPE_NONE;
   12790             }
   12791             stream_config_info.is_type = mIsType;
   12792             stream_config_info.type[stream_config_info.num_streams] =
   12793                     CAM_STREAM_TYPE_SNAPSHOT;
   12794             getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
   12795                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12796             updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
   12797             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12798                     mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
   12799             getStreamFormat(CAM_STREAM_TYPE_SNAPSHOT,
   12800                         stream_config_info.format[stream_config_info.num_streams]);
   12801             stream_config_info.num_streams++;
   12802 
   12803             stream_config_info.type[stream_config_info.num_streams] =
   12804                     CAM_STREAM_TYPE_VIDEO;
   12805             getStreamDimension(CAM_STREAM_TYPE_VIDEO,
   12806                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12807             updatePpFeatureMask(CAM_STREAM_TYPE_VIDEO);
   12808             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12809                     mStreamPpMask[CAM_STREAM_TYPE_VIDEO];
   12810             getStreamFormat(CAM_STREAM_TYPE_VIDEO,
   12811                     stream_config_info.format[stream_config_info.num_streams]);
   12812             stream_config_info.num_streams++;
   12813         }
   12814 
   12815         /* Analysis stream is needed by DCRF regardless of recording hint */
   12816         if ((getDcrf() == true) ||
   12817                 (getRecordingHintValue() != true) ||
   12818                 (fdModeInVideo())) {
   12819             stream_config_info.type[stream_config_info.num_streams] =
   12820                     CAM_STREAM_TYPE_ANALYSIS;
   12821             getStreamDimension(CAM_STREAM_TYPE_ANALYSIS,
   12822                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12823             updatePpFeatureMask(CAM_STREAM_TYPE_ANALYSIS);
   12824             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12825                     mStreamPpMask[CAM_STREAM_TYPE_ANALYSIS];
   12826             getStreamFormat(CAM_STREAM_TYPE_ANALYSIS,
   12827                     stream_config_info.format[stream_config_info.num_streams]);
   12828             stream_config_info.num_streams++;
   12829         }
   12830 
   12831         stream_config_info.type[stream_config_info.num_streams] =
   12832                 CAM_STREAM_TYPE_PREVIEW;
   12833         getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
   12834                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12835         updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
   12836         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12837                 mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
   12838         getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
   12839                     stream_config_info.format[stream_config_info.num_streams]);
   12840         stream_config_info.num_streams++;
   12841 
   12842         if (isUBWCEnabled() && getRecordingHintValue() != true) {
   12843             cam_format_t fmt;
   12844             getStreamFormat(CAM_STREAM_TYPE_PREVIEW,fmt);
   12845             if (fmt == CAM_FORMAT_YUV_420_NV12_UBWC) {
   12846                 stream_config_info.type[stream_config_info.num_streams] =
   12847                         CAM_STREAM_TYPE_CALLBACK;
   12848                 getStreamDimension(CAM_STREAM_TYPE_CALLBACK,
   12849                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12850                 updatePpFeatureMask(CAM_STREAM_TYPE_CALLBACK);
   12851                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12852                         mStreamPpMask[CAM_STREAM_TYPE_CALLBACK];
   12853                 getStreamFormat(CAM_STREAM_TYPE_CALLBACK,
   12854                         stream_config_info.format[stream_config_info.num_streams]);
   12855                 stream_config_info.num_streams++;
   12856             }
   12857         }
   12858 
   12859     } else {
   12860         if (isJpegPictureFormat() || isNV16PictureFormat() || isNV21PictureFormat()) {
   12861             if (!getofflineRAW()) {
   12862                 stream_config_info.type[stream_config_info.num_streams] =
   12863                         CAM_STREAM_TYPE_SNAPSHOT;
   12864                 getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
   12865                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12866                 updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
   12867                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12868                         mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
   12869                 getStreamFormat(CAM_STREAM_TYPE_SNAPSHOT,
   12870                         stream_config_info.format[stream_config_info.num_streams]);
   12871                 stream_config_info.num_streams++;
   12872             }
   12873 
   12874             if (previewAsPostview) {
   12875                 stream_config_info.type[stream_config_info.num_streams] =
   12876                         CAM_STREAM_TYPE_PREVIEW;
   12877                 getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
   12878                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12879                 updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
   12880                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12881                         mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
   12882                 getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
   12883                         stream_config_info.format[stream_config_info.num_streams]);
   12884                 stream_config_info.num_streams++;
   12885             } else {
   12886                 stream_config_info.type[stream_config_info.num_streams] =
   12887                         CAM_STREAM_TYPE_POSTVIEW;
   12888                 getStreamDimension(CAM_STREAM_TYPE_POSTVIEW,
   12889                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12890                 updatePpFeatureMask(CAM_STREAM_TYPE_POSTVIEW);
   12891                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12892                         mStreamPpMask[CAM_STREAM_TYPE_POSTVIEW];
   12893                 getStreamFormat(CAM_STREAM_TYPE_POSTVIEW,
   12894                         stream_config_info.format[stream_config_info.num_streams]);
   12895                 stream_config_info.num_streams++;
   12896             }
   12897         } else {
   12898             raw_capture = true;
   12899             stream_config_info.type[stream_config_info.num_streams] =
   12900                     CAM_STREAM_TYPE_RAW;
   12901             getStreamDimension(CAM_STREAM_TYPE_RAW,
   12902                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12903             updatePpFeatureMask(CAM_STREAM_TYPE_RAW);
   12904             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12905                     mStreamPpMask[CAM_STREAM_TYPE_RAW];
   12906             getStreamFormat(CAM_STREAM_TYPE_RAW,
   12907                     stream_config_info.format[stream_config_info.num_streams]);
   12908             stream_config_info.num_streams++;
   12909         }
   12910     }
   12911 
   12912     if ((!raw_capture) && ((getofflineRAW() && !getRecordingHintValue())
   12913             || (raw_yuv))) {
   12914         cam_dimension_t max_dim = {0,0};
   12915         // Find the Maximum dimension admong all the streams
   12916         for (uint32_t j = 0; j < stream_config_info.num_streams; j++) {
   12917             if (stream_config_info.stream_sizes[j].width > max_dim.width) {
   12918                 max_dim.width = stream_config_info.stream_sizes[j].width;
   12919             }
   12920             if (stream_config_info.stream_sizes[j].height > max_dim.height) {
   12921                 max_dim.height = stream_config_info.stream_sizes[j].height;
   12922             }
   12923         }
   12924         LOGH("Max Dimension = %d X %d", max_dim.width, max_dim.height);
   12925         updateRAW(max_dim);
   12926         stream_config_info.type[stream_config_info.num_streams] =
   12927                 CAM_STREAM_TYPE_RAW;
   12928         getStreamDimension(CAM_STREAM_TYPE_RAW,
   12929                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
   12930         updatePpFeatureMask(CAM_STREAM_TYPE_RAW);
   12931         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
   12932                 mStreamPpMask[CAM_STREAM_TYPE_RAW];
   12933         getStreamFormat(CAM_STREAM_TYPE_RAW,
   12934                 stream_config_info.format[stream_config_info.num_streams]);
   12935         stream_config_info.num_streams++;
   12936     }
   12937     for (uint32_t k = 0; k < stream_config_info.num_streams; k++) {
   12938         LOGI("STREAM INFO : type %d, wxh: %d x %d, pp_mask: 0x%llx Format = %d",
   12939                 stream_config_info.type[k],
   12940                 stream_config_info.stream_sizes[k].width,
   12941                 stream_config_info.stream_sizes[k].height,
   12942                 stream_config_info.postprocess_mask[k],
   12943                 stream_config_info.format[k]);
   12944     }
   12945 
   12946     rc = sendStreamConfigInfo(stream_config_info);
   12947     return rc;
   12948 }
   12949 
   12950 /*===========================================================================
   12951  * FUNCTION   : addOnlineRotation
   12952  *
   12953  * DESCRIPTION: send additional rotation information for specific stream
   12954  *
   12955  * PARAMETERS :
   12956  *   @rotation: rotation
   12957  *   @streamId: internal stream id
   12958  *   @device_rotation: device rotation
   12959  *
   12960  * RETURN     : int32_t type of status
   12961  *              NO_ERROR  -- success
   12962  *              none-zero failure code
   12963  *==========================================================================*/
   12964 int32_t QCameraParameters::addOnlineRotation(uint32_t rotation, uint32_t streamId,
   12965         int32_t device_rotation)
   12966 {
   12967     int32_t rc = NO_ERROR;
   12968     cam_rotation_info_t rotation_info;
   12969     memset(&rotation_info, 0, sizeof(cam_rotation_info_t));
   12970 
   12971     /* Add jpeg rotation information */
   12972     if (rotation == 0) {
   12973         rotation_info.rotation = ROTATE_0;
   12974     } else if (rotation == 90) {
   12975         rotation_info.rotation = ROTATE_90;
   12976     } else if (rotation == 180) {
   12977         rotation_info.rotation = ROTATE_180;
   12978     } else if (rotation == 270) {
   12979         rotation_info.rotation = ROTATE_270;
   12980     } else {
   12981         rotation_info.rotation = ROTATE_0;
   12982     }
   12983     rotation_info.streamId = streamId;
   12984 
   12985     /* Add device rotation information */
   12986     if (device_rotation == 0) {
   12987         rotation_info.device_rotation = ROTATE_0;
   12988     } else if (device_rotation == 90) {
   12989         rotation_info.device_rotation = ROTATE_90;
   12990     } else if (device_rotation == 180) {
   12991         rotation_info.device_rotation = ROTATE_180;
   12992     } else if (device_rotation == 270) {
   12993         rotation_info.device_rotation = ROTATE_270;
   12994     } else {
   12995         rotation_info.device_rotation = ROTATE_0;
   12996     }
   12997 
   12998     if(initBatchUpdate(m_pParamBuf) < 0 ) {
   12999         LOGE("Failed to initialize group update table");
   13000         return BAD_TYPE;
   13001     }
   13002 
   13003     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ROTATION, rotation_info)) {
   13004         LOGE("Failed to update table");
   13005         return BAD_VALUE;
   13006     }
   13007 
   13008     rc = commitSetBatch();
   13009     if (rc != NO_ERROR) {
   13010         LOGE("Failed to set stream info parm");
   13011         return rc;
   13012     }
   13013 
   13014     return rc;
   13015 }
   13016 
   13017 /*===========================================================================
   13018  * FUNCTION   : needThumbnailReprocess
   13019  *
   13020  * DESCRIPTION: Check if thumbnail reprocessing is needed
   13021  *
   13022  * PARAMETERS : @pFeatureMask - feature mask
   13023  *
   13024  * RETURN     : true: needed
   13025  *              false: no need
   13026  *==========================================================================*/
   13027 bool QCameraParameters::needThumbnailReprocess(cam_feature_mask_t *pFeatureMask)
   13028 {
   13029     if (isUbiFocusEnabled() || isChromaFlashEnabled() ||
   13030             isOptiZoomEnabled() || isUbiRefocus() ||
   13031             isStillMoreEnabled() ||
   13032             (isHDREnabled() && !isHDRThumbnailProcessNeeded())
   13033             || isUBWCEnabled()) {
   13034         *pFeatureMask &= ~CAM_QCOM_FEATURE_CHROMA_FLASH;
   13035         *pFeatureMask &= ~CAM_QCOM_FEATURE_UBIFOCUS;
   13036         *pFeatureMask &= ~CAM_QCOM_FEATURE_REFOCUS;
   13037         *pFeatureMask &= ~CAM_QCOM_FEATURE_OPTIZOOM;
   13038         *pFeatureMask &= ~CAM_QCOM_FEATURE_STILLMORE;
   13039         *pFeatureMask &= ~CAM_QCOM_FEATURE_HDR;
   13040         return false;
   13041     } else {
   13042         cam_dimension_t thumb_dim;
   13043         getThumbnailSize(&(thumb_dim.width), &(thumb_dim.height));
   13044         if (thumb_dim.width == 0 || thumb_dim.height == 0) {
   13045             return false;
   13046         }
   13047         else {
   13048             return true;
   13049         }
   13050     }
   13051 }
   13052 
   13053 /*===========================================================================
   13054  * FUNCTION   : getNumOfExtraBuffersForImageProc
   13055  *
   13056  * DESCRIPTION: get number of extra input buffers needed by image processing
   13057  *
   13058  * PARAMETERS : none
   13059  *
   13060  * RETURN     : number of extra buffers needed by ImageProc;
   13061  *              0 if not ImageProc enabled
   13062  *==========================================================================*/
   13063 uint8_t QCameraParameters::getNumOfExtraBuffersForImageProc()
   13064 {
   13065     int numOfBufs = 0;
   13066 
   13067     if (isUbiRefocus()) {
   13068         return (uint8_t)(m_pCapability->refocus_af_bracketing_need.burst_count - 1);
   13069     } else if (isUbiFocusEnabled()) {
   13070         numOfBufs += m_pCapability->ubifocus_af_bracketing_need.burst_count - 1;
   13071     } else if (m_bOptiZoomOn) {
   13072         numOfBufs += m_pCapability->opti_zoom_settings_need.burst_count - 1;
   13073     } else if (isChromaFlashEnabled()) {
   13074         numOfBufs += m_pCapability->chroma_flash_settings_need.burst_count - 1;
   13075     } else if (isStillMoreEnabled()) {
   13076         if (isSeeMoreEnabled()) {
   13077             m_stillmore_config.burst_count = 1;
   13078         } else if ((m_stillmore_config.burst_count >=
   13079                 m_pCapability->stillmore_settings_need.min_burst_count) &&
   13080                 (m_stillmore_config.burst_count <=
   13081                 m_pCapability->stillmore_settings_need.max_burst_count)) {
   13082             numOfBufs += m_stillmore_config.burst_count - 1;
   13083         } else {
   13084             numOfBufs += m_pCapability->stillmore_settings_need.burst_count - 1;
   13085         }
   13086     } else if (isOEMFeatEnabled()) {
   13087         numOfBufs += 1;
   13088     }
   13089 
   13090     return (uint8_t)(numOfBufs);
   13091 }
   13092 
   13093 /*===========================================================================
   13094  * FUNCTION   : getExifBufIndex
   13095  *
   13096  * DESCRIPTION: get index of metadata to be used for EXIF
   13097  *
   13098  * PARAMETERS : @captureIndex - index of current captured frame
   13099  *
   13100  * RETURN     : index of metadata to be used for EXIF
   13101  *==========================================================================*/
   13102 uint32_t QCameraParameters::getExifBufIndex(uint32_t captureIndex)
   13103 {
   13104     uint32_t index = captureIndex;
   13105 
   13106     if (isUbiRefocus()) {
   13107         if (captureIndex < m_pCapability->refocus_af_bracketing_need.burst_count) {
   13108             index = captureIndex;
   13109         } else {
   13110             index = 0;
   13111         }
   13112     } else if (isChromaFlashEnabled()) {
   13113         index = m_pCapability->chroma_flash_settings_need.metadata_index;
   13114     } else if (isHDREnabled()) {
   13115         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
   13116             index = m_pCapability->hdr_bracketing_setting.num_frames;
   13117         } else {
   13118             for (index = 0; index < m_pCapability->hdr_bracketing_setting.num_frames; index++) {
   13119                 if (0 == m_pCapability->hdr_bracketing_setting.exp_val.values[index]) {
   13120                     break;
   13121                 }
   13122             }
   13123             if (index == m_pCapability->hdr_bracketing_setting.num_frames) {
   13124                 index = captureIndex;
   13125             }
   13126         }
   13127     }
   13128 
   13129     return index;
   13130 }
   13131 
   13132 /*===========================================================================
   13133  * FUNCTION   : getNumberInBufsForSingleShot
   13134  *
   13135  * DESCRIPTION: get number of input buffers for single shot
   13136  *
   13137  * PARAMETERS : none
   13138  *
   13139  * RETURN     : number of input buffers for single shot
   13140  *==========================================================================*/
   13141 uint32_t QCameraParameters::getNumberInBufsForSingleShot()
   13142 {
   13143     uint32_t numOfBufs = 1;
   13144 
   13145     if (isUbiRefocus()) {
   13146         numOfBufs = m_pCapability->refocus_af_bracketing_need.burst_count;
   13147     } else if (isUbiFocusEnabled()) {
   13148         numOfBufs = m_pCapability->ubifocus_af_bracketing_need.burst_count;
   13149     } else if (m_bOptiZoomOn) {
   13150         numOfBufs = m_pCapability->opti_zoom_settings_need.burst_count;
   13151     } else if (isChromaFlashEnabled()) {
   13152         numOfBufs = m_pCapability->chroma_flash_settings_need.burst_count;
   13153     } else if (isHDREnabled()) {
   13154         numOfBufs = m_pCapability->hdr_bracketing_setting.num_frames;
   13155         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
   13156             numOfBufs++;
   13157         }
   13158     } else if (isStillMoreEnabled()) {
   13159         if (isSeeMoreEnabled()) {
   13160             m_stillmore_config.burst_count = 1;
   13161             numOfBufs = m_stillmore_config.burst_count;
   13162         } else if ((m_stillmore_config.burst_count >=
   13163                 m_pCapability->stillmore_settings_need.min_burst_count) &&
   13164                 (m_stillmore_config.burst_count <=
   13165                 m_pCapability->stillmore_settings_need.max_burst_count)) {
   13166             numOfBufs = m_stillmore_config.burst_count;
   13167         } else {
   13168             numOfBufs = m_pCapability->stillmore_settings_need.burst_count;
   13169         }
   13170     }
   13171 
   13172     return numOfBufs;
   13173 }
   13174 
   13175 /*===========================================================================
   13176  * FUNCTION   : getNumberOutBufsForSingleShot
   13177  *
   13178  * DESCRIPTION: get number of output buffers for single shot
   13179  *
   13180  * PARAMETERS : none
   13181  *
   13182  * RETURN     : number of output buffers for single shot
   13183  *==========================================================================*/
   13184 uint32_t QCameraParameters::getNumberOutBufsForSingleShot()
   13185 {
   13186     uint32_t numOfBufs = 1;
   13187 
   13188     if (isUbiRefocus()) {
   13189         numOfBufs = m_pCapability->refocus_af_bracketing_need.output_count;
   13190     } else if (isHDREnabled()) {
   13191         if (isHDR1xFrameEnabled()) {
   13192             numOfBufs++;
   13193         }
   13194     }
   13195 
   13196     return numOfBufs;
   13197 }
   13198 
   13199 /*===========================================================================
   13200  * FUNCTION   : is4k2kVideoResolution
   13201  *
   13202  * DESCRIPTION: if resolution is 4k x 2k or true 4k x 2k
   13203  *
   13204  * PARAMETERS : none
   13205  *
   13206  * RETURN     : true: video resolution is 4k x 2k
   13207  *              false: video resolution is not 4k x 2k
   13208  *==========================================================================*/
   13209 bool QCameraParameters::is4k2kVideoResolution()
   13210 {
   13211    bool enabled = false;
   13212    cam_dimension_t resolution;
   13213    getVideoSize(&resolution.width, &resolution.height);
   13214    if (!(resolution.width < 3840 && resolution.height < 2160)) {
   13215       enabled = true;
   13216    }
   13217 
   13218    return enabled;
   13219 }
   13220 
   13221 /*===========================================================================
   13222  * FUNCTION   : isPreviewSeeMoreRequired
   13223  *
   13224  * DESCRIPTION: This function checks whether SeeMmore(SW TNR) needs to be applied for
   13225  *              preview stream depending on video resoluion and setprop
   13226  *
   13227  * PARAMETERS : none
   13228  *
   13229  * RETURN     : true: If SeeMore needs to apply
   13230  *              false: No need to apply
   13231  *==========================================================================*/
   13232 bool QCameraParameters::isPreviewSeeMoreRequired()
   13233 {
   13234    cam_dimension_t dim;
   13235    char prop[PROPERTY_VALUE_MAX];
   13236 
   13237    getVideoSize(&dim.width, &dim.height);
   13238    memset(prop, 0, sizeof(prop));
   13239    property_get("persist.camera.preview.seemore", prop, "0");
   13240    int enable = atoi(prop);
   13241 
   13242    // Enable SeeMore for preview stream if :
   13243    // 1. Video resolution <= (1920x1080)  (or)
   13244    // 2. persist.camera.preview.seemore is set
   13245    LOGD("width=%d, height=%d, enable=%d", dim.width, dim.height, enable);
   13246    return (((dim.width * dim.height) <= (1920 * 1080)) || enable);
   13247 }
   13248 
   13249 /*===========================================================================
   13250  * FUNCTION   : updateDebugLevel
   13251  *
   13252  * DESCRIPTION: send CAM_INTF_PARM_UPDATE_DEBUG_LEVEL to backend
   13253  *
   13254  * PARAMETERS : none
   13255  *
   13256  * RETURN     : NO_ERROR --success
   13257  *              int32_t type of status
   13258  *==========================================================================*/
   13259 int32_t QCameraParameters::updateDebugLevel()
   13260 {
   13261     if ( m_pParamBuf == NULL ) {
   13262         return NO_INIT;
   13263     }
   13264 
   13265     int32_t rc = initBatchUpdate(m_pParamBuf);
   13266     if ( rc != NO_ERROR ) {
   13267         LOGE("Failed to initialize group update table");
   13268         return rc;
   13269     }
   13270 
   13271     uint32_t dummyDebugLevel = 0;
   13272     /* The value of dummyDebugLevel is irrelavent. On
   13273      * CAM_INTF_PARM_UPDATE_DEBUG_LEVEL, read debug property */
   13274     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_UPDATE_DEBUG_LEVEL, dummyDebugLevel)) {
   13275         LOGE("Parameters batch failed");
   13276         return BAD_VALUE;
   13277     }
   13278 
   13279     rc = commitSetBatch();
   13280     if ( rc != NO_ERROR ) {
   13281         LOGE("Failed to commit batch parameters");
   13282         return rc;
   13283     }
   13284 
   13285     return NO_ERROR;
   13286 }
   13287 
   13288 /*===========================================================================
   13289  * FUNCTION   : setOfflineRAW
   13290  *
   13291  * DESCRIPTION: Function to decide Offline RAW feature.
   13292  *
   13293  * PARAMETERS :
   13294  *  @raw_value: offline raw value to set.
   13295  *
   13296  * RETURN     : none
   13297  *==========================================================================*/
   13298 void QCameraParameters::setOfflineRAW(bool raw_value)
   13299 {
   13300     char value[PROPERTY_VALUE_MAX];
   13301     bool raw_yuv = false;
   13302     bool offlineRaw = false;
   13303 
   13304     if (raw_value) {
   13305         mOfflineRAW = true;
   13306         LOGH("Offline Raw  %d", mOfflineRAW);
   13307         return;
   13308     }
   13309 
   13310     property_get("persist.camera.raw_yuv", value, "0");
   13311     raw_yuv = atoi(value) > 0 ? true : false;
   13312     property_get("persist.camera.offlineraw", value, "0");
   13313     offlineRaw = atoi(value) > 0 ? true : false;
   13314     if ((raw_yuv || isRdiMode()) && offlineRaw) {
   13315         mOfflineRAW = true;
   13316     } else {
   13317         mOfflineRAW = false;
   13318     }
   13319     LOGH("Offline Raw  %d", mOfflineRAW);
   13320 }
   13321 
   13322 /*===========================================================================
   13323  * FUNCTION   : updatePpFeatureMask
   13324  *
   13325  * DESCRIPTION: Updates the feature mask for a particular stream depending
   13326  *              on current client configuration.
   13327  *
   13328  * PARAMETERS :
   13329  *  @stream_type: Camera stream type
   13330  *
   13331  * RETURN     : NO_ERROR --success
   13332  *              int32_t type of status
   13333  *==========================================================================*/
   13334 int32_t QCameraParameters::updatePpFeatureMask(cam_stream_type_t stream_type) {
   13335 
   13336     cam_feature_mask_t feature_mask = 0;
   13337 
   13338     if (stream_type >= CAM_STREAM_TYPE_MAX) {
   13339         LOGE("Error!! stream type: %d not valid", stream_type);
   13340         return -1;
   13341     }
   13342 
   13343     // Update feature mask for SeeMore in video and video preview
   13344     if (isSeeMoreEnabled() && ((stream_type == CAM_STREAM_TYPE_VIDEO) ||
   13345             (stream_type == CAM_STREAM_TYPE_PREVIEW && getRecordingHintValue() &&
   13346             isPreviewSeeMoreRequired()))) {
   13347        feature_mask |= CAM_QCOM_FEATURE_LLVD;
   13348     }
   13349 
   13350     if (isHighQualityNoiseReductionMode() &&
   13351             ((stream_type == CAM_STREAM_TYPE_VIDEO) ||
   13352             (stream_type == CAM_STREAM_TYPE_PREVIEW && getRecordingHintValue() &&
   13353             isPreviewSeeMoreRequired()))) {
   13354         feature_mask |= CAM_QTI_FEATURE_SW_TNR;
   13355     }
   13356 
   13357     // Do not enable feature mask for ZSL/non-ZSL/liveshot snapshot except for 4K2k case
   13358     if ((getRecordingHintValue() &&
   13359             (stream_type == CAM_STREAM_TYPE_SNAPSHOT) && is4k2kVideoResolution()) ||
   13360             (stream_type != CAM_STREAM_TYPE_SNAPSHOT)) {
   13361         if ((m_nMinRequiredPpMask & CAM_QCOM_FEATURE_SHARPNESS) &&
   13362                 !isOptiZoomEnabled()) {
   13363             feature_mask |= CAM_QCOM_FEATURE_SHARPNESS;
   13364         }
   13365 
   13366         if (m_nMinRequiredPpMask & CAM_QCOM_FEATURE_EFFECT) {
   13367             feature_mask |= CAM_QCOM_FEATURE_EFFECT;
   13368         }
   13369         if (isWNREnabled()) {
   13370             feature_mask |= CAM_QCOM_FEATURE_DENOISE2D;
   13371         }
   13372 
   13373         //Set flip mode based on Stream type;
   13374         int flipMode = getFlipMode(stream_type);
   13375         if (flipMode > 0) {
   13376             feature_mask |= CAM_QCOM_FEATURE_FLIP;
   13377         }
   13378     }
   13379 
   13380     if ((isTNRVideoEnabled() && (CAM_STREAM_TYPE_VIDEO == stream_type))
   13381             || (isTNRPreviewEnabled() && (CAM_STREAM_TYPE_PREVIEW == stream_type))) {
   13382         feature_mask |= CAM_QCOM_FEATURE_CPP_TNR;
   13383     }
   13384     if (isEztuneEnabled() &&
   13385             ((CAM_STREAM_TYPE_PREVIEW == stream_type) ||
   13386             (CAM_STREAM_TYPE_SNAPSHOT == stream_type))) {
   13387         feature_mask |= CAM_QCOM_FEATURE_EZTUNE;
   13388     }
   13389 
   13390     if ((getCDSMode() != CAM_CDS_MODE_OFF) &&
   13391             ((CAM_STREAM_TYPE_PREVIEW == stream_type) ||
   13392             (CAM_STREAM_TYPE_VIDEO == stream_type) ||
   13393             (CAM_STREAM_TYPE_CALLBACK == stream_type) ||
   13394             ((CAM_STREAM_TYPE_SNAPSHOT == stream_type) &&
   13395             getRecordingHintValue() && is4k2kVideoResolution()))) {
   13396          if (m_nMinRequiredPpMask & CAM_QCOM_FEATURE_DSDN) {
   13397              feature_mask |= CAM_QCOM_FEATURE_DSDN;
   13398          } else {
   13399              feature_mask |= CAM_QCOM_FEATURE_CDS;
   13400          }
   13401     }
   13402 
   13403     if (isTNRSnapshotEnabled() && (CAM_STREAM_TYPE_SNAPSHOT == stream_type)
   13404             && (isZSLMode() || getRecordingHintValue())) {
   13405         feature_mask |= CAM_QCOM_FEATURE_CPP_TNR;
   13406     }
   13407 
   13408     //Rotation could also have an effect on pp feature mask
   13409     cam_pp_feature_config_t config;
   13410     cam_dimension_t dim;
   13411     memset(&config, 0, sizeof(cam_pp_feature_config_t));
   13412     getStreamRotation(stream_type, config, dim);
   13413     feature_mask |= config.feature_mask;
   13414 
   13415     // Dual Camera scenarios
   13416     // all feature masks are disabled for preview and analysis streams for aux session
   13417     // all required feature masks for aux session preview and analysis streams need
   13418     // to be enabled explicitly here
   13419     ///@note When aux camera is of bayer type, keep pp mask as is or we'd run
   13420     ///      into stream mapping problems. YUV sensor is marked as interleaved and has
   13421     ///      preferred mapping setup so we don't see any mapping issues.
   13422     if (m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
   13423         if (((CAM_STREAM_TYPE_ANALYSIS == stream_type) ||
   13424                 (CAM_STREAM_TYPE_PREVIEW == stream_type)) &&
   13425                 (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) &&
   13426                 (m_pCapability->sensor_type.sens_type == CAM_SENSOR_YUV)) {
   13427             LOGH("Disabling all pp feature masks for aux preview and "
   13428                     "analysis streams");
   13429             feature_mask = 0;
   13430         }
   13431 
   13432         // all feature masks need to be enabled here
   13433         // enable DCRF feature mask on analysis stream in case of dual camera
   13434         if (m_bDcrfEnabled && (CAM_STREAM_TYPE_ANALYSIS == stream_type)) {
   13435             feature_mask |= CAM_QCOM_FEATURE_DCRF;
   13436         } else {
   13437             feature_mask &= ~CAM_QCOM_FEATURE_DCRF;
   13438         }
   13439     }
   13440 
   13441     // Preview assisted autofocus needs to be supported for
   13442     // callback, preview, or video streams
   13443     switch (stream_type) {
   13444     case CAM_STREAM_TYPE_CALLBACK:
   13445     case CAM_STREAM_TYPE_PREVIEW:
   13446     case CAM_STREAM_TYPE_VIDEO:
   13447         feature_mask |= CAM_QCOM_FEATURE_PAAF;
   13448         break;
   13449     default:
   13450         break;
   13451     }
   13452 
   13453     // Store stream feature mask
   13454     setStreamPpMask(stream_type, feature_mask);
   13455     LOGH("stream type: %d, pp_mask: 0x%llx", stream_type, feature_mask);
   13456 
   13457     return NO_ERROR;
   13458 }
   13459 
   13460 /*===========================================================================
   13461  * FUNCTION   : setStreamPpMask
   13462  *
   13463  * DESCRIPTION: Stores a particular feature mask for a given camera stream
   13464  *
   13465  * PARAMETERS :
   13466  *  @stream_type: Camera stream type
   13467  *  @pp_mask  : Feature mask
   13468  *
   13469  * RETURN     : NO_ERROR --success
   13470  *              int32_t type of status
   13471  *==========================================================================*/
   13472 int32_t QCameraParameters::setStreamPpMask(cam_stream_type_t stream_type,
   13473         cam_feature_mask_t pp_mask) {
   13474 
   13475     if(stream_type >= CAM_STREAM_TYPE_MAX) {
   13476         return BAD_TYPE;
   13477     }
   13478 
   13479     mStreamPpMask[stream_type] = pp_mask;
   13480     return NO_ERROR;
   13481 }
   13482 
   13483 /*===========================================================================
   13484  * FUNCTION   : getStreamPpMask
   13485  *
   13486  * DESCRIPTION: Retrieves the feature mask for a given camera stream
   13487  *
   13488  * PARAMETERS :
   13489  *  @stream_type: Camera stream type
   13490  *  @pp_mask  : Feature mask
   13491  *
   13492  * RETURN     : NO_ERROR --success
   13493  *              int32_t type of status
   13494  *==========================================================================*/
   13495 int32_t QCameraParameters::getStreamPpMask(cam_stream_type_t stream_type,
   13496         cam_feature_mask_t &pp_mask) {
   13497 
   13498     if(stream_type >= CAM_STREAM_TYPE_MAX) {
   13499         return BAD_TYPE;
   13500     }
   13501 
   13502     pp_mask = mStreamPpMask[stream_type];
   13503     return NO_ERROR;
   13504 }
   13505 
   13506 /*===========================================================================
   13507  * FUNCTION   : isMultiPassReprocessing
   13508  *
   13509  * DESCRIPTION: Read setprop to enable/disable multipass
   13510  *
   13511  * PARAMETERS : none
   13512  *
   13513  * RETURN     : TRUE  -- If enabled
   13514  *              FALSE  -- disabled
   13515  *==========================================================================*/
   13516 bool QCameraParameters::isMultiPassReprocessing()
   13517 {
   13518     char value[PROPERTY_VALUE_MAX];
   13519     int multpass = 0;
   13520 
   13521     property_get("persist.camera.multi_pass", value, "0");
   13522     multpass = atoi(value);
   13523 
   13524     return (multpass == 0)? FALSE : TRUE;
   13525 }
   13526 
   13527 /*===========================================================================
   13528  * FUNCTION   : setReprocCount
   13529  *
   13530  * DESCRIPTION: Set total reprocessing pass count
   13531  *
   13532  * PARAMETERS : none
   13533  *
   13534  * RETURN     : None
   13535  *==========================================================================*/
   13536 void QCameraParameters::setReprocCount()
   13537 {
   13538     mTotalPPCount = 1; //Default reprocessing Pass count
   13539 
   13540     if (getManualCaptureMode() >=
   13541             CAM_MANUAL_CAPTURE_TYPE_3) {
   13542         LOGD("Additional post processing enabled for manual capture");
   13543         mTotalPPCount++;
   13544     }
   13545 
   13546     if (!isMultiPassReprocessing()) {
   13547         return;
   13548     }
   13549 
   13550     if ((getZoomLevel() != 0)
   13551             && (getBurstCountForAdvancedCapture()
   13552             == getNumOfSnapshots())) {
   13553         LOGD("2 Pass postprocessing enabled");
   13554         mTotalPPCount++;
   13555     }
   13556 }
   13557 
   13558 /*===========================================================================
   13559  * FUNCTION   : isUBWCEnabled
   13560  *
   13561  * DESCRIPTION: Function to get UBWC hardware support.
   13562  *
   13563  * PARAMETERS : None
   13564  *
   13565  * RETURN     : TRUE -- UBWC format supported
   13566  *              FALSE -- UBWC is not supported.
   13567  *==========================================================================*/
   13568 bool QCameraParameters::isUBWCEnabled()
   13569 {
   13570 #ifdef UBWC_PRESENT
   13571     char value[PROPERTY_VALUE_MAX];
   13572     int prop_value = 0;
   13573     memset(value, 0, sizeof(value));
   13574     property_get("debug.gralloc.gfx_ubwc_disable", value, "0");
   13575     prop_value = atoi(value);
   13576     if (prop_value) {
   13577         return FALSE;
   13578     }
   13579 
   13580     //Disable UBWC if it is YUV sensor.
   13581     if ((m_pCapability != NULL) &&
   13582             (m_pCapability->sensor_type.sens_type == CAM_SENSOR_YUV)) {
   13583         return FALSE;
   13584     }
   13585 
   13586     //Disable UBWC if Eztune is enabled
   13587     // Eztune works on CPP output and cannot understand UBWC buffer.
   13588     memset(value, 0, sizeof(value));
   13589     property_get("persist.camera.eztune.enable", value, "0");
   13590     prop_value = atoi(value);
   13591     if (prop_value) {
   13592         return FALSE;
   13593     }
   13594     return TRUE;
   13595 #else
   13596     return FALSE;
   13597 #endif
   13598 }
   13599 
   13600 /*===========================================================================
   13601  * FUNCTION   : isPostProcScaling
   13602  *
   13603  * DESCRIPTION: is scaling to be done by CPP?
   13604  *
   13605  * PARAMETERS : none
   13606  *
   13607  * RETURN     : TRUE  : If CPP scaling enabled
   13608  *              FALSE : If VFE scaling enabled
   13609  *==========================================================================*/
   13610 bool QCameraParameters::isPostProcScaling()
   13611 {
   13612     char value[PROPERTY_VALUE_MAX];
   13613     bool cpp_scaling = FALSE;
   13614 
   13615     if (getRecordingHintValue()) {
   13616         return FALSE;
   13617     }
   13618 
   13619     property_get("persist.camera.pp_scaling", value, "0");
   13620     cpp_scaling = atoi(value) > 0 ? TRUE : FALSE;
   13621 
   13622     LOGH("Post proc scaling enabled : %d",
   13623              cpp_scaling);
   13624     return cpp_scaling;
   13625 }
   13626 
   13627 /*===========================================================================
   13628  * FUNCTION   : isLLNoiseEnabled
   13629  *
   13630  * DESCRIPTION: Low light noise change
   13631  *
   13632  * PARAMETERS : none
   13633  *
   13634  * RETURN     : TRUE  : If low light noise enabled
   13635  *              FALSE : If low light noise disabled
   13636  *==========================================================================*/
   13637 bool QCameraParameters::isLLNoiseEnabled()
   13638 {
   13639     char value[PROPERTY_VALUE_MAX];
   13640     bool llnoise = FALSE;
   13641 
   13642     if (!isWNREnabled()) {
   13643         return FALSE;
   13644     }
   13645 
   13646     property_get("persist.camera.llnoise", value, "0");
   13647     llnoise = atoi(value) > 0 ? TRUE : FALSE;
   13648 
   13649     LOGH("Low light noise enabled : %d",
   13650              llnoise);
   13651     return llnoise;
   13652 }
   13653 
   13654 /*===========================================================================
   13655  * FUNCTION   : setBufBatchCount
   13656  *
   13657  * DESCRIPTION: Function to configure batch buffer
   13658  *
   13659  * PARAMETERS : int8_t buf_cnt
   13660  *                     Buffer batch count
   13661  *
   13662  * RETURN     :  None
   13663  *==========================================================================*/
   13664 void QCameraParameters::setBufBatchCount(int8_t buf_cnt)
   13665 {
   13666     mBufBatchCnt = 0;
   13667     char value[PROPERTY_VALUE_MAX];
   13668     int8_t count = 0;
   13669 
   13670     property_get("persist.camera.batchcount", value, "0");
   13671     count = atoi(value);
   13672 
   13673     if (!(count != 0 || buf_cnt > CAMERA_MIN_BATCH_COUNT)) {
   13674         LOGH("Buffer batch count = %d", mBufBatchCnt);
   13675         set(KEY_QC_VIDEO_BATCH_SIZE, mBufBatchCnt);
   13676         return;
   13677     }
   13678 
   13679     while((m_pCapability->max_batch_bufs_supported != 0)
   13680             && (m_pCapability->max_batch_bufs_supported < buf_cnt)) {
   13681         buf_cnt = buf_cnt / 2;
   13682     }
   13683 
   13684     if (count > 0) {
   13685         mBufBatchCnt = count;
   13686         LOGH("Buffer batch count = %d", mBufBatchCnt);
   13687         set(KEY_QC_VIDEO_BATCH_SIZE, mBufBatchCnt);
   13688         return;
   13689     }
   13690 
   13691     if (buf_cnt > CAMERA_MIN_BATCH_COUNT) {
   13692         mBufBatchCnt = buf_cnt;
   13693         LOGH("Buffer batch count = %d", mBufBatchCnt);
   13694         set(KEY_QC_VIDEO_BATCH_SIZE, mBufBatchCnt);
   13695         return;
   13696     }
   13697 }
   13698 
   13699 /*===========================================================================
   13700  * FUNCTION   : setVideoBatch()
   13701  *
   13702  * DESCRIPTION: Function to batching for video.
   13703  *
   13704  * PARAMETERS : none
   13705  *
   13706  * RETURN     :  None
   13707  *==========================================================================*/
   13708 void QCameraParameters::setVideoBatchSize()
   13709 {
   13710     char value[PROPERTY_VALUE_MAX];
   13711     int8_t minBatchcnt = 2; //Batching enabled only if batch size if greater than 2;
   13712     int32_t width = 0, height = 0;
   13713     mVideoBatchSize = 0;
   13714 
   13715     if (getBufBatchCount()) {
   13716         //We don't need HAL to HAL batching if camera batching enabled.
   13717         return;
   13718     }
   13719 
   13720     getVideoSize(&width, &height);
   13721     if ((width > 1920) || (height > 1080)) {
   13722         //Cannot enable batch mode for video size bigger than 1080p
   13723         return;
   13724     }
   13725 
   13726     //Batch size "6" is the recommended and gives optimal power saving.
   13727     property_get("persist.camera.video.batchsize", value, "0");
   13728     mVideoBatchSize = atoi(value);
   13729 
   13730     if (mVideoBatchSize > CAMERA_MAX_CONSUMER_BATCH_BUFFER_SIZE) {
   13731         mVideoBatchSize = CAMERA_MAX_CONSUMER_BATCH_BUFFER_SIZE;
   13732     } else if (mVideoBatchSize <= minBatchcnt) {
   13733         //Batching enabled only if batch size is greater than 2.
   13734         mVideoBatchSize = 0;
   13735     }
   13736     LOGD("mVideoBatchSize = %d", mVideoBatchSize);
   13737     set(KEY_QC_VIDEO_BATCH_SIZE, mVideoBatchSize);
   13738 }
   13739 
   13740 /*===========================================================================
   13741  * FUNCTION   : setCustomParams
   13742  *
   13743  * DESCRIPTION: Function to update OEM specific custom parameter
   13744  *
   13745  * PARAMETERS : params: Input Parameter object
   13746  *
   13747  * RETURN     :  error value
   13748  *==========================================================================*/
   13749 int32_t QCameraParameters::setCustomParams(__unused const QCameraParameters& params)
   13750 {
   13751     int32_t rc = NO_ERROR;
   13752 
   13753     /* Application specific parameter can be read from "params" and update m_pParamBuf
   13754        We can also update internal OEM custom parameters in this funcion.
   13755        "CAM_CUSTOM_PARM_EXAMPLE" is used as a example */
   13756 
   13757     /*Get the pointer of shared buffer for custom parameter*/
   13758     custom_parm_buffer_t *customParam =
   13759             (custom_parm_buffer_t *)POINTER_OF_META(CAM_INTF_PARM_CUSTOM, m_pParamBuf);
   13760 
   13761 
   13762     /*start updating custom parameter values*/
   13763     if (ADD_SET_PARAM_ENTRY_TO_BATCH(customParam, CAM_CUSTOM_PARM_EXAMPLE, 1)) {
   13764         LOGE("Failed to update CAM_CUSTOM_PARM_DUMMY");
   13765         return BAD_VALUE;
   13766     }
   13767 
   13768     /*set custom parameter values to main parameter buffer. Update isvalid flag*/
   13769     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CUSTOM);
   13770 
   13771     return rc;
   13772 }
   13773 
   13774 /*===========================================================================
   13775  * FUNCTION   : dump
   13776  *
   13777  * DESCRIPTION: Composes a string based on current configuration
   13778  *
   13779  * PARAMETERS : none
   13780  *
   13781  * RETURN     : Formatted string
   13782  *==========================================================================*/
   13783 String8 QCameraParameters::dump()
   13784 {
   13785     String8 str("\n");
   13786     char s[128];
   13787 
   13788     snprintf(s, 128, "Preview Pixel Fmt: %d\n", getPreviewHalPixelFormat());
   13789     str += s;
   13790 
   13791     snprintf(s, 128, "ZSL Burst Interval: %d\n", getZSLBurstInterval());
   13792     str += s;
   13793 
   13794     snprintf(s, 128, "ZSL Queue Depth: %d\n", getZSLQueueDepth());
   13795     str += s;
   13796 
   13797     snprintf(s, 128, "ZSL Back Look Count %d\n", getZSLBackLookCount());
   13798     str += s;
   13799 
   13800     snprintf(s, 128, "Max Unmatched Frames In Queue: %d\n",
   13801         getMaxUnmatchedFramesInQueue());
   13802     str += s;
   13803 
   13804     snprintf(s, 128, "Is ZSL Mode: %d\n", isZSLMode());
   13805     str += s;
   13806 
   13807     snprintf(s, 128, "Is No Display Mode: %d\n", isNoDisplayMode());
   13808     str += s;
   13809 
   13810     snprintf(s, 128, "Is WNR Enabled: %d\n", isWNREnabled());
   13811     str += s;
   13812 
   13813     snprintf(s, 128, "isHfrMode: %d\n", isHfrMode());
   13814     str += s;
   13815 
   13816     snprintf(s, 128, "getNumOfSnapshots: %d\n", getNumOfSnapshots());
   13817     str += s;
   13818 
   13819     snprintf(s, 128, "getNumOfExtraHDRInBufsIfNeeded: %d\n",
   13820         getNumOfExtraHDRInBufsIfNeeded());
   13821     str += s;
   13822 
   13823     snprintf(s, 128, "getNumOfExtraHDROutBufsIfNeeded: %d\n",
   13824         getNumOfExtraHDROutBufsIfNeeded());
   13825     str += s;
   13826 
   13827     snprintf(s, 128, "getRecordingHintValue: %d\n", getRecordingHintValue());
   13828     str += s;
   13829 
   13830     snprintf(s, 128, "getJpegQuality: %u\n", getJpegQuality());
   13831     str += s;
   13832 
   13833     snprintf(s, 128, "getJpegRotation: %u\n", getJpegRotation());
   13834     str += s;
   13835 
   13836     snprintf(s, 128, "isHistogramEnabled: %d\n", isHistogramEnabled());
   13837     str += s;
   13838 
   13839     snprintf(s, 128, "isFaceDetectionEnabled: %d\n", isFaceDetectionEnabled());
   13840     str += s;
   13841 
   13842     snprintf(s, 128, "isHDREnabled: %d\n", isHDREnabled());
   13843     str += s;
   13844 
   13845     snprintf(s, 128, "isAutoHDREnabled: %d\n", isAutoHDREnabled());
   13846     str += s;
   13847 
   13848     snprintf(s, 128, "isAVTimerEnabled: %d\n", isAVTimerEnabled());
   13849     str += s;
   13850 
   13851     snprintf(s, 128, "getFocusMode: %d\n", getFocusMode());
   13852     str += s;
   13853 
   13854     snprintf(s, 128, "isJpegPictureFormat: %d\n", isJpegPictureFormat());
   13855     str += s;
   13856 
   13857     snprintf(s, 128, "isNV16PictureFormat: %d\n", isNV16PictureFormat());
   13858     str += s;
   13859 
   13860     snprintf(s, 128, "isNV21PictureFormat: %d\n", isNV21PictureFormat());
   13861     str += s;
   13862 
   13863     snprintf(s, 128, "isSnapshotFDNeeded: %d\n", isSnapshotFDNeeded());
   13864     str += s;
   13865 
   13866     snprintf(s, 128, "isHDR1xFrameEnabled: %d\n", isHDR1xFrameEnabled());
   13867     str += s;
   13868 
   13869     snprintf(s, 128, "isYUVFrameInfoNeeded: %d\n", isYUVFrameInfoNeeded());
   13870     str += s;
   13871 
   13872     snprintf(s, 128, "isHDR1xExtraBufferNeeded: %d\n",
   13873         isHDR1xExtraBufferNeeded());
   13874     str += s;
   13875 
   13876     snprintf(s, 128, "isHDROutputCropEnabled: %d\n", isHDROutputCropEnabled());
   13877     str += s;
   13878 
   13879     snprintf(s, 128, "isPreviewFlipChanged: %d\n", isPreviewFlipChanged());
   13880     str += s;
   13881 
   13882     snprintf(s, 128, "isVideoFlipChanged: %d\n", isVideoFlipChanged());
   13883     str += s;
   13884 
   13885     snprintf(s, 128, "isSnapshotFlipChanged: %d\n", isSnapshotFlipChanged());
   13886     str += s;
   13887 
   13888     snprintf(s, 128, "isHDRThumbnailProcessNeeded: %d\n",
   13889         isHDRThumbnailProcessNeeded());
   13890     str += s;
   13891 
   13892     snprintf(s, 128, "getAutoFlickerMode: %d\n", getAutoFlickerMode());
   13893     str += s;
   13894 
   13895     snprintf(s, 128, "getNumOfExtraBuffersForImageProc: %d\n",
   13896         getNumOfExtraBuffersForImageProc());
   13897     str += s;
   13898 
   13899     snprintf(s, 128, "isUbiFocusEnabled: %d\n", isUbiFocusEnabled());
   13900     str += s;
   13901 
   13902     snprintf(s, 128, "isChromaFlashEnabled: %d\n", isChromaFlashEnabled());
   13903     str += s;
   13904 
   13905     snprintf(s, 128, "isOptiZoomEnabled: %d\n", isOptiZoomEnabled());
   13906     str += s;
   13907 
   13908     snprintf(s, 128, "isStillMoreEnabled: %d\n", isStillMoreEnabled());
   13909     str += s;
   13910 
   13911     snprintf(s, 128, "getBurstCountForAdvancedCapture: %d\n",
   13912         getBurstCountForAdvancedCapture());
   13913     str += s;
   13914 
   13915     return str;
   13916 }
   13917 
   13918 /*===========================================================================
   13919  * FUNCTION   : getNumOfExtraBuffersForVideo
   13920  *
   13921  * DESCRIPTION: get number of extra buffers needed by image processing
   13922  *
   13923  * PARAMETERS : none
   13924  *
   13925  * RETURN     : number of extra buffers needed by ImageProc;
   13926  *              0 if not ImageProc enabled
   13927  *==========================================================================*/
   13928 uint8_t QCameraParameters::getNumOfExtraBuffersForVideo()
   13929 {
   13930     uint8_t numOfBufs = 0;
   13931 
   13932     if (isSeeMoreEnabled() || isHighQualityNoiseReductionMode()) {
   13933         numOfBufs = 1;
   13934     }
   13935 
   13936     return numOfBufs;
   13937 }
   13938 
   13939 /*===========================================================================
   13940  * FUNCTION   : getNumOfExtraBuffersForPreview
   13941  *
   13942  * DESCRIPTION: get number of extra buffers needed by image processing
   13943  *
   13944  * PARAMETERS : none
   13945  *
   13946  * RETURN     : number of extra buffers needed by ImageProc;
   13947  *              0 if not ImageProc enabled
   13948  *==========================================================================*/
   13949 uint8_t QCameraParameters::getNumOfExtraBuffersForPreview()
   13950 {
   13951     uint8_t numOfBufs = 0;
   13952 
   13953     if ((isSeeMoreEnabled() || isHighQualityNoiseReductionMode())
   13954             && !isZSLMode() && getRecordingHintValue()) {
   13955         numOfBufs = 1;
   13956     }
   13957 
   13958     return numOfBufs;
   13959 }
   13960 
   13961 /*===========================================================================
   13962  * FUNCTION   : setToneMapMode
   13963  *
   13964  * DESCRIPTION: enable or disable tone map
   13965  *
   13966  * PARAMETERS :
   13967  *   @enable : enable: 1; disable 0
   13968  *   @initCommit: if configuration list needs to be initialized and commited
   13969  *
   13970  * RETURN     : int32_t type of status
   13971  *              NO_ERROR  -- success
   13972  *              none-zero failure code
   13973  *==========================================================================*/
   13974 int32_t QCameraParameters::setToneMapMode(uint32_t enable, bool initCommit)
   13975 {
   13976     int32_t rc = NO_ERROR;
   13977     LOGH("tone map mode %d ", enable);
   13978 
   13979     if (initCommit) {
   13980         if (initBatchUpdate(m_pParamBuf) < 0) {
   13981             LOGE("Failed to initialize group update table");
   13982             return FAILED_TRANSACTION;
   13983         }
   13984     }
   13985 
   13986     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TONE_MAP_MODE, enable)) {
   13987         LOGE("Failed to update tone map mode");
   13988         return BAD_VALUE;
   13989     }
   13990 
   13991     if (initCommit) {
   13992         rc = commitSetBatch();
   13993         if (rc != NO_ERROR) {
   13994             LOGE("Failed to commit tone map mode");
   13995             return rc;
   13996         }
   13997     }
   13998 
   13999     return rc;
   14000 }
   14001 
   14002 /*===========================================================================
   14003  * FUNCTION   : getLongshotStages
   14004  *
   14005  * DESCRIPTION: get number of stages for longshot
   14006  *
   14007  * PARAMETERS : none
   14008  *
   14009  * RETURN     : number of stages
   14010  *==========================================================================*/
   14011 uint8_t QCameraParameters::getLongshotStages()
   14012 {
   14013     uint8_t numStages =
   14014             isLowMemoryDevice() ? CAMERA_MIN_LONGSHOT_STAGES : CAMERA_DEFAULT_LONGSHOT_STAGES;
   14015 
   14016     char prop[PROPERTY_VALUE_MAX];
   14017     memset(prop, 0, sizeof(prop));
   14018     property_get("persist.camera.longshot.stages", prop, "0");
   14019     uint8_t propStages = atoi(prop);
   14020     if (propStages > 0 && propStages <= CAMERA_DEFAULT_LONGSHOT_STAGES) {
   14021         numStages = propStages;
   14022     }
   14023     return numStages;
   14024 }
   14025 
   14026 /*===========================================================================
   14027  * FUNCTION   : setCDSMode
   14028  *
   14029  * DESCRIPTION: set CDS mode
   14030  *
   14031  * PARAMETERS :
   14032  *   @cds_mode : cds mode
   14033  *   @initCommit: if configuration list needs to be initialized and commited
   14034  *
   14035  * RETURN     : int32_t type of status
   14036  *              NO_ERROR  -- success
   14037  *              none-zero failure code
   14038  *==========================================================================*/
   14039 int32_t QCameraParameters::setCDSMode(int32_t cds_mode, bool initCommit)
   14040 {
   14041     if (initCommit) {
   14042         if (initBatchUpdate(m_pParamBuf) < 0) {
   14043             LOGE("Failed to initialize group update table");
   14044             return FAILED_TRANSACTION;
   14045         }
   14046     }
   14047 
   14048     int32_t rc = NO_ERROR;
   14049     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
   14050         LOGE("Failed to update cds mode");
   14051         return BAD_VALUE;
   14052     }
   14053 
   14054     if (initCommit) {
   14055         rc = commitSetBatch();
   14056         if (NO_ERROR != rc) {
   14057             LOGE("Failed to set cds mode");
   14058             return rc;
   14059         }
   14060     }
   14061 
   14062     LOGH("cds mode -> %d", cds_mode);
   14063 
   14064     return rc;
   14065 }
   14066 
   14067 /*===========================================================================
   14068  * FUNCTION   : setLowLightCapture
   14069  *
   14070  * DESCRIPTION: Function to enable low light capture
   14071  *==========================================================================*/
   14072 void QCameraParameters::setLowLightCapture()
   14073 {
   14074     char prop[PROPERTY_VALUE_MAX];
   14075     memset(prop, 0, sizeof(prop));
   14076     property_get("persist.camera.llc", prop, "0");
   14077     m_LLCaptureEnabled = (atoi(prop) > 0) ? TRUE : FALSE;
   14078 
   14079     if (!m_LLCaptureEnabled) {
   14080         m_LowLightLevel = CAM_LOW_LIGHT_OFF;
   14081     }
   14082 }
   14083 
   14084 /*===========================================================================
   14085  * FUNCTION   : fdModeInVideo
   14086  *
   14087  * DESCRIPTION: FD in Video change
   14088  *
   14089  * PARAMETERS : none
   14090  *
   14091  * RETURN     : FD Mode in Video
   14092  *              0 : If FD in Video disabled
   14093  *              1 : If FD in Video enabled for Detection, focus
   14094  *              2 : If FD in Video enabled only for focus
   14095  *==========================================================================*/
   14096 uint8_t QCameraParameters::fdModeInVideo()
   14097 {
   14098     char value[PROPERTY_VALUE_MAX];
   14099     uint8_t fdvideo = 0;
   14100 
   14101     cam_analysis_info_t *pAnalysisInfo =
   14102             &m_pCapability->analysis_info[CAM_ANALYSIS_INFO_FD_VIDEO];
   14103 
   14104     if (!pAnalysisInfo->hw_analysis_supported) {
   14105         return 0;
   14106     }
   14107 
   14108     property_get("persist.camera.fdvideo", value, "0");
   14109     fdvideo = (atoi(value) > 0) ? atoi(value) : 0;
   14110 
   14111     LOGD("FD mode in Video : %d", fdvideo);
   14112     return fdvideo;
   14113 }
   14114 
   14115 /*===========================================================================
   14116  * FUNCTION   : setManualCaptureMode
   14117  *
   14118  * DESCRIPTION: Function to set Manual capture modes
   14119  *
   14120  * PARAMETERS :
   14121  *   @mode : Capture mode configured
   14122  *
   14123  * RETURN     : int32_t type of status
   14124  *              NO_ERROR  -- success
   14125  *              none-zero failure code
   14126  *==========================================================================*/
   14127 int32_t QCameraParameters::setManualCaptureMode(QCameraManualCaptureModes mode)
   14128 {
   14129     int32_t rc = NO_ERROR;
   14130     char value[PROPERTY_VALUE_MAX];
   14131     int8_t count = 0;
   14132 
   14133     property_get("persist.camera.manual.capture", value, "0");
   14134     count = atoi(value);
   14135 
   14136     if (count) {
   14137         if (mode == CAM_MANUAL_CAPTURE_TYPE_OFF) {
   14138             m_ManualCaptureMode = CAM_MANUAL_CAPTURE_TYPE_1;
   14139         } else {
   14140             m_ManualCaptureMode = mode;
   14141         }
   14142     } else {
   14143         m_ManualCaptureMode = CAM_MANUAL_CAPTURE_TYPE_OFF;
   14144     }
   14145 
   14146     if (m_ManualCaptureMode == CAM_MANUAL_CAPTURE_TYPE_2) {
   14147         setOfflineRAW(FALSE);
   14148     } else if (m_ManualCaptureMode >= CAM_MANUAL_CAPTURE_TYPE_3) {
   14149         setOfflineRAW(TRUE);
   14150     } else {
   14151         setOfflineRAW(FALSE);
   14152     }
   14153     setReprocCount();
   14154     LOGH("Manual capture mode - %d", m_ManualCaptureMode);
   14155     return rc;
   14156 }
   14157 
   14158 /*===========================================================================
   14159  * FUNCTION   : isReprocScaleEnabled
   14160  *
   14161  * DESCRIPTION: Whether reprocess scale is enabled or not
   14162  *
   14163  * PARAMETERS : none
   14164  *
   14165  * RETURN     : TRUE  : Reprocess scale is enabled
   14166  *              FALSE : Reprocess scale is not enabled
   14167  *==========================================================================*/
   14168 bool QCameraParameters::isReprocScaleEnabled()
   14169 {
   14170     return m_reprocScaleParam.isScaleEnabled();
   14171 }
   14172 
   14173 /*===========================================================================
   14174  * FUNCTION   : isUnderReprocScaling
   14175  *
   14176  * DESCRIPTION: Whether image is under reprocess scaling
   14177  *
   14178  * PARAMETERS : none
   14179  *
   14180  * RETURN     : TRUE  : Image is under reprocess scaling
   14181  *              FALSE : Image is not under reprocess scaling
   14182  *==========================================================================*/
   14183 bool QCameraParameters::isUnderReprocScaling()
   14184 {
   14185     return m_reprocScaleParam.isUnderScaling();
   14186 }
   14187 
   14188 /*===========================================================================
   14189  * FUNCTION   : getPicSizeFromAPK
   14190  *
   14191  * DESCRIPTION: Get picture size set from application.
   14192  *
   14193  * PARAMETERS :
   14194  *   @width   : with set by application
   14195  *   @height  : height set by application
   14196  *
   14197  * RETURN     : int32_t type of status
   14198  *              NO_ERROR  -- success
   14199  *              none-zero failure code
   14200  *==========================================================================*/
   14201 int32_t QCameraParameters::getPicSizeFromAPK(int &width, int &height)
   14202 {
   14203     return m_reprocScaleParam.getPicSizeFromAPK(width, height);
   14204 }
   14205 
   14206 
   14207 
   14208 /*===========================================================================
   14209  * FUNCTION   : setDualLedCalibration
   14210  *
   14211  * DESCRIPTION: set dual led calibration
   14212  *
   14213  * PARAMETERS :
   14214  *   @params  : user setting parameters
   14215  *
   14216  * RETURN     : int32_t type of status
   14217  *              NO_ERROR  -- success
   14218  *              none-zero failure code
   14219  *==========================================================================*/
   14220 int32_t QCameraParameters::setDualLedCalibration(
   14221         __unused const QCameraParameters& params)
   14222 {
   14223     char value[PROPERTY_VALUE_MAX];
   14224     int32_t calibration = 0;
   14225 
   14226     memset(value, 0, sizeof(value));
   14227     property_get("persist.camera.dual_led_calib", value, "0");
   14228     calibration = atoi(value);
   14229     if (calibration != m_dualLedCalibration) {
   14230       m_dualLedCalibration = calibration;
   14231       LOGD("%s:updating calibration=%d m_dualLedCalibration=%d",
   14232         __func__, calibration, m_dualLedCalibration);
   14233 
   14234       if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   14235                CAM_INTF_PARM_DUAL_LED_CALIBRATION,
   14236                m_dualLedCalibration)) {
   14237           LOGE("%s:Failed to update dual led calibration param", __func__);
   14238           return BAD_VALUE;
   14239       }
   14240     }
   14241     return NO_ERROR;
   14242 }
   14243 
   14244 /*===========================================================================
   14245  * FUNCTION   : setinstantAEC
   14246  *
   14247  * DESCRIPTION: set instant AEC value to backend
   14248  *
   14249  * PARAMETERS :
   14250  *   @value : instant aec enabled or not.
   14251  *            0 - disable
   14252  *            1 - Enable and set agressive AEC algo to the backend
   14253  *            2 - Enable and set fast AEC algo to the backend
   14254  *
   14255  * RETURN     : int32_t type of status
   14256  *              NO_ERROR  -- success
   14257  *              none-zero failure code
   14258  *==========================================================================*/
   14259 int32_t QCameraParameters::setInstantAEC(uint8_t value, bool initCommit)
   14260 {
   14261     if (initCommit) {
   14262         if (initBatchUpdate(m_pParamBuf) < 0) {
   14263             LOGE("Failed to initialize group update table");
   14264             return FAILED_TRANSACTION;
   14265         }
   14266     }
   14267 
   14268     int32_t rc = NO_ERROR;
   14269     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_INSTANT_AEC, value)) {
   14270         LOGE("Failed to instant aec value");
   14271         return BAD_VALUE;
   14272     }
   14273 
   14274     // set the new value
   14275     char val[8];
   14276     snprintf(val, sizeof(val), "%d", value);
   14277     updateParamEntry(KEY_QC_INSTANT_AEC, val);
   14278 
   14279     if (initCommit) {
   14280         rc = commitSetBatch();
   14281         if (NO_ERROR != rc) {
   14282             LOGE("Failed to instant aec value");
   14283             return rc;
   14284         }
   14285     }
   14286 
   14287     LOGD(" Instant AEC value set to backend %d", value);
   14288     m_bInstantAEC = value;
   14289     return rc;
   14290 }
   14291 
   14292 /*===========================================================================
   14293  * FUNCTION   : setAdvancedCaptureMode
   14294  *
   14295  * DESCRIPTION: set advanced capture mode
   14296  *
   14297  * PARAMETERS : none
   14298  *
   14299  * RETURN     : int32_t type of status
   14300  *              NO_ERROR  -- success
   14301  *              none-zero failure code
   14302  *==========================================================================*/
   14303 int32_t QCameraParameters::setAdvancedCaptureMode()
   14304 {
   14305     uint8_t value = isAdvCamFeaturesEnabled();
   14306     LOGD("updating advanced capture mode value to %d",value);
   14307     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
   14308             CAM_INTF_PARM_ADV_CAPTURE_MODE, value)) {
   14309         LOGE("Failed to set advanced capture mode param");
   14310         return BAD_VALUE;
   14311     }
   14312     return NO_ERROR;
   14313 }
   14314 
   14315 /*===========================================================================
   14316  * FUNCTION   : getAnalysisInfo
   14317  *
   14318  * DESCRIPTION: Get the Analysis information based on
   14319  *     current mode and feature mask
   14320  *
   14321  * PARAMETERS :
   14322  *   @fdVideoEnabled : Whether fdVideo enabled currently
   14323  *   @videoEnabled   : Whether hal3 or hal1
   14324  *   @featureMask    : Feature mask
   14325  *   @analysis_info  : Analysis info to be filled
   14326  *
   14327  * RETURN     : int32_t type of status
   14328  *              NO_ERROR  -- success
   14329  *              none-zero failure code
   14330  *==========================================================================*/
   14331 int32_t QCameraParameters::getAnalysisInfo(
   14332         bool fdVideoEnabled,
   14333         bool hal3,
   14334         uint32_t featureMask,
   14335         cam_analysis_info_t *pAnalysisInfo)
   14336 {
   14337     return mCommon.getAnalysisInfo(fdVideoEnabled, hal3, featureMask, pAnalysisInfo);
   14338 }
   14339 
   14340 }; // namespace qcamera
   14341