am 17a80081: Merge change 5544 into donut
Merge commit '17a80081a42410f541a220ab7e6afc64fc6cc399' * commit '17a80081a42410f541a220ab7e6afc64fc6cc399': Pipe all the camera callbacks to Java to facilitate the addition
This commit is contained in:
committed by
The Android Open Source Project
commit
6034cb565c
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user