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;
@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) {
}
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);
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)
// 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