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