summaryrefslogtreecommitdiff
path: root/camera/AppCallbackNotifier.cpp
diff options
context:
space:
mode:
authorTyler Luu <tluu@ti.com>2011-08-27 16:18:55 -0500
committerIliyan Malchev <malchev@google.com>2011-08-30 09:36:21 -0700
commit6c73fda9fdca5431e4e7911bb3171e36088a861e (patch)
tree8e1aabdfa00779b8097fdd5100a99d611fcfa083 /camera/AppCallbackNotifier.cpp
parent97db71f3a06c88c16f46fea8189f542dcde28f7f (diff)
downloadomap4-aah-6c73fda9fdca5431e4e7911bb3171e36088a861e.tar.gz
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 <tluu@ti.com>
Diffstat (limited to 'camera/AppCallbackNotifier.cpp')
-rw-r--r--camera/AppCallbackNotifier.cpp18
1 files changed, 14 insertions, 4 deletions
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 <ui/GraphicBuffer.h>
#include <ui/GraphicBufferMapper.h>
-
+#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);