summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2010-06-10 13:32:16 +0800
committerChih-Chung Chang <chihchung@google.com>2010-06-11 16:47:33 +0800
commitb8bb78f54b48868465a9d69d65fda08524ab5ae1 (patch)
treefadbdd8dd989ce2b3b29cd780fabc91d7f98dd09 /core
parent2fd73a452268d2acb6e72a1d23a422085ed3c510 (diff)
downloadframeworks_base-b8bb78f54b48868465a9d69d65fda08524ab5ae1.zip
frameworks_base-b8bb78f54b48868465a9d69d65fda08524ab5ae1.tar.gz
frameworks_base-b8bb78f54b48868465a9d69d65fda08524ab5ae1.tar.bz2
Change camera interface to support multiple cameras.
Change-Id: Ie88fe706d2278acf762eca87780de349434778a4
Diffstat (limited to 'core')
-rw-r--r--core/java/android/hardware/Camera.java58
-rw-r--r--core/jni/android_hardware_Camera.cpp23
2 files changed, 78 insertions, 3 deletions
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index 5c96a44..7640cc1 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -90,8 +90,44 @@ public class Camera {
public native static int getNumberOfCameras();
/**
+ * Returns the information about the camera.
+ * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
+ * @hide
+ */
+ public native static void getCameraInfo(int cameraId, CameraInfo cameraInfo);
+
+ /**
+ * Information about a camera
+ * @hide
+ */
+ public static class CameraInfo {
+ public static final int CAMERA_FACING_BACK = 0;
+ public static final int CAMERA_FACING_FRONT = 1;
+
+ /**
+ * The direction that the camera faces to. It should be
+ * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
+ */
+ public int mFacing;
+
+ /**
+ * The orientation of the camera image. The value is the angle that the
+ * camera image needs to be rotated clockwise so it shows correctly on
+ * the display in its natural orientation. It should be 0, 90, 180, or 270.
+ *
+ * For example, suppose a device has a naturally tall screen, but the camera
+ * sensor is mounted in landscape. If the top side of the camera sensor is
+ * aligned with the right edge of the display in natural orientation, the
+ * value should be 90.
+ *
+ * @see #setDisplayOrientation(int)
+ */
+ public int mOrientation;
+ };
+
+ /**
* Returns a new Camera object.
- * If {@link #getNumberOfCameras()} returns N, the valid is is 0 to N-1.
+ * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
* The id 0 is the default camera.
* @hide
*/
@@ -100,10 +136,16 @@ public class Camera {
}
/**
+ * The id for the default camera.
+ * @hide
+ */
+ public static int CAMERA_ID_DEFAULT = 0;
+
+ /**
* Returns a new Camera object. This returns the default camera.
*/
public static Camera open() {
- return new Camera(0);
+ return new Camera(CAMERA_ID_DEFAULT);
}
Camera(int cameraId) {
@@ -581,6 +623,18 @@ public class Camera {
* {@link PreviewCallback#onPreviewFrame}. This method is not allowed to
* be called during preview.
*
+ * If you want to make the camera image show in the same orientation as
+ * the display, you can use <p>
+ * <pre>
+ * android.view.Display display;
+ * android.hardware.Camera.CameraInfo cameraInfo;
+ *
+ * int rotation = getWindowManager().getDefaultDisplay().getRotation();
+ * android.hardware.Camera.getCameraInfo(id, cameraInfo);
+ * int degrees = (cameraInfo.mOrientation - rotation + 360) % 360;
+ *
+ * setDisplayOrientation(degrees);
+ * </pre>
* @param degrees the angle that the picture will be rotated clockwise.
* Valid values are 0, 90, 180, and 270. The starting
* position is 0 (landscape).
diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp
index c363156..c784974 100644
--- a/core/jni/android_hardware_Camera.cpp
+++ b/core/jni/android_hardware_Camera.cpp
@@ -34,6 +34,8 @@ using namespace android;
struct fields_t {
jfieldID context;
jfieldID surface;
+ jfieldID facing;
+ jfieldID orientation;
jmethodID post_event;
};
@@ -293,6 +295,20 @@ static jint android_hardware_Camera_getNumberOfCameras(JNIEnv *env, jobject thiz
return Camera::getNumberOfCameras();
}
+static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz,
+ jint cameraId, jobject info_obj)
+{
+ CameraInfo cameraInfo;
+ status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
+ if (rc != NO_ERROR) {
+ jniThrowException(env, "java/lang/RuntimeException",
+ "Fail to get camera info");
+ return;
+ }
+ env->SetIntField(info_obj, fields.facing, cameraInfo.facing);
+ env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation);
+}
+
// connect to camera service
static void android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz,
jobject weak_this, jint cameraId)
@@ -575,6 +591,9 @@ static JNINativeMethod camMethods[] = {
{ "getNumberOfCameras",
"()I",
(void *)android_hardware_Camera_getNumberOfCameras },
+ { "getCameraInfo",
+ "(ILandroid/hardware/Camera$CameraInfo;)V",
+ (void*)android_hardware_Camera_getCameraInfo },
{ "native_setup",
"(Ljava/lang/Object;I)V",
(void*)android_hardware_Camera_native_setup },
@@ -668,7 +687,9 @@ int register_android_hardware_Camera(JNIEnv *env)
{
field fields_to_find[] = {
{ "android/hardware/Camera", "mNativeContext", "I", &fields.context },
- { "android/view/Surface", ANDROID_VIEW_SURFACE_JNI_ID, "I", &fields.surface }
+ { "android/view/Surface", ANDROID_VIEW_SURFACE_JNI_ID, "I", &fields.surface },
+ { "android/hardware/Camera$CameraInfo", "mFacing", "I", &fields.facing },
+ { "android/hardware/Camera$CameraInfo", "mOrientation", "I", &fields.orientation },
};
if (find_fields(env, fields_to_find, NELEM(fields_to_find)) < 0)