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