MBOOL MultiShotCc:: onCreateImage() { FUNCTION_LOG_START; AutoCPTLog cptlog(Event_MShot_onCreateImage); MUINT32 u4ShotCount = 0; // mpJpegImageCreateThread->postCommand(Command(Command::eID_YUV_BUF)); // move in jpeg create CPTLogStr(Event_MShot_onCreateImage, CPTFlagSeparator, "callback EOF"); handleNotifyCallback(ECamShot_NOTIFY_MSG_EOF, 0, 0); // loop, trigger jpeg create while(u4ShotCount<mu4ShotCount) { CPTLogStr(Event_MShot_onCreateImage, CPTFlagSeparator, "wait jpeg done"); ::sem_wait(&semJpeg); CPTLogStr(Event_MShot_onCreateImage, CPTFlagSeparator, "handle callback"); if(mbIsLastShot || u4ShotCount==mu4ShotCount-1) // last frame { MY_LOGD("notify last shot will callback"); handleNotifyCallback(ECamShot_NOTIFY_MSG_CSHOT_END, 0, 0); handleNotifyCallback(ECamShot_NOTIFY_MSG_FOCUS_VALUE, mFocusVal.u4ValH, mFocusVal.u4ValL); handleDataCallback(ECamShot_DATA_MSG_JPEG, (mThumbImgBufInfoReady.u4BufVA), mu4ThumbnailSize, reinterpret_cast<MUINT8*>(mJpegImgBufInfoReady.u4BufVA), mu4JpegSize); break; } else // create next jpeg { // trigger next jpeg create // mpJpegImageCreateThread->postCommand(Command(Command::eID_YUV_BUF)); handleNotifyCallback(ECamShot_NOTIFY_MSG_EOF, 0, 0); handleNotifyCallback(ECamShot_NOTIFY_MSG_FOCUS_VALUE, mFocusVal.u4ValH, mFocusVal.u4ValL); handleDataCallback(ECamShot_DATA_MSG_JPEG, (mThumbImgBufInfoReady.u4BufVA), mu4ThumbnailSize, reinterpret_cast<MUINT8*>(mJpegImgBufInfoReady.u4BufVA), mu4JpegSize); u4ShotCount++; } } // (7) start end CPTLogStr(Event_MShot_start, CPTFlagSeparator, "post start end sem"); ::sem_post(&semStartEnd); FUNCTION_LOG_END; return MTRUE; }
MBOOL MultiShotCc:: stop() { FUNCTION_LOG_START; AutoCPTLog cptlog(Event_MShot_stop); #warning [TODO] for continouous shot // [CS]+ // (1) mbCancelShot = MTRUE; // (2) wait start end CPTLogStr(Event_MShot_stop, CPTFlagSeparator, "wait start end"); ::sem_wait(&semStartEnd); // must call before thread stop, to sure the lastimage notify callback do. // (3) uninit thread CPTLogStr(Event_MShot_stop, CPTFlagSeparator, "uninit image create thread"); uninitImageCreateThread(); // (4) end continuous shot jobs in 3A NS3A::Hal3ABase *p3AObj = Hal3ABase::createInstance(mSensorParam.u4DeviceID); //p3AObj->endContinuousShotJobs(); p3AObj->destroyInstance(); #if 0 // (4) destroy CamIOPipe CPTLogStr(Event_MShot_stop, CPTFlagSeparator, "destroy/uninit CamIOPipe"); CHECK_OBJECT(mpCamIOPipe) MBOOL ret = mpCamIOPipe->uninit(); if (!ret) { MY_LOGE("mpCamIOPipe->uninit() fail "); } mpCamIOPipe = NULL; #endif // (5) prepare buffer freeShotMem(); // [CS]- FUNCTION_LOG_END; // return MTRUE; }
MBOOL MultiShotNcc:: onCreateImage() { AutoCPTLog cptlog(Event_MShot_onCreateImage); mpYuvImageCreateThread->postCommand(Command(Command::eID_WAKEUP)); MUINT32 u4ShotCount = 0; //MBOOL bCShotEndCB = false; // (3) loop, handle jpeg buffer while(u4ShotCount<mu4ShotCount) { CPTLogStr(Event_MShot_onCreateImage, CPTFlagSeparator, "wait jpeg done"); ::sem_wait(&semJpeg); CPTLogStr(Event_MShot_onCreateImage, CPTFlagSeparator, "handle callback"); if(mbIsLastShot || u4ShotCount==mu4ShotCount-1) // last frame { MY_LOGD("notify last shot will callback"); handleNotifyCallback(ECamShot_NOTIFY_MSG_CSHOT_END, 0, 0); handleNotifyCallback(ECamShot_NOTIFY_MSG_FOCUS_VALUE, mFocusVal.u4ValH, mFocusVal.u4ValL); handleDataCallback(ECamShot_DATA_MSG_JPEG, (mThumbImgBufInfoReady.u4BufVA), mu4ThumbnailSize, reinterpret_cast<MUINT8*>(mJpegImgBufInfoReady.u4BufVA), mu4JpegSize); break; } handleNotifyCallback(ECamShot_NOTIFY_MSG_FOCUS_VALUE, mFocusVal.u4ValH, mFocusVal.u4ValL); handleDataCallback(ECamShot_DATA_MSG_JPEG, (mThumbImgBufInfoReady.u4BufVA), mu4ThumbnailSize, reinterpret_cast<MUINT8*>(mJpegImgBufInfoReady.u4BufVA), mu4JpegSize); u4ShotCount++; } // (7) start end CPTLogStr(Event_MShot_start, CPTFlagSeparator, "post start end sem"); ::sem_post(&semStartEnd); return MTRUE; }
sp<ICamera> CameraService::connect( const sp<ICameraClient>& cameraClient, int cameraId) { #ifdef MTK_CAMERAPROFILE_SUPPORT initCameraProfile(); AutoCPTLog cptlog(Event_CS_connect); #endif int callingPid = getCallingPid(); #ifdef VENDOR_EDIT //LiChen@CameraApp, 2013/03/07, Add for IntelligentSleep #ifdef OPPO_INTELLIGENT_SLEEP LOG1("CameraService::connect Intelligent Sleep (pid %d, id %d)", callingPid, cameraId); LOG1("CameraService::connect Intelligent mIntelSleepId %d", mIntelSleepId); switch (cameraId) { case CAMERA_INTELLIGENT_SLEEP: for(int i = 0 ; i < mNumberOfCameras; i ++) { if (mBusy[i]) { return NULL; } } cameraId = 1; mIntelSleepId = CAMERA_INTELLIGENT_SLEEP; break; default: if (mIntelSleepId == CAMERA_INTELLIGENT_SLEEP) { int cnt = 0; while (mClient[1].promote() == NULL && cnt < 10) { usleep(50000); cnt++; } if (mClient[1].promote() != NULL) { mClient[1].promote()->disconnect(); } } mIntelSleepId = -1; break; } #endif #endif /* VENDOR_EDIT */ LOG1("CameraService::connect E (pid %d, id %d)", callingPid, cameraId); if (!mModule) { ALOGE("Camera HAL module not loaded"); return NULL; } sp<Client> client; //!++ #if defined(ATVCHIP_MTK_ENABLE) if (cameraId == 0xFF) { // It's atv, the last cameraId is atv cameraId = mNumberOfCameras - 1; status_t status = setProperty( String8(MtkCameraParameters::PROPERTY_KEY_CLIENT_APPMODE), String8(MtkCameraParameters::APP_MODE_NAME_MTK_ATV) ); ALOGD("connected from atv - cameraId(%d) status(%d) \n", cameraId, status); } else if (cameraId < 0 || cameraId >= (mNumberOfCameras - 1)) { ALOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d), (mNumberOfCameras-1=%d).", callingPid, cameraId, (mNumberOfCameras-1)); return NULL; } #else if (cameraId < 0 || cameraId >= mNumberOfCameras) { ALOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d).", callingPid, cameraId); return NULL; } #endif //!-- char value[PROPERTY_VALUE_MAX]; property_get("sys.secpolicy.camera.disabled", value, "0"); if (strcmp(value, "1") == 0) { // Camera is disabled by DevicePolicyManager. ALOGI("Camera is disabled. connect X (pid %d) rejected", callingPid); return NULL; } Mutex::Autolock lock(mServiceLock); if (mClient[cameraId] != 0) { client = mClient[cameraId].promote(); if (client != 0) { if (cameraClient->asBinder() == client->getCameraClient()->asBinder()) { LOG1("CameraService::connect X (pid %d) (the same client)", callingPid); return client; } else { ALOGW("CameraService::connect X (pid %d) rejected (existing client).", callingPid); return NULL; } } mClient[cameraId].clear(); } if (mBusy[cameraId]) { ALOGW("CameraService::connect X (pid %d) rejected" " (camera %d is still busy).", callingPid, cameraId); return NULL; } struct camera_info info; if (mModule->get_camera_info(cameraId, &info) != OK) { ALOGE("Invalid camera id %d", cameraId); return NULL; } int deviceVersion; if (mModule->common.module_api_version == CAMERA_MODULE_API_VERSION_2_0) { deviceVersion = info.device_version; } else { deviceVersion = CAMERA_DEVICE_API_VERSION_1_0; } switch(deviceVersion) { case CAMERA_DEVICE_API_VERSION_1_0: client = new CameraClient(this, cameraClient, cameraId, info.facing, callingPid, getpid()); break; case CAMERA_DEVICE_API_VERSION_2_0: client = new Camera2Client(this, cameraClient, cameraId, info.facing, callingPid, getpid()); break; default: ALOGE("Unknown camera device HAL version: %d", deviceVersion); return NULL; } #ifdef MTK_CAMERA_BSP_SUPPORT // To avoid release/new MediaPlayer when switching between main/sub sensor, and it will reduce the switch time. #ifdef VENDOR_EDIT //LiChen@CameraApp, 2013/04/08, Remove for speeding up the opening camera loadSound(); #endif /* VENDOR_EDIT */ #endif #ifdef MTK_CAMERAPROFILE_SUPPORT CPTLog(Event_CS_newCamHwIF, CPTFlagStart); #endif if (client->initialize(mModule) != OK) { #ifdef MTK_CAMERAPROFILE_SUPPORT CPTLogStr(Event_CS_newCamHwIF, CPTFlagEnd, "new CameraHardwareInterface failed"); #endif #ifdef MTK_CAMERA_BSP_SUPPORT // To avoid release/new MediaPlayer when switching between main/sub sensor, and it will reduce the switch time. releaseSound(); #endif return NULL; } #ifdef MTK_CAMERAPROFILE_SUPPORT CPTLog(Event_CS_newCamHwIF, CPTFlagEnd); #endif cameraClient->asBinder()->linkToDeath(this); mClient[cameraId] = client; LOG1("CameraService::connect X (id %d, this pid is %d)", cameraId, getpid()); return client; }
MBOOL MultiShotNcc:: start(SensorParam const & rSensorParam, MUINT32 u4ShotCount) { FUNCTION_LOG_START; AutoCPTLog cptlog(Event_MShot_start); mSensorParam = rSensorParam; // dumpSensorParam(mSensorParam); MY_LOGD("[start] enabled msg (nitify, data) = (0x%x, 0x%x)", mi4NotifyMsgSet, mi4DataMsgSet); // if (!isDataMsgEnabled(ECamShot_DATA_MSG_ALL) && !isNotifyMsgEnabled(ECamShot_NOTIFY_MSG_ALL)) { MY_LOGE("[start] No data msg enable !"); return MFALSE; } mbSet3ACapMode = MTRUE; mbCancelShot = MFALSE; mbIsLastShot = MFALSE; mu4JpegCount = 0; mu4ShotCount = u4ShotCount; mbJpegSemPost = MFALSE; ::sem_init(&semJpeg, 0, 0); ::sem_init(&semThumbnail, 0, 0); ::sem_init(&semStartEnd, 0, 0); MY_LOGD("mu4ShotCount = %d", mu4ShotCount); EImageFormat eImgFmt = querySensorFmt(rSensorParam.u4DeviceID, rSensorParam.u4Scenario, rSensorParam.u4Bitdepth); CPTLogStr(Event_MShot_start, CPTFlagSeparator, "create/init CamIOPipe"); // (1). Create Instance if (NULL == mpCamIOPipe) { mpCamIOPipe = ICamIOPipe::createInstance(eSWScenarioID_CAPTURE_NORMAL, static_cast<EScenarioFmt>(mapScenarioType(eImgFmt))); CHECK_OBJECT(mpCamIOPipe); // (2). Query port property #warning [TODO] Query port property // (3). init mpCamIOPipe->init(); } // (2) prepare buffer CPTLogStr(Event_MShot_start, CPTFlagSeparator, "prepare buffer"); // (2.1) raw buffer mRawImgBufInfo = querySensorRawImgBufInfo(); // (2.2) yuv buffer mYuvImgBufInfoWrite = queryYuvRawImgBufInfo(); mYuvImgBufInfoReady = queryYuvRawImgBufInfo(); mYuvImgBufInfoRead = queryYuvRawImgBufInfo(); // (2.3) PostView buffer mPostViewImgBufInfoWrite = queryPostViewImgInfo(); mPostViewImgBufInfoReady = queryPostViewImgInfo(); mPostViewImgBufInfoRead = queryPostViewImgInfo(); // (2.4) jpeg buffer mJpegImgBufInfoWrite = queryJpegImgBufInfo(); mJpegImgBufInfoReady = queryJpegImgBufInfo(); // (2.5) Thumb buffer mThumbImgBufInfoYuv = queryThumbYuvImgBufInfo(); mThumbImgBufInfoWrite = queryThumbImgBufInfo(); mThumbImgBufInfoReady = queryThumbImgBufInfo(); mThumbImgBufInfoTemp = queryThumbTempImgBufInfo(); // (3) init thread CPTLogStr(Event_MShot_start, CPTFlagSeparator, "init image create thread"); initImageCreateThread(); // (4) start c-shot loop CPTLogStr(Event_MShot_start, CPTFlagSeparator, "wakeup create thread"); mpImageCreateThread->postCommand(Command(Command::eID_WAKEUP)); //onCreateImage(); FUNCTION_LOG_END; // return MTRUE; }