bool EmulatedQemuCameraDevice::inWorkerThread() { /* Wait till FPS timeout expires, or thread exit message is received. */ WorkerThread::SelectRes res = getWorkerThread()->Select(-1, 1000000 / mEmulatedFPS); if (res == WorkerThread::EXIT_THREAD) { ALOGV("%s: Worker thread has been terminated.", __FUNCTION__); return false; } /* Query frames from the service. */ status_t query_res = mQemuClient.queryFrame(mCurrentFrame, mPreviewFrame, mFrameBufferSize, mTotalPixels * 4, mWhiteBalanceScale[0], mWhiteBalanceScale[1], mWhiteBalanceScale[2], mExposureCompensation); if (query_res == NO_ERROR) { /* Timestamp the current frame, and notify the camera HAL. */ mCurFrameTimestamp = systemTime(SYSTEM_TIME_MONOTONIC); mCameraHAL->onNextFrameAvailable(mCurrentFrame, mCurFrameTimestamp, this); return true; } else { ALOGE("%s: Unable to get current video frame: %s", __FUNCTION__, strerror(query_res)); mCameraHAL->onCameraDeviceError(CAMERA_ERROR_SERVER_DIED); return false; } }
status_t EmulatedCameraDevice::stopWorkerThread() { ALOGV("%s", __FUNCTION__); if (!isInitialized()) { ALOGE("%s: Emulated camera device is not initialized", __FUNCTION__); return EINVAL; } const status_t res = getWorkerThread()->stopThread(); ALOGE_IF(res != NO_ERROR, "%s: Unable to stop worker thread", __FUNCTION__); return res; }
bool EmulatedQemuCameraDevice::inWorkerThread() { /* Wait till FPS timeout expires, or thread exit message is received. */ WorkerThread::SelectRes res = getWorkerThread()->Select(-1, 1000000 / mEmulatedFPS); if (res == WorkerThread::EXIT_THREAD) { LOGV("%s: Worker thread has been terminated.", __FUNCTION__); return false; } /* Lets see if we need to generate a new frame. */ if ((systemTime(SYSTEM_TIME_MONOTONIC) - mLastRedrawn) >= mRedrawAfter) { /* * Time to generate a new frame. */ #if EFCD_ROTATE_FRAME LOGV("%s: calld frame_type = rotateFrame():%d", __FUNCTION__, frame_type); const int frame_type = rotateFrame(); switch (frame_type) { case 0: drawCheckerboard(); break; case 1: drawStripes(); break; case 2: drawSolid(mCurrentColor); break; } #else /* Draw the checker board. */ LOGV("%s: calld drawCheckerboard()", __FUNCTION__); drawCheckerboard(); #endif // EFCD_ROTATE_FRAME mLastRedrawn = systemTime(SYSTEM_TIME_MONOTONIC); } /* Timestamp the current frame, and notify the camera HAL about new frame. */ mCurFrameTimestamp = systemTime(SYSTEM_TIME_MONOTONIC); LOGV("%s: calld mCameraHAL->onNextFrameAvailable(mCurrentFrame:%p", __FUNCTION__,mCurrentFrame); mCameraHAL->onNextFrameAvailable(mCurrentFrame, mCurFrameTimestamp, this); return true; }
status_t EmulatedCameraDevice::Initialize() { if (isInitialized()) { ALOGW("%s: Emulated camera device is already initialized: mState = %d", __FUNCTION__, mState); return NO_ERROR; } /* Instantiate worker thread object. */ mWorkerThread = new WorkerThread(this); if (getWorkerThread() == NULL) { ALOGE("%s: Unable to instantiate worker thread object", __FUNCTION__); return ENOMEM; } mState = ECDS_INITIALIZED; return NO_ERROR; }