From 6c73fda9fdca5431e4e7911bb3171e36088a861e Mon Sep 17 00:00:00 2001 From: Tyler Luu Date: Sat, 27 Aug 2011 16:18:55 -0500 Subject: CameraHal: Lock buffers sent to FrameProvider Use GraphicBufferMapper API to lock buffer before sending to FrameProvider to ensure there isn't simultaneous accesses to bufffer by SGX Change-Id: Ifbb5c88bac49b1b494bd984137b523d35f4a6f57 Signed-off-by: Tyler Luu --- camera/AppCallbackNotifier.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'camera/AppCallbackNotifier.cpp') diff --git a/camera/AppCallbackNotifier.cpp b/camera/AppCallbackNotifier.cpp index 1c5482d..68ab850 100644 --- a/camera/AppCallbackNotifier.cpp +++ b/camera/AppCallbackNotifier.cpp @@ -26,7 +26,7 @@ #include #include - +#define LOCK_BUFFER_TRIES 5 namespace android { const int AppCallbackNotifier::NOTIFIER_TIMEOUT = -1; @@ -319,6 +319,7 @@ static void copy2Dto1D(void *dst, unsigned char *bufferDstEnd, *bufferSrcEnd; uint16_t *bufferSrc_UV; void *y_uv[2]; //y_uv[0]=> y pointer; y_uv[1]=>uv pointer + int lock_try_count = 0; GraphicBufferMapper &mapper = GraphicBufferMapper::get(); Rect bounds; @@ -329,9 +330,18 @@ static void copy2Dto1D(void *dst, bounds.bottom = height; // get the y & uv pointers from the gralloc handle; - mapper.lock((buffer_handle_t)src, - GRALLOC_USAGE_SW_READ_RARELY | GRALLOC_USAGE_SW_WRITE_NEVER, - bounds, y_uv); + while (mapper.lock((buffer_handle_t)src, + GRALLOC_USAGE_SW_READ_RARELY | GRALLOC_USAGE_SW_WRITE_NEVER, + bounds, y_uv) < 0) { + // give up after LOCK_BUFFER_TRIES (defined in this file) + if (++lock_try_count > LOCK_BUFFER_TRIES) { + return; + } + + // sleep for 50 ms before we try to lock again. + // somebody else has a write lock on this buffer + usleep(50000); + } CAMHAL_LOGDB("copy2Dto1D() y= %p ; uv=%p.",y_uv[0],y_uv[1]); CAMHAL_LOGDB("pixelFormat,= %d; offset=%d",*pixelFormat,offset); -- cgit v1.2.3