QCamera3HWI.cpp revision c31ab1ae7cd6b6eb410e71ead51dd36089dc2397
1/* Copyright (c) 2012-2013, The Linux Foundataion. All rights reserved. 2* 3* Redistribution and use in source and binary forms, with or without 4* modification, are permitted provided that the following conditions are 5* met: 6* * Redistributions of source code must retain the above copyright 7* notice, this list of conditions and the following disclaimer. 8* * Redistributions in binary form must reproduce the above 9* copyright notice, this list of conditions and the following 10* disclaimer in the documentation and/or other materials provided 11* with the distribution. 12* * Neither the name of The Linux Foundation nor the names of its 13* contributors may be used to endorse or promote products derived 14* from this software without specific prior written permission. 15* 16* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27* 28*/ 29 30#define LOG_TAG "QCamera3HWI" 31 32#include <cutils/properties.h> 33#include <hardware/camera3.h> 34#include <camera/CameraMetadata.h> 35#include <stdlib.h> 36#include <utils/Log.h> 37#include <utils/Errors.h> 38#include <ui/Fence.h> 39#include <gralloc_priv.h> 40#include "QCamera3HWI.h" 41#include "QCamera3Mem.h" 42#include "QCamera3Channel.h" 43#include "QCamera3PostProc.h" 44 45using namespace android; 46 47namespace qcamera { 48#define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX ) 49cam_capability_t *gCamCapability[MM_CAMERA_MAX_NUM_SENSORS]; 50parm_buffer_t *prevSettings; 51const camera_metadata_t *gStaticMetadata; 52 53const QCamera3HardwareInterface::QCameraMap QCamera3HardwareInterface::EFFECT_MODES_MAP[] = { 54 { ANDROID_CONTROL_EFFECT_MODE_OFF, CAM_EFFECT_MODE_OFF }, 55 { ANDROID_CONTROL_EFFECT_MODE_MONO, CAM_EFFECT_MODE_MONO }, 56 { ANDROID_CONTROL_EFFECT_MODE_NEGATIVE, CAM_EFFECT_MODE_NEGATIVE }, 57 { ANDROID_CONTROL_EFFECT_MODE_SOLARIZE, CAM_EFFECT_MODE_SOLARIZE }, 58 { ANDROID_CONTROL_EFFECT_MODE_SEPIA, CAM_EFFECT_MODE_SEPIA }, 59 { ANDROID_CONTROL_EFFECT_MODE_POSTERIZE, CAM_EFFECT_MODE_POSTERIZE }, 60 { ANDROID_CONTROL_EFFECT_MODE_WHITEBOARD, CAM_EFFECT_MODE_WHITEBOARD }, 61 { ANDROID_CONTROL_EFFECT_MODE_BLACKBOARD, CAM_EFFECT_MODE_BLACKBOARD }, 62 { ANDROID_CONTROL_EFFECT_MODE_AQUA, CAM_EFFECT_MODE_AQUA } 63}; 64 65const QCamera3HardwareInterface::QCameraMap QCamera3HardwareInterface::WHITE_BALANCE_MODES_MAP[] = { 66 { ANDROID_CONTROL_AWB_MODE_OFF, CAM_WB_MODE_OFF }, 67 { ANDROID_CONTROL_AWB_MODE_AUTO, CAM_WB_MODE_AUTO }, 68 { ANDROID_CONTROL_AWB_MODE_INCANDESCENT, CAM_WB_MODE_INCANDESCENT }, 69 { ANDROID_CONTROL_AWB_MODE_FLUORESCENT, CAM_WB_MODE_FLUORESCENT }, 70 { ANDROID_CONTROL_AWB_MODE_WARM_FLUORESCENT,CAM_WB_MODE_WARM_FLUORESCENT}, 71 { ANDROID_CONTROL_AWB_MODE_DAYLIGHT, CAM_WB_MODE_DAYLIGHT }, 72 { ANDROID_CONTROL_AWB_MODE_CLOUDY_DAYLIGHT, CAM_WB_MODE_CLOUDY_DAYLIGHT }, 73 { ANDROID_CONTROL_AWB_MODE_TWILIGHT, CAM_WB_MODE_TWILIGHT }, 74 { ANDROID_CONTROL_AWB_MODE_SHADE, CAM_WB_MODE_SHADE } 75}; 76 77const QCamera3HardwareInterface::QCameraMap QCamera3HardwareInterface::SCENE_MODES_MAP[] = { 78 { ANDROID_CONTROL_SCENE_MODE_UNSUPPORTED, CAM_SCENE_MODE_OFF }, 79 { ANDROID_CONTROL_SCENE_MODE_ACTION, CAM_SCENE_MODE_ACTION }, 80 { ANDROID_CONTROL_SCENE_MODE_PORTRAIT, CAM_SCENE_MODE_PORTRAIT }, 81 { ANDROID_CONTROL_SCENE_MODE_LANDSCAPE, CAM_SCENE_MODE_LANDSCAPE }, 82 { ANDROID_CONTROL_SCENE_MODE_NIGHT, CAM_SCENE_MODE_NIGHT }, 83 { ANDROID_CONTROL_SCENE_MODE_NIGHT_PORTRAIT, CAM_SCENE_MODE_NIGHT_PORTRAIT }, 84 { ANDROID_CONTROL_SCENE_MODE_THEATRE, CAM_SCENE_MODE_THEATRE }, 85 { ANDROID_CONTROL_SCENE_MODE_BEACH, CAM_SCENE_MODE_BEACH }, 86 { ANDROID_CONTROL_SCENE_MODE_SNOW, CAM_SCENE_MODE_SNOW }, 87 { ANDROID_CONTROL_SCENE_MODE_SUNSET, CAM_SCENE_MODE_SUNSET }, 88 { ANDROID_CONTROL_SCENE_MODE_STEADYPHOTO, CAM_SCENE_MODE_ANTISHAKE }, 89 { ANDROID_CONTROL_SCENE_MODE_FIREWORKS , CAM_SCENE_MODE_FIREWORKS }, 90 { ANDROID_CONTROL_SCENE_MODE_SPORTS , CAM_SCENE_MODE_SPORTS }, 91 { ANDROID_CONTROL_SCENE_MODE_PARTY, CAM_SCENE_MODE_PARTY }, 92 { ANDROID_CONTROL_SCENE_MODE_CANDLELIGHT, CAM_SCENE_MODE_CANDLELIGHT }, 93 { ANDROID_CONTROL_SCENE_MODE_BARCODE, CAM_SCENE_MODE_BARCODE} 94}; 95 96const QCamera3HardwareInterface::QCameraMap QCamera3HardwareInterface::FOCUS_MODES_MAP[] = { 97 { ANDROID_CONTROL_AF_MODE_OFF, CAM_FOCUS_MODE_OFF }, 98 { ANDROID_CONTROL_AF_MODE_OFF, CAM_FOCUS_MODE_FIXED }, 99 { ANDROID_CONTROL_AF_MODE_AUTO, CAM_FOCUS_MODE_AUTO }, 100 { ANDROID_CONTROL_AF_MODE_MACRO, CAM_FOCUS_MODE_MACRO }, 101 { ANDROID_CONTROL_AF_MODE_EDOF, CAM_FOCUS_MODE_EDOF }, 102 { ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE, CAM_FOCUS_MODE_CONTINOUS_PICTURE }, 103 { ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO, CAM_FOCUS_MODE_CONTINOUS_VIDEO } 104}; 105 106const QCamera3HardwareInterface::QCameraMap QCamera3HardwareInterface::ANTIBANDING_MODES_MAP[] = { 107 { ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF, CAM_ANTIBANDING_MODE_OFF }, 108 { ANDROID_CONTROL_AE_ANTIBANDING_MODE_50HZ, CAM_ANTIBANDING_MODE_50HZ }, 109 { ANDROID_CONTROL_AE_ANTIBANDING_MODE_60HZ, CAM_ANTIBANDING_MODE_60HZ }, 110 { ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO, CAM_ANTIBANDING_MODE_AUTO } 111}; 112 113const QCamera3HardwareInterface::QCameraMap QCamera3HardwareInterface::AUTO_EXPOSURE_MAP[] = { 114 { ANDROID_CONTROL_AE_MODE_OFF, CAM_AEC_MODE_OFF }, 115 { ANDROID_CONTROL_AE_MODE_ON, CAM_AEC_MODE_FRAME_AVERAGE }, 116}; 117 118const QCamera3HardwareInterface::QCameraMap QCamera3HardwareInterface::FLASH_MODES_MAP[] = { 119 { ANDROID_FLASH_MODE_OFF, CAM_FLASH_MODE_OFF }, 120 { ANDROID_FLASH_MODE_SINGLE, CAM_FLASH_MODE_ON }, 121 { ANDROID_FLASH_MODE_TORCH, CAM_FLASH_MODE_TORCH} 122}; 123 124 125camera3_device_ops_t QCamera3HardwareInterface::mCameraOps = { 126 initialize: QCamera3HardwareInterface::initialize, 127 configure_streams: QCamera3HardwareInterface::configure_streams, 128 register_stream_buffers: QCamera3HardwareInterface::register_stream_buffers, 129 construct_default_request_settings: QCamera3HardwareInterface::construct_default_request_settings, 130 process_capture_request: QCamera3HardwareInterface::process_capture_request, 131 get_metadata_vendor_tag_ops: QCamera3HardwareInterface::get_metadata_vendor_tag_ops, 132 dump: QCamera3HardwareInterface::dump, 133}; 134 135 136/*=========================================================================== 137 * FUNCTION : QCamera3HardwareInterface 138 * 139 * DESCRIPTION: constructor of QCamera3HardwareInterface 140 * 141 * PARAMETERS : 142 * @cameraId : camera ID 143 * 144 * RETURN : none 145 *==========================================================================*/ 146QCamera3HardwareInterface::QCamera3HardwareInterface(int cameraId) 147 : mCameraId(cameraId), 148 mCameraHandle(NULL), 149 mCameraOpened(false), 150 mCallbackOps(NULL), 151 mInputStream(NULL), 152 mMetadataChannel(NULL), 153 mFirstRequest(false), 154 mParamHeap(NULL), 155 mParameters(NULL), 156 mJpegSettings(NULL) 157{ 158 mCameraDevice.common.tag = HARDWARE_DEVICE_TAG; 159 mCameraDevice.common.version = CAMERA_DEVICE_API_VERSION_3_0; 160 mCameraDevice.common.close = close_camera_device; 161 mCameraDevice.ops = &mCameraOps; 162 mCameraDevice.priv = this; 163 gCamCapability[cameraId]->version = CAM_HAL_V3; 164 165 pthread_mutex_init(&mRequestLock, NULL); 166 pthread_cond_init(&mRequestCond, NULL); 167 mPendingRequest = 0; 168 169 pthread_mutex_init(&mMutex, NULL); 170 pthread_mutex_init(&mCaptureResultLock, NULL); 171 172 for (size_t i = 0; i < CAMERA3_TEMPLATE_COUNT; i++) 173 mDefaultMetadata[i] = NULL; 174} 175 176/*=========================================================================== 177 * FUNCTION : ~QCamera3HardwareInterface 178 * 179 * DESCRIPTION: destructor of QCamera3HardwareInterface 180 * 181 * PARAMETERS : none 182 * 183 * RETURN : none 184 *==========================================================================*/ 185QCamera3HardwareInterface::~QCamera3HardwareInterface() 186{ 187 ALOGE("%s: %d", __func__, __LINE__); 188 /* Clean up all channels */ 189 mMetadataChannel->stop(); 190 delete mMetadataChannel; 191 mMetadataChannel = NULL; 192 for (List<stream_info_t *>::iterator it = mStreamInfo.begin(); 193 it != mStreamInfo.end(); it++) { 194 QCamera3Channel *channel = (QCamera3Channel *)(*it)->stream->priv; 195 channel->stop(); 196 delete channel; 197 free (*it); 198 } 199 200 ALOGE("%s: %d", __func__, __LINE__); 201 if (mJpegSettings != NULL) { 202 free(mJpegSettings); 203 mJpegSettings = NULL; 204 } 205 ALOGE("%s: %d", __func__, __LINE__); 206 deinitParameters(); 207 ALOGE("%s: %d", __func__, __LINE__); 208 closeCamera(); 209 210 ALOGE("%s: %d", __func__, __LINE__); 211 for (size_t i = 0; i < CAMERA3_TEMPLATE_COUNT; i++) 212 if (mDefaultMetadata[i]) 213 free_camera_metadata(mDefaultMetadata[i]); 214 215 pthread_mutex_destroy(&mRequestLock); 216 pthread_cond_destroy(&mRequestCond); 217 218 pthread_mutex_destroy(&mMutex); 219 pthread_mutex_destroy(&mCaptureResultLock); 220} 221 222/*=========================================================================== 223 * FUNCTION : openCamera 224 * 225 * DESCRIPTION: open camera 226 * 227 * PARAMETERS : 228 * @hw_device : double ptr for camera device struct 229 * 230 * RETURN : int32_t type of status 231 * NO_ERROR -- success 232 * none-zero failure code 233 *==========================================================================*/ 234int QCamera3HardwareInterface::openCamera(struct hw_device_t **hw_device) 235{ 236 //int rc = NO_ERROR; 237 int rc = 0; 238 if (mCameraOpened) { 239 *hw_device = NULL; 240 return PERMISSION_DENIED; 241 } 242 243 rc = openCamera(); 244 if (rc == 0) 245 *hw_device = &mCameraDevice.common; 246 else 247 *hw_device = NULL; 248 return rc; 249} 250 251/*=========================================================================== 252 * FUNCTION : openCamera 253 * 254 * DESCRIPTION: open camera 255 * 256 * PARAMETERS : none 257 * 258 * RETURN : int32_t type of status 259 * NO_ERROR -- success 260 * none-zero failure code 261 *==========================================================================*/ 262int QCamera3HardwareInterface::openCamera() 263{ 264 if (mCameraHandle) { 265 ALOGE("Failure: Camera already opened"); 266 return ALREADY_EXISTS; 267 } 268 mCameraHandle = camera_open(mCameraId); 269 if (!mCameraHandle) { 270 ALOGE("camera_open failed."); 271 return UNKNOWN_ERROR; 272 } 273 274 mCameraOpened = true; 275 276 return NO_ERROR; 277} 278 279/*=========================================================================== 280 * FUNCTION : closeCamera 281 * 282 * DESCRIPTION: close camera 283 * 284 * PARAMETERS : none 285 * 286 * RETURN : int32_t type of status 287 * NO_ERROR -- success 288 * none-zero failure code 289 *==========================================================================*/ 290int QCamera3HardwareInterface::closeCamera() 291{ 292 int rc = NO_ERROR; 293 294 rc = mCameraHandle->ops->close_camera(mCameraHandle->camera_handle); 295 mCameraHandle = NULL; 296 mCameraOpened = false; 297 298 return rc; 299} 300 301/*=========================================================================== 302 * FUNCTION : initialize 303 * 304 * DESCRIPTION: Initialize frameworks callback functions 305 * 306 * PARAMETERS : 307 * @callback_ops : callback function to frameworks 308 * 309 * RETURN : 310 * 311 *==========================================================================*/ 312int QCamera3HardwareInterface::initialize( 313 const struct camera3_callback_ops *callback_ops) 314{ 315 int rc; 316 317 pthread_mutex_lock(&mMutex); 318 319 rc = initParameters(); 320 if (rc < 0) { 321 ALOGE("%s: initParamters failed %d", __func__, rc); 322 goto err1; 323 } 324 //Create metadata channel and initialize it 325 mMetadataChannel = new QCamera3MetadataChannel(mCameraHandle->camera_handle, 326 mCameraHandle->ops, captureResultCb, 327 &gCamCapability[mCameraId]->padding_info, this); 328 if (mMetadataChannel == NULL) { 329 ALOGE("%s: failed to allocate metadata channel", __func__); 330 rc = -ENOMEM; 331 goto err2; 332 } 333 rc = mMetadataChannel->initialize(); 334 if (rc < 0) { 335 ALOGE("%s: metadata channel initialization failed", __func__); 336 goto err3; 337 } 338 339 mCallbackOps = callback_ops; 340 341 pthread_mutex_unlock(&mMutex); 342 return 0; 343 344err3: 345 delete mMetadataChannel; 346 mMetadataChannel = NULL; 347err2: 348 deinitParameters(); 349err1: 350 pthread_mutex_unlock(&mMutex); 351 return rc; 352} 353 354/*=========================================================================== 355 * FUNCTION : configureStreams 356 * 357 * DESCRIPTION: Reset HAL camera device processing pipeline and set up new input 358 * and output streams. 359 * 360 * PARAMETERS : 361 * @stream_list : streams to be configured 362 * 363 * RETURN : 364 * 365 *==========================================================================*/ 366int QCamera3HardwareInterface::configureStreams( 367 camera3_stream_configuration_t *streamList) 368{ 369 int rc = 0; 370 pthread_mutex_lock(&mMutex); 371 372 // Sanity check stream_list 373 if (streamList == NULL) { 374 ALOGE("%s: NULL stream configuration", __func__); 375 pthread_mutex_unlock(&mMutex); 376 return BAD_VALUE; 377 } 378 379 if (streamList->streams == NULL) { 380 ALOGE("%s: NULL stream list", __func__); 381 pthread_mutex_unlock(&mMutex); 382 return BAD_VALUE; 383 } 384 385 if (streamList->num_streams < 1) { 386 ALOGE("%s: Bad number of streams requested: %d", __func__, 387 streamList->num_streams); 388 pthread_mutex_unlock(&mMutex); 389 return BAD_VALUE; 390 } 391 392 camera3_stream_t *inputStream = NULL; 393 /* first invalidate all the steams in the mStreamList 394 * if they appear again, they will be validated */ 395 for (List<stream_info_t*>::iterator it=mStreamInfo.begin(); 396 it != mStreamInfo.end(); it++) { 397 (*it)->status = INVALID; 398 } 399 for (size_t i = 0; i < streamList->num_streams; i++) { 400 camera3_stream_t *newStream = streamList->streams[i]; 401 ALOGV("%s: newStream type = %d, stream format = %d", 402 __func__, newStream->stream_type, newStream->format); 403 //if the stream is in the mStreamList validate it 404 bool stream_exists = false; 405 for (List<stream_info_t*>::iterator it=mStreamInfo.begin(); 406 it != mStreamInfo.end(); it++) { 407 if ((*it)->stream == newStream) { 408 QCamera3Channel *channel = 409 (QCamera3Channel*)(*it)->stream->priv; 410 stream_exists = true; 411 (*it)->status = RECONFIGURE; 412 /*delete the channel object associated with the stream because 413 we need to reconfigure*/ 414 channel->stop(); 415 delete channel; 416 (*it)->stream->priv = NULL; 417 } 418 } 419 if (!stream_exists) { 420 //new stream 421 stream_info_t* stream_info; 422 stream_info = (stream_info_t* )malloc(sizeof(stream_info_t)); 423 stream_info->stream = newStream; 424 stream_info->status = VALID; 425 stream_info->registered = 0; 426 mStreamInfo.push_back(stream_info); 427 } 428 if (newStream->stream_type == CAMERA3_STREAM_INPUT) { 429 if (inputStream != NULL) { 430 ALOGE("%s: Multiple input streams requested!", __func__); 431 pthread_mutex_unlock(&mMutex); 432 return BAD_VALUE; 433 } 434 inputStream = newStream; 435 } 436 } 437 mInputStream = inputStream; 438 439 /* TODO: Clean up no longer used streams, and maintain others if this 440 * is not the 1st time configureStreams is called */ 441 /*clean up invalid streams*/ 442 for (List<stream_info_t*>::iterator it=mStreamInfo.begin(); 443 it != mStreamInfo.end();) { 444 if(((*it)->status) == INVALID){ 445 QCamera3Channel *channel = (QCamera3Channel*)(*it)->stream->priv; 446 channel->stop(); 447 delete channel; 448 delete[] (buffer_handle_t*)(*it)->buffer_set.buffers; 449 free(*it); 450 it = mStreamInfo.erase(it); 451 } else { 452 it++; 453 } 454 } 455 456 //mMetadataChannel->stop(); 457 458 /* Allocate channel objects for the requested streams */ 459 for (size_t i = 0; i < streamList->num_streams; i++) { 460 camera3_stream_t *newStream = streamList->streams[i]; 461 if (newStream->priv == NULL) { 462 //New stream, construct channel 463 switch (newStream->stream_type) { 464 case CAMERA3_STREAM_INPUT: 465 newStream->usage = GRALLOC_USAGE_HW_CAMERA_READ; 466 break; 467 case CAMERA3_STREAM_BIDIRECTIONAL: 468 newStream->usage = GRALLOC_USAGE_HW_CAMERA_READ | 469 GRALLOC_USAGE_HW_CAMERA_WRITE; 470 break; 471 case CAMERA3_STREAM_OUTPUT: 472 newStream->usage = GRALLOC_USAGE_HW_CAMERA_WRITE; 473 break; 474 default: 475 ALOGE("%s: Invalid stream_type %d", __func__, newStream->stream_type); 476 break; 477 } 478 479 if (newStream->stream_type == CAMERA3_STREAM_OUTPUT || 480 newStream->stream_type == CAMERA3_STREAM_BIDIRECTIONAL) { 481 QCamera3Channel *channel; 482 switch (newStream->format) { 483 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: 484 newStream->max_buffers = QCamera3RegularChannel::kMaxBuffers; 485 channel = new QCamera3RegularChannel(mCameraHandle->camera_handle, 486 mCameraHandle->ops, captureResultCb, 487 &gCamCapability[mCameraId]->padding_info, this, newStream); 488 if (channel == NULL) { 489 ALOGE("%s: allocation of channel failed", __func__); 490 pthread_mutex_unlock(&mMutex); 491 return -ENOMEM; 492 } 493 494 newStream->priv = channel; 495 break; 496 case HAL_PIXEL_FORMAT_BLOB: 497 newStream->max_buffers = QCamera3PicChannel::kMaxBuffers; 498 channel = new QCamera3PicChannel(mCameraHandle->camera_handle, 499 mCameraHandle->ops, captureResultCb, 500 &gCamCapability[mCameraId]->padding_info, this, newStream); 501 if (channel == NULL) { 502 ALOGE("%s: allocation of channel failed", __func__); 503 pthread_mutex_unlock(&mMutex); 504 return -ENOMEM; 505 } 506 newStream->priv = channel; 507 break; 508 509 //TODO: Add support for app consumed format? 510 default: 511 ALOGE("%s: not a supported format 0x%x", __func__, newStream->format); 512 break; 513 } 514 } 515 } else { 516 // Channel already exists for this stream 517 // Do nothing for now 518 } 519 } 520 /*For the streams to be reconfigured we need to register the buffers 521 since the framework wont*/ 522 for (List<stream_info_t *>::iterator it = mStreamInfo.begin(); 523 it != mStreamInfo.end(); it++) { 524 if ((*it)->status == RECONFIGURE) { 525 QCamera3Channel *channel = (QCamera3Channel *)(*it)->stream->priv; 526 /*only register buffers for streams that have already been 527 registered*/ 528 if ((*it)->registered) { 529 rc = channel->registerBuffers((*it)->buffer_set.num_buffers, 530 (*it)->buffer_set.buffers); 531 if (rc != NO_ERROR) { 532 ALOGE("%s: Failed to register the buffers of old stream,\ 533 rc = %d", __func__, rc); 534 } 535 ALOGE("%s: channel %p has %d buffers", 536 __func__, channel, (*it)->buffer_set.num_buffers); 537 } 538 } 539 540 ssize_t index = mPendingBuffersMap.indexOfKey((*it)->stream); 541 if (index == NAME_NOT_FOUND) { 542 mPendingBuffersMap.add((*it)->stream, 0); 543 } else { 544 mPendingBuffersMap.editValueAt(index) = 0; 545 } 546 } 547 548 /* Initialize mPendingRequestInfo and mPendnigBuffersMap */ 549 mPendingRequestsList.clear(); 550 551 //settings/parameters don't carry over for new configureStreams 552 memset(mParameters, 0, sizeof(parm_buffer_t)); 553 mFirstRequest = true; 554 555end: 556 pthread_mutex_unlock(&mMutex); 557 return rc; 558} 559 560/*=========================================================================== 561 * FUNCTION : validateCaptureRequest 562 * 563 * DESCRIPTION: validate a capture request from camera service 564 * 565 * PARAMETERS : 566 * @request : request from framework to process 567 * 568 * RETURN : 569 * 570 *==========================================================================*/ 571int QCamera3HardwareInterface::validateCaptureRequest( 572 camera3_capture_request_t *request) 573{ 574 ssize_t idx = 0; 575 const camera3_stream_buffer_t *b; 576 CameraMetadata meta; 577 578 /* Sanity check the request */ 579 if (request == NULL) { 580 ALOGE("%s: NULL capture request", __func__); 581 return BAD_VALUE; 582 } 583 584 uint32_t frameNumber = request->frame_number; 585 if (request->input_buffer != NULL && 586 request->input_buffer->stream != mInputStream) { 587 ALOGE("%s: Request %d: Input buffer not from input stream!", 588 __FUNCTION__, frameNumber); 589 return BAD_VALUE; 590 } 591 if (request->num_output_buffers < 1 || request->output_buffers == NULL) { 592 ALOGE("%s: Request %d: No output buffers provided!", 593 __FUNCTION__, frameNumber); 594 return BAD_VALUE; 595 } 596 if (request->input_buffer != NULL) { 597 //TODO 598 ALOGE("%s: Not supporting input buffer yet", __func__); 599 return BAD_VALUE; 600 } 601 602 // Validate all buffers 603 b = request->output_buffers; 604 do { 605 QCamera3Channel *channel = 606 static_cast<QCamera3Channel*>(b->stream->priv); 607 if (channel == NULL) { 608 ALOGE("%s: Request %d: Buffer %d: Unconfigured stream!", 609 __func__, frameNumber, idx); 610 return BAD_VALUE; 611 } 612 if (b->status != CAMERA3_BUFFER_STATUS_OK) { 613 ALOGE("%s: Request %d: Buffer %d: Status not OK!", 614 __func__, frameNumber, idx); 615 return BAD_VALUE; 616 } 617 if (b->release_fence != -1) { 618 ALOGE("%s: Request %d: Buffer %d: Has a release fence!", 619 __func__, frameNumber, idx); 620 return BAD_VALUE; 621 } 622 if (b->buffer == NULL) { 623 ALOGE("%s: Request %d: Buffer %d: NULL buffer handle!", 624 __func__, frameNumber, idx); 625 return BAD_VALUE; 626 } 627 idx++; 628 b = request->output_buffers + idx; 629 } while (idx < (ssize_t)request->num_output_buffers); 630 631 return NO_ERROR; 632} 633 634/*=========================================================================== 635 * FUNCTION : registerStreamBuffers 636 * 637 * DESCRIPTION: Register buffers for a given stream with the HAL device. 638 * 639 * PARAMETERS : 640 * @stream_list : streams to be configured 641 * 642 * RETURN : 643 * 644 *==========================================================================*/ 645int QCamera3HardwareInterface::registerStreamBuffers( 646 const camera3_stream_buffer_set_t *buffer_set) 647{ 648 int rc = 0; 649 650 pthread_mutex_lock(&mMutex); 651 652 if (buffer_set == NULL) { 653 ALOGE("%s: Invalid buffer_set parameter.", __func__); 654 pthread_mutex_unlock(&mMutex); 655 return -EINVAL; 656 } 657 if (buffer_set->stream == NULL) { 658 ALOGE("%s: Invalid stream parameter.", __func__); 659 pthread_mutex_unlock(&mMutex); 660 return -EINVAL; 661 } 662 if (buffer_set->num_buffers < 1) { 663 ALOGE("%s: Invalid num_buffers %d.", __func__, buffer_set->num_buffers); 664 pthread_mutex_unlock(&mMutex); 665 return -EINVAL; 666 } 667 if (buffer_set->buffers == NULL) { 668 ALOGE("%s: Invalid buffers parameter.", __func__); 669 pthread_mutex_unlock(&mMutex); 670 return -EINVAL; 671 } 672 673 camera3_stream_t *stream = buffer_set->stream; 674 QCamera3Channel *channel = (QCamera3Channel *)stream->priv; 675 676 //set the buffer_set in the mStreamInfo array 677 for (List<stream_info_t *>::iterator it = mStreamInfo.begin(); 678 it != mStreamInfo.end(); it++) { 679 if ((*it)->stream == stream) { 680 uint32_t numBuffers = buffer_set->num_buffers; 681 (*it)->buffer_set.stream = buffer_set->stream; 682 (*it)->buffer_set.num_buffers = numBuffers; 683 (*it)->buffer_set.buffers = new buffer_handle_t*[numBuffers]; 684 if ((*it)->buffer_set.buffers == NULL) { 685 ALOGE("%s: Failed to allocate buffer_handle_t*", __func__); 686 pthread_mutex_unlock(&mMutex); 687 return -ENOMEM; 688 } 689 for (size_t j = 0; j < numBuffers; j++){ 690 (*it)->buffer_set.buffers[j] = buffer_set->buffers[j]; 691 } 692 (*it)->registered = 1; 693 } 694 } 695 696 if (stream->stream_type != CAMERA3_STREAM_OUTPUT) { 697 ALOGE("%s: not yet support non output type stream", __func__); 698 pthread_mutex_unlock(&mMutex); 699 return -EINVAL; 700 } 701 rc = channel->registerBuffers(buffer_set->num_buffers, buffer_set->buffers); 702 if (rc < 0) { 703 ALOGE("%s: registerBUffers for stream %p failed", __func__, stream); 704 pthread_mutex_unlock(&mMutex); 705 return -ENODEV; 706 } 707 708 pthread_mutex_unlock(&mMutex); 709 return NO_ERROR; 710} 711 712/*=========================================================================== 713 * FUNCTION : processCaptureRequest 714 * 715 * DESCRIPTION: process a capture request from camera service 716 * 717 * PARAMETERS : 718 * @request : request from framework to process 719 * 720 * RETURN : 721 * 722 *==========================================================================*/ 723int QCamera3HardwareInterface::processCaptureRequest( 724 camera3_capture_request_t *request) 725{ 726 int rc = NO_ERROR; 727 CameraMetadata meta; 728 729 pthread_mutex_lock(&mMutex); 730 731 rc = validateCaptureRequest(request); 732 if (rc != NO_ERROR) { 733 ALOGE("%s: incoming request is not valid", __func__); 734 pthread_mutex_unlock(&mMutex); 735 return rc; 736 } 737 738 uint32_t frameNumber = request->frame_number; 739 740 rc = setFrameParameters(request->frame_number, request->settings); 741 if (rc < 0) { 742 ALOGE("%s: fail to set frame parameters", __func__); 743 pthread_mutex_unlock(&mMutex); 744 return rc; 745 } 746 747 ALOGV("%s: %d, num_output_buffers = %d", __func__, __LINE__, 748 request->num_output_buffers); 749 // Acquire all request buffers first 750 for (size_t i = 0; i < request->num_output_buffers; i++) { 751 const camera3_stream_buffer_t& output = request->output_buffers[i]; 752 sp<Fence> acquireFence = new Fence(output.acquire_fence); 753 754 if (output.stream->format == HAL_PIXEL_FORMAT_BLOB) { 755 //Call function to store local copy of jpeg data for encode params. 756 rc = getJpegSettings(request->settings); 757 if (rc < 0) { 758 ALOGE("%s: failed to get jpeg parameters", __func__); 759 pthread_mutex_unlock(&mMutex); 760 return rc; 761 } 762 } 763 764 rc = acquireFence->wait(Fence::TIMEOUT_NEVER); 765 if (rc != OK) { 766 ALOGE("%s: fence wait failed %d", __func__, rc); 767 pthread_mutex_unlock(&mMutex); 768 return rc; 769 } 770 } 771 772 ALOGV("%s: %d", __func__, __LINE__); 773 774 /* Update pending request list and pending buffers map */ 775 pthread_mutex_lock(&mRequestLock); 776 PendingRequestInfo pendingRequest; 777 pendingRequest.frame_number = frameNumber; 778 pendingRequest.num_buffers = request->num_output_buffers; 779// pendingRequest.metadata = NULL; 780 for (size_t i = 0; i < request->num_output_buffers; i++) { 781 RequestedBufferInfo requestedBuf; 782 requestedBuf.stream = request->output_buffers[i].stream; 783 requestedBuf.buffer = NULL; 784 pendingRequest.buffers.push_back(requestedBuf); 785 786 mPendingBuffersMap.editValueFor(requestedBuf.stream)++; 787 } 788 mPendingRequestsList.push_back(pendingRequest); 789 pthread_mutex_unlock(&mRequestLock); 790 791 // Notify metadata channel we receive a request 792 mMetadataChannel->request(NULL, frameNumber); 793 794 // Call request on other streams 795 for (size_t i = 0; i < request->num_output_buffers; i++) { 796 const camera3_stream_buffer_t& output = request->output_buffers[i]; 797 QCamera3Channel *channel = (QCamera3Channel *)output.stream->priv; 798 799 if (channel == NULL) { 800 ALOGE("%s: invalid channel pointer for stream", __func__); 801 continue; 802 } 803 804 if (output.stream->format == HAL_PIXEL_FORMAT_BLOB) { 805 rc = channel->request(output.buffer, frameNumber, mJpegSettings); 806 } else { 807 ALOGE("%s: %d, request with buffer %p, frame_number %d", __func__, __LINE__, output.buffer, frameNumber); 808 rc = channel->request(output.buffer, frameNumber); 809 } 810 if (rc < 0) 811 ALOGE("%s: request failed", __func__); 812 } 813 814 mFirstRequest = false; 815 816 //Block on conditional variable 817 pthread_mutex_lock(&mRequestLock); 818 mPendingRequest = 1; 819 while (mPendingRequest == 1) { 820 pthread_cond_wait(&mRequestCond, &mRequestLock); 821 } 822 pthread_mutex_unlock(&mRequestLock); 823 824 pthread_mutex_unlock(&mMutex); 825 return rc; 826} 827 828/*=========================================================================== 829 * FUNCTION : getMetadataVendorTagOps 830 * 831 * DESCRIPTION: 832 * 833 * PARAMETERS : 834 * 835 * 836 * RETURN : 837 *==========================================================================*/ 838void QCamera3HardwareInterface::getMetadataVendorTagOps( 839 vendor_tag_query_ops_t* /*ops*/) 840{ 841 /* Enable locks when we eventually add Vendor Tags */ 842 /* 843 pthread_mutex_lock(&mMutex); 844 845 pthread_mutex_unlock(&mMutex); 846 */ 847 return; 848} 849 850/*=========================================================================== 851 * FUNCTION : dump 852 * 853 * DESCRIPTION: 854 * 855 * PARAMETERS : 856 * 857 * 858 * RETURN : 859 *==========================================================================*/ 860void QCamera3HardwareInterface::dump(int /*fd*/) 861{ 862 /*Enable lock when we implement this function*/ 863 /* 864 pthread_mutex_lock(&mMutex); 865 866 pthread_mutex_unlock(&mMutex); 867 */ 868 return; 869} 870 871/*=========================================================================== 872 * FUNCTION : captureResultCb 873 * 874 * DESCRIPTION: Callback handler for all capture result 875 * (streams, as well as metadata) 876 * 877 * PARAMETERS : 878 * @metadata : metadata information 879 * @buffer : actual gralloc buffer to be returned to frameworks. 880 * NULL if metadata. 881 * 882 * RETURN : NONE 883 *==========================================================================*/ 884void QCamera3HardwareInterface::captureResultCb(mm_camera_super_buf_t *metadata_buf, 885 camera3_stream_buffer_t *buffer, uint32_t frame_number) 886{ 887 pthread_mutex_lock(&mRequestLock); 888 889 if (metadata_buf) { 890 metadata_buffer_t *metadata = (metadata_buffer_t *)metadata_buf->bufs[0]->buffer; 891 int32_t frame_number_valid = *(int32_t *) 892 POINTER_OF(CAM_INTF_META_FRAME_NUMBER_VALID, metadata); 893 uint32_t frame_number = *(uint32_t *) 894 POINTER_OF(CAM_INTF_META_FRAME_NUMBER, metadata); 895 const struct timeval *tv = (const struct timeval *) 896 POINTER_OF(CAM_INTF_META_SENSOR_TIMESTAMP, metadata); 897 nsecs_t capture_time = (nsecs_t)tv->tv_sec * NSEC_PER_SEC + 898 tv->tv_usec * NSEC_PER_USEC; 899 900 if (!frame_number_valid) { 901 ALOGI("%s: Not a valid frame number, used as SOF only", __func__); 902 mMetadataChannel->bufDone(metadata_buf); 903 goto done_metadata; 904 } 905 ALOGE("%s: valid frame_number = %d, capture_time = %lld", __func__, 906 frame_number, capture_time); 907 908 // Go through the pending requests info and send shutter/results to frameworks 909 for (List<PendingRequestInfo>::iterator i = mPendingRequestsList.begin(); 910 i != mPendingRequestsList.end() && i->frame_number <= frame_number;) { 911 camera3_capture_result_t result; 912 camera3_notify_msg_t notify_msg; 913 ALOGE("%s: frame_number in the list is %d", __func__, i->frame_number); 914 915 // Flush out all entries with less or equal frame numbers. 916 917 //TODO: Make sure shutter timestamp really reflects shutter timestamp. 918 //Right now it's the same as metadata timestamp 919 920 //TODO: When there is metadata drop, how do we derive the timestamp of 921 //dropped frames? For now, we fake the dropped timestamp by substracting 922 //from the reported timestamp 923 nsecs_t current_capture_time = capture_time - 924 (frame_number - i->frame_number) * NSEC_PER_33MSEC; 925 926 // Send shutter notify to frameworks 927 notify_msg.type = CAMERA3_MSG_SHUTTER; 928 notify_msg.message.shutter.frame_number = i->frame_number; 929 notify_msg.message.shutter.timestamp = current_capture_time; 930 mCallbackOps->notify(mCallbackOps, ¬ify_msg); 931 ALOGE("%s: notify frame_number = %d, capture_time = %lld", __func__, 932 i->frame_number, capture_time); 933 934 // Send empty metadata with already filled buffers for dropped metadata 935 // and send valid metadata with already filled buffers for current metadata 936 if (i->frame_number < frame_number) { 937 CameraMetadata emptyMetadata(1, 0); 938 emptyMetadata.update(ANDROID_SENSOR_TIMESTAMP, 939 ¤t_capture_time, 1); 940 result.result = emptyMetadata.release(); 941 } else { 942 result.result = translateCbMetadataToResultMetadata(metadata, 943 current_capture_time); 944 // Return metadata buffer 945 mMetadataChannel->bufDone(metadata_buf); 946 } 947 if (!result.result) { 948 ALOGE("%s: metadata is NULL", __func__); 949 } 950 result.frame_number = i->frame_number; 951 result.num_output_buffers = 0; 952 result.output_buffers = NULL; 953 for (List<RequestedBufferInfo>::iterator j = i->buffers.begin(); 954 j != i->buffers.end(); j++) { 955 if (j->buffer) { 956 result.num_output_buffers++; 957 } 958 } 959 960 if (result.num_output_buffers > 0) { 961 camera3_stream_buffer_t *result_buffers = 962 new camera3_stream_buffer_t[result.num_output_buffers]; 963 if (!result_buffers) { 964 ALOGE("%s: Fatal error: out of memory", __func__); 965 } 966 size_t result_buffers_idx = 0; 967 for (List<RequestedBufferInfo>::iterator j = i->buffers.begin(); 968 j != i->buffers.end(); j++) { 969 if (j->buffer) { 970 result_buffers[result_buffers_idx++] = *(j->buffer); 971 free(j->buffer); 972 mPendingBuffersMap.editValueFor(j->stream)--; 973 } 974 } 975 result.output_buffers = result_buffers; 976 977 mCallbackOps->process_capture_result(mCallbackOps, &result); 978 ALOGE("%s: meta frame_number = %d, capture_time = %lld", __func__, 979 result.frame_number, 980 current_capture_time); 981 free_camera_metadata((camera_metadata_t *)result.result); 982 delete[] result_buffers; 983 } else { 984 mCallbackOps->process_capture_result(mCallbackOps, &result); 985 ALOGE("%s: meta frame_number = %d, capture_time = %lld", __func__, 986 result.frame_number, current_capture_time); 987 free_camera_metadata((camera_metadata_t *)result.result); 988 } 989 // erase the element from the list 990 i = mPendingRequestsList.erase(i); 991 } 992 993 994done_metadata: 995 bool max_buffers_dequeued = false; 996 for (size_t i = 0; i < mPendingBuffersMap.size(); i++) { 997 const camera3_stream_t *stream = mPendingBuffersMap.keyAt(i); 998 uint32_t queued_buffers = mPendingBuffersMap.valueAt(i); 999 if (queued_buffers == stream->max_buffers) { 1000 max_buffers_dequeued = true; 1001 break; 1002 } 1003 } 1004 if (!max_buffers_dequeued) { 1005 // Unblock process_capture_request 1006 mPendingRequest = 0; 1007 pthread_cond_signal(&mRequestCond); 1008 } 1009 } else { 1010 // If the frame number doesn't exist in the pending request list, 1011 // directly send the buffer to the frameworks, and update pending buffers map 1012 // Otherwise, book-keep the buffer. 1013 List<PendingRequestInfo>::iterator i = mPendingRequestsList.begin(); 1014 while (i != mPendingRequestsList.end() && i->frame_number != frame_number) 1015 i++; 1016 if (i == mPendingRequestsList.end()) { 1017 // Verify all pending requests frame_numbers are greater 1018 for (List<PendingRequestInfo>::iterator j = mPendingRequestsList.begin(); 1019 j != mPendingRequestsList.end(); j++) { 1020 if (j->frame_number < frame_number) { 1021 ALOGE("%s: Error: pending frame number %d is smaller than %d", 1022 __func__, j->frame_number, frame_number); 1023 } 1024 } 1025 camera3_capture_result_t result; 1026 result.result = NULL; 1027 result.frame_number = frame_number; 1028 result.num_output_buffers = 1; 1029 result.output_buffers = buffer; 1030 ALOGE("%s: result frame_number = %d, buffer = %p", 1031 __func__, frame_number, buffer); 1032 mPendingBuffersMap.editValueFor(buffer->stream)--; 1033 mCallbackOps->process_capture_result(mCallbackOps, &result); 1034 } else { 1035 for (List<RequestedBufferInfo>::iterator j = i->buffers.begin(); 1036 j != i->buffers.end(); j++) { 1037 if (j->stream == buffer->stream) { 1038 if (j->buffer != NULL) { 1039 ALOGE("%s: Error: buffer is already set", __func__); 1040 } else { 1041 j->buffer = (camera3_stream_buffer_t *)malloc( 1042 sizeof(camera3_stream_buffer_t)); 1043 *(j->buffer) = *buffer; 1044 ALOGE("%s: cache buffer %p at result frame_number %d", 1045 __func__, buffer, frame_number); 1046 } 1047 } 1048 } 1049 } 1050 } 1051 1052 pthread_mutex_unlock(&mRequestLock); 1053 return; 1054} 1055 1056/*=========================================================================== 1057 * FUNCTION : translateCbMetadataToResultMetadata 1058 * 1059 * DESCRIPTION: 1060 * 1061 * PARAMETERS : 1062 * @metadata : metadata information from callback 1063 * 1064 * RETURN : camera_metadata_t* 1065 * metadata in a format specified by fwk 1066 *==========================================================================*/ 1067camera_metadata_t* 1068QCamera3HardwareInterface::translateCbMetadataToResultMetadata 1069 (metadata_buffer_t *metadata, nsecs_t timestamp) 1070{ 1071 CameraMetadata camMetadata; 1072 camera_metadata_t* resultMetadata; 1073 1074 1075 camMetadata.update(ANDROID_SENSOR_TIMESTAMP, ×tamp, 1); 1076 1077 /*CAM_INTF_META_HISTOGRAM - TODO*/ 1078 /*cam_hist_stats_t *histogram = 1079 (cam_hist_stats_t *)POINTER_OF(CAM_INTF_META_HISTOGRAM, 1080 metadata);*/ 1081 1082 /*face detection*/ 1083 cam_face_detection_data_t *faceDetectionInfo =(cam_face_detection_data_t *) 1084 POINTER_OF(CAM_INTF_META_FACE_DETECTION, metadata); 1085 uint8_t numFaces = faceDetectionInfo->num_faces_detected; 1086 int32_t faceIds[numFaces]; 1087 uint8_t faceScores[numFaces]; 1088 int32_t faceRectangles[numFaces * 4]; 1089 int32_t faceLandmarks[numFaces * 6]; 1090 int j = 0, k = 0; 1091 for (int i = 0; i < numFaces; i++) { 1092 faceIds[i] = faceDetectionInfo->faces[i].face_id; 1093 faceScores[i] = faceDetectionInfo->faces[i].score; 1094 convertRegions(faceDetectionInfo->faces[i].face_boundary, 1095 faceRectangles+j, -1); 1096 convertLandmarks(faceDetectionInfo->faces[i], faceLandmarks+k); 1097 j+= 4; 1098 k+= 6; 1099 } 1100 camMetadata.update(ANDROID_STATISTICS_FACE_IDS, faceIds, numFaces); 1101 camMetadata.update(ANDROID_STATISTICS_FACE_SCORES, faceScores, numFaces); 1102 camMetadata.update(ANDROID_STATISTICS_FACE_RECTANGLES, 1103 faceRectangles, numFaces*4); 1104 camMetadata.update(ANDROID_STATISTICS_FACE_LANDMARKS, 1105 faceLandmarks, numFaces*6); 1106 1107 1108 /*autofocus - TODO*/ 1109 /*cam_auto_focus_data_t *afData =(cam_auto_focus_data_t *) 1110 POINTER_OF(CAM_INTF_META_AUTOFOCUS_DATA,metadata);*/ 1111 1112 uint8_t *color_correct_mode = 1113 (uint8_t *)POINTER_OF(CAM_INTF_META_COLOR_CORRECT_MODE, metadata); 1114 camMetadata.update(ANDROID_COLOR_CORRECTION_MODE, color_correct_mode, 1); 1115 1116 int32_t *ae_precapture_id = 1117 (int32_t *)POINTER_OF(CAM_INTF_META_AEC_PRECAPTURE_ID, metadata); 1118 camMetadata.update(ANDROID_CONTROL_AE_PRECAPTURE_ID, ae_precapture_id, 1); 1119 1120 /*aec regions*/ 1121 cam_area_t *hAeRegions = 1122 (cam_area_t *)POINTER_OF(CAM_INTF_META_AEC_ROI, metadata); 1123 int32_t aeRegions[5]; 1124 convertRegions(hAeRegions->rect, aeRegions, hAeRegions->weight); 1125 camMetadata.update(ANDROID_CONTROL_AE_REGIONS, aeRegions, 5); 1126 1127 uint8_t *ae_state = 1128 (uint8_t *)POINTER_OF(CAM_INTF_META_AEC_STATE, metadata); 1129 camMetadata.update(ANDROID_CONTROL_AE_STATE, ae_state, 1); 1130 1131 uint8_t *focusMode = 1132 (uint8_t *)POINTER_OF(CAM_INTF_PARM_FOCUS_MODE, metadata); 1133 camMetadata.update(ANDROID_CONTROL_AF_MODE, focusMode, 1); 1134 1135 /*af regions*/ 1136 cam_area_t *hAfRegions = 1137 (cam_area_t *)POINTER_OF(CAM_INTF_META_AF_ROI, metadata); 1138 int32_t afRegions[5]; 1139 convertRegions(hAfRegions->rect, afRegions, hAfRegions->weight); 1140 camMetadata.update(ANDROID_CONTROL_AF_REGIONS, afRegions, 5); 1141 1142 uint8_t *afState = (uint8_t *)POINTER_OF(CAM_INTF_META_AF_STATE, metadata); 1143 camMetadata.update(ANDROID_CONTROL_AF_STATE, afState, 1); 1144 1145 int32_t *afTriggerId = 1146 (int32_t *)POINTER_OF(CAM_INTF_META_AF_TRIGGER_ID, metadata); 1147 camMetadata.update(ANDROID_CONTROL_AF_TRIGGER_ID, afTriggerId, 1); 1148 1149 uint8_t *whiteBalance = 1150 (uint8_t *)POINTER_OF(CAM_INTF_PARM_WHITE_BALANCE, metadata); 1151 camMetadata.update(ANDROID_CONTROL_AWB_MODE, whiteBalance, 1); 1152 1153 /*awb regions*/ 1154 cam_area_t *hAwbRegions = 1155 (cam_area_t *)POINTER_OF(CAM_INTF_META_AWB_REGIONS, metadata); 1156 int32_t awbRegions[5]; 1157 convertRegions(hAwbRegions->rect, awbRegions, hAwbRegions->weight); 1158 camMetadata.update(ANDROID_CONTROL_AWB_REGIONS, awbRegions, 5); 1159 1160 uint8_t *whiteBalanceState = 1161 (uint8_t *)POINTER_OF(CAM_INTF_META_AWB_STATE, metadata); 1162 camMetadata.update(ANDROID_CONTROL_AWB_STATE, whiteBalanceState, 1); 1163 1164 uint8_t *mode = (uint8_t *)POINTER_OF(CAM_INTF_META_MODE, metadata); 1165 camMetadata.update(ANDROID_CONTROL_MODE, mode, 1); 1166 1167 uint8_t *edgeMode = (uint8_t *)POINTER_OF(CAM_INTF_META_EDGE, metadata); 1168 camMetadata.update(ANDROID_EDGE_MODE, edgeMode, 1); 1169 1170 uint8_t *flashPower = 1171 (uint8_t *)POINTER_OF(CAM_INTF_META_FLASH_POWER, metadata); 1172 camMetadata.update(ANDROID_FLASH_FIRING_POWER, flashPower, 1); 1173 1174 int64_t *flashFiringTime = 1175 (int64_t *)POINTER_OF(CAM_INTF_META_FLASH_FIRING_TIME, metadata); 1176 camMetadata.update(ANDROID_FLASH_FIRING_TIME, flashFiringTime, 1); 1177 1178 /*int32_t *ledMode = 1179 (int32_t *)POINTER_OF(CAM_INTF_PARM_LED_MODE, metadata); 1180 camMetadata.update(ANDROID_FLASH_FIRING_TIME, ledMode, 1);*/ 1181 1182 uint8_t *flashState = 1183 (uint8_t *)POINTER_OF(CAM_INTF_META_FLASH_STATE, metadata); 1184 camMetadata.update(ANDROID_FLASH_STATE, flashState, 1); 1185 1186 uint8_t *hotPixelMode = 1187 (uint8_t *)POINTER_OF(CAM_INTF_META_HOTPIXEL_MODE, metadata); 1188 camMetadata.update(ANDROID_HOT_PIXEL_MODE, hotPixelMode, 1); 1189 1190 float *lensAperture = 1191 (float *)POINTER_OF(CAM_INTF_META_LENS_APERTURE, metadata); 1192 camMetadata.update(ANDROID_LENS_APERTURE , lensAperture, 1); 1193 1194 float *filterDensity = 1195 (float *)POINTER_OF(CAM_INTF_META_LENS_FILTERDENSITY, metadata); 1196 camMetadata.update(ANDROID_LENS_FILTER_DENSITY , filterDensity, 1); 1197 1198 float *focalLength = 1199 (float *)POINTER_OF(CAM_INTF_META_LENS_FOCAL_LENGTH, metadata); 1200 camMetadata.update(ANDROID_LENS_FOCAL_LENGTH, focalLength, 1); 1201 1202 float *focusDistance = 1203 (float *)POINTER_OF(CAM_INTF_META_LENS_FOCUS_DISTANCE, metadata); 1204 camMetadata.update(ANDROID_LENS_FOCUS_DISTANCE , focusDistance, 1); 1205 1206 float *focusRange = 1207 (float *)POINTER_OF(CAM_INTF_META_LENS_FOCUS_RANGE, metadata); 1208 camMetadata.update(ANDROID_LENS_FOCUS_RANGE , focusRange, 1); 1209 1210 uint8_t *opticalStab = 1211 (uint8_t *)POINTER_OF(CAM_INTF_META_LENS_OPT_STAB_MODE, metadata); 1212 camMetadata.update(ANDROID_LENS_OPTICAL_STABILIZATION_MODE ,opticalStab, 1); 1213 1214 /*int32_t *focusState = 1215 (int32_t *)POINTER_OF(CAM_INTF_META_LENS_FOCUS_STATE, metadata); 1216 camMetadata.update(ANDROID_LENS_STATE , focusState, 1); //check */ 1217 1218 uint8_t *noiseRedMode = 1219 (uint8_t *)POINTER_OF(CAM_INTF_META_NOISE_REDUCTION_MODE, metadata); 1220 camMetadata.update(ANDROID_NOISE_REDUCTION_MODE , noiseRedMode, 1); 1221 1222 /*CAM_INTF_META_SCALER_CROP_REGION - check size*/ 1223 1224 cam_crop_region_t *hScalerCropRegion =(cam_crop_region_t *) 1225 POINTER_OF(CAM_INTF_META_SCALER_CROP_REGION, metadata); 1226 int32_t scalerCropRegion[3]; 1227 scalerCropRegion[0] = hScalerCropRegion->left; 1228 scalerCropRegion[1] = hScalerCropRegion->top; 1229 scalerCropRegion[2] = hScalerCropRegion->width; 1230 camMetadata.update(ANDROID_SCALER_CROP_REGION, scalerCropRegion, 3); 1231 1232 int64_t *sensorExpTime = 1233 (int64_t *)POINTER_OF(CAM_INTF_META_SENSOR_EXPOSURE_TIME, metadata); 1234 camMetadata.update(ANDROID_SENSOR_EXPOSURE_TIME , sensorExpTime, 1); 1235 1236 int64_t *sensorFameDuration = 1237 (int64_t *)POINTER_OF(CAM_INTF_META_SENSOR_FRAME_DURATION, metadata); 1238 camMetadata.update(ANDROID_SENSOR_FRAME_DURATION, sensorFameDuration, 1); 1239 1240 int32_t *sensorSensitivity = 1241 (int32_t *)POINTER_OF(CAM_INTF_META_SENSOR_SENSITIVITY, metadata); 1242 camMetadata.update(ANDROID_SENSOR_SENSITIVITY, sensorSensitivity, 1); 1243 1244 uint8_t *shadingMode = 1245 (uint8_t *)POINTER_OF(CAM_INTF_META_SHADING_MODE, metadata); 1246 camMetadata.update(ANDROID_SHADING_MODE, shadingMode, 1); 1247 1248 uint8_t *faceDetectMode = 1249 (uint8_t *)POINTER_OF(CAM_INTF_META_STATS_FACEDETECT_MODE, metadata); 1250 camMetadata.update(ANDROID_STATISTICS_FACE_DETECT_MODE, faceDetectMode, 1); 1251 1252 uint8_t *histogramMode = 1253 (uint8_t *)POINTER_OF(CAM_INTF_META_STATS_HISTOGRAM_MODE, metadata); 1254 camMetadata.update(ANDROID_STATISTICS_HISTOGRAM_MODE, histogramMode, 1); 1255 1256 uint8_t *sharpnessMapMode = 1257 (uint8_t *)POINTER_OF(CAM_INTF_META_STATS_SHARPNESS_MAP_MODE, metadata); 1258 camMetadata.update(ANDROID_STATISTICS_SHARPNESS_MAP_MODE, 1259 sharpnessMapMode, 1); 1260 1261 /*CAM_INTF_META_STATS_SHARPNESS_MAP - check size*/ 1262 cam_sharpness_map_t *sharpnessMap = (cam_sharpness_map_t *) 1263 POINTER_OF(CAM_INTF_META_STATS_SHARPNESS_MAP, metadata); 1264 camMetadata.update(ANDROID_STATISTICS_SHARPNESS_MAP, 1265 (int32_t*)sharpnessMap->sharpness, 1266 CAM_MAX_MAP_WIDTH*CAM_MAX_MAP_HEIGHT); 1267 1268 resultMetadata = camMetadata.release(); 1269 return resultMetadata; 1270} 1271 1272/*=========================================================================== 1273 * FUNCTION : convertRegions 1274 * 1275 * DESCRIPTION: helper method to convert from cam_rect_t into int32_t array 1276 * 1277 * PARAMETERS : 1278 * @rect : cam_rect_t struct to convert 1279 * @region : int32_t destination array 1280 * @weight : if we are converting from cam_area_t, weight is valid 1281 * else weight = -1 1282 * 1283 *==========================================================================*/ 1284void QCamera3HardwareInterface::convertRegions(cam_rect_t rect, int32_t* region, int weight){ 1285 region[0] = rect.left; 1286 region[1] = rect.top; 1287 region[2] = rect.width; 1288 region[3] = rect.height; 1289 if (weight > -1) { 1290 region[4] = weight; 1291 } 1292} 1293/*=========================================================================== 1294 * FUNCTION : convertLandmarks 1295 * 1296 * DESCRIPTION: helper method to extract the landmarks from face detection info 1297 * 1298 * PARAMETERS : 1299 * @face : cam_rect_t struct to convert 1300 * @landmarks : int32_t destination array 1301 * 1302 * 1303 *==========================================================================*/ 1304void QCamera3HardwareInterface::convertLandmarks(cam_face_detection_info_t face, int32_t* landmarks) 1305{ 1306 landmarks[0] = face.left_eye_center.x; 1307 landmarks[1] = face.left_eye_center.y; 1308 landmarks[2] = face.right_eye_center.y; 1309 landmarks[3] = face.right_eye_center.y; 1310 landmarks[4] = face.mouth_center.x; 1311 landmarks[5] = face.mouth_center.y; 1312} 1313 1314#define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX ) 1315/*=========================================================================== 1316 * FUNCTION : initCapabilities 1317 * 1318 * DESCRIPTION: initialize camera capabilities in static data struct 1319 * 1320 * PARAMETERS : 1321 * @cameraId : camera Id 1322 * 1323 * RETURN : int32_t type of status 1324 * NO_ERROR -- success 1325 * none-zero failure code 1326 *==========================================================================*/ 1327int QCamera3HardwareInterface::initCapabilities(int cameraId) 1328{ 1329 int rc = 0; 1330 mm_camera_vtbl_t *cameraHandle = NULL; 1331 QCamera3HeapMemory *capabilityHeap = NULL; 1332 1333 cameraHandle = camera_open(cameraId); 1334 if (!cameraHandle) { 1335 ALOGE("%s: camera_open failed", __func__); 1336 rc = -1; 1337 goto open_failed; 1338 } 1339 1340 capabilityHeap = new QCamera3HeapMemory(); 1341 if (capabilityHeap == NULL) { 1342 ALOGE("%s: creation of capabilityHeap failed", __func__); 1343 goto heap_creation_failed; 1344 } 1345 /* Allocate memory for capability buffer */ 1346 rc = capabilityHeap->allocate(1, sizeof(cam_capability_t), false); 1347 if(rc != OK) { 1348 ALOGE("%s: No memory for cappability", __func__); 1349 goto allocate_failed; 1350 } 1351 1352 /* Map memory for capability buffer */ 1353 memset(DATA_PTR(capabilityHeap,0), 0, sizeof(cam_capability_t)); 1354 rc = cameraHandle->ops->map_buf(cameraHandle->camera_handle, 1355 CAM_MAPPING_BUF_TYPE_CAPABILITY, 1356 capabilityHeap->getFd(0), 1357 sizeof(cam_capability_t)); 1358 if(rc < 0) { 1359 ALOGE("%s: failed to map capability buffer", __func__); 1360 goto map_failed; 1361 } 1362 1363 /* Query Capability */ 1364 rc = cameraHandle->ops->query_capability(cameraHandle->camera_handle); 1365 if(rc < 0) { 1366 ALOGE("%s: failed to query capability",__func__); 1367 goto query_failed; 1368 } 1369 gCamCapability[cameraId] = (cam_capability_t *)malloc(sizeof(cam_capability_t)); 1370 if (!gCamCapability[cameraId]) { 1371 ALOGE("%s: out of memory", __func__); 1372 goto query_failed; 1373 } 1374 memcpy(gCamCapability[cameraId], DATA_PTR(capabilityHeap,0), 1375 sizeof(cam_capability_t)); 1376 rc = 0; 1377 1378query_failed: 1379 cameraHandle->ops->unmap_buf(cameraHandle->camera_handle, 1380 CAM_MAPPING_BUF_TYPE_CAPABILITY); 1381map_failed: 1382 capabilityHeap->deallocate(); 1383allocate_failed: 1384 delete capabilityHeap; 1385heap_creation_failed: 1386 cameraHandle->ops->close_camera(cameraHandle->camera_handle); 1387 cameraHandle = NULL; 1388open_failed: 1389 return rc; 1390} 1391 1392/*=========================================================================== 1393 * FUNCTION : initParameters 1394 * 1395 * DESCRIPTION: initialize camera parameters 1396 * 1397 * PARAMETERS : 1398 * 1399 * RETURN : int32_t type of status 1400 * NO_ERROR -- success 1401 * none-zero failure code 1402 *==========================================================================*/ 1403int QCamera3HardwareInterface::initParameters() 1404{ 1405 int rc = 0; 1406 1407 //Allocate Set Param Buffer 1408 mParamHeap = new QCamera3HeapMemory(); 1409 rc = mParamHeap->allocate(1, sizeof(parm_buffer_t), false); 1410 if(rc != OK) { 1411 rc = NO_MEMORY; 1412 ALOGE("Failed to allocate SETPARM Heap memory"); 1413 delete mParamHeap; 1414 mParamHeap = NULL; 1415 return rc; 1416 } 1417 1418 //Map memory for parameters buffer 1419 rc = mCameraHandle->ops->map_buf(mCameraHandle->camera_handle, 1420 CAM_MAPPING_BUF_TYPE_PARM_BUF, 1421 mParamHeap->getFd(0), 1422 sizeof(parm_buffer_t)); 1423 if(rc < 0) { 1424 ALOGE("%s:failed to map SETPARM buffer",__func__); 1425 rc = FAILED_TRANSACTION; 1426 mParamHeap->deallocate(); 1427 delete mParamHeap; 1428 mParamHeap = NULL; 1429 return rc; 1430 } 1431 1432 mParameters = (parm_buffer_t*) DATA_PTR(mParamHeap,0); 1433 return rc; 1434} 1435 1436/*=========================================================================== 1437 * FUNCTION : deinitParameters 1438 * 1439 * DESCRIPTION: de-initialize camera parameters 1440 * 1441 * PARAMETERS : 1442 * 1443 * RETURN : NONE 1444 *==========================================================================*/ 1445void QCamera3HardwareInterface::deinitParameters() 1446{ 1447 mCameraHandle->ops->unmap_buf(mCameraHandle->camera_handle, 1448 CAM_MAPPING_BUF_TYPE_PARM_BUF); 1449 1450 mParamHeap->deallocate(); 1451 delete mParamHeap; 1452 mParamHeap = NULL; 1453 1454 mParameters = NULL; 1455} 1456 1457/*=========================================================================== 1458 * FUNCTION : initStaticMetadata 1459 * 1460 * DESCRIPTION: initialize the static metadata 1461 * 1462 * PARAMETERS : 1463 * @cameraId : camera Id 1464 * 1465 * RETURN : int32_t type of status 1466 * 0 -- success 1467 * non-zero failure code 1468 *==========================================================================*/ 1469int QCamera3HardwareInterface::initStaticMetadata(int cameraId) 1470{ 1471 int rc = 0; 1472 CameraMetadata staticInfo; 1473 int facingBack = gCamCapability[cameraId]->position == CAM_POSITION_BACK; 1474 /*HAL 3 only*/ 1475 #ifdef HAL_3_CAPABILITIES 1476 staticInfo.update(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, 1477 &gCamCapability[cameraId]->min_focus_distance, 1); 1478 1479 staticInfo.update(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, 1480 &gCamCapability[cameraId]->hyper_focal_distance, 1); 1481 1482 /*should be using focal lengths but sensor doesn't provide that info now*/ 1483 staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, 1484 &gCamCapability[cameraId]->focal_length, 1485 1); 1486 1487 staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_APERTURES, 1488 gCamCapability[cameraId]->apertures, 1489 gCamCapability[cameraId]->apertures_count); 1490 1491 staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES, 1492 gCamCapability[cameraId]->filter_densities, 1493 gCamCapability[cameraId]->filter_densities_count); 1494 1495 1496 staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, 1497 (uint8_t*)gCamCapability[cameraId]->optical_stab_modes, 1498 gCamCapability[cameraId]->optical_stab_modes_count); 1499 1500 staticInfo.update(ANDROID_LENS_POSITION, 1501 gCamCapability[cameraId]->lens_position, 1502 sizeof(gCamCapability[cameraId]->lens_position)/ sizeof(float)); 1503 1504 static const int32_t lens_shading_map_size[] = {gCamCapability[cameraId]->lens_shading_map_size.width, 1505 gCamCapability[cameraId]->lens_shading_map_size.height}; 1506 staticInfo.update(ANDROID_LENS_INFO_SHADING_MAP_SIZE, 1507 lens_shading_map_size, 1508 sizeof(lens_shading_map_size)/sizeof(int32_t)); 1509 1510 staticInfo.update(ANDROID_LENS_INFO_SHADING_MAP, gCamCapability[cameraId]->lens_shading_map, 1511 sizeof(gCamCapability[cameraId]->lens_shading_map)/ sizeof(float)); 1512 1513 static const int32_t geo_correction_map_size[] = {gCamCapability[cameraId]->geo_correction_map_size.width, 1514 gCamCapability[cameraId]->geo_correction_map_size.height}; 1515 staticInfo.update(ANDROID_LENS_INFO_GEOMETRIC_CORRECTION_MAP_SIZE, 1516 geo_correction_map_size, 1517 sizeof(geo_correction_map_size)/sizeof(int32_t)); 1518 1519 staticInfo.update(ANDROID_LENS_INFO_GEOMETRIC_CORRECTION_MAP, 1520 gCamCapability[cameraId]->geo_correction_map, 1521 sizeof(gCamCapability[cameraId]->geo_correction_map)/sizeof(float)); 1522 1523 staticInfo.update(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, 1524 gCamCapability[cameraId]->sensor_physical_size, 2); 1525 1526 staticInfo.update(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, 1527 gCamCapability[cameraId]->exposure_time_range, 2); 1528 1529 staticInfo.update(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION, 1530 &gCamCapability[cameraId]->max_frame_duration, 1); 1531 1532 1533 staticInfo.update(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, 1534 (uint8_t*)&gCamCapability[cameraId]->color_arrangement, 1); 1535 1536 static const int32_t pixel_array_size[] = {gCamCapability[cameraId]->pixel_array_size.width, 1537 gCamCapability[cameraId]->pixel_array_size.height}; 1538 staticInfo.update(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, 1539 pixel_array_size, 2); 1540 1541 static const int32_t active_array_size[] = {gCamCapability[cameraId]->active_array_size.width, 1542 gCamCapability[cameraId]->active_array_size.height}; 1543 staticInfo.update(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, 1544 active_array_size, 2); 1545 1546 staticInfo.update(ANDROID_SENSOR_INFO_WHITE_LEVEL, 1547 &gCamCapability[cameraId]->white_level, 1); 1548 1549 staticInfo.update(ANDROID_SENSOR_BLACK_LEVEL_PATTERN, 1550 gCamCapability[cameraId]->black_level_pattern, 4); 1551 1552 staticInfo.update(ANDROID_FLASH_INFO_CHARGE_DURATION, 1553 &gCamCapability[cameraId]->flash_charge_duration, 1); 1554 1555 staticInfo.update(ANDROID_TONEMAP_MAX_CURVE_POINTS, 1556 &gCamCapability[cameraId]->max_tone_map_curve_points, 1); 1557 1558 /*staticInfo.update(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, 1559 (int*)&gCamCapability[cameraId]->max_face_detection_count, 1);*/ 1560 /*hardcode 0 for now*/ 1561 int32_t max_face_count = 0; 1562 staticInfo.update(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, 1563 &max_face_count, 1); 1564 1565 staticInfo.update(ANDROID_STATISTICS_INFO_HISTOGRAM_BUCKET_COUNT, 1566 &gCamCapability[cameraId]->histogram_size, 1); 1567 1568 staticInfo.update(ANDROID_STATISTICS_INFO_MAX_HISTOGRAM_COUNT, 1569 &gCamCapability[cameraId]->max_histogram_count, 1); 1570 1571 static const int32_t sharpness_map_size[] = {gCamCapability[cameraId]->sharpness_map_size.width, 1572 gCamCapability[cameraId]->sharpness_map_size.height}; 1573 1574 staticInfo.update(ANDROID_STATISTICS_INFO_SHARPNESS_MAP_SIZE, 1575 sharpness_map_size, sizeof(sharpness_map_size)/sizeof(int32_t)); 1576 1577 staticInfo.update(ANDROID_STATISTICS_INFO_MAX_SHARPNESS_MAP_VALUE, 1578 &gCamCapability[cameraId]->max_sharpness_map_value, 1); 1579 1580 1581 staticInfo.update(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS, 1582 &gCamCapability[cameraId]->raw_min_duration, 1583 1); 1584 1585 static int32_t scalar_formats[CAM_FORMAT_MAX]; 1586 for (int i = 0; i < gCamCapability[cameraId]->supported_scalar_format_cnt; i++) { 1587 scalar_formats[i] = getScalarFormat(gCamCapability[cameraId]->supported_scalar_fmts[i]); 1588 } 1589 staticInfo.update(ANDROID_SCALER_AVAILABLE_FORMATS, 1590 scalar_formats, 1591 gCamCapability[cameraId]->supported_scalar_format_cnt); 1592 1593 static int32_t available_processed_sizes[CAM_FORMAT_MAX]; 1594 makeTable(gCamCapability[cameraId]->supported_sizes_tbl, 1595 gCamCapability[cameraId]->supported_sizes_tbl_cnt, 1596 available_processed_sizes); 1597 staticInfo.update(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES, 1598 available_processed_sizes, 1599 (gCamCapability[cameraId]->supported_sizes_tbl_cnt) * 2); 1600 1601 static int32_t available_fps_ranges[MAX_SIZES_CNT]; 1602 makeFPSTable(gCamCapability[cameraId]->fps_ranges_tbl, 1603 gCamCapability[cameraId]->fps_ranges_tbl_cnt, 1604 available_fps_ranges); 1605 staticInfo.update(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, 1606 available_fps_ranges, (gCamCapability[cameraId]->fps_ranges_tbl_cnt*2) ); 1607 1608 static const camera_metadata_rational exposureCompensationStep = { 1609 gCamCapability[cameraId]->exp_compensation_step.numerator, 1610 gCamCapability[cameraId]->exp_compensation_step.denominator}; 1611 staticInfo.update(ANDROID_CONTROL_AE_COMPENSATION_STEP, 1612 &exposureCompensationStep, 1); 1613 1614 /*TO DO*/ 1615 static const uint8_t availableVstabModes[] = {ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF}; 1616 staticInfo.update(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, 1617 availableVstabModes, sizeof(availableVstabModes)); 1618 1619 #else 1620 const float minFocusDistance = 0; 1621 staticInfo.update(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, 1622 &minFocusDistance, 1); 1623 1624 const float hyperFocusDistance = 0; 1625 staticInfo.update(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, 1626 &hyperFocusDistance, 1); 1627 1628 static const float focalLength = 3.30f; 1629 staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, 1630 &focalLength, 1631 1); 1632 1633 static const float aperture = 2.8f; 1634 staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_APERTURES, 1635 &aperture, 1636 1); 1637 1638 static const float filterDensity = 0; 1639 staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES, 1640 &filterDensity, 1); 1641 1642 static const uint8_t availableOpticalStabilization = 1643 ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF; 1644 staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, 1645 &availableOpticalStabilization, 1); 1646 1647 float lensPosition[3]; 1648 if (facingBack) { 1649 // Back-facing camera is center-top on device 1650 lensPosition[0] = 0; 1651 lensPosition[1] = 20; 1652 lensPosition[2] = -5; 1653 } else { 1654 // Front-facing camera is center-right on device 1655 lensPosition[0] = 20; 1656 lensPosition[1] = 20; 1657 lensPosition[2] = 0; 1658 } 1659 staticInfo.update(ANDROID_LENS_POSITION, 1660 lensPosition, 1661 sizeof(lensPosition)/ sizeof(float)); 1662 1663 static const int32_t lensShadingMapSize[] = {1, 1}; 1664 staticInfo.update(ANDROID_LENS_INFO_SHADING_MAP_SIZE, 1665 lensShadingMapSize, 1666 sizeof(lensShadingMapSize)/sizeof(int32_t)); 1667 1668 static const float lensShadingMap[3 * 1 * 1 ] = 1669 { 1.f, 1.f, 1.f }; 1670 staticInfo.update(ANDROID_LENS_INFO_SHADING_MAP, 1671 lensShadingMap, 1672 sizeof(lensShadingMap)/ sizeof(float)); 1673 1674 static const int32_t geometricCorrectionMapSize[] = {2, 2}; 1675 staticInfo.update(ANDROID_LENS_INFO_GEOMETRIC_CORRECTION_MAP_SIZE, 1676 geometricCorrectionMapSize, 1677 sizeof(geometricCorrectionMapSize)/sizeof(int32_t)); 1678 1679 static const float geometricCorrectionMap[2 * 3 * 2 * 2] = { 1680 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 1681 1.f, 0.f, 1.f, 0.f, 1.f, 0.f, 1682 0.f, 1.f, 0.f, 1.f, 0.f, 1.f, 1683 1.f, 1.f, 1.f, 1.f, 1.f, 1.f}; 1684 staticInfo.update(ANDROID_LENS_INFO_GEOMETRIC_CORRECTION_MAP, 1685 geometricCorrectionMap, 1686 sizeof(geometricCorrectionMap)/ sizeof(float)); 1687 1688 static const float sensorPhysicalSize[2] = {3.20f, 2.40f}; 1689 staticInfo.update(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, 1690 sensorPhysicalSize, 2); 1691 1692 const int64_t exposureTimeRange[2] = {1000L, 30000000000L} ; // 1 us - 30 sec 1693 staticInfo.update(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, 1694 exposureTimeRange, 2); 1695 1696 const int64_t frameDurationRange[2] = {33331760L, 30000000000L}; 1697 staticInfo.update(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION, 1698 frameDurationRange, 1); 1699 1700 const uint8_t colorFilterArrangement = 1701 ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_RGGB; 1702 staticInfo.update(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, 1703 &colorFilterArrangement, 1); 1704 1705 const int resolution[2] = {640, 480}; 1706 staticInfo.update(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, 1707 resolution, 2); 1708 1709 staticInfo.update(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, 1710 resolution, 2); 1711 1712 const uint32_t whiteLevel = 4000; 1713 staticInfo.update(ANDROID_SENSOR_INFO_WHITE_LEVEL, 1714 (int32_t*)&whiteLevel, 1); 1715 1716 static const int32_t blackLevelPattern[4] = { 1717 1000, 1000, 1718 1000, 1000 }; 1719 staticInfo.update(ANDROID_SENSOR_BLACK_LEVEL_PATTERN, 1720 blackLevelPattern, 4); 1721 1722 static const int64_t flashChargeDuration = 0; 1723 staticInfo.update(ANDROID_FLASH_INFO_CHARGE_DURATION, 1724 &flashChargeDuration, 1); 1725 1726 static const int32_t tonemapCurvePoints = 128; 1727 staticInfo.update(ANDROID_TONEMAP_MAX_CURVE_POINTS, 1728 &tonemapCurvePoints, 1); 1729 1730 static const int32_t maxFaceCount = 0; 1731 staticInfo.update(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, 1732 &maxFaceCount, 1); 1733 1734 static const int32_t histogramSize = 64; 1735 staticInfo.update(ANDROID_STATISTICS_INFO_HISTOGRAM_BUCKET_COUNT, 1736 &histogramSize, 1); 1737 1738 static const int32_t maxHistogramCount = 1000; 1739 staticInfo.update(ANDROID_STATISTICS_INFO_MAX_HISTOGRAM_COUNT, 1740 &maxHistogramCount, 1); 1741 1742 static const int32_t sharpnessMapSize[2] = {64, 64}; 1743 staticInfo.update(ANDROID_STATISTICS_INFO_SHARPNESS_MAP_SIZE, 1744 sharpnessMapSize, sizeof(sharpnessMapSize)/sizeof(int32_t)); 1745 1746 static const int32_t maxSharpnessMapValue = 1000; 1747 staticInfo.update(ANDROID_STATISTICS_INFO_MAX_SHARPNESS_MAP_VALUE, 1748 &maxSharpnessMapValue, 1); 1749 1750 static const uint8_t availableVstabModes[] = {ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF}; 1751 staticInfo.update(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, 1752 availableVstabModes, sizeof(availableVstabModes)); 1753 1754 const uint64_t availableRawMinDurations[1] = {33331760L}; 1755 staticInfo.update(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS, 1756 (int64_t*)&availableRawMinDurations, 1757 1); 1758 1759 const uint32_t availableFormats[4] = { 1760 HAL_PIXEL_FORMAT_RAW_SENSOR, 1761 HAL_PIXEL_FORMAT_BLOB, 1762 HAL_PIXEL_FORMAT_RGBA_8888, 1763 HAL_PIXEL_FORMAT_YCrCb_420_SP 1764 }; 1765 staticInfo.update(ANDROID_SCALER_AVAILABLE_FORMATS, 1766 (int32_t*)availableFormats, 1767 4); 1768 1769 const uint32_t availableProcessedSizes[4] = {1280, 720, 640, 480}; 1770 staticInfo.update(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES, 1771 (int32_t*)availableProcessedSizes, 1772 sizeof(availableProcessedSizes)/sizeof(int32_t)); 1773 1774 staticInfo.update(ANDROID_SCALER_AVAILABLE_JPEG_SIZES, 1775 resolution, 1776 sizeof(resolution)/sizeof(int)); 1777 1778 static const uint8_t availableSceneModes[] = { 1779 ANDROID_CONTROL_SCENE_MODE_UNSUPPORTED }; 1780 1781 staticInfo.update(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, 1782 availableSceneModes, sizeof(availableSceneModes)); 1783 1784 static const int32_t availableFpsRanges[] = {15, 30}; 1785 staticInfo.update(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, 1786 availableFpsRanges, sizeof(availableFpsRanges)/sizeof(int32_t)); 1787 1788 static const uint8_t availableEffectsModes[] = { 1789 ANDROID_CONTROL_EFFECT_MODE_OFF }; 1790 staticInfo.update(ANDROID_CONTROL_AVAILABLE_EFFECTS, 1791 availableEffectsModes, sizeof(availableEffectsModes)); 1792 1793 static const uint8_t availableAntibandingModes[] = { 1794 ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF }; 1795 staticInfo.update(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, 1796 availableAntibandingModes, sizeof(availableAntibandingModes)); 1797 1798 static const camera_metadata_rational exposureCompensationStep = { 1799 1, 3 1800 }; 1801 staticInfo.update(ANDROID_CONTROL_AE_COMPENSATION_STEP, 1802 &exposureCompensationStep, 1); 1803 1804 static const int32_t jpegThumbnailSizes[] = { 1805 0, 0, 1806 160, 120, 1807 320, 240 1808 }; 1809 staticInfo.update(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, 1810 jpegThumbnailSizes, sizeof(jpegThumbnailSizes)/sizeof(int32_t)); 1811 1812 static int64_t jpegMinDuration[] = {33331760L, 30000000000L}; 1813 staticInfo.update(ANDROID_SCALER_AVAILABLE_JPEG_MIN_DURATIONS, 1814 jpegMinDuration, 1815 sizeof(jpegMinDuration)/sizeof(uint64_t)); 1816 #endif 1817 /*HAL 1 and HAL 3 common*/ 1818 static const int32_t maxZoom = 10; 1819 staticInfo.update(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, 1820 &maxZoom, 1); 1821 1822 static const int32_t max3aRegions = 0; 1823 staticInfo.update(ANDROID_CONTROL_MAX_REGIONS, 1824 &max3aRegions, 1); 1825 1826 static const uint8_t flashAvailable = 0; 1827 staticInfo.update(ANDROID_FLASH_INFO_AVAILABLE, 1828 &flashAvailable, sizeof(flashAvailable)); 1829 1830 static const uint8_t availableFaceDetectModes[] = { 1831 ANDROID_STATISTICS_FACE_DETECT_MODE_OFF }; 1832 1833 staticInfo.update(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, 1834 availableFaceDetectModes, 1835 sizeof(availableFaceDetectModes)); 1836 1837 static const int32_t raw_size[] = {gCamCapability[cameraId]->raw_dim.width, 1838 gCamCapability[cameraId]->raw_dim.height}; 1839 staticInfo.update(ANDROID_SCALER_AVAILABLE_RAW_SIZES, 1840 raw_size, 1841 sizeof(raw_size)/sizeof(uint32_t)); 1842 1843 static const int32_t exposureCompensationRange[] = {gCamCapability[cameraId]->exposure_compensation_min, 1844 gCamCapability[cameraId]->exposure_compensation_max}; 1845 staticInfo.update(ANDROID_CONTROL_AE_COMPENSATION_RANGE, 1846 exposureCompensationRange, 1847 sizeof(exposureCompensationRange)/sizeof(int32_t)); 1848 1849 uint8_t lensFacing = (facingBack) ? 1850 ANDROID_LENS_FACING_BACK : ANDROID_LENS_FACING_FRONT; 1851 staticInfo.update(ANDROID_LENS_FACING, &lensFacing, 1); 1852 1853 static int32_t available_jpeg_sizes[MAX_SIZES_CNT]; 1854 makeTable(gCamCapability[cameraId]->picture_sizes_tbl, 1855 gCamCapability[cameraId]->picture_sizes_tbl_cnt, 1856 available_jpeg_sizes); 1857 staticInfo.update(ANDROID_SCALER_AVAILABLE_JPEG_SIZES, 1858 available_jpeg_sizes, 1859 (gCamCapability[cameraId]->picture_sizes_tbl_cnt * 2)); 1860 1861 staticInfo.update(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, 1862 available_jpeg_sizes, 1863 (gCamCapability[cameraId]->picture_sizes_tbl_cnt * 2)); 1864 1865 static int32_t max_jpeg_size = 0; 1866 int temp_width, temp_height; 1867 for (int i = 0; i < gCamCapability[cameraId]->picture_sizes_tbl_cnt; i++) { 1868 temp_width = gCamCapability[cameraId]->picture_sizes_tbl[i].width; 1869 temp_height = gCamCapability[cameraId]->picture_sizes_tbl[i].height; 1870 if (temp_width * temp_height > max_jpeg_size ) { 1871 max_jpeg_size = temp_width * temp_height; 1872 } 1873 } 1874 max_jpeg_size = max_jpeg_size * 3/2 + sizeof(camera3_jpeg_blob_t); 1875 staticInfo.update(ANDROID_JPEG_MAX_SIZE, 1876 &max_jpeg_size, 1); 1877 1878 static uint8_t avail_effects[CAM_EFFECT_MODE_MAX]; 1879 int32_t size = 0; 1880 for (int i = 0; i < gCamCapability[cameraId]->supported_effects_cnt; i++) { 1881 int val = lookupFwkName(EFFECT_MODES_MAP, 1882 sizeof(EFFECT_MODES_MAP)/sizeof(EFFECT_MODES_MAP[0]), 1883 gCamCapability[cameraId]->supported_effects[i]); 1884 if (val != NAME_NOT_FOUND) { 1885 avail_effects[size] = (uint8_t)val; 1886 size++; 1887 } 1888 } 1889 staticInfo.update(ANDROID_CONTROL_AVAILABLE_EFFECTS, 1890 avail_effects, 1891 size); 1892 1893 static uint8_t avail_scene_modes[CAM_SCENE_MODE_MAX]; 1894 size = 0; 1895 for (int i = 0; i < gCamCapability[cameraId]->supported_scene_modes_cnt; i++) { 1896 int val = lookupFwkName(SCENE_MODES_MAP, 1897 sizeof(SCENE_MODES_MAP)/sizeof(SCENE_MODES_MAP[0]), 1898 gCamCapability[cameraId]->supported_scene_modes[i]); 1899 if (val != NAME_NOT_FOUND) { 1900 avail_scene_modes[size] = (uint8_t)val; 1901 size++; 1902 } 1903 } 1904 staticInfo.update(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, 1905 avail_scene_modes, 1906 size); 1907 1908 static uint8_t avail_antibanding_modes[CAM_ANTIBANDING_MODE_MAX]; 1909 size = 0; 1910 for (int i = 0; i < gCamCapability[cameraId]->supported_antibandings_cnt; i++) { 1911 int val = lookupFwkName(ANTIBANDING_MODES_MAP, 1912 sizeof(ANTIBANDING_MODES_MAP)/sizeof(ANTIBANDING_MODES_MAP[0]), 1913 gCamCapability[cameraId]->supported_antibandings[i]); 1914 if (val != NAME_NOT_FOUND) { 1915 avail_antibanding_modes[size] = (uint8_t)val; 1916 size++; 1917 } 1918 1919 } 1920 staticInfo.update(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, 1921 avail_antibanding_modes, 1922 size); 1923 1924 ALOGE("%s: %d", __func__, __LINE__); 1925 static uint8_t avail_af_modes[CAM_FOCUS_MODE_MAX]; 1926 size = 0; 1927 for (int i = 0; i < gCamCapability[cameraId]->supported_focus_modes_cnt; i++) { 1928 int val = lookupFwkName(FOCUS_MODES_MAP, 1929 sizeof(FOCUS_MODES_MAP)/sizeof(FOCUS_MODES_MAP[0]), 1930 gCamCapability[cameraId]->supported_focus_modes[i]); 1931 if (val != NAME_NOT_FOUND) { 1932 avail_af_modes[size] = (uint8_t)val; 1933 size++; 1934 } 1935 } 1936 staticInfo.update(ANDROID_CONTROL_AF_AVAILABLE_MODES, 1937 avail_af_modes, 1938 size); 1939 1940 static uint8_t avail_awb_modes[CAM_WB_MODE_MAX]; 1941 size = 0; 1942 for (int i = 0; i < gCamCapability[cameraId]->supported_white_balances_cnt; i++) { 1943 int8_t val = lookupFwkName(WHITE_BALANCE_MODES_MAP, 1944 sizeof(WHITE_BALANCE_MODES_MAP)/sizeof(WHITE_BALANCE_MODES_MAP[0]), 1945 gCamCapability[cameraId]->supported_white_balances[i]); 1946 if (val != NAME_NOT_FOUND) { 1947 avail_awb_modes[size] = (uint8_t)val; 1948 size++; 1949 } 1950 } 1951 staticInfo.update(ANDROID_CONTROL_AWB_AVAILABLE_MODES, 1952 avail_awb_modes, 1953 size); 1954 1955 static uint8_t avail_flash_modes[CAM_FLASH_MODE_MAX]; 1956 size = 0; 1957 for (int i = 0; i < gCamCapability[cameraId]->supported_flash_modes_cnt; i++) { 1958 int val = lookupFwkName(FLASH_MODES_MAP, 1959 sizeof(FLASH_MODES_MAP)/sizeof(FLASH_MODES_MAP[0]), 1960 gCamCapability[cameraId]->supported_flash_modes[i]); 1961 if (val != NAME_NOT_FOUND) { 1962 avail_flash_modes[size] = (uint8_t)val; 1963 size++; 1964 } 1965 } 1966 staticInfo.update(ANDROID_FLASH_MODE, 1967 avail_flash_modes, 1968 size); 1969 1970 /*so far fwk seems to support only 2 aec modes on and off*/ 1971 static const uint8_t avail_ae_modes[] = { 1972 ANDROID_CONTROL_AE_MODE_OFF, 1973 ANDROID_CONTROL_AE_MODE_ON 1974 }; 1975 staticInfo.update(ANDROID_CONTROL_AE_AVAILABLE_MODES, 1976 avail_ae_modes, 1977 sizeof(avail_ae_modes)); 1978 1979 gStaticMetadata = staticInfo.release(); 1980 return rc; 1981} 1982 1983/*=========================================================================== 1984 * FUNCTION : makeTable 1985 * 1986 * DESCRIPTION: make a table of sizes 1987 * 1988 * PARAMETERS : 1989 * 1990 * 1991 * 1992 * RETURN : int32_t type of status 1993 * NO_ERROR -- success 1994 * none-zero failure code 1995 *==========================================================================*/ 1996void QCamera3HardwareInterface::makeTable(cam_dimension_t* dimTable, uint8_t size, 1997 int32_t* sizeTable) 1998{ 1999 int j = 0; 2000 for (int i = 0; i < size; i++) { 2001 sizeTable[j] = dimTable[i].width; 2002 sizeTable[j+1] = dimTable[i].height; 2003 j+=2; 2004 } 2005} 2006 2007/*=========================================================================== 2008 * FUNCTION : makeFPSTable 2009 * 2010 * DESCRIPTION: make a table of fps ranges 2011 * 2012 * PARAMETERS : 2013 * 2014 * 2015 * 2016 * RETURN : int32_t type of status 2017 * NO_ERROR -- success 2018 * none-zero failure code 2019 *==========================================================================*/ 2020void QCamera3HardwareInterface::makeFPSTable(cam_fps_range_t* fpsTable, uint8_t size, 2021 int32_t* fpsRangesTable) 2022{ 2023 int j = 0; 2024 for (int i = 0; i < size; i++) { 2025 fpsRangesTable[j] = (int32_t)fpsTable[i].min_fps; 2026 fpsRangesTable[j+1] = (int32_t)fpsTable[i].max_fps; 2027 j+=2; 2028 } 2029} 2030/*=========================================================================== 2031 * FUNCTION : getPreviewHalPixelFormat 2032 * 2033 * DESCRIPTION: convert the format to type recognized by framework 2034 * 2035 * PARAMETERS : format : the format from backend 2036 * 2037 ** RETURN : format recognized by framework 2038 * 2039 *==========================================================================*/ 2040int32_t QCamera3HardwareInterface::getScalarFormat(int32_t format) 2041{ 2042 int32_t halPixelFormat; 2043 2044 switch (format) { 2045 case CAM_FORMAT_YUV_420_NV12: 2046 halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP; 2047 break; 2048 case CAM_FORMAT_YUV_420_NV21: 2049 halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; 2050 break; 2051 case CAM_FORMAT_YUV_420_NV21_ADRENO: 2052 halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO; 2053 break; 2054 case CAM_FORMAT_YUV_420_YV12: 2055 halPixelFormat = HAL_PIXEL_FORMAT_YV12; 2056 break; 2057 case CAM_FORMAT_YUV_422_NV16: 2058 case CAM_FORMAT_YUV_422_NV61: 2059 default: 2060 halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; 2061 break; 2062 } 2063 return halPixelFormat; 2064} 2065 2066/*=========================================================================== 2067 * FUNCTION : AddSetParmEntryToBatch 2068 * 2069 * DESCRIPTION: add set parameter entry into batch 2070 * 2071 * PARAMETERS : 2072 * @p_table : ptr to parameter buffer 2073 * @paramType : parameter type 2074 * @paramLength : length of parameter value 2075 * @paramValue : ptr to parameter value 2076 * 2077 * RETURN : int32_t type of status 2078 * NO_ERROR -- success 2079 * none-zero failure code 2080 *==========================================================================*/ 2081int32_t QCamera3HardwareInterface::AddSetParmEntryToBatch(parm_buffer_t *p_table, 2082 cam_intf_parm_type_t paramType, 2083 uint32_t paramLength, 2084 void *paramValue) 2085{ 2086 int position = paramType; 2087 int current, next; 2088 2089 /************************************************************************* 2090 * Code to take care of linking next flags * 2091 *************************************************************************/ 2092 current = GET_FIRST_PARAM_ID(p_table); 2093 if (position == current){ 2094 //DO NOTHING 2095 } else if (position < current){ 2096 SET_NEXT_PARAM_ID(position, p_table, current); 2097 SET_FIRST_PARAM_ID(p_table, position); 2098 } else { 2099 /* Search for the position in the linked list where we need to slot in*/ 2100 while (position > GET_NEXT_PARAM_ID(current, p_table)) 2101 current = GET_NEXT_PARAM_ID(current, p_table); 2102 2103 /*If node already exists no need to alter linking*/ 2104 if (position != GET_NEXT_PARAM_ID(current, p_table)) { 2105 next = GET_NEXT_PARAM_ID(current, p_table); 2106 SET_NEXT_PARAM_ID(current, p_table, position); 2107 SET_NEXT_PARAM_ID(position, p_table, next); 2108 } 2109 } 2110 2111 /************************************************************************* 2112 * Copy contents into entry * 2113 *************************************************************************/ 2114 2115 if (paramLength > sizeof(parm_type_t)) { 2116 ALOGE("%s:Size of input larger than max entry size",__func__); 2117 return BAD_VALUE; 2118 } 2119 memcpy(POINTER_OF(paramType,p_table), paramValue, paramLength); 2120 return NO_ERROR; 2121} 2122 2123/*=========================================================================== 2124 * FUNCTION : lookupFwkName 2125 * 2126 * DESCRIPTION: In case the enum is not same in fwk and backend 2127 * make sure the parameter is correctly propogated 2128 * 2129 * PARAMETERS : 2130 * @arr : map between the two enums 2131 * @len : len of the map 2132 * @hal_name : name of the hal_parm to map 2133 * 2134 * RETURN : int type of status 2135 * fwk_name -- success 2136 * none-zero failure code 2137 *==========================================================================*/ 2138int8_t QCamera3HardwareInterface::lookupFwkName(const QCameraMap arr[], 2139 int len, int hal_name) 2140{ 2141 2142 for (int i = 0; i < len; i++) { 2143 if (arr[i].hal_name == hal_name) 2144 return arr[i].fwk_name; 2145 } 2146 ALOGE("%s: Cannot find matching framework type", __func__); 2147 return NAME_NOT_FOUND; 2148} 2149 2150/*=========================================================================== 2151 * FUNCTION : lookupHalName 2152 * 2153 * DESCRIPTION: In case the enum is not same in fwk and backend 2154 * make sure the parameter is correctly propogated 2155 * 2156 * PARAMETERS : 2157 * @arr : map between the two enums 2158 * @len : len of the map 2159 * @fwk_name : name of the hal_parm to map 2160 * 2161 * RETURN : int32_t type of status 2162 * hal_name -- success 2163 * none-zero failure code 2164 *==========================================================================*/ 2165int8_t QCamera3HardwareInterface::lookupHalName(const QCameraMap arr[], 2166 int len, int fwk_name) 2167{ 2168 for (int i = 0; i < len; i++) { 2169 if (arr[i].fwk_name == fwk_name) 2170 return arr[i].hal_name; 2171 } 2172 ALOGE("%s: Cannot find matching hal type", __func__); 2173 return NAME_NOT_FOUND; 2174} 2175 2176/*=========================================================================== 2177 * FUNCTION : getCapabilities 2178 * 2179 * DESCRIPTION: query camera capabilities 2180 * 2181 * PARAMETERS : 2182 * @cameraId : camera Id 2183 * @info : camera info struct to be filled in with camera capabilities 2184 * 2185 * RETURN : int32_t type of status 2186 * NO_ERROR -- success 2187 * none-zero failure code 2188 *==========================================================================*/ 2189int QCamera3HardwareInterface::getCamInfo(int cameraId, 2190 struct camera_info *info) 2191{ 2192 int rc = 0; 2193 2194 if (NULL == gCamCapability[cameraId]) { 2195 rc = initCapabilities(cameraId); 2196 if (rc < 0) { 2197 //pthread_mutex_unlock(&g_camlock); 2198 return rc; 2199 } 2200 } 2201 2202 if (NULL == gStaticMetadata) { 2203 rc = initStaticMetadata(cameraId); 2204 if (rc < 0) { 2205 return rc; 2206 } 2207 } 2208 2209 switch(gCamCapability[cameraId]->position) { 2210 case CAM_POSITION_BACK: 2211 info->facing = CAMERA_FACING_BACK; 2212 break; 2213 2214 case CAM_POSITION_FRONT: 2215 info->facing = CAMERA_FACING_FRONT; 2216 break; 2217 2218 default: 2219 ALOGE("%s:Unknown position type for camera id:%d", __func__, cameraId); 2220 rc = -1; 2221 break; 2222 } 2223 2224 2225 info->orientation = gCamCapability[cameraId]->sensor_mount_angle; 2226 info->device_version = HARDWARE_DEVICE_API_VERSION(3, 0); 2227 info->static_camera_characteristics = gStaticMetadata; 2228 2229 return rc; 2230} 2231 2232/*=========================================================================== 2233 * FUNCTION : translateMetadata 2234 * 2235 * DESCRIPTION: translate the metadata into camera_metadata_t 2236 * 2237 * PARAMETERS : type of the request 2238 * 2239 * 2240 * RETURN : success: camera_metadata_t* 2241 * failure: NULL 2242 * 2243 *==========================================================================*/ 2244camera_metadata_t* QCamera3HardwareInterface::translateCapabilityToMetadata(int type) 2245{ 2246 pthread_mutex_lock(&mMutex); 2247 2248 if (mDefaultMetadata[type] != NULL) { 2249 pthread_mutex_unlock(&mMutex); 2250 return mDefaultMetadata[type]; 2251 } 2252 //first time we are handling this request 2253 //fill up the metadata structure using the wrapper class 2254 CameraMetadata settings; 2255 //translate from cam_capability_t to camera_metadata_tag_t 2256 static const uint8_t requestType = ANDROID_REQUEST_TYPE_CAPTURE; 2257 settings.update(ANDROID_REQUEST_TYPE, &requestType, 1); 2258 2259 /*control*/ 2260 2261 uint8_t controlIntent = 0; 2262 switch (type) { 2263 case CAMERA3_TEMPLATE_PREVIEW: 2264 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; 2265 break; 2266 case CAMERA3_TEMPLATE_STILL_CAPTURE: 2267 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE; 2268 break; 2269 case CAMERA3_TEMPLATE_VIDEO_RECORD: 2270 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; 2271 break; 2272 case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT: 2273 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT; 2274 break; 2275 case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG: 2276 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG; 2277 break; 2278 default: 2279 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_CUSTOM; 2280 break; 2281 } 2282 settings.update(ANDROID_CONTROL_CAPTURE_INTENT, &controlIntent, 1); 2283 2284 settings.update(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, 2285 &gCamCapability[mCameraId]->exposure_compensation_default, 1); 2286 2287 static const uint8_t aeLock = ANDROID_CONTROL_AE_LOCK_OFF; 2288 settings.update(ANDROID_CONTROL_AE_LOCK, &aeLock, 1); 2289 2290 static const uint8_t awbLock = ANDROID_CONTROL_AWB_LOCK_OFF; 2291 settings.update(ANDROID_CONTROL_AWB_LOCK, &awbLock, 1); 2292 2293 static const uint8_t awbMode = ANDROID_CONTROL_AWB_MODE_AUTO; 2294 settings.update(ANDROID_CONTROL_AWB_MODE, &awbMode, 1); 2295 2296 static const uint8_t controlMode = ANDROID_CONTROL_MODE_AUTO; 2297 settings.update(ANDROID_CONTROL_MODE, &controlMode, 1); 2298 2299 static const uint8_t effectMode = ANDROID_CONTROL_EFFECT_MODE_OFF; 2300 settings.update(ANDROID_CONTROL_EFFECT_MODE, &effectMode, 1); 2301 2302 static const uint8_t sceneMode = ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY; //similar to AUTO? 2303 settings.update(ANDROID_CONTROL_SCENE_MODE, &sceneMode, 1); 2304 2305 /*flash*/ 2306 static const uint8_t flashMode = ANDROID_FLASH_MODE_OFF; 2307 settings.update(ANDROID_FLASH_MODE, &flashMode, 1); 2308 2309 2310 /* lens */ 2311 static const float default_aperture = gCamCapability[mCameraId]->apertures[0]; 2312 settings.update(ANDROID_LENS_APERTURE, &default_aperture, 1); 2313 2314 if (gCamCapability[mCameraId]->filter_densities_count) { 2315 static const float default_filter_density = gCamCapability[mCameraId]->filter_densities[0]; 2316 settings.update(ANDROID_LENS_FILTER_DENSITY, &default_filter_density, 2317 gCamCapability[mCameraId]->filter_densities_count); 2318 } 2319 2320 /* TODO: Enable focus lengths once supported*/ 2321 /*if (gCamCapability[mCameraId]->focal_lengths_count) { 2322 static const float default_focal_length = gCamCapability[mCameraId]->focal_lengths[0]; 2323 settings.update(ANDROID_LENS_FOCAL_LENGTH, &default_focal_length, 1); 2324 }*/ 2325 2326 mDefaultMetadata[type] = settings.release(); 2327 2328 pthread_mutex_unlock(&mMutex); 2329 return mDefaultMetadata[type]; 2330} 2331 2332/*=========================================================================== 2333 * FUNCTION : setFrameParameters 2334 * 2335 * DESCRIPTION: set parameters per frame as requested in the metadata from 2336 * framework 2337 * 2338 * PARAMETERS : 2339 * @settings : frame settings information from framework 2340 * 2341 * 2342 * RETURN : success: NO_ERROR 2343 * failure: 2344 *==========================================================================*/ 2345int QCamera3HardwareInterface::setFrameParameters(int frame_id, 2346 const camera_metadata_t *settings) 2347{ 2348 /*translate from camera_metadata_t type to parm_type_t*/ 2349 int rc = 0; 2350 if (settings == NULL && mFirstRequest) { 2351 /*settings cannot be null for the first request*/ 2352 return BAD_VALUE; 2353 } 2354 2355 int32_t hal_version = CAM_HAL_V3; 2356 2357 memset(mParameters, 0, sizeof(parm_buffer_t)); 2358 mParameters->first_flagged_entry = CAM_INTF_PARM_MAX; 2359 AddSetParmEntryToBatch(mParameters, CAM_INTF_PARM_HAL_VERSION, 2360 sizeof(hal_version), &hal_version); 2361 2362 /*we need to update the frame number in the parameters*/ 2363 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_FRAME_NUMBER, 2364 sizeof(frame_id), &frame_id); 2365 if (rc < 0) { 2366 ALOGE("%s: Failed to set the frame number in the parameters", __func__); 2367 return BAD_VALUE; 2368 } 2369 2370 if(settings != NULL){ 2371 rc = translateMetadataToParameters(settings); 2372 } 2373 /*set the parameters to backend*/ 2374 ALOGE("%s: %d", __func__, __LINE__); 2375 mCameraHandle->ops->set_parms(mCameraHandle->camera_handle, mParameters); 2376 return rc; 2377} 2378 2379/*=========================================================================== 2380 * FUNCTION : translateMetadataToParameters 2381 * 2382 * DESCRIPTION: read from the camera_metadata_t and change to parm_type_t 2383 * 2384 * 2385 * PARAMETERS : 2386 * @settings : frame settings information from framework 2387 * 2388 * 2389 * RETURN : success: NO_ERROR 2390 * failure: 2391 *==========================================================================*/ 2392int QCamera3HardwareInterface::translateMetadataToParameters 2393 (const camera_metadata_t *settings) 2394{ 2395 int rc = 0; 2396 CameraMetadata frame_settings; 2397 frame_settings = settings; 2398 2399 2400 if (frame_settings.exists(ANDROID_CONTROL_AE_ANTIBANDING_MODE)) { 2401 int32_t antibandingMode = 2402 frame_settings.find(ANDROID_CONTROL_AE_ANTIBANDING_MODE).data.i32[0]; 2403 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_PARM_ANTIBANDING, 2404 sizeof(antibandingMode), &antibandingMode); 2405 } 2406 2407 /*int32_t expCompensation = frame_settings.find().data.i32[0]; 2408 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_PARM_EXPOSURE_COMPENSATION, 2409 sizeof(expCompensation), &expCompensation);*/ 2410 if (frame_settings.exists(ANDROID_CONTROL_AE_LOCK)) { 2411 uint8_t aeLock = frame_settings.find(ANDROID_CONTROL_AE_LOCK).data.u8[0]; 2412 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_PARM_AEC_LOCK, 2413 sizeof(aeLock), &aeLock); 2414 } 2415 2416 if (frame_settings.exists(ANDROID_CONTROL_AE_TARGET_FPS_RANGE)) { 2417 cam_fps_range_t fps_range; 2418 fps_range.min_fps = 2419 frame_settings.find(ANDROID_CONTROL_AE_TARGET_FPS_RANGE).data.i32[0]; 2420 fps_range.max_fps = 2421 frame_settings.find(ANDROID_CONTROL_AE_TARGET_FPS_RANGE).data.i32[0]; 2422 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_PARM_FPS_RANGE, 2423 sizeof(fps_range), &fps_range); 2424 } 2425 2426 if (frame_settings.exists(ANDROID_CONTROL_AF_MODE)) { 2427 uint8_t focusMode = 2428 frame_settings.find(ANDROID_CONTROL_AF_MODE).data.u8[0]; 2429 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_PARM_FOCUS_MODE, 2430 sizeof(focusMode), &focusMode); 2431 } 2432 2433 if (frame_settings.exists(ANDROID_CONTROL_AWB_LOCK)) { 2434 uint8_t awbLock = 2435 frame_settings.find(ANDROID_CONTROL_AWB_LOCK).data.u8[0]; 2436 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_PARM_AWB_LOCK, 2437 sizeof(awbLock), &awbLock); 2438 } 2439 2440 if (frame_settings.exists(ANDROID_CONTROL_AWB_MODE)) { 2441 uint8_t fwk_whiteLevel = 2442 frame_settings.find(ANDROID_CONTROL_AWB_MODE).data.u8[0]; 2443 uint8_t whiteLevel = lookupHalName(WHITE_BALANCE_MODES_MAP, 2444 sizeof(WHITE_BALANCE_MODES_MAP), 2445 fwk_whiteLevel); 2446 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_PARM_WHITE_BALANCE, 2447 sizeof(whiteLevel), &whiteLevel); 2448 } 2449 2450 if (frame_settings.exists(ANDROID_CONTROL_EFFECT_MODE)) { 2451 uint8_t fwk_effectMode = 2452 frame_settings.find(ANDROID_CONTROL_EFFECT_MODE).data.u8[0]; 2453 uint8_t effectMode = lookupHalName(EFFECT_MODES_MAP, 2454 sizeof(EFFECT_MODES_MAP), 2455 fwk_effectMode); 2456 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_PARM_EFFECT, 2457 sizeof(effectMode), &effectMode); 2458 } 2459 2460 if (frame_settings.exists(ANDROID_CONTROL_AE_MODE)) { 2461 uint8_t fwk_aeMode = 2462 frame_settings.find(ANDROID_CONTROL_AE_MODE).data.u8[0]; 2463 uint8_t aeMode = lookupHalName(AUTO_EXPOSURE_MAP, 2464 sizeof(AUTO_EXPOSURE_MAP), 2465 fwk_aeMode); 2466 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_AEC_MODE, 2467 sizeof(aeMode), &aeMode); 2468 } 2469 2470 if (frame_settings.exists(ANDROID_REQUEST_FRAME_COUNT)) { 2471 int32_t metaFrameNumber = 2472 frame_settings.find(ANDROID_REQUEST_FRAME_COUNT).data.i32[0]; 2473 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_FRAME_NUMBER, 2474 sizeof(metaFrameNumber), &metaFrameNumber); 2475 } 2476 2477 if (frame_settings.exists(ANDROID_COLOR_CORRECTION_MODE)) { 2478 uint8_t colorCorrectMode = 2479 frame_settings.find(ANDROID_COLOR_CORRECTION_MODE).data.u8[0]; 2480 rc = 2481 AddSetParmEntryToBatch(mParameters, CAM_INTF_META_COLOR_CORRECT_MODE, 2482 sizeof(colorCorrectMode), &colorCorrectMode); 2483 } 2484 2485 uint8_t aecTrigger = CAM_AEC_TRIGGER_IDLE; 2486 if (frame_settings.exists(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER)) { 2487 aecTrigger = 2488 frame_settings.find(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER).data.u8[0]; 2489 } 2490 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_AEC_PRECAPTURE_TRIGGER, 2491 sizeof(aecTrigger), &aecTrigger); 2492 2493 if (frame_settings.exists(ANDROID_CONTROL_AF_TRIGGER)) { 2494 uint8_t afTrigger = 2495 frame_settings.find(ANDROID_CONTROL_AF_TRIGGER).data.u8[0]; 2496 rc = AddSetParmEntryToBatch(mParameters, 2497 CAM_INTF_META_AF_TRIGGER, sizeof(afTrigger), &afTrigger); 2498 } 2499 2500 if (frame_settings.exists(ANDROID_CONTROL_MODE)) { 2501 uint8_t metaMode = frame_settings.find(ANDROID_CONTROL_MODE).data.u8[0]; 2502 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_MODE, 2503 sizeof(metaMode), &metaMode); 2504 } 2505 2506 if (frame_settings.exists(ANDROID_DEMOSAIC_MODE)) { 2507 int32_t demosaic = 2508 frame_settings.find(ANDROID_DEMOSAIC_MODE).data.u8[0]; 2509 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_DEMOSAIC, 2510 sizeof(demosaic), &demosaic); 2511 } 2512 2513 if (frame_settings.exists(ANDROID_EDGE_MODE)) { 2514 uint8_t edgeMode = frame_settings.find(ANDROID_EDGE_MODE).data.u8[0]; 2515 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_EDGE, 2516 sizeof(edgeMode), &edgeMode); 2517 } 2518 2519 if (frame_settings.exists(ANDROID_EDGE_STRENGTH)) { 2520 int32_t edgeStrength = 2521 frame_settings.find(ANDROID_EDGE_STRENGTH).data.i32[0]; 2522 rc = AddSetParmEntryToBatch(mParameters, 2523 CAM_INTF_META_SHARPNESS_STRENGTH, sizeof(edgeStrength), &edgeStrength); 2524 } 2525 2526 if (frame_settings.exists(ANDROID_FLASH_FIRING_POWER)) { 2527 uint8_t flashPower = 2528 frame_settings.find(ANDROID_FLASH_FIRING_POWER).data.u8[0]; 2529 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_FLASH_POWER, 2530 sizeof(flashPower), &flashPower); 2531 } 2532 2533 if (frame_settings.exists(ANDROID_FLASH_FIRING_TIME)) { 2534 int64_t flashFiringTime = 2535 frame_settings.find(ANDROID_FLASH_FIRING_TIME).data.i64[0]; 2536 rc = AddSetParmEntryToBatch(mParameters, 2537 CAM_INTF_META_FLASH_FIRING_TIME, sizeof(flashFiringTime), &flashFiringTime); 2538 } 2539 2540 if (frame_settings.exists(ANDROID_GEOMETRIC_MODE)) { 2541 uint8_t geometricMode = 2542 frame_settings.find(ANDROID_GEOMETRIC_MODE).data.u8[0]; 2543 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_GEOMETRIC_MODE, 2544 sizeof(geometricMode), &geometricMode); 2545 } 2546 2547 if (frame_settings.exists(ANDROID_GEOMETRIC_STRENGTH)) { 2548 uint8_t geometricStrength = 2549 frame_settings.find(ANDROID_GEOMETRIC_STRENGTH).data.u8[0]; 2550 rc = AddSetParmEntryToBatch(mParameters, 2551 CAM_INTF_META_GEOMETRIC_STRENGTH, 2552 sizeof(geometricStrength), &geometricStrength); 2553 } 2554 2555 if (frame_settings.exists(ANDROID_HOT_PIXEL_MODE)) { 2556 uint8_t hotPixelMode = 2557 frame_settings.find(ANDROID_HOT_PIXEL_MODE).data.u8[0]; 2558 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_HOTPIXEL_MODE, 2559 sizeof(hotPixelMode), &hotPixelMode); 2560 } 2561 2562 if (frame_settings.exists(ANDROID_LENS_APERTURE)) { 2563 float lensAperture = 2564 frame_settings.find( ANDROID_LENS_APERTURE).data.f[0]; 2565 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_LENS_APERTURE, 2566 sizeof(lensAperture), &lensAperture); 2567 } 2568 2569 if (frame_settings.exists(ANDROID_LENS_FILTER_DENSITY)) { 2570 float filterDensity = 2571 frame_settings.find(ANDROID_LENS_FILTER_DENSITY).data.f[0]; 2572 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_LENS_FILTERDENSITY, 2573 sizeof(filterDensity), &filterDensity); 2574 } 2575 2576 if (frame_settings.exists(ANDROID_LENS_FOCAL_LENGTH)) { 2577 float focalLength = 2578 frame_settings.find(ANDROID_LENS_FOCAL_LENGTH).data.f[0]; 2579 rc = AddSetParmEntryToBatch(mParameters, 2580 CAM_INTF_META_LENS_FOCAL_LENGTH, 2581 sizeof(focalLength), &focalLength); 2582 } 2583 2584 if (frame_settings.exists(ANDROID_LENS_FOCUS_DISTANCE)) { 2585 float focalDistance = 2586 frame_settings.find(ANDROID_LENS_FOCUS_DISTANCE).data.f[0]; 2587 rc = AddSetParmEntryToBatch(mParameters, 2588 CAM_INTF_META_LENS_FOCUS_DISTANCE, 2589 sizeof(focalDistance), &focalDistance); 2590 } 2591 2592 if (frame_settings.exists(ANDROID_LENS_OPTICAL_STABILIZATION_MODE)) { 2593 uint8_t optStabMode = 2594 frame_settings.find(ANDROID_LENS_OPTICAL_STABILIZATION_MODE).data.u8[0]; 2595 rc = AddSetParmEntryToBatch(mParameters, 2596 CAM_INTF_META_LENS_OPT_STAB_MODE, 2597 sizeof(optStabMode), &optStabMode); 2598 } 2599 2600 if (frame_settings.exists(ANDROID_NOISE_REDUCTION_MODE)) { 2601 uint8_t noiseRedMode = 2602 frame_settings.find(ANDROID_NOISE_REDUCTION_MODE).data.u8[0]; 2603 rc = AddSetParmEntryToBatch(mParameters, 2604 CAM_INTF_META_NOISE_REDUCTION_MODE, 2605 sizeof(noiseRedMode), &noiseRedMode); 2606 } 2607 2608 if (frame_settings.exists(ANDROID_NOISE_REDUCTION_STRENGTH)) { 2609 uint8_t noiseRedStrength = 2610 frame_settings.find(ANDROID_NOISE_REDUCTION_STRENGTH).data.u8[0]; 2611 rc = AddSetParmEntryToBatch(mParameters, 2612 CAM_INTF_META_NOISE_REDUCTION_STRENGTH, 2613 sizeof(noiseRedStrength), &noiseRedStrength); 2614 } 2615 2616 if (frame_settings.exists(ANDROID_SCALER_CROP_REGION)) { 2617 cam_crop_region_t scalerCropRegion; 2618 scalerCropRegion.left = 2619 frame_settings.find(ANDROID_SCALER_CROP_REGION).data.i32[0]; 2620 scalerCropRegion.top = 2621 frame_settings.find(ANDROID_SCALER_CROP_REGION).data.i32[1]; 2622 scalerCropRegion.width = 2623 frame_settings.find(ANDROID_SCALER_CROP_REGION).data.i32[2]; 2624 rc = AddSetParmEntryToBatch(mParameters, 2625 CAM_INTF_META_SCALER_CROP_REGION, 2626 sizeof(scalerCropRegion), &scalerCropRegion); 2627 } 2628 2629 if (frame_settings.exists(ANDROID_SENSOR_EXPOSURE_TIME)) { 2630 int64_t sensorExpTime = 2631 frame_settings.find(ANDROID_SENSOR_EXPOSURE_TIME).data.i64[0]; 2632 rc = AddSetParmEntryToBatch(mParameters, 2633 CAM_INTF_META_SENSOR_EXPOSURE_TIME, 2634 sizeof(sensorExpTime), &sensorExpTime); 2635 } 2636 2637 if (frame_settings.exists(ANDROID_SENSOR_FRAME_DURATION)) { 2638 int64_t sensorFrameDuration = 2639 frame_settings.find(ANDROID_SENSOR_FRAME_DURATION).data.i64[0]; 2640 rc = AddSetParmEntryToBatch(mParameters, 2641 CAM_INTF_META_SENSOR_FRAME_DURATION, 2642 sizeof(sensorFrameDuration), &sensorFrameDuration); 2643 } 2644 2645 if (frame_settings.exists(ANDROID_SENSOR_SENSITIVITY)) { 2646 int32_t sensorSensitivity = 2647 frame_settings.find(ANDROID_SENSOR_SENSITIVITY).data.i32[0]; 2648 rc = AddSetParmEntryToBatch(mParameters, 2649 CAM_INTF_META_SENSOR_SENSITIVITY, 2650 sizeof(sensorSensitivity), &sensorSensitivity); 2651 } 2652 2653 if (frame_settings.exists(ANDROID_SHADING_MODE)) { 2654 int32_t shadingMode = 2655 frame_settings.find(ANDROID_SHADING_MODE).data.u8[0]; 2656 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_SHADING_MODE, 2657 sizeof(shadingMode), &shadingMode); 2658 } 2659 2660 if (frame_settings.exists(ANDROID_SHADING_STRENGTH)) { 2661 uint8_t shadingStrength = 2662 frame_settings.find(ANDROID_SHADING_STRENGTH).data.u8[0]; 2663 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_SHADING_STRENGTH, 2664 sizeof(shadingStrength), &shadingStrength); 2665 } 2666 2667 if (frame_settings.exists(ANDROID_STATISTICS_FACE_DETECT_MODE)) { 2668 uint8_t facedetectMode = 2669 frame_settings.find(ANDROID_STATISTICS_FACE_DETECT_MODE).data.u8[0]; 2670 rc = AddSetParmEntryToBatch(mParameters, 2671 CAM_INTF_META_STATS_FACEDETECT_MODE, 2672 sizeof(facedetectMode), &facedetectMode); 2673 } 2674 2675 if (frame_settings.exists(ANDROID_STATISTICS_HISTOGRAM_MODE)) { 2676 uint8_t histogramMode = 2677 frame_settings.find(ANDROID_STATISTICS_HISTOGRAM_MODE).data.u8[0]; 2678 rc = AddSetParmEntryToBatch(mParameters, 2679 CAM_INTF_META_STATS_HISTOGRAM_MODE, 2680 sizeof(histogramMode), &histogramMode); 2681 } 2682 2683 if (frame_settings.exists(ANDROID_STATISTICS_SHARPNESS_MAP_MODE)) { 2684 uint8_t sharpnessMapMode = 2685 frame_settings.find(ANDROID_STATISTICS_SHARPNESS_MAP_MODE).data.u8[0]; 2686 rc = AddSetParmEntryToBatch(mParameters, 2687 CAM_INTF_META_STATS_SHARPNESS_MAP_MODE, 2688 sizeof(sharpnessMapMode), &sharpnessMapMode); 2689 } 2690 2691 if (frame_settings.exists(ANDROID_TONEMAP_MODE)) { 2692 uint8_t tonemapMode = 2693 frame_settings.find(ANDROID_TONEMAP_MODE).data.u8[0]; 2694 rc = AddSetParmEntryToBatch(mParameters, 2695 CAM_INTF_META_TONEMAP_MODE, 2696 sizeof(tonemapMode), &tonemapMode); 2697 } 2698 2699 if (frame_settings.exists(ANDROID_CONTROL_CAPTURE_INTENT)) { 2700 uint8_t captureIntent = 2701 frame_settings.find(ANDROID_CONTROL_CAPTURE_INTENT).data.u8[0]; 2702 rc = AddSetParmEntryToBatch(mParameters, CAM_INTF_META_CAPTURE_INTENT, 2703 sizeof(captureIntent), &captureIntent); 2704 } 2705 2706 return rc; 2707} 2708 2709/*=========================================================================== 2710 * FUNCTION : getJpegSettings 2711 * 2712 * DESCRIPTION: save the jpeg settings in the HAL 2713 * 2714 * 2715 * PARAMETERS : 2716 * @settings : frame settings information from framework 2717 * 2718 * 2719 * RETURN : success: NO_ERROR 2720 * failure: 2721 *==========================================================================*/ 2722int QCamera3HardwareInterface::getJpegSettings 2723 (const camera_metadata_t *settings) 2724{ 2725 if (mJpegSettings) { 2726 free(mJpegSettings); 2727 mJpegSettings = NULL; 2728 } 2729 mJpegSettings = (jpeg_settings_t*) malloc(sizeof(jpeg_settings_t)); 2730 CameraMetadata jpeg_settings; 2731 jpeg_settings = settings; 2732 2733 if (jpeg_settings.exists(ANDROID_JPEG_ORIENTATION)) { 2734 mJpegSettings->jpeg_orientation = 2735 jpeg_settings.find(ANDROID_JPEG_ORIENTATION).data.i32[0]; 2736 } else { 2737 mJpegSettings->jpeg_orientation = 0; 2738 } 2739 if (jpeg_settings.exists(ANDROID_JPEG_QUALITY)) { 2740 mJpegSettings->jpeg_quality = 2741 jpeg_settings.find(ANDROID_JPEG_QUALITY).data.u8[0]; 2742 } else { 2743 mJpegSettings->jpeg_quality = 85; 2744 } 2745 if (jpeg_settings.exists(ANDROID_JPEG_THUMBNAIL_SIZE)) { 2746 mJpegSettings->thumbnail_size.width = 2747 jpeg_settings.find(ANDROID_JPEG_THUMBNAIL_SIZE).data.i32[0]; 2748 mJpegSettings->thumbnail_size.height = 2749 jpeg_settings.find(ANDROID_JPEG_THUMBNAIL_SIZE).data.i32[1]; 2750 mJpegSettings->thumbnail_size.width = 320; 2751 mJpegSettings->thumbnail_size.height = 240; 2752 } else { 2753 mJpegSettings->thumbnail_size.width = 640; 2754 mJpegSettings->thumbnail_size.height = 480; 2755 } 2756 if (jpeg_settings.exists(ANDROID_JPEG_GPS_COORDINATES)) { 2757 for (int i = 0; i < 3; i++) { 2758 mJpegSettings->gps_coordinates[i] = 2759 jpeg_settings.find(ANDROID_JPEG_GPS_COORDINATES).data.d[i]; 2760 } 2761 } 2762 if (jpeg_settings.exists(ANDROID_JPEG_GPS_TIMESTAMP)) { 2763 mJpegSettings->gps_timestamp = 2764 jpeg_settings.find(ANDROID_JPEG_GPS_TIMESTAMP).data.i64[0]; 2765 } 2766 2767 if (jpeg_settings.exists(ANDROID_JPEG_GPS_PROCESSING_METHOD)) { 2768 mJpegSettings->gps_processing_method = 2769 jpeg_settings.find(ANDROID_JPEG_GPS_PROCESSING_METHOD).data.u8[0]; 2770 } 2771 if (jpeg_settings.exists(ANDROID_SENSOR_SENSITIVITY)) { 2772 mJpegSettings->sensor_sensitivity = 2773 jpeg_settings.find(ANDROID_SENSOR_SENSITIVITY).data.i32[0]; 2774 } 2775 if (jpeg_settings.exists(ANDROID_LENS_FOCAL_LENGTH)) { 2776 mJpegSettings->lens_focal_length = 2777 jpeg_settings.find(ANDROID_LENS_FOCAL_LENGTH).data.f[0]; 2778 } 2779 return 0; 2780} 2781 2782/*=========================================================================== 2783 * FUNCTION : captureResultCb 2784 * 2785 * DESCRIPTION: Callback handler for all channels (streams, as well as metadata) 2786 * 2787 * PARAMETERS : 2788 * @frame : frame information from mm-camera-interface 2789 * @buffer : actual gralloc buffer to be returned to frameworks. NULL if metadata. 2790 * @userdata: userdata 2791 * 2792 * RETURN : NONE 2793 *==========================================================================*/ 2794void QCamera3HardwareInterface::captureResultCb(mm_camera_super_buf_t *metadata, 2795 camera3_stream_buffer_t *buffer, 2796 uint32_t frame_number, void *userdata) 2797{ 2798 QCamera3HardwareInterface *hw = (QCamera3HardwareInterface *)userdata; 2799 if (hw == NULL) { 2800 ALOGE("%s: Invalid hw %p", __func__, hw); 2801 return; 2802 } 2803 2804 hw->captureResultCb(metadata, buffer, frame_number); 2805 return; 2806} 2807 2808/*=========================================================================== 2809 * FUNCTION : initialize 2810 * 2811 * DESCRIPTION: Pass framework callback pointers to HAL 2812 * 2813 * PARAMETERS : 2814 * 2815 * 2816 * RETURN : Success : 0 2817 * Failure: -ENODEV 2818 *==========================================================================*/ 2819 2820int QCamera3HardwareInterface::initialize(const struct camera3_device *device, 2821 const camera3_callback_ops_t *callback_ops) 2822{ 2823 ALOGE("%s: E", __func__); 2824 QCamera3HardwareInterface *hw = 2825 reinterpret_cast<QCamera3HardwareInterface *>(device->priv); 2826 if (!hw) { 2827 ALOGE("%s: NULL camera device", __func__); 2828 return -ENODEV; 2829 } 2830 2831 int rc = hw->initialize(callback_ops); 2832 ALOGE("%s: X", __func__); 2833 return rc; 2834} 2835 2836/*=========================================================================== 2837 * FUNCTION : configure_streams 2838 * 2839 * DESCRIPTION: 2840 * 2841 * PARAMETERS : 2842 * 2843 * 2844 * RETURN : Success: 0 2845 * Failure: -EINVAL (if stream configuration is invalid) 2846 * -ENODEV (fatal error) 2847 *==========================================================================*/ 2848 2849int QCamera3HardwareInterface::configure_streams( 2850 const struct camera3_device *device, 2851 camera3_stream_configuration_t *stream_list) 2852{ 2853 ALOGE("%s: E", __func__); 2854 QCamera3HardwareInterface *hw = 2855 reinterpret_cast<QCamera3HardwareInterface *>(device->priv); 2856 if (!hw) { 2857 ALOGE("%s: NULL camera device", __func__); 2858 return -ENODEV; 2859 } 2860 int rc = hw->configureStreams(stream_list); 2861 ALOGE("%s: X", __func__); 2862 return rc; 2863} 2864 2865/*=========================================================================== 2866 * FUNCTION : register_stream_buffers 2867 * 2868 * DESCRIPTION: Register stream buffers with the device 2869 * 2870 * PARAMETERS : 2871 * 2872 * RETURN : 2873 *==========================================================================*/ 2874int QCamera3HardwareInterface::register_stream_buffers( 2875 const struct camera3_device *device, 2876 const camera3_stream_buffer_set_t *buffer_set) 2877{ 2878 ALOGE("%s: E", __func__); 2879 QCamera3HardwareInterface *hw = 2880 reinterpret_cast<QCamera3HardwareInterface *>(device->priv); 2881 if (!hw) { 2882 ALOGE("%s: NULL camera device", __func__); 2883 return -ENODEV; 2884 } 2885 int rc = hw->registerStreamBuffers(buffer_set); 2886 ALOGE("%s: X", __func__); 2887 return rc; 2888} 2889 2890/*=========================================================================== 2891 * FUNCTION : construct_default_request_settings 2892 * 2893 * DESCRIPTION: Configure a settings buffer to meet the required use case 2894 * 2895 * PARAMETERS : 2896 * 2897 * 2898 * RETURN : Success: Return valid metadata 2899 * Failure: Return NULL 2900 *==========================================================================*/ 2901const camera_metadata_t* QCamera3HardwareInterface:: 2902 construct_default_request_settings(const struct camera3_device *device, 2903 int type) 2904{ 2905 2906 ALOGE("%s: E", __func__); 2907 camera_metadata_t* fwk_metadata = NULL; 2908 QCamera3HardwareInterface *hw = 2909 reinterpret_cast<QCamera3HardwareInterface *>(device->priv); 2910 if (!hw) { 2911 ALOGE("%s: NULL camera device", __func__); 2912 return NULL; 2913 } 2914 2915 fwk_metadata = hw->translateCapabilityToMetadata(type); 2916 2917 ALOGE("%s: X", __func__); 2918 return fwk_metadata; 2919} 2920 2921/*=========================================================================== 2922 * FUNCTION : process_capture_request 2923 * 2924 * DESCRIPTION: 2925 * 2926 * PARAMETERS : 2927 * 2928 * 2929 * RETURN : 2930 *==========================================================================*/ 2931int QCamera3HardwareInterface::process_capture_request( 2932 const struct camera3_device *device, 2933 camera3_capture_request_t *request) 2934{ 2935 ALOGE("%s: E", __func__); 2936 QCamera3HardwareInterface *hw = 2937 reinterpret_cast<QCamera3HardwareInterface *>(device->priv); 2938 if (!hw) { 2939 ALOGE("%s: NULL camera device", __func__); 2940 return -EINVAL; 2941 } 2942 2943 int rc = hw->processCaptureRequest(request); 2944 ALOGE("%s: X", __func__); 2945 return rc; 2946} 2947 2948/*=========================================================================== 2949 * FUNCTION : get_metadata_vendor_tag_ops 2950 * 2951 * DESCRIPTION: 2952 * 2953 * PARAMETERS : 2954 * 2955 * 2956 * RETURN : 2957 *==========================================================================*/ 2958 2959void QCamera3HardwareInterface::get_metadata_vendor_tag_ops( 2960 const struct camera3_device *device, 2961 vendor_tag_query_ops_t* ops) 2962{ 2963 ALOGE("%s: E", __func__); 2964 QCamera3HardwareInterface *hw = 2965 reinterpret_cast<QCamera3HardwareInterface *>(device->priv); 2966 if (!hw) { 2967 ALOGE("%s: NULL camera device", __func__); 2968 return; 2969 } 2970 2971 hw->getMetadataVendorTagOps(ops); 2972 ALOGE("%s: X", __func__); 2973 return; 2974} 2975 2976/*=========================================================================== 2977 * FUNCTION : dump 2978 * 2979 * DESCRIPTION: 2980 * 2981 * PARAMETERS : 2982 * 2983 * 2984 * RETURN : 2985 *==========================================================================*/ 2986 2987void QCamera3HardwareInterface::dump( 2988 const struct camera3_device *device, int fd) 2989{ 2990 ALOGE("%s: E", __func__); 2991 QCamera3HardwareInterface *hw = 2992 reinterpret_cast<QCamera3HardwareInterface *>(device->priv); 2993 if (!hw) { 2994 ALOGE("%s: NULL camera device", __func__); 2995 return; 2996 } 2997 2998 hw->dump(fd); 2999 ALOGE("%s: X", __func__); 3000 return; 3001} 3002 3003/*=========================================================================== 3004 * FUNCTION : close_camera_device 3005 * 3006 * DESCRIPTION: 3007 * 3008 * PARAMETERS : 3009 * 3010 * 3011 * RETURN : 3012 *==========================================================================*/ 3013int QCamera3HardwareInterface::close_camera_device(struct hw_device_t* device) 3014{ 3015 ALOGE("%s: E", __func__); 3016 int ret = NO_ERROR; 3017 QCamera3HardwareInterface *hw = 3018 reinterpret_cast<QCamera3HardwareInterface *>( 3019 reinterpret_cast<camera3_device_t *>(device)->priv); 3020 if (!hw) { 3021 ALOGE("NULL camera device"); 3022 return BAD_VALUE; 3023 } 3024 delete hw; 3025 ALOGE("%s: X", __func__); 3026 return ret; 3027} 3028 3029}; //end namespace qcamera 3030