1 /* 2 ** Copyright (c) 2011-2012 The Linux Foundation. All rights reserved. 3 ** 4 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** you may not use this file except in compliance with the License. 6 ** You may obtain a copy of the License at 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 10 ** Unless required by applicable law or agreed to in writing, software 11 ** distributed under the License is distributed on an "AS IS" BASIS, 12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 */ 16 17 /*#error uncomment this for compiler test!*/ 18 19 #define LOG_NIDEBUG 0 20 21 #define LOG_TAG "QCameraHWI" 22 #include <utils/Log.h> 23 #include <utils/threads.h> 24 #include <cutils/properties.h> 25 #include <fcntl.h> 26 #include <sys/mman.h> 27 28 #include "QCameraHAL.h" 29 #include "QCameraHWI.h" 30 31 /* QCameraHardwareInterface class implementation goes here*/ 32 /* following code implement the contol logic of this class*/ 33 34 namespace android { 35 static void HAL_event_cb(mm_camera_event_t *evt, void *user_data) 36 { 37 QCameraHardwareInterface *obj = (QCameraHardwareInterface *)user_data; 38 if (obj) { 39 obj->processEvent(evt); 40 } else { 41 LOGE("%s: NULL user_data", __func__); 42 } 43 } 44 45 int32_t QCameraHardwareInterface::createRecord() 46 { 47 int32_t ret = MM_CAMERA_OK; 48 LOGV("%s : BEGIN",__func__); 49 50 /* 51 * Creating Instance of record stream. 52 */ 53 LOGE("Mymode Record = %d",myMode); 54 mStreamRecord = QCameraStream_record::createInstance(mCameraId, 55 myMode); 56 57 if (!mStreamRecord) { 58 LOGE("%s: error - can't creat record stream!", __func__); 59 return BAD_VALUE; 60 } 61 62 /* Store HAL object in record stream Object */ 63 mStreamRecord->setHALCameraControl(this); 64 65 /*Init Channel */ 66 ret = mStreamRecord->init(); 67 if (MM_CAMERA_OK != ret){ 68 LOGE("%s: error - can't init Record channel!", __func__); 69 return BAD_VALUE; 70 } 71 LOGV("%s : END",__func__); 72 return ret; 73 } 74 75 int32_t QCameraHardwareInterface::createSnapshot() 76 { 77 int32_t ret = MM_CAMERA_OK; 78 LOGV("%s : BEGIN",__func__); 79 80 /* 81 * Creating Instance of Snapshot stream. 82 */ 83 LOGE("Mymode Snap = %d",myMode); 84 mStreamSnap = QCameraStream_Snapshot::createInstance(mCameraId, 85 myMode); 86 if (!mStreamSnap) { 87 LOGE("%s: error - can't creat snapshot stream!", __func__); 88 return BAD_VALUE; 89 } 90 91 /* Store HAL object in Snapshot stream Object */ 92 mStreamSnap->setHALCameraControl(this); 93 94 /*Init Channel */ 95 ret = mStreamSnap->init(); 96 if (MM_CAMERA_OK != ret){ 97 LOGE("%s: error - can't init Snapshot channel!", __func__); 98 return BAD_VALUE; 99 } 100 LOGV("%s : END",__func__); 101 return ret; 102 } 103 104 int32_t QCameraHardwareInterface::createPreview() 105 { 106 int32_t ret = MM_CAMERA_OK; 107 LOGV("%s : BEGIN",__func__); 108 109 LOGE("Mymode Preview = %d",myMode); 110 mStreamDisplay = QCameraStream_preview::createInstance(mCameraId, 111 myMode); 112 if (!mStreamDisplay) { 113 LOGE("%s: error - can't creat preview stream!", __func__); 114 return BAD_VALUE; 115 } 116 117 mStreamDisplay->setHALCameraControl(this); 118 119 /*now init all the buffers and send to steam object*/ 120 ret = mStreamDisplay->init(); 121 if (MM_CAMERA_OK != ret){ 122 LOGE("%s: error - can't init Preview channel!", __func__); 123 return BAD_VALUE; 124 } 125 LOGV("%s : END",__func__); 126 return ret; 127 } 128 129 /* constructor */ 130 QCameraHardwareInterface:: 131 QCameraHardwareInterface(int cameraId, int mode) 132 : mCameraId(cameraId), 133 mParameters(), 134 mMsgEnabled(0), 135 mNotifyCb(0), 136 mDataCb(0), 137 mDataCbTimestamp(0), 138 mCallbackCookie(0), 139 //mPreviewHeap(0), 140 mStreamDisplay (NULL), mStreamRecord(NULL), mStreamSnap(NULL), 141 mFps(0), 142 mDebugFps(0), 143 mMaxZoom(0), 144 mCurrentZoom(0), 145 mSupportedPictureSizesCount(15), 146 mDumpFrmCnt(0), mDumpSkipCnt(0), 147 mPictureSizeCount(15), 148 mPreviewSizeCount(13), 149 mVideoSizeCount(0), 150 mAutoFocusRunning(false), 151 mHasAutoFocusSupport(false), 152 mInitialized(false), 153 mIs3DModeOn(0), 154 mSmoothZoomRunning(false), 155 mParamStringInitialized(false), 156 mFaceDetectOn(0), 157 mDisEnabled(0), 158 mZoomSupported(false), 159 mFullLiveshotEnabled(true), 160 mRecordingHint(0), 161 mStatsOn(0), mCurrentHisto(-1), mSendData(false), mStatHeap(NULL), 162 mZslLookBackMode(0), 163 mZslLookBackValue(0), 164 mZslEmptyQueueFlag(FALSE), 165 mPictureSizes(NULL), 166 mVideoSizes(NULL), 167 mCameraState(CAMERA_STATE_UNINITED), 168 mPostPreviewHeap(NULL), 169 mHdrMode(HDR_BRACKETING_OFF), 170 mStreamLiveSnap(NULL), 171 mExifTableNumEntries(0), 172 mDenoiseValue(0), 173 mSnapshotFormat(0), 174 mStartRecording(0), 175 mZslInterval(1), 176 mNoDisplayMode(0), 177 mBrightness(0), 178 mContrast(0), 179 mEffects(0), 180 mBestShotMode(0), 181 mHJR(0), 182 mSkinToneEnhancement(0), 183 mRotation(0), 184 mFocusMode(AF_MODE_MAX), 185 mPreviewFormat(CAMERA_YUV_420_NV21), 186 mRestartPreview(false), 187 mReleasedRecordingFrame(false) 188 { 189 LOGI("QCameraHardwareInterface: E"); 190 int32_t result = MM_CAMERA_E_GENERAL; 191 char value[PROPERTY_VALUE_MAX]; 192 193 pthread_mutex_init(&mAsyncCmdMutex, NULL); 194 pthread_cond_init(&mAsyncCmdWait, NULL); 195 196 property_get("persist.debug.sf.showfps", value, "0"); 197 mDebugFps = atoi(value); 198 mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED; 199 mPreviewWindow = NULL; 200 property_get("camera.hal.fps", value, "0"); 201 mFps = atoi(value); 202 203 LOGI("Init mPreviewState = %d", mPreviewState); 204 205 property_get("persist.camera.hal.multitouchaf", value, "0"); 206 mMultiTouch = atoi(value); 207 208 property_get("persist.camera.full.liveshot", value, "1"); 209 mFullLiveshotEnabled = atoi(value); 210 211 property_get("persist.camera.hal.dis", value, "0"); 212 mDisEnabled = atoi(value); 213 214 /* Open camera stack! */ 215 result=cam_ops_open(mCameraId, MM_CAMERA_OP_MODE_NOTUSED); 216 if (result == MM_CAMERA_OK) { 217 int i; 218 mm_camera_event_type_t evt; 219 for (i = 0; i < MM_CAMERA_EVT_TYPE_MAX; i++) { 220 evt = (mm_camera_event_type_t) i; 221 if (cam_evt_is_event_supported(mCameraId, evt)){ 222 cam_evt_register_event_notify(mCameraId, 223 HAL_event_cb, (void *)this, evt); 224 } 225 } 226 } 227 LOGV("Cam open returned %d",result); 228 if(MM_CAMERA_OK != result) { 229 LOGE("startCamera: cam_ops_open failed: id = %d", mCameraId); 230 return; 231 } 232 233 loadTables(); 234 /* Setup Picture Size and Preview size tables */ 235 setPictureSizeTable(); 236 LOGD("%s: Picture table size: %d", __func__, mPictureSizeCount); 237 LOGD("%s: Picture table: ", __func__); 238 for(unsigned int i=0; i < mPictureSizeCount;i++) { 239 LOGD(" %d %d", mPictureSizes[i].width, mPictureSizes[i].height); 240 } 241 242 setPreviewSizeTable(); 243 LOGD("%s: Preview table size: %d", __func__, mPreviewSizeCount); 244 LOGD("%s: Preview table: ", __func__); 245 for(unsigned int i=0; i < mPreviewSizeCount;i++) { 246 LOGD(" %d %d", mPreviewSizes[i].width, mPreviewSizes[i].height); 247 } 248 249 setVideoSizeTable(); 250 LOGD("%s: Video table size: %d", __func__, mVideoSizeCount); 251 LOGD("%s: Video table: ", __func__); 252 for(unsigned int i=0; i < mVideoSizeCount;i++) { 253 LOGD(" %d %d", mVideoSizes[i].width, mVideoSizes[i].height); 254 } 255 256 /* set my mode - update myMode member variable due to difference in 257 enum definition between upper and lower layer*/ 258 setMyMode(mode); 259 initDefaultParameters(); 260 261 //Create Stream Objects 262 //Preview 263 result = createPreview(); 264 if(result != MM_CAMERA_OK) { 265 LOGE("%s X: Failed to create Preview Object",__func__); 266 return; 267 } 268 269 //Record 270 result = createRecord(); 271 if(result != MM_CAMERA_OK) { 272 LOGE("%s X: Failed to create Record Object",__func__); 273 return; 274 } 275 276 //Snapshot 277 result = createSnapshot(); 278 if(result != MM_CAMERA_OK) { 279 LOGE("%s X: Failed to create Record Object",__func__); 280 return; 281 } 282 mCameraState = CAMERA_STATE_READY; 283 284 LOGI("QCameraHardwareInterface: X"); 285 } 286 287 QCameraHardwareInterface::~QCameraHardwareInterface() 288 { 289 LOGI("~QCameraHardwareInterface: E"); 290 int result; 291 292 switch(mPreviewState) { 293 case QCAMERA_HAL_PREVIEW_STOPPED: 294 break; 295 case QCAMERA_HAL_PREVIEW_START: 296 break; 297 case QCAMERA_HAL_PREVIEW_STARTED: 298 stopPreview(); 299 break; 300 case QCAMERA_HAL_RECORDING_STARTED: 301 stopRecordingInternal(); 302 stopPreview(); 303 break; 304 case QCAMERA_HAL_TAKE_PICTURE: 305 cancelPictureInternal(); 306 break; 307 default: 308 break; 309 } 310 mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED; 311 312 freePictureTable(); 313 freeVideoSizeTable(); 314 if(mStatHeap != NULL) { 315 mStatHeap.clear( ); 316 mStatHeap = NULL; 317 } 318 /* Join the threads, complete operations and then delete 319 the instances. */ 320 cam_ops_close(mCameraId); 321 if(mStreamDisplay){ 322 QCameraStream_preview::deleteInstance (mStreamDisplay); 323 mStreamDisplay = NULL; 324 } 325 if(mStreamRecord) { 326 QCameraStream_record::deleteInstance (mStreamRecord); 327 mStreamRecord = NULL; 328 } 329 if(mStreamSnap) { 330 QCameraStream_Snapshot::deleteInstance (mStreamSnap); 331 mStreamSnap = NULL; 332 } 333 334 if (mStreamLiveSnap){ 335 QCameraStream_Snapshot::deleteInstance (mStreamLiveSnap); 336 mStreamLiveSnap = NULL; 337 } 338 339 pthread_mutex_destroy(&mAsyncCmdMutex); 340 pthread_cond_destroy(&mAsyncCmdWait); 341 342 LOGI("~QCameraHardwareInterface: X"); 343 } 344 345 bool QCameraHardwareInterface::isCameraReady() 346 { 347 LOGE("isCameraReady mCameraState %d", mCameraState); 348 return (mCameraState == CAMERA_STATE_READY); 349 } 350 351 void QCameraHardwareInterface::release() 352 { 353 LOGI("release: E"); 354 Mutex::Autolock l(&mLock); 355 356 switch(mPreviewState) { 357 case QCAMERA_HAL_PREVIEW_STOPPED: 358 break; 359 case QCAMERA_HAL_PREVIEW_START: 360 break; 361 case QCAMERA_HAL_PREVIEW_STARTED: 362 stopPreviewInternal(); 363 break; 364 case QCAMERA_HAL_RECORDING_STARTED: 365 stopRecordingInternal(); 366 stopPreviewInternal(); 367 break; 368 case QCAMERA_HAL_TAKE_PICTURE: 369 cancelPictureInternal(); 370 break; 371 default: 372 break; 373 } 374 #if 0 375 if (isRecordingRunning()) { 376 stopRecordingInternal(); 377 LOGI("release: stopRecordingInternal done."); 378 } 379 if (isPreviewRunning()) { 380 stopPreview(); //stopPreviewInternal(); 381 LOGI("release: stopPreviewInternal done."); 382 } 383 if (isSnapshotRunning()) { 384 cancelPictureInternal(); 385 LOGI("release: cancelPictureInternal done."); 386 } 387 if (mCameraState == CAMERA_STATE_ERROR) { 388 //TBD: If Error occurs then tear down 389 LOGI("release: Tear down."); 390 } 391 #endif 392 mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED; 393 LOGI("release: X"); 394 } 395 396 void QCameraHardwareInterface::setCallbacks( 397 camera_notify_callback notify_cb, 398 camera_data_callback data_cb, 399 camera_data_timestamp_callback data_cb_timestamp, 400 camera_request_memory get_memory, 401 void *user) 402 { 403 LOGE("setCallbacks: E"); 404 Mutex::Autolock lock(mLock); 405 mNotifyCb = notify_cb; 406 mDataCb = data_cb; 407 mDataCbTimestamp = data_cb_timestamp; 408 mGetMemory = get_memory; 409 mCallbackCookie = user; 410 LOGI("setCallbacks: X"); 411 } 412 413 void QCameraHardwareInterface::enableMsgType(int32_t msgType) 414 { 415 LOGI("enableMsgType: E, msgType =0x%x", msgType); 416 Mutex::Autolock lock(mLock); 417 mMsgEnabled |= msgType; 418 LOGI("enableMsgType: X, msgType =0x%x, mMsgEnabled=0x%x", msgType, mMsgEnabled); 419 } 420 421 void QCameraHardwareInterface::disableMsgType(int32_t msgType) 422 { 423 LOGI("disableMsgType: E"); 424 Mutex::Autolock lock(mLock); 425 mMsgEnabled &= ~msgType; 426 LOGI("disableMsgType: X, msgType =0x%x, mMsgEnabled=0x%x", msgType, mMsgEnabled); 427 } 428 429 int QCameraHardwareInterface::msgTypeEnabled(int32_t msgType) 430 { 431 LOGI("msgTypeEnabled: E"); 432 Mutex::Autolock lock(mLock); 433 return (mMsgEnabled & msgType); 434 LOGI("msgTypeEnabled: X"); 435 } 436 #if 0 437 status_t QCameraHardwareInterface::dump(int fd, const Vector<String16>& args) const 438 { 439 LOGI("dump: E"); 440 const size_t SIZE = 256; 441 char buffer[SIZE]; 442 String8 result; 443 AutoMutex lock(&mLock); 444 write(fd, result.string(), result.size()); 445 LOGI("dump: E"); 446 return NO_ERROR; 447 } 448 #endif 449 450 int QCameraHardwareInterface::dump(int fd) 451 { 452 LOGE("%s: not supported yet", __func__); 453 return -1; 454 } 455 456 status_t QCameraHardwareInterface::sendCommand(int32_t command, int32_t arg1, 457 int32_t arg2) 458 { 459 LOGI("sendCommand: E"); 460 status_t rc = NO_ERROR; 461 Mutex::Autolock l(&mLock); 462 463 switch (command) { 464 case CAMERA_CMD_HISTOGRAM_ON: 465 LOGE("histogram set to on"); 466 rc = setHistogram(1); 467 break; 468 case CAMERA_CMD_HISTOGRAM_OFF: 469 LOGE("histogram set to off"); 470 rc = setHistogram(0); 471 break; 472 case CAMERA_CMD_HISTOGRAM_SEND_DATA: 473 LOGE("histogram send data"); 474 mSendData = true; 475 rc = NO_ERROR; 476 break; 477 case CAMERA_CMD_START_FACE_DETECTION: 478 if(supportsFaceDetection() == false){ 479 LOGE("Face detection support is not available"); 480 return NO_ERROR; 481 } 482 setFaceDetection("on"); 483 return runFaceDetection(); 484 case CAMERA_CMD_STOP_FACE_DETECTION: 485 if(supportsFaceDetection() == false){ 486 LOGE("Face detection support is not available"); 487 return NO_ERROR; 488 } 489 setFaceDetection("off"); 490 return runFaceDetection(); 491 #if 0 492 case CAMERA_CMD_SEND_META_DATA: 493 mMetaDataWaitLock.lock(); 494 if(mFaceDetectOn == true) { 495 mSendMetaData = true; 496 } 497 mMetaDataWaitLock.unlock(); 498 return NO_ERROR; 499 #endif 500 #if 0 /* To Do: will enable it later */ 501 case CAMERA_CMD_START_SMOOTH_ZOOM : 502 LOGV("HAL sendcmd start smooth zoom %d %d", arg1 , arg2); 503 /*TO DO: get MaxZoom from parameter*/ 504 int MaxZoom = 100; 505 506 switch(mCameraState ) { 507 case CAMERA_STATE_PREVIEW: 508 case CAMERA_STATE_RECORD_CMD_SENT: 509 case CAMERA_STATE_RECORD: 510 mTargetSmoothZoom = arg1; 511 mCurrentZoom = mParameters.getInt("zoom"); 512 mSmoothZoomStep = (mCurrentZoom > mTargetSmoothZoom)? -1: 1; 513 if(mCurrentZoom == mTargetSmoothZoom) { 514 LOGV("Smoothzoom target zoom value is same as " 515 "current zoom value, return..."); 516 mNotifyCallback(CAMERA_MSG_ZOOM, 517 mCurrentZoom, 1, mCallbackCookie); 518 } else if(mCurrentZoom < 0 || mCurrentZoom > MaxZoom || 519 mTargetSmoothZoom < 0 || mTargetSmoothZoom > MaxZoom) { 520 LOGE(" ERROR : beyond supported zoom values, break.."); 521 mNotifyCallback(CAMERA_MSG_ZOOM, 522 mCurrentZoom, 0, mCallbackCookie); 523 } else { 524 mSmoothZoomRunning = true; 525 mCurrentZoom += mSmoothZoomStep; 526 if ((mSmoothZoomStep < 0 && mCurrentZoom < mTargetSmoothZoom)|| 527 (mSmoothZoomStep > 0 && mCurrentZoom > mTargetSmoothZoom )) { 528 mCurrentZoom = mTargetSmoothZoom; 529 } 530 mParameters.set("zoom", mCurrentZoom); 531 setZoom(mParameters); 532 } 533 break; 534 default: 535 LOGV(" No preview, no smoothzoom "); 536 break; 537 } 538 rc = NO_ERROR; 539 break; 540 541 case CAMERA_CMD_STOP_SMOOTH_ZOOM: 542 if(mSmoothZoomRunning) { 543 mSmoothZoomRunning = false; 544 /*To Do: send cmd to stop zooming*/ 545 } 546 LOGV("HAL sendcmd stop smooth zoom"); 547 rc = NO_ERROR; 548 break; 549 #endif 550 default: 551 break; 552 } 553 LOGI("sendCommand: X"); 554 return rc; 555 } 556 557 void QCameraHardwareInterface::setMyMode(int mode) 558 { 559 LOGI("setMyMode: E"); 560 if (mode & CAMERA_SUPPORT_MODE_3D) { 561 myMode = CAMERA_MODE_3D; 562 }else { 563 /* default mode is 2D */ 564 myMode = CAMERA_MODE_2D; 565 } 566 567 if (mode & CAMERA_SUPPORT_MODE_ZSL) { 568 myMode = (camera_mode_t)(myMode |CAMERA_ZSL_MODE); 569 }else { 570 myMode = (camera_mode_t) (myMode | CAMERA_NONZSL_MODE); 571 } 572 LOGI("setMyMode: Set mode to %d (passed mode: %d)", myMode, mode); 573 LOGI("setMyMode: X"); 574 } 575 /* static factory function */ 576 QCameraHardwareInterface *QCameraHardwareInterface::createInstance(int cameraId, int mode) 577 { 578 LOGI("createInstance: E"); 579 QCameraHardwareInterface *cam = new QCameraHardwareInterface(cameraId, mode); 580 if (cam ) { 581 if (cam->mCameraState != CAMERA_STATE_READY) { 582 LOGE("createInstance: Failed"); 583 delete cam; 584 cam = NULL; 585 } 586 } 587 588 if (cam) { 589 //sp<CameraHardwareInterface> hardware(cam); 590 LOGI("createInstance: X"); 591 return cam; 592 } else { 593 return NULL; 594 } 595 } 596 /* external plug in function */ 597 extern "C" void * 598 QCameraHAL_openCameraHardware(int cameraId, int mode) 599 { 600 LOGI("QCameraHAL_openCameraHardware: E"); 601 return (void *) QCameraHardwareInterface::createInstance(cameraId, mode); 602 } 603 604 #if 0 605 bool QCameraHardwareInterface::useOverlay(void) 606 { 607 LOGI("useOverlay: E"); 608 mUseOverlay = TRUE; 609 LOGI("useOverlay: X"); 610 return mUseOverlay; 611 } 612 #endif 613 614 bool QCameraHardwareInterface::isPreviewRunning() { 615 LOGI("isPreviewRunning: E"); 616 bool ret = false; 617 LOGI("isPreviewRunning: camera state:%d", mCameraState); 618 619 if((mCameraState == CAMERA_STATE_PREVIEW) || 620 (mCameraState == CAMERA_STATE_PREVIEW_START_CMD_SENT) || 621 (mCameraState == CAMERA_STATE_RECORD) || 622 (mCameraState == CAMERA_STATE_RECORD_START_CMD_SENT) || 623 (mCameraState == CAMERA_STATE_ZSL) || 624 (mCameraState == CAMERA_STATE_ZSL_START_CMD_SENT)){ 625 return true; 626 } 627 LOGI("isPreviewRunning: X"); 628 return ret; 629 } 630 631 bool QCameraHardwareInterface::isRecordingRunning() { 632 LOGE("isRecordingRunning: E"); 633 bool ret = false; 634 if(QCAMERA_HAL_RECORDING_STARTED == mPreviewState) 635 ret = true; 636 //if((mCameraState == CAMERA_STATE_RECORD) || 637 // (mCameraState == CAMERA_STATE_RECORD_START_CMD_SENT)) { 638 // return true; 639 //} 640 LOGE("isRecordingRunning: X"); 641 return ret; 642 } 643 644 bool QCameraHardwareInterface::isSnapshotRunning() { 645 LOGE("isSnapshotRunning: E"); 646 bool ret = false; 647 //if((mCameraState == CAMERA_STATE_SNAP_CMD_ACKED) || 648 // (mCameraState == CAMERA_STATE_SNAP_START_CMD_SENT)) { 649 // return true; 650 //} 651 switch(mPreviewState) { 652 case QCAMERA_HAL_PREVIEW_STOPPED: 653 case QCAMERA_HAL_PREVIEW_START: 654 case QCAMERA_HAL_PREVIEW_STARTED: 655 case QCAMERA_HAL_RECORDING_STARTED: 656 default: 657 break; 658 case QCAMERA_HAL_TAKE_PICTURE: 659 ret = true; 660 break; 661 } 662 LOGI("isSnapshotRunning: X"); 663 return ret; 664 } 665 666 bool QCameraHardwareInterface::isZSLMode() { 667 return (myMode & CAMERA_ZSL_MODE); 668 } 669 670 int QCameraHardwareInterface::getHDRMode() { 671 return mHdrMode; 672 } 673 674 void QCameraHardwareInterface::debugShowPreviewFPS() const 675 { 676 static int mFrameCount; 677 static int mLastFrameCount = 0; 678 static nsecs_t mLastFpsTime = 0; 679 static float mFps = 0; 680 mFrameCount++; 681 nsecs_t now = systemTime(); 682 nsecs_t diff = now - mLastFpsTime; 683 if (diff > ms2ns(250)) { 684 mFps = ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff; 685 LOGI("Preview Frames Per Second: %.4f", mFps); 686 mLastFpsTime = now; 687 mLastFrameCount = mFrameCount; 688 } 689 } 690 691 void QCameraHardwareInterface:: 692 processPreviewChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *app_cb) { 693 LOGI("processPreviewChannelEvent: E"); 694 switch(channelEvent) { 695 case MM_CAMERA_CH_EVT_STREAMING_ON: 696 mCameraState = 697 isZSLMode() ? CAMERA_STATE_ZSL : CAMERA_STATE_PREVIEW; 698 break; 699 case MM_CAMERA_CH_EVT_STREAMING_OFF: 700 mCameraState = CAMERA_STATE_READY; 701 break; 702 case MM_CAMERA_CH_EVT_DATA_DELIVERY_DONE: 703 break; 704 default: 705 break; 706 } 707 LOGI("processPreviewChannelEvent: X"); 708 return; 709 } 710 711 void QCameraHardwareInterface::processRecordChannelEvent( 712 mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *app_cb) { 713 LOGI("processRecordChannelEvent: E"); 714 switch(channelEvent) { 715 case MM_CAMERA_CH_EVT_STREAMING_ON: 716 mCameraState = CAMERA_STATE_RECORD; 717 break; 718 case MM_CAMERA_CH_EVT_STREAMING_OFF: 719 mCameraState = CAMERA_STATE_PREVIEW; 720 break; 721 case MM_CAMERA_CH_EVT_DATA_DELIVERY_DONE: 722 break; 723 default: 724 break; 725 } 726 LOGI("processRecordChannelEvent: X"); 727 return; 728 } 729 730 void QCameraHardwareInterface:: 731 processSnapshotChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *app_cb) { 732 LOGI("processSnapshotChannelEvent: E evt=%d state=%d", channelEvent, 733 mCameraState); 734 switch(channelEvent) { 735 case MM_CAMERA_CH_EVT_STREAMING_ON: 736 if (!mFullLiveshotEnabled) { 737 mCameraState = 738 isZSLMode() ? CAMERA_STATE_ZSL : CAMERA_STATE_SNAP_CMD_ACKED; 739 } 740 break; 741 case MM_CAMERA_CH_EVT_STREAMING_OFF: 742 if (!mFullLiveshotEnabled) { 743 mCameraState = CAMERA_STATE_READY; 744 } 745 break; 746 case MM_CAMERA_CH_EVT_DATA_DELIVERY_DONE: 747 break; 748 case MM_CAMERA_CH_EVT_DATA_REQUEST_MORE: 749 if (isZSLMode()) { 750 /* ZSL Mode: In ZSL Burst Mode, users may request for number of 751 snapshots larger than internal size of ZSL queue. So we'll need 752 process the remaining frames as they become available. 753 In such case, we'll get this event */ 754 if(NULL != mStreamSnap) 755 mStreamSnap->takePictureZSL(); 756 } 757 break; 758 default: 759 break; 760 } 761 LOGI("processSnapshotChannelEvent: X"); 762 return; 763 } 764 765 void QCameraHardwareInterface::processChannelEvent( 766 mm_camera_ch_event_t *event, app_notify_cb_t *app_cb) 767 { 768 LOGI("processChannelEvent: E"); 769 Mutex::Autolock lock(mLock); 770 switch(event->ch) { 771 case MM_CAMERA_CH_PREVIEW: 772 processPreviewChannelEvent(event->evt, app_cb); 773 break; 774 case MM_CAMERA_CH_VIDEO: 775 processRecordChannelEvent(event->evt, app_cb); 776 break; 777 case MM_CAMERA_CH_SNAPSHOT: 778 processSnapshotChannelEvent(event->evt, app_cb); 779 break; 780 default: 781 break; 782 } 783 LOGI("processChannelEvent: X"); 784 return; 785 } 786 787 void QCameraHardwareInterface::processCtrlEvent(mm_camera_ctrl_event_t *event, app_notify_cb_t *app_cb) 788 { 789 LOGI("processCtrlEvent: %d, E",event->evt); 790 Mutex::Autolock lock(mLock); 791 switch(event->evt) 792 { 793 case MM_CAMERA_CTRL_EVT_ZOOM_DONE: 794 zoomEvent(&event->status, app_cb); 795 break; 796 case MM_CAMERA_CTRL_EVT_AUTO_FOCUS_DONE: 797 autoFocusEvent(&event->status, app_cb); 798 break; 799 case MM_CAMERA_CTRL_EVT_PREP_SNAPSHOT: 800 break; 801 case MM_CAMERA_CTRL_EVT_WDN_DONE: 802 wdenoiseEvent(event->status, (void *)(event->cookie)); 803 break; 804 case MM_CAMERA_CTRL_EVT_ERROR: 805 app_cb->notifyCb = mNotifyCb; 806 app_cb->argm_notify.msg_type = CAMERA_MSG_ERROR; 807 app_cb->argm_notify.ext1 = CAMERA_ERROR_UNKNOWN; 808 app_cb->argm_notify.cookie = mCallbackCookie; 809 break; 810 default: 811 break; 812 } 813 LOGI("processCtrlEvent: X"); 814 return; 815 } 816 817 void QCameraHardwareInterface::processStatsEvent( 818 mm_camera_stats_event_t *event, app_notify_cb_t *app_cb) 819 { 820 LOGI("processStatsEvent: E"); 821 if (!isPreviewRunning( )) { 822 LOGE("preview is not running"); 823 return; 824 } 825 826 switch (event->event_id) { 827 case MM_CAMERA_STATS_EVT_HISTO: 828 { 829 LOGE("HAL process Histo: mMsgEnabled=0x%x, mStatsOn=%d, mSendData=%d, mDataCb=%p ", 830 (mMsgEnabled & CAMERA_MSG_STATS_DATA), mStatsOn, mSendData, mDataCb); 831 int msgEnabled = mMsgEnabled; 832 /*get stats buffer based on index*/ 833 camera_preview_histogram_info* hist_info = 834 (camera_preview_histogram_info*) mHistServer.camera_memory[event->e.stats_histo.index]->data; 835 836 if(mStatsOn == QCAMERA_PARM_ENABLE && mSendData && 837 mDataCb && (msgEnabled & CAMERA_MSG_STATS_DATA) ) { 838 uint32_t *dest; 839 mSendData = false; 840 mCurrentHisto = (mCurrentHisto + 1) % 3; 841 // The first element of the array will contain the maximum hist value provided by driver. 842 *(uint32_t *)((unsigned int)(mStatsMapped[mCurrentHisto]->data)) = hist_info->max_value; 843 memcpy((uint32_t *)((unsigned int)mStatsMapped[mCurrentHisto]->data + sizeof(int32_t)), 844 (uint32_t *)hist_info->buffer,(sizeof(int32_t) * 256)); 845 846 app_cb->dataCb = mDataCb; 847 app_cb->argm_data_cb.msg_type = CAMERA_MSG_STATS_DATA; 848 app_cb->argm_data_cb.data = mStatsMapped[mCurrentHisto]; 849 app_cb->argm_data_cb.index = 0; 850 app_cb->argm_data_cb.metadata = NULL; 851 app_cb->argm_data_cb.cookie = mCallbackCookie; 852 } 853 break; 854 } 855 default: 856 break; 857 } 858 LOGV("receiveCameraStats X"); 859 } 860 861 void QCameraHardwareInterface::processInfoEvent( 862 mm_camera_info_event_t *event, app_notify_cb_t *app_cb) { 863 LOGI("processInfoEvent: %d, E",event->event_id); 864 //Mutex::Autolock lock(eventLock); 865 switch(event->event_id) 866 { 867 case MM_CAMERA_INFO_EVT_ROI: 868 roiEvent(event->e.roi, app_cb); 869 break; 870 default: 871 break; 872 } 873 LOGI("processInfoEvent: X"); 874 return; 875 } 876 877 void QCameraHardwareInterface::processEvent(mm_camera_event_t *event) 878 { 879 app_notify_cb_t app_cb; 880 LOGE("processEvent: type :%d E",event->event_type); 881 if(mPreviewState == QCAMERA_HAL_PREVIEW_STOPPED){ 882 LOGE("Stop recording issued. Return from process Event"); 883 return; 884 } 885 memset(&app_cb, 0, sizeof(app_notify_cb_t)); 886 switch(event->event_type) 887 { 888 case MM_CAMERA_EVT_TYPE_CH: 889 processChannelEvent(&event->e.ch, &app_cb); 890 break; 891 case MM_CAMERA_EVT_TYPE_CTRL: 892 processCtrlEvent(&event->e.ctrl, &app_cb); 893 break; 894 case MM_CAMERA_EVT_TYPE_STATS: 895 processStatsEvent(&event->e.stats, &app_cb); 896 break; 897 case MM_CAMERA_EVT_TYPE_INFO: 898 processInfoEvent(&event->e.info, &app_cb); 899 break; 900 default: 901 break; 902 } 903 LOGE(" App_cb Notify %p, datacb=%p", app_cb.notifyCb, app_cb.dataCb); 904 if (app_cb.notifyCb) { 905 app_cb.notifyCb(app_cb.argm_notify.msg_type, 906 app_cb.argm_notify.ext1, app_cb.argm_notify.ext2, 907 app_cb.argm_notify.cookie); 908 } 909 if (app_cb.dataCb) { 910 app_cb.dataCb(app_cb.argm_data_cb.msg_type, 911 app_cb.argm_data_cb.data, app_cb.argm_data_cb.index, 912 app_cb.argm_data_cb.metadata, app_cb.argm_data_cb.cookie); 913 } 914 LOGI("processEvent: X"); 915 return; 916 } 917 918 bool QCameraHardwareInterface::preview_parm_config (cam_ctrl_dimension_t* dim, 919 CameraParameters& parm) 920 { 921 LOGI("preview_parm_config: E"); 922 bool matching = true; 923 int display_width = 0; /* width of display */ 924 int display_height = 0; /* height of display */ 925 uint16_t video_width = 0; /* width of the video */ 926 uint16_t video_height = 0; /* height of the video */ 927 928 /* First check if the preview resolution is the same, if not, change it*/ 929 parm.getPreviewSize(&display_width, &display_height); 930 if (display_width && display_height) { 931 matching = (display_width == dim->display_width) && 932 (display_height == dim->display_height); 933 934 if (!matching) { 935 dim->display_width = display_width; 936 dim->display_height = display_height; 937 } 938 } 939 else 940 matching = false; 941 942 cam_format_t value = getPreviewFormat(); 943 944 if(value != NOT_FOUND && value != dim->prev_format ) { 945 //Setting to Parameter requested by the Upper layer 946 dim->prev_format = value; 947 }else{ 948 //Setting to default Format. 949 dim->prev_format = CAMERA_YUV_420_NV21; 950 } 951 mPreviewFormat = dim->prev_format; 952 953 dim->prev_padding_format = getPreviewPadding( ); 954 955 dim->enc_format = CAMERA_YUV_420_NV12; 956 dim->orig_video_width = mDimension.orig_video_width; 957 dim->orig_video_height = mDimension.orig_video_height; 958 dim->video_width = mDimension.video_width; 959 dim->video_height = mDimension.video_height; 960 dim->video_chroma_width = mDimension.video_width; 961 dim->video_chroma_height = mDimension.video_height; 962 /* Reset the Main image and thumbnail formats here, 963 * since they might have been changed when video size 964 * livesnapshot was taken. */ 965 if (mSnapshotFormat == 1) 966 dim->main_img_format = CAMERA_YUV_422_NV61; 967 else 968 dim->main_img_format = CAMERA_YUV_420_NV21; 969 dim->thumb_format = CAMERA_YUV_420_NV21; 970 LOGI("preview_parm_config: X"); 971 return matching; 972 } 973 974 status_t QCameraHardwareInterface::startPreview() 975 { 976 status_t retVal = NO_ERROR; 977 978 LOGE("%s: mPreviewState =%d", __func__, mPreviewState); 979 Mutex::Autolock lock(mLock); 980 switch(mPreviewState) { 981 case QCAMERA_HAL_PREVIEW_STOPPED: 982 case QCAMERA_HAL_TAKE_PICTURE: 983 mPreviewState = QCAMERA_HAL_PREVIEW_START; 984 LOGE("%s: HAL::startPreview begin", __func__); 985 986 if(QCAMERA_HAL_PREVIEW_START == mPreviewState && 987 (mPreviewWindow || isNoDisplayMode())) { 988 LOGE("%s: start preview now", __func__); 989 retVal = startPreview2(); 990 if(retVal == NO_ERROR) 991 mPreviewState = QCAMERA_HAL_PREVIEW_STARTED; 992 } else { 993 LOGE("%s: received startPreview, but preview window = null", __func__); 994 } 995 break; 996 case QCAMERA_HAL_PREVIEW_START: 997 case QCAMERA_HAL_PREVIEW_STARTED: 998 break; 999 case QCAMERA_HAL_RECORDING_STARTED: 1000 LOGE("%s: cannot start preview in recording state", __func__); 1001 break; 1002 default: 1003 LOGE("%s: unknow state %d received", __func__, mPreviewState); 1004 retVal = UNKNOWN_ERROR; 1005 break; 1006 } 1007 return retVal; 1008 } 1009 1010 status_t QCameraHardwareInterface::startPreview2() 1011 { 1012 LOGI("startPreview2: E"); 1013 status_t ret = NO_ERROR; 1014 1015 cam_ctrl_dimension_t dim; 1016 mm_camera_dimension_t maxDim; 1017 bool initPreview = false; 1018 1019 if (mPreviewState == QCAMERA_HAL_PREVIEW_STARTED) { //isPreviewRunning()){ 1020 LOGE("%s:Preview already started mCameraState = %d!", __func__, mCameraState); 1021 LOGE("%s: X", __func__); 1022 return NO_ERROR; 1023 } 1024 1025 /* get existing preview information, by qury mm_camera*/ 1026 memset(&dim, 0, sizeof(cam_ctrl_dimension_t)); 1027 ret = cam_config_get_parm(mCameraId, MM_CAMERA_PARM_DIMENSION,&dim); 1028 1029 if (MM_CAMERA_OK != ret) { 1030 LOGE("%s: error - can't get preview dimension!", __func__); 1031 LOGE("%s: X", __func__); 1032 return BAD_VALUE; 1033 } 1034 1035 /* config the parmeters and see if we need to re-init the stream*/ 1036 initPreview = preview_parm_config (&dim, mParameters); 1037 1038 if (mRecordingHint && mFullLiveshotEnabled) { 1039 #if 0 1040 /* Camcorder mode and Full resolution liveshot enabled 1041 * TBD lookup table for correct aspect ratio matching size */ 1042 memset(&maxDim, 0, sizeof(mm_camera_dimension_t)); 1043 getMaxPictureDimension(&maxDim); 1044 if (!maxDim.width || !maxDim.height) { 1045 maxDim.width = DEFAULT_LIVESHOT_WIDTH; 1046 maxDim.height = DEFAULT_LIVESHOT_HEIGHT; 1047 } 1048 /* TODO Remove this hack after adding code to get live shot dimension */ 1049 if (!mCameraId) { 1050 maxDim.width = DEFAULT_LIVESHOT_WIDTH; 1051 maxDim.height = DEFAULT_LIVESHOT_HEIGHT; 1052 } 1053 dim.picture_width = maxDim.width; 1054 dim.picture_height = maxDim.height; 1055 mParameters.setPictureSize(dim.picture_width, dim.picture_height); 1056 LOGI("%s Setting Liveshot dimension as %d x %d", __func__, 1057 maxDim.width, maxDim.height); 1058 #endif 1059 int mPictureWidth, mPictureHeight; 1060 bool matching; 1061 /* First check if the picture resolution is the same, if not, change it*/ 1062 getPictureSize(&mPictureWidth, &mPictureHeight); 1063 1064 matching = (mPictureWidth == dim.picture_width) && 1065 (mPictureHeight == dim.picture_height); 1066 1067 if (!matching) { 1068 dim.picture_width = mPictureWidth; 1069 dim.picture_height = mPictureHeight; 1070 dim.ui_thumbnail_height = dim.display_height; 1071 dim.ui_thumbnail_width = dim.display_width; 1072 } 1073 LOGE("%s: Fullsize Liveshaot Picture size to set: %d x %d", __func__, 1074 dim.picture_width, dim.picture_height); 1075 mParameters.setPictureSize(dim.picture_width, dim.picture_height); 1076 } 1077 1078 ret = cam_config_set_parm(mCameraId, MM_CAMERA_PARM_DIMENSION,&dim); 1079 if (MM_CAMERA_OK != ret) { 1080 LOGE("%s X: error - can't config preview parms!", __func__); 1081 return BAD_VALUE; 1082 } 1083 1084 mStreamDisplay->setMode(myMode & CAMERA_ZSL_MODE); 1085 mStreamSnap->setMode(myMode & CAMERA_ZSL_MODE); 1086 mStreamRecord->setMode(myMode & CAMERA_ZSL_MODE); 1087 LOGE("%s: myMode = %d", __func__, myMode); 1088 1089 LOGE("%s: setPreviewWindow", __func__); 1090 mStreamDisplay->setPreviewWindow(mPreviewWindow); 1091 1092 if(isZSLMode()) { 1093 /* Start preview streaming */ 1094 ret = mStreamDisplay->start(); 1095 if (MM_CAMERA_OK != ret){ 1096 LOGE("%s: X -error - can't start nonZSL stream!", __func__); 1097 return BAD_VALUE; 1098 } 1099 1100 /* Start ZSL stream */ 1101 ret = mStreamSnap->start(); 1102 if (MM_CAMERA_OK != ret){ 1103 LOGE("%s: error - can't start Snapshot stream!", __func__); 1104 mStreamDisplay->stop(); 1105 return BAD_VALUE; 1106 } 1107 }else{ 1108 ret = mStreamDisplay->start(); 1109 } 1110 1111 /*call QCameraStream_noneZSL::start() */ 1112 if (MM_CAMERA_OK != ret){ 1113 LOGE("%s: X error - can't start stream!", __func__); 1114 return BAD_VALUE; 1115 } 1116 if(MM_CAMERA_OK == ret) 1117 mCameraState = CAMERA_STATE_PREVIEW_START_CMD_SENT; 1118 else 1119 mCameraState = CAMERA_STATE_ERROR; 1120 1121 if(mPostPreviewHeap != NULL) { 1122 mPostPreviewHeap.clear(); 1123 mPostPreviewHeap = NULL; 1124 } 1125 1126 LOGI("startPreview: X"); 1127 return ret; 1128 } 1129 1130 void QCameraHardwareInterface::stopPreview() 1131 { 1132 LOGI("%s: stopPreview: E", __func__); 1133 Mutex::Autolock lock(mLock); 1134 mm_camera_util_profile("HAL: stopPreview(): E"); 1135 mFaceDetectOn = false; 1136 1137 // reset recording hint to the value passed from Apps 1138 const char * str = mParameters.get(CameraParameters::KEY_RECORDING_HINT); 1139 if((str != NULL) && !strcmp(str, "true")){ 1140 mRecordingHint = TRUE; 1141 } else { 1142 mRecordingHint = FALSE; 1143 } 1144 1145 switch(mPreviewState) { 1146 case QCAMERA_HAL_PREVIEW_START: 1147 //mPreviewWindow = NULL; 1148 mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED; 1149 break; 1150 case QCAMERA_HAL_PREVIEW_STARTED: 1151 stopPreviewInternal(); 1152 mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED; 1153 break; 1154 case QCAMERA_HAL_RECORDING_STARTED: 1155 stopRecordingInternal(); 1156 stopPreviewInternal(); 1157 mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED; 1158 break; 1159 case QCAMERA_HAL_TAKE_PICTURE: 1160 case QCAMERA_HAL_PREVIEW_STOPPED: 1161 default: 1162 break; 1163 } 1164 LOGI("stopPreview: X, mPreviewState = %d", mPreviewState); 1165 } 1166 1167 #if 0 //mzhu 1168 void QCameraHardwareInterface::stopPreviewZSL() 1169 { 1170 LOGI("stopPreviewZSL: E"); 1171 1172 if(!mStreamDisplay || !mStreamSnap) { 1173 LOGE("mStreamDisplay/mStreamSnap is null"); 1174 return; 1175 } 1176 LOGI("stopPreview: X, mPreviewState = %d", mPreviewState); 1177 } 1178 #endif 1179 void QCameraHardwareInterface::stopPreviewInternal() 1180 { 1181 LOGI("stopPreviewInternal: E"); 1182 status_t ret = NO_ERROR; 1183 1184 if(!mStreamDisplay) { 1185 LOGE("mStreamDisplay is null"); 1186 return; 1187 } 1188 1189 if(isZSLMode()) { 1190 /* take care snapshot object for ZSL mode */ 1191 mStreamSnap->stop(); 1192 } 1193 mStreamDisplay->stop(); 1194 1195 mCameraState = CAMERA_STATE_PREVIEW_STOP_CMD_SENT; 1196 LOGI("stopPreviewInternal: X"); 1197 } 1198 1199 int QCameraHardwareInterface::previewEnabled() 1200 { 1201 LOGI("previewEnabled: E"); 1202 Mutex::Autolock lock(mLock); 1203 LOGE("%s: mCameraState = %d", __func__, mCameraState); 1204 switch(mPreviewState) { 1205 case QCAMERA_HAL_PREVIEW_STOPPED: 1206 case QCAMERA_HAL_TAKE_PICTURE: 1207 default: 1208 return false; 1209 break; 1210 case QCAMERA_HAL_PREVIEW_START: 1211 case QCAMERA_HAL_PREVIEW_STARTED: 1212 case QCAMERA_HAL_RECORDING_STARTED: 1213 return true; 1214 break; 1215 } 1216 return false; 1217 } 1218 1219 status_t QCameraHardwareInterface::startRecording() 1220 { 1221 LOGI("startRecording: E"); 1222 status_t ret = NO_ERROR; 1223 Mutex::Autolock lock(mLock); 1224 1225 switch(mPreviewState) { 1226 case QCAMERA_HAL_PREVIEW_STOPPED: 1227 LOGE("%s: preview has not been started", __func__); 1228 ret = UNKNOWN_ERROR; 1229 break; 1230 case QCAMERA_HAL_PREVIEW_START: 1231 LOGE("%s: no preview native window", __func__); 1232 ret = UNKNOWN_ERROR; 1233 break; 1234 case QCAMERA_HAL_PREVIEW_STARTED: 1235 if (mRecordingHint == FALSE) { 1236 LOGE("%s: start recording when hint is false, stop preview first", __func__); 1237 stopPreviewInternal(); 1238 mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED; 1239 1240 // Set recording hint to TRUE 1241 mRecordingHint = TRUE; 1242 setRecordingHintValue(mRecordingHint); 1243 1244 // start preview again 1245 mPreviewState = QCAMERA_HAL_PREVIEW_START; 1246 if (startPreview2() == NO_ERROR) 1247 mPreviewState = QCAMERA_HAL_PREVIEW_STARTED; 1248 } 1249 ret = mStreamRecord->start(); 1250 if (MM_CAMERA_OK != ret){ 1251 LOGE("%s: error - mStreamRecord->start!", __func__); 1252 ret = BAD_VALUE; 1253 break; 1254 } 1255 if(MM_CAMERA_OK == ret) 1256 mCameraState = CAMERA_STATE_RECORD_START_CMD_SENT; 1257 else 1258 mCameraState = CAMERA_STATE_ERROR; 1259 mPreviewState = QCAMERA_HAL_RECORDING_STARTED; 1260 break; 1261 case QCAMERA_HAL_RECORDING_STARTED: 1262 LOGE("%s: ", __func__); 1263 break; 1264 case QCAMERA_HAL_TAKE_PICTURE: 1265 default: 1266 ret = BAD_VALUE; 1267 break; 1268 } 1269 LOGI("startRecording: X"); 1270 return ret; 1271 } 1272 1273 void QCameraHardwareInterface::stopRecording() 1274 { 1275 LOGI("stopRecording: E"); 1276 Mutex::Autolock lock(mLock); 1277 switch(mPreviewState) { 1278 case QCAMERA_HAL_PREVIEW_STOPPED: 1279 case QCAMERA_HAL_PREVIEW_START: 1280 case QCAMERA_HAL_PREVIEW_STARTED: 1281 break; 1282 case QCAMERA_HAL_RECORDING_STARTED: 1283 stopRecordingInternal(); 1284 mPreviewState = QCAMERA_HAL_PREVIEW_STARTED; 1285 break; 1286 case QCAMERA_HAL_TAKE_PICTURE: 1287 default: 1288 break; 1289 } 1290 LOGI("stopRecording: X"); 1291 1292 } 1293 void QCameraHardwareInterface::stopRecordingInternal() 1294 { 1295 LOGI("stopRecordingInternal: E"); 1296 status_t ret = NO_ERROR; 1297 1298 if(!mStreamRecord) { 1299 LOGE("mStreamRecord is null"); 1300 return; 1301 } 1302 1303 /* 1304 * call QCameraStream_record::stop() 1305 * Unregister Callback, action stop 1306 */ 1307 mStreamRecord->stop(); 1308 mCameraState = CAMERA_STATE_PREVIEW; //TODO : Apurva : Hacked for 2nd time Recording 1309 mPreviewState = QCAMERA_HAL_PREVIEW_STARTED; 1310 LOGI("stopRecordingInternal: X"); 1311 return; 1312 } 1313 1314 int QCameraHardwareInterface::recordingEnabled() 1315 { 1316 int ret = 0; 1317 Mutex::Autolock lock(mLock); 1318 LOGV("%s: E", __func__); 1319 switch(mPreviewState) { 1320 case QCAMERA_HAL_PREVIEW_STOPPED: 1321 case QCAMERA_HAL_PREVIEW_START: 1322 case QCAMERA_HAL_PREVIEW_STARTED: 1323 break; 1324 case QCAMERA_HAL_RECORDING_STARTED: 1325 ret = 1; 1326 break; 1327 case QCAMERA_HAL_TAKE_PICTURE: 1328 default: 1329 break; 1330 } 1331 LOGV("%s: X, ret = %d", __func__, ret); 1332 return ret; //isRecordingRunning(); 1333 } 1334 1335 /** 1336 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME. 1337 */ 1338 void QCameraHardwareInterface::releaseRecordingFrame(const void *opaque) 1339 { 1340 LOGV("%s : BEGIN",__func__); 1341 if(mStreamRecord == NULL) { 1342 LOGE("Record stream Not Initialized"); 1343 return; 1344 } 1345 mStreamRecord->releaseRecordingFrame(opaque); 1346 LOGV("%s : END",__func__); 1347 return; 1348 } 1349 1350 status_t QCameraHardwareInterface::autoFocusEvent(cam_ctrl_status_t *status, app_notify_cb_t *app_cb) 1351 { 1352 LOGE("autoFocusEvent: E"); 1353 int ret = NO_ERROR; 1354 /************************************************************ 1355 BEGIN MUTEX CODE 1356 *************************************************************/ 1357 1358 LOGE("%s:%d: Trying to acquire AF bit lock",__func__,__LINE__); 1359 mAutofocusLock.lock(); 1360 LOGE("%s:%d: Acquired AF bit lock",__func__,__LINE__); 1361 1362 if(mAutoFocusRunning==false) { 1363 LOGE("%s:AF not running, discarding stale event",__func__); 1364 mAutofocusLock.unlock(); 1365 return ret; 1366 } 1367 1368 mAutoFocusRunning = false; 1369 mAutofocusLock.unlock(); 1370 1371 /************************************************************ 1372 END MUTEX CODE 1373 *************************************************************/ 1374 if(status==NULL) { 1375 LOGE("%s:NULL ptr received for status",__func__); 1376 return BAD_VALUE; 1377 } 1378 1379 /* update focus distances after autofocus is done */ 1380 if(updateFocusDistances() != NO_ERROR) { 1381 LOGE("%s: updateFocusDistances failed for %d", __FUNCTION__, mFocusMode); 1382 } 1383 1384 /*(Do?) we need to make sure that the call back is the 1385 last possible step in the execution flow since the same 1386 context might be used if a fail triggers another round 1387 of AF then the mAutoFocusRunning flag and other state 1388 variables' validity will be under question*/ 1389 1390 if (mNotifyCb && ( mMsgEnabled & CAMERA_MSG_FOCUS)){ 1391 LOGE("%s:Issuing callback to service",__func__); 1392 1393 /* "Accepted" status is not appropriate it should be used for 1394 initial cmd, event reporting should only give use SUCCESS/FAIL 1395 */ 1396 1397 app_cb->notifyCb = mNotifyCb; 1398 app_cb->argm_notify.msg_type = CAMERA_MSG_FOCUS; 1399 app_cb->argm_notify.ext2 = 0; 1400 app_cb->argm_notify.cookie = mCallbackCookie; 1401 1402 LOGE("Auto foucs state =%d", *status); 1403 if(*status==CAM_CTRL_SUCCESS) { 1404 app_cb->argm_notify.ext1 = true; 1405 } 1406 else if(*status==CAM_CTRL_FAILED){ 1407 app_cb->argm_notify.ext1 = false; 1408 } 1409 else{ 1410 app_cb->notifyCb = NULL; 1411 LOGE("%s:Unknown AF status (%d) received",__func__,*status); 1412 } 1413 1414 }/*(mNotifyCb && ( mMsgEnabled & CAMERA_MSG_FOCUS))*/ 1415 else{ 1416 LOGE("%s:Call back not enabled",__func__); 1417 } 1418 1419 LOGE("autoFocusEvent: X"); 1420 return ret; 1421 1422 } 1423 1424 status_t QCameraHardwareInterface::cancelPicture() 1425 { 1426 LOGI("cancelPicture: E"); 1427 status_t ret = MM_CAMERA_OK; 1428 Mutex::Autolock lock(mLock); 1429 1430 switch(mPreviewState) { 1431 case QCAMERA_HAL_PREVIEW_STOPPED: 1432 case QCAMERA_HAL_PREVIEW_START: 1433 case QCAMERA_HAL_PREVIEW_STARTED: 1434 case QCAMERA_HAL_RECORDING_STARTED: 1435 default: 1436 break; 1437 case QCAMERA_HAL_TAKE_PICTURE: 1438 ret = cancelPictureInternal(); 1439 break; 1440 } 1441 LOGI("cancelPicture: X"); 1442 return ret; 1443 } 1444 1445 status_t QCameraHardwareInterface::cancelPictureInternal() 1446 { 1447 LOGI("cancelPictureInternal: E"); 1448 status_t ret = MM_CAMERA_OK; 1449 if(mCameraState != CAMERA_STATE_READY) { 1450 if(mStreamSnap) { 1451 mStreamSnap->stop(); 1452 mCameraState = CAMERA_STATE_SNAP_STOP_CMD_SENT; 1453 } 1454 } else { 1455 LOGE("%s: Cannot process cancel picture as snapshot is already done",__func__); 1456 } 1457 LOGI("cancelPictureInternal: X"); 1458 return ret; 1459 } 1460 1461 void QCameraHardwareInterface::pausePreviewForSnapshot() 1462 { 1463 stopPreviewInternal( ); 1464 } 1465 status_t QCameraHardwareInterface::resumePreviewAfterSnapshot() 1466 { 1467 status_t ret = NO_ERROR; 1468 ret = mStreamDisplay->start(); 1469 return ret; 1470 } 1471 1472 void liveshot_callback(mm_camera_ch_data_buf_t *recvd_frame, 1473 void *user_data) 1474 { 1475 QCameraHardwareInterface *pme = (QCameraHardwareInterface *)user_data; 1476 cam_ctrl_dimension_t dim; 1477 int mJpegMaxSize; 1478 status_t ret; 1479 LOGE("%s: E", __func__); 1480 1481 1482 mm_camera_ch_data_buf_t* frame = 1483 (mm_camera_ch_data_buf_t *)malloc(sizeof(mm_camera_ch_data_buf_t)); 1484 if (frame == NULL) { 1485 LOGE("%s: Error allocating memory to save received_frame structure.", __func__); 1486 cam_evt_buf_done(pme->mCameraId, recvd_frame); 1487 return ; 1488 } 1489 memcpy(frame, recvd_frame, sizeof(mm_camera_ch_data_buf_t)); 1490 1491 LOGE("<DEBUG> Liveshot buffer idx:%d",frame->video.video.idx); 1492 memset(&dim, 0, sizeof(cam_ctrl_dimension_t)); 1493 ret = cam_config_get_parm(pme->mCameraId, MM_CAMERA_PARM_DIMENSION, &dim); 1494 if (MM_CAMERA_OK != ret) { 1495 LOGE("%s: error - can't get dimension!", __func__); 1496 LOGE("%s: X", __func__); 1497 } 1498 1499 #if 1 1500 LOGE("Live Snapshot Enabled"); 1501 frame->snapshot.main.frame = frame->video.video.frame; 1502 frame->snapshot.main.idx = frame->video.video.idx; 1503 frame->snapshot.thumbnail.frame = frame->video.video.frame; 1504 frame->snapshot.thumbnail.idx = frame->video.video.idx; 1505 1506 dim.picture_width = pme->mDimension.video_width; 1507 dim.picture_height = pme->mDimension.video_height; 1508 dim.ui_thumbnail_width = pme->mDimension.video_width; 1509 dim.ui_thumbnail_height = pme->mDimension.video_height; 1510 dim.main_img_format = pme->mDimension.enc_format; 1511 dim.thumb_format = pme->mDimension.enc_format; 1512 1513 mJpegMaxSize = pme->mDimension.video_width * pme->mDimension.video_width * 1.5; 1514 1515 LOGE("Picture w = %d , h = %d, size = %d",dim.picture_width,dim.picture_height,mJpegMaxSize); 1516 if (pme->mStreamLiveSnap){ 1517 LOGE("%s:Deleting old Snapshot stream instance",__func__); 1518 QCameraStream_Snapshot::deleteInstance (pme->mStreamLiveSnap); 1519 pme->mStreamLiveSnap = NULL; 1520 } 1521 1522 pme->mStreamLiveSnap = (QCameraStream_Snapshot*)QCameraStream_Snapshot::createInstance(pme->mCameraId, 1523 pme->myMode); 1524 1525 if (!pme->mStreamLiveSnap) { 1526 LOGE("%s: error - can't creat snapshot stream!", __func__); 1527 return ; 1528 } 1529 pme->mStreamLiveSnap->setModeLiveSnapshot(true); 1530 pme->mStreamLiveSnap->setHALCameraControl(pme); 1531 pme->mStreamLiveSnap->initSnapshotBuffers(&dim,1); 1532 LOGE("Calling live shot"); 1533 1534 1535 ((QCameraStream_Snapshot*)(pme->mStreamLiveSnap))->takePictureLiveshot(frame,&dim,mJpegMaxSize); 1536 1537 #else 1538 1539 1540 1541 1542 if(MM_CAMERA_OK != cam_evt_buf_done(pme->mCameraId,frame )) { 1543 LOGE(" BUF DONE FAILED"); 1544 } 1545 #endif 1546 LOGE("%s: X", __func__); 1547 1548 } 1549 1550 status_t QCameraHardwareInterface::takePicture() 1551 { 1552 LOGI("takePicture: E"); 1553 status_t ret = MM_CAMERA_OK; 1554 Mutex::Autolock lock(mLock); 1555 1556 mStreamSnap->resetSnapshotCounters( ); 1557 switch(mPreviewState) { 1558 case QCAMERA_HAL_PREVIEW_STARTED: 1559 mStreamSnap->setFullSizeLiveshot(false); 1560 if (isZSLMode()) { 1561 if (mStreamSnap != NULL) { 1562 pausePreviewForZSL(); 1563 ret = mStreamSnap->takePictureZSL(); 1564 if (ret != MM_CAMERA_OK) { 1565 LOGE("%s: Error taking ZSL snapshot!", __func__); 1566 ret = BAD_VALUE; 1567 } 1568 } 1569 else { 1570 LOGE("%s: ZSL stream not active! Failure!!", __func__); 1571 ret = BAD_VALUE; 1572 } 1573 return ret; 1574 } 1575 1576 /*prepare snapshot, e.g LED*/ 1577 takePicturePrepareHardware( ); 1578 /* There's an issue where we have a glimpse of corrupted data between 1579 a time we stop a preview and display the postview. It happens because 1580 when we call stopPreview we deallocate the preview buffers hence overlay 1581 displays garbage value till we enqueue postview buffer to be displayed. 1582 Hence for temporary fix, we'll do memcopy of the last frame displayed and 1583 queue it to overlay*/ 1584 // mzhu storePreviewFrameForPostview(); 1585 1586 /* stop preview */ 1587 pausePreviewForSnapshot(); 1588 1589 /* call Snapshot start() :*/ 1590 ret = mStreamSnap->start(); 1591 if (MM_CAMERA_OK != ret){ 1592 /* mzhu: fix me, restore preview */ 1593 LOGE("%s: error - can't start Snapshot stream!", __func__); 1594 return BAD_VALUE; 1595 } 1596 1597 if(MM_CAMERA_OK == ret) 1598 mCameraState = CAMERA_STATE_SNAP_START_CMD_SENT; 1599 else 1600 mCameraState = CAMERA_STATE_ERROR; 1601 mPreviewState = QCAMERA_HAL_TAKE_PICTURE; 1602 break; 1603 case QCAMERA_HAL_TAKE_PICTURE: 1604 break; 1605 case QCAMERA_HAL_PREVIEW_STOPPED: 1606 case QCAMERA_HAL_PREVIEW_START: 1607 ret = UNKNOWN_ERROR; 1608 break; 1609 case QCAMERA_HAL_RECORDING_STARTED: 1610 if (canTakeFullSizeLiveshot()) { 1611 LOGD(" Calling takeFullSizeLiveshot"); 1612 takeFullSizeLiveshot(); 1613 }else{ 1614 (void) cam_evt_register_buf_notify(mCameraId, MM_CAMERA_CH_VIDEO, 1615 liveshot_callback, 1616 MM_CAMERA_REG_BUF_CB_COUNT, 1617 1, 1618 this); 1619 } 1620 1621 break; 1622 default: 1623 ret = UNKNOWN_ERROR; 1624 break; 1625 } 1626 LOGI("takePicture: X"); 1627 return ret; 1628 } 1629 1630 bool QCameraHardwareInterface::canTakeFullSizeLiveshot() { 1631 bool ret; 1632 if (mFullLiveshotEnabled && !isLowPowerCamcorder()) { 1633 /* Full size liveshot enabled. */ 1634 1635 /* If Picture size is same as video size, switch to Video size 1636 * live snapshot */ 1637 if ((mDimension.picture_width == mDimension.video_width) && 1638 (mDimension.picture_height == mDimension.video_height)) { 1639 return FALSE; 1640 } 1641 1642 if (mDisEnabled) { 1643 /* If DIS is enabled and Picture size is 1644 * less than (video size + 10% DIS Margin) 1645 * then fall back to Video size liveshot. */ 1646 if ((mDimension.picture_width < 1647 (int)(mDimension.video_width * 1.1)) || 1648 (mDimension.picture_height < 1649 (int)(mDimension.video_height * 1.1))) { 1650 ret = FALSE; 1651 } else { 1652 /* Go with Full size live snapshot. */ 1653 ret = TRUE; 1654 } 1655 } else { 1656 /* DIS Disabled. Go with Full size live snapshot */ 1657 ret = TRUE; 1658 } 1659 } else { 1660 /* Full size liveshot disabled. Fallback to Video size liveshot. */ 1661 ret = FALSE; 1662 } 1663 1664 return ret; 1665 } 1666 1667 status_t QCameraHardwareInterface::takeFullSizeLiveshot() 1668 { 1669 status_t ret = NO_ERROR; 1670 if (mStreamLiveSnap){ 1671 LOGE("%s:Deleting old Snapshot stream instance",__func__); 1672 QCameraStream_Snapshot::deleteInstance (mStreamLiveSnap); 1673 mStreamLiveSnap = NULL; 1674 } 1675 mStreamLiveSnap = QCameraStream_Snapshot::createInstance(mCameraId, myMode); 1676 1677 if (!mStreamLiveSnap) { 1678 LOGE("%s: error - can't creat snapshot stream!", __func__); 1679 /* mzhu: fix me, restore preview */ 1680 return BAD_VALUE; 1681 } 1682 1683 /* Store HAL object in snapshot stream Object */ 1684 mStreamLiveSnap->setHALCameraControl(this); 1685 1686 mStreamLiveSnap->setFullSizeLiveshot(true); 1687 1688 /* Call snapshot init*/ 1689 ret = mStreamLiveSnap->init(); 1690 if (MM_CAMERA_OK != ret){ 1691 LOGE("%s: error - can't init Snapshot stream!", __func__); 1692 return BAD_VALUE; 1693 } 1694 1695 /* call Snapshot start() :*/ 1696 mStreamLiveSnap->resetSnapshotCounters( ); 1697 ret = mStreamLiveSnap->start(); 1698 if (MM_CAMERA_OK != ret){ 1699 /* mzhu: fix me, restore preview */ 1700 LOGE("%s: error - can't start Snapshot stream!", __func__); 1701 return BAD_VALUE; 1702 } 1703 return ret; 1704 } 1705 1706 status_t QCameraHardwareInterface::takeLiveSnapshot() 1707 { 1708 status_t ret = NO_ERROR; 1709 LOGI("takeLiveSnapshot: E"); 1710 mStreamRecord->takeLiveSnapshot(); 1711 LOGI("takeLiveSnapshot: X"); 1712 return ret; 1713 } 1714 1715 status_t QCameraHardwareInterface::autoFocus() 1716 { 1717 LOGI("autoFocus: E"); 1718 status_t ret = NO_ERROR; 1719 Mutex::Autolock lock(mLock); 1720 LOGI("autoFocus: Got lock"); 1721 bool status = true; 1722 isp3a_af_mode_t afMode = getAutoFocusMode(mParameters); 1723 1724 if(mAutoFocusRunning==true){ 1725 LOGE("%s:AF already running should not have got this call",__func__); 1726 return NO_ERROR; 1727 } 1728 1729 if (afMode == AF_MODE_MAX) { 1730 /* This should never happen. We cannot send a 1731 * callback notifying error from this place because 1732 * the CameraService has called this function after 1733 * acquiring the lock. So if we try to issue a callback 1734 * from this place, the callback will try to acquire 1735 * the same lock in CameraService and it will result 1736 * in deadlock. So, let the call go in to the lower 1737 * layer. The lower layer will anyway return error if 1738 * the autofocus is not supported or if the focus 1739 * value is invalid. 1740 * Just print out the error. */ 1741 LOGE("%s:Invalid AF mode (%d)", __func__, afMode); 1742 } 1743 1744 LOGI("%s:AF start (mode %d)", __func__, afMode); 1745 if(MM_CAMERA_OK != cam_ops_action(mCameraId, TRUE, 1746 MM_CAMERA_OPS_FOCUS, &afMode)) { 1747 LOGE("%s: AF command failed err:%d error %s", 1748 __func__, errno, strerror(errno)); 1749 return UNKNOWN_ERROR; 1750 } 1751 1752 mAutoFocusRunning = true; 1753 LOGI("autoFocus: X"); 1754 return ret; 1755 } 1756 1757 status_t QCameraHardwareInterface::cancelAutoFocus() 1758 { 1759 LOGE("cancelAutoFocus: E"); 1760 status_t ret = NO_ERROR; 1761 Mutex::Autolock lock(mLock); 1762 1763 /************************************************************** 1764 BEGIN MUTEX CODE 1765 *************************************************************/ 1766 1767 mAutofocusLock.lock(); 1768 if(mAutoFocusRunning) { 1769 1770 mAutoFocusRunning = false; 1771 mAutofocusLock.unlock(); 1772 1773 }else/*(!mAutoFocusRunning)*/{ 1774 1775 mAutofocusLock.unlock(); 1776 LOGE("%s:Af not running",__func__); 1777 return NO_ERROR; 1778 } 1779 /************************************************************** 1780 END MUTEX CODE 1781 *************************************************************/ 1782 1783 1784 if(MM_CAMERA_OK!=cam_ops_action(mCameraId,FALSE,MM_CAMERA_OPS_FOCUS,NULL )) { 1785 LOGE("%s: AF command failed err:%d error %s",__func__, errno,strerror(errno)); 1786 } 1787 1788 LOGE("cancelAutoFocus: X"); 1789 return NO_ERROR; 1790 } 1791 1792 #if 0 //mzhu 1793 /*========================================================================== 1794 * FUNCTION - prepareSnapshotAndWait - 1795 * 1796 * DESCRIPTION: invoke preparesnapshot and wait for it done 1797 it can be called within takepicture, so no need 1798 to grab mLock. 1799 *=========================================================================*/ 1800 void QCameraHardwareInterface::prepareSnapshotAndWait() 1801 { 1802 LOGI("prepareSnapshotAndWait: E"); 1803 int rc = 0; 1804 /*To Do: call mm camera preparesnapshot */ 1805 if(!rc ) { 1806 mPreparingSnapshot = true; 1807 pthread_mutex_lock(&mAsyncCmdMutex); 1808 pthread_cond_wait(&mAsyncCmdWait, &mAsyncCmdMutex); 1809 pthread_mutex_unlock(&mAsyncCmdMutex); 1810 mPreparingSnapshot = false; 1811 } 1812 LOGI("prepareSnapshotAndWait: X"); 1813 } 1814 #endif //mzhu 1815 1816 /*========================================================================== 1817 * FUNCTION - processprepareSnapshotEvent - 1818 * 1819 * DESCRIPTION: Process the event of preparesnapshot done msg 1820 unblock prepareSnapshotAndWait( ) 1821 *=========================================================================*/ 1822 void QCameraHardwareInterface::processprepareSnapshotEvent(cam_ctrl_status_t *status) 1823 { 1824 LOGI("processprepareSnapshotEvent: E"); 1825 pthread_mutex_lock(&mAsyncCmdMutex); 1826 pthread_cond_signal(&mAsyncCmdWait); 1827 pthread_mutex_unlock(&mAsyncCmdMutex); 1828 LOGI("processprepareSnapshotEvent: X"); 1829 } 1830 1831 void QCameraHardwareInterface::roiEvent(fd_roi_t roi,app_notify_cb_t *app_cb) 1832 { 1833 LOGE("roiEvent: E"); 1834 1835 if(mStreamDisplay) mStreamDisplay->notifyROIEvent(roi); 1836 #if 0 //TODO: move to preview obj 1837 mCallbackLock.lock(); 1838 data_callback mcb = mDataCb; 1839 void *mdata = mCallbackCookie; 1840 int msgEnabled = mMsgEnabled; 1841 mCallbackLock.unlock(); 1842 1843 mMetaDataWaitLock.lock(); 1844 if (mFaceDetectOn == true && mSendMetaData == true) { 1845 mSendMetaData = false; 1846 int faces_detected = roi.rect_num; 1847 int max_faces_detected = MAX_ROI * 4; 1848 int array[max_faces_detected + 1]; 1849 1850 array[0] = faces_detected * 4; 1851 for (int i = 1, j = 0;j < MAX_ROI; j++, i = i + 4) { 1852 if (j < faces_detected) { 1853 array[i] = roi.faces[j].x; 1854 array[i+1] = roi.faces[j].y; 1855 array[i+2] = roi.faces[j].dx; 1856 array[i+3] = roi.faces[j].dy; 1857 } else { 1858 array[i] = -1; 1859 array[i+1] = -1; 1860 array[i+2] = -1; 1861 array[i+3] = -1; 1862 } 1863 } 1864 if(mMetaDataHeap != NULL){ 1865 LOGV("mMetaDataHEap is non-NULL"); 1866 memcpy((uint32_t *)mMetaDataHeap->mHeap->base(), (uint32_t *)array, (sizeof(int)*(MAX_ROI*4+1))); 1867 mMetaDataWaitLock.unlock(); 1868 1869 if (mcb != NULL && (msgEnabled & CAMERA_MSG_META_DATA)) { 1870 mcb(CAMERA_MSG_META_DATA, mMetaDataHeap->mBuffers[0], mdata); 1871 } 1872 } else { 1873 mMetaDataWaitLock.unlock(); 1874 LOGE("runPreviewThread mMetaDataHeap is NULL"); 1875 } 1876 } else { 1877 mMetaDataWaitLock.unlock(); 1878 } 1879 #endif // mzhu 1880 LOGE("roiEvent: X"); 1881 } 1882 1883 1884 void QCameraHardwareInterface::handleZoomEventForSnapshot(void) 1885 { 1886 mm_camera_ch_crop_t v4l2_crop; 1887 1888 1889 LOGI("%s: E", __func__); 1890 1891 memset(&v4l2_crop,0,sizeof(v4l2_crop)); 1892 v4l2_crop.ch_type=MM_CAMERA_CH_SNAPSHOT; 1893 1894 LOGI("%s: Fetching crop info", __func__); 1895 cam_config_get_parm(mCameraId,MM_CAMERA_PARM_CROP,&v4l2_crop); 1896 1897 LOGI("%s: Crop info received for main: %d, %d, %d, %d ", __func__, 1898 v4l2_crop.snapshot.main_crop.left, 1899 v4l2_crop.snapshot.main_crop.top, 1900 v4l2_crop.snapshot.main_crop.width, 1901 v4l2_crop.snapshot.main_crop.height); 1902 LOGI("%s: Crop info received for thumbnail: %d, %d, %d, %d ",__func__, 1903 v4l2_crop.snapshot.thumbnail_crop.left, 1904 v4l2_crop.snapshot.thumbnail_crop.top, 1905 v4l2_crop.snapshot.thumbnail_crop.width, 1906 v4l2_crop.snapshot.thumbnail_crop.height); 1907 1908 if(mStreamSnap) { 1909 LOGD("%s: Setting crop info for snapshot", __func__); 1910 memcpy(&(mStreamSnap->mCrop), &v4l2_crop, sizeof(v4l2_crop)); 1911 } 1912 if(mFullLiveshotEnabled && mStreamLiveSnap){ 1913 LOGD("%s: Setting crop info for snapshot", __func__); 1914 memcpy(&(mStreamLiveSnap->mCrop), &v4l2_crop, sizeof(v4l2_crop)); 1915 } 1916 LOGD("%s: X", __func__); 1917 } 1918 1919 void QCameraHardwareInterface::handleZoomEventForPreview(app_notify_cb_t *app_cb) 1920 { 1921 mm_camera_ch_crop_t v4l2_crop; 1922 1923 LOGI("%s: E", __func__); 1924 1925 /*regular zooming or smooth zoom stopped*/ 1926 if (!mSmoothZoomRunning && mPreviewWindow) { 1927 memset(&v4l2_crop, 0, sizeof(v4l2_crop)); 1928 v4l2_crop.ch_type = MM_CAMERA_CH_PREVIEW; 1929 1930 LOGI("%s: Fetching crop info", __func__); 1931 cam_config_get_parm(mCameraId,MM_CAMERA_PARM_CROP,&v4l2_crop); 1932 1933 LOGI("%s: Crop info received: %d, %d, %d, %d ", __func__, 1934 v4l2_crop.crop.left, 1935 v4l2_crop.crop.top, 1936 v4l2_crop.crop.width, 1937 v4l2_crop.crop.height); 1938 1939 mPreviewWindow->set_crop(mPreviewWindow, 1940 v4l2_crop.crop.left, 1941 v4l2_crop.crop.top, 1942 v4l2_crop.crop.left + v4l2_crop.crop.width, 1943 v4l2_crop.crop.top + v4l2_crop.crop.height); 1944 LOGI("%s: Done setting crop", __func__); 1945 LOGI("%s: Currrent zoom :%d",__func__, mCurrentZoom); 1946 } 1947 1948 LOGI("%s: X", __func__); 1949 } 1950 1951 void QCameraHardwareInterface::zoomEvent(cam_ctrl_status_t *status, app_notify_cb_t *app_cb) 1952 { 1953 LOGI("zoomEvent: state:%d E",mPreviewState); 1954 switch (mPreviewState) { 1955 case QCAMERA_HAL_PREVIEW_STOPPED: 1956 break; 1957 case QCAMERA_HAL_PREVIEW_START: 1958 break; 1959 case QCAMERA_HAL_PREVIEW_STARTED: 1960 handleZoomEventForPreview(app_cb); 1961 if (isZSLMode()) 1962 handleZoomEventForSnapshot(); 1963 break; 1964 case QCAMERA_HAL_RECORDING_STARTED: 1965 handleZoomEventForPreview(app_cb); 1966 if (mFullLiveshotEnabled) 1967 handleZoomEventForSnapshot(); 1968 break; 1969 case QCAMERA_HAL_TAKE_PICTURE: 1970 if(isZSLMode()) 1971 handleZoomEventForPreview(app_cb); 1972 handleZoomEventForSnapshot(); 1973 break; 1974 default: 1975 break; 1976 } 1977 LOGI("zoomEvent: X"); 1978 } 1979 1980 void QCameraHardwareInterface::dumpFrameToFile(const void * data, uint32_t size, char* name, char* ext, int index) 1981 { 1982 char buf[32]; 1983 int file_fd; 1984 if ( data != NULL) { 1985 char * str; 1986 snprintf(buf, sizeof(buf), "/data/%s_%d.%s", name, index, ext); 1987 LOGE("marvin, %s size =%d", buf, size); 1988 file_fd = open(buf, O_RDWR | O_CREAT, 0777); 1989 write(file_fd, data, size); 1990 close(file_fd); 1991 } 1992 } 1993 1994 void QCameraHardwareInterface::dumpFrameToFile(struct msm_frame* newFrame, 1995 HAL_cam_dump_frm_type_t frm_type) 1996 { 1997 int32_t enabled = 0; 1998 int frm_num; 1999 uint32_t skip_mode; 2000 char value[PROPERTY_VALUE_MAX]; 2001 char buf[32]; 2002 int main_422 = 1; 2003 property_get("persist.camera.dumpimg", value, "0"); 2004 enabled = atoi(value); 2005 2006 LOGV(" newFrame =%p, frm_type = %d", newFrame, frm_type); 2007 if(enabled & HAL_DUMP_FRM_MASK_ALL) { 2008 if((enabled & frm_type) && newFrame) { 2009 frm_num = ((enabled & 0xffff0000) >> 16); 2010 if(frm_num == 0) frm_num = 10; /*default 10 frames*/ 2011 if(frm_num > 256) frm_num = 256; /*256 buffers cycle around*/ 2012 skip_mode = ((enabled & 0x0000ff00) >> 8); 2013 if(skip_mode == 0) skip_mode = 1; /*no -skip */ 2014 2015 if( mDumpSkipCnt % skip_mode == 0) { 2016 if (mDumpFrmCnt >= 0 && mDumpFrmCnt <= frm_num) { 2017 int w, h; 2018 int file_fd; 2019 switch (frm_type) { 2020 case HAL_DUMP_FRM_PREVIEW: 2021 w = mDimension.display_width; 2022 h = mDimension.display_height; 2023 snprintf(buf, sizeof(buf), "/data/%dp_%dx%d.yuv", mDumpFrmCnt, w, h); 2024 file_fd = open(buf, O_RDWR | O_CREAT, 0777); 2025 break; 2026 case HAL_DUMP_FRM_VIDEO: 2027 w = mDimension.video_width; 2028 h = mDimension.video_height; 2029 snprintf(buf, sizeof(buf),"/data/%dv_%dx%d.yuv", mDumpFrmCnt, w, h); 2030 file_fd = open(buf, O_RDWR | O_CREAT, 0777); 2031 break; 2032 case HAL_DUMP_FRM_MAIN: 2033 w = mDimension.picture_width; 2034 h = mDimension.picture_height; 2035 snprintf(buf, sizeof(buf), "/data/%dm_%dx%d.yuv", mDumpFrmCnt, w, h); 2036 file_fd = open(buf, O_RDWR | O_CREAT, 0777); 2037 if (mDimension.main_img_format == CAMERA_YUV_422_NV16 || 2038 mDimension.main_img_format == CAMERA_YUV_422_NV61) 2039 main_422 = 2; 2040 break; 2041 case HAL_DUMP_FRM_THUMBNAIL: 2042 w = mDimension.ui_thumbnail_width; 2043 h = mDimension.ui_thumbnail_height; 2044 snprintf(buf, sizeof(buf),"/data/%dt_%dx%d.yuv", mDumpFrmCnt, w, h); 2045 file_fd = open(buf, O_RDWR | O_CREAT, 0777); 2046 break; 2047 default: 2048 w = h = 0; 2049 file_fd = -1; 2050 break; 2051 } 2052 2053 if (file_fd < 0) { 2054 LOGE("%s: cannot open file:type=%d\n", __func__, frm_type); 2055 } else { 2056 LOGE("%s: %d %d", __func__, newFrame->y_off, newFrame->cbcr_off); 2057 write(file_fd, (const void *)(newFrame->buffer+newFrame->y_off), w * h); 2058 write(file_fd, (const void *) 2059 (newFrame->buffer + newFrame->cbcr_off), w * h / 2 * main_422); 2060 close(file_fd); 2061 LOGE("dump %s", buf); 2062 } 2063 } else if(frm_num == 256){ 2064 mDumpFrmCnt = 0; 2065 } 2066 mDumpFrmCnt++; 2067 } 2068 mDumpSkipCnt++; 2069 } 2070 } else { 2071 mDumpFrmCnt = 0; 2072 } 2073 } 2074 2075 status_t QCameraHardwareInterface::setPreviewWindow(preview_stream_ops_t* window) 2076 { 2077 status_t retVal = NO_ERROR; 2078 LOGE(" %s: E mPreviewState = %d, mStreamDisplay = %p", __FUNCTION__, mPreviewState, mStreamDisplay); 2079 if( window == NULL) { 2080 LOGE("%s:Received Setting NULL preview window", __func__); 2081 } 2082 Mutex::Autolock lock(mLock); 2083 switch(mPreviewState) { 2084 case QCAMERA_HAL_PREVIEW_START: 2085 mPreviewWindow = window; 2086 if(mPreviewWindow) { 2087 /* we have valid surface now, start preview */ 2088 LOGE("%s: calling startPreview2", __func__); 2089 retVal = startPreview2(); 2090 if(retVal == NO_ERROR) 2091 mPreviewState = QCAMERA_HAL_PREVIEW_STARTED; 2092 LOGE("%s: startPreview2 done, mPreviewState = %d", __func__, mPreviewState); 2093 } else 2094 LOGE("%s: null window received, mPreviewState = %d", __func__, mPreviewState); 2095 break; 2096 case QCAMERA_HAL_PREVIEW_STARTED: 2097 /* new window comes */ 2098 LOGE("%s: bug, cannot handle new window in started state", __func__); 2099 //retVal = UNKNOWN_ERROR; 2100 break; 2101 case QCAMERA_HAL_PREVIEW_STOPPED: 2102 case QCAMERA_HAL_TAKE_PICTURE: 2103 mPreviewWindow = window; 2104 LOGE("%s: mPreviewWindow = 0x%p, mStreamDisplay = 0x%p", 2105 __func__, mPreviewWindow, mStreamDisplay); 2106 if(mStreamDisplay) 2107 retVal = mStreamDisplay->setPreviewWindow(window); 2108 break; 2109 default: 2110 LOGE("%s: bug, cannot handle new window in state %d", __func__, mPreviewState); 2111 retVal = UNKNOWN_ERROR; 2112 break; 2113 } 2114 LOGE(" %s : X, mPreviewState = %d", __FUNCTION__, mPreviewState); 2115 return retVal; 2116 } 2117 2118 int QCameraHardwareInterface::storeMetaDataInBuffers(int enable) 2119 { 2120 /* this is a dummy func now. fix me later */ 2121 mStoreMetaDataInFrame = enable; 2122 return 0; 2123 } 2124 2125 status_t QCameraHardwareInterface::sendMappingBuf(int ext_mode, int idx, int fd, 2126 uint32_t size, int cameraid, 2127 mm_camera_socket_msg_type msg_type) 2128 { 2129 cam_sock_packet_t packet; 2130 memset(&packet, 0, sizeof(cam_sock_packet_t)); 2131 packet.msg_type = msg_type; 2132 packet.payload.frame_fd_map.ext_mode = ext_mode; 2133 packet.payload.frame_fd_map.frame_idx = idx; 2134 packet.payload.frame_fd_map.fd = fd; 2135 packet.payload.frame_fd_map.size = size; 2136 2137 if ( cam_ops_sendmsg(cameraid, &packet, sizeof(cam_sock_packet_t), packet.payload.frame_fd_map.fd) <= 0 ) { 2138 LOGE("%s: sending frame mapping buf msg Failed", __func__); 2139 return FAILED_TRANSACTION; 2140 } 2141 return NO_ERROR; 2142 } 2143 2144 status_t QCameraHardwareInterface::sendUnMappingBuf(int ext_mode, int idx, int cameraid, 2145 mm_camera_socket_msg_type msg_type) 2146 { 2147 cam_sock_packet_t packet; 2148 memset(&packet, 0, sizeof(cam_sock_packet_t)); 2149 packet.msg_type = msg_type; 2150 packet.payload.frame_fd_unmap.ext_mode = ext_mode; 2151 packet.payload.frame_fd_unmap.frame_idx = idx; 2152 if ( cam_ops_sendmsg(cameraid, &packet, sizeof(cam_sock_packet_t), 0) <= 0 ) { 2153 LOGE("%s: sending frame unmapping buf msg Failed", __func__); 2154 return FAILED_TRANSACTION; 2155 } 2156 return NO_ERROR; 2157 } 2158 2159 int QCameraHardwareInterface::allocate_ion_memory(QCameraHalHeap_t *p_camera_memory, int cnt, int ion_type) 2160 { 2161 int rc = 0; 2162 struct ion_handle_data handle_data; 2163 2164 p_camera_memory->main_ion_fd[cnt] = open("/dev/ion", O_RDONLY); 2165 if (p_camera_memory->main_ion_fd[cnt] < 0) { 2166 LOGE("Ion dev open failed\n"); 2167 LOGE("Error is %s\n", strerror(errno)); 2168 goto ION_OPEN_FAILED; 2169 } 2170 p_camera_memory->alloc[cnt].len = p_camera_memory->size; 2171 /* to make it page size aligned */ 2172 p_camera_memory->alloc[cnt].len = (p_camera_memory->alloc[cnt].len + 4095) & (~4095); 2173 p_camera_memory->alloc[cnt].align = 4096; 2174 p_camera_memory->alloc[cnt].flags = ION_FLAG_CACHED; 2175 p_camera_memory->alloc[cnt].heap_mask = ion_type; 2176 2177 2178 rc = ioctl(p_camera_memory->main_ion_fd[cnt], ION_IOC_ALLOC, &p_camera_memory->alloc[cnt]); 2179 if (rc < 0) { 2180 LOGE("ION allocation failed\n"); 2181 goto ION_ALLOC_FAILED; 2182 } 2183 2184 p_camera_memory->ion_info_fd[cnt].handle = p_camera_memory->alloc[cnt].handle; 2185 rc = ioctl(p_camera_memory->main_ion_fd[cnt], ION_IOC_SHARE, &p_camera_memory->ion_info_fd[cnt]); 2186 if (rc < 0) { 2187 LOGE("ION map failed %s\n", strerror(errno)); 2188 goto ION_MAP_FAILED; 2189 } 2190 p_camera_memory->fd[cnt] = p_camera_memory->ion_info_fd[cnt].fd; 2191 return 0; 2192 2193 ION_MAP_FAILED: 2194 handle_data.handle = p_camera_memory->ion_info_fd[cnt].handle; 2195 ioctl(p_camera_memory->main_ion_fd[cnt], ION_IOC_FREE, &handle_data); 2196 ION_ALLOC_FAILED: 2197 close(p_camera_memory->main_ion_fd[cnt]); 2198 p_camera_memory->main_ion_fd[cnt] = -1; 2199 ION_OPEN_FAILED: 2200 return -1; 2201 } 2202 2203 int QCameraHardwareInterface::deallocate_ion_memory(QCameraHalHeap_t *p_camera_memory, int cnt) 2204 { 2205 struct ion_handle_data handle_data; 2206 int rc = 0; 2207 2208 if (p_camera_memory->main_ion_fd[cnt] > 0) { 2209 handle_data.handle = p_camera_memory->ion_info_fd[cnt].handle; 2210 ioctl(p_camera_memory->main_ion_fd[cnt], ION_IOC_FREE, &handle_data); 2211 close(p_camera_memory->main_ion_fd[cnt]); 2212 p_camera_memory->main_ion_fd[cnt] = -1; 2213 } 2214 return rc; 2215 } 2216 2217 int QCameraHardwareInterface::allocate_ion_memory(QCameraStatHeap_t *p_camera_memory, int cnt, int ion_type) 2218 { 2219 int rc = 0; 2220 struct ion_handle_data handle_data; 2221 2222 p_camera_memory->main_ion_fd[cnt] = open("/dev/ion", O_RDONLY); 2223 if (p_camera_memory->main_ion_fd[cnt] < 0) { 2224 LOGE("Ion dev open failed\n"); 2225 LOGE("Error is %s\n", strerror(errno)); 2226 goto ION_OPEN_FAILED; 2227 } 2228 p_camera_memory->alloc[cnt].len = p_camera_memory->size; 2229 /* to make it page size aligned */ 2230 p_camera_memory->alloc[cnt].len = (p_camera_memory->alloc[cnt].len + 4095) & (~4095); 2231 p_camera_memory->alloc[cnt].align = 4096; 2232 p_camera_memory->alloc[cnt].flags = ION_FLAG_CACHED; 2233 p_camera_memory->alloc[cnt].heap_mask = (0x1 << ion_type | 0x1 << ION_IOMMU_HEAP_ID); 2234 2235 rc = ioctl(p_camera_memory->main_ion_fd[cnt], ION_IOC_ALLOC, &p_camera_memory->alloc[cnt]); 2236 if (rc < 0) { 2237 LOGE("ION allocation failed\n"); 2238 goto ION_ALLOC_FAILED; 2239 } 2240 2241 p_camera_memory->ion_info_fd[cnt].handle = p_camera_memory->alloc[cnt].handle; 2242 rc = ioctl(p_camera_memory->main_ion_fd[cnt], ION_IOC_SHARE, &p_camera_memory->ion_info_fd[cnt]); 2243 if (rc < 0) { 2244 LOGE("ION map failed %s\n", strerror(errno)); 2245 goto ION_MAP_FAILED; 2246 } 2247 p_camera_memory->fd[cnt] = p_camera_memory->ion_info_fd[cnt].fd; 2248 return 0; 2249 2250 ION_MAP_FAILED: 2251 handle_data.handle = p_camera_memory->ion_info_fd[cnt].handle; 2252 ioctl(p_camera_memory->main_ion_fd[cnt], ION_IOC_FREE, &handle_data); 2253 ION_ALLOC_FAILED: 2254 close(p_camera_memory->main_ion_fd[cnt]); 2255 p_camera_memory->main_ion_fd[cnt] = -1; 2256 ION_OPEN_FAILED: 2257 return -1; 2258 } 2259 2260 int QCameraHardwareInterface::cache_ops(int ion_fd, 2261 struct ion_flush_data *cache_data, int type) 2262 { 2263 int rc = 0; 2264 struct ion_custom_data data; 2265 data.cmd = type; 2266 data.arg = (unsigned long)cache_data; 2267 rc = ioctl(ion_fd, ION_IOC_CUSTOM, &data); 2268 if (rc < 0) 2269 LOGE("%s: Cache Invalidate failed\n", __func__); 2270 else 2271 LOGV("%s: Cache OPs type(%d) success", __func__); 2272 2273 return rc; 2274 } 2275 2276 int QCameraHardwareInterface::deallocate_ion_memory(QCameraStatHeap_t *p_camera_memory, int cnt) 2277 { 2278 struct ion_handle_data handle_data; 2279 int rc = 0; 2280 2281 if (p_camera_memory->main_ion_fd[cnt] > 0) { 2282 handle_data.handle = p_camera_memory->ion_info_fd[cnt].handle; 2283 ioctl(p_camera_memory->main_ion_fd[cnt], ION_IOC_FREE, &handle_data); 2284 close(p_camera_memory->main_ion_fd[cnt]); 2285 p_camera_memory->main_ion_fd[cnt] = -1; 2286 } 2287 return rc; 2288 } 2289 2290 int QCameraHardwareInterface::initHeapMem( QCameraHalHeap_t *heap, 2291 int num_of_buf, 2292 int buf_len, 2293 int y_off, 2294 int cbcr_off, 2295 int pmem_type, 2296 mm_cameara_stream_buf_t *StreamBuf, 2297 mm_camera_buf_def_t *buf_def, 2298 uint8_t num_planes, 2299 uint32_t *planes 2300 ) 2301 { 2302 int rc = 0; 2303 int i; 2304 int path; 2305 struct msm_frame *frame; 2306 LOGE("Init Heap =%p. stream_buf =%p, pmem_type =%d, num_of_buf=%d. buf_len=%d, cbcr_off=%d", 2307 heap, StreamBuf, pmem_type, num_of_buf, buf_len, cbcr_off); 2308 if(num_of_buf > MM_CAMERA_MAX_NUM_FRAMES || heap == NULL || 2309 mGetMemory == NULL ) { 2310 LOGE("Init Heap error"); 2311 rc = -1; 2312 return rc; 2313 } 2314 memset(heap, 0, sizeof(QCameraHalHeap_t)); 2315 for (i=0; i<MM_CAMERA_MAX_NUM_FRAMES;i++) { 2316 heap->main_ion_fd[i] = -1; 2317 heap->fd[i] = -1; 2318 } 2319 heap->buffer_count = num_of_buf; 2320 heap->size = buf_len; 2321 heap->y_offset = y_off; 2322 heap->cbcr_offset = cbcr_off; 2323 2324 if (StreamBuf != NULL) { 2325 StreamBuf->num = num_of_buf; 2326 StreamBuf->frame_len = buf_len; 2327 switch (pmem_type) { 2328 case MSM_PMEM_MAINIMG: 2329 case MSM_PMEM_RAW_MAINIMG: 2330 path = OUTPUT_TYPE_S; 2331 break; 2332 2333 case MSM_PMEM_THUMBNAIL: 2334 path = OUTPUT_TYPE_T; 2335 break; 2336 2337 default: 2338 rc = -1; 2339 return rc; 2340 } 2341 } 2342 2343 2344 for(i = 0; i < num_of_buf; i++) { 2345 #ifdef USE_ION 2346 if (isZSLMode()) 2347 rc = allocate_ion_memory(heap, i, ((0x1 << CAMERA_ZSL_ION_HEAP_ID) | 2348 (0x1 << CAMERA_ZSL_ION_FALLBACK_HEAP_ID))); 2349 else 2350 rc = allocate_ion_memory(heap, i, ((0x1 << CAMERA_ION_HEAP_ID) | 2351 (0x1 << CAMERA_ION_FALLBACK_HEAP_ID))); 2352 2353 if (rc < 0) { 2354 LOGE("%sION allocation failed\n", __func__); 2355 break; 2356 } 2357 #else 2358 if (pmem_type == MSM_PMEM_MAX) 2359 heap->fd[i] = -1; 2360 else { 2361 heap->fd[i] = open("/dev/pmem_adsp", O_RDWR|O_SYNC); 2362 if ( heap->fd[i] <= 0) { 2363 rc = -1; 2364 LOGE("Open fail: heap->fd[%d] =%d", i, heap->fd[i]); 2365 break; 2366 } 2367 } 2368 #endif 2369 heap->camera_memory[i] = mGetMemory( heap->fd[i], buf_len, 1, (void *)this); 2370 2371 if (heap->camera_memory[i] == NULL ) { 2372 LOGE("Getmem fail %d: ", i); 2373 rc = -1; 2374 break; 2375 } 2376 if (StreamBuf != NULL) { 2377 frame = &(StreamBuf->frame[i]); 2378 memset(frame, 0, sizeof(struct msm_frame)); 2379 frame->fd = heap->fd[i]; 2380 frame->phy_offset = 0; 2381 frame->buffer = (uint32_t) heap->camera_memory[i]->data; 2382 frame->path = path; 2383 frame->cbcr_off = planes[0]+heap->cbcr_offset; 2384 frame->y_off = heap->y_offset; 2385 frame->fd_data = heap->ion_info_fd[i]; 2386 frame->ion_alloc = heap->alloc[i]; 2387 frame->ion_dev_fd = heap->main_ion_fd[i]; 2388 LOGD("%s: Buffer idx: %d addr: %x fd: %d phy_offset: %d" 2389 "cbcr_off: %d y_off: %d frame_len: %d", __func__, 2390 i, (unsigned int)frame->buffer, frame->fd, 2391 frame->phy_offset, cbcr_off, y_off, frame->ion_alloc.len); 2392 2393 buf_def->buf.mp[i].frame = *frame; 2394 buf_def->buf.mp[i].frame_offset = 0; 2395 buf_def->buf.mp[i].num_planes = num_planes; 2396 /* Plane 0 needs to be set seperately. Set other planes 2397 * in a loop. */ 2398 buf_def->buf.mp[i].planes[0].length = planes[0]; 2399 buf_def->buf.mp[i].planes[0].m.userptr = frame->fd; 2400 buf_def->buf.mp[i].planes[0].data_offset = y_off; 2401 buf_def->buf.mp[i].planes[0].reserved[0] = 2402 buf_def->buf.mp[i].frame_offset; 2403 for (int j = 1; j < num_planes; j++) { 2404 buf_def->buf.mp[i].planes[j].length = planes[j]; 2405 buf_def->buf.mp[i].planes[j].m.userptr = frame->fd; 2406 buf_def->buf.mp[i].planes[j].data_offset = cbcr_off; 2407 buf_def->buf.mp[i].planes[j].reserved[0] = 2408 buf_def->buf.mp[i].planes[j-1].reserved[0] + 2409 buf_def->buf.mp[i].planes[j-1].length; 2410 } 2411 } else { 2412 } 2413 2414 LOGE("heap->fd[%d] =%d, camera_memory=%p", i, heap->fd[i], heap->camera_memory[i]); 2415 heap->local_flag[i] = 1; 2416 } 2417 if( rc < 0) { 2418 releaseHeapMem(heap); 2419 } 2420 return rc; 2421 2422 } 2423 2424 int QCameraHardwareInterface::releaseHeapMem( QCameraHalHeap_t *heap) 2425 { 2426 int rc = 0; 2427 LOGE("Release %p", heap); 2428 if (heap != NULL) { 2429 2430 for (int i = 0; i < heap->buffer_count; i++) { 2431 if(heap->camera_memory[i] != NULL) { 2432 heap->camera_memory[i]->release( heap->camera_memory[i] ); 2433 heap->camera_memory[i] = NULL; 2434 } else if (heap->fd[i] <= 0) { 2435 LOGE("impossible: amera_memory[%d] = %p, fd = %d", 2436 i, heap->camera_memory[i], heap->fd[i]); 2437 } 2438 2439 if(heap->fd[i] > 0) { 2440 close(heap->fd[i]); 2441 heap->fd[i] = -1; 2442 } 2443 #ifdef USE_ION 2444 deallocate_ion_memory(heap, i); 2445 #endif 2446 } 2447 heap->buffer_count = 0; 2448 heap->size = 0; 2449 heap->y_offset = 0; 2450 heap->cbcr_offset = 0; 2451 } 2452 return rc; 2453 } 2454 2455 preview_format_info_t QCameraHardwareInterface::getPreviewFormatInfo( ) 2456 { 2457 return mPreviewFormatInfo; 2458 } 2459 2460 void QCameraHardwareInterface::wdenoiseEvent(cam_ctrl_status_t status, void *cookie) 2461 { 2462 LOGI("wdnEvent: preview state:%d E",mPreviewState); 2463 if (mStreamSnap != NULL) { 2464 LOGI("notifyWDNEvent to snapshot stream"); 2465 mStreamSnap->notifyWDenoiseEvent(status, cookie); 2466 } 2467 } 2468 2469 bool QCameraHardwareInterface::isWDenoiseEnabled() 2470 { 2471 return mDenoiseValue; 2472 } 2473 2474 void QCameraHardwareInterface::takePicturePrepareHardware() 2475 { 2476 LOGV("%s: E", __func__); 2477 2478 /* Prepare snapshot*/ 2479 cam_ops_action(mCameraId, 2480 TRUE, 2481 MM_CAMERA_OPS_PREPARE_SNAPSHOT, 2482 this); 2483 LOGV("%s: X", __func__); 2484 } 2485 2486 bool QCameraHardwareInterface::isNoDisplayMode() 2487 { 2488 return (mNoDisplayMode != 0); 2489 } 2490 2491 void QCameraHardwareInterface::pausePreviewForZSL() 2492 { 2493 if(mRestartPreview) { 2494 stopPreviewInternal(); 2495 mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED; 2496 startPreview2(); 2497 mPreviewState = QCAMERA_HAL_PREVIEW_STARTED; 2498 mRestartPreview = false; 2499 } 2500 } 2501 }; // namespace android 2502 2503