diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-06-26 14:02:10 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-06-26 14:02:10 -0700 |
commit | 17a80081a42410f541a220ab7e6afc64fc6cc399 (patch) | |
tree | a4fe51dcf8e8caddc7cba9ebbc2c98606cf44950 | |
parent | 72eb0acad5cffc57ce5006f6deab29ee259e461e (diff) | |
parent | c62f9bd13327937aa2d2f20b44215397120634c1 (diff) | |
download | frameworks_base-17a80081a42410f541a220ab7e6afc64fc6cc399.zip frameworks_base-17a80081a42410f541a220ab7e6afc64fc6cc399.tar.gz frameworks_base-17a80081a42410f541a220ab7e6afc64fc6cc399.tar.bz2 |
Merge change 5544 into donut
* changes:
Pipe all the camera callbacks to Java to facilitate the addition of new features. This will make it easy to add things like zoom callbacks without modifying the entire camera stack. Bug 1837832.
-rw-r--r-- | core/java/android/hardware/Camera.java | 30 | ||||
-rw-r--r-- | core/jni/android_hardware_Camera.cpp | 48 | ||||
-rw-r--r-- | include/ui/Camera.h | 10 |
3 files changed, 26 insertions, 62 deletions
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java index ca579b6..09fbc97 100644 --- a/core/java/android/hardware/Camera.java +++ b/core/java/android/hardware/Camera.java @@ -39,13 +39,16 @@ import android.os.Message; public class Camera { private static final String TAG = "Camera"; - // These match the enum in libs/android_runtime/android_hardware_Camera.cpp - private static final int SHUTTER_CALLBACK = 0; - private static final int RAW_PICTURE_CALLBACK = 1; - private static final int JPEG_PICTURE_CALLBACK = 2; - private static final int PREVIEW_CALLBACK = 3; - private static final int AUTOFOCUS_CALLBACK = 4; - private static final int ERROR_CALLBACK = 5; + // These match the enums in frameworks/base/include/ui/Camera.h + private static final int CAMERA_MSG_ERROR = 0; + private static final int CAMERA_MSG_SHUTTER = 1; + private static final int CAMERA_MSG_FOCUS = 2; + private static final int CAMERA_MSG_ZOOM = 3; + private static final int CAMERA_MSG_PREVIEW_FRAME = 4; + private static final int CAMERA_MSG_VIDEO_FRAME = 5; + private static final int CAMERA_MSG_POSTVIEW_FRAME = 6; + private static final int CAMERA_MSG_RAW_IMAGE = 7; + private static final int CAMERA_MSG_COMPRESSED_IMAGE = 8; private int mNativeContext; // accessed by native methods private EventHandler mEventHandler; @@ -231,22 +234,23 @@ public class Camera { @Override public void handleMessage(Message msg) { switch(msg.what) { - case SHUTTER_CALLBACK: + case CAMERA_MSG_SHUTTER: if (mShutterCallback != null) { mShutterCallback.onShutter(); } return; - case RAW_PICTURE_CALLBACK: + + case CAMERA_MSG_RAW_IMAGE: if (mRawImageCallback != null) mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera); return; - case JPEG_PICTURE_CALLBACK: + case CAMERA_MSG_COMPRESSED_IMAGE: if (mJpegCallback != null) mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera); return; - case PREVIEW_CALLBACK: + case CAMERA_MSG_PREVIEW_FRAME: if (mPreviewCallback != null) { mPreviewCallback.onPreviewFrame((byte[])msg.obj, mCamera); if (mOneShot) { @@ -255,12 +259,12 @@ public class Camera { } return; - case AUTOFOCUS_CALLBACK: + case CAMERA_MSG_FOCUS: if (mAutoFocusCallback != null) mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera); return; - case ERROR_CALLBACK: + case CAMERA_MSG_ERROR : Log.e(TAG, "Error " + msg.arg1); if (mErrorCallback != null) mErrorCallback.onError(msg.arg1, mCamera); diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp index b07ba7d..8e48b38 100644 --- a/core/jni/android_hardware_Camera.cpp +++ b/core/jni/android_hardware_Camera.cpp @@ -125,37 +125,8 @@ void JNICameraContext::notify(int32_t msgType, int32_t ext1, int32_t ext2) return; } JNIEnv *env = AndroidRuntime::getJNIEnv(); - - // parse message - switch (msgType) { - case CAMERA_MSG_ERROR: - LOGV("errorCallback"); - int error; - switch (ext1) { - case DEAD_OBJECT: - error = kCameraErrorMediaServer; - break; - default: - error = kCameraErrorUnknown; - break; - } - env->CallStaticVoidMethod(mCameraJClass, fields.post_event, - mCameraJObjectWeak, kErrorCallback, error, 0, NULL); - break; - case CAMERA_MSG_FOCUS: - LOGV("autoFocusCallback"); - env->CallStaticVoidMethod(mCameraJClass, fields.post_event, - mCameraJObjectWeak, kAutoFocusCallback, ext1, 0, NULL); - break; - case CAMERA_MSG_SHUTTER: - LOGV("shutterCallback"); - env->CallStaticVoidMethod(mCameraJClass, fields.post_event, - mCameraJObjectWeak, kShutterCallback, 0, 0, NULL); - break; - default: - LOGV("notifyCallback(%d, %d, %d)", msgType, ext1, ext2); - break; - } + env->CallStaticVoidMethod(mCameraJClass, fields.post_event, + mCameraJObjectWeak, msgType, ext1, ext2); } void JNICameraContext::copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType) @@ -203,27 +174,20 @@ void JNICameraContext::postData(int32_t msgType, const sp<IMemory>& dataPtr) // return data based on callback type switch(msgType) { - case CAMERA_MSG_PREVIEW_FRAME: - LOGV("previewCallback"); - copyAndPost(env, dataPtr, kPreviewCallback); - break; case CAMERA_MSG_VIDEO_FRAME: - LOGV("recordingCallback"); + // should never happen break; + // don't return raw data to Java case CAMERA_MSG_RAW_IMAGE: LOGV("rawCallback"); env->CallStaticVoidMethod(mCameraJClass, fields.post_event, - mCameraJObjectWeak, kRawCallback, 0, 0, NULL); - break; - case CAMERA_MSG_COMPRESSED_IMAGE: - LOGV("jpegCallback"); - copyAndPost(env, dataPtr, kJpegCallback); + mCameraJObjectWeak, msgType, 0, 0, NULL); break; default: LOGV("dataCallback(%d, %p)", msgType, dataPtr.get()); + copyAndPost(env, dataPtr, msgType); break; } - } // connect to camera service diff --git a/include/ui/Camera.h b/include/ui/Camera.h index bbc21c4..97e0e90 100644 --- a/include/ui/Camera.h +++ b/include/ui/Camera.h @@ -63,16 +63,12 @@ namespace android { #define FRAME_CALLBACK_FLAG_CAMERA 0x05 #define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07 -// msgType in notifyCallback function +// msgType in notifyCallback and dataCallback functions enum { - CAMERA_MSG_ERROR, + CAMERA_MSG_ERROR = 0, CAMERA_MSG_SHUTTER, CAMERA_MSG_FOCUS, - CAMERA_MSG_ZOOM -}; - -// msgType in dataCallback function -enum { + CAMERA_MSG_ZOOM, CAMERA_MSG_PREVIEW_FRAME, CAMERA_MSG_VIDEO_FRAME, CAMERA_MSG_POSTVIEW_FRAME, |