1 /* 2 ** Copyright (c) 2011-2012 The Linux Foundation. All rights reserved. 3 ** 4 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** you may not use this file except in compliance with the License. 6 ** You may obtain a copy of the License at 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 10 ** Unless required by applicable law or agreed to in writing, software 11 ** distributed under the License is distributed on an "AS IS" BASIS, 12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 */ 16 17 //#define ALOG_NDEBUG 0 18 #define ALOG_NIDEBUG 0 19 #define LOG_TAG "QCameraHWI_Parm" 20 #include <utils/Log.h> 21 22 #include <utils/Errors.h> 23 #include <utils/threads.h> 24 //#include <binder/MemoryHeapPmem.h> 25 #include <utils/String16.h> 26 #include <sys/types.h> 27 #include <sys/stat.h> 28 #include <unistd.h> 29 #include <fcntl.h> 30 #include <cutils/properties.h> 31 #include <math.h> 32 #if HAVE_ANDROID_OS 33 #include <linux/android_pmem.h> 34 #endif 35 #include <linux/ioctl.h> 36 #include "QCameraParameters.h" 37 #include <media/mediarecorder.h> 38 #include <gralloc_priv.h> 39 40 #include "linux/msm_mdp.h" 41 #include <linux/fb.h> 42 #include <limits.h> 43 44 extern "C" { 45 #include <fcntl.h> 46 #include <time.h> 47 #include <pthread.h> 48 #include <stdio.h> 49 #include <string.h> 50 #include <unistd.h> 51 #include <termios.h> 52 #include <assert.h> 53 #include <stdlib.h> 54 #include <ctype.h> 55 #include <signal.h> 56 #include <errno.h> 57 #include <sys/mman.h> 58 #include <sys/system_properties.h> 59 #include <sys/time.h> 60 #include <stdlib.h> 61 #include <linux/msm_ion.h> 62 63 } // extern "C" 64 65 #include "QCameraHWI.h" 66 #include "QCameraStream.h" 67 68 /* QCameraHardwareInterface class implementation goes here*/ 69 /* following code implements the parameter logic of this class*/ 70 #define EXPOSURE_COMPENSATION_MAXIMUM_NUMERATOR 12 71 #define EXPOSURE_COMPENSATION_MINIMUM_NUMERATOR -12 72 #define EXPOSURE_COMPENSATION_DEFAULT_NUMERATOR 0 73 #define EXPOSURE_COMPENSATION_DENOMINATOR 6 74 #define EXPOSURE_COMPENSATION_STEP ((float (1))/EXPOSURE_COMPENSATION_DENOMINATOR) 75 #define DEFAULT_CAMERA_AREA "(0, 0, 0, 0, 0)" 76 77 #define HDR_HAL_FRAME 2 78 79 #define BURST_INTREVAL_MIN 1 80 #define BURST_INTREVAL_MAX 10 81 #define BURST_INTREVAL_DEFAULT 1 82 83 //Default FPS 84 #define MINIMUM_FPS 5 85 #define MAXIMUM_FPS 30 86 #define DEFAULT_FIXED_FPS 30 87 #define DEFAULT_FPS 30 88 89 //Default Picture Width 90 #define DEFAULT_PICTURE_WIDTH 640 91 #define DEFAULT_PICTURE_HEIGHT 480 92 93 //Default Video Width 94 #define DEFAULT_VIDEO_WIDTH 1920 95 #define DEFAULT_VIDEO_HEIGHT 1088 96 97 #define THUMBNAIL_SIZE_COUNT (sizeof(thumbnail_sizes)/sizeof(thumbnail_size_type)) 98 #define DEFAULT_THUMBNAIL_SETTING 4 99 #define THUMBNAIL_WIDTH_STR "512" 100 #define THUMBNAIL_HEIGHT_STR "384" 101 #define THUMBNAIL_SMALL_HEIGHT 144 102 103 #define DONT_CARE_COORDINATE -1 104 105 //for histogram stats 106 #define HISTOGRAM_STATS_SIZE 257 107 108 //Supported preview fps ranges should be added to this array in the form (minFps,maxFps) 109 static android::FPSRange FpsRangesSupported[] = { 110 android::FPSRange(MINIMUM_FPS*1000,MAXIMUM_FPS*1000) 111 }; 112 #define FPS_RANGES_SUPPORTED_COUNT (sizeof(FpsRangesSupported)/sizeof(FpsRangesSupported[0])) 113 114 115 typedef struct { 116 uint32_t aspect_ratio; 117 uint32_t width; 118 uint32_t height; 119 } thumbnail_size_type; 120 121 static thumbnail_size_type thumbnail_sizes[] = { 122 { 7281, 512, 288 }, //1.777778 123 { 6826, 480, 288 }, //1.666667 124 { 6808, 256, 154 }, //1.66233 125 { 6144, 432, 288 }, //1.5 126 { 5461, 512, 384 }, //1.333333 127 { 5006, 352, 288 }, //1.222222 128 { 5461, 320, 240 }, //1.33333 129 { 5006, 176, 144 }, //1.222222 130 131 }; 132 133 static struct camera_size_type zsl_picture_sizes[] = { 134 { 1280, 960}, // 1.3MP 135 { 800, 600}, //SVGA 136 { 800, 480}, // WVGA 137 { 640, 480}, // VGA 138 { 352, 288}, //CIF 139 { 320, 240}, // QVGA 140 { 176, 144} // QCIF 141 }; 142 143 static camera_size_type default_picture_sizes[] = { 144 { 4000, 3000}, // 12MP 145 { 3264, 2448}, // 8MP 146 { 3264, 1836}, // Picture Size to match 1080p,720p AR 147 { 3264, 2176}, // Picture Size to match 480p AR 148 { 2592, 1944}, // 5MP 149 { 2048, 1536}, // 3MP QXGA 150 { 1920, 1080}, // HD1080 151 { 1600, 1200}, // 2MP UXGA 152 { 1280, 960}, // 1.3MP 153 { 1280, 720}, 154 { 720, 480}, 155 { 800, 480}, // WVGA 156 { 640, 480}, // VGA 157 { 352, 288}, // CIF 158 { 320, 240}, // QVGA 159 { 176, 144} // QCIF 160 }; 161 162 static int iso_speed_values[] = { 163 0, 1, 100, 200, 400, 800, 1600 164 }; 165 166 extern int HAL_numOfCameras; 167 extern qcamera_info_t HAL_cameraInfo[MSM_MAX_CAMERA_SENSORS]; 168 extern mm_camera_t * HAL_camerahandle[MSM_MAX_CAMERA_SENSORS]; 169 170 namespace android { 171 172 static uint32_t HFR_SIZE_COUNT=2; 173 static const int PICTURE_FORMAT_JPEG = 1; 174 static const int PICTURE_FORMAT_RAW = 2; 175 176 /********************************************************************/ 177 static const str_map effects[] = { 178 { QCameraParameters::EFFECT_NONE, CAMERA_EFFECT_OFF }, 179 { QCameraParameters::EFFECT_MONO, CAMERA_EFFECT_MONO }, 180 { QCameraParameters::EFFECT_NEGATIVE, CAMERA_EFFECT_NEGATIVE }, 181 { QCameraParameters::EFFECT_SOLARIZE, CAMERA_EFFECT_SOLARIZE }, 182 { QCameraParameters::EFFECT_SEPIA, CAMERA_EFFECT_SEPIA }, 183 { QCameraParameters::EFFECT_POSTERIZE, CAMERA_EFFECT_POSTERIZE }, 184 { QCameraParameters::EFFECT_WHITEBOARD, CAMERA_EFFECT_WHITEBOARD }, 185 { QCameraParameters::EFFECT_BLACKBOARD, CAMERA_EFFECT_BLACKBOARD }, 186 { QCameraParameters::EFFECT_AQUA, CAMERA_EFFECT_AQUA }, 187 { QCameraParameters::EFFECT_EMBOSS, CAMERA_EFFECT_EMBOSS }, 188 { QCameraParameters::EFFECT_SKETCH, CAMERA_EFFECT_SKETCH }, 189 { QCameraParameters::EFFECT_NEON, CAMERA_EFFECT_NEON } 190 }; 191 192 static const str_map iso[] = { 193 { QCameraParameters::ISO_AUTO, CAMERA_ISO_AUTO}, 194 { QCameraParameters::ISO_HJR, CAMERA_ISO_DEBLUR}, 195 { QCameraParameters::ISO_100, CAMERA_ISO_100}, 196 { QCameraParameters::ISO_200, CAMERA_ISO_200}, 197 { QCameraParameters::ISO_400, CAMERA_ISO_400}, 198 { QCameraParameters::ISO_800, CAMERA_ISO_800 }, 199 { QCameraParameters::ISO_1600, CAMERA_ISO_1600 } 200 }; 201 202 static const str_map scenemode[] = { 203 { QCameraParameters::SCENE_MODE_AUTO, CAMERA_BESTSHOT_OFF }, 204 { QCameraParameters::SCENE_MODE_ASD, CAMERA_BESTSHOT_AUTO }, 205 { QCameraParameters::SCENE_MODE_ACTION, CAMERA_BESTSHOT_ACTION }, 206 { QCameraParameters::SCENE_MODE_PORTRAIT, CAMERA_BESTSHOT_PORTRAIT }, 207 { QCameraParameters::SCENE_MODE_LANDSCAPE, CAMERA_BESTSHOT_LANDSCAPE }, 208 { QCameraParameters::SCENE_MODE_NIGHT, CAMERA_BESTSHOT_NIGHT }, 209 { QCameraParameters::SCENE_MODE_NIGHT_PORTRAIT, CAMERA_BESTSHOT_NIGHT_PORTRAIT }, 210 { QCameraParameters::SCENE_MODE_THEATRE, CAMERA_BESTSHOT_THEATRE }, 211 { QCameraParameters::SCENE_MODE_BEACH, CAMERA_BESTSHOT_BEACH }, 212 { QCameraParameters::SCENE_MODE_SNOW, CAMERA_BESTSHOT_SNOW }, 213 { QCameraParameters::SCENE_MODE_SUNSET, CAMERA_BESTSHOT_SUNSET }, 214 { QCameraParameters::SCENE_MODE_STEADYPHOTO, CAMERA_BESTSHOT_ANTISHAKE }, 215 { QCameraParameters::SCENE_MODE_FIREWORKS , CAMERA_BESTSHOT_FIREWORKS }, 216 { QCameraParameters::SCENE_MODE_SPORTS , CAMERA_BESTSHOT_SPORTS }, 217 { QCameraParameters::SCENE_MODE_PARTY, CAMERA_BESTSHOT_PARTY }, 218 { QCameraParameters::SCENE_MODE_CANDLELIGHT, CAMERA_BESTSHOT_CANDLELIGHT }, 219 { QCameraParameters::SCENE_MODE_BACKLIGHT, CAMERA_BESTSHOT_BACKLIGHT }, 220 { QCameraParameters::SCENE_MODE_FLOWERS, CAMERA_BESTSHOT_FLOWERS }, 221 { QCameraParameters::SCENE_MODE_AR, CAMERA_BESTSHOT_AR }, 222 { QCameraParameters::SCENE_MODE_HDR, CAMERA_BESTSHOT_AUTO }, 223 }; 224 225 static const str_map scenedetect[] = { 226 { QCameraParameters::SCENE_DETECT_OFF, false }, 227 { QCameraParameters::SCENE_DETECT_ON, true }, 228 }; 229 230 #define DONT_CARE AF_MODE_MAX 231 static const str_map focus_modes[] = { 232 { QCameraParameters::FOCUS_MODE_AUTO, AF_MODE_AUTO}, 233 { QCameraParameters::FOCUS_MODE_INFINITY, AF_MODE_INFINITY }, 234 { QCameraParameters::FOCUS_MODE_NORMAL, AF_MODE_NORMAL }, 235 { QCameraParameters::FOCUS_MODE_MACRO, AF_MODE_MACRO }, 236 { QCameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE, AF_MODE_CAF}, 237 { QCameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO, AF_MODE_CAF } 238 }; 239 240 static const str_map selectable_zone_af[] = { 241 { QCameraParameters::SELECTABLE_ZONE_AF_AUTO, AUTO }, 242 { QCameraParameters::SELECTABLE_ZONE_AF_SPOT_METERING, SPOT }, 243 { QCameraParameters::SELECTABLE_ZONE_AF_CENTER_WEIGHTED, CENTER_WEIGHTED }, 244 { QCameraParameters::SELECTABLE_ZONE_AF_FRAME_AVERAGE, AVERAGE } 245 }; 246 247 static const str_map autoexposure[] = { 248 { QCameraParameters::AUTO_EXPOSURE_FRAME_AVG, CAMERA_AEC_FRAME_AVERAGE }, 249 { QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED, CAMERA_AEC_CENTER_WEIGHTED }, 250 { QCameraParameters::AUTO_EXPOSURE_SPOT_METERING, CAMERA_AEC_SPOT_METERING } 251 }; 252 253 // from aeecamera.h 254 static const str_map whitebalance[] = { 255 { QCameraParameters::WHITE_BALANCE_AUTO, CAMERA_WB_AUTO }, 256 { QCameraParameters::WHITE_BALANCE_INCANDESCENT, CAMERA_WB_INCANDESCENT }, 257 { QCameraParameters::WHITE_BALANCE_FLUORESCENT, CAMERA_WB_FLUORESCENT }, 258 { QCameraParameters::WHITE_BALANCE_DAYLIGHT, CAMERA_WB_DAYLIGHT }, 259 { QCameraParameters::WHITE_BALANCE_CLOUDY_DAYLIGHT, CAMERA_WB_CLOUDY_DAYLIGHT } 260 }; 261 262 static const str_map antibanding[] = { 263 { QCameraParameters::ANTIBANDING_OFF, CAMERA_ANTIBANDING_OFF }, 264 { QCameraParameters::ANTIBANDING_50HZ, CAMERA_ANTIBANDING_50HZ }, 265 { QCameraParameters::ANTIBANDING_60HZ, CAMERA_ANTIBANDING_60HZ }, 266 { QCameraParameters::ANTIBANDING_AUTO, CAMERA_ANTIBANDING_AUTO } 267 }; 268 269 static const str_map frame_rate_modes[] = { 270 {QCameraParameters::KEY_PREVIEW_FRAME_RATE_AUTO_MODE, FPS_MODE_AUTO}, 271 {QCameraParameters::KEY_PREVIEW_FRAME_RATE_FIXED_MODE, FPS_MODE_FIXED} 272 }; 273 274 static const str_map touchafaec[] = { 275 { QCameraParameters::TOUCH_AF_AEC_OFF, false }, 276 { QCameraParameters::TOUCH_AF_AEC_ON, true } 277 }; 278 279 static const str_map hfr[] = { 280 { QCameraParameters::VIDEO_HFR_OFF, CAMERA_HFR_MODE_OFF }, 281 { QCameraParameters::VIDEO_HFR_2X, CAMERA_HFR_MODE_60FPS }, 282 { QCameraParameters::VIDEO_HFR_3X, CAMERA_HFR_MODE_90FPS }, 283 { QCameraParameters::VIDEO_HFR_4X, CAMERA_HFR_MODE_120FPS }, 284 }; 285 static const int HFR_VALUES_COUNT = (sizeof(hfr)/sizeof(str_map)); 286 287 static const str_map flash[] = { 288 { QCameraParameters::FLASH_MODE_OFF, LED_MODE_OFF }, 289 { QCameraParameters::FLASH_MODE_AUTO, LED_MODE_AUTO }, 290 { QCameraParameters::FLASH_MODE_ON, LED_MODE_ON }, 291 { QCameraParameters::FLASH_MODE_TORCH, LED_MODE_TORCH} 292 }; 293 294 static const str_map lensshade[] = { 295 { QCameraParameters::LENSSHADE_ENABLE, true }, 296 { QCameraParameters::LENSSHADE_DISABLE, false } 297 }; 298 299 static const str_map mce[] = { 300 { QCameraParameters::MCE_ENABLE, true }, 301 { QCameraParameters::MCE_DISABLE, false } 302 }; 303 304 static const str_map histogram[] = { 305 { QCameraParameters::HISTOGRAM_ENABLE, true }, 306 { QCameraParameters::HISTOGRAM_DISABLE, false } 307 }; 308 309 static const str_map skinToneEnhancement[] = { 310 { QCameraParameters::SKIN_TONE_ENHANCEMENT_ENABLE, true }, 311 { QCameraParameters::SKIN_TONE_ENHANCEMENT_DISABLE, false } 312 }; 313 314 static const str_map denoise[] = { 315 { QCameraParameters::DENOISE_OFF, false }, 316 { QCameraParameters::DENOISE_ON, true } 317 }; 318 319 static const str_map facedetection[] = { 320 { QCameraParameters::FACE_DETECTION_OFF, false }, 321 { QCameraParameters::FACE_DETECTION_ON, true } 322 }; 323 324 static const str_map redeye_reduction[] = { 325 { QCameraParameters::REDEYE_REDUCTION_ENABLE, true }, 326 { QCameraParameters::REDEYE_REDUCTION_DISABLE, false } 327 }; 328 329 static const str_map picture_formats[] = { 330 {QCameraParameters::PIXEL_FORMAT_JPEG, PICTURE_FORMAT_JPEG}, 331 {QCameraParameters::PIXEL_FORMAT_RAW, PICTURE_FORMAT_RAW} 332 }; 333 334 static const str_map recording_Hints[] = { 335 {"false", false}, 336 {"true", true} 337 }; 338 339 static const str_map preview_formats[] = { 340 {QCameraParameters::PIXEL_FORMAT_YUV420SP, HAL_PIXEL_FORMAT_YCrCb_420_SP}, 341 {QCameraParameters::PIXEL_FORMAT_YUV420SP_ADRENO, HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO}, 342 {QCameraParameters::PIXEL_FORMAT_YV12, HAL_PIXEL_FORMAT_YV12}, 343 {QCameraParameters::PIXEL_FORMAT_YUV420P,HAL_PIXEL_FORMAT_YV12}, 344 {QCameraParameters::PIXEL_FORMAT_NV12, HAL_PIXEL_FORMAT_YCbCr_420_SP} 345 }; 346 347 static const preview_format_info_t preview_format_info_list[] = { 348 {HAL_PIXEL_FORMAT_YCrCb_420_SP, CAMERA_YUV_420_NV21, CAMERA_PAD_TO_WORD, 2}, 349 {HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO, CAMERA_YUV_420_NV21, CAMERA_PAD_TO_4K, 2}, 350 {HAL_PIXEL_FORMAT_YCbCr_420_SP, CAMERA_YUV_420_NV12, CAMERA_PAD_TO_WORD, 2}, 351 {HAL_PIXEL_FORMAT_YV12, CAMERA_YUV_420_YV12, CAMERA_PAD_TO_WORD, 3} 352 }; 353 354 static const str_map zsl_modes[] = { 355 { QCameraParameters::ZSL_OFF, false }, 356 { QCameraParameters::ZSL_ON, true }, 357 }; 358 359 360 static const str_map hdr_bracket[] = { 361 { QCameraParameters::AE_BRACKET_HDR_OFF,HDR_BRACKETING_OFF}, 362 { QCameraParameters::AE_BRACKET_HDR,HDR_MODE }, 363 }; 364 365 typedef enum { 366 NORMAL_POWER, 367 LOW_POWER 368 } power_mode; 369 370 static const str_map power_modes[] = { 371 { QCameraParameters::NORMAL_POWER,NORMAL_POWER }, 372 { QCameraParameters::LOW_POWER,LOW_POWER } 373 }; 374 375 /**************************************************************************/ 376 static int attr_lookup(const str_map arr[], int len, const char *name) 377 { 378 if (name) { 379 for (int i = 0; i < len; i++) { 380 if (!strcmp(arr[i].desc, name)) 381 return arr[i].val; 382 } 383 } 384 return NOT_FOUND; 385 } 386 387 bool QCameraHardwareInterface::native_set_parms( 388 mm_camera_parm_type_t type, uint16_t length, void *value) 389 { 390 ALOGV("%s : type : %d Value : %d",__func__,type,*((int *)value)); 391 if(MM_CAMERA_OK != cam_config_set_parm(mCameraId, type,value )) { 392 ALOGE("native_set_parms failed: type %d length %d error %s", 393 type, length, strerror(errno)); 394 return false; 395 } 396 397 return true; 398 399 } 400 401 bool QCameraHardwareInterface::native_set_parms( 402 mm_camera_parm_type_t type, uint16_t length, void *value, int *result) 403 { 404 *result= cam_config_set_parm(mCameraId, type,value ); 405 if(MM_CAMERA_OK == *result) { 406 ALOGV("native_set_parms: succeeded : %d", *result); 407 return true; 408 } 409 410 ALOGE("native_set_parms failed: type %d length %d error str %s error# %d", 411 type, length, strerror(errno), errno); 412 return false; 413 } 414 415 //Filter Picture sizes based on max width and height 416 /* TBD: do we still need this - except for ZSL? */ 417 void QCameraHardwareInterface::filterPictureSizes(){ 418 unsigned int i; 419 if(mPictureSizeCount <= 0) 420 return; 421 maxSnapshotWidth = mPictureSizes[0].width; 422 maxSnapshotHeight = mPictureSizes[0].height; 423 // Iterate through all the width and height to find the max value 424 for(i =0; i<mPictureSizeCount;i++){ 425 if(((maxSnapshotWidth < mPictureSizes[i].width) && 426 (maxSnapshotHeight <= mPictureSizes[i].height))){ 427 maxSnapshotWidth = mPictureSizes[i].width; 428 maxSnapshotHeight = mPictureSizes[i].height; 429 } 430 } 431 if(myMode & CAMERA_ZSL_MODE){ 432 // due to lack of PMEM we restrict to lower resolution 433 mPictureSizesPtr = zsl_picture_sizes; 434 mSupportedPictureSizesCount = 7; 435 }else{ 436 mPictureSizesPtr = mPictureSizes; 437 mSupportedPictureSizesCount = mPictureSizeCount; 438 } 439 } 440 441 static String8 create_sizes_str(const camera_size_type *sizes, int len) { 442 String8 str; 443 char buffer[32]; 444 445 if (len > 0) { 446 snprintf(buffer, sizeof(buffer), "%dx%d", sizes[0].width, sizes[0].height); 447 str.append(buffer); 448 } 449 for (int i = 1; i < len; i++) { 450 snprintf(buffer, sizeof(buffer), ",%dx%d", sizes[i].width, sizes[i].height); 451 str.append(buffer); 452 } 453 return str; 454 } 455 456 String8 QCameraHardwareInterface::create_values_str(const str_map *values, int len) { 457 String8 str; 458 459 if (len > 0) { 460 str.append(values[0].desc); 461 } 462 for (int i = 1; i < len; i++) { 463 str.append(","); 464 str.append(values[i].desc); 465 } 466 return str; 467 } 468 469 static String8 create_fps_str(const android:: FPSRange* fps, int len) { 470 String8 str; 471 char buffer[32]; 472 473 if (len > 0) { 474 snprintf(buffer, sizeof(buffer), "(%d,%d)", fps[0].minFPS, fps[0].maxFPS); 475 str.append(buffer); 476 } 477 for (int i = 1; i < len; i++) { 478 snprintf(buffer, sizeof(buffer), ",(%d,%d)", fps[i].minFPS, fps[i].maxFPS); 479 str.append(buffer); 480 } 481 return str; 482 } 483 484 static String8 create_values_range_str(int min, int max){ 485 String8 str; 486 char buffer[32]; 487 488 if(min <= max){ 489 snprintf(buffer, sizeof(buffer), "%d", min); 490 str.append(buffer); 491 492 for (int i = min + 1; i <= max; i++) { 493 snprintf(buffer, sizeof(buffer), ",%d", i); 494 str.append(buffer); 495 } 496 } 497 return str; 498 } 499 500 static int parse_size(const char *str, int &width, int &height) 501 { 502 // Find the width. 503 char *end; 504 int w = (int)strtol(str, &end, 10); 505 // If an 'x' or 'X' does not immediately follow, give up. 506 if ( (*end != 'x') && (*end != 'X') ) 507 return -1; 508 509 // Find the height, immediately after the 'x'. 510 int h = (int)strtol(end+1, 0, 10); 511 512 width = w; 513 height = h; 514 515 return 0; 516 } 517 518 bool QCameraHardwareInterface::isValidDimension(int width, int height) { 519 bool retVal = false; 520 /* This function checks if a given resolution is valid or not. 521 * A particular resolution is considered valid if it satisfies 522 * the following conditions: 523 * 1. width & height should be multiple of 16. 524 * 2. width & height should be less than/equal to the dimensions 525 * supported by the camera sensor. 526 * 3. the aspect ratio is a valid aspect ratio and is among the 527 * commonly used aspect ratio as determined by the thumbnail_sizes 528 * data structure. 529 */ 530 531 if( (width == CEILING16(width)) && (height == CEILING16(height)) 532 && (width <= maxSnapshotWidth) 533 && (height <= maxSnapshotHeight) ) 534 { 535 uint32_t pictureAspectRatio = (uint32_t)((width * Q12)/height); 536 for(uint32_t i = 0; i < THUMBNAIL_SIZE_COUNT; i++ ) { 537 if(thumbnail_sizes[i].aspect_ratio == pictureAspectRatio) { 538 retVal = true; 539 break; 540 } 541 } 542 } 543 return retVal; 544 } 545 546 void QCameraHardwareInterface::hasAutoFocusSupport(){ 547 548 ALOGV("%s",__func__); 549 550 if(isZSLMode()){ 551 mHasAutoFocusSupport = false; 552 return; 553 } 554 555 if(cam_ops_is_op_supported (mCameraId, MM_CAMERA_OPS_FOCUS )) { 556 mHasAutoFocusSupport = true; 557 } 558 else { 559 ALOGV("AutoFocus is not supported"); 560 mHasAutoFocusSupport = false; 561 } 562 563 ALOGV("%s:rc= %d",__func__, mHasAutoFocusSupport); 564 565 } 566 567 bool QCameraHardwareInterface::supportsSceneDetection() { 568 bool rc = cam_config_is_parm_supported(mCameraId,MM_CAMERA_PARM_ASD_ENABLE); 569 return rc; 570 } 571 572 bool QCameraHardwareInterface::supportsFaceDetection() { 573 bool rc; 574 575 status_t ret = NO_ERROR; 576 mm_camera_op_mode_type_t op_mode; 577 578 ret = cam_config_get_parm(mCameraId, MM_CAMERA_PARM_OP_MODE, &op_mode); 579 if(ret != NO_ERROR){ 580 ALOGE("%s: Failed to get Op Mode", __func__); 581 } 582 583 ALOGV("%s: OP_Mode is %d, ret=%d, mHdrMode=%d",__func__,op_mode,ret,mHdrMode); 584 if ((ret == NO_ERROR) && (op_mode == MM_CAMERA_OP_MODE_VIDEO) && (mHdrMode != HDR_MODE)) 585 { 586 ALOGV("%s: Video mode : FD not supported",__func__); 587 return false; 588 } 589 else{ 590 rc = cam_config_is_parm_supported(mCameraId,MM_CAMERA_PARM_FD); 591 ALOGV("%s: Still mode : FD supported : %d",__func__,rc); 592 return rc; 593 } 594 } 595 596 bool QCameraHardwareInterface::supportsSelectableZoneAf() { 597 bool rc = cam_config_is_parm_supported(mCameraId,MM_CAMERA_PARM_FOCUS_RECT); 598 return rc; 599 } 600 601 bool QCameraHardwareInterface::supportsRedEyeReduction() { 602 bool rc = cam_config_is_parm_supported(mCameraId,MM_CAMERA_PARM_REDEYE_REDUCTION); 603 return rc; 604 } 605 606 static String8 create_str(int16_t *arr, int length){ 607 String8 str; 608 char buffer[32] = {0}; 609 610 if(length > 0){ 611 snprintf(buffer, sizeof(buffer), "%d", arr[0]); 612 str.append(buffer); 613 } 614 615 for (int i =1;i<length;i++){ 616 snprintf(buffer, sizeof(buffer), ",%d",arr[i]); 617 str.append(buffer); 618 } 619 return str; 620 } 621 622 bool QCameraHardwareInterface::getMaxPictureDimension(mm_camera_dimension_t *maxDim) 623 { 624 bool ret = NO_ERROR; 625 mm_camera_dimension_t dim; 626 627 ret = cam_config_get_parm(mCameraId, 628 MM_CAMERA_PARM_MAX_PICTURE_SIZE, &dim); 629 if (ret != NO_ERROR) 630 return ret; 631 632 /* Find the first dimension in the mPictureSizes 633 * array which is smaller than the max dimension. 634 * This will be the valid max picture resolution */ 635 for (unsigned int i = 0; i < mPictureSizeCount; i++) { 636 if ((mPictureSizes[i].width <= dim.width) && 637 (mPictureSizes[i].height <= dim.height)) { 638 maxDim->height = mPictureSizes[i].height; 639 maxDim->width = mPictureSizes[i].width; 640 break; 641 } 642 } 643 ALOGV("%s: Found Max Picture dimension: %d x %d", __func__, 644 maxDim->width, maxDim->height); 645 return ret; 646 } 647 void QCameraHardwareInterface::loadTables() 648 { 649 650 bool ret = NO_ERROR; 651 ALOGV("%s: E", __func__); 652 653 ret = cam_config_get_parm(mCameraId, 654 MM_CAMERA_PARM_PREVIEW_SIZES_CNT, &preview_sizes_count); 655 656 default_sizes_tbl_t preview_sizes_tbl; 657 preview_sizes_tbl.tbl_size=preview_sizes_count; 658 preview_sizes_tbl.sizes_tbl=&default_preview_sizes[0]; 659 if(MM_CAMERA_OK != cam_config_get_parm(mCameraId, 660 MM_CAMERA_PARM_DEF_PREVIEW_SIZES, &preview_sizes_tbl)){ 661 ALOGE("%s:Failed to get default preview sizes",__func__); 662 } 663 ret = cam_config_get_parm(mCameraId, 664 MM_CAMERA_PARM_VIDEO_SIZES_CNT, &video_sizes_count); 665 666 default_sizes_tbl_t video_sizes_tbl; 667 video_sizes_tbl.tbl_size=video_sizes_count; 668 video_sizes_tbl.sizes_tbl=&default_video_sizes[0]; 669 if(MM_CAMERA_OK != cam_config_get_parm(mCameraId, 670 MM_CAMERA_PARM_DEF_VIDEO_SIZES, &video_sizes_tbl)){ 671 ALOGE("%s:Failed to get default video sizes",__func__); 672 } 673 674 ret = cam_config_get_parm(mCameraId, 675 MM_CAMERA_PARM_THUMB_SIZES_CNT, &thumbnail_sizes_count); 676 677 default_sizes_tbl_t thumbnail_sizes_tbl; 678 thumbnail_sizes_tbl.tbl_size=thumbnail_sizes_count; 679 thumbnail_sizes_tbl.sizes_tbl=&default_thumbnail_sizes[0]; 680 if(MM_CAMERA_OK != cam_config_get_parm(mCameraId, 681 MM_CAMERA_PARM_DEF_THUMB_SIZES, &thumbnail_sizes_tbl)){ 682 ALOGE("%s:Failed to get default thumbnail sizes",__func__); 683 } 684 685 ret = cam_config_get_parm(mCameraId, 686 MM_CAMERA_PARM_HFR_SIZES_CNT, &hfr_sizes_count); 687 688 default_sizes_tbl_t hfr_sizes_tbl; 689 hfr_sizes_tbl.tbl_size=hfr_sizes_count; 690 hfr_sizes_tbl.sizes_tbl=&default_hfr_sizes[0]; 691 if(MM_CAMERA_OK != cam_config_get_parm(mCameraId, 692 MM_CAMERA_PARM_DEF_HFR_SIZES, &hfr_sizes_tbl)){ 693 ALOGE("%s:Failed to get default HFR sizes",__func__); 694 } 695 ALOGV("%s: X", __func__); 696 } 697 698 rat_t getRational(int num, int denom) 699 { 700 rat_t temp = {num, denom}; 701 return temp; 702 } 703 704 void QCameraHardwareInterface::initDefaultParameters() 705 { 706 bool ret; 707 char prop[PROPERTY_VALUE_MAX]; 708 mm_camera_dimension_t maxDim; 709 int rc = MM_CAMERA_OK; 710 ALOGV("%s: E", __func__); 711 712 memset(&maxDim, 0, sizeof(mm_camera_dimension_t)); 713 ret = getMaxPictureDimension(&maxDim); 714 715 if (ret != NO_ERROR) { 716 ALOGE("%s: Cannot get Max picture size supported", __func__); 717 return; 718 } 719 if (!maxDim.width || !maxDim.height) { 720 maxDim.width = DEFAULT_LIVESHOT_WIDTH; 721 maxDim.height = DEFAULT_LIVESHOT_HEIGHT; 722 } 723 724 memset(prop, 0, sizeof(prop)); 725 property_get("persist.camera.snap.format", prop, "0"); 726 mSnapshotFormat = atoi(prop); 727 ALOGV("%s: prop =(%s), snap_format=%d", __func__, prop, mSnapshotFormat); 728 729 //cam_ctrl_dimension_t dim; 730 mHFRLevel = 0; 731 memset(&mDimension, 0, sizeof(cam_ctrl_dimension_t)); 732 memset(&mPreviewFormatInfo, 0, sizeof(preview_format_info_t)); 733 mDimension.video_width = DEFAULT_VIDEO_WIDTH; 734 mDimension.video_height = DEFAULT_VIDEO_HEIGHT; 735 // mzhu mDimension.picture_width = DEFAULT_STREAM_WIDTH; 736 // mzhu mDimension.picture_height = DEFAULT_STREAM_HEIGHT; 737 mDimension.picture_width = maxDim.width; 738 mDimension.picture_height = maxDim.height; 739 mDimension.display_width = DEFAULT_STREAM_WIDTH; 740 mDimension.display_height = DEFAULT_STREAM_HEIGHT; 741 mDimension.orig_picture_dx = mDimension.picture_width; 742 mDimension.orig_picture_dy = mDimension.picture_height; 743 mDimension.ui_thumbnail_width = DEFAULT_STREAM_WIDTH; 744 mDimension.ui_thumbnail_height = DEFAULT_STREAM_HEIGHT; 745 mDimension.orig_video_width = DEFAULT_STREAM_WIDTH; 746 mDimension.orig_video_height = DEFAULT_STREAM_HEIGHT; 747 748 mDimension.prev_format = CAMERA_YUV_420_NV21; 749 mDimension.enc_format = CAMERA_YUV_420_NV12; 750 if (mSnapshotFormat == 1) { 751 mDimension.main_img_format = CAMERA_YUV_422_NV61; 752 } else { 753 mDimension.main_img_format = CAMERA_YUV_420_NV21; 754 } 755 mDimension.thumb_format = CAMERA_YUV_420_NV21; 756 ALOGV("%s: main_img_format =%d, thumb_format=%d", __func__, 757 mDimension.main_img_format, mDimension.thumb_format); 758 mDimension.prev_padding_format = CAMERA_PAD_TO_WORD; 759 760 ret = native_set_parms(MM_CAMERA_PARM_DIMENSION, 761 sizeof(cam_ctrl_dimension_t), (void *) &mDimension); 762 if(!ret) { 763 ALOGE("MM_CAMERA_PARM_DIMENSION Failed."); 764 return; 765 } 766 767 hasAutoFocusSupport(); 768 769 // Initialize constant parameter strings. This will happen only once in the 770 // lifetime of the mediaserver process. 771 if (true/*!mParamStringInitialized*/) { 772 //filter picture sizes 773 filterPictureSizes(); 774 mPictureSizeValues = create_sizes_str( 775 mPictureSizesPtr, mSupportedPictureSizesCount); 776 mPreviewSizeValues = create_sizes_str( 777 mPreviewSizes, mPreviewSizeCount); 778 mVideoSizeValues = create_sizes_str( 779 mVideoSizes, mVideoSizeCount); 780 781 //Query for max HFR value 782 camera_hfr_mode_t maxHFR; 783 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_MAX_HFR_MODE, (void *)&maxHFR); 784 //Filter HFR values and build parameter string 785 String8 str; 786 for(int i=0; i<HFR_VALUES_COUNT; i++){ 787 if(hfr[i].val <= maxHFR){ 788 if(i>0) str.append(","); 789 str.append(hfr[i].desc); 790 } 791 } 792 mHfrValues = str; 793 mHfrSizeValues = create_sizes_str( 794 default_hfr_sizes, hfr_sizes_count); 795 mFpsRangesSupportedValues = create_fps_str( 796 FpsRangesSupported,FPS_RANGES_SUPPORTED_COUNT ); 797 mParameters.set( 798 QCameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, 799 mFpsRangesSupportedValues); 800 mParameters.setPreviewFpsRange(MINIMUM_FPS*1000,MAXIMUM_FPS*1000); 801 mFlashValues = create_values_str( 802 flash, sizeof(flash) / sizeof(str_map)); 803 mLensShadeValues = create_values_str( 804 lensshade,sizeof(lensshade)/sizeof(str_map)); 805 mMceValues = create_values_str( 806 mce,sizeof(mce)/sizeof(str_map)); 807 mEffectValues = create_values_str(effects, sizeof(effects) / sizeof(str_map)); 808 mAntibandingValues = create_values_str( 809 antibanding, sizeof(antibanding) / sizeof(str_map)); 810 mIsoValues = create_values_str(iso,sizeof(iso)/sizeof(str_map)); 811 mAutoExposureValues = create_values_str( 812 autoexposure, sizeof(autoexposure) / sizeof(str_map)); 813 mWhitebalanceValues = create_values_str( 814 whitebalance, sizeof(whitebalance) / sizeof(str_map)); 815 816 if(mHasAutoFocusSupport){ 817 mFocusModeValues = create_values_str( 818 focus_modes, sizeof(focus_modes) / sizeof(str_map)); 819 } 820 821 mSceneModeValues = create_values_str(scenemode, sizeof(scenemode) / sizeof(str_map)); 822 823 if(mHasAutoFocusSupport){ 824 mTouchAfAecValues = create_values_str( 825 touchafaec,sizeof(touchafaec)/sizeof(str_map)); 826 } 827 //Currently Enabling Histogram for 8x60 828 mHistogramValues = create_values_str( 829 histogram,sizeof(histogram)/sizeof(str_map)); 830 831 mSkinToneEnhancementValues = create_values_str( 832 skinToneEnhancement,sizeof(skinToneEnhancement)/sizeof(str_map)); 833 834 mPictureFormatValues = create_values_str( 835 picture_formats, sizeof(picture_formats)/sizeof(str_map)); 836 837 mZoomSupported=false; 838 mMaxZoom=0; 839 mm_camera_zoom_tbl_t zmt; 840 if(MM_CAMERA_OK != cam_config_get_parm(mCameraId, 841 MM_CAMERA_PARM_MAXZOOM, &mMaxZoom)){ 842 ALOGE("%s:Failed to get max zoom",__func__); 843 }else{ 844 845 ALOGV("Max Zoom:%d",mMaxZoom); 846 /* Kernel driver limits the max amount of data that can be retreived through a control 847 command to 260 bytes hence we conservatively limit to 110 zoom ratios */ 848 if(mMaxZoom>MAX_ZOOM_RATIOS) { 849 ALOGV("%s:max zoom is larger than sizeof zoomRatios table",__func__); 850 mMaxZoom=MAX_ZOOM_RATIOS-1; 851 } 852 zmt.size=mMaxZoom; 853 zmt.zoom_ratio_tbl=&zoomRatios[0]; 854 if(MM_CAMERA_OK != cam_config_get_parm(mCameraId, 855 MM_CAMERA_PARM_ZOOM_RATIO, &zmt)){ 856 ALOGE("%s:Failed to get max zoom ratios",__func__); 857 }else{ 858 mZoomSupported=true; 859 mZoomRatioValues = create_str(zoomRatios, mMaxZoom); 860 } 861 } 862 863 ALOGV("Zoom supported:%d",mZoomSupported); 864 865 denoise_value = create_values_str( 866 denoise, sizeof(denoise) / sizeof(str_map)); 867 868 if(supportsFaceDetection()) { 869 mFaceDetectionValues = create_values_str( 870 facedetection, sizeof(facedetection) / sizeof(str_map)); 871 } 872 873 if(mHasAutoFocusSupport){ 874 mSelectableZoneAfValues = create_values_str( 875 selectable_zone_af, sizeof(selectable_zone_af) / sizeof(str_map)); 876 } 877 878 mSceneDetectValues = create_values_str(scenedetect, sizeof(scenedetect) / sizeof(str_map)); 879 880 mRedeyeReductionValues = create_values_str( 881 redeye_reduction, sizeof(redeye_reduction) / sizeof(str_map)); 882 883 mZslValues = create_values_str( 884 zsl_modes,sizeof(zsl_modes)/sizeof(str_map)); 885 886 mParamStringInitialized = true; 887 } 888 889 //set supported video sizes 890 mParameters.set(QCameraParameters::KEY_SUPPORTED_VIDEO_SIZES, mVideoSizeValues.string()); 891 892 //set default video size to first one in supported table 893 String8 vSize = create_sizes_str(&mVideoSizes[0], 1); 894 mParameters.set(QCameraParameters::KEY_VIDEO_SIZE, vSize.string()); 895 896 //Set Preview size 897 int default_preview_width, default_preview_height; 898 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_DEFAULT_PREVIEW_WIDTH, 899 &default_preview_width); 900 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_DEFAULT_PREVIEW_HEIGHT, 901 &default_preview_height); 902 mParameters.setPreviewSize(default_preview_width, default_preview_height); 903 mParameters.set(QCameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, 904 mPreviewSizeValues.string()); 905 mDimension.display_width = default_preview_width; 906 mDimension.display_height = default_preview_height; 907 908 //Set Preview Frame Rate 909 if(mFps >= MINIMUM_FPS && mFps <= MAXIMUM_FPS) { 910 mPreviewFrameRateValues = create_values_range_str( 911 MINIMUM_FPS, mFps); 912 }else{ 913 mPreviewFrameRateValues = create_values_range_str( 914 MINIMUM_FPS, MAXIMUM_FPS); 915 } 916 917 918 if (cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_FPS)) { 919 mParameters.set(QCameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, 920 mPreviewFrameRateValues.string()); 921 } else { 922 mParameters.set( 923 QCameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, 924 DEFAULT_FIXED_FPS); 925 } 926 927 //Set Preview Frame Rate Modes 928 mParameters.setPreviewFrameRateMode("frame-rate-auto"); 929 mFrameRateModeValues = create_values_str( 930 frame_rate_modes, sizeof(frame_rate_modes) / sizeof(str_map)); 931 if(cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_FPS_MODE)){ 932 mParameters.set(QCameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATE_MODES, 933 mFrameRateModeValues.string()); 934 } 935 936 //Set Preview Format 937 //mParameters.setPreviewFormat("yuv420sp"); // informative 938 mParameters.setPreviewFormat(QCameraParameters::PIXEL_FORMAT_YUV420SP); 939 940 mPreviewFormatValues = create_values_str( 941 preview_formats, sizeof(preview_formats) / sizeof(str_map)); 942 mParameters.set(QCameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, 943 mPreviewFormatValues.string()); 944 945 //Set Overlay Format 946 mParameters.set("overlay-format", HAL_PIXEL_FORMAT_YCbCr_420_SP); 947 mParameters.set("max-num-detected-faces-hw", "2"); 948 949 // Set supported max faces 950 int maxNumFaces = 0; 951 if (supportsFaceDetection()) { 952 //Query the maximum number of faces supported by hardware. 953 if(MM_CAMERA_OK != cam_config_get_parm(mCameraId, 954 MM_CAMERA_PARM_MAX_NUM_FACES_DECT, &maxNumFaces)){ 955 ALOGE("%s:Failed to get max number of faces supported",__func__); 956 } 957 } 958 mParameters.set(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW, maxNumFaces); 959 //This paramtere is set to default here. This will be changed by application 960 //if it needs to support specific number of faces. See also setParameters. 961 mParameters.set(QCameraParameters::KEY_MAX_NUM_REQUESTED_FACES, 2); 962 963 // Set camera features supported flag 964 int32_t featureFlag = 0; 965 if (supportsFaceDetection()) { 966 featureFlag |= 0x00000001; // bit 0 indicate faciral feature 967 } 968 mParameters.set(QCameraParameters::KEY_SUPPORTED_CAMERA_FEATURES, featureFlag); 969 970 //Set Picture Size 971 mParameters.setPictureSize(DEFAULT_PICTURE_WIDTH, DEFAULT_PICTURE_HEIGHT); 972 mParameters.set(QCameraParameters::KEY_SUPPORTED_PICTURE_SIZES, 973 mPictureSizeValues.string()); 974 975 //Set Preview Frame Rate 976 if(mFps >= MINIMUM_FPS && mFps <= MAXIMUM_FPS) { 977 mParameters.setPreviewFrameRate(mFps); 978 }else{ 979 mParameters.setPreviewFrameRate(DEFAULT_FPS); 980 } 981 982 //Set Picture Format 983 mParameters.setPictureFormat("jpeg"); // informative 984 mParameters.set(QCameraParameters::KEY_SUPPORTED_PICTURE_FORMATS, 985 mPictureFormatValues); 986 987 mParameters.set(QCameraParameters::KEY_JPEG_QUALITY, "90"); // max quality 988 mJpegQuality = 90; 989 //Set Video Format 990 mParameters.set(QCameraParameters::KEY_VIDEO_FRAME_FORMAT, "yuv420sp"); 991 992 //Set Thumbnail parameters 993 mParameters.set(QCameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, 994 THUMBNAIL_WIDTH_STR); // informative 995 mParameters.set(QCameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, 996 THUMBNAIL_HEIGHT_STR); // informative 997 mDimension.ui_thumbnail_width = 998 thumbnail_sizes[DEFAULT_THUMBNAIL_SETTING].width; 999 mDimension.ui_thumbnail_height = 1000 thumbnail_sizes[DEFAULT_THUMBNAIL_SETTING].height; 1001 mParameters.set(QCameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, "90"); 1002 String8 valuesStr = create_sizes_str(default_thumbnail_sizes, thumbnail_sizes_count); 1003 mParameters.set(QCameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, 1004 valuesStr.string()); 1005 // Define CAMERA_SMOOTH_ZOOM in Android.mk file , to enable smoothzoom 1006 #ifdef CAMERA_SMOOTH_ZOOM 1007 mParameters.set(QCameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED, "true"); 1008 #endif 1009 if(mZoomSupported){ 1010 mParameters.set(QCameraParameters::KEY_ZOOM_SUPPORTED, "true"); 1011 ALOGV("max zoom is %d", mMaxZoom-1); 1012 /* mMaxZoom value that the query interface returns is the size 1013 ALOGV("max zoom is %d", mMaxZoom-1); 1014 * mMaxZoom value that the query interface returns is the size 1015 * of zoom table. So the actual max zoom value will be one 1016 * less than that value. */ 1017 1018 mParameters.set("max-zoom",mMaxZoom-1); 1019 mParameters.set(QCameraParameters::KEY_ZOOM_RATIOS, 1020 mZoomRatioValues); 1021 } else 1022 { 1023 mParameters.set(QCameraParameters::KEY_ZOOM_SUPPORTED, "false"); 1024 } 1025 1026 /* Enable zoom support for video application if VPE enabled */ 1027 if(mZoomSupported) { 1028 mParameters.set("video-zoom-support", "true"); 1029 } else { 1030 mParameters.set("video-zoom-support", "false"); 1031 } 1032 1033 //8960 supports Power modes : Low power, Normal Power. 1034 mParameters.set("power-mode-supported", "true"); 1035 1036 //Set Live shot support 1037 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_LIVESHOT_MAIN); 1038 if(!rc) { 1039 ALOGV("%s:LIVESHOT is not supported", __func__); 1040 mParameters.set("video-snapshot-supported", "false"); 1041 } else { 1042 mParameters.set("video-snapshot-supported", "true"); 1043 } 1044 1045 1046 //Set default power mode 1047 mParameters.set(QCameraParameters::KEY_POWER_MODE,"Low_Power"); 1048 //Set Wnr on 1049 mParameters.set(QCameraParameters::KEY_DENOISE,true); 1050 //Set Camera Mode 1051 mParameters.set(QCameraParameters::KEY_CAMERA_MODE,1); 1052 mParameters.set(QCameraParameters::KEY_AE_BRACKET_HDR,"Off"); 1053 1054 //Set Antibanding 1055 mParameters.set(QCameraParameters::KEY_ANTIBANDING, 1056 QCameraParameters::ANTIBANDING_AUTO); 1057 mParameters.set(QCameraParameters::KEY_SUPPORTED_ANTIBANDING, 1058 mAntibandingValues); 1059 1060 //Set Effect 1061 mParameters.set(QCameraParameters::KEY_EFFECT, 1062 QCameraParameters::EFFECT_NONE); 1063 mParameters.set(QCameraParameters::KEY_SUPPORTED_EFFECTS, mEffectValues); 1064 1065 //Set Auto Exposure 1066 mParameters.set(QCameraParameters::KEY_AUTO_EXPOSURE, 1067 QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED); 1068 mParameters.set(QCameraParameters::KEY_SUPPORTED_AUTO_EXPOSURE, mAutoExposureValues); 1069 1070 //Set WhiteBalance 1071 mParameters.set(QCameraParameters::KEY_WHITE_BALANCE, 1072 QCameraParameters::WHITE_BALANCE_AUTO); 1073 mParameters.set(QCameraParameters::KEY_SUPPORTED_WHITE_BALANCE,mWhitebalanceValues); 1074 1075 //Set AEC_LOCK 1076 mParameters.set(QCameraParameters::KEY_AUTO_EXPOSURE_LOCK, "false"); 1077 if(cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_AEC_LOCK)){ 1078 mParameters.set(QCameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED, "true"); 1079 } else { 1080 mParameters.set(QCameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED, "false"); 1081 } 1082 //Set AWB_LOCK 1083 mParameters.set(QCameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, "false"); 1084 if(cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_AWB_LOCK)) 1085 mParameters.set(QCameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED, "true"); 1086 else 1087 mParameters.set(QCameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED, "false"); 1088 1089 //Set Focus Mode 1090 if(mHasAutoFocusSupport){ 1091 mParameters.set(QCameraParameters::KEY_FOCUS_MODE, 1092 QCameraParameters::FOCUS_MODE_AUTO); 1093 mFocusMode = AF_MODE_AUTO; 1094 mParameters.set(QCameraParameters::KEY_SUPPORTED_FOCUS_MODES, 1095 mFocusModeValues); 1096 mParameters.set(QCameraParameters::KEY_MAX_NUM_FOCUS_AREAS, "1"); 1097 mParameters.set(QCameraParameters::KEY_MAX_NUM_METERING_AREAS, "1"); 1098 } else { 1099 mParameters.set(QCameraParameters::KEY_FOCUS_MODE, 1100 QCameraParameters::FOCUS_MODE_INFINITY); 1101 mFocusMode = DONT_CARE; 1102 mParameters.set(QCameraParameters::KEY_SUPPORTED_FOCUS_MODES, 1103 QCameraParameters::FOCUS_MODE_INFINITY); 1104 mParameters.set(QCameraParameters::KEY_MAX_NUM_FOCUS_AREAS, "0"); 1105 mParameters.set(QCameraParameters::KEY_MAX_NUM_METERING_AREAS, "0"); 1106 } 1107 1108 mParameters.set(QCameraParameters::KEY_FOCUS_AREAS, DEFAULT_CAMERA_AREA); 1109 mParameters.set(QCameraParameters::KEY_METERING_AREAS, DEFAULT_CAMERA_AREA); 1110 1111 //Set Flash 1112 if (cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_LED_MODE)) { 1113 mParameters.set(QCameraParameters::KEY_FLASH_MODE, 1114 QCameraParameters::FLASH_MODE_OFF); 1115 mParameters.set(QCameraParameters::KEY_SUPPORTED_FLASH_MODES, 1116 mFlashValues); 1117 } 1118 1119 //Set Sharpness 1120 mParameters.set(QCameraParameters::KEY_MAX_SHARPNESS, 1121 CAMERA_MAX_SHARPNESS); 1122 mParameters.set(QCameraParameters::KEY_SHARPNESS, 1123 CAMERA_DEF_SHARPNESS); 1124 1125 //Set Contrast 1126 mParameters.set(QCameraParameters::KEY_MAX_CONTRAST, 1127 CAMERA_MAX_CONTRAST); 1128 mParameters.set(QCameraParameters::KEY_CONTRAST, 1129 CAMERA_DEF_CONTRAST); 1130 1131 //Set Saturation 1132 mParameters.set(QCameraParameters::KEY_MAX_SATURATION, 1133 CAMERA_MAX_SATURATION); 1134 mParameters.set(QCameraParameters::KEY_SATURATION, 1135 CAMERA_DEF_SATURATION); 1136 1137 //Set Brightness/luma-adaptaion 1138 mParameters.set("luma-adaptation", "3"); 1139 1140 mParameters.set(QCameraParameters::KEY_PICTURE_FORMAT, 1141 QCameraParameters::PIXEL_FORMAT_JPEG); 1142 1143 //Set Lensshading 1144 mParameters.set(QCameraParameters::KEY_LENSSHADE, 1145 QCameraParameters::LENSSHADE_ENABLE); 1146 mParameters.set(QCameraParameters::KEY_SUPPORTED_LENSSHADE_MODES, 1147 mLensShadeValues); 1148 1149 //Set ISO Mode 1150 mParameters.set(QCameraParameters::KEY_ISO_MODE, 1151 QCameraParameters::ISO_AUTO); 1152 mParameters.set(QCameraParameters::KEY_SUPPORTED_ISO_MODES, 1153 mIsoValues); 1154 1155 //Set MCE 1156 mParameters.set(QCameraParameters::KEY_MEMORY_COLOR_ENHANCEMENT, 1157 QCameraParameters::MCE_ENABLE); 1158 mParameters.set(QCameraParameters::KEY_SUPPORTED_MEM_COLOR_ENHANCE_MODES, 1159 mMceValues); 1160 //Set HFR 1161 if (cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_HFR)) { 1162 mParameters.set(QCameraParameters::KEY_VIDEO_HIGH_FRAME_RATE, 1163 QCameraParameters::VIDEO_HFR_OFF); 1164 mParameters.set(QCameraParameters::KEY_SUPPORTED_HFR_SIZES, 1165 mHfrSizeValues.string()); 1166 mParameters.set(QCameraParameters::KEY_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES, 1167 mHfrValues); 1168 } else{ 1169 mParameters.set(QCameraParameters::KEY_SUPPORTED_HFR_SIZES,""); 1170 } 1171 1172 //Set Histogram 1173 mParameters.set(QCameraParameters::KEY_HISTOGRAM, 1174 QCameraParameters::HISTOGRAM_DISABLE); 1175 mParameters.set(QCameraParameters::KEY_SUPPORTED_HISTOGRAM_MODES, 1176 mHistogramValues); 1177 1178 //Set SkinTone Enhancement 1179 mParameters.set(QCameraParameters::KEY_SKIN_TONE_ENHANCEMENT, 1180 QCameraParameters::SKIN_TONE_ENHANCEMENT_DISABLE); 1181 mParameters.set("skinToneEnhancement", "0"); 1182 mParameters.set(QCameraParameters::KEY_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES, 1183 mSkinToneEnhancementValues); 1184 1185 //Set Scene Mode 1186 mParameters.set(QCameraParameters::KEY_SCENE_MODE, 1187 QCameraParameters::SCENE_MODE_AUTO); 1188 mParameters.set(QCameraParameters::KEY_SUPPORTED_SCENE_MODES, 1189 mSceneModeValues); 1190 1191 //Set Streaming Textures 1192 mParameters.set("strtextures", "OFF"); 1193 1194 //Set Denoise 1195 mParameters.set(QCameraParameters::KEY_DENOISE, 1196 QCameraParameters::DENOISE_ON); 1197 mParameters.set(QCameraParameters::KEY_SUPPORTED_DENOISE, 1198 denoise_value); 1199 //Set Touch AF/AEC 1200 mParameters.set(QCameraParameters::KEY_TOUCH_AF_AEC, 1201 QCameraParameters::TOUCH_AF_AEC_OFF); 1202 mParameters.set(QCameraParameters::KEY_SUPPORTED_TOUCH_AF_AEC, 1203 mTouchAfAecValues); 1204 /* touch-AF ROI for reducing af fail case */ 1205 mParameters.set("touchAfAec-dx","200"); 1206 mParameters.set("touchAfAec-dy","200"); 1207 1208 //Set Scene Detection 1209 mParameters.set(QCameraParameters::KEY_SCENE_DETECT, 1210 QCameraParameters::SCENE_DETECT_OFF); 1211 mParameters.set(QCameraParameters::KEY_SUPPORTED_SCENE_DETECT, 1212 mSceneDetectValues); 1213 1214 //Set Selectable Zone AF 1215 mParameters.set(QCameraParameters::KEY_SELECTABLE_ZONE_AF, 1216 QCameraParameters::SELECTABLE_ZONE_AF_AUTO); 1217 mParameters.set(QCameraParameters::KEY_SUPPORTED_SELECTABLE_ZONE_AF, 1218 mSelectableZoneAfValues); 1219 1220 //Set Face Detection 1221 if(supportsFaceDetection()){ 1222 mParameters.set(QCameraParameters::KEY_FACE_DETECTION, 1223 QCameraParameters::FACE_DETECTION_OFF); 1224 mParameters.set(QCameraParameters::KEY_SUPPORTED_FACE_DETECTION, 1225 mFaceDetectionValues); 1226 } 1227 1228 //Set Red Eye Reduction 1229 mParameters.set(QCameraParameters::KEY_REDEYE_REDUCTION, 1230 QCameraParameters::REDEYE_REDUCTION_DISABLE); 1231 mParameters.set(QCameraParameters::KEY_SUPPORTED_REDEYE_REDUCTION, 1232 mRedeyeReductionValues); 1233 1234 //Set ZSL 1235 mParameters.set(QCameraParameters::KEY_ZSL, 1236 QCameraParameters::ZSL_OFF); 1237 mParameters.set(QCameraParameters::KEY_SUPPORTED_ZSL_MODES, 1238 mZslValues); 1239 1240 //Set Focal length, horizontal and vertical view angles 1241 focus_distances_info_t focalLength; 1242 float horizontalViewAngle = 0.0f; 1243 float verticalViewAngle = 0.0f; 1244 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_FOCAL_LENGTH, 1245 (void *)&focalLength); 1246 mParameters.setFloat(QCameraParameters::KEY_FOCAL_LENGTH, 1247 focalLength.focus_distance[0]); 1248 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_HORIZONTAL_VIEW_ANGLE, 1249 (void *)&horizontalViewAngle); 1250 mParameters.setFloat(QCameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, 1251 horizontalViewAngle); 1252 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_VERTICAL_VIEW_ANGLE, 1253 (void *)&verticalViewAngle); 1254 mParameters.setFloat(QCameraParameters::KEY_VERTICAL_VIEW_ANGLE, 1255 verticalViewAngle); 1256 1257 //Set Aperture 1258 float f_number = 0.0f; 1259 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_F_NUMBER, 1260 (void *)&f_number); 1261 mExifValues.f_number = getRational(f_number*F_NUMBER_DECIMAL_PRECISION, F_NUMBER_DECIMAL_PRECISION); 1262 1263 //Set Exposure Compensation 1264 mParameters.set( 1265 QCameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, 1266 EXPOSURE_COMPENSATION_MAXIMUM_NUMERATOR); 1267 mParameters.set( 1268 QCameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, 1269 EXPOSURE_COMPENSATION_MINIMUM_NUMERATOR); 1270 mParameters.set( 1271 QCameraParameters::KEY_EXPOSURE_COMPENSATION, 1272 EXPOSURE_COMPENSATION_DEFAULT_NUMERATOR); 1273 mParameters.setFloat( 1274 QCameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, 1275 EXPOSURE_COMPENSATION_STEP); 1276 1277 mParameters.set("num-snaps-per-shutter", 1); 1278 1279 mParameters.set("capture-burst-captures-values", getZSLQueueDepth()); 1280 mParameters.set("capture-burst-interval-supported", "true"); 1281 mParameters.set("capture-burst-interval-max", BURST_INTREVAL_MAX); /*skip frames*/ 1282 mParameters.set("capture-burst-interval-min", BURST_INTREVAL_MIN); /*skip frames*/ 1283 mParameters.set("capture-burst-interval", BURST_INTREVAL_DEFAULT); /*skip frames*/ 1284 mParameters.set("capture-burst-retroactive", 0); 1285 mParameters.set("capture-burst-retroactive-max", getZSLQueueDepth()); 1286 mParameters.set("capture-burst-exposures", ""); 1287 mParameters.set("capture-burst-exposures-values", 1288 "-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12"); 1289 { 1290 String8 CamModeStr; 1291 char buffer[32]; 1292 int flag = 0; 1293 1294 for (int i = 0; i < HAL_CAM_MODE_MAX; i++) { 1295 if ( 0 ) { /*exclude some conflicting case*/ 1296 } else { 1297 if (flag == 0) { /*first item*/ 1298 snprintf(buffer, sizeof(buffer), "%d", i); 1299 } else { 1300 snprintf(buffer, sizeof(buffer), ",%d", i); 1301 } 1302 flag = 1; 1303 CamModeStr.append(buffer); 1304 } 1305 } 1306 mParameters.set("camera-mode-values", CamModeStr); 1307 } 1308 1309 mParameters.set("ae-bracket-hdr-values", 1310 create_values_str(hdr_bracket, sizeof(hdr_bracket)/sizeof(str_map) )); 1311 1312 // if(mIs3DModeOn) 1313 // mParameters.set("3d-frame-format", "left-right"); 1314 mParameters.set("no-display-mode", 0); 1315 //mUseOverlay = useOverlay(); 1316 mParameters.set("zoom", 0); 1317 1318 int mNuberOfVFEOutputs; 1319 ret = cam_config_get_parm(mCameraId, MM_CAMERA_PARM_VFE_OUTPUT_ENABLE, &mNuberOfVFEOutputs); 1320 if(ret != MM_CAMERA_OK) { 1321 ALOGE("get parm MM_CAMERA_PARM_VFE_OUTPUT_ENABLE failed"); 1322 ret = BAD_VALUE; 1323 } 1324 if(mNuberOfVFEOutputs == 1) 1325 { 1326 mParameters.set(QCameraParameters::KEY_SINGLE_ISP_OUTPUT_ENABLED, "true"); 1327 } else { 1328 mParameters.set(QCameraParameters::KEY_SINGLE_ISP_OUTPUT_ENABLED, "false"); 1329 } 1330 1331 if (setParameters(mParameters) != NO_ERROR) { 1332 ALOGE("Failed to set default parameters?!"); 1333 } 1334 1335 mNoDisplayMode = 0; 1336 mLedStatusForZsl = LED_MODE_OFF; 1337 1338 mInitialized = true; 1339 strTexturesOn = false; 1340 1341 ALOGV("%s: X", __func__); 1342 return; 1343 } 1344 1345 /** 1346 * Set the camera parameters. This returns BAD_VALUE if any parameter is 1347 * invalid or not supported. 1348 */ 1349 1350 int QCameraHardwareInterface::setParameters(const char *parms) 1351 { 1352 QCameraParameters param; 1353 String8 str = String8(parms); 1354 param.unflatten(str); 1355 status_t ret = setParameters(param); 1356 if(ret == NO_ERROR) 1357 return 0; 1358 else 1359 return -1; 1360 } 1361 1362 /** 1363 * Set the camera parameters. This returns BAD_VALUE if any parameter is 1364 * invalid or not supported. */ 1365 status_t QCameraHardwareInterface::setParameters(const QCameraParameters& params) 1366 { 1367 status_t ret = NO_ERROR; 1368 1369 ALOGV("%s: E", __func__); 1370 // Mutex::Autolock l(&mLock); 1371 status_t rc, final_rc = NO_ERROR; 1372 1373 if ((rc = setPowerMode(params))) final_rc = rc; 1374 if ((rc = setPreviewSize(params))) final_rc = rc; 1375 if ((rc = setVideoSize(params))) final_rc = rc; 1376 if ((rc = setPictureSize(params))) final_rc = rc; 1377 if ((rc = setJpegThumbnailSize(params))) final_rc = rc; 1378 if ((rc = setJpegQuality(params))) final_rc = rc; 1379 if ((rc = setEffect(params))) final_rc = rc; 1380 if ((rc = setGpsLocation(params))) final_rc = rc; 1381 if ((rc = setRotation(params))) final_rc = rc; 1382 if ((rc = setZoom(params))) final_rc = rc; 1383 if ((rc = setOrientation(params))) final_rc = rc; 1384 if ((rc = setLensshadeValue(params))) final_rc = rc; 1385 if ((rc = setMCEValue(params))) final_rc = rc; 1386 if ((rc = setPictureFormat(params))) final_rc = rc; 1387 if ((rc = setSharpness(params))) final_rc = rc; 1388 if ((rc = setSaturation(params))) final_rc = rc; 1389 if ((rc = setSceneMode(params))) final_rc = rc; 1390 if ((rc = setContrast(params))) final_rc = rc; 1391 // if ((rc = setFaceDetect(params))) final_rc = rc; 1392 if ((rc = setStrTextures(params))) final_rc = rc; 1393 if ((rc = setPreviewFormat(params))) final_rc = rc; 1394 if ((rc = setSkinToneEnhancement(params))) final_rc = rc; 1395 if ((rc = setWaveletDenoise(params))) final_rc = rc; 1396 if ((rc = setAntibanding(params))) final_rc = rc; 1397 // if ((rc = setOverlayFormats(params))) final_rc = rc; 1398 if ((rc = setRedeyeReduction(params))) final_rc = rc; 1399 if ((rc = setCaptureBurstExp())) final_rc = rc; 1400 1401 const char *str_val = params.get("capture-burst-exposures"); 1402 if ( str_val == NULL || strlen(str_val)==0 ) { 1403 char burst_exp[PROPERTY_VALUE_MAX]; 1404 memset(burst_exp, 0, sizeof(burst_exp)); 1405 property_get("persist.capture.burst.exposures", burst_exp, ""); 1406 if ( strlen(burst_exp)>0 ) { 1407 mParameters.set("capture-burst-exposures", burst_exp); 1408 } 1409 } else { 1410 mParameters.set("capture-burst-exposures", str_val); 1411 } 1412 mParameters.set("num-snaps-per-shutter", params.get("num-snaps-per-shutter")); 1413 1414 if ((rc = setAEBracket(params))) final_rc = rc; 1415 // if ((rc = setDenoise(params))) final_rc = rc; 1416 if ((rc = setPreviewFpsRange(params))) final_rc = rc; 1417 if((rc = setRecordingHint(params))) final_rc = rc; 1418 if ((rc = setNumOfSnapshot(params))) final_rc = rc; 1419 if ((rc = setAecAwbLock(params))) final_rc = rc; 1420 if ((rc = setWhiteBalance(params))) final_rc = rc; 1421 const char *str = params.get(QCameraParameters::KEY_SCENE_MODE); 1422 int32_t value = attr_lookup(scenemode, sizeof(scenemode) / sizeof(str_map), str); 1423 1424 if((value != NOT_FOUND) && (value == CAMERA_BESTSHOT_OFF )) { 1425 //if ((rc = setPreviewFrameRateMode(params))) final_rc = rc; 1426 if ((rc = setPreviewFrameRate(params))) final_rc = rc; 1427 if ((rc = setBrightness(params))) final_rc = rc; 1428 if ((rc = setISOValue(params))) final_rc = rc; 1429 if ((rc = setFocusAreas(params))) final_rc = rc; 1430 if ((rc = setMeteringAreas(params))) final_rc = rc; 1431 } 1432 if ((rc = setFocusMode(params))) final_rc = rc; 1433 if ((rc = setAutoExposure(params))) final_rc = rc; 1434 if ((rc = setExposureCompensation(params))) final_rc = rc; 1435 if ((rc = setFlash(params))) final_rc = rc; 1436 //selectableZoneAF needs to be invoked after continuous AF 1437 if ((rc = setSelectableZoneAf(params))) final_rc = rc; 1438 // setHighFrameRate needs to be done at end, as there can 1439 // be a preview restart, and need to use the updated parameters 1440 if ((rc = setHighFrameRate(params))) final_rc = rc; 1441 if ((rc = setZSLBurstLookBack(params))) final_rc = rc; 1442 if ((rc = setZSLBurstInterval(params))) final_rc = rc; 1443 if ((rc = setNoDisplayMode(params))) final_rc = rc; 1444 1445 //Update Exiftag values. 1446 setExifTags(); 1447 1448 ALOGV("%s: X", __func__); 1449 return final_rc; 1450 } 1451 1452 /** Retrieve the camera parameters. The buffer returned by the camera HAL 1453 must be returned back to it with put_parameters, if put_parameters 1454 is not NULL. 1455 */ 1456 int QCameraHardwareInterface::getParameters(char **parms) 1457 { 1458 char* rc = NULL; 1459 String8 str; 1460 QCameraParameters param = getParameters(); 1461 //param.dump(); 1462 str = param.flatten( ); 1463 rc = (char *)malloc(sizeof(char)*(str.length()+1)); 1464 if(rc != NULL){ 1465 memset(rc, 0, sizeof(char)*(str.length()+1)); 1466 strncpy(rc, str.string(), str.length()); 1467 rc[str.length()] = 0; 1468 *parms = rc; 1469 } 1470 return 0; 1471 } 1472 1473 /** The camera HAL uses its own memory to pass us the parameters when we 1474 call get_parameters. Use this function to return the memory back to 1475 the camera HAL, if put_parameters is not NULL. If put_parameters 1476 is NULL, then you have to use free() to release the memory. 1477 */ 1478 void QCameraHardwareInterface::putParameters(char *rc) 1479 { 1480 free(rc); 1481 rc = NULL; 1482 } 1483 1484 QCameraParameters& QCameraHardwareInterface::getParameters() 1485 { 1486 Mutex::Autolock lock(mLock); 1487 mParameters.set(QCameraParameters::KEY_FOCUS_DISTANCES, mFocusDistance.string()); 1488 const char *str = mParameters.get(QCameraParameters::KEY_SCENE_MODE); 1489 if (mHasAutoFocusSupport && strcmp(str, "auto")) { 1490 mParameters.set(QCameraParameters::KEY_FOCUS_MODE, 1491 QCameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE); 1492 } 1493 return mParameters; 1494 } 1495 1496 status_t QCameraHardwareInterface::runFaceDetection() 1497 { 1498 bool ret = true; 1499 1500 const char *str = mParameters.get(QCameraParameters::KEY_FACE_DETECTION); 1501 if (str != NULL) { 1502 int value = attr_lookup(facedetection, 1503 sizeof(facedetection) / sizeof(str_map), str); 1504 fd_set_parm_t fd_set_parm; 1505 int requested_faces = mParameters.getInt(QCameraParameters::KEY_MAX_NUM_REQUESTED_FACES); 1506 fd_set_parm.fd_mode = value; 1507 fd_set_parm.num_fd = requested_faces; 1508 ret = native_set_parms(MM_CAMERA_PARM_FD, sizeof(fd_set_parm_t), (void *)&fd_set_parm); 1509 return ret ? NO_ERROR : UNKNOWN_ERROR; 1510 } 1511 ALOGE("Invalid Face Detection value: %s", (str == NULL) ? "NULL" : str); 1512 return BAD_VALUE; 1513 } 1514 1515 status_t QCameraHardwareInterface::setSharpness(const QCameraParameters& params) 1516 { 1517 bool ret = false; 1518 int rc = MM_CAMERA_OK; 1519 ALOGV("%s",__func__); 1520 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_SHARPNESS); 1521 if(!rc) { 1522 ALOGV("%s:CONTRAST not supported", __func__); 1523 return NO_ERROR; 1524 } 1525 int sharpness = params.getInt(QCameraParameters::KEY_SHARPNESS); 1526 if((sharpness < CAMERA_MIN_SHARPNESS 1527 || sharpness > CAMERA_MAX_SHARPNESS)) 1528 return UNKNOWN_ERROR; 1529 1530 ALOGV("setting sharpness %d", sharpness); 1531 mParameters.set(QCameraParameters::KEY_SHARPNESS, sharpness); 1532 ret = native_set_parms(MM_CAMERA_PARM_SHARPNESS, sizeof(sharpness), 1533 (void *)&sharpness); 1534 return ret ? NO_ERROR : UNKNOWN_ERROR; 1535 } 1536 1537 status_t QCameraHardwareInterface::setSaturation(const QCameraParameters& params) 1538 { 1539 bool ret = false; 1540 int rc = MM_CAMERA_OK; 1541 ALOGV("%s",__func__); 1542 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_SATURATION); 1543 if(!rc) { 1544 ALOGV("%s:MM_CAMERA_PARM_SATURATION not supported", __func__); 1545 return NO_ERROR; 1546 } 1547 int result; 1548 int saturation = params.getInt(QCameraParameters::KEY_SATURATION); 1549 1550 if((saturation < CAMERA_MIN_SATURATION) 1551 || (saturation > CAMERA_MAX_SATURATION)) 1552 return UNKNOWN_ERROR; 1553 1554 ALOGV("Setting saturation %d", saturation); 1555 mParameters.set(QCameraParameters::KEY_SATURATION, saturation); 1556 ret = native_set_parms(MM_CAMERA_PARM_SATURATION, sizeof(saturation), 1557 (void *)&saturation, (int *)&result); 1558 if(result != MM_CAMERA_OK) 1559 ALOGV("Saturation Value: %d is not set as the selected value is not supported", saturation); 1560 return ret ? NO_ERROR : UNKNOWN_ERROR; 1561 } 1562 1563 status_t QCameraHardwareInterface::setContrast(const QCameraParameters& params) 1564 { 1565 ALOGV("%s E", __func__ ); 1566 int rc = MM_CAMERA_OK; 1567 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_CONTRAST); 1568 if(!rc) { 1569 ALOGV("%s:CONTRAST not supported", __func__); 1570 return NO_ERROR; 1571 } 1572 const char *str = params.get(QCameraParameters::KEY_SCENE_MODE); 1573 ALOGV("Contrast : %s",str); 1574 int32_t value = attr_lookup(scenemode, sizeof(scenemode) / sizeof(str_map), str); 1575 if(value == CAMERA_BESTSHOT_OFF) { 1576 int contrast = params.getInt(QCameraParameters::KEY_CONTRAST); 1577 if((contrast < CAMERA_MIN_CONTRAST) 1578 || (contrast > CAMERA_MAX_CONTRAST)) 1579 { 1580 ALOGV("Contrast Value not matching"); 1581 return UNKNOWN_ERROR; 1582 } 1583 ALOGV("setting contrast %d", contrast); 1584 mParameters.set(QCameraParameters::KEY_CONTRAST, contrast); 1585 ALOGV("Calling Contrast set on Lower layer"); 1586 bool ret = native_set_parms(MM_CAMERA_PARM_CONTRAST, sizeof(contrast), 1587 (void *)&contrast); 1588 ALOGV("Lower layer returned %d", ret); 1589 int bestshot_reconfigure; 1590 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_BESTSHOT_RECONFIGURE, 1591 &bestshot_reconfigure); 1592 if(bestshot_reconfigure) { 1593 if (mContrast != contrast) { 1594 mContrast = contrast; 1595 if (mPreviewState == QCAMERA_HAL_PREVIEW_STARTED && ret) { 1596 mRestartPreview = 1; 1597 pausePreviewForZSL(); 1598 } 1599 } 1600 } 1601 return ret ? NO_ERROR : UNKNOWN_ERROR; 1602 } else { 1603 ALOGV(" Contrast value will not be set " \ 1604 "when the scenemode selected is %s", str); 1605 return NO_ERROR; 1606 } 1607 return BAD_VALUE; 1608 } 1609 1610 status_t QCameraHardwareInterface::setSceneDetect(const QCameraParameters& params) 1611 { 1612 ALOGV("%s",__func__); 1613 bool retParm; 1614 int rc = MM_CAMERA_OK; 1615 1616 rc = cam_config_is_parm_supported(mCameraId,MM_CAMERA_PARM_ASD_ENABLE); 1617 if(!rc) { 1618 ALOGV("%s:MM_CAMERA_PARM_ASD_ENABLE not supported", __func__); 1619 return NO_ERROR; 1620 } 1621 1622 const char *str = params.get(QCameraParameters::KEY_SCENE_DETECT); 1623 ALOGV("Scene Detect string : %s",str); 1624 if (str != NULL) { 1625 int32_t value = attr_lookup(scenedetect, sizeof(scenedetect) / sizeof(str_map), str); 1626 ALOGV("Scenedetect Value : %d",value); 1627 if (value != NOT_FOUND) { 1628 mParameters.set(QCameraParameters::KEY_SCENE_DETECT, str); 1629 1630 retParm = native_set_parms(MM_CAMERA_PARM_ASD_ENABLE, sizeof(value), 1631 (void *)&value); 1632 1633 return retParm ? NO_ERROR : UNKNOWN_ERROR; 1634 } 1635 } 1636 return BAD_VALUE; 1637 } 1638 1639 status_t QCameraHardwareInterface::setZoom(const QCameraParameters& params) 1640 { 1641 status_t rc = NO_ERROR; 1642 1643 ALOGV("%s: E",__func__); 1644 1645 1646 if( !( cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_ZOOM))) { 1647 ALOGV("%s:MM_CAMERA_PARM_ZOOM not supported", __func__); 1648 return NO_ERROR; 1649 } 1650 // No matter how many different zoom values the driver can provide, HAL 1651 // provides applictations the same number of zoom levels. The maximum driver 1652 // zoom value depends on sensor output (VFE input) and preview size (VFE 1653 // output) because VFE can only crop and cannot upscale. If the preview size 1654 // is bigger, the maximum zoom ratio is smaller. However, we want the 1655 // zoom ratio of each zoom level is always the same whatever the preview 1656 // size is. Ex: zoom level 1 is always 1.2x, zoom level 2 is 1.44x, etc. So, 1657 // we need to have a fixed maximum zoom value and do read it from the 1658 // driver. 1659 static const int ZOOM_STEP = 1; 1660 int32_t zoom_level = params.getInt("zoom"); 1661 if(zoom_level >= 0 && zoom_level <= mMaxZoom-1) { 1662 mParameters.set("zoom", zoom_level); 1663 int32_t zoom_value = ZOOM_STEP * zoom_level; 1664 bool ret = native_set_parms(MM_CAMERA_PARM_ZOOM, 1665 sizeof(zoom_value), (void *)&zoom_value); 1666 if(ret) { 1667 mCurrentZoom=zoom_level; 1668 } 1669 rc = ret ? NO_ERROR : UNKNOWN_ERROR; 1670 } else { 1671 rc = BAD_VALUE; 1672 } 1673 ALOGV("%s X",__func__); 1674 return rc; 1675 1676 } 1677 1678 status_t QCameraHardwareInterface::setISOValue(const QCameraParameters& params) { 1679 1680 status_t rc = NO_ERROR; 1681 ALOGV("%s",__func__); 1682 1683 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_ISO); 1684 if(!rc) { 1685 ALOGV("%s:MM_CAMERA_PARM_ISO not supported", __func__); 1686 return NO_ERROR; 1687 } 1688 const char *str = params.get(QCameraParameters::KEY_ISO_MODE); 1689 ALOGV("ISO string : %s", str); 1690 int8_t temp_hjr; 1691 if (str != NULL) { 1692 int value = (camera_iso_mode_type)attr_lookup( 1693 iso, sizeof(iso) / sizeof(str_map), str); 1694 ALOGV("ISO string : %s", str); 1695 if (value != NOT_FOUND) { 1696 camera_iso_mode_type temp = (camera_iso_mode_type) value; 1697 if (value == CAMERA_ISO_DEBLUR) { 1698 temp_hjr = true; 1699 native_set_parms(MM_CAMERA_PARM_HJR, sizeof(int8_t), (void*)&temp_hjr); 1700 mHJR = value; 1701 } 1702 else { 1703 if (mHJR == CAMERA_ISO_DEBLUR) { 1704 temp_hjr = false; 1705 native_set_parms(MM_CAMERA_PARM_HJR, sizeof(int8_t), (void*)&temp_hjr); 1706 mHJR = value; 1707 } 1708 } 1709 1710 mParameters.set(QCameraParameters::KEY_ISO_MODE, str); 1711 native_set_parms(MM_CAMERA_PARM_ISO, sizeof(camera_iso_mode_type), (void *)&temp); 1712 mIsoValue = (int)temp; 1713 return NO_ERROR; 1714 } 1715 } 1716 return BAD_VALUE; 1717 } 1718 1719 status_t QCameraHardwareInterface::updateFocusDistances() 1720 { 1721 ALOGV("%s: IN", __FUNCTION__); 1722 focus_distances_info_t focusDistances; 1723 if(cam_config_get_parm(mCameraId, MM_CAMERA_PARM_FOCUS_DISTANCES, 1724 &focusDistances) == MM_CAMERA_OK) { 1725 String8 str; 1726 char buffer[32] = {0}; 1727 //set all distances to infinity if focus mode is infinity 1728 if(mFocusMode == AF_MODE_INFINITY) { 1729 snprintf(buffer, sizeof(buffer), "Infinity,"); 1730 str.append(buffer); 1731 snprintf(buffer, sizeof(buffer), "Infinity,"); 1732 str.append(buffer); 1733 snprintf(buffer, sizeof(buffer), "Infinity"); 1734 str.append(buffer); 1735 } else { 1736 snprintf(buffer, sizeof(buffer), "%f", focusDistances.focus_distance[0]); 1737 str.append(buffer); 1738 snprintf(buffer, sizeof(buffer), ",%f", focusDistances.focus_distance[1]); 1739 str.append(buffer); 1740 snprintf(buffer, sizeof(buffer), ",%f", focusDistances.focus_distance[2]); 1741 str.append(buffer); 1742 } 1743 ALOGV("%s: setting KEY_FOCUS_DISTANCES as %s", __FUNCTION__, str.string()); 1744 mFocusDistance = str; 1745 return NO_ERROR; 1746 } 1747 ALOGE("%s: get CAMERA_PARM_FOCUS_DISTANCES failed!!!", __FUNCTION__); 1748 return BAD_VALUE; 1749 } 1750 1751 // Parse string like "(1, 2, 3, 4, ..., N)" 1752 // num is pointer to an allocated array of size N 1753 static int parseNDimVector(const char *str, int *num, int N, char delim = ',') 1754 { 1755 char *start, *end; 1756 if(num == NULL) { 1757 ALOGE("Invalid output array (num == NULL)"); 1758 return -1; 1759 } 1760 //check if string starts and ends with parantheses 1761 if(str[0] != '(' || str[strlen(str)-1] != ')') { 1762 ALOGE("Invalid format of string %s, valid format is (n1, n2, n3, n4 ...)", str); 1763 return -1; 1764 } 1765 start = (char*) str; 1766 start++; 1767 for(int i=0; i<N; i++) { 1768 *(num+i) = (int) strtol(start, &end, 10); 1769 if(*end != delim && i < N-1) { 1770 ALOGE("Cannot find delimeter '%c' in string \"%s\". end = %c", delim, str, *end); 1771 return -1; 1772 } 1773 start = end+1; 1774 } 1775 return 0; 1776 } 1777 1778 // parse string like "(1, 2, 3, 4, 5),(1, 2, 3, 4, 5),..." 1779 static int parseCameraAreaString(const char* str, int max_num_areas, 1780 camera_area_t *pAreas, int *num_areas_found) 1781 { 1782 char area_str[32]; 1783 const char *start, *end, *p; 1784 start = str; end = NULL; 1785 int values[5], index=0; 1786 *num_areas_found = 0; 1787 1788 while(start != NULL) { 1789 if(*start != '(') { 1790 ALOGE("%s: error: Ill formatted area string: %s", __func__, str); 1791 return -1; 1792 } 1793 end = strchr(start, ')'); 1794 if(end == NULL) { 1795 ALOGE("%s: error: Ill formatted area string: %s", __func__, str); 1796 return -1; 1797 } 1798 int i; 1799 for (i=0,p=start; p<=end; p++, i++) { 1800 area_str[i] = *p; 1801 } 1802 area_str[i] = '\0'; 1803 if(parseNDimVector(area_str, values, 5) < 0){ 1804 ALOGE("%s: error: Failed to parse the area string: %s", __func__, area_str); 1805 return -1; 1806 } 1807 // no more areas than max_num_areas are accepted. 1808 if(index >= max_num_areas) { 1809 ALOGE("%s: error: too many areas specified %s", __func__, str); 1810 return -1; 1811 } 1812 pAreas[index].x1 = values[0]; 1813 pAreas[index].y1 = values[1]; 1814 pAreas[index].x2 = values[2]; 1815 pAreas[index].y2 = values[3]; 1816 pAreas[index].weight = values[4]; 1817 1818 index++; 1819 start = strchr(end, '('); // serach for next '(' 1820 } 1821 (*num_areas_found) = index; 1822 return 0; 1823 } 1824 static bool validateCameraAreas(camera_area_t *areas, int num_areas) 1825 { 1826 for(int i=0; i<num_areas; i++) { 1827 1828 // handle special case (0, 0, 0, 0, 0) 1829 if((areas[i].x1 == 0) && (areas[i].y1 == 0) 1830 && (areas[i].x2 == 0) && (areas[i].y2 == 0) && (areas[i].weight == 0)) { 1831 continue; 1832 } 1833 if(areas[i].x1 < -1000) return false; // left should be >= -1000 1834 if(areas[i].y1 < -1000) return false; // top should be >= -1000 1835 if(areas[i].x2 > 1000) return false; // right should be <= 1000 1836 if(areas[i].y2 > 1000) return false; // bottom should be <= 1000 1837 if(areas[i].weight <= 0 || areas[i].weight > 1000) // weight should be in [1, 1000] 1838 return false; 1839 if(areas[i].x1 >= areas[i].x2) { // left should be < right 1840 return false; 1841 } 1842 if(areas[i].y1 >= areas[i].y2) // top should be < bottom 1843 return false; 1844 } 1845 return true; 1846 } 1847 1848 status_t QCameraHardwareInterface::setFocusAreas(const QCameraParameters& params) 1849 { 1850 ALOGV("%s: E", __func__); 1851 status_t rc; 1852 int max_num_af_areas = mParameters.getInt(QCameraParameters::KEY_MAX_NUM_FOCUS_AREAS); 1853 if(max_num_af_areas == 0) { 1854 return NO_ERROR; 1855 } 1856 const char *str = params.get(QCameraParameters::KEY_FOCUS_AREAS); 1857 if (str == NULL) { 1858 ALOGE("%s: Parameter string is null", __func__); 1859 rc = NO_ERROR; 1860 } else { 1861 camera_area_t *areas = new camera_area_t[max_num_af_areas]; 1862 int num_areas_found=0; 1863 if(parseCameraAreaString(str, max_num_af_areas, areas, &num_areas_found) < 0) { 1864 ALOGE("%s: Failed to parse the string: %s", __func__, str); 1865 delete areas; 1866 return BAD_VALUE; 1867 } 1868 for(int i=0; i<num_areas_found; i++) { 1869 ALOGV("FocusArea[%d] = (%d, %d, %d, %d, %d)", i, (areas[i].x1), (areas[i].y1), 1870 (areas[i].x2), (areas[i].y2), (areas[i].weight)); 1871 } 1872 if(validateCameraAreas(areas, num_areas_found) == false) { 1873 ALOGE("%s: invalid areas specified : %s", __func__, str); 1874 delete areas; 1875 return BAD_VALUE; 1876 } 1877 mParameters.set(QCameraParameters::KEY_FOCUS_AREAS, str); 1878 num_areas_found = 1; //temp; need to change after the multi-roi is enabled 1879 1880 //if the native_set_parms is called when preview is not started, it 1881 //crashes in lower layer, so return of preview is not started 1882 if(mPreviewState == QCAMERA_HAL_PREVIEW_STOPPED) { 1883 delete areas; 1884 return NO_ERROR; 1885 } 1886 1887 //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0, 1888 //so no action is takenby the lower layer 1889 if(num_areas_found == 1 && (areas[0].x1 == 0) && (areas[0].y1 == 0) 1890 && (areas[0].x2 == 0) && (areas[0].y2 == 0) && (areas[0].weight == 0)) { 1891 num_areas_found = 0; 1892 } 1893 #if 1 //temp solution 1894 1895 roi_info_t af_roi_value; 1896 memset(&af_roi_value, 0, sizeof(roi_info_t)); 1897 uint16_t x1, x2, y1, y2, dx, dy; 1898 int previewWidth, previewHeight; 1899 this->getPreviewSize(&previewWidth, &previewHeight); 1900 //transform the coords from (-1000, 1000) to (0, previewWidth or previewHeight) 1901 x1 = (uint16_t)((areas[0].x1 + 1000.0f)*(previewWidth/2000.0f)); 1902 y1 = (uint16_t)((areas[0].y1 + 1000.0f)*(previewHeight/2000.0f)); 1903 x2 = (uint16_t)((areas[0].x2 + 1000.0f)*(previewWidth/2000.0f)); 1904 y2 = (uint16_t)((areas[0].y2 + 1000.0f)*(previewHeight/2000.0f)); 1905 dx = x2 - x1; 1906 dy = y2 - y1; 1907 1908 af_roi_value.num_roi = num_areas_found; 1909 af_roi_value.roi[0].x = x1; 1910 af_roi_value.roi[0].y = y1; 1911 af_roi_value.roi[0].dx = dx; 1912 af_roi_value.roi[0].dy = dy; 1913 af_roi_value.is_multiwindow = 0; 1914 if (native_set_parms(MM_CAMERA_PARM_AF_ROI, sizeof(roi_info_t), (void*)&af_roi_value)) 1915 rc = NO_ERROR; 1916 else 1917 rc = BAD_VALUE; 1918 delete areas; 1919 #endif 1920 #if 0 //better solution with multi-roi, to be enabled later 1921 af_mtr_area_t afArea; 1922 afArea.num_area = num_areas_found; 1923 1924 uint16_t x1, x2, y1, y2, dx, dy; 1925 int previewWidth, previewHeight; 1926 this->getPreviewSize(&previewWidth, &previewHeight); 1927 1928 for(int i=0; i<num_areas_found; i++) { 1929 //transform the coords from (-1000, 1000) to (0, previewWidth or previewHeight) 1930 x1 = (uint16_t)((areas[i].x1 + 1000.0f)*(previewWidth/2000.0f)); 1931 y1 = (uint16_t)((areas[i].y1 + 1000.0f)*(previewHeight/2000.0f)); 1932 x2 = (uint16_t)((areas[i].x2 + 1000.0f)*(previewWidth/2000.0f)); 1933 y2 = (uint16_t)((areas[i].y2 + 1000.0f)*(previewHeight/2000.0f)); 1934 dx = x2 - x1; 1935 dy = y2 - y1; 1936 afArea.mtr_area[i].x = x1; 1937 afArea.mtr_area[i].y = y1; 1938 afArea.mtr_area[i].dx = dx; 1939 afArea.mtr_area[i].dy = dy; 1940 afArea.weight[i] = areas[i].weight; 1941 } 1942 1943 if(native_set_parms(MM_CAMERA_PARM_AF_MTR_AREA, sizeof(af_mtr_area_t), (void*)&afArea)) 1944 rc = NO_ERROR; 1945 else 1946 rc = BAD_VALUE;*/ 1947 #endif 1948 } 1949 ALOGV("%s: X", __func__); 1950 return rc; 1951 } 1952 1953 status_t QCameraHardwareInterface::setMeteringAreas(const QCameraParameters& params) 1954 { 1955 ALOGV("%s: E", __func__); 1956 status_t rc; 1957 int max_num_mtr_areas = mParameters.getInt(QCameraParameters::KEY_MAX_NUM_METERING_AREAS); 1958 if(max_num_mtr_areas == 0) { 1959 return NO_ERROR; 1960 } 1961 1962 const char *str = params.get(QCameraParameters::KEY_METERING_AREAS); 1963 if (str == NULL) { 1964 ALOGE("%s: Parameter string is null", __func__); 1965 rc = NO_ERROR; 1966 } else { 1967 camera_area_t *areas = new camera_area_t[max_num_mtr_areas]; 1968 int num_areas_found=0; 1969 if(parseCameraAreaString(str, max_num_mtr_areas, areas, &num_areas_found) < 0) { 1970 ALOGE("%s: Failed to parse the string: %s", __func__, str); 1971 delete areas; 1972 return BAD_VALUE; 1973 } 1974 for(int i=0; i<num_areas_found; i++) { 1975 ALOGV("MeteringArea[%d] = (%d, %d, %d, %d, %d)", i, (areas[i].x1), (areas[i].y1), 1976 (areas[i].x2), (areas[i].y2), (areas[i].weight)); 1977 } 1978 if(validateCameraAreas(areas, num_areas_found) == false) { 1979 ALOGE("%s: invalid areas specified : %s", __func__, str); 1980 delete areas; 1981 return BAD_VALUE; 1982 } 1983 mParameters.set(QCameraParameters::KEY_METERING_AREAS, str); 1984 1985 //if the native_set_parms is called when preview is not started, it 1986 //crashes in lower layer, so return of preview is not started 1987 if(mPreviewState == QCAMERA_HAL_PREVIEW_STOPPED) { 1988 delete areas; 1989 return NO_ERROR; 1990 } 1991 1992 num_areas_found = 1; //temp; need to change after the multi-roi is enabled 1993 1994 //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0, 1995 //so no action is takenby the lower layer 1996 if(num_areas_found == 1 && (areas[0].x1 == 0) && (areas[0].y1 == 0) 1997 && (areas[0].x2 == 0) && (areas[0].y2 == 0) && (areas[0].weight == 0)) { 1998 num_areas_found = 0; 1999 } 2000 #if 1 2001 cam_set_aec_roi_t aec_roi_value; 2002 uint16_t x1, x2, y1, y2; 2003 int previewWidth, previewHeight; 2004 this->getPreviewSize(&previewWidth, &previewHeight); 2005 //transform the coords from (-1000, 1000) to (0, previewWidth or previewHeight) 2006 x1 = (uint16_t)((areas[0].x1 + 1000.0f)*(previewWidth/2000.0f)); 2007 y1 = (uint16_t)((areas[0].y1 + 1000.0f)*(previewHeight/2000.0f)); 2008 x2 = (uint16_t)((areas[0].x2 + 1000.0f)*(previewWidth/2000.0f)); 2009 y2 = (uint16_t)((areas[0].y2 + 1000.0f)*(previewHeight/2000.0f)); 2010 delete areas; 2011 2012 if(num_areas_found == 1) { 2013 aec_roi_value.aec_roi_enable = AEC_ROI_ON; 2014 aec_roi_value.aec_roi_type = AEC_ROI_BY_COORDINATE; 2015 aec_roi_value.aec_roi_position.coordinate.x = (x1+x2)/2; 2016 aec_roi_value.aec_roi_position.coordinate.y = (y1+y2)/2; 2017 } else { 2018 aec_roi_value.aec_roi_enable = AEC_ROI_OFF; 2019 aec_roi_value.aec_roi_type = AEC_ROI_BY_COORDINATE; 2020 aec_roi_value.aec_roi_position.coordinate.x = DONT_CARE_COORDINATE; 2021 aec_roi_value.aec_roi_position.coordinate.y = DONT_CARE_COORDINATE; 2022 } 2023 2024 if(native_set_parms(MM_CAMERA_PARM_AEC_ROI, sizeof(cam_set_aec_roi_t), (void *)&aec_roi_value)) 2025 rc = NO_ERROR; 2026 else 2027 rc = BAD_VALUE; 2028 #endif 2029 #if 0 //solution including multi-roi, to be enabled later 2030 aec_mtr_area_t aecArea; 2031 aecArea.num_area = num_areas_found; 2032 2033 uint16_t x1, x2, y1, y2, dx, dy; 2034 int previewWidth, previewHeight; 2035 this->getPreviewSize(&previewWidth, &previewHeight); 2036 2037 for(int i=0; i<num_areas_found; i++) { 2038 //transform the coords from (-1000, 1000) to (0, previewWidth or previewHeight) 2039 x1 = (uint16_t)((areas[i].x1 + 1000.0f)*(previewWidth/2000.0f)); 2040 y1 = (uint16_t)((areas[i].y1 + 1000.0f)*(previewHeight/2000.0f)); 2041 x2 = (uint16_t)((areas[i].x2 + 1000.0f)*(previewWidth/2000.0f)); 2042 y2 = (uint16_t)((areas[i].y2 + 1000.0f)*(previewHeight/2000.0f)); 2043 dx = x2 - x1; 2044 dy = y2 - y1; 2045 aecArea.mtr_area[i].x = x1; 2046 aecArea.mtr_area[i].y = y1; 2047 aecArea.mtr_area[i].dx = dx; 2048 aecArea.mtr_area[i].dy = dy; 2049 aecArea.weight[i] = areas[i].weight; 2050 } 2051 delete areas; 2052 2053 if(native_set_parms(MM_CAMERA_PARM_AEC_MTR_AREA, sizeof(aec_mtr_area_t), (void*)&aecArea)) 2054 rc = NO_ERROR; 2055 else 2056 rc = BAD_VALUE; 2057 #endif 2058 } 2059 ALOGV("%s: X", __func__); 2060 return rc; 2061 } 2062 2063 status_t QCameraHardwareInterface::setFocusMode(const QCameraParameters& params) 2064 { 2065 const char *str = params.get(QCameraParameters::KEY_FOCUS_MODE); 2066 const char *prev_str = mParameters.get(QCameraParameters::KEY_FOCUS_MODE); 2067 ALOGV("%s",__func__); 2068 if (str != NULL) { 2069 ALOGV("Focus mode %s",str); 2070 int32_t value = attr_lookup(focus_modes, 2071 sizeof(focus_modes) / sizeof(str_map), str); 2072 if (value != NOT_FOUND) { 2073 mParameters.set(QCameraParameters::KEY_FOCUS_MODE, str); 2074 mFocusMode = value; 2075 2076 if(updateFocusDistances() != NO_ERROR) { 2077 ALOGE("%s: updateFocusDistances failed for %s", __FUNCTION__, str); 2078 return UNKNOWN_ERROR; 2079 } 2080 mParameters.set(QCameraParameters::KEY_FOCUS_DISTANCES, mFocusDistance.string()); 2081 if(mHasAutoFocusSupport){ 2082 bool ret = native_set_parms(MM_CAMERA_PARM_FOCUS_MODE, 2083 sizeof(value), 2084 (void *)&value); 2085 2086 int cafSupport = false; 2087 int caf_type=0; 2088 const char *str_hdr = mParameters.get(QCameraParameters::KEY_SCENE_MODE); 2089 if(!strcmp(str, QCameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO) || 2090 !strcmp(str, QCameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE)){ 2091 cafSupport = true; 2092 bool rc = false; 2093 if(!strcmp(str, QCameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO)) 2094 { 2095 caf_type = 1; 2096 rc = native_set_parms(MM_CAMERA_PARM_CAF_TYPE, sizeof(caf_type), (void *)&caf_type); 2097 } 2098 else if(!strcmp(str, QCameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE)) 2099 { 2100 caf_type = 2; 2101 rc = native_set_parms(MM_CAMERA_PARM_CAF_TYPE, sizeof(caf_type), (void *)&caf_type); 2102 } 2103 ALOGV("caf_type %d rc %d", caf_type, rc); 2104 } 2105 ALOGV("Continuous Auto Focus %d", cafSupport); 2106 if(mAutoFocusRunning && cafSupport){ 2107 mAutoFocusRunning = false; 2108 if(MM_CAMERA_OK!=cam_ops_action(mCameraId,false,MM_CAMERA_OPS_FOCUS,NULL )) { 2109 ALOGE("%s: AF command failed err:%d error %s",__func__, errno,strerror(errno)); 2110 } 2111 } 2112 ret = native_set_parms(MM_CAMERA_PARM_CONTINUOUS_AF, sizeof(cafSupport), 2113 (void *)&cafSupport); 2114 } 2115 2116 return NO_ERROR; 2117 } 2118 ALOGV("%s:Could not look up str value",__func__); 2119 } 2120 ALOGE("Invalid focus mode value: %s", (str == NULL) ? "NULL" : str); 2121 return BAD_VALUE; 2122 } 2123 2124 status_t QCameraHardwareInterface::setSceneMode(const QCameraParameters& params) 2125 { 2126 status_t rc = NO_ERROR; 2127 ALOGV("%s",__func__); 2128 2129 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_BESTSHOT_MODE); 2130 if(!rc) { 2131 ALOGV("%s:Parameter Scenemode is not supported for this sensor", __func__); 2132 return NO_ERROR; 2133 } 2134 const char *str = params.get(QCameraParameters::KEY_SCENE_MODE); 2135 const char *oldstr = mParameters.get(QCameraParameters::KEY_SCENE_MODE); 2136 2137 if (str != NULL && oldstr != NULL) { 2138 int32_t value = attr_lookup(scenemode, sizeof(scenemode) / sizeof(str_map), str); 2139 if (value != NOT_FOUND) { 2140 /* Check to see if there was a change of scene mode */ 2141 if(strcmp(str,oldstr)) { 2142 ALOGV("%s: valued changed from %s to %s",__func__,oldstr, str); 2143 2144 /* Check if we are either transitioning to/from HDR state 2145 if yes preview needs restart*/ 2146 if(!strcmp(str, "hdr") || !strcmp(oldstr, "hdr") ) { 2147 ALOGV("Changed between HDR/non-HDR states"); 2148 2149 /* Restart only if preview already running*/ 2150 if (mPreviewState == QCAMERA_HAL_PREVIEW_STARTED) { 2151 ALOGV("Preview in progress,restarting for HDR transition"); 2152 mParameters.set(QCameraParameters::KEY_SCENE_MODE, str); 2153 mRestartPreview = 1; 2154 pausePreviewForZSL(); 2155 } 2156 } 2157 } 2158 2159 mParameters.set(QCameraParameters::KEY_SCENE_MODE, str); 2160 bool ret = native_set_parms(MM_CAMERA_PARM_BESTSHOT_MODE, sizeof(value), 2161 (void *)&value); 2162 int bestshot_reconfigure; 2163 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_BESTSHOT_RECONFIGURE, 2164 &bestshot_reconfigure); 2165 if(bestshot_reconfigure) { 2166 if (mBestShotMode != value) { 2167 mBestShotMode = value; 2168 if (mPreviewState == QCAMERA_HAL_PREVIEW_STARTED && ret) { 2169 ALOGV("%s:Bestshot trigerring restart",__func__); 2170 mRestartPreview = 1; 2171 pausePreviewForZSL(); 2172 } 2173 } 2174 } 2175 return ret ? NO_ERROR : UNKNOWN_ERROR; 2176 } 2177 } 2178 ALOGE("Invalid scenemode value: %s", (str == NULL) ? "NULL" : str); 2179 return BAD_VALUE; 2180 } 2181 2182 status_t QCameraHardwareInterface::setSelectableZoneAf(const QCameraParameters& params) 2183 { 2184 ALOGV("%s",__func__); 2185 status_t rc = NO_ERROR; 2186 if(mHasAutoFocusSupport) { 2187 const char *str = params.get(QCameraParameters::KEY_SELECTABLE_ZONE_AF); 2188 if (str != NULL) { 2189 int32_t value = attr_lookup(selectable_zone_af, sizeof(selectable_zone_af) / sizeof(str_map), str); 2190 if (value != NOT_FOUND) { 2191 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_FOCUS_RECT); 2192 if(!rc) { 2193 ALOGV("SelectableZoneAF is not supported for this sensor"); 2194 return NO_ERROR; 2195 }else { 2196 mParameters.set(QCameraParameters::KEY_SELECTABLE_ZONE_AF, str); 2197 bool ret = native_set_parms(MM_CAMERA_PARM_FOCUS_RECT, sizeof(value), 2198 (void *)&value); 2199 return ret ? NO_ERROR : UNKNOWN_ERROR; 2200 } 2201 } 2202 } 2203 ALOGE("Invalid selectable zone af value: %s", (str == NULL) ? "NULL" : str); 2204 return BAD_VALUE; 2205 2206 } 2207 return NO_ERROR; 2208 } 2209 2210 status_t QCameraHardwareInterface::setEffect(const QCameraParameters& params) 2211 { 2212 ALOGV("%s",__func__); 2213 status_t rc = NO_ERROR; 2214 const char *str = params.get(QCameraParameters::KEY_EFFECT); 2215 int result; 2216 if (str != NULL) { 2217 ALOGV("Setting effect %s",str); 2218 int32_t value = attr_lookup(effects, sizeof(effects) / sizeof(str_map), str); 2219 if (value != NOT_FOUND) { 2220 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_EFFECT); 2221 if(!rc) { 2222 ALOGV("Camera Effect - %s mode is not supported for this sensor",str); 2223 return NO_ERROR; 2224 }else { 2225 mParameters.set(QCameraParameters::KEY_EFFECT, str); 2226 bool ret = native_set_parms(MM_CAMERA_PARM_EFFECT, sizeof(value), 2227 (void *)&value,(int *)&result); 2228 if(result != MM_CAMERA_OK) { 2229 ALOGE("Camera Effect: %s is not set as the selected value is not supported ", str); 2230 } 2231 int bestshot_reconfigure; 2232 cam_config_get_parm(mCameraId, MM_CAMERA_PARM_BESTSHOT_RECONFIGURE, 2233 &bestshot_reconfigure); 2234 if(bestshot_reconfigure) { 2235 if (mEffects != value) { 2236 mEffects = value; 2237 if (mPreviewState == QCAMERA_HAL_PREVIEW_STARTED && ret) { 2238 mRestartPreview = 1; 2239 pausePreviewForZSL(); 2240 } 2241 } 2242 } 2243 return ret ? NO_ERROR : UNKNOWN_ERROR; 2244 } 2245 } 2246 } 2247 ALOGE("Invalid effect value: %s", (str == NULL) ? "NULL" : str); 2248 ALOGV("setEffect X"); 2249 return BAD_VALUE; 2250 } 2251 2252 status_t QCameraHardwareInterface::setBrightness(const QCameraParameters& params) { 2253 2254 ALOGV("%s",__func__); 2255 status_t rc = NO_ERROR; 2256 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_BRIGHTNESS); 2257 if(!rc) { 2258 ALOGV("MM_CAMERA_PARM_BRIGHTNESS mode is not supported for this sensor"); 2259 return NO_ERROR; 2260 } 2261 int brightness = params.getInt("luma-adaptation"); 2262 if (mBrightness != brightness) { 2263 ALOGV(" new brightness value : %d ", brightness); 2264 mBrightness = brightness; 2265 mParameters.set("luma-adaptation", brightness); 2266 bool ret = native_set_parms(MM_CAMERA_PARM_BRIGHTNESS, sizeof(mBrightness), 2267 (void *)&mBrightness); 2268 return ret ? NO_ERROR : UNKNOWN_ERROR; 2269 } 2270 2271 return NO_ERROR; 2272 } 2273 2274 status_t QCameraHardwareInterface::setAutoExposure(const QCameraParameters& params) 2275 { 2276 2277 ALOGV("%s",__func__); 2278 status_t rc = NO_ERROR; 2279 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_EXPOSURE); 2280 if(!rc) { 2281 ALOGV("MM_CAMERA_PARM_EXPOSURE mode is not supported for this sensor"); 2282 return NO_ERROR; 2283 } 2284 const char *str = params.get(QCameraParameters::KEY_AUTO_EXPOSURE); 2285 if (str != NULL) { 2286 int32_t value = attr_lookup(autoexposure, sizeof(autoexposure) / sizeof(str_map), str); 2287 if (value != NOT_FOUND) { 2288 mParameters.set(QCameraParameters::KEY_AUTO_EXPOSURE, str); 2289 bool ret = native_set_parms(MM_CAMERA_PARM_EXPOSURE, sizeof(value), 2290 (void *)&value); 2291 return ret ? NO_ERROR : UNKNOWN_ERROR; 2292 } 2293 } 2294 ALOGE("Invalid auto exposure value: %s", (str == NULL) ? "NULL" : str); 2295 return BAD_VALUE; 2296 } 2297 2298 status_t QCameraHardwareInterface::setExposureCompensation( 2299 const QCameraParameters & params){ 2300 ALOGV("%s",__func__); 2301 status_t rc = NO_ERROR; 2302 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_EXPOSURE_COMPENSATION); 2303 if(!rc) { 2304 ALOGV("MM_CAMERA_PARM_EXPOSURE_COMPENSATION mode is not supported for this sensor"); 2305 return NO_ERROR; 2306 } 2307 int numerator = params.getInt(QCameraParameters::KEY_EXPOSURE_COMPENSATION); 2308 if(EXPOSURE_COMPENSATION_MINIMUM_NUMERATOR <= numerator && 2309 numerator <= EXPOSURE_COMPENSATION_MAXIMUM_NUMERATOR){ 2310 int16_t numerator16 = (int16_t)(numerator & 0x0000ffff); 2311 uint16_t denominator16 = EXPOSURE_COMPENSATION_DENOMINATOR; 2312 uint32_t value = 0; 2313 value = numerator16 << 16 | denominator16; 2314 2315 const char *sce_str = params.get(QCameraParameters::KEY_SCENE_MODE); 2316 if (sce_str != NULL) { 2317 if(!strcmp(sce_str, "sunset")){ 2318 //Exposure comp value in sunset scene mode 2319 mParameters.set(QCameraParameters::KEY_EXPOSURE_COMPENSATION, 2320 -6); 2321 }else{ 2322 //Exposure comp value for other 2323 mParameters.set(QCameraParameters::KEY_EXPOSURE_COMPENSATION, 2324 numerator); 2325 } 2326 }else { 2327 mParameters.set(QCameraParameters::KEY_EXPOSURE_COMPENSATION, 2328 numerator); 2329 } 2330 bool ret = native_set_parms(MM_CAMERA_PARM_EXPOSURE_COMPENSATION, 2331 sizeof(value), (void *)&value); 2332 return ret ? NO_ERROR : UNKNOWN_ERROR; 2333 } 2334 ALOGE("Invalid Exposure Compensation"); 2335 return BAD_VALUE; 2336 } 2337 2338 status_t QCameraHardwareInterface::setWhiteBalance(const QCameraParameters& params) 2339 { 2340 2341 ALOGV("%s",__func__); 2342 status_t rc = NO_ERROR; 2343 int result; 2344 const char *str = NULL; 2345 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_WHITE_BALANCE); 2346 if(!rc) { 2347 ALOGV("MM_CAMERA_PARM_WHITE_BALANCE mode is not supported for this sensor"); 2348 return NO_ERROR; 2349 } 2350 2351 const char *sce_str = params.get(QCameraParameters::KEY_SCENE_MODE); 2352 if (sce_str != NULL) { 2353 if(!strcmp(sce_str, "sunset")){ 2354 //AWB value in sunset scene mode 2355 str = QCameraParameters::WHITE_BALANCE_DAYLIGHT; 2356 mParameters.set(QCameraParameters::KEY_WHITE_BALANCE, str); 2357 }else if(!strcmp(sce_str, "auto")){ 2358 str = params.get(QCameraParameters::KEY_WHITE_BALANCE); 2359 }else{ 2360 //AWB in other scene Mode 2361 str = QCameraParameters::WHITE_BALANCE_AUTO; 2362 mParameters.set(QCameraParameters::KEY_WHITE_BALANCE, str); 2363 } 2364 }else { 2365 str = params.get(QCameraParameters::KEY_WHITE_BALANCE); 2366 } 2367 2368 if (str != NULL) { 2369 int32_t value = attr_lookup(whitebalance, sizeof(whitebalance) / sizeof(str_map), str); 2370 if (value != NOT_FOUND) { 2371 mParameters.set(QCameraParameters::KEY_WHITE_BALANCE, str); 2372 bool ret = native_set_parms(MM_CAMERA_PARM_WHITE_BALANCE, sizeof(value), 2373 (void *)&value, (int *)&result); 2374 if(result != MM_CAMERA_OK) { 2375 ALOGE("WhiteBalance Value: %s is not set as the selected value is not supported ", str); 2376 } 2377 return ret ? NO_ERROR : UNKNOWN_ERROR; 2378 } 2379 } 2380 ALOGE("Invalid whitebalance value: %s", (str == NULL) ? "NULL" : str); 2381 return BAD_VALUE; 2382 } 2383 2384 status_t QCameraHardwareInterface::setAntibanding(const QCameraParameters& params) 2385 { 2386 int result; 2387 2388 ALOGV("%s",__func__); 2389 status_t rc = NO_ERROR; 2390 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_ANTIBANDING); 2391 if(!rc) { 2392 ALOGV("ANTIBANDING mode is not supported for this sensor"); 2393 return NO_ERROR; 2394 } 2395 const char *str = params.get(QCameraParameters::KEY_ANTIBANDING); 2396 if (str != NULL) { 2397 int value = (camera_antibanding_type)attr_lookup( 2398 antibanding, sizeof(antibanding) / sizeof(str_map), str); 2399 if (value != NOT_FOUND) { 2400 camera_antibanding_type temp = (camera_antibanding_type) value; 2401 ALOGV("Antibanding Value : %d",value); 2402 mParameters.set(QCameraParameters::KEY_ANTIBANDING, str); 2403 bool ret = native_set_parms(MM_CAMERA_PARM_ANTIBANDING, 2404 sizeof(camera_antibanding_type), (void *)&value ,(int *)&result); 2405 if(result != MM_CAMERA_OK) { 2406 ALOGE("AntiBanding Value: %s is not supported for the given BestShot Mode", str); 2407 } 2408 return ret ? NO_ERROR : UNKNOWN_ERROR; 2409 } 2410 } 2411 ALOGE("Invalid antibanding value: %s", (str == NULL) ? "NULL" : str); 2412 2413 return BAD_VALUE; 2414 } 2415 2416 status_t QCameraHardwareInterface::setPreviewFrameRate(const QCameraParameters& params) 2417 { 2418 ALOGV("%s",__func__); 2419 status_t rc = NO_ERROR; 2420 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_FPS); 2421 if(!rc) { 2422 ALOGV("MM_CAMERA_PARM_FPS is not supported for this sensor"); 2423 return NO_ERROR; 2424 } 2425 uint16_t previousFps = (uint16_t)mParameters.getPreviewFrameRate(); 2426 uint16_t fps = (uint16_t)params.getPreviewFrameRate(); 2427 ALOGV("requested preview frame rate is %u", fps); 2428 2429 if(mInitialized && (fps == previousFps)){ 2430 ALOGV("No change is FPS Value %d",fps ); 2431 return NO_ERROR; 2432 } 2433 2434 if(MINIMUM_FPS <= fps && fps <=MAXIMUM_FPS){ 2435 mParameters.setPreviewFrameRate(fps); 2436 bool ret = native_set_parms(MM_CAMERA_PARM_FPS, 2437 sizeof(fps), (void *)&fps); 2438 return ret ? NO_ERROR : UNKNOWN_ERROR; 2439 } 2440 2441 return BAD_VALUE; 2442 } 2443 2444 status_t QCameraHardwareInterface::setPreviewFrameRateMode(const QCameraParameters& params) { 2445 2446 ALOGV("%s",__func__); 2447 status_t rc = NO_ERROR; 2448 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_FPS); 2449 if(!rc) { 2450 ALOGV(" CAMERA FPS mode is not supported for this sensor"); 2451 return NO_ERROR; 2452 } 2453 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_FPS_MODE); 2454 if(!rc) { 2455 ALOGV("CAMERA FPS MODE mode is not supported for this sensor"); 2456 return NO_ERROR; 2457 } 2458 2459 const char *previousMode = mParameters.getPreviewFrameRateMode(); 2460 const char *str = params.getPreviewFrameRateMode(); 2461 if (NULL == previousMode) { 2462 ALOGV("Preview Frame Rate Mode is NULL\n"); 2463 return NO_ERROR; 2464 } 2465 if (NULL == str) { 2466 ALOGV("Preview Frame Rate Mode is NULL\n"); 2467 return NO_ERROR; 2468 } 2469 int32_t frameRateMode = attr_lookup(frame_rate_modes, sizeof(frame_rate_modes) / sizeof(str_map),str); 2470 if(frameRateMode != NOT_FOUND) { 2471 ALOGV("setPreviewFrameRateMode: %s ", str); 2472 mParameters.setPreviewFrameRateMode(str); 2473 bool ret = native_set_parms(MM_CAMERA_PARM_FPS_MODE, sizeof(frameRateMode), (void *)&frameRateMode); 2474 if(!ret) return ret; 2475 //set the fps value when chaging modes 2476 int16_t fps = (uint16_t)params.getPreviewFrameRate(); 2477 if(MINIMUM_FPS <= fps && fps <=MAXIMUM_FPS){ 2478 mParameters.setPreviewFrameRate(fps); 2479 ret = native_set_parms(MM_CAMERA_PARM_FPS, 2480 sizeof(fps), (void *)&fps); 2481 return ret ? NO_ERROR : UNKNOWN_ERROR; 2482 } 2483 ALOGE("Invalid preview frame rate value: %d", fps); 2484 return BAD_VALUE; 2485 } 2486 ALOGE("Invalid preview frame rate mode value: %s", (str == NULL) ? "NULL" : str); 2487 2488 return BAD_VALUE; 2489 } 2490 2491 status_t QCameraHardwareInterface::setSkinToneEnhancement(const QCameraParameters& params) { 2492 ALOGV("%s",__func__); 2493 status_t rc = NO_ERROR; 2494 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_SCE_FACTOR); 2495 if(!rc) { 2496 ALOGV("SkinToneEnhancement is not supported for this sensor"); 2497 return NO_ERROR; 2498 } 2499 int skinToneValue = params.getInt("skinToneEnhancement"); 2500 if (mSkinToneEnhancement != skinToneValue) { 2501 ALOGV(" new skinTone correction value : %d ", skinToneValue); 2502 mSkinToneEnhancement = skinToneValue; 2503 mParameters.set("skinToneEnhancement", skinToneValue); 2504 bool ret = native_set_parms(MM_CAMERA_PARM_SCE_FACTOR, sizeof(mSkinToneEnhancement), 2505 (void *)&mSkinToneEnhancement); 2506 return ret ? NO_ERROR : UNKNOWN_ERROR; 2507 } 2508 return NO_ERROR; 2509 } 2510 2511 status_t QCameraHardwareInterface::setWaveletDenoise(const QCameraParameters& params) { 2512 ALOGV("%s",__func__); 2513 status_t rc = NO_ERROR; 2514 rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_WAVELET_DENOISE); 2515 if(rc != MM_CAMERA_PARM_SUPPORT_SET) { 2516 ALOGV("Wavelet Denoise is not supported for this sensor"); 2517 /* TO DO */ 2518 // return NO_ERROR; 2519 } 2520 const char *str = params.get(QCameraParameters::KEY_DENOISE); 2521 if (str != NULL) { 2522 int value = attr_lookup(denoise, 2523 sizeof(denoise) / sizeof(str_map), str); 2524 if ((value != NOT_FOUND) && (mDenoiseValue != value)) { 2525 mDenoiseValue = value; 2526 mParameters.set(QCameraParameters::KEY_DENOISE, str); 2527 2528 char prop[PROPERTY_VALUE_MAX]; 2529 memset(prop, 0, sizeof(prop)); 2530 property_get("persist.denoise.process.plates", prop, "1"); 2531 2532 denoise_param_t temp; 2533 memset(&temp, 0, sizeof(denoise_param_t)); 2534 temp.denoise_enable = value; 2535 temp.process_plates = atoi(prop); 2536 ALOGV("Denoise enable=%d, plates=%d", temp.denoise_enable, temp.process_plates); 2537 bool ret = native_set_parms(MM_CAMERA_PARM_WAVELET_DENOISE, sizeof(temp), 2538 (void *)&temp); 2539 return ret ? NO_ERROR : UNKNOWN_ERROR; 2540 } 2541 return NO_ERROR; 2542 } 2543 ALOGE("Invalid Denoise value: %s", (str == NULL) ? "NULL" : str); 2544 return BAD_VALUE; 2545 } 2546 2547 status_t QCameraHardwareInterface::setVideoSize(const QCameraParameters& params) 2548 { 2549 const char *str= NULL; 2550 const char *str_t= NULL; 2551 int old_vid_w = 0, old_vid_h = 0; 2552 ALOGV("%s: E", __func__); 2553 str = params.get(QCameraParameters::KEY_VIDEO_SIZE); 2554 str_t = mParameters.get(CameraParameters::KEY_VIDEO_SIZE); 2555 if(!str) { 2556 mParameters.set(QCameraParameters::KEY_VIDEO_SIZE, ""); 2557 //If application didn't set this parameter string, use the values from 2558 //getPreviewSize() as video dimensions. 2559 ALOGV("No Record Size requested, use the preview dimensions"); 2560 mVideoWidth = mPreviewWidth; 2561 mVideoHeight = mPreviewHeight; 2562 } else { 2563 //Extract the record witdh and height that application requested. 2564 ALOGV("%s: requested record size %s", __func__, str); 2565 if(!parse_size(str, mVideoWidth, mVideoHeight)) { 2566 parse_size(str_t, old_vid_w, old_vid_h); 2567 if(old_vid_w != mVideoWidth || old_vid_h != mVideoHeight) { 2568 mRestartPreview = true; 2569 ALOGV("%s: Video sizes changes, Restart preview...", __func__); 2570 } 2571 mParameters.set(QCameraParameters::KEY_VIDEO_SIZE, str); 2572 } else { 2573 mParameters.set(QCameraParameters::KEY_VIDEO_SIZE, ""); 2574 ALOGE("%s: error :failed to parse parameter record-size (%s)", __func__, str); 2575 return BAD_VALUE; 2576 } 2577 } 2578 ALOGV("%s: preview dimensions: %dx%d", __func__, mPreviewWidth, mPreviewHeight); 2579 ALOGV("%s: video dimensions: %dx%d", __func__, mVideoWidth, mVideoHeight); 2580 2581 ALOGV("%s: X", __func__); 2582 return NO_ERROR; 2583 } 2584 2585 status_t QCameraHardwareInterface::setCameraMode(const QCameraParameters& params) { 2586 int32_t value = params.getInt(QCameraParameters::KEY_CAMERA_MODE); 2587 mParameters.set(QCameraParameters::KEY_CAMERA_MODE,value); 2588 2589 ALOGV("ZSL is enabled %d", value); 2590 if (value == 1) { 2591 myMode = (camera_mode_t)(myMode | CAMERA_ZSL_MODE); 2592 } else { 2593 myMode = (camera_mode_t)(myMode & ~CAMERA_ZSL_MODE); 2594 } 2595 2596 return NO_ERROR; 2597 } 2598 2599 status_t QCameraHardwareInterface::setPowerMode(const QCameraParameters& params) { 2600 uint32_t value = NORMAL_POWER; 2601 const char *powermode = NULL; 2602 2603 powermode = params.get(QCameraParameters::KEY_POWER_MODE); 2604 if (powermode != NULL) { 2605 value = attr_lookup(power_modes, 2606 sizeof(power_modes) / sizeof(str_map), powermode); 2607 if((value == LOW_POWER) || mHFRLevel > 1) { 2608 ALOGV("Enable Low Power Mode"); 2609 value = LOW_POWER; 2610 mPowerMode = value; 2611 mParameters.set(QCameraParameters::KEY_POWER_MODE,"Low_Power"); 2612 } else { 2613 ALOGV("Enable Normal Power Mode"); 2614 mPowerMode = value; 2615 mParameters.set(QCameraParameters::KEY_POWER_MODE,"Normal_Power"); 2616 } 2617 } 2618 2619 ALOGV("%s Low power mode %s value = %d", __func__, 2620 value ? "Enabled" : "Disabled", value); 2621 native_set_parms(MM_CAMERA_PARM_LOW_POWER_MODE, sizeof(value), 2622 (void *)&value); 2623 return NO_ERROR; 2624 } 2625 2626 2627 status_t QCameraHardwareInterface::setPreviewSize(const QCameraParameters& params) 2628 { 2629 int width, height; 2630 params.getPreviewSize(&width, &height); 2631 ALOGV("################requested preview size %d x %d", width, height); 2632 2633 // Validate the preview size 2634 for (size_t i = 0; i < mPreviewSizeCount; ++i) { 2635 if (width == mPreviewSizes[i].width 2636 && height == mPreviewSizes[i].height) { 2637 int old_width, old_height; 2638 mParameters.getPreviewSize(&old_width,&old_height); 2639 if(width != old_width || height != old_height) { 2640 mRestartPreview = true; 2641 } 2642 mParameters.setPreviewSize(width, height); 2643 ALOGV("setPreviewSize: width: %d heigh: %d", width, height); 2644 mPreviewWidth = width; 2645 mPreviewHeight = height; 2646 2647 mDimension.display_width = mPreviewWidth; 2648 mDimension.display_height= mPreviewHeight; 2649 mDimension.orig_video_width = mPreviewWidth; 2650 mDimension.orig_video_height = mPreviewHeight; 2651 mDimension.video_width = mPreviewWidth; 2652 mDimension.video_height = mPreviewHeight; 2653 2654 return NO_ERROR; 2655 } 2656 } 2657 ALOGE("Invalid preview size requested: %dx%d", width, height); 2658 return BAD_VALUE; 2659 } 2660 status_t QCameraHardwareInterface::setPreviewFpsRange(const QCameraParameters& params) 2661 { 2662 ALOGV("%s: E", __func__); 2663 int minFps,maxFps; 2664 int prevMinFps, prevMaxFps; 2665 int rc = NO_ERROR; 2666 bool found = false; 2667 2668 mParameters.getPreviewFpsRange(&prevMinFps, &prevMaxFps); 2669 ALOGV("%s: Existing FpsRange Values:(%d, %d)", __func__, prevMinFps, prevMaxFps); 2670 params.getPreviewFpsRange(&minFps,&maxFps); 2671 ALOGV("%s: Requested FpsRange Values:(%d, %d)", __func__, minFps, maxFps); 2672 2673 if(mInitialized && (minFps == prevMinFps && maxFps == prevMaxFps)) { 2674 ALOGV("%s: No change in FpsRange", __func__); 2675 rc = NO_ERROR; 2676 goto end; 2677 } 2678 for(size_t i=0; i<FPS_RANGES_SUPPORTED_COUNT; i++) { 2679 // if the value is in the supported list 2680 if(minFps==FpsRangesSupported[i].minFPS && maxFps == FpsRangesSupported[i].maxFPS){ 2681 found = true; 2682 ALOGV("FPS: i=%d : minFps = %d, maxFps = %d ",i,FpsRangesSupported[i].minFPS,FpsRangesSupported[i].maxFPS ); 2683 mParameters.setPreviewFpsRange(minFps,maxFps); 2684 // validate the values 2685 bool valid = true; 2686 // FPS can not be negative 2687 if(minFps < 0 || maxFps < 0) valid = false; 2688 // minFps must be >= maxFps 2689 if(minFps > maxFps) valid = false; 2690 2691 if(valid) { 2692 //Set the FPS mode 2693 const char *str = (minFps == maxFps) ? 2694 QCameraParameters::KEY_PREVIEW_FRAME_RATE_FIXED_MODE: 2695 QCameraParameters::KEY_PREVIEW_FRAME_RATE_AUTO_MODE; 2696 ALOGV("%s FPS_MODE = %s", __func__, str); 2697 int32_t frameRateMode = attr_lookup(frame_rate_modes, 2698 sizeof(frame_rate_modes) / sizeof(str_map),str); 2699 bool ret; 2700 ret = native_set_parms(MM_CAMERA_PARM_FPS_MODE, sizeof(int32_t), 2701 (void *)&frameRateMode); 2702 2703 //set FPS values 2704 uint32_t fps; //lower 2 bytes specify maxFps and higher 2 bytes specify minFps 2705 fps = ((uint32_t)(minFps/1000) << 16) + ((uint16_t)(maxFps/1000)); 2706 ret = native_set_parms(MM_CAMERA_PARM_FPS, sizeof(uint32_t), (void *)&fps); 2707 mParameters.setPreviewFpsRange(minFps, maxFps); 2708 if(ret) 2709 rc = NO_ERROR; 2710 else { 2711 rc = BAD_VALUE; 2712 ALOGE("%s: error: native_set_params failed", __func__); 2713 } 2714 } else { 2715 ALOGE("%s: error: invalid FPS range value", __func__); 2716 rc = BAD_VALUE; 2717 } 2718 } 2719 } 2720 if(found == false){ 2721 ALOGE("%s: error: FPS range value not supported", __func__); 2722 rc = BAD_VALUE; 2723 } 2724 end: 2725 ALOGV("%s: X", __func__); 2726 return rc; 2727 } 2728 2729 status_t QCameraHardwareInterface::setJpegThumbnailSize(const QCameraParameters& params){ 2730 int width = params.getInt(QCameraParameters::KEY_JPEG_THUMBNAIL_WIDTH); 2731 int height = params.getInt(QCameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT); 2732 2733 ALOGV("requested jpeg thumbnail size %d x %d", width, height); 2734 2735 // Validate the picture size 2736 for (unsigned int i = 0; i < thumbnail_sizes_count; ++i) { 2737 if (width == default_thumbnail_sizes[i].width 2738 && height == default_thumbnail_sizes[i].height) { 2739 thumbnailWidth = width; 2740 thumbnailHeight = height; 2741 mParameters.set(QCameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, width); 2742 mParameters.set(QCameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, height); 2743 return NO_ERROR; 2744 } 2745 } 2746 ALOGE("error: setting jpeg thumbnail size"); 2747 return BAD_VALUE; 2748 } 2749 status_t QCameraHardwareInterface::setPictureSize(const QCameraParameters& params) 2750 { 2751 int width, height; 2752 ALOGV("QualcommCameraHardware::setPictureSize E"); 2753 params.getPictureSize(&width, &height); 2754 ALOGV("requested picture size %d x %d", width, height); 2755 2756 // Validate the picture size 2757 for (int i = 0; i < mSupportedPictureSizesCount; ++i) { 2758 if (width == mPictureSizesPtr[i].width 2759 && height == mPictureSizesPtr[i].height) { 2760 int old_width, old_height; 2761 mParameters.getPictureSize(&old_width,&old_height); 2762 if(width != old_width || height != old_height) { 2763 mRestartPreview = true; 2764 } 2765 mParameters.setPictureSize(width, height); 2766 mDimension.picture_width = width; 2767 mDimension.picture_height = height; 2768 return NO_ERROR; 2769 } 2770 } 2771 /* Dimension not among the ones in the list. Check if 2772 * its a valid dimension, if it is, then configure the 2773 * camera accordingly. else reject it. 2774 */ 2775 if( isValidDimension(width, height) ) { 2776 mParameters.setPictureSize(width, height); 2777 mDimension.picture_width = width; 2778 mDimension.picture_height = height; 2779 return NO_ERROR; 2780 } else 2781 ALOGE("Invalid picture size requested: %dx%d", width, height); 2782 return BAD_VALUE; 2783 } 2784 2785 status_t QCameraHardwareInterface::setJpegRotation(int isZsl) { 2786 return mm_jpeg_encoder_setRotation(mRotation, isZsl); 2787 } 2788 2789 int QCameraHardwareInterface::getJpegRotation(void) { 2790 return mRotation; 2791 } 2792 2793 int QCameraHardwareInterface::getISOSpeedValue() 2794 { 2795 const char *iso_str = mParameters.get(QCameraParameters::KEY_ISO_MODE); 2796 int iso_index = attr_lookup(iso, sizeof(iso) / sizeof(str_map), iso_str); 2797 int iso_value = iso_speed_values[iso_index]; 2798 return iso_value; 2799 } 2800 2801 2802 status_t QCameraHardwareInterface::setJpegQuality(const QCameraParameters& params) { 2803 status_t rc = NO_ERROR; 2804 int quality = params.getInt(QCameraParameters::KEY_JPEG_QUALITY); 2805 ALOGV("setJpegQuality E"); 2806 if (quality >= 0 && quality <= 100) { 2807 mParameters.set(QCameraParameters::KEY_JPEG_QUALITY, quality); 2808 mJpegQuality = quality; 2809 } else { 2810 ALOGE("Invalid jpeg quality=%d", quality); 2811 rc = BAD_VALUE; 2812 } 2813 2814 quality = params.getInt(QCameraParameters::KEY_JPEG_THUMBNAIL_QUALITY); 2815 if (quality >= 0 && quality <= 100) { 2816 mParameters.set(QCameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, quality); 2817 } else { 2818 ALOGE("Invalid jpeg thumbnail quality=%d", quality); 2819 rc = BAD_VALUE; 2820 } 2821 ALOGV("setJpegQuality X"); 2822 return rc; 2823 } 2824 2825 status_t QCameraHardwareInterface:: 2826 setNumOfSnapshot(const QCameraParameters& params) { 2827 status_t rc = NO_ERROR; 2828 2829 int num_of_snapshot = getNumOfSnapshots(params); 2830 2831 if (num_of_snapshot <= 0) { 2832 num_of_snapshot = 1; 2833 } 2834 ALOGV("number of snapshots = %d", num_of_snapshot); 2835 mParameters.set("num-snaps-per-shutter", num_of_snapshot); 2836 2837 bool result = native_set_parms(MM_CAMERA_PARM_SNAPSHOT_BURST_NUM, 2838 sizeof(int), 2839 (void *)&num_of_snapshot); 2840 if(!result) 2841 ALOGE("%s:Failure setting number of snapshots!!!", __func__); 2842 return rc; 2843 } 2844 2845 status_t QCameraHardwareInterface::setPreviewFormat(const QCameraParameters& params) { 2846 const char *str = params.getPreviewFormat(); 2847 int32_t previewFormat = attr_lookup(preview_formats, sizeof(preview_formats) / sizeof(str_map), str); 2848 if(previewFormat != NOT_FOUND) { 2849 int num = sizeof(preview_format_info_list)/sizeof(preview_format_info_t); 2850 int i; 2851 2852 for (i = 0; i < num; i++) { 2853 if (preview_format_info_list[i].Hal_format == previewFormat) { 2854 mPreviewFormatInfo = preview_format_info_list[i]; 2855 break; 2856 } 2857 } 2858 2859 if (i == num) { 2860 mPreviewFormatInfo.mm_cam_format = CAMERA_YUV_420_NV21; 2861 mPreviewFormatInfo.padding = CAMERA_PAD_TO_WORD; 2862 return BAD_VALUE; 2863 } 2864 bool ret = native_set_parms(MM_CAMERA_PARM_PREVIEW_FORMAT, sizeof(cam_format_t), 2865 (void *)&mPreviewFormatInfo.mm_cam_format); 2866 mParameters.set(QCameraParameters::KEY_PREVIEW_FORMAT, str); 2867 mPreviewFormat = mPreviewFormatInfo.mm_cam_format; 2868 ALOGV("Setting preview format to %d, i =%d, num=%d, hal_format=%d", 2869 mPreviewFormat, i, num, mPreviewFormatInfo.Hal_format); 2870 return NO_ERROR; 2871 } else if ( strTexturesOn ) { 2872 mPreviewFormatInfo.mm_cam_format = CAMERA_YUV_420_NV21; 2873 mPreviewFormatInfo.padding = CAMERA_PAD_TO_4K; 2874 } else { 2875 mPreviewFormatInfo.mm_cam_format = CAMERA_YUV_420_NV21; 2876 mPreviewFormatInfo.padding = CAMERA_PAD_TO_WORD; 2877 } 2878 ALOGE("Invalid preview format value: %s", (str == NULL) ? "NULL" : str); 2879 return BAD_VALUE; 2880 } 2881 2882 status_t QCameraHardwareInterface::setStrTextures(const QCameraParameters& params) { 2883 const char *str = params.get("strtextures"); 2884 const char *prev_str = mParameters.get("strtextures"); 2885 2886 if(str != NULL) { 2887 if(!strcmp(str,prev_str)) { 2888 return NO_ERROR; 2889 } 2890 int str_size = strlen(str); 2891 mParameters.set("strtextures", str); 2892 if(str_size == 2) { 2893 if(!strncmp(str, "on", str_size) || !strncmp(str, "ON", str_size)){ 2894 ALOGV("Resetting mUseOverlay to false"); 2895 strTexturesOn = true; 2896 mUseOverlay = false; 2897 } 2898 }else if(str_size == 3){ 2899 if (!strncmp(str, "off", str_size) || !strncmp(str, "OFF", str_size)) { 2900 strTexturesOn = false; 2901 mUseOverlay = true; 2902 } 2903 } 2904 2905 } 2906 return NO_ERROR; 2907 } 2908 2909 status_t QCameraHardwareInterface::setFlash(const QCameraParameters& params) 2910 { 2911 const char *str = NULL; 2912 2913 ALOGV("%s: E",__func__); 2914 int rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_LED_MODE); 2915 if(!rc) { 2916 ALOGV("%s:LED FLASH not supported", __func__); 2917 return NO_ERROR; 2918 } 2919 2920 const char *sce_str = params.get(QCameraParameters::KEY_SCENE_MODE); 2921 if (sce_str != NULL) { 2922 if (!strcmp(sce_str, "hdr")) { 2923 //Flash In HDR 2924 str = QCameraParameters::FLASH_MODE_OFF; 2925 mParameters.set(QCameraParameters::KEY_FLASH_MODE, str); 2926 }else if(!strcmp(sce_str, "auto")){ 2927 //Flash Mode in auto scene mode 2928 str = params.get(QCameraParameters::KEY_FLASH_MODE); 2929 }else{ 2930 //FLASH in scene Mode except auto, hdr 2931 str = QCameraParameters::FLASH_MODE_AUTO; 2932 mParameters.set(QCameraParameters::KEY_FLASH_MODE, str); 2933 } 2934 }else { 2935 str = params.get(QCameraParameters::KEY_FLASH_MODE); 2936 } 2937 2938 if (str != NULL) { 2939 int32_t value = attr_lookup(flash, sizeof(flash) / sizeof(str_map), str); 2940 if (value != NOT_FOUND) { 2941 mParameters.set(QCameraParameters::KEY_FLASH_MODE, str); 2942 bool ret = native_set_parms(MM_CAMERA_PARM_LED_MODE, 2943 sizeof(value), (void *)&value); 2944 mLedStatusForZsl = (led_mode_t)value; 2945 return ret ? NO_ERROR : UNKNOWN_ERROR; 2946 } 2947 } 2948 ALOGE("Invalid flash mode value: %s", (str == NULL) ? "NULL" : str); 2949 2950 return BAD_VALUE; 2951 } 2952 2953 status_t QCameraHardwareInterface::setAecAwbLock(const QCameraParameters & params) 2954 { 2955 ALOGV("%s : E", __func__); 2956 status_t rc = NO_ERROR; 2957 int32_t value; 2958 const char* str; 2959 2960 //for AEC lock 2961 str = params.get(QCameraParameters::KEY_AUTO_EXPOSURE_LOCK); 2962 value = (strcmp(str, "true") == 0)? 1 : 0; 2963 mParameters.set(QCameraParameters::KEY_AUTO_EXPOSURE_LOCK, str); 2964 rc = (native_set_parms(MM_CAMERA_PARM_AEC_LOCK, sizeof(int32_t), (void *)(&value))) ? 2965 NO_ERROR : UNKNOWN_ERROR; 2966 2967 //for AWB lock 2968 str = params.get(QCameraParameters::KEY_AUTO_WHITEBALANCE_LOCK); 2969 value = (strcmp(str, "true") == 0)? 1 : 0; 2970 mParameters.set(QCameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, str); 2971 rc = (native_set_parms(MM_CAMERA_PARM_AWB_LOCK, sizeof(int32_t), (void *)(&value))) ? 2972 NO_ERROR : UNKNOWN_ERROR; 2973 ALOGV("%s : X", __func__); 2974 return rc; 2975 } 2976 2977 status_t QCameraHardwareInterface::setOverlayFormats(const QCameraParameters& params) 2978 { 2979 mParameters.set("overlay-format", HAL_PIXEL_FORMAT_YCbCr_420_SP); 2980 if(mIs3DModeOn == true) { 2981 int ovFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP|HAL_3D_IN_SIDE_BY_SIDE_L_R|HAL_3D_OUT_SIDE_BY_SIDE; 2982 mParameters.set("overlay-format", ovFormat); 2983 } 2984 return NO_ERROR; 2985 } 2986 2987 status_t QCameraHardwareInterface::setMCEValue(const QCameraParameters& params) 2988 { 2989 ALOGV("%s",__func__); 2990 status_t rc = NO_ERROR; 2991 rc = cam_config_is_parm_supported(mCameraId,MM_CAMERA_PARM_MCE); 2992 if(!rc) { 2993 ALOGV("MM_CAMERA_PARM_MCE mode is not supported for this sensor"); 2994 return NO_ERROR; 2995 } 2996 const char *str = params.get(QCameraParameters::KEY_MEMORY_COLOR_ENHANCEMENT); 2997 if (str != NULL) { 2998 int value = attr_lookup(mce, sizeof(mce) / sizeof(str_map), str); 2999 if (value != NOT_FOUND) { 3000 int temp = (int8_t)value; 3001 ALOGV("%s: setting MCE value of %s", __FUNCTION__, str); 3002 mParameters.set(QCameraParameters::KEY_MEMORY_COLOR_ENHANCEMENT, str); 3003 3004 native_set_parms(MM_CAMERA_PARM_MCE, sizeof(int8_t), (void *)&temp); 3005 return NO_ERROR; 3006 } 3007 } 3008 ALOGE("Invalid MCE value: %s", (str == NULL) ? "NULL" : str); 3009 3010 return NO_ERROR; 3011 } 3012 3013 status_t QCameraHardwareInterface::setHighFrameRate(const QCameraParameters& params) 3014 { 3015 3016 bool mCameraRunning; 3017 3018 int rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_HFR); 3019 if(!rc) { 3020 ALOGV("%s: MM_CAMERA_PARM_HFR not supported", __func__); 3021 return NO_ERROR; 3022 } 3023 3024 const char *str = params.get(QCameraParameters::KEY_VIDEO_HIGH_FRAME_RATE); 3025 if (str != NULL) { 3026 int value = attr_lookup(hfr, sizeof(hfr) / sizeof(str_map), str); 3027 if (value != NOT_FOUND) { 3028 mHFRLevel = (int32_t)value; 3029 //Check for change in HFR value 3030 const char *oldHfr = mParameters.get(QCameraParameters::KEY_VIDEO_HIGH_FRAME_RATE); 3031 if(strcmp(oldHfr, str)){ 3032 mParameters.set(QCameraParameters::KEY_VIDEO_HIGH_FRAME_RATE, str); 3033 // mHFRMode = true; 3034 mCameraRunning=isPreviewRunning(); 3035 if(mCameraRunning == true) { 3036 // mHFRThreadWaitLock.lock(); 3037 // pthread_attr_t pattr; 3038 // pthread_attr_init(&pattr); 3039 // pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); 3040 // mHFRThreadRunning = !pthread_create(&mHFRThread, 3041 // &pattr, 3042 // hfr_thread, 3043 // (void*)NULL); 3044 // mHFRThreadWaitLock.unlock(); 3045 stopPreviewInternal(); 3046 mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED; 3047 native_set_parms(MM_CAMERA_PARM_HFR, sizeof(int32_t), (void *)&mHFRLevel); 3048 mPreviewState = QCAMERA_HAL_PREVIEW_START; 3049 if (startPreview2() == NO_ERROR) 3050 mPreviewState = QCAMERA_HAL_PREVIEW_STARTED; 3051 return NO_ERROR; 3052 } 3053 } 3054 native_set_parms(MM_CAMERA_PARM_HFR, sizeof(int32_t), (void *)&mHFRLevel); 3055 return NO_ERROR; 3056 } 3057 } 3058 ALOGE("Invalid HFR value: %s", (str == NULL) ? "NULL" : str); 3059 return NO_ERROR; 3060 } 3061 3062 status_t QCameraHardwareInterface::setLensshadeValue(const QCameraParameters& params) 3063 { 3064 3065 int rc = cam_config_is_parm_supported(mCameraId, MM_CAMERA_PARM_ROLLOFF); 3066 if(!rc) { 3067 ALOGV("%s:LENS SHADING not supported", __func__); 3068 return NO_ERROR; 3069 } 3070 3071 const char *str = params.get(QCameraParameters::KEY_LENSSHADE); 3072 if (str != NULL) { 3073 int value = attr_lookup(lensshade, 3074 sizeof(lensshade) / sizeof(str_map), str); 3075 if (value != NOT_FOUND) { 3076 int8_t temp = (int8_t)value; 3077 mParameters.set(QCameraParameters::KEY_LENSSHADE, str); 3078 native_set_parms(MM_CAMERA_PARM_ROLLOFF, sizeof(int8_t), (void *)&temp); 3079 return NO_ERROR; 3080 } 3081 } 3082 ALOGE("Invalid lensShade value: %s", (str == NULL) ? "NULL" : str); 3083 return BAD_VALUE; 3084 } 3085 3086 status_t QCameraHardwareInterface::setFaceDetect(const QCameraParameters& params) 3087 { 3088 if(supportsFaceDetection() == false){ 3089 ALOGI("setFaceDetect support is not available"); 3090 return NO_ERROR; 3091 } 3092 3093 int requested_faces = params.getInt(QCameraParameters::KEY_MAX_NUM_REQUESTED_FACES); 3094 int hardware_supported_faces = mParameters.getInt(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW); 3095 if (requested_faces > hardware_supported_faces) { 3096 requested_faces = hardware_supported_faces; 3097 } 3098 mParameters.set(QCameraParameters::KEY_MAX_NUM_REQUESTED_FACES, requested_faces); 3099 const char *str = params.get(QCameraParameters::KEY_FACE_DETECTION); 3100 ALOGV("setFaceDetect: %s", str); 3101 if (str != NULL) { 3102 fd_set_parm_t fd_set_parm; 3103 int value = attr_lookup(facedetection, 3104 sizeof(facedetection) / sizeof(str_map), str); 3105 mFaceDetectOn = value; 3106 fd_set_parm.fd_mode = value; 3107 fd_set_parm.num_fd = requested_faces; 3108 ALOGV("%s Face detection value = %d, num_fd = %d",__func__, value, requested_faces); 3109 native_set_parms(MM_CAMERA_PARM_FD, sizeof(fd_set_parm_t), (void *)&fd_set_parm); 3110 mParameters.set(QCameraParameters::KEY_FACE_DETECTION, str); 3111 return NO_ERROR; 3112 } 3113 ALOGE("Invalid Face Detection value: %s", (str == NULL) ? "NULL" : str); 3114 return BAD_VALUE; 3115 } 3116 status_t QCameraHardwareInterface::setFaceDetection(const char *str) 3117 { 3118 if(supportsFaceDetection() == false){ 3119 ALOGV("Face detection is not enabled"); 3120 return NO_ERROR; 3121 } 3122 if (str != NULL) { 3123 int requested_faces = mParameters.getInt(QCameraParameters::KEY_MAX_NUM_REQUESTED_FACES); 3124 int value = attr_lookup(facedetection, 3125 sizeof(facedetection) / sizeof(str_map), str); 3126 if (value != NOT_FOUND) { 3127 fd_set_parm_t fd_set_parm; 3128 mMetaDataWaitLock.lock(); 3129 mFaceDetectOn = value; 3130 mMetaDataWaitLock.unlock(); 3131 fd_set_parm.fd_mode = value; 3132 fd_set_parm.num_fd = requested_faces; 3133 ALOGV("%s Face detection value = %d, num_fd = %d",__func__, value, requested_faces); 3134 native_set_parms(MM_CAMERA_PARM_FD, sizeof(fd_set_parm_t), (void *)&fd_set_parm); 3135 mParameters.set(QCameraParameters::KEY_FACE_DETECTION, str); 3136 return NO_ERROR; 3137 } 3138 } 3139 ALOGE("Invalid Face Detection value: %s", (str == NULL) ? "NULL" : str); 3140 return BAD_VALUE; 3141 } 3142 3143 status_t QCameraHardwareInterface::setAEBracket(const QCameraParameters& params) 3144 { 3145 const char *str; 3146 if(!cam_config_is_parm_supported(mCameraId,MM_CAMERA_PARM_HDR) || (myMode & CAMERA_ZSL_MODE)) { 3147 ALOGV("Parameter HDR is not supported for this sensor/ ZSL mode"); 3148 3149 if (myMode & CAMERA_ZSL_MODE) { 3150 ALOGV("In ZSL mode, reset AEBBracket to HDR_OFF mode"); 3151 exp_bracketing_t temp; 3152 memset(&temp, 0, sizeof(temp)); 3153 mHdrMode = HDR_BRACKETING_OFF; 3154 temp.hdr_enable= false; 3155 temp.mode = HDR_BRACKETING_OFF; 3156 native_set_parms(MM_CAMERA_PARM_HDR, sizeof(exp_bracketing_t), (void *)&temp); 3157 } 3158 return NO_ERROR; 3159 } 3160 3161 const char *str2 = params.get(QCameraParameters::KEY_SCENE_MODE); 3162 if(!strcmp(str2, "hdr")) { 3163 str="HDR"; 3164 } else { 3165 str = params.get(QCameraParameters::KEY_AE_BRACKET_HDR); 3166 } 3167 3168 if (str != NULL) { 3169 int value = attr_lookup(hdr_bracket, 3170 sizeof(hdr_bracket) / sizeof(str_map), str); 3171 exp_bracketing_t temp; 3172 memset(&temp, 0, sizeof(temp)); 3173 switch (value) { 3174 case HDR_MODE: 3175 { 3176 mHdrMode = HDR_MODE; 3177 } 3178 break; 3179 case EXP_BRACKETING_MODE: 3180 { 3181 int numFrames = getNumOfSnapshots(); 3182 const char *str_val = params.get("capture-burst-exposures"); 3183 if ((str_val != NULL) && (strlen(str_val)>0)) { 3184 ALOGV("%s: capture-burst-exposures %s", __FUNCTION__, str_val); 3185 3186 mHdrMode = EXP_BRACKETING_MODE; 3187 temp.hdr_enable = false; 3188 temp.mode = EXP_BRACKETING_MODE; 3189 temp.total_frames = (numFrames > MAX_SNAPSHOT_BUFFERS -2) ? MAX_SNAPSHOT_BUFFERS -2 : numFrames; 3190 temp.total_hal_frames = temp.total_frames; 3191 strlcpy(temp.values, str_val, MAX_EXP_BRACKETING_LENGTH); 3192 ALOGV("%s: setting Exposure Bracketing value of %s, frame (%d)", __FUNCTION__, temp.values, temp.total_hal_frames); 3193 native_set_parms(MM_CAMERA_PARM_HDR, sizeof(exp_bracketing_t), (void *)&temp); 3194 } 3195 else { 3196 /* Apps not set capture-burst-exposures, error case fall into bracketing off mode */ 3197 ALOGV("%s: capture-burst-exposures not set, back to HDR OFF mode", __FUNCTION__); 3198 mHdrMode = HDR_BRACKETING_OFF; 3199 temp.hdr_enable= false; 3200 temp.mode = HDR_BRACKETING_OFF; 3201 native_set_parms(MM_CAMERA_PARM_HDR, sizeof(exp_bracketing_t), (void *)&temp); 3202 } 3203 } 3204 break; 3205 case HDR_BRACKETING_OFF: 3206 default: 3207 { 3208 mHdrMode = HDR_BRACKETING_OFF; 3209 temp.hdr_enable= false; 3210 temp.mode = HDR_BRACKETING_OFF; 3211 native_set_parms(MM_CAMERA_PARM_HDR, sizeof(exp_bracketing_t), (void *)&temp); 3212 } 3213 break; 3214 } 3215 3216 /* save the value*/ 3217 mParameters.set(QCameraParameters::KEY_AE_BRACKET_HDR, str); 3218 } 3219 return NO_ERROR; 3220 } 3221 3222 status_t QCameraHardwareInterface::setCaptureBurstExp() 3223 { 3224 char burst_exp[PROPERTY_VALUE_MAX]; 3225 memset(burst_exp, 0, sizeof(burst_exp)); 3226 property_get("persist.capture.burst.exposures", burst_exp, ""); 3227 if (NULL != burst_exp) 3228 mParameters.set("capture-burst-exposures", burst_exp); 3229 return NO_ERROR; 3230 } 3231 3232 status_t QCameraHardwareInterface::setRedeyeReduction(const QCameraParameters& params) 3233 { 3234 if(supportsRedEyeReduction() == false) { 3235 ALOGV("Parameter Redeye Reduction is not supported for this sensor"); 3236 return NO_ERROR; 3237 } 3238 3239 const char *str = params.get(QCameraParameters::KEY_REDEYE_REDUCTION); 3240 if (str != NULL) { 3241 int value = attr_lookup(redeye_reduction, sizeof(redeye_reduction) / sizeof(str_map), str); 3242 if (value != NOT_FOUND) { 3243 int8_t temp = (int8_t)value; 3244 ALOGV("%s: setting Redeye Reduction value of %s", __FUNCTION__, str); 3245 mParameters.set(QCameraParameters::KEY_REDEYE_REDUCTION, str); 3246 3247 native_set_parms(MM_CAMERA_PARM_REDEYE_REDUCTION, sizeof(int8_t), (void *)&temp); 3248 return NO_ERROR; 3249 } 3250 } 3251 ALOGE("Invalid Redeye Reduction value: %s", (str == NULL) ? "NULL" : str); 3252 return BAD_VALUE; 3253 } 3254 3255 status_t QCameraHardwareInterface::setGpsLocation(const QCameraParameters& params) 3256 { 3257 const char *method = params.get(QCameraParameters::KEY_GPS_PROCESSING_METHOD); 3258 if (method) { 3259 mParameters.set(QCameraParameters::KEY_GPS_PROCESSING_METHOD, method); 3260 }else { 3261 mParameters.remove(QCameraParameters::KEY_GPS_PROCESSING_METHOD); 3262 } 3263 3264 const char *latitude = params.get(QCameraParameters::KEY_GPS_LATITUDE); 3265 if (latitude) { 3266 mParameters.set(QCameraParameters::KEY_GPS_LATITUDE, latitude); 3267 }else { 3268 mParameters.remove(QCameraParameters::KEY_GPS_LATITUDE); 3269 } 3270 3271 const char *latitudeRef = params.get(QCameraParameters::KEY_GPS_LATITUDE_REF); 3272 if (latitudeRef) { 3273 mParameters.set(QCameraParameters::KEY_GPS_LATITUDE_REF, latitudeRef); 3274 }else { 3275 mParameters.remove(QCameraParameters::KEY_GPS_LATITUDE_REF); 3276 } 3277 3278 const char *longitude = params.get(QCameraParameters::KEY_GPS_LONGITUDE); 3279 if (longitude) { 3280 mParameters.set(QCameraParameters::KEY_GPS_LONGITUDE, longitude); 3281 }else { 3282 mParameters.remove(QCameraParameters::KEY_GPS_LONGITUDE); 3283 } 3284 3285 const char *longitudeRef = params.get(QCameraParameters::KEY_GPS_LONGITUDE_REF); 3286 if (longitudeRef) { 3287 mParameters.set(QCameraParameters::KEY_GPS_LONGITUDE_REF, longitudeRef); 3288 }else { 3289 mParameters.remove(QCameraParameters::KEY_GPS_LONGITUDE_REF); 3290 } 3291 3292 const char *altitudeRef = params.get(QCameraParameters::KEY_GPS_ALTITUDE_REF); 3293 if (altitudeRef) { 3294 mParameters.set(QCameraParameters::KEY_GPS_ALTITUDE_REF, altitudeRef); 3295 }else { 3296 mParameters.remove(QCameraParameters::KEY_GPS_ALTITUDE_REF); 3297 } 3298 3299 const char *altitude = params.get(QCameraParameters::KEY_GPS_ALTITUDE); 3300 if (altitude) { 3301 mParameters.set(QCameraParameters::KEY_GPS_ALTITUDE, altitude); 3302 }else { 3303 mParameters.remove(QCameraParameters::KEY_GPS_ALTITUDE); 3304 } 3305 3306 const char *status = params.get(QCameraParameters::KEY_GPS_STATUS); 3307 if (status) { 3308 mParameters.set(QCameraParameters::KEY_GPS_STATUS, status); 3309 } 3310 3311 const char *dateTime = params.get(QCameraParameters::KEY_EXIF_DATETIME); 3312 if (dateTime) { 3313 mParameters.set(QCameraParameters::KEY_EXIF_DATETIME, dateTime); 3314 }else { 3315 mParameters.remove(QCameraParameters::KEY_EXIF_DATETIME); 3316 } 3317 3318 const char *timestamp = params.get(QCameraParameters::KEY_GPS_TIMESTAMP); 3319 if (timestamp) { 3320 mParameters.set(QCameraParameters::KEY_GPS_TIMESTAMP, timestamp); 3321 }else { 3322 mParameters.remove(QCameraParameters::KEY_GPS_TIMESTAMP); 3323 } 3324 ALOGV("setGpsLocation X"); 3325 return NO_ERROR; 3326 } 3327 3328 status_t QCameraHardwareInterface::setRotation(const QCameraParameters& params) 3329 { 3330 status_t rc = NO_ERROR; 3331 int rotation = params.getInt(QCameraParameters::KEY_ROTATION); 3332 if (rotation != NOT_FOUND) { 3333 if (rotation == 0 || rotation == 90 || rotation == 180 3334 || rotation == 270) { 3335 mParameters.set(QCameraParameters::KEY_ROTATION, rotation); 3336 mRotation = rotation; 3337 } else { 3338 ALOGE("Invalid rotation value: %d", rotation); 3339 rc = BAD_VALUE; 3340 } 3341 } 3342 ALOGV("setRotation"); 3343 return rc; 3344 } 3345 3346 status_t QCameraHardwareInterface::setDenoise(const QCameraParameters& params) 3347 { 3348 #if 0 3349 if(!mCfgControl.mm_camera_is_supported(MM_CAMERA_PARM_WAVELET_DENOISE)) { 3350 ALOGE("Wavelet Denoise is not supported for this sensor"); 3351 return NO_ERROR; 3352 } 3353 const char *str = params.get(QCameraParameters::KEY_DENOISE); 3354 if (str != NULL) { 3355 int value = attr_lookup(denoise, 3356 sizeof(denoise) / sizeof(str_map), str); 3357 if ((value != NOT_FOUND) && (mDenoiseValue != value)) { 3358 mDenoiseValue = value; 3359 mParameters.set(QCameraParameters::KEY_DENOISE, str); 3360 bool ret = native_set_parms(MM_CAMERA_PARM_WAVELET_DENOISE, sizeof(value), 3361 (void *)&value); 3362 return ret ? NO_ERROR : UNKNOWN_ERROR; 3363 } 3364 return NO_ERROR; 3365 } 3366 ALOGE("Invalid Denoise value: %s", (str == NULL) ? "NULL" : str); 3367 #endif 3368 return BAD_VALUE; 3369 } 3370 3371 status_t QCameraHardwareInterface::setOrientation(const QCameraParameters& params) 3372 { 3373 const char *str = params.get("orientation"); 3374 3375 if (str != NULL) { 3376 if (strcmp(str, "portrait") == 0 || strcmp(str, "landscape") == 0) { 3377 // Camera service needs this to decide if the preview frames and raw 3378 // pictures should be rotated. 3379 mParameters.set("orientation", str); 3380 } else { 3381 ALOGE("Invalid orientation value: %s", str); 3382 return BAD_VALUE; 3383 } 3384 } 3385 return NO_ERROR; 3386 } 3387 3388 status_t QCameraHardwareInterface::setPictureFormat(const QCameraParameters& params) 3389 { 3390 const char * str = params.get(QCameraParameters::KEY_PICTURE_FORMAT); 3391 3392 if(str != NULL){ 3393 int32_t value = attr_lookup(picture_formats, 3394 sizeof(picture_formats) / sizeof(str_map), str); 3395 if(value != NOT_FOUND){ 3396 mParameters.set(QCameraParameters::KEY_PICTURE_FORMAT, str); 3397 } else { 3398 ALOGE("Invalid Picture Format value: %s", str); 3399 return BAD_VALUE; 3400 } 3401 } 3402 return NO_ERROR; 3403 } 3404 3405 status_t QCameraHardwareInterface::setRecordingHintValue(const int32_t value) 3406 { 3407 native_set_parms(MM_CAMERA_PARM_RECORDING_HINT, sizeof(value), 3408 (void *)&value); 3409 if (value == true){ 3410 native_set_parms(MM_CAMERA_PARM_CAF_ENABLE, sizeof(value), 3411 (void *)&value); 3412 } 3413 setDISMode(); 3414 setFullLiveshot(); 3415 return NO_ERROR; 3416 } 3417 3418 status_t QCameraHardwareInterface::setRecordingHint(const QCameraParameters& params) 3419 { 3420 3421 const char * str = params.get(QCameraParameters::KEY_RECORDING_HINT); 3422 3423 if(str != NULL){ 3424 int32_t value = attr_lookup(recording_Hints, 3425 sizeof(recording_Hints) / sizeof(str_map), str); 3426 if(value != NOT_FOUND){ 3427 mRecordingHint = value; 3428 setRecordingHintValue(mRecordingHint); 3429 mParameters.set(QCameraParameters::KEY_RECORDING_HINT, str); 3430 return NO_ERROR; 3431 } else { 3432 ALOGE("Invalid Picture Format value: %s", str); 3433 setDISMode(); 3434 setFullLiveshot(); 3435 return BAD_VALUE; 3436 } 3437 } 3438 setDISMode(); 3439 setFullLiveshot(); 3440 return NO_ERROR; 3441 } 3442 3443 status_t QCameraHardwareInterface::setDISMode() { 3444 /* Enable DIS only if 3445 * - Camcorder mode AND 3446 * - DIS property is set AND 3447 * - Not in Low power mode. */ 3448 uint32_t value = mRecordingHint && mDisEnabled 3449 && !isLowPowerCamcorder(); 3450 3451 ALOGV("%s DIS is %s value = %d", __func__, 3452 value ? "Enabled" : "Disabled", value); 3453 native_set_parms(MM_CAMERA_PARM_DIS_ENABLE, sizeof(value), 3454 (void *)&value); 3455 return NO_ERROR; 3456 } 3457 3458 status_t QCameraHardwareInterface::setFullLiveshot() 3459 { 3460 /* Enable full size liveshot only if 3461 * - Camcorder mode AND 3462 * - Full size liveshot is enabled. */ 3463 uint32_t value = mRecordingHint && mFullLiveshotEnabled 3464 && !isLowPowerCamcorder(); 3465 3466 if (((mDimension.picture_width == mVideoWidth) && 3467 (mDimension.picture_height == mVideoHeight))) { 3468 /* If video size matches the live snapshot size 3469 * turn off full size liveshot to get higher fps. */ 3470 value = 0; 3471 } 3472 3473 ALOGV("%s Full size liveshot %s value = %d", __func__, 3474 value ? "Enabled" : "Disabled", value); 3475 native_set_parms(MM_CAMERA_PARM_FULL_LIVESHOT, sizeof(value), 3476 (void *)&value); 3477 return NO_ERROR; 3478 } 3479 3480 3481 isp3a_af_mode_t QCameraHardwareInterface::getAutoFocusMode( 3482 const QCameraParameters& params) 3483 { 3484 isp3a_af_mode_t afMode = AF_MODE_MAX; 3485 afMode = (isp3a_af_mode_t)mFocusMode; 3486 return afMode; 3487 } 3488 3489 void QCameraHardwareInterface::getPictureSize(int *picture_width, 3490 int *picture_height) const 3491 { 3492 mParameters.getPictureSize(picture_width, picture_height); 3493 } 3494 3495 void QCameraHardwareInterface::getPreviewSize(int *preview_width, 3496 int *preview_height) const 3497 { 3498 mParameters.getPreviewSize(preview_width, preview_height); 3499 } 3500 3501 cam_format_t QCameraHardwareInterface::getPreviewFormat() const 3502 { 3503 cam_format_t foramt = CAMERA_YUV_420_NV21; 3504 const char *str = mParameters.getPreviewFormat(); 3505 int32_t value = attr_lookup(preview_formats, 3506 sizeof(preview_formats)/sizeof(str_map), 3507 str); 3508 3509 if(value != NOT_FOUND) { 3510 int num = sizeof(preview_format_info_list)/sizeof(preview_format_info_t); 3511 int i; 3512 for (i = 0; i < num; i++) { 3513 if (preview_format_info_list[i].Hal_format == value) { 3514 foramt = preview_format_info_list[i].mm_cam_format; 3515 break; 3516 } 3517 } 3518 } 3519 3520 return foramt; 3521 } 3522 3523 cam_pad_format_t QCameraHardwareInterface::getPreviewPadding() const 3524 { 3525 return mPreviewFormatInfo.padding; 3526 } 3527 3528 int QCameraHardwareInterface::getJpegQuality() const 3529 { 3530 return mJpegQuality; 3531 } 3532 3533 int QCameraHardwareInterface::getNumOfSnapshots(void) const 3534 { 3535 char prop[PROPERTY_VALUE_MAX]; 3536 memset(prop, 0, sizeof(prop)); 3537 property_get("persist.camera.snapshot.number", prop, "0"); 3538 ALOGV("%s: prop enable/disable = %d", __func__, atoi(prop)); 3539 if (atoi(prop)) { 3540 ALOGV("%s: Reading maximum no of snapshots = %d" 3541 "from properties", __func__, atoi(prop)); 3542 return atoi(prop); 3543 } else { 3544 return mParameters.getInt("num-snaps-per-shutter"); 3545 } 3546 } 3547 3548 int QCameraHardwareInterface::getNumOfSnapshots(const QCameraParameters& params) 3549 { 3550 char prop[PROPERTY_VALUE_MAX]; 3551 memset(prop, 0, sizeof(prop)); 3552 property_get("persist.camera.snapshot.number", prop, "0"); 3553 ALOGV("%s: prop enable/disable = %d", __func__, atoi(prop)); 3554 if (atoi(prop)) { 3555 ALOGV("%s: Reading maximum no of snapshots = %d" 3556 "from properties", __func__, atoi(prop)); 3557 return atoi(prop); 3558 } else { 3559 return params.getInt("num-snaps-per-shutter"); 3560 } 3561 3562 } 3563 3564 int QCameraHardwareInterface:: 3565 getThumbSizesFromAspectRatio(uint32_t aspect_ratio, 3566 int *picture_width, 3567 int *picture_height) 3568 { 3569 for(unsigned int i = 0; i < THUMBNAIL_SIZE_COUNT; i++ ){ 3570 if(thumbnail_sizes[i].aspect_ratio == aspect_ratio) 3571 { 3572 *picture_width = thumbnail_sizes[i].width; 3573 *picture_height = thumbnail_sizes[i].height; 3574 return NO_ERROR; 3575 } 3576 } 3577 3578 return BAD_VALUE; 3579 } 3580 3581 bool QCameraHardwareInterface::isRawSnapshot() 3582 { 3583 const char *format = mParameters.getPictureFormat(); 3584 if( format!= NULL && 3585 !strcmp(format, QCameraParameters::PIXEL_FORMAT_RAW)){ 3586 return true; 3587 } 3588 else{ 3589 return false; 3590 } 3591 } 3592 3593 status_t QCameraHardwareInterface::setPreviewSizeTable(void) 3594 { 3595 status_t ret = NO_ERROR; 3596 mm_camera_dimension_t dim; 3597 struct camera_size_type* preview_size_table; 3598 int preview_table_size; 3599 int i = 0; 3600 char str[10] = {0}; 3601 3602 /* Initialize table with default values */ 3603 preview_size_table = default_preview_sizes; 3604 preview_table_size = preview_sizes_count; 3605 3606 3607 /* Get maximum preview size supported by sensor*/ 3608 memset(&dim, 0, sizeof(mm_camera_dimension_t)); 3609 ret = cam_config_get_parm(mCameraId, 3610 MM_CAMERA_PARM_MAX_PREVIEW_SIZE, &dim); 3611 if (ret != NO_ERROR) { 3612 ALOGE("%s: Failure getting Max Preview Size supported by camera", 3613 __func__); 3614 goto end; 3615 } 3616 3617 ALOGV("%s: Max Preview Sizes Supported: %d X %d", __func__, 3618 dim.width, dim.height); 3619 3620 for (i = 0; i < preview_table_size; i++) { 3621 if ((preview_size_table->width <= dim.width) && 3622 (preview_size_table->height <= dim.height)) { 3623 ALOGV("%s: Camera Preview Size Table " 3624 "Max width: %d height %d table_size: %d", 3625 __func__, preview_size_table->width, 3626 preview_size_table->height, preview_table_size - i); 3627 break; 3628 } 3629 preview_size_table++; 3630 } 3631 //set preferred preview size to maximum preview size 3632 sprintf(str, "%dx%d", preview_size_table->width, preview_size_table->height); 3633 mParameters.set(QCameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO, str); 3634 ALOGV("KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO = %s", str); 3635 3636 end: 3637 /* Save the table in global member*/ 3638 mPreviewSizes = preview_size_table; 3639 mPreviewSizeCount = preview_table_size - i; 3640 3641 return ret; 3642 } 3643 3644 status_t QCameraHardwareInterface::setPictureSizeTable(void) 3645 { 3646 status_t ret = NO_ERROR; 3647 mm_camera_dimension_t dim; 3648 struct camera_size_type* picture_size_table; 3649 int picture_table_size; 3650 int i = 0, count = 0; 3651 3652 /* Initialize table with default values */ 3653 picture_table_size = sizeof(default_picture_sizes)/ 3654 sizeof(default_picture_sizes[0]); 3655 picture_size_table = default_picture_sizes; 3656 mPictureSizes = 3657 ( struct camera_size_type *)malloc(picture_table_size * 3658 sizeof(struct camera_size_type)); 3659 if (mPictureSizes == NULL) { 3660 ALOGE("%s: Failre allocating memory to store picture size table",__func__); 3661 goto end; 3662 } 3663 3664 /* Get maximum picture size supported by sensor*/ 3665 memset(&dim, 0, sizeof(mm_camera_dimension_t)); 3666 ret = cam_config_get_parm(mCameraId, 3667 MM_CAMERA_PARM_MAX_PICTURE_SIZE, &dim); 3668 if (ret != NO_ERROR) { 3669 ALOGE("%s: Failure getting Max Picture Size supported by camera", 3670 __func__); 3671 ret = NO_MEMORY; 3672 free(mPictureSizes); 3673 mPictureSizes = NULL; 3674 goto end; 3675 } 3676 3677 ALOGV("%s: Max Picture Sizes Supported: %d X %d", __func__, 3678 dim.width, dim.height); 3679 3680 for (i = 0; i < picture_table_size; i++) { 3681 /* We'll store those dimensions whose width AND height 3682 are less than or equal to maximum supported */ 3683 if ((picture_size_table->width <= dim.width) && 3684 (picture_size_table->height <= dim.height)) { 3685 ALOGV("%s: Camera Picture Size Table " 3686 "Max width: %d height %d table_size: %d", 3687 __func__, picture_size_table->width, 3688 picture_size_table->height, count+1); 3689 mPictureSizes[count].height = picture_size_table->height; 3690 mPictureSizes[count].width = picture_size_table->width; 3691 count++; 3692 } 3693 picture_size_table++; 3694 } 3695 mPictureSizeCount = count; 3696 3697 end: 3698 /* In case of error, we use default picture sizes */ 3699 if (ret != NO_ERROR) { 3700 mPictureSizes = default_picture_sizes; 3701 mPictureSizeCount = picture_table_size; 3702 } 3703 return ret; 3704 } 3705 3706 status_t QCameraHardwareInterface::setVideoSizeTable(void) 3707 { 3708 status_t ret = NO_ERROR; 3709 mm_camera_dimension_t dim; 3710 struct camera_size_type* video_size_table; 3711 int video_table_size; 3712 int i = 0, count = 0; 3713 ALOGV("%s: E", __func__); 3714 3715 /* Initialize table with default values */ 3716 video_table_size = video_sizes_count; 3717 video_size_table = default_video_sizes; 3718 mVideoSizes = 3719 (struct camera_size_type *)malloc(video_table_size * 3720 sizeof(struct camera_size_type)); 3721 if(mVideoSizes == NULL) { 3722 ALOGE("%s: error allocating memory to store video size table",__func__); 3723 ret = BAD_VALUE; 3724 goto end; 3725 } 3726 3727 /* Get maximum video size supported by sensor*/ 3728 memset(&dim, 0, sizeof(mm_camera_dimension_t)); 3729 ret = cam_config_get_parm(mCameraId, 3730 MM_CAMERA_PARM_MAX_VIDEO_SIZE, &dim); 3731 if(ret != NO_ERROR) { 3732 ALOGE("%s: error getting Max Video Size supported by camera", 3733 __func__); 3734 ret = NO_MEMORY; 3735 free(mVideoSizes); 3736 mVideoSizes = NULL; 3737 ret = BAD_VALUE; 3738 goto end; 3739 } 3740 3741 ALOGV("%s: Max Video Size Supported: %d X %d", __func__, 3742 dim.width, dim.height); 3743 3744 for(i=0; i < video_table_size; i++) { 3745 /* We'll store those dimensions whose width AND height 3746 are less than or equal to maximum supported */ 3747 if((video_size_table->width <= dim.width) && 3748 (video_size_table->height <= dim.height)) { 3749 ALOGV("%s: Supported Video Size [%d] = %dx%d", __func__, count, video_size_table->width, 3750 video_size_table->height); 3751 mVideoSizes[count].height = video_size_table->height; 3752 mVideoSizes[count].width = video_size_table->width; 3753 count++; 3754 } 3755 video_size_table++; 3756 } 3757 mVideoSizeCount = count; 3758 3759 end: 3760 ALOGV("%s: X", __func__); 3761 return ret; 3762 } 3763 3764 void QCameraHardwareInterface::freeVideoSizeTable(void) 3765 { 3766 if(mVideoSizes != NULL) 3767 { 3768 free(mVideoSizes); 3769 } 3770 mVideoSizeCount = 0; 3771 } 3772 3773 3774 void QCameraHardwareInterface::freePictureTable(void) 3775 { 3776 /* If we couldn't allocate memory to store picture table 3777 we use the picture table pointer to point to default 3778 picture table array. In that case we cannot free it.*/ 3779 if ((mPictureSizes != default_picture_sizes) && mPictureSizes) { 3780 free(mPictureSizes); 3781 } 3782 } 3783 3784 status_t QCameraHardwareInterface::setHistogram(int histogram_en) 3785 { 3786 ALOGV("setHistogram: E"); 3787 if(mStatsOn == histogram_en) { 3788 return NO_ERROR; 3789 } 3790 3791 mSendData = histogram_en; 3792 mStatsOn = histogram_en; 3793 mCurrentHisto = -1; 3794 mStatSize = sizeof(uint32_t)* HISTOGRAM_STATS_SIZE; 3795 3796 if (histogram_en == QCAMERA_PARM_ENABLE) { 3797 /*Currently the Ashmem is multiplying the buffer size with total number 3798 of buffers and page aligning. This causes a crash in JNI as each buffer 3799 individually expected to be page aligned */ 3800 int page_size_minus_1 = getpagesize() - 1; 3801 int statSize = sizeof (camera_preview_histogram_info ); 3802 int32_t mAlignedStatSize = ((statSize + page_size_minus_1) & (~page_size_minus_1)); 3803 #if 0 3804 mStatHeap = 3805 new AshmemPool(mAlignedStatSize, 3, statSize, "stat"); 3806 if (!mStatHeap->initialized()) { 3807 ALOGE("Stat Heap X failed "); 3808 mStatHeap.clear(); 3809 mStatHeap = NULL; 3810 return UNKNOWN_ERROR; 3811 } 3812 #endif 3813 for(int cnt = 0; cnt<3; cnt++) { 3814 mStatsMapped[cnt]=mGetMemory(-1, mStatSize, 1, mCallbackCookie); 3815 if(mStatsMapped[cnt] == NULL) { 3816 ALOGE("Failed to get camera memory for stats heap index: %d", cnt); 3817 return(-1); 3818 } else { 3819 ALOGV("Received following info for stats mapped data:%p,handle:%p, size:%d,release:%p", 3820 mStatsMapped[cnt]->data ,mStatsMapped[cnt]->handle, mStatsMapped[cnt]->size, mStatsMapped[cnt]->release); 3821 } 3822 mHistServer.size = sizeof(camera_preview_histogram_info); 3823 #ifdef USE_ION 3824 if(allocate_ion_memory(&mHistServer, cnt, ION_IOMMU_HEAP_ID) < 0) { 3825 ALOGE("%s ION alloc failed\n", __func__); 3826 return -1; 3827 } 3828 #else 3829 mHistServer.fd[cnt] = open("/dev/pmem_adsp", O_RDWR|O_SYNC); 3830 if(mHistServer.fd[cnt] <= 0) { 3831 ALOGE("%s: no pmem for frame %d", __func__, cnt); 3832 return -1; 3833 } 3834 #endif 3835 mHistServer.camera_memory[cnt]=mGetMemory(mHistServer.fd[cnt],mHistServer.size, 1, mCallbackCookie); 3836 if(mHistServer.camera_memory[cnt] == NULL) { 3837 ALOGE("Failed to get camera memory for server side histogram index: %d", cnt); 3838 return(-1); 3839 } else { 3840 ALOGV("Received following info for server side histogram data:%p,handle:%p, size:%d,release:%p", 3841 mHistServer.camera_memory[cnt]->data ,mHistServer.camera_memory[cnt]->handle, 3842 mHistServer.camera_memory[cnt]->size, mHistServer.camera_memory[cnt]->release); 3843 } 3844 /*Register buffer at back-end*/ 3845 if (NO_ERROR != sendMappingBuf(0, cnt, mHistServer.fd[cnt], 3846 mHistServer.size, mCameraId, 3847 CAM_SOCK_MSG_TYPE_HIST_MAPPING)) { 3848 ALOGE("%s could not send buffer to back-end\n", __func__); 3849 } 3850 } 3851 } 3852 ALOGV("Setting histogram = %d", histogram_en); 3853 native_set_parms(MM_CAMERA_PARM_HISTOGRAM, sizeof(int), &histogram_en); 3854 if(histogram_en == QCAMERA_PARM_DISABLE) 3855 { 3856 //release memory 3857 for(int i=0; i<3; i++){ 3858 if(mStatsMapped[i] != NULL) { 3859 mStatsMapped[i]->release(mStatsMapped[i]); 3860 } 3861 /*Unregister buffer at back-end */ 3862 if (NO_ERROR != sendUnMappingBuf(0, i, mCameraId, CAM_SOCK_MSG_TYPE_HIST_UNMAPPING)) { 3863 ALOGE("%s could not unregister buffer from back-end\n", __func__); 3864 } 3865 if(mHistServer.camera_memory[i] != NULL) { 3866 mHistServer.camera_memory[i]->release(mHistServer.camera_memory[i]); 3867 } 3868 close(mHistServer.fd[i]); 3869 #ifdef USE_ION 3870 deallocate_ion_memory(&mHistServer, i); 3871 #endif 3872 } 3873 } 3874 return NO_ERROR; 3875 } 3876 3877 status_t QCameraHardwareInterface::setZSLBurstLookBack(const QCameraParameters& params) 3878 { 3879 const char *v = params.get("capture-burst-retroactive"); 3880 if (v) { 3881 int look_back = atoi(v); 3882 ALOGV("%s: look_back =%d", __func__, look_back); 3883 mParameters.set("capture-burst-retroactive", look_back); 3884 } 3885 return NO_ERROR; 3886 } 3887 3888 status_t QCameraHardwareInterface::setZSLBurstInterval(const QCameraParameters& params) 3889 { 3890 mZslInterval = BURST_INTREVAL_DEFAULT; 3891 const char *v = params.get("capture-burst-interval"); 3892 if (v) { 3893 int interval = atoi(v); 3894 ALOGV("%s: Interval =%d", __func__, interval); 3895 if(interval < BURST_INTREVAL_MIN ||interval > BURST_INTREVAL_MAX ) { 3896 return BAD_VALUE; 3897 } 3898 mZslInterval = interval; 3899 } 3900 return NO_ERROR; 3901 } 3902 3903 int QCameraHardwareInterface::getZSLBurstInterval( void ) 3904 { 3905 int val; 3906 3907 if (mZslInterval == BURST_INTREVAL_DEFAULT) { 3908 char prop[PROPERTY_VALUE_MAX]; 3909 memset(prop, 0, sizeof(prop)); 3910 property_get("persist.camera.zsl.interval", prop, "1"); 3911 val = atoi(prop); 3912 ALOGV("%s: prop interval = %d", __func__, val); 3913 } else { 3914 val = mZslInterval; 3915 } 3916 return val; 3917 } 3918 3919 3920 int QCameraHardwareInterface::getZSLQueueDepth(void) const 3921 { 3922 char prop[PROPERTY_VALUE_MAX]; 3923 memset(prop, 0, sizeof(prop)); 3924 property_get("persist.camera.zsl.queuedepth", prop, "2"); 3925 ALOGV("%s: prop = %d", __func__, atoi(prop)); 3926 return atoi(prop); 3927 } 3928 3929 int QCameraHardwareInterface::getZSLBackLookCount(void) const 3930 { 3931 int look_back; 3932 char prop[PROPERTY_VALUE_MAX]; 3933 memset(prop, 0, sizeof(prop)); 3934 property_get("persist.camera.zsl.backlookcnt", prop, "0"); 3935 ALOGV("%s: prop = %d", __func__, atoi(prop)); 3936 look_back = atoi(prop); 3937 if (look_back == 0 ) { 3938 look_back = mParameters.getInt("capture-burst-retroactive"); 3939 ALOGV("%s: look_back = %d", __func__, look_back); 3940 } 3941 return look_back; 3942 } 3943 3944 bool QCameraHardwareInterface::getFlashCondition(void) 3945 { 3946 int32_t rc = 0; 3947 bool flash_cond = false; 3948 aec_info_for_flash_t lowLightForZSL; 3949 3950 lowLightForZSL.aec_index_for_zsl = 0; 3951 lowLightForZSL.zsl_flash_enable = 0; 3952 3953 if(myMode & CAMERA_ZSL_MODE){ 3954 switch(mLedStatusForZsl) { 3955 case LED_MODE_ON: 3956 flash_cond = true; 3957 break; 3958 case LED_MODE_AUTO: 3959 rc = cam_config_get_parm(mCameraId, 3960 MM_CAMERA_GET_PARM_LOW_LIGHT_FOR_ZSL, &lowLightForZSL); 3961 if(MM_CAMERA_OK == rc) { 3962 if(lowLightForZSL.zsl_flash_enable != 0) 3963 flash_cond = true; 3964 else 3965 flash_cond = false; 3966 } 3967 else 3968 ALOGE("%s: Failed to get lowLightForZSL, rc %d", __func__, rc); 3969 break; 3970 default: 3971 break; 3972 } 3973 } 3974 3975 ALOGV("%s: myMode %d, flash mode %d, flash condition %d", 3976 __func__, myMode, mLedStatusForZsl, flash_cond); 3977 return flash_cond; 3978 } 3979 3980 //EXIF functions 3981 void QCameraHardwareInterface::deinitExifData() 3982 { 3983 ALOGV("Clearing EXIF data"); 3984 for(int i=0; i<MAX_EXIF_TABLE_ENTRIES; i++) 3985 { 3986 //clear all data 3987 memset(&mExifData[i], 0x00, sizeof(exif_tags_info_t)); 3988 } 3989 mExifTableNumEntries = 0; 3990 } 3991 3992 void QCameraHardwareInterface::addExifTag(exif_tag_id_t tagid, exif_tag_type_t type, 3993 uint32_t count, uint8_t copy, void *data) { 3994 3995 if(mExifTableNumEntries >= MAX_EXIF_TABLE_ENTRIES) { 3996 ALOGE("%s: Number of entries exceeded limit", __func__); 3997 return; 3998 } 3999 int index = mExifTableNumEntries; 4000 mExifData[index].tag_id = tagid; 4001 mExifData[index].tag_entry.type = type; 4002 mExifData[index].tag_entry.count = count; 4003 mExifData[index].tag_entry.copy = copy; 4004 if((type == EXIF_RATIONAL) && (count > 1)) 4005 mExifData[index].tag_entry.data._rats = (rat_t *)data; 4006 if((type == EXIF_RATIONAL) && (count == 1)) 4007 mExifData[index].tag_entry.data._rat = *(rat_t *)data; 4008 else if(type == EXIF_ASCII) 4009 mExifData[index].tag_entry.data._ascii = (char *)data; 4010 else if(type == EXIF_BYTE) 4011 mExifData[index].tag_entry.data._byte = *(uint8_t *)data; 4012 else if((type == EXIF_SHORT) && (count > 1)) 4013 mExifData[index].tag_entry.data._shorts = (uint16_t *)data; 4014 else if((type == EXIF_SHORT) && (count == 1)) 4015 mExifData[index].tag_entry.data._short = *(uint16_t *)data; 4016 // Increase number of entries 4017 mExifTableNumEntries++; 4018 } 4019 4020 void QCameraHardwareInterface::initExifData(){ 4021 if(mExifValues.dateTime) { 4022 addExifTag(EXIFTAGID_EXIF_DATE_TIME_ORIGINAL, EXIF_ASCII, 4023 20, 1, (void *)mExifValues.dateTime); 4024 addExifTag(EXIFTAGID_EXIF_DATE_TIME_DIGITIZED, EXIF_ASCII, 4025 20, 1, (void *)mExifValues.dateTime); 4026 } 4027 addExifTag(EXIFTAGID_FOCAL_LENGTH, EXIF_RATIONAL, 1, 1, (void *)&(mExifValues.focalLength)); 4028 addExifTag(EXIFTAGID_ISO_SPEED_RATING,EXIF_SHORT,1,1,(void *)&(mExifValues.isoSpeed)); 4029 4030 // normal f_number is from 1.2 to 22, but I'd like to put some margin. 4031 if(mExifValues.f_number.num>0 && mExifValues.f_number.num<3200) 4032 addExifTag(EXIFTAGID_F_NUMBER,EXIF_RATIONAL,1,1,(void *)&(mExifValues.f_number)); 4033 4034 if(mExifValues.mGpsProcess) { 4035 addExifTag(EXIFTAGID_GPS_PROCESSINGMETHOD, EXIF_ASCII, 4036 EXIF_ASCII_PREFIX_SIZE + strlen(mExifValues.gpsProcessingMethod + EXIF_ASCII_PREFIX_SIZE) + 1, 4037 1, (void *)mExifValues.gpsProcessingMethod); 4038 } 4039 4040 if(mExifValues.mLatitude) { 4041 addExifTag(EXIFTAGID_GPS_LATITUDE, EXIF_RATIONAL, 3, 1, (void *)mExifValues.latitude); 4042 4043 if(mExifValues.latRef) { 4044 addExifTag(EXIFTAGID_GPS_LATITUDE_REF, EXIF_ASCII, 2, 4045 1, (void *)mExifValues.latRef); 4046 } 4047 } 4048 4049 if(mExifValues.mLongitude) { 4050 addExifTag(EXIFTAGID_GPS_LONGITUDE, EXIF_RATIONAL, 3, 1, (void *)mExifValues.longitude); 4051 4052 if(mExifValues.lonRef) { 4053 addExifTag(EXIFTAGID_GPS_LONGITUDE_REF, EXIF_ASCII, 2, 4054 1, (void *)mExifValues.lonRef); 4055 } 4056 } 4057 4058 if(mExifValues.mAltitude) { 4059 addExifTag(EXIFTAGID_GPS_ALTITUDE, EXIF_RATIONAL, 1, 4060 1, (void *)&(mExifValues.altitude)); 4061 4062 addExifTag(EXIFTAGID_GPS_ALTITUDE_REF, EXIF_BYTE, 1, 1, (void *)&mExifValues.mAltitude_ref); 4063 } 4064 4065 if(mExifValues.mTimeStamp) { 4066 time_t unixTime; 4067 struct tm *UTCTimestamp; 4068 4069 unixTime = (time_t)mExifValues.mGPSTimestamp; 4070 UTCTimestamp = gmtime(&unixTime); 4071 4072 strftime(mExifValues.gpsDateStamp, sizeof(mExifValues.gpsDateStamp), "%Y:%m:%d", UTCTimestamp); 4073 addExifTag(EXIFTAGID_GPS_DATESTAMP, EXIF_ASCII, 4074 strlen(mExifValues.gpsDateStamp)+1 , 1, (void *)mExifValues.gpsDateStamp); 4075 4076 mExifValues.gpsTimeStamp[0] = getRational(UTCTimestamp->tm_hour, 1); 4077 mExifValues.gpsTimeStamp[1] = getRational(UTCTimestamp->tm_min, 1); 4078 mExifValues.gpsTimeStamp[2] = getRational(UTCTimestamp->tm_sec, 1); 4079 4080 addExifTag(EXIFTAGID_GPS_TIMESTAMP, EXIF_RATIONAL, 4081 3, 1, (void *)mExifValues.gpsTimeStamp); 4082 ALOGV("EXIFTAGID_GPS_TIMESTAMP set"); 4083 } 4084 if(mExifValues.exposure_time.num || mExifValues.exposure_time.denom) 4085 addExifTag(EXIFTAGID_EXPOSURE_TIME, EXIF_RATIONAL, 1, 1, (void *)&mExifValues.exposure_time); 4086 4087 } 4088 4089 //Add all exif tags in this function 4090 void QCameraHardwareInterface::setExifTags() 4091 { 4092 const char *str; 4093 4094 //set TimeStamp 4095 str = mParameters.get(QCameraParameters::KEY_EXIF_DATETIME); 4096 if(str != NULL) { 4097 strncpy(mExifValues.dateTime, str, 19); 4098 mExifValues.dateTime[19] = '\0'; 4099 } 4100 4101 //Set focal length 4102 int focalLengthValue = (int) (mParameters.getFloat( 4103 QCameraParameters::KEY_FOCAL_LENGTH) * FOCAL_LENGTH_DECIMAL_PRECISION); 4104 4105 mExifValues.focalLength = getRational(focalLengthValue, FOCAL_LENGTH_DECIMAL_PRECISION); 4106 4107 focus_distances_info_t focusDistances; 4108 status_t rc = NO_ERROR; 4109 rc = cam_config_get_parm(mCameraId, MM_CAMERA_PARM_FOCAL_LENGTH,(void *)&focusDistances); 4110 if (rc == MM_CAMERA_OK){ 4111 uint16_t temp1; 4112 rat_t temp; 4113 if(mIsoValue == 0) // ISO is auto 4114 { 4115 temp1 = (uint16_t)(focusDistances.real_gain + 0.5)*100; 4116 mExifValues.isoSpeed = temp1; 4117 ALOGV("The new ISO value is %d", temp1); 4118 } 4119 else{ 4120 temp1 = iso_speed_values[mIsoValue]; 4121 mExifValues.isoSpeed = temp1; 4122 ALOGV("else The new ISO value is %d", temp1); 4123 } 4124 4125 if(focusDistances.exp_time <= 0) // avoid zero-divide problem 4126 focusDistances.exp_time = 0.01668; // expoure time will be 1/60 s 4127 4128 uint16_t temp2 = (uint16_t)(focusDistances.exp_time * 100000); 4129 temp2 = (uint16_t)(100000 / temp2); 4130 temp.num = 1; 4131 temp.denom = temp2; 4132 memcpy(&mExifValues.exposure_time, &temp, sizeof(mExifValues.exposure_time)); 4133 ALOGV(" The exposure value is %f", temp2); 4134 } 4135 //get time and date from system 4136 time_t rawtime; 4137 struct tm * timeinfo; 4138 time(&rawtime); 4139 timeinfo = localtime (&rawtime); 4140 //Write datetime according to EXIF Spec 4141 //"YYYY:MM:DD HH:MM:SS" (20 chars including \0) 4142 snprintf(mExifValues.dateTime, 20, "%04d:%02d:%02d %02d:%02d:%02d", 4143 timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, 4144 timeinfo->tm_mday, timeinfo->tm_hour, 4145 timeinfo->tm_min, timeinfo->tm_sec); 4146 //set gps tags 4147 setExifTagsGPS(); 4148 } 4149 4150 void QCameraHardwareInterface::setExifTagsGPS() 4151 { 4152 const char *str = NULL; 4153 4154 //Set GPS processing method 4155 str = mParameters.get(QCameraParameters::KEY_GPS_PROCESSING_METHOD); 4156 if(str != NULL) { 4157 memcpy(mExifValues.gpsProcessingMethod, ExifAsciiPrefix, EXIF_ASCII_PREFIX_SIZE); 4158 strncpy(mExifValues.gpsProcessingMethod + EXIF_ASCII_PREFIX_SIZE, str, 4159 GPS_PROCESSING_METHOD_SIZE - 1); 4160 mExifValues.gpsProcessingMethod[EXIF_ASCII_PREFIX_SIZE + GPS_PROCESSING_METHOD_SIZE-1] = '\0'; 4161 ALOGV("EXIFTAGID_GPS_PROCESSINGMETHOD = %s %s", mExifValues.gpsProcessingMethod, 4162 mExifValues.gpsProcessingMethod+8); 4163 mExifValues.mGpsProcess = true; 4164 }else{ 4165 mExifValues.mGpsProcess = false; 4166 } 4167 str = NULL; 4168 4169 //Set Latitude 4170 str = mParameters.get(QCameraParameters::KEY_GPS_LATITUDE); 4171 if(str != NULL) { 4172 parseGPSCoordinate(str, mExifValues.latitude); 4173 ALOGV("EXIFTAGID_GPS_LATITUDE = %s", str); 4174 4175 //set Latitude Ref 4176 float latitudeValue = mParameters.getFloat(QCameraParameters::KEY_GPS_LATITUDE); 4177 if(latitudeValue < 0.0f) { 4178 mExifValues.latRef[0] = 'S'; 4179 } else { 4180 mExifValues.latRef[0] = 'N'; 4181 } 4182 mExifValues.latRef[1] = '\0'; 4183 mExifValues.mLatitude = true; 4184 mParameters.set(QCameraParameters::KEY_GPS_LATITUDE_REF,mExifValues.latRef); 4185 ALOGV("EXIFTAGID_GPS_LATITUDE_REF = %s", mExifValues.latRef); 4186 }else{ 4187 mExifValues.mLatitude = false; 4188 } 4189 4190 //set Longitude 4191 str = NULL; 4192 str = mParameters.get(QCameraParameters::KEY_GPS_LONGITUDE); 4193 if(str != NULL) { 4194 parseGPSCoordinate(str, mExifValues.longitude); 4195 ALOGV("EXIFTAGID_GPS_LONGITUDE = %s", str); 4196 4197 //set Longitude Ref 4198 float longitudeValue = mParameters.getFloat(QCameraParameters::KEY_GPS_LONGITUDE); 4199 if(longitudeValue < 0.0f) { 4200 mExifValues.lonRef[0] = 'W'; 4201 } else { 4202 mExifValues.lonRef[0] = 'E'; 4203 } 4204 mExifValues.lonRef[1] = '\0'; 4205 mExifValues.mLongitude = true; 4206 ALOGV("EXIFTAGID_GPS_LONGITUDE_REF = %s", mExifValues.lonRef); 4207 mParameters.set(QCameraParameters::KEY_GPS_LONGITUDE_REF, mExifValues.lonRef); 4208 }else{ 4209 mExifValues.mLongitude = false; 4210 } 4211 4212 //set Altitude 4213 str = mParameters.get(QCameraParameters::KEY_GPS_ALTITUDE); 4214 if(str != NULL) { 4215 double value = atof(str); 4216 mExifValues.mAltitude_ref = 0; 4217 if(value < 0){ 4218 mExifValues.mAltitude_ref = 1; 4219 value = -value; 4220 } 4221 mExifValues.altitude = getRational(value*1000, 1000); 4222 mExifValues.mAltitude = true; 4223 //set AltitudeRef 4224 mParameters.set(QCameraParameters::KEY_GPS_ALTITUDE_REF, mExifValues.mAltitude_ref); 4225 ALOGV("EXIFTAGID_GPS_ALTITUDE = %f", value); 4226 }else{ 4227 mExifValues.mAltitude = false; 4228 } 4229 4230 //set Gps TimeStamp 4231 str = NULL; 4232 str = mParameters.get(QCameraParameters::KEY_GPS_TIMESTAMP); 4233 if(str != NULL) { 4234 mExifValues.mTimeStamp = true; 4235 mExifValues.mGPSTimestamp = atol(str); 4236 }else{ 4237 mExifValues.mTimeStamp = false; 4238 } 4239 } 4240 4241 //latlonString is string formatted coordinate 4242 //coord is rat_t[3] 4243 void QCameraHardwareInterface::parseGPSCoordinate(const char *latlonString, rat_t* coord) 4244 { 4245 if(coord == NULL) { 4246 ALOGE("%s: error, invalid argument coord == NULL", __func__); 4247 return; 4248 } 4249 float degF = fabs(atof(latlonString)); 4250 float minF = (degF- (int) degF) * 60; 4251 float secF = (minF - (int) minF) * 60; 4252 4253 coord[0] = getRational((int) degF, 1); 4254 coord[1] = getRational((int) minF, 1); 4255 coord[2] = getRational((int) (secF * 10000), 10000); 4256 } 4257 4258 bool QCameraHardwareInterface::isLowPowerCamcorder() { 4259 4260 if (mPowerMode == LOW_POWER) 4261 return true; 4262 4263 if(mHFRLevel > 1) /* hard code the value now. Need to move tgtcommon to camear.h */ 4264 return true; 4265 4266 return false; 4267 } 4268 4269 status_t QCameraHardwareInterface::setNoDisplayMode(const QCameraParameters& params) 4270 { 4271 char prop[PROPERTY_VALUE_MAX]; 4272 memset(prop, 0, sizeof(prop)); 4273 property_get("persist.camera.nodisplay", prop, "0"); 4274 int prop_val = atoi(prop); 4275 4276 if (prop_val == 0) { 4277 const char *str_val = params.get("no-display-mode"); 4278 if(str_val && strlen(str_val) > 0) { 4279 mNoDisplayMode = atoi(str_val); 4280 } else { 4281 mNoDisplayMode = 0; 4282 } 4283 ALOGV("Param mNoDisplayMode =%d", mNoDisplayMode); 4284 } else { 4285 mNoDisplayMode = prop_val; 4286 ALOGV("prop mNoDisplayMode =%d", mNoDisplayMode); 4287 } 4288 return NO_ERROR; 4289 } 4290 4291 status_t QCameraHardwareInterface::setCAFLockCancel(void) 4292 { 4293 ALOGV("%s : E", __func__); 4294 4295 //for CAF unlock 4296 if(MM_CAMERA_OK!=cam_ops_action(mCameraId,false,MM_CAMERA_OPS_FOCUS,NULL )) { 4297 ALOGE("%s: AF command failed err:%d error %s",__func__, errno,strerror(errno)); 4298 return -1; 4299 } 4300 4301 ALOGV("%s : X", __func__); 4302 return NO_ERROR; 4303 } 4304 4305 void QCameraHardwareInterface::prepareVideoPicture(bool disable){ 4306 String8 str; 4307 char buffer[32]; 4308 4309 if(disable) { 4310 sprintf(buffer, "%dx%d", mDimension.video_width, mDimension.video_height); 4311 str.append(buffer); 4312 4313 mParameters.setPictureSize(mDimension.video_width, mDimension.video_height); 4314 mParameters.set(QCameraParameters::KEY_SUPPORTED_PICTURE_SIZES, 4315 str.string()); 4316 ALOGV("%s: Video Picture size supported = %d X %d", 4317 __func__,mDimension.video_width,mDimension.video_height); 4318 }else{ 4319 //Set Picture Size 4320 mParameters.setPictureSize(mDimension.picture_width, mDimension.picture_height); 4321 mParameters.set(QCameraParameters::KEY_SUPPORTED_PICTURE_SIZES, 4322 mPictureSizeValues.string()); 4323 } 4324 } 4325 4326 }; /*namespace android */ 4327