diff options
author | Andriy Chepurnyy <x0155536@ti.com> | 2012-10-26 14:02:25 +0300 |
---|---|---|
committer | Daniel Levin <dendy@ti.com> | 2012-11-26 20:17:15 +0200 |
commit | 5be19d85932b7efd58885bf4ca1934f52beb32c0 (patch) | |
tree | 671d0e83fb4de8278ac1eadc0d578cf97b5aee7c /camera | |
parent | e54099214a3a1c340f4785c9e4d46265cecbfb49 (diff) | |
download | hardware_ti_omap4-5be19d85932b7efd58885bf4ca1934f52beb32c0.zip hardware_ti_omap4-5be19d85932b7efd58885bf4ca1934f52beb32c0.tar.gz hardware_ti_omap4-5be19d85932b7efd58885bf4ca1934f52beb32c0.tar.bz2 |
CameraHAL: Make graphic buffer locking conditional
This mechanism is added to support components where
locking mechanism is handled on DOMX layer.
As example is using ducati decoder with buffers allocated
via ANativeWindowDisplayAdapter.
Change-Id: I33ae0f0766473a6d8e85699c31dcad9345b4df70
Signed-off-by: Andriy Chepurnyy <x0155536@ti.com>
Diffstat (limited to 'camera')
-rw-r--r-- | camera/ANativeWindowDisplayAdapter.cpp | 62 | ||||
-rw-r--r-- | camera/AppCallbackNotifier.cpp | 55 | ||||
-rw-r--r-- | camera/CameraHal.cpp | 18 | ||||
-rw-r--r-- | camera/inc/ANativeWindowDisplayAdapter.h | 7 | ||||
-rw-r--r-- | camera/inc/CameraHal.h | 10 |
5 files changed, 124 insertions, 28 deletions
diff --git a/camera/ANativeWindowDisplayAdapter.cpp b/camera/ANativeWindowDisplayAdapter.cpp index fce9c50..396e6d4 100644 --- a/camera/ANativeWindowDisplayAdapter.cpp +++ b/camera/ANativeWindowDisplayAdapter.cpp @@ -75,7 +75,8 @@ OMX_COLOR_FORMATTYPE toOMXPixFormat(const char* parameters_format) ANativeWindowDisplayAdapter::ANativeWindowDisplayAdapter():mDisplayThread(NULL), mDisplayState(ANativeWindowDisplayAdapter::DISPLAY_INIT), mDisplayEnabled(false), - mBufferCount(0) + mBufferCount(0), + mUseExternalBufferLocking(false) @@ -579,6 +580,9 @@ CameraBuffer* ANativeWindowDisplayAdapter::allocateBufferList(int width, int hei mapper.lock(*handle, CAMHAL_GRALLOC_USAGE, bounds, y_uv); mBuffers[i].mapped = y_uv[0]; mFrameProvider->addFramePointers(&mBuffers[i], y_uv); + if (mUseExternalBufferLocking) { + mapper.unlock(*handle); + } } // return the rest of the buffers back to ANativeWindow @@ -781,8 +785,10 @@ status_t ANativeWindowDisplayAdapter::returnBuffersToWindow() continue; } - // unlock buffer before giving it up - mapper.unlock(*handle); + if (!mUseExternalBufferLocking) { + // unlock buffer before giving it up + mapper.unlock(*handle); + } ret = mANativeWindow->cancel_buffer(mANativeWindow, handle); if ( NO_INIT == ret ) { @@ -1070,8 +1076,10 @@ status_t ANativeWindowDisplayAdapter::PostFrame(ANativeWindowDisplayAdapter::Dis { buffer_handle_t *handle = (buffer_handle_t *) mBuffers[i].opaque; - // unlock buffer before sending to display - mapper.unlock(*handle); + if (!mUseExternalBufferLocking) { + // unlock buffer before sending to display + mapper.unlock(*handle); + } ret = mANativeWindow->enqueue_buffer(mANativeWindow, handle); } if ( NO_ERROR != ret ) { @@ -1090,9 +1098,10 @@ status_t ANativeWindowDisplayAdapter::PostFrame(ANativeWindowDisplayAdapter::Dis else { buffer_handle_t *handle = (buffer_handle_t *) mBuffers[i].opaque; - - // unlock buffer before giving it up - mapper.unlock(*handle); + if (!mUseExternalBufferLocking) { + // unlock buffer before giving it up + mapper.unlock(*handle); + } // cancel buffer and dequeue another one ret = mANativeWindow->cancel_buffer(mANativeWindow, handle); @@ -1162,23 +1171,24 @@ bool ANativeWindowDisplayAdapter::handleFrameReturn() if (i == mBufferCount) { CAMHAL_LOGEB("Failed to find handle %p", buf); } - - // lock buffer before sending to FrameProvider for filling - bounds.left = 0; - bounds.top = 0; - bounds.right = mFrameWidth; - bounds.bottom = mFrameHeight; - - int lock_try_count = 0; - while (mapper.lock(*(buffer_handle_t *) mBuffers[i].opaque, CAMHAL_GRALLOC_USAGE, bounds, y_uv) < 0){ - if (++lock_try_count > LOCK_BUFFER_TRIES){ - if ( NULL != mErrorNotifier.get() ){ - mErrorNotifier->errorNotify(CAMERA_ERROR_UNKNOWN); + if (!mUseExternalBufferLocking) { + // lock buffer before sending to FrameProvider for filling + bounds.left = 0; + bounds.top = 0; + bounds.right = mFrameWidth; + bounds.bottom = mFrameHeight; + + int lock_try_count = 0; + while (mapper.lock(*(buffer_handle_t *) mBuffers[i].opaque, CAMHAL_GRALLOC_USAGE, bounds, y_uv) < 0){ + if (++lock_try_count > LOCK_BUFFER_TRIES){ + if ( NULL != mErrorNotifier.get() ){ + mErrorNotifier->errorNotify(CAMERA_ERROR_UNKNOWN); + } + return false; + } + CAMHAL_LOGEA("Gralloc Lock FrameReturn Error: Sleeping 15ms"); + usleep(15000); } - return false; - } - CAMHAL_LOGEA("Gralloc Lock FrameReturn Error: Sleeping 15ms"); - usleep(15000); } { @@ -1242,6 +1252,10 @@ void ANativeWindowDisplayAdapter::frameCallback(CameraFrame* caFrame) PostFrame(df); } +void ANativeWindowDisplayAdapter::setExternalLocking(bool extBuffLocking) +{ + mUseExternalBufferLocking = extBuffLocking; +} /*--------------------ANativeWindowDisplayAdapter Class ENDS here-----------------------------*/ diff --git a/camera/AppCallbackNotifier.cpp b/camera/AppCallbackNotifier.cpp index e7f2b19..dcb7918 100644 --- a/camera/AppCallbackNotifier.cpp +++ b/camera/AppCallbackNotifier.cpp @@ -201,6 +201,7 @@ status_t AppCallbackNotifier::initialize() mRecording = false; mPreviewing = false; + mExternalLocking = false; LOG_FUNCTION_NAME_EXIT; @@ -786,6 +787,38 @@ void AppCallbackNotifier::copyAndSendPictureFrame(CameraFrame* frame, int32_t ms } } +void AppCallbackNotifier::lockBufferAndUpdatePtrs(CameraFrame* frame) +{ + android::GraphicBufferMapper &mapper = android::GraphicBufferMapper::get(); + android::Rect bounds; + + bounds.left = 0; + bounds.top = 0; + bounds.right = frame->mWidth; + bounds.bottom = frame->mHeight; + void *y_uv[2]; + buffer_handle_t *handle = reinterpret_cast<buffer_handle_t *>(frame->mBuffer->opaque); + mapper.lock(*handle, CAMHAL_GRALLOC_USAGE, bounds, y_uv); + frame->mBuffer->mapped = y_uv[0]; + frame->mYuv[0] = reinterpret_cast<int>(frame->mBuffer->mapped); + frame->mYuv[1] = frame->mYuv[0] + (frame->mLength + frame->mOffset)*2/3; +} + +void AppCallbackNotifier::unlockBufferAndUpdatePtrs(CameraFrame* frame) +{ + android::GraphicBufferMapper &mapper = android::GraphicBufferMapper::get(); + buffer_handle_t *handle = reinterpret_cast<buffer_handle_t *>(frame->mBuffer->opaque); + mapper.unlock(*handle); + frame->mBuffer->mapped = NULL; + frame->mYuv[0] = NULL; + frame->mYuv[1] = NULL; +} + +void AppCallbackNotifier::setExternalLocking(bool extBuffLocking) +{ + mExternalLocking = extBuffLocking; +} + void AppCallbackNotifier::copyAndSendPreviewFrame(CameraFrame* frame, int32_t msgType) { camera_memory_t* picture = NULL; @@ -805,7 +838,9 @@ void AppCallbackNotifier::copyAndSendPreviewFrame(CameraFrame* frame, int32_t ms } dest = &mPreviewBuffers[mPreviewBufCount]; - + if (mExternalLocking) { + lockBufferAndUpdatePtrs(frame); + } CAMHAL_LOGVB("%d:copy2Dto1D(%p, %p, %d, %d, %d, %d, %d,%s)", __LINE__, dest, @@ -857,6 +892,10 @@ void AppCallbackNotifier::copyAndSendPreviewFrame(CameraFrame* frame, int32_t ms mDataCb(msgType, mPreviewMemory, mPreviewBufCount, NULL, mCallbackCookie); } + if (mExternalLocking) { + unlockBufferAndUpdatePtrs(frame); + } + // increment for next buffer mPreviewBufCount = (mPreviewBufCount + 1) % AppCallbackNotifier::MAX_BUFFERS; } @@ -1131,7 +1170,9 @@ void AppCallbackNotifier::notifyFrame() bounds.top = 0; bounds.right = mVideoWidth; bounds.bottom = mVideoHeight; - + if (mExternalLocking) { + lockBufferAndUpdatePtrs(frame); + } void *y_uv[2]; mapper.lock((buffer_handle_t)vBuf, CAMHAL_GRALLOC_USAGE, bounds, y_uv); y_uv[1] = y_uv[0] + mVideoHeight*4096; @@ -1154,6 +1195,9 @@ void AppCallbackNotifier::notifyFrame() VT_resizeFrame_Video_opt2_lp(&input, &output, NULL, 0); mapper.unlock((buffer_handle_t)vBuf->opaque); + if (mExternalLocking) { + unlockBufferAndUpdatePtrs(frame); + } videoMetadataBuffer->metadataBufferType = (int) android::kMetadataBufferTypeCameraSource; /* FIXME remove cast */ videoMetadataBuffer->handle = (void *)vBuf->opaque; @@ -1181,10 +1225,15 @@ void AppCallbackNotifier::notifyFrame() CAMHAL_LOGEA("Error! One of the video buffers is NULL"); break; } - + if (mExternalLocking) { + lockBufferAndUpdatePtrs(frame); + } *reinterpret_cast<buffer_handle_t*>(fakebuf->data) = reinterpret_cast<buffer_handle_t>(frame->mBuffer->mapped); mDataCbTimestamp(frame->mTimestamp, CAMERA_MSG_VIDEO_FRAME, fakebuf, 0, mCallbackCookie); fakebuf->release(fakebuf); + if (mExternalLocking) { + unlockBufferAndUpdatePtrs(frame); + } } } } diff --git a/camera/CameraHal.cpp b/camera/CameraHal.cpp index 7754d51..369c398 100644 --- a/camera/CameraHal.cpp +++ b/camera/CameraHal.cpp @@ -2044,7 +2044,16 @@ status_t CameraHal::setPreviewWindow(struct preview_stream_ops *window) { // Need to create the display adapter since it has not been created // Create display adapter - mDisplayAdapter = new ANativeWindowDisplayAdapter(); + ANativeWindowDisplayAdapter* displayAdapter = new ANativeWindowDisplayAdapter(); + displayAdapter->setExternalLocking(mExternalLocking); + if (NULL != mAppCallbackNotifier.get()) { + mAppCallbackNotifier->setExternalLocking(mExternalLocking); + } else { + CAMHAL_LOGE("Can't apply locking policy on AppCallbackNotifier"); + CAMHAL_ASSERT(0); + } + + mDisplayAdapter = displayAdapter; #ifdef OMAP_ENHANCEMENT mDisplayAdapter->setExtendedOps(mExtendedPreviewStreamOps); #endif @@ -3991,6 +4000,8 @@ CameraHal::CameraHal(int cameraId) mCameraIndex = cameraId; + mExternalLocking = false; + LOG_FUNCTION_NAME_EXIT; } @@ -4679,6 +4690,11 @@ void CameraHal::getPreferredPreviewRes(int *width, int *height) LOG_FUNCTION_NAME_EXIT; } +void CameraHal::setExternalLocking(bool extBuffLocking) +{ + mExternalLocking = extBuffLocking; +} + void CameraHal::resetPreviewRes(android::CameraParameters *params) { LOG_FUNCTION_NAME; diff --git a/camera/inc/ANativeWindowDisplayAdapter.h b/camera/inc/ANativeWindowDisplayAdapter.h index 560e98d..eba91bb 100644 --- a/camera/inc/ANativeWindowDisplayAdapter.h +++ b/camera/inc/ANativeWindowDisplayAdapter.h @@ -86,6 +86,9 @@ public: virtual status_t maxQueueableBuffers(unsigned int& queueable); virtual status_t minUndequeueableBuffers(int& unqueueable); + // If set to true ANativeWindowDisplayAdapter will not lock/unlock graphic buffers + void setExternalLocking(bool extBuffLocking); + ///Class specific functions static void frameCallbackRelay(CameraFrame* caFrame); void frameCallback(CameraFrame* caFrame); @@ -173,6 +176,10 @@ private: const char *mPixelFormat; + //In case if we ,as example, using out buffers in Ducati Decoder + //DOMX will handle lock/unlock of graphic buffers + bool mUseExternalBufferLocking; + #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS //Used for calculating standby to first shot struct timeval mStandbyToShot; diff --git a/camera/inc/CameraHal.h b/camera/inc/CameraHal.h index a97ae96..e5e6fdf 100644 --- a/camera/inc/CameraHal.h +++ b/camera/inc/CameraHal.h @@ -725,6 +725,7 @@ public: void setVideoRes(int width, int height); void flushEventQueue(); + void setExternalLocking(bool extBuffLocking); //Internal class definitions class NotificationThread : public android::Thread { @@ -760,6 +761,8 @@ private: void copyAndSendPreviewFrame(CameraFrame* frame, int32_t msgType); size_t calculateBufferSize(size_t width, size_t height, const char *pixelFormat); const char* getContstantForPixelFormat(const char *pixelFormat); + void lockBufferAndUpdatePtrs(CameraFrame* frame); + void unlockBufferAndUpdatePtrs(CameraFrame* frame); private: mutable android::Mutex mLock; @@ -815,6 +818,8 @@ private: int mVideoWidth; int mVideoHeight; + bool mExternalLocking; + }; @@ -1242,6 +1247,9 @@ public: status_t storeMetaDataInBuffers(bool enable); + // Use external locking for graphic buffers + void setExternalLocking(bool extBuffLocking); + //@} /*--------------------Internal Member functions - Public---------------------------------*/ @@ -1504,6 +1512,8 @@ private: int mVideoHeight; android::String8 mCapModeBackup; + + bool mExternalLocking; }; } // namespace Camera |