summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Android (Google) Code Review <android-gerrit@google.com> 2009-06-24 08:34:34 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2009-06-24 08:34:34 -0700
commit3d7b8d1aa6a362292f56defbe8fb2d5653f79282 (patch)
tree6b39af2cd67c60bbcef8092c3f6035924624ebfb /libs
parent544450b4eee175c78a1ca8647a3bfaca4aecf47a (diff)
parent5e27115995c4506dddf4f1271effd4fb4c935ad3 (diff)
Merge change 5158 into donut
* changes: Use a ref-counted callback interface for Camera. This allows the camera service to hang onto the callback interface until all callbacks have been processed. This prevents problems where pending callbacks in binder worker threads are processed after the Java camera object and its associated native resources have been released. Bug 1884362
Diffstat (limited to 'libs')
-rw-r--r--libs/ui/Camera.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/libs/ui/Camera.cpp b/libs/ui/Camera.cpp
index 661370040e44..1aa52452021e 100644
--- a/libs/ui/Camera.cpp
+++ b/libs/ui/Camera.cpp
@@ -337,9 +337,32 @@ void Camera::setErrorCallback(error_callback cb, void *cookie)
mErrorCallbackCookie = cookie;
}
+void Camera::setListener(const sp<CameraListener>& listener)
+{
+ Mutex::Autolock _l(mLock);
+ mListener = listener;
+}
+
+void Camera::setPreviewCallbackFlags(int flag)
+{
+ LOGV("setPreviewCallbackFlags");
+ sp <ICamera> c = mCamera;
+ if (c == 0) return;
+ mCamera->setPreviewCallbackFlag(flag);
+}
+
// callback from camera service
void Camera::notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
{
+ sp<CameraListener> listener;
+ {
+ Mutex::Autolock _l(mLock);
+ listener = mListener;
+ }
+ if (listener != NULL) {
+ listener->notify(msgType, ext1, ext2);
+ }
+
switch(msgType) {
case CAMERA_MSG_ERROR:
LOGV("errorCallback");
@@ -368,6 +391,15 @@ void Camera::notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
// callback from camera service when frame or image is ready
void Camera::dataCallback(int32_t msgType, const sp<IMemory>& dataPtr)
{
+ sp<CameraListener> listener;
+ {
+ Mutex::Autolock _l(mLock);
+ listener = mListener;
+ }
+ if (listener != NULL) {
+ listener->postData(msgType, dataPtr);
+ }
+
switch(msgType) {
case CAMERA_MSG_PREVIEW_FRAME:
LOGV("previewCallback");
@@ -401,6 +433,7 @@ void Camera::dataCallback(int32_t msgType, const sp<IMemory>& dataPtr)
void Camera::binderDied(const wp<IBinder>& who) {
LOGW("ICamera died");
+ notifyCallback(CAMERA_MSG_ERROR, DEAD_OBJECT, 0);
if (mErrorCallback) {
mErrorCallback(DEAD_OBJECT, mErrorCallbackCookie);
}