summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHashcode <hashcode0f@gmail.com>2015-02-02 12:00:15 -0800
committerHashcode <hashcode0f@gmail.com>2015-02-02 12:00:15 -0800
commit70a72e669f35ed4b7331579068c78393255b9d24 (patch)
tree566dd08787a9da93e519b7cfc23af025dbeb596b
parent8071929a1c6d2c7cbe3d82e3bbe796182c45de78 (diff)
downloadhardware_ti_omap4-70a72e669f35ed4b7331579068c78393255b9d24.zip
hardware_ti_omap4-70a72e669f35ed4b7331579068c78393255b9d24.tar.gz
hardware_ti_omap4-70a72e669f35ed4b7331579068c78393255b9d24.tar.bz2
remove cpcam support
-rw-r--r--Android.mk1
-rw-r--r--cpcam/Android.mk75
-rw-r--r--cpcam/README.txt106
-rw-r--r--cpcam/com.ti.omap.android.cpcam.xml38
-rw-r--r--cpcam/java/com/ti/omap/android/cpcam/CPCam.java3726
-rw-r--r--cpcam/java/com/ti/omap/android/cpcam/CPCamBufferQueue.java245
-rw-r--r--cpcam/java/com/ti/omap/android/cpcam/CPCamMetadata.java453
-rw-r--r--cpcam/jni/Android.mk69
-rw-r--r--cpcam/jni/com_ti_omap_android_cpcam_CPCam.cpp1226
-rw-r--r--cpcam/jni/com_ti_omap_android_cpcam_CPCamBufferQueue.cpp447
-rw-r--r--cpcam/jni/com_ti_omap_android_cpcam_CPCamMetadata.cpp629
11 files changed, 0 insertions, 7015 deletions
diff --git a/Android.mk b/Android.mk
index ad21b5f..ab7d6f8 100644
--- a/Android.mk
+++ b/Android.mk
@@ -37,7 +37,6 @@ endif
include $(call first-makefiles-under,$(LOCAL_PATH))
else
LOCAL_PATH:= $(call my-dir)
-include $(LOCAL_PATH)/cpcam/Android.mk
$(clear-android-api-vars)
diff --git a/cpcam/Android.mk b/cpcam/Android.mk
deleted file mode 100644
index d3961c6..0000000
--- a/cpcam/Android.mk
+++ /dev/null
@@ -1,75 +0,0 @@
-# Copyright (c) 2010, Texas Instruments Incorporated
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# Neither the name of Texas Instruments Incorporated nor the names of
-# its contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-# This makefile shows how to build your own shared library that can be
-# shipped on the system of a phone, and included additional examples of
-# including JNI code with the library and writing client applications against it.
-
-ifdef OMAP_ENHANCEMENT_CPCAM
-
-LOCAL_PATH := $(call my-dir)
-
-# the library
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
- $(call all-subdir-java-files)
-
-LOCAL_MODULE_TAGS := optional
-
-# This is the target being built.
-LOCAL_MODULE:= com.ti.omap.android.cpcam
-
-include $(BUILD_JAVA_LIBRARY)
-
-# the documentation
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files) $(call all-subdir-html-files)
-
-LOCAL_MODULE:= cpcam
-LOCAL_DROIDDOC_OPTIONS := com.ti.omap.android.cpcam
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_DROIDDOC_USE_STANDARD_DOCLET := true
-
-include $(BUILD_DROIDDOC)
-
-# The JNI component
-# ============================================================
-# Also build all of the sub-targets under this one: the library's
-# associated JNI code, and a sample client of the library.
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
-
-endif
diff --git a/cpcam/README.txt b/cpcam/README.txt
deleted file mode 100644
index 0b3d8c1..0000000
--- a/cpcam/README.txt
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2010, Texas Instruments Incorporated
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-Platform Library Example
-~~~~~~~~~~~~~~~~~~~~~~~~
-
-
-This directory contains a full example of writing your own Android platform
-shared library, without changing the Android framework. It also shows how to
-write JNI code for incorporating native code into the library, and a client
-application that uses the library.
-
-This example is ONLY for people working with the open source platform to
-create a system image that will be delivered on a device which will include
-a custom library as shown here. It can not be used to create a third party
-shared library, which is not currently supported in Android.
-
-To declare your library to the framework, you must place a file with a .xml
-extension in the /system/etc/permissions directory with the following contents:
-
-<?xml version="1.0" encoding="utf-8"?>
-<permissions>
- <library name="com.example.android.platform_library"
- file="/system/framework/com.example.android.platform_library.jar"/>
-</permissions>
-
-There are three major parts of this example, supplying three distinct
-build targets and corresponding build outputs:
-
-
-com.example.android.platform_library
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-The top-level Android.mk defines the rules to build the shared library itself,
-whose target is "com.example.android.platform_library". The code for this
-library lives under java/.
-
-Note that the product for this library is a raw .jar file, NOT a .apk, which
-means there is no manifest or resources associated with the library.
-Unfortunately this means that if you need any resources for the library, such
-as drawables or layout files, you will need to add these to the core framework
-resources under frameworks/base/res. Please make sure when doing this that
-you do not make any of these resources public, they should not become part of
-the Android API. In the future we will allow shared libraries to have their
-own resources.
-
-Other than that, the library is very straight-forward, and you can write
-basically whatever code you want. You can also put code in other Java
-namespaces -- the namespace given in the <library> tag above is just the
-public unique name by which clients will link to your library, but once this
-link happens all of the Java namespaces in that library will be available
-to the client.
-
-
-libplatform_library_jni
-~~~~~~~~~~~~~~~~~~~~~~~
-
-This is an optional example of how to write JNI code associated with a
-shared library. This code lives under jni/. The jni/Android.mk file defines
-the rules for building the final .so in which the code lives. This example
-provides everything needed to hook up the native code with the Java library
-and call through to it, plus a very simple JNI call.
-
-
-PlatformLibraryClient
-~~~~~~~~~~~~~~~~~~~~~
-
-This shows an example of how you can write client applications for your new
-shared library. This code lives under client/. Note that the example is
-simply a regular Android .apk, like all of the other .apks created by the
-build system. The only two special things needed to use your library are:
-
-- A LOCAL_JAVA_LIBRARIES line in the Android.mk to have the build system link
-against your shared library.
-
-- A <uses-library> line in the AndroidManifest.xml to have the runtime load
-your library into the application.
diff --git a/cpcam/com.ti.omap.android.cpcam.xml b/cpcam/com.ti.omap.android.cpcam.xml
deleted file mode 100644
index e31cf7e..0000000
--- a/cpcam/com.ti.omap.android.cpcam.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- * Copyright (c) 2010, Texas Instruments Incorporated
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
--->
-
-<permissions>
- <library name="com.ti.omap.android.cpcam"
- file="/system/framework/com.ti.omap.android.cpcam.jar"/>
-</permissions>
diff --git a/cpcam/java/com/ti/omap/android/cpcam/CPCam.java b/cpcam/java/com/ti/omap/android/cpcam/CPCam.java
deleted file mode 100644
index 9865e70..0000000
--- a/cpcam/java/com/ti/omap/android/cpcam/CPCam.java
+++ /dev/null
@@ -1,3726 +0,0 @@
-/*
- * Copyright (c) 2010, Texas Instruments Incorporated
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package com.ti.omap.android.cpcam;
-
-import android.annotation.SdkConstant;
-import android.annotation.SdkConstant.SdkConstantType;
-import android.graphics.ImageFormat;
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.graphics.SurfaceTexture;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * The CPCam class is essentially a copycat of the standard Camera class, extended with specific cpcam methods:
- * takePicture( ..., shotParams);
- * setBufferSource();
- * reprocess();
- */
-public class CPCam {
- static {
- /*
- * Load the library. If it's already loaded, this does nothing.
- */
- System.loadLibrary("cpcam_jni");
- }
-
- private static final String TAG = "CPCam";
-
- // These match the enums in frameworks/base/include/camera/Camera.h
- private static final int CAMERA_MSG_ERROR = 0x001;
- private static final int CAMERA_MSG_SHUTTER = 0x002;
- private static final int CAMERA_MSG_FOCUS = 0x004;
- private static final int CAMERA_MSG_ZOOM = 0x008;
- private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010;
- private static final int CAMERA_MSG_VIDEO_FRAME = 0x020;
- private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040;
- private static final int CAMERA_MSG_RAW_IMAGE = 0x080;
- private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
- private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
- private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
- private static final int CAMERA_MSG_ALL_MSGS = 0x4FF;
-
- private static final int CAMERA_MSG_FOCUS_MOVE = 0x800;
- private static final int CAMERA_MSG_COMPRESSED_BURST_IMAGE = 0x1000; // dataCallback
- private static final int CAMERA_MSG_RAW_BURST = 0x2000; // dataCallback
-
- private int mNativeContext; // accessed by native methods
- private EventHandler mEventHandler;
- private ShutterCallback mShutterCallback;
- private PictureCallback mRawImageCallback;
- private PictureCallback mJpegCallback;
- private PreviewCallback mPreviewCallback;
- private PictureCallback mPostviewCallback;
- private AutoFocusCallback mAutoFocusCallback;
- private AutoFocusMoveCallback mAutoFocusMoveCallback;
- private OnZoomChangeListener mZoomListener;
- private FaceDetectionListener mFaceListener;
- private MetadataListener mMetadataListener;
- private ErrorCallback mErrorCallback;
- private boolean mOneShot;
- private boolean mWithBuffer;
- private boolean mFaceDetectionRunning = false;
- private Object mAutoFocusCallbackLock = new Object();
-
- /**
- * Broadcast Action: A new picture is taken by the camera, and the entry of
- * the picture has been added to the media store.
- * {@link android.content.Intent#getData} is URI of the picture.
- */
- @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
- public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
-
- /**
- * Broadcast Action: A new video is recorded by the camera, and the entry
- * of the video has been added to the media store.
- * {@link android.content.Intent#getData} is URI of the video.
- */
- @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
- public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
-
- /**
- * Hardware face detection. It does not use much CPU.
- */
- private static final int CAMERA_FACE_DETECTION_HW = 0;
-
- /**
- * Software face detection. It uses some CPU.
- */
- private static final int CAMERA_FACE_DETECTION_SW = 1;
-
- /**
- * Returns the number of physical cameras available on this device.
- */
- public native static int getNumberOfCameras();
-
- /**
- * Returns the information about a particular camera.
- * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
- */
- public native static void getCameraInfo(int cameraId, CameraInfo cameraInfo);
-
- /**
- * Information about a camera
- */
- public static class CameraInfo {
- /**
- * The facing of the camera is opposite to that of the screen.
- */
- public static final int CAMERA_FACING_BACK = 0;
-
- /**
- * The facing of the camera is the same as that of the screen.
- */
- public static final int CAMERA_FACING_FRONT = 1;
-
- /**
- * The direction that the camera faces. It should be
- * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
- */
- public int facing;
-
- /**
- * <p>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.</p>
- *
- * <p>For example, suppose a device has a naturally tall screen. The
- * back-facing camera sensor is mounted in landscape. You are looking at
- * the screen. If the top side of the camera sensor is aligned with the
- * right edge of the screen in natural orientation, the value should be
- * 90. If the top side of a front-facing camera sensor is aligned with
- * the right of the screen, the value should be 270.</p>
- *
- * @see #setDisplayOrientation(int)
- * @see Parameters#setRotation(int)
- * @see Parameters#setPreviewSize(int, int)
- * @see Parameters#setPictureSize(int, int)
- * @see Parameters#setJpegThumbnailSize(int, int)
- */
- public int orientation;
- };
-
- /**
- * Creates a new Camera object to access a particular hardware camera. If
- * the same camera is opened by other applications, this will throw a
- * RuntimeException.
- *
- * <p>You must call {@link #release()} when you are done using the camera,
- * otherwise it will remain locked and be unavailable to other applications.
- *
- * <p>Your application should only have one Camera object active at a time
- * for a particular hardware camera.
- *
- * <p>Callbacks from other methods are delivered to the event loop of the
- * thread which called open(). If this thread has no event loop, then
- * callbacks are delivered to the main application event loop. If there
- * is no main application event loop, callbacks are not delivered.
- *
- * <p class="caution"><b>Caution:</b> On some devices, this method may
- * take a long time to complete. It is best to call this method from a
- * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
- * blocking the main application UI thread.
- *
- * @param cameraId the hardware camera to access, between 0 and
- * {@link #getNumberOfCameras()}-1.
- * @return a new Camera object, connected, locked and ready for use.
- * @throws RuntimeException if opening the camera fails (for example, if the
- * camera is in use by another process or device policy manager has
- * disabled the camera).
- * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
- */
- public static CPCam open(int cameraId) {
- return new CPCam(cameraId);
- }
-
- /**
- * Creates a new Camera object to access the first back-facing camera on the
- * device. If the device does not have a back-facing camera, this returns
- * null.
- * @see #open(int)
- */
- public static CPCam open() {
- int numberOfCameras = getNumberOfCameras();
- CameraInfo cameraInfo = new CameraInfo();
- for (int i = 0; i < numberOfCameras; i++) {
- getCameraInfo(i, cameraInfo);
- if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
- return new CPCam(i);
- }
- }
- return null;
- }
-
- CPCam(int cameraId) {
- mShutterCallback = null;
- mRawImageCallback = null;
- mJpegCallback = null;
- mPreviewCallback = null;
- mPostviewCallback = null;
- mZoomListener = null;
-
- Looper looper;
- if ((looper = Looper.myLooper()) != null) {
- mEventHandler = new EventHandler(this, looper);
- } else if ((looper = Looper.getMainLooper()) != null) {
- mEventHandler = new EventHandler(this, looper);
- } else {
- mEventHandler = null;
- }
-
- native_setup(new WeakReference<CPCam>(this), cameraId);
- }
-
- /**
- * An empty Camera for testing purpose.
- */
- CPCam() {
- }
-
- protected void finalize() {
- release();
- }
-
- private native final void native_setup(Object camera_this, int cameraId);
- private native final void native_release();
-
-
- /**
- * Disconnects and releases the Camera object resources.
- *
- * <p>You must call this as soon as you're done with the Camera object.</p>
- */
- public final void release() {
- native_release();
- mFaceDetectionRunning = false;
- }
-
- /**
- * Unlocks the camera to allow another process to access it.
- * Normally, the camera is locked to the process with an active Camera
- * object until {@link #release()} is called. To allow rapid handoff
- * between processes, you can call this method to release the camera
- * temporarily for another process to use; once the other process is done
- * you can call {@link #reconnect()} to reclaim the camera.
- *
- * <p>This must be done before calling
- * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
- * called after recording starts.
- *
- * <p>If you are not recording video, you probably do not need this method.
- *
- * @throws RuntimeException if the camera cannot be unlocked.
- */
- public native final void unlock();
-
- /**
- * Re-locks the camera to prevent other processes from accessing it.
- * Camera objects are locked by default unless {@link #unlock()} is
- * called. Normally {@link #reconnect()} is used instead.
- *
- * <p>Since API level 14, camera is automatically locked for applications in
- * {@link android.media.MediaRecorder#start()}. Applications can use the
- * camera (ex: zoom) after recording starts. There is no need to call this
- * after recording starts or stops.
- *
- * <p>If you are not recording video, you probably do not need this method.
- *
- * @throws RuntimeException if the camera cannot be re-locked (for
- * example, if the camera is still in use by another process).
- */
- public native final void lock();
-
- /**
- * Reconnects to the camera service after another process used it.
- * After {@link #unlock()} is called, another process may use the
- * camera; when the process is done, you must reconnect to the camera,
- * which will re-acquire the lock and allow you to continue using the
- * camera.
- *
- * <p>Since API level 14, camera is automatically locked for applications in
- * {@link android.media.MediaRecorder#start()}. Applications can use the
- * camera (ex: zoom) after recording starts. There is no need to call this
- * after recording starts or stops.
- *
- * <p>If you are not recording video, you probably do not need this method.
- *
- * @throws IOException if a connection cannot be re-established (for
- * example, if the camera is still in use by another process).
- */
- public native final void reconnect() throws IOException;
-
- /**
- * Sets the {@link Surface} to be used for live preview.
- * Either a surface or surface texture is necessary for preview, and
- * preview is necessary to take pictures. The same surface can be re-set
- * without harm. Setting a preview surface will un-set any preview surface
- * texture that was set via {@link #setPreviewTexture}.
- *
- * <p>The {@link SurfaceHolder} must already contain a surface when this
- * method is called. If you are using {@link android.view.SurfaceView},
- * you will need to register a {@link SurfaceHolder.Callback} with
- * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
- * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
- * calling setPreviewDisplay() or starting preview.
- *
- * <p>This method must be called before {@link #startPreview()}. The
- * one exception is that if the preview surface is not set (or set to null)
- * before startPreview() is called, then this method may be called once
- * with a non-null parameter to set the preview surface. (This allows
- * camera setup and surface creation to happen in parallel, saving time.)
- * The preview surface may not otherwise change while preview is running.
- *
- * @param holder containing the Surface on which to place the preview,
- * or null to remove the preview surface
- * @throws IOException if the method fails (for example, if the surface
- * is unavailable or unsuitable).
- */
- public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
- if (holder != null) {
- setPreviewDisplay(holder.getSurface());
- } else {
- setPreviewDisplay((Surface)null);
- }
- }
-
- private native final void setPreviewDisplay(Surface surface) throws IOException;
-
- /**
- * Sets the {@link SurfaceTexture} to be used for live preview.
- * Either a surface or surface texture is necessary for preview, and
- * preview is necessary to take pictures. The same surface texture can be
- * re-set without harm. Setting a preview surface texture will un-set any
- * preview surface that was set via {@link #setPreviewDisplay}.
- *
- * <p>This method must be called before {@link #startPreview()}. The
- * one exception is that if the preview surface texture is not set (or set
- * to null) before startPreview() is called, then this method may be called
- * once with a non-null parameter to set the preview surface. (This allows
- * camera setup and surface creation to happen in parallel, saving time.)
- * The preview surface texture may not otherwise change while preview is
- * running.
- *
- * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
- * SurfaceTexture set as the preview texture have an unspecified zero point,
- * and cannot be directly compared between different cameras or different
- * instances of the same camera, or across multiple runs of the same
- * program.
- *
- * <p>If you are using the preview data to create video or still images,
- * strongly consider using {@link android.media.MediaActionSound} to
- * properly indicate image capture or recording start/stop to the user.</p>
- *
- * @see android.media.MediaActionSound
- * @see android.graphics.SurfaceTexture
- * @see android.view.TextureView
- * @param surfaceTexture the {@link SurfaceTexture} to which the preview
- * images are to be sent or null to remove the current preview surface
- * texture
- * @throws IOException if the method fails (for example, if the surface
- * texture is unavailable or unsuitable).
- */
- public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
-
- /**
- * Sets the {@link SurfaceTexture} to be used for tap-out.
- * This is used in conjuntion with cp-cam mode.
- *
- * @param surfaceTexture the {@link SurfaceTexture} to which the tap-out
- * frame will be sent
- * @throws IOException if the method fails (for example, if the surface
- * texture is unavailable or unsuitable).
- */
- public native final void setBufferSource(CPCamBufferQueue tapIn, CPCamBufferQueue tapOut) throws IOException;
-
- /**
- * Releases the {@link SurfaceTexture}s used for tap-out and tap-in.
- * This is used in conjuntion with cp-cam mode.
- *
- * @param tapIn surfaceTexture the {@link SurfaceTexture} to be cleared
- * @param tapOut surfaceTexture the {@link SurfaceTexture} to be cleared
- * @throws IOException if the method fails (for example, if the surface
- * texture is unavailable or unsuitable).
- */
- public native final void releaseBufferSource(CPCamBufferQueue tapIn, CPCamBufferQueue tapOut) throws IOException;
-
- /**
- * Sets the {@link SurfaceTexture} to be used for tap-out.
- * This is used in conjuntion with cp-cam mode.
- *
- * @param surfaceTexture the {@link SurfaceTexture} to which the tap-out
- * frame will be sent
- * @throws IOException if the method fails (for example, if the surface
- * texture is unavailable or unsuitable).
- */
- public final void reprocess(Parameters params) throws IOException {
- int msgType = CAMERA_MSG_COMPRESSED_IMAGE |
- CAMERA_MSG_RAW_IMAGE |
- CAMERA_MSG_RAW_BURST;
-
- native_reprocess(msgType, params.flatten());
- }
- public native final void native_reprocess(int msgType, String ShotParams) throws IOException;
-
- /**
- * Callback interface used to deliver copies of preview frames as
- * they are displayed.
- *
- * @see #setPreviewCallback(Camera.PreviewCallback)
- * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
- * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
- * @see #startPreview()
- */
- public interface PreviewCallback
- {
- /**
- * Called as preview frames are displayed. This callback is invoked
- * on the event thread {@link #open(int)} was called from.
- *
- * <p>If using the {@link android.graphics.ImageFormat#YV12} format,
- * refer to the equations in {@link Camera.Parameters#setPreviewFormat}
- * for the arrangement of the pixel data in the preview callback
- * buffers.
- *
- * @param data the contents of the preview frame in the format defined
- * by {@link android.graphics.ImageFormat}, which can be queried
- * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
- * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
- * is never called, the default will be the YCbCr_420_SP
- * (NV21) format.
- * @param camera the Camera service object.
- */
- void onPreviewFrame(byte[] data, CPCam camera);
- };
-
- /**
- * Starts capturing and drawing preview frames to the screen.
- * Preview will not actually start until a surface is supplied
- * with {@link #setPreviewDisplay(SurfaceHolder)} or
- * {@link #setPreviewTexture(SurfaceTexture)}.
- *
- * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
- * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
- * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
- * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
- * will be called when preview data becomes available.
- */
- public native final void startPreview();
-
- /**
- * Stops capturing and drawing preview frames to the surface, and
- * resets the camera for a future call to {@link #startPreview()}.
- */
- public final void stopPreview() {
- _stopPreview();
- mFaceDetectionRunning = false;
-
- mShutterCallback = null;
- mRawImageCallback = null;
- mPostviewCallback = null;
- mJpegCallback = null;
- synchronized (mAutoFocusCallbackLock) {
- mAutoFocusCallback = null;
- }
- mAutoFocusMoveCallback = null;
- }
-
- private native final void _stopPreview();
-
- /**
- * Return current preview state.
- *
- * FIXME: Unhide before release
- * @hide
- */
- public native final boolean previewEnabled();
-
- /**
- * <p>Installs a callback to be invoked for every preview frame in addition
- * to displaying them on the screen. The callback will be repeatedly called
- * for as long as preview is active. This method can be called at any time,
- * even while preview is live. Any other preview callbacks are
- * overridden.</p>
- *
- * <p>If you are using the preview data to create video or still images,
- * strongly consider using {@link android.media.MediaActionSound} to
- * properly indicate image capture or recording start/stop to the user.</p>
- *
- * @param cb a callback object that receives a copy of each preview frame,
- * or null to stop receiving callbacks.
- * @see android.media.MediaActionSound
- */
- public final void setPreviewCallback(PreviewCallback cb) {
- mPreviewCallback = cb;
- mOneShot = false;
- mWithBuffer = false;
- // Always use one-shot mode. We fake camera preview mode by
- // doing one-shot preview continuously.
- setHasPreviewCallback(cb != null, false);
- }
-
- /**
- * <p>Installs a callback to be invoked for the next preview frame in
- * addition to displaying it on the screen. After one invocation, the
- * callback is cleared. This method can be called any time, even when
- * preview is live. Any other preview callbacks are overridden.</p>
- *
- * <p>If you are using the preview data to create video or still images,
- * strongly consider using {@link android.media.MediaActionSound} to
- * properly indicate image capture or recording start/stop to the user.</p>
- *
- * @param cb a callback object that receives a copy of the next preview frame,
- * or null to stop receiving callbacks.
- * @see android.media.MediaActionSound
- */
- public final void setOneShotPreviewCallback(PreviewCallback cb) {
- mPreviewCallback = cb;
- mOneShot = true;
- mWithBuffer = false;
- setHasPreviewCallback(cb != null, false);
- }
-
- private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
-
- /**
- * <p>Installs a callback to be invoked for every preview frame, using
- * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to
- * displaying them on the screen. The callback will be repeatedly called
- * for as long as preview is active and buffers are available. Any other
- * preview callbacks are overridden.</p>
- *
- * <p>The purpose of this method is to improve preview efficiency and frame
- * rate by allowing preview frame memory reuse. You must call
- * {@link #addCallbackBuffer(byte[])} at some point -- before or after
- * calling this method -- or no callbacks will received.</p>
- *
- * <p>The buffer queue will be cleared if this method is called with a null
- * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
- * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is
- * called.</p>
- *
- * <p>If you are using the preview data to create video or still images,
- * strongly consider using {@link android.media.MediaActionSound} to
- * properly indicate image capture or recording start/stop to the user.</p>
- *
- * @param cb a callback object that receives a copy of the preview frame,
- * or null to stop receiving callbacks and clear the buffer queue.
- * @see #addCallbackBuffer(byte[])
- * @see android.media.MediaActionSound
- */
- public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
- mPreviewCallback = cb;
- mOneShot = false;
- mWithBuffer = true;
- setHasPreviewCallback(cb != null, true);
- }
-
- /**
- * Adds a pre-allocated buffer to the preview callback buffer queue.
- * Applications can add one or more buffers to the queue. When a preview
- * frame arrives and there is still at least one available buffer, the
- * buffer will be used and removed from the queue. Then preview callback is
- * invoked with the buffer. If a frame arrives and there is no buffer left,
- * the frame is discarded. Applications should add buffers back when they
- * finish processing the data in them.
- *
- * <p>For formats besides YV12, the size of the buffer is determined by
- * multiplying the preview image width, height, and bytes per pixel. The
- * width and height can be read from
- * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be
- * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} /
- * 8, using the image format from
- * {@link Camera.Parameters#getPreviewFormat()}.
- *
- * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the
- * size can be calculated using the equations listed in
- * {@link Camera.Parameters#setPreviewFormat}.
- *
- * <p>This method is only necessary when
- * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
- * {@link #setPreviewCallback(PreviewCallback)} or
- * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
- * are automatically allocated. When a supplied buffer is too small to
- * hold the preview frame data, preview callback will return null and
- * the buffer will be removed from the buffer queue.
- *
- * @param callbackBuffer the buffer to add to the queue. The size of the
- * buffer must match the values described above.
- * @see #setPreviewCallbackWithBuffer(PreviewCallback)
- */
- public final void addCallbackBuffer(byte[] callbackBuffer)
- {
- _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
- }
-
- /**
- * Adds a pre-allocated buffer to the raw image callback buffer queue.
- * Applications can add one or more buffers to the queue. When a raw image
- * frame arrives and there is still at least one available buffer, the
- * buffer will be used to hold the raw image data and removed from the
- * queue. Then raw image callback is invoked with the buffer. If a raw
- * image frame arrives but there is no buffer left, the frame is
- * discarded. Applications should add buffers back when they finish
- * processing the data in them by calling this method again in order
- * to avoid running out of raw image callback buffers.
- *
- * <p>The size of the buffer is determined by multiplying the raw image
- * width, height, and bytes per pixel. The width and height can be
- * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
- * can be computed from
- * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
- * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
- *
- * <p>This method is only necessary when the PictureCallbck for raw image
- * is used while calling {@link #takePicture(Camera.ShutterCallback,
- * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
- *
- * <p>Please note that by calling this method, the mode for
- * application-managed callback buffers is triggered. If this method has
- * never been called, null will be returned by the raw image callback since
- * there is no image callback buffer available. Furthermore, When a supplied
- * buffer is too small to hold the raw image data, raw image callback will
- * return null and the buffer will be removed from the buffer queue.
- *
- * @param callbackBuffer the buffer to add to the raw image callback buffer
- * queue. The size should be width * height * (bits per pixel) / 8. An
- * null callbackBuffer will be ignored and won't be added to the queue.
- *
- * @see #takePicture(Camera.ShutterCallback,
- * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
- *
- * {@hide}
- */
- public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
- {
- addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
- }
-
- private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
- {
- // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
- if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
- msgType != CAMERA_MSG_RAW_IMAGE) {
- throw new IllegalArgumentException(
- "Unsupported message type: " + msgType);
- }
-
- _addCallbackBuffer(callbackBuffer, msgType);
- }
-
- private native final void _addCallbackBuffer(
- byte[] callbackBuffer, int msgType);
-
- private class EventHandler extends Handler
- {
- private CPCam mCamera;
-
- public EventHandler(CPCam c, Looper looper) {
- super(looper);
- mCamera = c;
- }
-
- @Override
- public void handleMessage(Message msg) {
- switch(msg.what) {
- case CAMERA_MSG_SHUTTER:
- if (mShutterCallback != null) {
- mShutterCallback.onShutter();
- }
- return;
-
- case CAMERA_MSG_RAW_IMAGE:
- if (mRawImageCallback != null) {
- mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
- }
- return;
-
- case CAMERA_MSG_COMPRESSED_IMAGE:
- if (mJpegCallback != null) {
- mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
- }
- return;
-
- case CAMERA_MSG_PREVIEW_FRAME:
- PreviewCallback pCb = mPreviewCallback;
- if (pCb != null) {
- if (mOneShot) {
- // Clear the callback variable before the callback
- // in case the app calls setPreviewCallback from
- // the callback function
- mPreviewCallback = null;
- } else if (!mWithBuffer) {
- // We're faking the camera preview mode to prevent
- // the app from being flooded with preview frames.
- // Set to oneshot mode again.
- setHasPreviewCallback(true, false);
- }
- pCb.onPreviewFrame((byte[])msg.obj, mCamera);
- }
- return;
-
- case CAMERA_MSG_POSTVIEW_FRAME:
- if (mPostviewCallback != null) {
- mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
- }
- return;
-
- case CAMERA_MSG_FOCUS:
- AutoFocusCallback cb = null;
- synchronized (mAutoFocusCallbackLock) {
- cb = mAutoFocusCallback;
- }
- if (cb != null) {
- boolean success = msg.arg1 == 0 ? false : true;
- cb.onAutoFocus(success, mCamera);
- }
- return;
-
- case CAMERA_MSG_ZOOM:
- if (mZoomListener != null) {
- mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
- }
- return;
-
- case CAMERA_MSG_PREVIEW_METADATA:
- Metadata data = (Metadata)msg.obj;
- if (mFaceListener != null) {
- mFaceListener.onFaceDetection(data.faces, mCamera);
- }
- if (mMetadataListener != null) {
- mMetadataListener.onMetadata(data, mCamera);
- }
- return;
-
- case CAMERA_MSG_ERROR :
- Log.e(TAG, "Error " + msg.arg1);
- if (mErrorCallback != null) {
- mErrorCallback.onError(msg.arg1, mCamera);
- }
- return;
-
- case CAMERA_MSG_FOCUS_MOVE:
- if (mAutoFocusMoveCallback != null) {
- mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera);
- }
- return;
-
- default:
- Log.e(TAG, "Unknown message type " + msg.what);
- return;
- }
- }
- }
-
- private static void postEventFromNative(Object camera_ref,
- int what, int arg1, int arg2, Object obj)
- {
- CPCam c = (CPCam)((WeakReference)camera_ref).get();
- if (c == null)
- return;
-
- if (c.mEventHandler != null) {
- Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
- c.mEventHandler.sendMessage(m);
- }
- }
-
- /**
- * Callback interface used to notify on completion of camera auto focus.
- *
- * <p>Devices that do not support auto-focus will receive a "fake"
- * callback to this interface. If your application needs auto-focus and
- * should not be installed on devices <em>without</em> auto-focus, you must
- * declare that your app uses the
- * {@code android.hardware.camera.autofocus} feature, in the
- * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
- * manifest element.</p>
- *
- * @see #autoFocus(AutoFocusCallback)
- */
- public interface AutoFocusCallback
- {
- /**
- * Called when the camera auto focus completes. If the camera
- * does not support auto-focus and autoFocus is called,
- * onAutoFocus will be called immediately with a fake value of
- * <code>success</code> set to <code>true</code>.
- *
- * The auto-focus routine does not lock auto-exposure and auto-white
- * balance after it completes.
- *
- * @param success true if focus was successful, false if otherwise
- * @param camera the Camera service object
- * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
- * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
- */
- void onAutoFocus(boolean success, CPCam camera);
- }
-
- /**
- * Starts camera auto-focus and registers a callback function to run when
- * the camera is focused. This method is only valid when preview is active
- * (between {@link #startPreview()} and before {@link #stopPreview()}).
- *
- * <p>Callers should check
- * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
- * this method should be called. If the camera does not support auto-focus,
- * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
- * callback will be called immediately.
- *
- * <p>If your application should not be installed
- * on devices without auto-focus, you must declare that your application
- * uses auto-focus with the
- * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
- * manifest element.</p>
- *
- * <p>If the current flash mode is not
- * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
- * fired during auto-focus, depending on the driver and camera hardware.<p>
- *
- * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()}
- * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
- * do not change during and after autofocus. But auto-focus routine may stop
- * auto-exposure and auto-white balance transiently during focusing.
- *
- * <p>Stopping preview with {@link #stopPreview()}, or triggering still
- * image capture with {@link #takePicture(Camera.ShutterCallback,
- * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
- * the focus position. Applications must call cancelAutoFocus to reset the
- * focus.</p>
- *
- * <p>If autofocus is successful, consider using
- * {@link android.media.MediaActionSound} to properly play back an autofocus
- * success sound to the user.</p>
- *
- * @param cb the callback to run
- * @see #cancelAutoFocus()
- * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
- * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
- * @see android.media.MediaActionSound
- */
- public final void autoFocus(AutoFocusCallback cb)
- {
- synchronized (mAutoFocusCallbackLock) {
- mAutoFocusCallback = cb;
- }
- native_autoFocus();
- }
- private native final void native_autoFocus();
-
- /**
- * Cancels any auto-focus function in progress.
- * Whether or not auto-focus is currently in progress,
- * this function will return the focus position to the default.
- * If the camera does not support auto-focus, this is a no-op.
- *
- * @see #autoFocus(Camera.AutoFocusCallback)
- */
- public final void cancelAutoFocus()
- {
- synchronized (mAutoFocusCallbackLock) {
- mAutoFocusCallback = null;
- }
- native_cancelAutoFocus();
- // CAMERA_MSG_FOCUS should be removed here because the following
- // scenario can happen:
- // - An application uses the same thread for autoFocus, cancelAutoFocus
- // and looper thread.
- // - The application calls autoFocus.
- // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue.
- // Before event handler's handleMessage() is invoked, the application
- // calls cancelAutoFocus and autoFocus.
- // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus
- // has been completed. But in fact it is not.
- //
- // As documented in the beginning of the file, apps should not use
- // multiple threads to call autoFocus and cancelAutoFocus at the same
- // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS
- // message after native_cancelAutoFocus is called.
- mEventHandler.removeMessages(CAMERA_MSG_FOCUS);
- }
- private native final void native_cancelAutoFocus();
-
- /**
- * Callback interface used to notify on auto focus start and stop.
- *
- * <p>This is only supported in continuous autofocus modes -- {@link
- * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link
- * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show
- * autofocus animation based on this.</p>
- */
- public interface AutoFocusMoveCallback
- {
- /**
- * Called when the camera auto focus starts or stops.
- *
- * @param start true if focus starts to move, false if focus stops to move
- * @param camera the Camera service object
- */
- void onAutoFocusMoving(boolean start, CPCam camera);
- }
-
- /**
- * Sets camera auto-focus move callback.
- *
- * @param cb the callback to run
- */
- public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) {
- mAutoFocusMoveCallback = cb;
- enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0);
- }
-
- private native void enableFocusMoveCallback(int enable);
-
- /**
- * Callback interface used to signal the moment of actual image capture.
- *
- * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
- */
- public interface ShutterCallback
- {
- /**
- * Called as near as possible to the moment when a photo is captured
- * from the sensor. This is a good opportunity to play a shutter sound
- * or give other feedback of camera operation. This may be some time
- * after the photo was triggered, but some time before the actual data
- * is available.
- */
- void onShutter();
- }
-
- /**
- * Callback interface used to supply image data from a photo capture.
- *
- * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
- */
- public interface PictureCallback {
- /**
- * Called when image data is available after a picture is taken.
- * The format of the data depends on the context of the callback
- * and {@link Camera.Parameters} settings.
- *
- * @param data a byte array of the picture data
- * @param camera the Camera service object
- */
- void onPictureTaken(byte[] data, CPCam camera);
- };
-
- /**
- * Equivalent to takePicture(shutter, raw, null, jpeg).
- *
- * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
- */
- public final void takePicture(ShutterCallback shutter, PictureCallback raw,
- PictureCallback jpeg) {
- takePicture(shutter, raw, null, jpeg);
- }
- private native final void native_takePicture(int msgType, String param);
-
- /**
- * Triggers an asynchronous image capture. The camera service will initiate
- * a series of callbacks to the application as the image capture progresses.
- * The shutter callback occurs after the image is captured. This can be used
- * to trigger a sound to let the user know that image has been captured. The
- * raw callback occurs when the raw image data is available (NOTE: the data
- * will be null if there is no raw image callback buffer available or the
- * raw image callback buffer is not large enough to hold the raw image).
- * The postview callback occurs when a scaled, fully processed postview
- * image is available (NOTE: not all hardware supports this). The jpeg
- * callback occurs when the compressed image is available. If the
- * application does not need a particular callback, a null can be passed
- * instead of a callback method.
- *
- * <p>This method is only valid when preview is active (after
- * {@link #startPreview()}). Preview will be stopped after the image is
- * taken; callers must call {@link #startPreview()} again if they want to
- * re-start preview or take more pictures. This should not be called between
- * {@link android.media.MediaRecorder#start()} and
- * {@link android.media.MediaRecorder#stop()}.
- *
- * <p>After calling this method, you must not call {@link #startPreview()}
- * or take another picture until the JPEG callback has returned.
- *
- * @param shutter the callback for image capture moment, or null
- * @param raw the callback for raw (uncompressed) image data, or null
- * @param postview callback with postview image data, may be null
- * @param jpeg the callback for JPEG image data, or null
- */
- public final void takePicture(ShutterCallback shutter, PictureCallback raw,
- PictureCallback postview, PictureCallback jpeg) {
- takePicture(shutter, raw, postview, jpeg, null);
- }
-
- /**
- * TODO(XXX): Still need implement ShotParameters at Java level
- *
- * @hide
- */
- public final void takePicture(ShutterCallback shutter, PictureCallback raw,
- PictureCallback postview, PictureCallback jpeg, Parameters param) {
- mShutterCallback = shutter;
- mRawImageCallback = raw;
- mPostviewCallback = postview;
- mJpegCallback = jpeg;
-
- // If callback is not set, do not send me callbacks.
- int msgType = 0;
- if (mShutterCallback != null) {
- msgType |= CAMERA_MSG_SHUTTER;
- }
- if (mRawImageCallback != null) {
- msgType |= CAMERA_MSG_RAW_IMAGE;
- }
- if (mPostviewCallback != null) {
- msgType |= CAMERA_MSG_POSTVIEW_FRAME;
- }
- if (mJpegCallback != null) {
- msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
- }
-
- String param_str = null;
- if (param != null) {
- param_str = param.flatten();
- }
-
- native_takePicture(msgType, param_str);
- mFaceDetectionRunning = false;
- }
-
- /**
- * Zooms to the requested value smoothly. The driver will notify {@link
- * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
- * the time. For example, suppose the current zoom is 0 and startSmoothZoom
- * is called with value 3. The
- * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
- * method will be called three times with zoom values 1, 2, and 3.
- * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
- * Applications should not call startSmoothZoom again or change the zoom
- * value before zoom stops. If the supplied zoom value equals to the current
- * zoom value, no zoom callback will be generated. This method is supported
- * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
- * returns true.
- *
- * @param value zoom value. The valid range is 0 to {@link
- * android.hardware.Camera.Parameters#getMaxZoom}.
- * @throws IllegalArgumentException if the zoom value is invalid.
- * @throws RuntimeException if the method fails.
- * @see #setZoomChangeListener(OnZoomChangeListener)
- */
- public native final void startSmoothZoom(int value);
-
- /**
- * Stops the smooth zoom. Applications should wait for the {@link
- * OnZoomChangeListener} to know when the zoom is actually stopped. This
- * method is supported if {@link
- * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
- *
- * @throws RuntimeException if the method fails.
- */
- public native final void stopSmoothZoom();
-
- /**
- * Set the clockwise rotation of preview display in degrees. This affects
- * the preview frames and the picture displayed after snapshot. This method
- * is useful for portrait mode applications. Note that preview display of
- * front-facing cameras is flipped horizontally before the rotation, that
- * is, the image is reflected along the central vertical axis of the camera
- * sensor. So the users can see themselves as looking into a mirror.
- *
- * <p>This does not affect the order of byte array passed in {@link
- * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
- * method is not allowed to be called during preview.
- *
- * <p>If you want to make the camera image show in the same orientation as
- * the display, you can use the following code.
- * <pre>
- * public static void setCameraDisplayOrientation(Activity activity,
- * int cameraId, android.hardware.Camera camera) {
- * android.hardware.Camera.CameraInfo info =
- * new android.hardware.Camera.CameraInfo();
- * android.hardware.Camera.getCameraInfo(cameraId, info);
- * int rotation = activity.getWindowManager().getDefaultDisplay()
- * .getRotation();
- * int degrees = 0;
- * switch (rotation) {
- * case Surface.ROTATION_0: degrees = 0; break;
- * case Surface.ROTATION_90: degrees = 90; break;
- * case Surface.ROTATION_180: degrees = 180; break;
- * case Surface.ROTATION_270: degrees = 270; break;
- * }
- *
- * int result;
- * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
- * result = (info.orientation + degrees) % 360;
- * result = (360 - result) % 360; // compensate the mirror
- * } else { // back-facing
- * result = (info.orientation - degrees + 360) % 360;
- * }
- * camera.setDisplayOrientation(result);
- * }
- * </pre>
- *
- * <p>Starting from API level 14, this method can be called when preview is
- * active.
- *
- * @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).
- * @see #setPreviewDisplay(SurfaceHolder)
- */
- public native final void setDisplayOrientation(int degrees);
-
- /**
- * Callback interface for zoom changes during a smooth zoom operation.
- *
- * @see #setZoomChangeListener(OnZoomChangeListener)
- * @see #startSmoothZoom(int)
- */
- public interface OnZoomChangeListener
- {
- /**
- * Called when the zoom value has changed during a smooth zoom.
- *
- * @param zoomValue the current zoom value. In smooth zoom mode, camera
- * calls this for every new zoom value.
- * @param stopped whether smooth zoom is stopped. If the value is true,
- * this is the last zoom update for the application.
- * @param camera the Camera service object
- */
- void onZoomChange(int zoomValue, boolean stopped, CPCam camera);
- };
-
- /**
- * Registers a listener to be notified when the zoom value is updated by the
- * camera driver during smooth zoom.
- *
- * @param listener the listener to notify
- * @see #startSmoothZoom(int)
- */
- public final void setZoomChangeListener(OnZoomChangeListener listener)
- {
- mZoomListener = listener;
- }
-
- /**
- * Callback interface for face detected in the preview frame.
- *
- */
- public interface FaceDetectionListener
- {
- /**
- * Notify the listener of the detected faces in the preview frame.
- *
- * @param faces The detected faces in a list
- * @param camera The {@link Camera} service object
- */
- void onFaceDetection(Face[] faces, CPCam camera);
- }
-
- /**
- * Registers a listener to be notified about the faces detected in the
- * preview frame.
- *
- * @param listener the listener to notify
- * @see #startFaceDetection()
- */
- public final void setFaceDetectionListener(FaceDetectionListener listener)
- {
- mFaceListener = listener;
- }
-
- /**
- * Callback interface for metadata.
- *
- * @see #setMetadataListener(MetadataListener)
- */
- public interface MetadataListener
- {
- /**
- * Called when metadata is available
- *
- * @param metadata the metadata of associated frame
- * @param camera the Camera service object
- */
- void onMetadata(Metadata metadata, CPCam camera);
- };
-
- /**
- * Registers a listener to be notified when metadata
- * is available.
- *
- * @param listener the listener to notify
- */
- public final void setMetadataListener(MetadataListener listener)
- {
- mMetadataListener = listener;
- }
-
- /**
- * Starts the face detection. This should be called after preview is started.
- * The camera will notify {@link FaceDetectionListener} of the detected
- * faces in the preview frame. The detected faces may be the same as the
- * previous ones. Applications should call {@link #stopFaceDetection} to
- * stop the face detection. This method is supported if {@link
- * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
- * If the face detection has started, apps should not call this again.
- *
- * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
- * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
- * have no effect. The camera uses the detected faces to do auto-white balance,
- * auto exposure, and autofocus.
- *
- * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
- * will stop sending face callbacks. The last face callback indicates the
- * areas used to do autofocus. After focus completes, face detection will
- * resume sending face callbacks. If the apps call {@link
- * #cancelAutoFocus()}, the face callbacks will also resume.</p>
- *
- * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
- * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
- * preview with {@link #startPreview()}, the apps should call this method
- * again to resume face detection.</p>
- *
- * @throws IllegalArgumentException if the face detection is unsupported.
- * @throws RuntimeException if the method fails or the face detection is
- * already running.
- * @see FaceDetectionListener
- * @see #stopFaceDetection()
- * @see Parameters#getMaxNumDetectedFaces()
- */
- public final void startFaceDetection() {
- if (mFaceDetectionRunning) {
- throw new RuntimeException("Face detection is already running");
- }
- _startFaceDetection(CAMERA_FACE_DETECTION_HW);
- mFaceDetectionRunning = true;
- }
-
- /**
- * Stops the face detection.
- *
- * @see #startFaceDetection()
- */
- public final void stopFaceDetection() {
- _stopFaceDetection();
- mFaceDetectionRunning = false;
- }
-
- private native final void _startFaceDetection(int type);
- private native final void _stopFaceDetection();
-
- /**
- * Information about a face identified through camera face detection.
- *
- * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a
- * list of face objects for use in focusing and metering.</p>
- *
- * @see FaceDetectionListener
- */
- public static class Face {
- /**
- * Create an empty face.
- */
- public Face() {
- }
-
- /**
- * Bounds of the face. (-1000, -1000) represents the top-left of the
- * camera field of view, and (1000, 1000) represents the bottom-right of
- * the field of view. For example, suppose the size of the viewfinder UI
- * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0).
- * The corresponding viewfinder rect should be (0, 0, 400, 240). It is
- * guaranteed left < right and top < bottom. The coordinates can be
- * smaller than -1000 or bigger than 1000. But at least one vertex will
- * be within (-1000, -1000) and (1000, 1000).
- *
- * <p>The direction is relative to the sensor orientation, that is, what
- * the sensor sees. The direction is not affected by the rotation or
- * mirroring of {@link #setDisplayOrientation(int)}. The face bounding
- * rectangle does not provide any information about face orientation.</p>
- *
- * <p>Here is the matrix to convert driver coordinates to View coordinates
- * in pixels.</p>
- * <pre>
- * Matrix matrix = new Matrix();
- * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
- * // Need mirror for front camera.
- * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
- * matrix.setScale(mirror ? -1 : 1, 1);
- * // This is the value for android.hardware.Camera.setDisplayOrientation.
- * matrix.postRotate(displayOrientation);
- * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
- * // UI coordinates range from (0, 0) to (width, height).
- * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
- * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
- * </pre>
- *
- * @see #startFaceDetection()
- */
- public Rect rect;
-
- /**
- * The confidence level for the detection of the face. The range is 1 to 100. 100 is the
- * highest confidence.
- *
- * @see #startFaceDetection()
- */
- public int score;
-
- /**
- * An unique id per face while the face is visible to the tracker. If
- * the face leaves the field-of-view and comes back, it will get a new
- * id. This is an optional field, may not be supported on all devices.
- * If not supported, id will always be set to -1. The optional fields
- * are supported as a set. Either they are all valid, or none of them
- * are.
- */
- public int id = -1;
-
- /**
- * The coordinates of the center of the left eye. The coordinates are in
- * the same space as the ones for {@link #rect}. This is an optional
- * field, may not be supported on all devices. If not supported, the
- * value will always be set to null. The optional fields are supported
- * as a set. Either they are all valid, or none of them are.
- */
- public Point leftEye = null;
-
- /**
- * The coordinates of the center of the right eye. The coordinates are
- * in the same space as the ones for {@link #rect}.This is an optional
- * field, may not be supported on all devices. If not supported, the
- * value will always be set to null. The optional fields are supported
- * as a set. Either they are all valid, or none of them are.
- */
- public Point rightEye = null;
-
- /**
- * The coordinates of the center of the mouth. The coordinates are in
- * the same space as the ones for {@link #rect}. This is an optional
- * field, may not be supported on all devices. If not supported, the
- * value will always be set to null. The optional fields are supported
- * as a set. Either they are all valid, or none of them are.
- */
- public Point mouth = null;
- }
-
- /**
- * Information about metadata values of an associated frame.
- *
- * @see MetadataListener
- */
- public static class Metadata {
-
- /**
- * Create an empty metadata.
- */
- public Metadata() {
- }
-
- /**
- * Create metadata with given values.
- */
- public Metadata(int exp, int gain, Face[] _faces) {
- exposureTime = exp;
- analogGain = gain;
- faces = _faces;
- }
-
- /**
- * Exposure time in microseconds
- */
- public int exposureTime;
-
- /**
- * Analog gain in EV units * 1000
- */
- public int analogGain;
-
- /**
- * List of faces for a particular frame
- */
- public Face[] faces;
- }
-
- // Error codes match the enum in include/ui/Camera.h
-
- /**
- * Unspecified camera error.
- * @see Camera.ErrorCallback
- */
- public static final int CAMERA_ERROR_UNKNOWN = 1;
-
- /**
- * Media server died. In this case, the application must release the
- * Camera object and instantiate a new one.
- * @see Camera.ErrorCallback
- */
- public static final int CAMERA_ERROR_SERVER_DIED = 100;
-
- /**
- * Callback interface for camera error notification.
- *
- * @see #setErrorCallback(ErrorCallback)
- */
- public interface ErrorCallback
- {
- /**
- * Callback for camera errors.
- * @param error error code:
- * <ul>
- * <li>{@link #CAMERA_ERROR_UNKNOWN}
- * <li>{@link #CAMERA_ERROR_SERVER_DIED}
- * </ul>
- * @param camera the Camera service object
- */
- void onError(int error, CPCam camera);
- };
-
- /**
- * Registers a callback to be invoked when an error occurs.
- * @param cb The callback to run
- */
- public final void setErrorCallback(ErrorCallback cb)
- {
- mErrorCallback = cb;
- }
-
- private native final void native_setParameters(String params);
- private native final String native_getParameters();
-
- /**
- * Changes the settings for this Camera service.
- *
- * @param params the Parameters to use for this Camera service
- * @throws RuntimeException if any parameter is invalid or not supported.
- * @see #getParameters()
- */
- public void setParameters(Parameters params) {
- native_setParameters(params.flatten());
- }
-
- /**
- * Returns the current settings for this Camera service.
- * If modifications are made to the returned Parameters, they must be passed
- * to {@link #setParameters(Camera.Parameters)} to take effect.
- *
- * @see #setParameters(Camera.Parameters)
- */
- public Parameters getParameters() {
- Parameters p = new Parameters();
- String s = native_getParameters();
- p.unflatten(s);
- return p;
- }
-
- /**
- * Returns an empty {@link Parameters} for testing purpose.
- *
- * @return a Parameter object.
- *
- * @hide
- */
- public static Parameters getEmptyParameters() {
- CPCam camera = new CPCam();
- return camera.new Parameters();
- }
-
- /**
- * Image size (width and height dimensions).
- */
- public class Size {
- /**
- * Sets the dimensions for pictures.
- *
- * @param w the photo width (pixels)
- * @param h the photo height (pixels)
- */
- public Size(int w, int h) {
- width = w;
- height = h;
- }
- /**
- * Compares {@code obj} to this size.
- *
- * @param obj the object to compare this size with.
- * @return {@code true} if the width and height of {@code obj} is the
- * same as those of this size. {@code false} otherwise.
- */
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof Size)) {
- return false;
- }
- Size s = (Size) obj;
- return width == s.width && height == s.height;
- }
- @Override
- public int hashCode() {
- return width * 32713 + height;
- }
- /** width of the picture */
- public int width;
- /** height of the picture */
- public int height;
- };
-
- /**
- * <p>The Area class is used for choosing specific metering and focus areas for
- * the camera to use when calculating auto-exposure, auto-white balance, and
- * auto-focus.</p>
- *
- * <p>To find out how many simultaneous areas a given camera supports, use
- * {@link Parameters#getMaxNumMeteringAreas()} and
- * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
- * selection is unsupported, these methods will return 0.</p>
- *
- * <p>Each Area consists of a rectangle specifying its bounds, and a weight
- * that determines its importance. The bounds are relative to the camera's
- * current field of view. The coordinates are mapped so that (-1000, -1000)
- * is always the top-left corner of the current field of view, and (1000,
- * 1000) is always the bottom-right corner of the current field of
- * view. Setting Areas with bounds outside that range is not allowed. Areas
- * with zero or negative width or height are not allowed.</p>
- *
- * <p>The weight must range from 1 to 1000, and represents a weight for
- * every pixel in the area. This means that a large metering area with
- * the same weight as a smaller area will have more effect in the
- * metering result. Metering areas can overlap and the driver
- * will add the weights in the overlap region.</p>
- *
- * @see Parameters#setFocusAreas(List)
- * @see Parameters#getFocusAreas()
- * @see Parameters#getMaxNumFocusAreas()
- * @see Parameters#setMeteringAreas(List)
- * @see Parameters#getMeteringAreas()
- * @see Parameters#getMaxNumMeteringAreas()
- */
- public static class Area {
- /**
- * Create an area with specified rectangle and weight.
- *
- * @param rect the bounds of the area.
- * @param weight the weight of the area.
- */
- public Area(Rect rect, int weight) {
- this.rect = rect;
- this.weight = weight;
- }
- /**
- * Compares {@code obj} to this area.
- *
- * @param obj the object to compare this area with.
- * @return {@code true} if the rectangle and weight of {@code obj} is
- * the same as those of this area. {@code false} otherwise.
- */
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof Area)) {
- return false;
- }
- Area a = (Area) obj;
- if (rect == null) {
- if (a.rect != null) return false;
- } else {
- if (!rect.equals(a.rect)) return false;
- }
- return weight == a.weight;
- }
-
- /**
- * Bounds of the area. (-1000, -1000) represents the top-left of the
- * camera field of view, and (1000, 1000) represents the bottom-right of
- * the field of view. Setting bounds outside that range is not
- * allowed. Bounds with zero or negative width or height are not
- * allowed.
- *
- * @see Parameters#getFocusAreas()
- * @see Parameters#getMeteringAreas()
- */
- public Rect rect;
-
- /**
- * Weight of the area. The weight must range from 1 to 1000, and
- * represents a weight for every pixel in the area. This means that a
- * large metering area with the same weight as a smaller area will have
- * more effect in the metering result. Metering areas can overlap and
- * the driver will add the weights in the overlap region.
- *
- * @see Parameters#getFocusAreas()
- * @see Parameters#getMeteringAreas()
- */
- public int weight;
- }
-
- /**
- * Camera service settings.
- *
- * <p>To make camera parameters take effect, applications have to call
- * {@link Camera#setParameters(Camera.Parameters)}. For example, after
- * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
- * actually changed until {@link Camera#setParameters(Camera.Parameters)}
- * is called with the changed parameters object.
- *
- * <p>Different devices may have different camera capabilities, such as
- * picture size or flash modes. The application should query the camera
- * capabilities before setting parameters. For example, the application
- * should call {@link Camera.Parameters#getSupportedColorEffects()} before
- * calling {@link Camera.Parameters#setColorEffect(String)}. If the
- * camera does not support color effects,
- * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
- */
- public class Parameters {
- // Parameter keys to communicate with the camera driver.
- private static final String KEY_PREVIEW_SIZE = "preview-size";
- private static final String KEY_PREVIEW_FORMAT = "preview-format";
- private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
- private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
- private static final String KEY_PICTURE_SIZE = "picture-size";
- private static final String KEY_PICTURE_FORMAT = "picture-format";
- private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
- private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
- private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
- private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
- private static final String KEY_JPEG_QUALITY = "jpeg-quality";
- private static final String KEY_ROTATION = "rotation";
- private static final String KEY_GPS_LATITUDE = "gps-latitude";
- private static final String KEY_GPS_LONGITUDE = "gps-longitude";
- private static final String KEY_GPS_ALTITUDE = "gps-altitude";
- private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
- private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
- private static final String KEY_WHITE_BALANCE = "whitebalance";
- private static final String KEY_EFFECT = "effect";
- private static final String KEY_ANTIBANDING = "antibanding";
- private static final String KEY_SCENE_MODE = "scene-mode";
- private static final String KEY_FLASH_MODE = "flash-mode";
- private static final String KEY_FOCUS_MODE = "focus-mode";
- private static final String KEY_FOCUS_AREAS = "focus-areas";
- private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
- private static final String KEY_FOCAL_LENGTH = "focal-length";
- private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
- private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
- private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
- private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
- private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
- private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
- private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
- private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
- private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
- private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
- private static final String KEY_METERING_AREAS = "metering-areas";
- private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
- private static final String KEY_ZOOM = "zoom";
- private static final String KEY_MAX_ZOOM = "max-zoom";
- private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
- private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
- private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
- private static final String KEY_FOCUS_DISTANCES = "focus-distances";
- private static final String KEY_VIDEO_SIZE = "video-size";
- private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
- "preferred-preview-size-for-video";
- private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
- private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
- private static final String KEY_RECORDING_HINT = "recording-hint";
- private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
- private static final String KEY_VIDEO_STABILIZATION = "video-stabilization";
- private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported";
-
- // Parameter key suffix for supported values.
- private static final String SUPPORTED_VALUES_SUFFIX = "-values";
-
- private static final String TRUE = "true";
- private static final String FALSE = "false";
-
- // Values for white balance settings.
- public static final String WHITE_BALANCE_AUTO = "auto";
- public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
- public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
- public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
- public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
- public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
- public static final String WHITE_BALANCE_TWILIGHT = "twilight";
- public static final String WHITE_BALANCE_SHADE = "shade";
-
- // Values for color effect settings.
- public static final String EFFECT_NONE = "none";
- public static final String EFFECT_MONO = "mono";
- public static final String EFFECT_NEGATIVE = "negative";
- public static final String EFFECT_SOLARIZE = "solarize";
- public static final String EFFECT_SEPIA = "sepia";
- public static final String EFFECT_POSTERIZE = "posterize";
- public static final String EFFECT_WHITEBOARD = "whiteboard";
- public static final String EFFECT_BLACKBOARD = "blackboard";
- public static final String EFFECT_AQUA = "aqua";
-
- // Values for antibanding settings.
- public static final String ANTIBANDING_AUTO = "auto";
- public static final String ANTIBANDING_50HZ = "50hz";
- public static final String ANTIBANDING_60HZ = "60hz";
- public static final String ANTIBANDING_OFF = "off";
-
- // Values for flash mode settings.
- /**
- * Flash will not be fired.
- */
- public static final String FLASH_MODE_OFF = "off";
-
- /**
- * Flash will be fired automatically when required. The flash may be fired
- * during preview, auto-focus, or snapshot depending on the driver.
- */
- public static final String FLASH_MODE_AUTO = "auto";
-
- /**
- * Flash will always be fired during snapshot. The flash may also be
- * fired during preview or auto-focus depending on the driver.
- */
- public static final String FLASH_MODE_ON = "on";
-
- /**
- * Flash will be fired in red-eye reduction mode.
- */
- public static final String FLASH_MODE_RED_EYE = "red-eye";
-
- /**
- * Constant emission of light during preview, auto-focus and snapshot.
- * This can also be used for video recording.
- */
- public static final String FLASH_MODE_TORCH = "torch";
-
- /**
- * Scene mode is off.
- */
- public static final String SCENE_MODE_AUTO = "auto";
-
- /**
- * Take photos of fast moving objects. Same as {@link
- * #SCENE_MODE_SPORTS}.
- */
- public static final String SCENE_MODE_ACTION = "action";
-
- /**
- * Take people pictures.
- */
- public static final String SCENE_MODE_PORTRAIT = "portrait";
-
- /**
- * Take pictures on distant objects.
- */
- public static final String SCENE_MODE_LANDSCAPE = "landscape";
-
- /**
- * Take photos at night.
- */
- public static final String SCENE_MODE_NIGHT = "night";
-
- /**
- * Take people pictures at night.
- */
- public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
-
- /**
- * Take photos in a theater. Flash light is off.
- */
- public static final String SCENE_MODE_THEATRE = "theatre";
-
- /**
- * Take pictures on the beach.
- */
- public static final String SCENE_MODE_BEACH = "beach";
-
- /**
- * Take pictures on the snow.
- */
- public static final String SCENE_MODE_SNOW = "snow";
-
- /**
- * Take sunset photos.
- */
- public static final String SCENE_MODE_SUNSET = "sunset";
-
- /**
- * Avoid blurry pictures (for example, due to hand shake).
- */
- public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
-
- /**
- * For shooting firework displays.
- */
- public static final String SCENE_MODE_FIREWORKS = "fireworks";
-
- /**
- * Take photos of fast moving objects. Same as {@link
- * #SCENE_MODE_ACTION}.
- */
- public static final String SCENE_MODE_SPORTS = "sports";
-
- /**
- * Take indoor low-light shot.
- */
- public static final String SCENE_MODE_PARTY = "party";
-
- /**
- * Capture the naturally warm color of scenes lit by candles.
- */
- public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
-
- /**
- * Applications are looking for a barcode. Camera driver will be
- * optimized for barcode reading.
- */
- public static final String SCENE_MODE_BARCODE = "barcode";
-
- /**
- * Auto-focus mode. Applications should call {@link
- * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
- */
- public static final String FOCUS_MODE_AUTO = "auto";
-
- /**
- * Focus is set at infinity. Applications should not call
- * {@link #autoFocus(AutoFocusCallback)} in this mode.
- */
- public static final String FOCUS_MODE_INFINITY = "infinity";
-
- /**
- * Macro (close-up) focus mode. Applications should call
- * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
- * mode.
- */
- public static final String FOCUS_MODE_MACRO = "macro";
-
- /**
- * Focus is fixed. The camera is always in this mode if the focus is not
- * adjustable. If the camera has auto-focus, this mode can fix the
- * focus, which is usually at hyperfocal distance. Applications should
- * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
- */
- public static final String FOCUS_MODE_FIXED = "fixed";
-
- /**
- * Extended depth of field (EDOF). Focusing is done digitally and
- * continuously. Applications should not call {@link
- * #autoFocus(AutoFocusCallback)} in this mode.
- */
- public static final String FOCUS_MODE_EDOF = "edof";
-
- /**
- * Continuous auto focus mode intended for video recording. The camera
- * continuously tries to focus. This is the best choice for video
- * recording because the focus changes smoothly . Applications still can
- * call {@link #takePicture(Camera.ShutterCallback,
- * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
- * subject may not be in focus. Auto focus starts when the parameter is
- * set.
- *
- * <p>Since API level 14, applications can call {@link
- * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
- * immediately return with a boolean that indicates whether the focus is
- * sharp or not. The focus position is locked after autoFocus call. If
- * applications want to resume the continuous focus, cancelAutoFocus
- * must be called. Restarting the preview will not resume the continuous
- * autofocus. To stop continuous focus, applications should change the
- * focus mode to other modes.
- *
- * @see #FOCUS_MODE_CONTINUOUS_PICTURE
- */
- public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
-
- /**
- * Continuous auto focus mode intended for taking pictures. The camera
- * continuously tries to focus. The speed of focus change is more
- * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
- * starts when the parameter is set.
- *
- * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
- * this mode. If the autofocus is in the middle of scanning, the focus
- * callback will return when it completes. If the autofocus is not
- * scanning, the focus callback will immediately return with a boolean
- * that indicates whether the focus is sharp or not. The apps can then
- * decide if they want to take a picture immediately or to change the
- * focus mode to auto, and run a full autofocus cycle. The focus
- * position is locked after autoFocus call. If applications want to
- * resume the continuous focus, cancelAutoFocus must be called.
- * Restarting the preview will not resume the continuous autofocus. To
- * stop continuous focus, applications should change the focus mode to
- * other modes.
- *
- * @see #FOCUS_MODE_CONTINUOUS_VIDEO
- */
- public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
-
- // Indices for focus distance array.
- /**
- * The array index of near focus distance for use with
- * {@link #getFocusDistances(float[])}.
- */
- public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
-
- /**
- * The array index of optimal focus distance for use with
- * {@link #getFocusDistances(float[])}.
- */
- public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
-
- /**
- * The array index of far focus distance for use with
- * {@link #getFocusDistances(float[])}.
- */
- public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
-
- /**
- * The array index of minimum preview fps for use with {@link
- * #getPreviewFpsRange(int[])} or {@link
- * #getSupportedPreviewFpsRange()}.
- */
- public static final int PREVIEW_FPS_MIN_INDEX = 0;
-
- /**
- * The array index of maximum preview fps for use with {@link
- * #getPreviewFpsRange(int[])} or {@link
- * #getSupportedPreviewFpsRange()}.
- */
- public static final int PREVIEW_FPS_MAX_INDEX = 1;
-
- // Formats for setPreviewFormat and setPictureFormat.
- private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
- private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
- private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
- private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
- private static final String PIXEL_FORMAT_RGB565 = "rgb565";
- private static final String PIXEL_FORMAT_JPEG = "jpeg";
- private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb";
-
- private HashMap<String, String> mMap;
-
- private Parameters() {
- mMap = new HashMap<String, String>();
- }
-
- /**
- * Writes the current Parameters to the log.
- * @hide
- * @deprecated
- */
- public void dump() {
- Log.e(TAG, "dump: size=" + mMap.size());
- for (String k : mMap.keySet()) {
- Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
- }
- }
-
- /**
- * Creates a single string with all the parameters set in
- * this Parameters object.
- * <p>The {@link #unflatten(String)} method does the reverse.</p>
- *
- * @return a String with all values from this Parameters object, in
- * semi-colon delimited key-value pairs
- */
- public String flatten() {
- StringBuilder flattened = new StringBuilder();
- for (String k : mMap.keySet()) {
- flattened.append(k);
- flattened.append("=");
- flattened.append(mMap.get(k));
- flattened.append(";");
- }
- // chop off the extra semicolon at the end
- flattened.deleteCharAt(flattened.length()-1);
- return flattened.toString();
- }
-
- /**
- * Takes a flattened string of parameters and adds each one to
- * this Parameters object.
- * <p>The {@link #flatten()} method does the reverse.</p>
- *
- * @param flattened a String of parameters (key-value paired) that
- * are semi-colon delimited
- */
- public void unflatten(String flattened) {
- mMap.clear();
-
- StringTokenizer tokenizer = new StringTokenizer(flattened, ";");
- while (tokenizer.hasMoreElements()) {
- String kv = tokenizer.nextToken();
- int pos = kv.indexOf('=');
- if (pos == -1) {
- continue;
- }
- String k = kv.substring(0, pos);
- String v = kv.substring(pos + 1);
- mMap.put(k, v);
- }
- }
-
- public void remove(String key) {
- mMap.remove(key);
- }
-
- /**
- * Sets a String parameter.
- *
- * @param key the key name for the parameter
- * @param value the String value of the parameter
- */
- public void set(String key, String value) {
- if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) {
- Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)");
- return;
- }
- if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) {
- Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)");
- return;
- }
-
- mMap.put(key, value);
- }
-
- /**
- * Sets an integer parameter.
- *
- * @param key the key name for the parameter
- * @param value the int value of the parameter
- */
- public void set(String key, int value) {
- mMap.put(key, Integer.toString(value));
- }
-
- private void set(String key, List<Area> areas) {
- if (areas == null) {
- set(key, "(0,0,0,0,0)");
- } else {
- StringBuilder buffer = new StringBuilder();
- for (int i = 0; i < areas.size(); i++) {
- Area area = areas.get(i);
- Rect rect = area.rect;
- buffer.append('(');
- buffer.append(rect.left);
- buffer.append(',');
- buffer.append(rect.top);
- buffer.append(',');
- buffer.append(rect.right);
- buffer.append(',');
- buffer.append(rect.bottom);
- buffer.append(',');
- buffer.append(area.weight);
- buffer.append(')');
- if (i != areas.size() - 1) buffer.append(',');
- }
- set(key, buffer.toString());
- }
- }
-
- /**
- * Returns the value of a String parameter.
- *
- * @param key the key name for the parameter
- * @return the String value of the parameter
- */
- public String get(String key) {
- return mMap.get(key);
- }
-
- /**
- * Returns the value of an integer parameter.
- *
- * @param key the key name for the parameter
- * @return the int value of the parameter
- */
- public int getInt(String key) {
- return Integer.parseInt(mMap.get(key));
- }
-
- /**
- * Sets the dimensions for preview pictures. If the preview has already
- * started, applications should stop the preview first before changing
- * preview size.
- *
- * The sides of width and height are based on camera orientation. That
- * is, the preview size is the size before it is rotated by display
- * orientation. So applications need to consider the display orientation
- * while setting preview size. For example, suppose the camera supports
- * both 480x320 and 320x480 preview sizes. The application wants a 3:2
- * preview ratio. If the display orientation is set to 0 or 180, preview
- * size should be set to 480x320. If the display orientation is set to
- * 90 or 270, preview size should be set to 320x480. The display
- * orientation should also be considered while setting picture size and
- * thumbnail size.
- *
- * @param width the width of the pictures, in pixels
- * @param height the height of the pictures, in pixels
- * @see #setDisplayOrientation(int)
- * @see #getCameraInfo(int, CameraInfo)
- * @see #setPictureSize(int, int)
- * @see #setJpegThumbnailSize(int, int)
- */
- public void setPreviewSize(int width, int height) {
- String v = Integer.toString(width) + "x" + Integer.toString(height);
- set(KEY_PREVIEW_SIZE, v);
- }
-
- /**
- * Returns the dimensions setting for preview pictures.
- *
- * @return a Size object with the width and height setting
- * for the preview picture
- */
- public Size getPreviewSize() {
- String pair = get(KEY_PREVIEW_SIZE);
- return strToSize(pair);
- }
-
- /**
- * Gets the supported preview sizes.
- *
- * @return a list of Size object. This method will always return a list
- * with at least one element.
- */
- public List<Size> getSupportedPreviewSizes() {
- String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
- return splitSize(str);
- }
-
- /**
- * <p>Gets the supported video frame sizes that can be used by
- * MediaRecorder.</p>
- *
- * <p>If the returned list is not null, the returned list will contain at
- * least one Size and one of the sizes in the returned list must be
- * passed to MediaRecorder.setVideoSize() for camcorder application if
- * camera is used as the video source. In this case, the size of the
- * preview can be different from the resolution of the recorded video
- * during video recording.</p>
- *
- * @return a list of Size object if camera has separate preview and
- * video output; otherwise, null is returned.
- * @see #getPreferredPreviewSizeForVideo()
- */
- public List<Size> getSupportedVideoSizes() {
- String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
- return splitSize(str);
- }
-
- /**
- * Returns the preferred or recommended preview size (width and height)
- * in pixels for video recording. Camcorder applications should
- * set the preview size to a value that is not larger than the
- * preferred preview size. In other words, the product of the width
- * and height of the preview size should not be larger than that of
- * the preferred preview size. In addition, we recommend to choose a
- * preview size that has the same aspect ratio as the resolution of
- * video to be recorded.
- *
- * @return the preferred preview size (width and height) in pixels for
- * video recording if getSupportedVideoSizes() does not return
- * null; otherwise, null is returned.
- * @see #getSupportedVideoSizes()
- */
- public Size getPreferredPreviewSizeForVideo() {
- String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
- return strToSize(pair);
- }
-
- /**
- * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
- * applications set both width and height to 0, EXIF will not contain
- * thumbnail.</p>
- *
- * <p>Applications need to consider the display orientation. See {@link
- * #setPreviewSize(int,int)} for reference.</p>
- *
- * @param width the width of the thumbnail, in pixels
- * @param height the height of the thumbnail, in pixels
- * @see #setPreviewSize(int,int)
- */
- public void setJpegThumbnailSize(int width, int height) {
- set(KEY_JPEG_THUMBNAIL_WIDTH, width);
- set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
- }
-
- /**
- * Returns the dimensions for EXIF thumbnail in Jpeg picture.
- *
- * @return a Size object with the height and width setting for the EXIF
- * thumbnails
- */
- public Size getJpegThumbnailSize() {
- return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
- getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
- }
-
- /**
- * Gets the supported jpeg thumbnail sizes.
- *
- * @return a list of Size object. This method will always return a list
- * with at least two elements. Size 0,0 (no thumbnail) is always
- * supported.
- */
- public List<Size> getSupportedJpegThumbnailSizes() {
- String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
- return splitSize(str);
- }
-
- /**
- * Sets the quality of the EXIF thumbnail in Jpeg picture.
- *
- * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
- * to 100, with 100 being the best.
- */
- public void setJpegThumbnailQuality(int quality) {
- set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
- }
-
- /**
- * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
- *
- * @return the JPEG quality setting of the EXIF thumbnail.
- */
- public int getJpegThumbnailQuality() {
- return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
- }
-
- /**
- * Sets Jpeg quality of captured picture.
- *
- * @param quality the JPEG quality of captured picture. The range is 1
- * to 100, with 100 being the best.
- */
- public void setJpegQuality(int quality) {
- set(KEY_JPEG_QUALITY, quality);
- }
-
- /**
- * Returns the quality setting for the JPEG picture.
- *
- * @return the JPEG picture quality setting.
- */
- public int getJpegQuality() {
- return getInt(KEY_JPEG_QUALITY);
- }
-
- /**
- * Sets the rate at which preview frames are received. This is the
- * target frame rate. The actual frame rate depends on the driver.
- *
- * @param fps the frame rate (frames per second)
- * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
- */
- @Deprecated
- public void setPreviewFrameRate(int fps) {
- set(KEY_PREVIEW_FRAME_RATE, fps);
- }
-
- /**
- * Returns the setting for the rate at which preview frames are
- * received. This is the target frame rate. The actual frame rate
- * depends on the driver.
- *
- * @return the frame rate setting (frames per second)
- * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
- */
- @Deprecated
- public int getPreviewFrameRate() {
- return getInt(KEY_PREVIEW_FRAME_RATE);
- }
-
- /**
- * Gets the supported preview frame rates.
- *
- * @return a list of supported preview frame rates. null if preview
- * frame rate setting is not supported.
- * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
- */
- @Deprecated
- public List<Integer> getSupportedPreviewFrameRates() {
- String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
- return splitInt(str);
- }
-
- /**
- * Sets the maximum and maximum preview fps. This controls the rate of
- * preview frames received in {@link PreviewCallback}. The minimum and
- * maximum preview fps must be one of the elements from {@link
- * #getSupportedPreviewFpsRange}.
- *
- * @param min the minimum preview fps (scaled by 1000).
- * @param max the maximum preview fps (scaled by 1000).
- * @throws RuntimeException if fps range is invalid.
- * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
- * @see #getSupportedPreviewFpsRange()
- */
- public void setPreviewFpsRange(int min, int max) {
- set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
- }
-
- /**
- * Returns the current minimum and maximum preview fps. The values are
- * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
- *
- * @return range the minimum and maximum preview fps (scaled by 1000).
- * @see #PREVIEW_FPS_MIN_INDEX
- * @see #PREVIEW_FPS_MAX_INDEX
- * @see #getSupportedPreviewFpsRange()
- */
- public void getPreviewFpsRange(int[] range) {
- if (range == null || range.length != 2) {
- throw new IllegalArgumentException(
- "range must be an array with two elements.");
- }
- splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
- }
-
- /**
- * Gets the supported preview fps (frame-per-second) ranges. Each range
- * contains a minimum fps and maximum fps. If minimum fps equals to
- * maximum fps, the camera outputs frames in fixed frame rate. If not,
- * the camera outputs frames in auto frame rate. The actual frame rate
- * fluctuates between the minimum and the maximum. The values are
- * multiplied by 1000 and represented in integers. For example, if frame
- * rate is 26.623 frames per second, the value is 26623.
- *
- * @return a list of supported preview fps ranges. This method returns a
- * list with at least one element. Every element is an int array
- * of two values - minimum fps and maximum fps. The list is
- * sorted from small to large (first by maximum fps and then
- * minimum fps).
- * @see #PREVIEW_FPS_MIN_INDEX
- * @see #PREVIEW_FPS_MAX_INDEX
- */
- public List<int[]> getSupportedPreviewFpsRange() {
- String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
- return splitRange(str);
- }
-
- /**
- * Sets the image format for preview pictures.
- * <p>If this is never called, the default format will be
- * {@link android.graphics.ImageFormat#NV21}, which
- * uses the NV21 encoding format.</p>
- *
- * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of
- * the available preview formats.
- *
- * <p>It is strongly recommended that either
- * {@link android.graphics.ImageFormat#NV21} or
- * {@link android.graphics.ImageFormat#YV12} is used, since
- * they are supported by all camera devices.</p>
- *
- * <p>For YV12, the image buffer that is received is not necessarily
- * tightly packed, as there may be padding at the end of each row of
- * pixel data, as described in
- * {@link android.graphics.ImageFormat#YV12}. For camera callback data,
- * it can be assumed that the stride of the Y and UV data is the
- * smallest possible that meets the alignment requirements. That is, if
- * the preview size is <var>width x height</var>, then the following
- * equations describe the buffer index for the beginning of row
- * <var>y</var> for the Y plane and row <var>c</var> for the U and V
- * planes:
- *
- * {@code
- * <pre>
- * yStride = (int) ceil(width / 16.0) * 16;
- * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16;
- * ySize = yStride * height;
- * uvSize = uvStride * height / 2;
- * yRowIndex = yStride * y;
- * uRowIndex = ySize + uvSize + uvStride * c;
- * vRowIndex = ySize + uvStride * c;
- * size = ySize + uvSize * 2;</pre>
- * }
- *
- * @param pixel_format the desired preview picture format, defined by
- * one of the {@link android.graphics.ImageFormat} constants. (E.g.,
- * <var>ImageFormat.NV21</var> (default), or
- * <var>ImageFormat.YV12</var>)
- *
- * @see android.graphics.ImageFormat
- * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats
- */
- public void setPreviewFormat(int pixel_format) {
- String s = cameraFormatForPixelFormat(pixel_format);
- if (s == null) {
- throw new IllegalArgumentException(
- "Invalid pixel_format=" + pixel_format);
- }
-
- set(KEY_PREVIEW_FORMAT, s);
- }
-
- /**
- * Returns the image format for preview frames got from
- * {@link PreviewCallback}.
- *
- * @return the preview format.
- * @see android.graphics.ImageFormat
- * @see #setPreviewFormat
- */
- public int getPreviewFormat() {
- return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
- }
-
- /**
- * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
- * is always supported. {@link android.graphics.ImageFormat#YV12}
- * is always supported since API level 12.
- *
- * @return a list of supported preview formats. This method will always
- * return a list with at least one element.
- * @see android.graphics.ImageFormat
- * @see #setPreviewFormat
- */
- public List<Integer> getSupportedPreviewFormats() {
- String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
- ArrayList<Integer> formats = new ArrayList<Integer>();
- for (String s : split(str)) {
- int f = pixelFormatForCameraFormat(s);
- if (f == ImageFormat.UNKNOWN) continue;
- formats.add(f);
- }
- return formats;
- }
-
- /**
- * <p>Sets the dimensions for pictures.</p>
- *
- * <p>Applications need to consider the display orientation. See {@link
- * #setPreviewSize(int,int)} for reference.</p>
- *
- * @param width the width for pictures, in pixels
- * @param height the height for pictures, in pixels
- * @see #setPreviewSize(int,int)
- *
- */
- public void setPictureSize(int width, int height) {
- String v = Integer.toString(width) + "x" + Integer.toString(height);
- set(KEY_PICTURE_SIZE, v);
- }
-
- /**
- * Returns the dimension setting for pictures.
- *
- * @return a Size object with the height and width setting
- * for pictures
- */
- public Size getPictureSize() {
- String pair = get(KEY_PICTURE_SIZE);
- return strToSize(pair);
- }
-
- /**
- * Gets the supported picture sizes.
- *
- * @return a list of supported picture sizes. This method will always
- * return a list with at least one element.
- */
- public List<Size> getSupportedPictureSizes() {
- String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
- return splitSize(str);
- }
-
- /**
- * Sets the image format for pictures.
- *
- * @param pixel_format the desired picture format
- * (<var>ImageFormat.NV21</var>,
- * <var>ImageFormat.RGB_565</var>, or
- * <var>ImageFormat.JPEG</var>)
- * @see android.graphics.ImageFormat
- */
- public void setPictureFormat(int pixel_format) {
- String s = cameraFormatForPixelFormat(pixel_format);
- if (s == null) {
- throw new IllegalArgumentException(
- "Invalid pixel_format=" + pixel_format);
- }
-
- set(KEY_PICTURE_FORMAT, s);
- }
-
- /**
- * Returns the image format for pictures.
- *
- * @return the picture format
- * @see android.graphics.ImageFormat
- */
- public int getPictureFormat() {
- return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
- }
-
- /**
- * Gets the supported picture formats.
- *
- * @return supported picture formats. This method will always return a
- * list with at least one element.
- * @see android.graphics.ImageFormat
- */
- public List<Integer> getSupportedPictureFormats() {
- String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
- ArrayList<Integer> formats = new ArrayList<Integer>();
- for (String s : split(str)) {
- int f = pixelFormatForCameraFormat(s);
- if (f == ImageFormat.UNKNOWN) continue;
- formats.add(f);
- }
- return formats;
- }
-
- private String cameraFormatForPixelFormat(int pixel_format) {
- switch(pixel_format) {
- case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP;
- case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP;
- case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I;
- case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P;
- case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565;
- case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG;
- case ImageFormat.BAYER_RGGB: return PIXEL_FORMAT_BAYER_RGGB;
- default: return null;
- }
- }
-
- private int pixelFormatForCameraFormat(String format) {
- if (format == null)
- return ImageFormat.UNKNOWN;
-
- if (format.equals(PIXEL_FORMAT_YUV422SP))
- return ImageFormat.NV16;
-
- if (format.equals(PIXEL_FORMAT_YUV420SP))
- return ImageFormat.NV21;
-
- if (format.equals(PIXEL_FORMAT_YUV422I))
- return ImageFormat.YUY2;
-
- if (format.equals(PIXEL_FORMAT_YUV420P))
- return ImageFormat.YV12;
-
- if (format.equals(PIXEL_FORMAT_RGB565))
- return ImageFormat.RGB_565;
-
- if (format.equals(PIXEL_FORMAT_JPEG))
- return ImageFormat.JPEG;
-
- return ImageFormat.UNKNOWN;
- }
-
- /**
- * Sets the clockwise rotation angle in degrees relative to the
- * orientation of the camera. This affects the pictures returned from
- * JPEG {@link PictureCallback}. The camera driver may set orientation
- * in the EXIF header without rotating the picture. Or the driver may
- * rotate the picture and the EXIF thumbnail. If the Jpeg picture is
- * rotated, the orientation in the EXIF header will be missing or 1
- * (row #0 is top and column #0 is left side).
- *
- * <p>If applications want to rotate the picture to match the orientation
- * of what users see, apps should use {@link
- * android.view.OrientationEventListener} and {@link CameraInfo}.
- * The value from OrientationEventListener is relative to the natural
- * orientation of the device. CameraInfo.orientation is the angle
- * between camera orientation and natural device orientation. The sum
- * of the two is the rotation angle for back-facing camera. The
- * difference of the two is the rotation angle for front-facing camera.
- * Note that the JPEG pictures of front-facing cameras are not mirrored
- * as in preview display.
- *
- * <p>For example, suppose the natural orientation of the device is
- * portrait. The device is rotated 270 degrees clockwise, so the device
- * orientation is 270. Suppose a back-facing camera sensor is mounted in
- * landscape and the top side of the camera sensor is aligned with the
- * right edge of the display in natural orientation. So the camera
- * orientation is 90. The rotation should be set to 0 (270 + 90).
- *
- * <p>The reference code is as follows.
- *
- * <pre>
- * public void onOrientationChanged(int orientation) {
- * if (orientation == ORIENTATION_UNKNOWN) return;
- * android.hardware.Camera.CameraInfo info =
- * new android.hardware.Camera.CameraInfo();
- * android.hardware.Camera.getCameraInfo(cameraId, info);
- * orientation = (orientation + 45) / 90 * 90;
- * int rotation = 0;
- * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
- * rotation = (info.orientation - orientation + 360) % 360;
- * } else { // back-facing camera
- * rotation = (info.orientation + orientation) % 360;
- * }
- * mParameters.setRotation(rotation);
- * }
- * </pre>
- *
- * @param rotation The rotation angle in degrees relative to the
- * orientation of the camera. Rotation can only be 0,
- * 90, 180 or 270.
- * @throws IllegalArgumentException if rotation value is invalid.
- * @see android.view.OrientationEventListener
- * @see #getCameraInfo(int, CameraInfo)
- */
- public void setRotation(int rotation) {
- if (rotation == 0 || rotation == 90 || rotation == 180
- || rotation == 270) {
- set(KEY_ROTATION, Integer.toString(rotation));
- } else {
- throw new IllegalArgumentException(
- "Invalid rotation=" + rotation);
- }
- }
-
- /**
- * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
- * header.
- *
- * @param latitude GPS latitude coordinate.
- */
- public void setGpsLatitude(double latitude) {
- set(KEY_GPS_LATITUDE, Double.toString(latitude));
- }
-
- /**
- * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
- * header.
- *
- * @param longitude GPS longitude coordinate.
- */
- public void setGpsLongitude(double longitude) {
- set(KEY_GPS_LONGITUDE, Double.toString(longitude));
- }
-
- /**
- * Sets GPS altitude. This will be stored in JPEG EXIF header.
- *
- * @param altitude GPS altitude in meters.
- */
- public void setGpsAltitude(double altitude) {
- set(KEY_GPS_ALTITUDE, Double.toString(altitude));
- }
-
- /**
- * Sets GPS timestamp. This will be stored in JPEG EXIF header.
- *
- * @param timestamp GPS timestamp (UTC in seconds since January 1,
- * 1970).
- */
- public void setGpsTimestamp(long timestamp) {
- set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
- }
-
- /**
- * Sets GPS processing method. It will store up to 32 characters
- * in JPEG EXIF header.
- *
- * @param processing_method The processing method to get this location.
- */
- public void setGpsProcessingMethod(String processing_method) {
- set(KEY_GPS_PROCESSING_METHOD, processing_method);
- }
-
- /**
- * Removes GPS latitude, longitude, altitude, and timestamp from the
- * parameters.
- */
- public void removeGpsData() {
- remove(KEY_GPS_LATITUDE);
- remove(KEY_GPS_LONGITUDE);
- remove(KEY_GPS_ALTITUDE);
- remove(KEY_GPS_TIMESTAMP);
- remove(KEY_GPS_PROCESSING_METHOD);
- }
-
- /**
- * Gets the current white balance setting.
- *
- * @return current white balance. null if white balance setting is not
- * supported.
- * @see #WHITE_BALANCE_AUTO
- * @see #WHITE_BALANCE_INCANDESCENT
- * @see #WHITE_BALANCE_FLUORESCENT
- * @see #WHITE_BALANCE_WARM_FLUORESCENT
- * @see #WHITE_BALANCE_DAYLIGHT
- * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
- * @see #WHITE_BALANCE_TWILIGHT
- * @see #WHITE_BALANCE_SHADE
- *
- */
- public String getWhiteBalance() {
- return get(KEY_WHITE_BALANCE);
- }
-
- /**
- * Sets the white balance. Changing the setting will release the
- * auto-white balance lock. It is recommended not to change white
- * balance and AWB lock at the same time.
- *
- * @param value new white balance.
- * @see #getWhiteBalance()
- * @see #setAutoWhiteBalanceLock(boolean)
- */
- public void setWhiteBalance(String value) {
- String oldValue = get(KEY_WHITE_BALANCE);
- if (same(value, oldValue)) return;
- set(KEY_WHITE_BALANCE, value);
- set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE);
- }
-
- /**
- * Gets the supported white balance.
- *
- * @return a list of supported white balance. null if white balance
- * setting is not supported.
- * @see #getWhiteBalance()
- */
- public List<String> getSupportedWhiteBalance() {
- String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
- return split(str);
- }
-
- /**
- * Gets the current color effect setting.
- *
- * @return current color effect. null if color effect
- * setting is not supported.
- * @see #EFFECT_NONE
- * @see #EFFECT_MONO
- * @see #EFFECT_NEGATIVE
- * @see #EFFECT_SOLARIZE
- * @see #EFFECT_SEPIA
- * @see #EFFECT_POSTERIZE
- * @see #EFFECT_WHITEBOARD
- * @see #EFFECT_BLACKBOARD
- * @see #EFFECT_AQUA
- */
- public String getColorEffect() {
- return get(KEY_EFFECT);
- }
-
- /**
- * Sets the current color effect setting.
- *
- * @param value new color effect.
- * @see #getColorEffect()
- */
- public void setColorEffect(String value) {
- set(KEY_EFFECT, value);
- }
-
- /**
- * Gets the supported color effects.
- *
- * @return a list of supported color effects. null if color effect
- * setting is not supported.
- * @see #getColorEffect()
- */
- public List<String> getSupportedColorEffects() {
- String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
- return split(str);
- }
-
-
- /**
- * Gets the current antibanding setting.
- *
- * @return current antibanding. null if antibanding setting is not
- * supported.
- * @see #ANTIBANDING_AUTO
- * @see #ANTIBANDING_50HZ
- * @see #ANTIBANDING_60HZ
- * @see #ANTIBANDING_OFF
- */
- public String getAntibanding() {
- return get(KEY_ANTIBANDING);
- }
-
- /**
- * Sets the antibanding.
- *
- * @param antibanding new antibanding value.
- * @see #getAntibanding()
- */
- public void setAntibanding(String antibanding) {
- set(KEY_ANTIBANDING, antibanding);
- }
-
- /**
- * Gets the supported antibanding values.
- *
- * @return a list of supported antibanding values. null if antibanding
- * setting is not supported.
- * @see #getAntibanding()
- */
- public List<String> getSupportedAntibanding() {
- String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
- return split(str);
- }
-
- /**
- * Gets the current scene mode setting.
- *
- * @return one of SCENE_MODE_XXX string constant. null if scene mode
- * setting is not supported.
- * @see #SCENE_MODE_AUTO
- * @see #SCENE_MODE_ACTION
- * @see #SCENE_MODE_PORTRAIT
- * @see #SCENE_MODE_LANDSCAPE
- * @see #SCENE_MODE_NIGHT
- * @see #SCENE_MODE_NIGHT_PORTRAIT
- * @see #SCENE_MODE_THEATRE
- * @see #SCENE_MODE_BEACH
- * @see #SCENE_MODE_SNOW
- * @see #SCENE_MODE_SUNSET
- * @see #SCENE_MODE_STEADYPHOTO
- * @see #SCENE_MODE_FIREWORKS
- * @see #SCENE_MODE_SPORTS
- * @see #SCENE_MODE_PARTY
- * @see #SCENE_MODE_CANDLELIGHT
- */
- public String getSceneMode() {
- return get(KEY_SCENE_MODE);
- }
-
- /**
- * Sets the scene mode. Changing scene mode may override other
- * parameters (such as flash mode, focus mode, white balance). For
- * example, suppose originally flash mode is on and supported flash
- * modes are on/off. In night scene mode, both flash mode and supported
- * flash mode may be changed to off. After setting scene mode,
- * applications should call getParameters to know if some parameters are
- * changed.
- *
- * @param value scene mode.
- * @see #getSceneMode()
- */
- public void setSceneMode(String value) {
- set(KEY_SCENE_MODE, value);
- }
-
- /**
- * Gets the supported scene modes.
- *
- * @return a list of supported scene modes. null if scene mode setting
- * is not supported.
- * @see #getSceneMode()
- */
- public List<String> getSupportedSceneModes() {
- String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
- return split(str);
- }
-
- /**
- * Gets the current flash mode setting.
- *
- * @return current flash mode. null if flash mode setting is not
- * supported.
- * @see #FLASH_MODE_OFF
- * @see #FLASH_MODE_AUTO
- * @see #FLASH_MODE_ON
- * @see #FLASH_MODE_RED_EYE
- * @see #FLASH_MODE_TORCH
- */
- public String getFlashMode() {
- return get(KEY_FLASH_MODE);
- }
-
- /**
- * Sets the flash mode.
- *
- * @param value flash mode.
- * @see #getFlashMode()
- */
- public void setFlashMode(String value) {
- set(KEY_FLASH_MODE, value);
- }
-
- /**
- * Gets the supported flash modes.
- *
- * @return a list of supported flash modes. null if flash mode setting
- * is not supported.
- * @see #getFlashMode()
- */
- public List<String> getSupportedFlashModes() {
- String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
- return split(str);
- }
-
- /**
- * Gets the current focus mode setting.
- *
- * @return current focus mode. This method will always return a non-null
- * value. Applications should call {@link
- * #autoFocus(AutoFocusCallback)} to start the focus if focus
- * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
- * @see #FOCUS_MODE_AUTO
- * @see #FOCUS_MODE_INFINITY
- * @see #FOCUS_MODE_MACRO
- * @see #FOCUS_MODE_FIXED
- * @see #FOCUS_MODE_EDOF
- * @see #FOCUS_MODE_CONTINUOUS_VIDEO
- */
- public String getFocusMode() {
- return get(KEY_FOCUS_MODE);
- }
-
- /**
- * Sets the focus mode.
- *
- * @param value focus mode.
- * @see #getFocusMode()
- */
- public void setFocusMode(String value) {
- set(KEY_FOCUS_MODE, value);
- }
-
- /**
- * Gets the supported focus modes.
- *
- * @return a list of supported focus modes. This method will always
- * return a list with at least one element.
- * @see #getFocusMode()
- */
- public List<String> getSupportedFocusModes() {
- String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
- return split(str);
- }
-
- /**
- * Gets the focal length (in millimeter) of the camera.
- *
- * @return the focal length. This method will always return a valid
- * value.
- */
- public float getFocalLength() {
- return Float.parseFloat(get(KEY_FOCAL_LENGTH));
- }
-
- /**
- * Gets the horizontal angle of view in degrees.
- *
- * @return horizontal angle of view. This method will always return a
- * valid value.
- */
- public float getHorizontalViewAngle() {
- return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
- }
-
- /**
- * Gets the vertical angle of view in degrees.
- *
- * @return vertical angle of view. This method will always return a
- * valid value.
- */
- public float getVerticalViewAngle() {
- return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
- }
-
- /**
- * Gets the current exposure compensation index.
- *
- * @return current exposure compensation index. The range is {@link
- * #getMinExposureCompensation} to {@link
- * #getMaxExposureCompensation}. 0 means exposure is not
- * adjusted.
- */
- public int getExposureCompensation() {
- return getInt(KEY_EXPOSURE_COMPENSATION, 0);
- }
-
- /**
- * Sets the exposure compensation index.
- *
- * @param value exposure compensation index. The valid value range is
- * from {@link #getMinExposureCompensation} (inclusive) to {@link
- * #getMaxExposureCompensation} (inclusive). 0 means exposure is
- * not adjusted. Application should call
- * getMinExposureCompensation and getMaxExposureCompensation to
- * know if exposure compensation is supported.
- */
- public void setExposureCompensation(int value) {
- set(KEY_EXPOSURE_COMPENSATION, value);
- }
-
- /**
- * Gets the maximum exposure compensation index.
- *
- * @return maximum exposure compensation index (>=0). If both this
- * method and {@link #getMinExposureCompensation} return 0,
- * exposure compensation is not supported.
- */
- public int getMaxExposureCompensation() {
- return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
- }
-
- /**
- * Gets the minimum exposure compensation index.
- *
- * @return minimum exposure compensation index (<=0). If both this
- * method and {@link #getMaxExposureCompensation} return 0,
- * exposure compensation is not supported.
- */
- public int getMinExposureCompensation() {
- return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
- }
-
- /**
- * Gets the exposure compensation step.
- *
- * @return exposure compensation step. Applications can get EV by
- * multiplying the exposure compensation index and step. Ex: if
- * exposure compensation index is -6 and step is 0.333333333, EV
- * is -2.
- */
- public float getExposureCompensationStep() {
- return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
- }
-
- /**
- * <p>Sets the auto-exposure lock state. Applications should check
- * {@link #isAutoExposureLockSupported} before using this method.</p>
- *
- * <p>If set to true, the camera auto-exposure routine will immediately
- * pause until the lock is set to false. Exposure compensation settings
- * changes will still take effect while auto-exposure is locked.</p>
- *
- * <p>If auto-exposure is already locked, setting this to true again has
- * no effect (the driver will not recalculate exposure values).</p>
- *
- * <p>Stopping preview with {@link #stopPreview()}, or triggering still
- * image capture with {@link #takePicture(Camera.ShutterCallback,
- * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
- * lock.</p>
- *
- * <p>Exposure compensation, auto-exposure lock, and auto-white balance
- * lock can be used to capture an exposure-bracketed burst of images,
- * for example.</p>
- *
- * <p>Auto-exposure state, including the lock state, will not be
- * maintained after camera {@link #release()} is called. Locking
- * auto-exposure after {@link #open()} but before the first call to
- * {@link #startPreview()} will not allow the auto-exposure routine to
- * run at all, and may result in severely over- or under-exposed
- * images.</p>
- *
- * @param toggle new state of the auto-exposure lock. True means that
- * auto-exposure is locked, false means that the auto-exposure
- * routine is free to run normally.
- *
- * @see #getAutoExposureLock()
- */
- public void setAutoExposureLock(boolean toggle) {
- set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
- }
-
- /**
- * Gets the state of the auto-exposure lock. Applications should check
- * {@link #isAutoExposureLockSupported} before using this method. See
- * {@link #setAutoExposureLock} for details about the lock.
- *
- * @return State of the auto-exposure lock. Returns true if
- * auto-exposure is currently locked, and false otherwise.
- *
- * @see #setAutoExposureLock(boolean)
- *
- */
- public boolean getAutoExposureLock() {
- String str = get(KEY_AUTO_EXPOSURE_LOCK);
- return TRUE.equals(str);
- }
-
- /**
- * Returns true if auto-exposure locking is supported. Applications
- * should call this before trying to lock auto-exposure. See
- * {@link #setAutoExposureLock} for details about the lock.
- *
- * @return true if auto-exposure lock is supported.
- * @see #setAutoExposureLock(boolean)
- *
- */
- public boolean isAutoExposureLockSupported() {
- String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
- return TRUE.equals(str);
- }
-
- /**
- * <p>Sets the auto-white balance lock state. Applications should check
- * {@link #isAutoWhiteBalanceLockSupported} before using this
- * method.</p>
- *
- * <p>If set to true, the camera auto-white balance routine will
- * immediately pause until the lock is set to false.</p>
- *
- * <p>If auto-white balance is already locked, setting this to true
- * again has no effect (the driver will not recalculate white balance
- * values).</p>
- *
- * <p>Stopping preview with {@link #stopPreview()}, or triggering still
- * image capture with {@link #takePicture(Camera.ShutterCallback,
- * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
- * the lock.</p>
- *
- * <p> Changing the white balance mode with {@link #setWhiteBalance}
- * will release the auto-white balance lock if it is set.</p>
- *
- * <p>Exposure compensation, AE lock, and AWB lock can be used to
- * capture an exposure-bracketed burst of images, for example.
- * Auto-white balance state, including the lock state, will not be
- * maintained after camera {@link #release()} is called. Locking
- * auto-white balance after {@link #open()} but before the first call to
- * {@link #startPreview()} will not allow the auto-white balance routine
- * to run at all, and may result in severely incorrect color in captured
- * images.</p>
- *
- * @param toggle new state of the auto-white balance lock. True means
- * that auto-white balance is locked, false means that the
- * auto-white balance routine is free to run normally.
- *
- * @see #getAutoWhiteBalanceLock()
- * @see #setWhiteBalance(String)
- */
- public void setAutoWhiteBalanceLock(boolean toggle) {
- set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
- }
-
- /**
- * Gets the state of the auto-white balance lock. Applications should
- * check {@link #isAutoWhiteBalanceLockSupported} before using this
- * method. See {@link #setAutoWhiteBalanceLock} for details about the
- * lock.
- *
- * @return State of the auto-white balance lock. Returns true if
- * auto-white balance is currently locked, and false
- * otherwise.
- *
- * @see #setAutoWhiteBalanceLock(boolean)
- *
- */
- public boolean getAutoWhiteBalanceLock() {
- String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
- return TRUE.equals(str);
- }
-
- /**
- * Returns true if auto-white balance locking is supported. Applications
- * should call this before trying to lock auto-white balance. See
- * {@link #setAutoWhiteBalanceLock} for details about the lock.
- *
- * @return true if auto-white balance lock is supported.
- * @see #setAutoWhiteBalanceLock(boolean)
- *
- */
- public boolean isAutoWhiteBalanceLockSupported() {
- String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
- return TRUE.equals(str);
- }
-
- /**
- * Gets current zoom value. This also works when smooth zoom is in
- * progress. Applications should check {@link #isZoomSupported} before
- * using this method.
- *
- * @return the current zoom value. The range is 0 to {@link
- * #getMaxZoom}. 0 means the camera is not zoomed.
- */
- public int getZoom() {
- return getInt(KEY_ZOOM, 0);
- }
-
- /**
- * Sets current zoom value. If the camera is zoomed (value > 0), the
- * actual picture size may be smaller than picture size setting.
- * Applications can check the actual picture size after picture is
- * returned from {@link PictureCallback}. The preview size remains the
- * same in zoom. Applications should check {@link #isZoomSupported}
- * before using this method.
- *
- * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
- */
- public void setZoom(int value) {
- set(KEY_ZOOM, value);
- }
-
- /**
- * Returns true if zoom is supported. Applications should call this
- * before using other zoom methods.
- *
- * @return true if zoom is supported.
- */
- public boolean isZoomSupported() {
- String str = get(KEY_ZOOM_SUPPORTED);
- return TRUE.equals(str);
- }
-
- /**
- * Gets the maximum zoom value allowed for snapshot. This is the maximum
- * value that applications can set to {@link #setZoom(int)}.
- * Applications should call {@link #isZoomSupported} before using this
- * method. This value may change in different preview size. Applications
- * should call this again after setting preview size.
- *
- * @return the maximum zoom value supported by the camera.
- */
- public int getMaxZoom() {
- return getInt(KEY_MAX_ZOOM, 0);
- }
-
- /**
- * Gets the zoom ratios of all zoom values. Applications should check
- * {@link #isZoomSupported} before using this method.
- *
- * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
- * returned as 320. The number of elements is {@link
- * #getMaxZoom} + 1. The list is sorted from small to large. The
- * first element is always 100. The last element is the zoom
- * ratio of the maximum zoom value.
- */
- public List<Integer> getZoomRatios() {
- return splitInt(get(KEY_ZOOM_RATIOS));
- }
-
- /**
- * Returns true if smooth zoom is supported. Applications should call
- * this before using other smooth zoom methods.
- *
- * @return true if smooth zoom is supported.
- */
- public boolean isSmoothZoomSupported() {
- String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
- return TRUE.equals(str);
- }
-
- /**
- * <p>Gets the distances from the camera to where an object appears to be
- * in focus. The object is sharpest at the optimal focus distance. The
- * depth of field is the far focus distance minus near focus distance.</p>
- *
- * <p>Focus distances may change after calling {@link
- * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
- * #startPreview()}. Applications can call {@link #getParameters()}
- * and this method anytime to get the latest focus distances. If the
- * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
- * from time to time.</p>
- *
- * <p>This method is intended to estimate the distance between the camera
- * and the subject. After autofocus, the subject distance may be within
- * near and far focus distance. However, the precision depends on the
- * camera hardware, autofocus algorithm, the focus area, and the scene.
- * The error can be large and it should be only used as a reference.</p>
- *
- * <p>Far focus distance >= optimal focus distance >= near focus distance.
- * If the focus distance is infinity, the value will be
- * {@code Float.POSITIVE_INFINITY}.</p>
- *
- * @param output focus distances in meters. output must be a float
- * array with three elements. Near focus distance, optimal focus
- * distance, and far focus distance will be filled in the array.
- * @see #FOCUS_DISTANCE_NEAR_INDEX
- * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
- * @see #FOCUS_DISTANCE_FAR_INDEX
- */
- public void getFocusDistances(float[] output) {
- if (output == null || output.length != 3) {
- throw new IllegalArgumentException(
- "output must be a float array with three elements.");
- }
- splitFloat(get(KEY_FOCUS_DISTANCES), output);
- }
-
- /**
- * Gets the maximum number of focus areas supported. This is the maximum
- * length of the list in {@link #setFocusAreas(List)} and
- * {@link #getFocusAreas()}.
- *
- * @return the maximum number of focus areas supported by the camera.
- * @see #getFocusAreas()
- */
- public int getMaxNumFocusAreas() {
- return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
- }
-
- /**
- * <p>Gets the current focus areas. Camera driver uses the areas to decide
- * focus.</p>
- *
- * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
- * call {@link #getMaxNumFocusAreas()} to know the maximum number of
- * focus areas first. If the value is 0, focus area is not supported.</p>
- *
- * <p>Each focus area is a rectangle with specified weight. The direction
- * is relative to the sensor orientation, that is, what the sensor sees.
- * The direction is not affected by the rotation or mirroring of
- * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
- * range from -1000 to 1000. (-1000, -1000) is the upper left point.
- * (1000, 1000) is the lower right point. The width and height of focus
- * areas cannot be 0 or negative.</p>
- *
- * <p>The weight must range from 1 to 1000. The weight should be
- * interpreted as a per-pixel weight - all pixels in the area have the
- * specified weight. This means a small area with the same weight as a
- * larger area will have less influence on the focusing than the larger
- * area. Focus areas can partially overlap and the driver will add the
- * weights in the overlap region.</p>
- *
- * <p>A special case of a {@code null} focus area list means the driver is
- * free to select focus targets as it wants. For example, the driver may
- * use more signals to select focus areas and change them
- * dynamically. Apps can set the focus area list to {@code null} if they
- * want the driver to completely control focusing.</p>
- *
- * <p>Focus areas are relative to the current field of view
- * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
- * represents the top of the currently visible camera frame. The focus
- * area cannot be set to be outside the current field of view, even
- * when using zoom.</p>
- *
- * <p>Focus area only has effect if the current focus mode is
- * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO},
- * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or
- * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p>
- *
- * @return a list of current focus areas
- */
- public List<Area> getFocusAreas() {
- return splitArea(get(KEY_FOCUS_AREAS));
- }
-
- /**
- * Sets focus areas. See {@link #getFocusAreas()} for documentation.
- *
- * @param focusAreas the focus areas
- * @see #getFocusAreas()
- */
- public void setFocusAreas(List<Area> focusAreas) {
- set(KEY_FOCUS_AREAS, focusAreas);
- }
-
- /**
- * Gets the maximum number of metering areas supported. This is the
- * maximum length of the list in {@link #setMeteringAreas(List)} and
- * {@link #getMeteringAreas()}.
- *
- * @return the maximum number of metering areas supported by the camera.
- * @see #getMeteringAreas()
- */
- public int getMaxNumMeteringAreas() {
- return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
- }
-
- /**
- * <p>Gets the current metering areas. Camera driver uses these areas to
- * decide exposure.</p>
- *
- * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
- * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
- * metering areas first. If the value is 0, metering area is not
- * supported.</p>
- *
- * <p>Each metering area is a rectangle with specified weight. The
- * direction is relative to the sensor orientation, that is, what the
- * sensor sees. The direction is not affected by the rotation or
- * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
- * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
- * point. (1000, 1000) is the lower right point. The width and height of
- * metering areas cannot be 0 or negative.</p>
- *
- * <p>The weight must range from 1 to 1000, and represents a weight for
- * every pixel in the area. This means that a large metering area with
- * the same weight as a smaller area will have more effect in the
- * metering result. Metering areas can partially overlap and the driver
- * will add the weights in the overlap region.</p>
- *
- * <p>A special case of a {@code null} metering area list means the driver
- * is free to meter as it chooses. For example, the driver may use more
- * signals to select metering areas and change them dynamically. Apps
- * can set the metering area list to {@code null} if they want the
- * driver to completely control metering.</p>
- *
- * <p>Metering areas are relative to the current field of view
- * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
- * represents the top of the currently visible camera frame. The
- * metering area cannot be set to be outside the current field of view,
- * even when using zoom.</p>
- *
- * <p>No matter what metering areas are, the final exposure are compensated
- * by {@link #setExposureCompensation(int)}.</p>
- *
- * @return a list of current metering areas
- */
- public List<Area> getMeteringAreas() {
- return splitArea(get(KEY_METERING_AREAS));
- }
-
- /**
- * Sets metering areas. See {@link #getMeteringAreas()} for
- * documentation.
- *
- * @param meteringAreas the metering areas
- * @see #getMeteringAreas()
- */
- public void setMeteringAreas(List<Area> meteringAreas) {
- set(KEY_METERING_AREAS, meteringAreas);
- }
-
- /**
- * Gets the maximum number of detected faces supported. This is the
- * maximum length of the list returned from {@link FaceDetectionListener}.
- * If the return value is 0, face detection of the specified type is not
- * supported.
- *
- * @return the maximum number of detected face supported by the camera.
- * @see #startFaceDetection()
- */
- public int getMaxNumDetectedFaces() {
- return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
- }
-
- /**
- * Sets recording mode hint. This tells the camera that the intent of
- * the application is to record videos {@link
- * android.media.MediaRecorder#start()}, not to take still pictures
- * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
- * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
- * allow MediaRecorder.start() to start faster or with fewer glitches on
- * output. This should be called before starting preview for the best
- * result, but can be changed while the preview is active. The default
- * value is false.
- *
- * The app can still call takePicture() when the hint is true or call
- * MediaRecorder.start() when the hint is false. But the performance may
- * be worse.
- *
- * @param hint true if the apps intend to record videos using
- * {@link android.media.MediaRecorder}.
- */
- public void setRecordingHint(boolean hint) {
- set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
- }
-
- /**
- * Returns true if video snapshot is supported. That is, applications
- * can call {@link #takePicture(Camera.ShutterCallback,
- * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}
- * during recording. Applications do not need to call {@link
- * #startPreview()} after taking a picture. The preview will be still
- * active. Other than that, taking a picture during recording is
- * identical to taking a picture normally. All settings and methods
- * related to takePicture work identically. Ex: {@link
- * #getPictureSize()}, {@link #getSupportedPictureSizes()}, {@link
- * #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The
- * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and {@link
- * #FLASH_MODE_ON} also still work, but the video will record the flash.
- *
- * Applications can set shutter callback as null to avoid the shutter
- * sound. It is also recommended to set raw picture and post view
- * callbacks to null to avoid the interrupt of preview display.
- *
- * Field-of-view of the recorded video may be different from that of the
- * captured pictures.
- *
- * @return true if video snapshot is supported.
- */
- public boolean isVideoSnapshotSupported() {
- String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED);
- return TRUE.equals(str);
- }
-
- /**
- * <p>Enables and disables video stabilization. Use
- * {@link #isVideoStabilizationSupported} to determine if calling this
- * method is valid.</p>
- *
- * <p>Video stabilization reduces the shaking due to the motion of the
- * camera in both the preview stream and in recorded videos, including
- * data received from the preview callback. It does not reduce motion
- * blur in images captured with
- * {@link Camera#takePicture takePicture}.</p>
- *
- * <p>Video stabilization can be enabled and disabled while preview or
- * recording is active, but toggling it may cause a jump in the video
- * stream that may be undesirable in a recorded video.</p>
- *
- * @param toggle Set to true to enable video stabilization, and false to
- * disable video stabilization.
- * @see #isVideoStabilizationSupported()
- * @see #getVideoStabilization()
- */
- public void setVideoStabilization(boolean toggle) {
- set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE);
- }
-
- /**
- * Get the current state of video stabilization. See
- * {@link #setVideoStabilization} for details of video stabilization.
- *
- * @return true if video stabilization is enabled
- * @see #isVideoStabilizationSupported()
- * @see #setVideoStabilization(boolean)
- */
- public boolean getVideoStabilization() {
- String str = get(KEY_VIDEO_STABILIZATION);
- return TRUE.equals(str);
- }
-
- /**
- * Returns true if video stabilization is supported. See
- * {@link #setVideoStabilization} for details of video stabilization.
- *
- * @return true if video stabilization is supported
- * @see #setVideoStabilization(boolean)
- * @see #getVideoStabilization()
- */
- public boolean isVideoStabilizationSupported() {
- String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED);
- return TRUE.equals(str);
- }
-
- // Splits a comma delimited string to an ArrayList of String.
- // Return null if the passing string is null or the size is 0.
- private ArrayList<String> split(String str) {
- if (str == null) return null;
-
- // Use StringTokenizer because it is faster than split.
- StringTokenizer tokenizer = new StringTokenizer(str, ",");
- ArrayList<String> substrings = new ArrayList<String>();
- while (tokenizer.hasMoreElements()) {
- substrings.add(tokenizer.nextToken());
- }
- return substrings;
- }
-
- // Splits a comma delimited string to an ArrayList of Integer.
- // Return null if the passing string is null or the size is 0.
- private ArrayList<Integer> splitInt(String str) {
- if (str == null) return null;
-
- StringTokenizer tokenizer = new StringTokenizer(str, ",");
- ArrayList<Integer> substrings = new ArrayList<Integer>();
- while (tokenizer.hasMoreElements()) {
- String token = tokenizer.nextToken();
- substrings.add(Integer.parseInt(token));
- }
- if (substrings.size() == 0) return null;
- return substrings;
- }
-
- private void splitInt(String str, int[] output) {
- if (str == null) return;
-
- StringTokenizer tokenizer = new StringTokenizer(str, ",");
- int index = 0;
- while (tokenizer.hasMoreElements()) {
- String token = tokenizer.nextToken();
- output[index++] = Integer.parseInt(token);
- }
- }
-
- // Splits a comma delimited string to an ArrayList of Float.
- private void splitFloat(String str, float[] output) {
- if (str == null) return;
-
- StringTokenizer tokenizer = new StringTokenizer(str, ",");
- int index = 0;
- while (tokenizer.hasMoreElements()) {
- String token = tokenizer.nextToken();
- output[index++] = Float.parseFloat(token);
- }
- }
-
- // Returns the value of a float parameter.
- private float getFloat(String key, float defaultValue) {
- try {
- return Float.parseFloat(mMap.get(key));
- } catch (NumberFormatException ex) {
- return defaultValue;
- }
- }
-
- // Returns the value of a integer parameter.
- private int getInt(String key, int defaultValue) {
- try {
- return Integer.parseInt(mMap.get(key));
- } catch (NumberFormatException ex) {
- return defaultValue;
- }
- }
-
- // Splits a comma delimited string to an ArrayList of Size.
- // Return null if the passing string is null or the size is 0.
- private ArrayList<Size> splitSize(String str) {
- if (str == null) return null;
-
- StringTokenizer tokenizer = new StringTokenizer(str, ",");
- ArrayList<Size> sizeList = new ArrayList<Size>();
- while (tokenizer.hasMoreElements()) {
- Size size = strToSize(tokenizer.nextToken());
- if (size != null) sizeList.add(size);
- }
- if (sizeList.size() == 0) return null;
- return sizeList;
- }
-
- // Parses a string (ex: "480x320") to Size object.
- // Return null if the passing string is null.
- private Size strToSize(String str) {
- if (str == null) return null;
-
- int pos = str.indexOf('x');
- if (pos != -1) {
- String width = str.substring(0, pos);
- String height = str.substring(pos + 1);
- return new Size(Integer.parseInt(width),
- Integer.parseInt(height));
- }
- Log.e(TAG, "Invalid size parameter string=" + str);
- return null;
- }
-
- // Splits a comma delimited string to an ArrayList of int array.
- // Example string: "(10000,26623),(10000,30000)". Return null if the
- // passing string is null or the size is 0.
- private ArrayList<int[]> splitRange(String str) {
- if (str == null || str.charAt(0) != '('
- || str.charAt(str.length() - 1) != ')') {
- Log.e(TAG, "Invalid range list string=" + str);
- return null;
- }
-
- ArrayList<int[]> rangeList = new ArrayList<int[]>();
- int endIndex, fromIndex = 1;
- do {
- int[] range = new int[2];
- endIndex = str.indexOf("),(", fromIndex);
- if (endIndex == -1) endIndex = str.length() - 1;
- splitInt(str.substring(fromIndex, endIndex), range);
- rangeList.add(range);
- fromIndex = endIndex + 3;
- } while (endIndex != str.length() - 1);
-
- if (rangeList.size() == 0) return null;
- return rangeList;
- }
-
- // Splits a comma delimited string to an ArrayList of Area objects.
- // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
- // the passing string is null or the size is 0 or (0,0,0,0,0).
- private ArrayList<Area> splitArea(String str) {
- if (str == null || str.charAt(0) != '('
- || str.charAt(str.length() - 1) != ')') {
- Log.e(TAG, "Invalid area string=" + str);
- return null;
- }
-
- ArrayList<Area> result = new ArrayList<Area>();
- int endIndex, fromIndex = 1;
- int[] array = new int[5];
- do {
- endIndex = str.indexOf("),(", fromIndex);
- if (endIndex == -1) endIndex = str.length() - 1;
- splitInt(str.substring(fromIndex, endIndex), array);
- Rect rect = new Rect(array[0], array[1], array[2], array[3]);
- result.add(new Area(rect, array[4]));
- fromIndex = endIndex + 3;
- } while (endIndex != str.length() - 1);
-
- if (result.size() == 0) return null;
-
- if (result.size() == 1) {
- Area area = result.get(0);
- Rect rect = area.rect;
- if (rect.left == 0 && rect.top == 0 && rect.right == 0
- && rect.bottom == 0 && area.weight == 0) {
- return null;
- }
- }
-
- return result;
- }
-
- private boolean same(String s1, String s2) {
- if (s1 == null && s2 == null) return true;
- if (s1 != null && s1.equals(s2)) return true;
- return false;
- }
- };
-}
diff --git a/cpcam/java/com/ti/omap/android/cpcam/CPCamBufferQueue.java b/cpcam/java/com/ti/omap/android/cpcam/CPCamBufferQueue.java
deleted file mode 100644
index b567131..0000000
--- a/cpcam/java/com/ti/omap/android/cpcam/CPCamBufferQueue.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (c) 2010, Texas Instruments Incorporated
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-package com.ti.omap.android.cpcam;
-
-import java.lang.ref.WeakReference;
-
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-
-/**
- * BufferQueue provides image and video buffers for the for the system to use.
- * These buffers can be accessed by the application as well as the lower level
- * system and drivers in a zero-copy fashion.
- *
- * This implementation is based off of SurfaceTexture.java found in
- * frameworks/base project
- */
-public class CPCamBufferQueue {
-
- private EventHandler mEventHandler;
- private OnFrameAvailableListener mOnFrameAvailableListener;
-
- /**
- * This field is used by native code, do not access or modify.
- */
- private int mBufferQueue;
- private int mNativeContext;
-
- /**
- * Callback interface for being notified that a new stream frame is available.
- */
- public interface OnFrameAvailableListener {
- void onFrameAvailable(CPCamBufferQueue bufferQueue);
- }
-
- /**
- * Exception thrown when a surface couldn't be created or resized
- */
- public static class OutOfResourcesException extends Exception {
- public OutOfResourcesException() {
- }
- public OutOfResourcesException(String name) {
- super(name);
- }
- }
-
- /**
- * Construct a new BufferQueue.
- *
- */
- public CPCamBufferQueue() {
- this(false);
- }
-
- /**
- * Construct a new BufferQueue.
- *
- * @param allowSynchronousMode whether the BufferQueue can run in the synchronous mode.
- * To avoid the thread block, set allowSynchronousMode to false.
- *
- */
- public CPCamBufferQueue(boolean allowSynchronousMode) {
- Looper looper;
- if ((looper = Looper.myLooper()) != null) {
- mEventHandler = new EventHandler(looper);
- } else if ((looper = Looper.getMainLooper()) != null) {
- mEventHandler = new EventHandler(looper);
- } else {
- mEventHandler = null;
- }
- nativeInit(new WeakReference<CPCamBufferQueue>(this), allowSynchronousMode);
- }
-
- /**
- * Register a callback to be invoked when a new image frame becomes available to the
- * BufferQueue.
- */
- public void setOnFrameAvailableListener(OnFrameAvailableListener l) {
- mOnFrameAvailableListener = l;
- }
-
- /**
- * Set the default size of the image buffers. The image producer may override the buffer size,
- * in which case the producer-set buffer size will be used, not the default size set by this
- * method. Both video and camera based image producers do override the size.
- */
- public void setDefaultBufferSize(int width, int height) {
- nativeSetDefaultBufferSize(width, height);
- }
-
- /**
- * Updates and takes a reference to the current buffer from the queue.
- *
- * Returns buffer slot index of the buffer
- *
- * Applications must call {@link #releaseBuffer} to release reference to
- * buffer the buffer
- */
- public int acquireBuffer() {
- return nativeAcquireBuffer();
- }
-
- /**
- * Releases reference to buffer.
- *
- * @param slot indicates the slot index of the buffer to be released
- *
- */
- public void releaseBuffer(int slot) {
- nativeReleaseBuffer(slot);
- }
-
- /**
- * Gets the unique ID of the Buffer Queue
- *
- * @param slot indicates the slot index of the buffer to be released
- *
- */
- public String getId() {
- return nativeGetId();
- }
-
- /**
- * Retrieve the timestamp associated with the texture image set by the most recent call to
- * updateTexImage.
- *
- * This timestamp is in nanoseconds, and is normally monotonically increasing. The timestamp
- * should be unaffected by time-of-day adjustments, and for a camera should be strictly
- * monotonic but for a MediaPlayer may be reset when the position is set. The
- * specific meaning and zero point of the timestamp depends on the source providing images to
- * the CPCamBufferQueue. Unless otherwise specified by the image source, timestamps cannot
- * generally be compared across CPCamBufferQueue instances, or across multiple program
- * invocations. It is mostly useful for determining time offsets between subsequent frames.
- */
-
- public long getTimestamp(int slot) {
- return nativeGetTimestamp(slot);
- }
-
- /**
- * release() frees all the buffers and puts the BufferQueue into the
- * 'abandoned' state. Once put in this state the BufferQueue can never
- * leave it. When in the 'abandoned' state, all methods of the
- * interface will fail with the NO_INIT error.
- *
- * Note that while calling this method causes all the buffers to be freed
- * from the perspective of the the BufferQueue, if there are additional
- * references on the buffers (e.g. if a buffer is referenced by a client)
- * then those buffer will remain allocated.
- *
- * Always call this method when you are done with BufferQueue. Failing
- * to do so may delay resource deallocation for a significant amount of
- * time.
- */
- public void release() {
- nativeRelease();
- }
-
- protected void finalize() throws Throwable {
- try {
- nativeFinalize();
- } finally {
- super.finalize();
- }
- }
-
- private class EventHandler extends Handler {
- public EventHandler(Looper looper) {
- super(looper);
- }
-
- @Override
- public void handleMessage(Message msg) {
- if (mOnFrameAvailableListener != null) {
- mOnFrameAvailableListener.onFrameAvailable(CPCamBufferQueue.this);
- }
- }
- }
-
- /**
- * This method is invoked from native code only.
- */
- @SuppressWarnings({"UnusedDeclaration"})
- private static void postEventFromNative(Object selfRef) {
- WeakReference weakSelf = (WeakReference)selfRef;
- CPCamBufferQueue st = (CPCamBufferQueue)weakSelf.get();
- if (st == null) {
- return;
- }
-
- if (st.mEventHandler != null) {
- Message m = st.mEventHandler.obtainMessage();
- st.mEventHandler.sendMessage(m);
- }
- }
-
- private native void nativeInit(Object weakSelf, boolean allowSynchronousMode);
- private native void nativeFinalize();
- private native long nativeGetTimestamp(int slot);
- private native void nativeSetDefaultBufferSize(int width, int height);
- private native int nativeAcquireBuffer();
- private native void nativeReleaseBuffer(int slot);
- private native int nativeGetQueuedCount();
- private native void nativeRelease();
- private native final String nativeGetId();
-
- /*
- * We use a class initializer to allow the native code to cache some
- * field offsets.
- */
- private static native void nativeClassInit();
- static { nativeClassInit(); }
-}
diff --git a/cpcam/java/com/ti/omap/android/cpcam/CPCamMetadata.java b/cpcam/java/com/ti/omap/android/cpcam/CPCamMetadata.java
deleted file mode 100644
index 25800c3..0000000
--- a/cpcam/java/com/ti/omap/android/cpcam/CPCamMetadata.java
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.ti.omap.android.cpcam;
-
-import android.graphics.*;
-import java.nio.ByteBuffer;
-
-/**
- * Used for passing camera related metadata
- */
-public class CPCamMetadata {
-
- protected CPCamMetadata() {
- }
-
- public static CPCamMetadata getMetadata(CPCamBufferQueue st) {
- return nativeRetrieveMetadata(st, 0);
- }
-
- public static CPCamMetadata getMetadata(CPCamBufferQueue st, int slot) {
- return nativeRetrieveMetadata(st, slot);
- }
-
- public static class BSCPosition {
-
- /**
- * The number of row/column sums cannot exceed 1920, implies:
- * - (vectors + 1) * (vertical_number) <=1920, for row sums
- * - (vectors + 1) * (horizontal_number) <=1920, for column sums
- */
- BSCPosition () {
- }
-
- /**
- * vectors : number of row/column sum vectors. Max value = 4
- */
- public int vectors;
-
- /**
- * shift : down-shift of input data
- */
- public int shift;
-
- /**
- * vertical_position : vertical position of first pixel to be summed
- */
- public int verticalPosition;
-
- /**
- * horizontal_position : horizontal position of first pixel to be summed
- */
- public int horizontalPosition;
-
- /**
- * vertical_number : number of pixels sampled vertically
- */
- public int verticalNumber;
-
- /**
- * horizontal_number : number of pixels sampled horizontally
- */
- public int horizontalNumber;
-
- /**
- * vertical_skip : vertical spacing between adjacent pixels to be summed
- */
- public int verticalSkip;
-
- /**
- * horizontal_skip : horizontal pixel spacing between adjacent pixels to be summed
- */
- public int horizontalSkip;
- }
-
- public static class H3AConfig {
-
- H3AConfig () {
- }
-
- /**
- * vertical_position: vertical start point of paxel grid
- * w.r.t first pixel of input image frame
- */
- public int verticalPosition;
-
- /**
- * vertical_size: vertical paxel size
- */
- public int verticalSize;
-
- /**
- * horizontal_position: horizontal start point of paxel grid
- * w.r.t first pixel of input image frame
- */
- public int horizontalPosition;
-
- /**
- * horizontal_size: horizontal paxel size
- */
- public int horizontalSize;
-
- /**
- * vertical_count: num of vert paxels. AF/AEWB paxels
- * are always adjacent to each other
- */
- public int verticalCount;
-
- /**
- * vetical_increment: num of pixels to skip within a paxel, vertically
- */
- public int veticalIncrement;
-
- /**
- * horizontal_count: num of horz paxels.
- * AF/AEWB paxels are always adjacent to each other
- */
- public int horizontalCount;
-
- /**
- * horizontal_increment: num of pixels to skip within a paxel,
- * horizontally
- */
- public int horizontalIncrement;
- }
-
- /**
- * Used to store the information about frame
- * number in processing sequence (i.e preview)
- */
- public int frameNumber;
-
- /**
- * Used to store the information about shot number
- * in a burst sequence.
- */
- public int shotNumber;
-
- /**
- * Used to store analog gain information for
- * current frame. Metadata is represented as 100*EV.
- */
- public int analogGain;
-
- /**
- * Used for storing analog gain information
- * requested by application for current frame. Metadata is represented as 100*EV.
- */
- public int analogGainReq;
-
- /**
- * Used for storing the analog gain
- * lower limit for current frame. Metadata is represented as 100*EV.
- */
- public int analogGainMin;
-
- /**
- * Used for storing the analog gain
- * upper limit for current frame. Metadata is represented as 100*EV.
- */
- public int analogGainMax;
-
- /**
- * Used for storing the analog gain
- * deviation after flicker reduction for current frame. Metadata is represented as 100*EV.
- */
- public int analogGainDev;
-
- /**
- * Used for storing analog gain error for
- * current frame. Represents the difference between requested value and actual value.
- */
- public int analogGainError;
-
- /**
- * Used for storing the exposure time for current frame.
- * Metadata is represented in us.
- */
- public int exposureTime;
-
- /**
- * Used for storing the exposure time requested by
- * application for current frame. Metadata is represented in us.
- */
- public int exposureTimeReq;
-
- /**
- * Used for storing the exposure time lower limit for
- * current frame. Metadata is represented in us.
- */
- public int exposureTimeMin;
-
- /**
- * Used for storing the exposure time upper limit for
- * current frame. Metadata is represented in us.
- */
- public int exposureTimeMax;
-
- /**
- * Used for storing the exposure time
- * deviation after flicker reduction for current frame. Metadata is represented in us.
- */
- public int exposureTimeDev;
-
- /**
- * Used for storing the time difference between
- * requested exposure time and actual exposure time.
- */
- public int exposureTimeError;
-
- /**
- * Used for storing the current total exposure
- * compensation requested by application for current frame. Metadata is represented as 100*EV.
- */
- public int exposureCompensationReq;
-
- /**
- * Used for storing current total exposure
- * deviation for current frame. Metadata is represented as 100*EV.
- */
- public int exposureDev;
-
- /**
- * Represents the timestamp in terms of a reference clock.
- */
- public long timestamp;
-
- /**
- * Represents the temperature of current scene in Kelvin
- */
- public int awbTemp;
-
- /**
- * Represent gains applied to each RGGB color channel.
- */
- public int gainR;
- public int gainGR;
- public int gainGB;
- public int gainB;
-
- /**
- * Represent offsets applied to each RGGB color channel.
- */
- public int offsetR;
- public int offsetGR;
- public int offsetGB;
- public int offsetB;
-
- /**
- * Used to store the current
- * lens shading correction table. The table consists of an
- * N by M array of elements. Each element has 4 integer values
- * ranging from 0 to 1000, corresponding to a multiplier for
- * each of the Bayer color filter channels (R, Gr, Gb, B).
- * Correction is performed on pixels in a Bayer image by interpolating
- * the corresponding color filter channel in the array, and then
- * multiplying by (value/1000).
- */
- public ByteBuffer lscTable;
-
- /**
- * Indicates whether LSC table is applied or not
- */
- public int lscTableApplied;
-
- /**
- * An array of the detected faces. The length is numberOfFaces.
- * The Face rectangles have to following layout:
- * int top - Top coordinate of the face rectangle,
- * int left - Left coordinate of the face rectangle,
- * int bottom - Bottom coordinate of the face rectangle.
- * int right - Right coordnate of the face rectangle.
- */
- public ByteBuffer faces;
-
- public int numberOfFaces;
-
- /**
- * Width of the auxiliary image
- */
- public int auxImageWidth;
-
- /**
- * Height of the auxiliary image
- */
- public int auxImageHeight;
-
- /**
- * Auxiliary image buffer NV12 pixelformat
- */
- public ByteBuffer auxImage;
-
- /**
- * Element to be summed
- * Y = 0,
- * Cb = 1,
- * Cr = 2,
- */
- public int bscColorElement;
-
- /**
- * BSC row sum descriptor
- */
- BSCPosition bscRowPosition;
-
- /**
- * BSC column sum descriptor
- */
- BSCPosition bscColPosition;
-
- /**
- * Each value corresponds to sum value in a row.
- * Num of row sums = row_position.vectors * row_position.vertical_number
- */
- public ByteBuffer bscRowSum;
-
- /**
- * Each value corresponds to sum value in a row.
- * Num of row sums = row_position.vectors * row_position.vertical_number
- */
- public ByteBuffer bscColSum;
-
- /**
- * When Vertical focus is disabled, R,G,B location w.r.t.
- * to paxel start location is specified by this field.
- * AF_RGBPOSITION_BAYER_GR_GB = 0
- * AF_RGBPOSITION_BAYER_RG_GB = 1
- * AF_RGBPOSITION_BAYER_GR_BG = 2
- * AF_RGBPOSITION_BAYER_RG_BG = 3
- * AF_RGBPOSITION_CUSTOM_GG_RB = 4
- * AF_RGBPOSITION_CUSTOM_RB_GG = 5
- */
- public int afBayeRGBPosition;
-
- /**
- * If enabled, peak for FV, FV^2 is computed for a paxel.
- * If disabled, average of FV, FV^2 is computed for a paxel.
- */
- public int afEnableAFPeakMode;
-
- /**
- * Whether vertical focus is enabled.
- */
- public int afEnableAFVertical;
-
- /**
- * AF paxel description
- */
- public H3AConfig afPaxelWindow;
-
- /**
- * Output AF buffer. Data is ordered in paxels:
- *
- * g_paxel - Paxel information for green color
- * rb_paxel - Paxel information for red/blue color
- * br_paxel - Paxel information for blue/red color
- *
- * Each paxel consists of :
- * int sum - Sum of the pixels used to arrive at
- * the statistics for a paxel
- * int focus_value_sum - Focus Value (sum/peak)
- * for a paxel
- * int focus_value_sqr_sum - Focus Value Squared
- * (sum/peak) for a paxel
- * int reserved - To be ignored
- * ------------------------------------
- * | G paxel |
- * | ------ ------ ------ ------ |
- * || | | | | | | | |
- * || sum | |f_sum | |f_sum | | rsv | |
- * || | | | |sqr | | | |
- * | ------ ------ ------ ------ |
- * ------------------------------------
- *
- * ------------------------------------
- * | RB paxel |
- * | ------ ------ ------ ------ |
- * || | | | | | | | |
- * || sum | |f_sum | |f_sum | | rsv | |
- * || | | | |sqr | | | |
- * | ------ ------ ------ ------ |
- * ------------------------------------
- *
- * ------------------------------------
- * | BR paxel |
- * | ------ ------ ------ ------ |
- * || | | | | | | | |
- * || sum | |f_sum | |f_sum | | rsv | |
- * || | | | |sqr | | | |
- * | ------ ------ ------ ------ |
- * ------------------------------------
- */
- public ByteBuffer afPaxelStatistics;
-
- /**
- * AEWB mode :
- * AEWB_MODE_SUM_OF_SQUARE = 0 - Sum of square calculated
- * across sub-samples in a paxel.
- * AEWB_MODE_MINMAX = 1 - Min-max calculted across sub-samples
- * in a paxel.
- * AEWB_MODE_SUM_ONLY = 2 - Only Sum calculated across sub-samples
- * in a paxel.
- */
- public int aewbMode;
-
- /**
- * Threshold against which pixel values are compared
- */
- public int aewbThresholdPixelValue;
-
- /**
- * Right shift value applied on result of pixel accumulation
- */
- public int aewbAccumulationShift;
-
- /**
- * AE/AWB paxel description
- */
- public H3AConfig aewbPaxelWindow;
-
- /**
- * Output AE/AWB buffer, containing:
- * subsampled_acc_values[4] - Sub sample accumulator(s), not-clipped.
- * Separate for each pixel in 2x2 sub-sample.
- * saturator_acc_values[4] - Saturator accumulator(s), clipped based upon threshold.
- * Separate for each pixel in 2x2 sub-sample.
- * nUnsaturatedCount[2] - Count of unsaturated 2x2 sub-samples in a paxel.
- * (LS 16-bits stored in [0], MS stored in [1])
- */
- public ByteBuffer aewbPaxelStatistics;
-
- private static native CPCamMetadata nativeRetrieveMetadata(CPCamBufferQueue st, int slot);
-
- /*
- * We use a class initializer to allow the native code to cache some
- * field offsets.
- */
- private static native void nativeClassInit();
- static { nativeClassInit(); }
-}
diff --git a/cpcam/jni/Android.mk b/cpcam/jni/Android.mk
deleted file mode 100644
index 54aab6c..0000000
--- a/cpcam/jni/Android.mk
+++ /dev/null
@@ -1,69 +0,0 @@
-# Copyright (c) 2010, Texas Instruments Incorporated
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# * Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# * Neither the name of Texas Instruments Incorporated nor the names of
-# its contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-# This makefile supplies the rules for building a library of JNI code for
-# use by our example platform shared library.
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := optional
-
-# This is the target being built.
-LOCAL_MODULE:= libcpcam_jni
-
-# All of the source files that we will compile.
-LOCAL_SRC_FILES:= \
- com_ti_omap_android_cpcam_CPCam.cpp \
- com_ti_omap_android_cpcam_CPCamMetadata.cpp \
- com_ti_omap_android_cpcam_CPCamBufferQueue.cpp
-
-# All of the shared libraries we link against.
-LOCAL_SHARED_LIBRARIES := \
- libcamera_client \
- libnativehelper \
- libcutils \
- libutils \
- libui \
- libbinder \
- libgui
-
-# No static libraries.
-LOCAL_STATIC_LIBRARIES :=
-
-# Also need the JNI headers.
-LOCAL_C_INCLUDES += \
- $(JNI_H_INCLUDE)
-
-# No specia compiler flags.
-LOCAL_CFLAGS += $(ANDROID_API_CFLAGS)
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/cpcam/jni/com_ti_omap_android_cpcam_CPCam.cpp b/cpcam/jni/com_ti_omap_android_cpcam_CPCam.cpp
deleted file mode 100644
index 1b09ac4..0000000
--- a/cpcam/jni/com_ti_omap_android_cpcam_CPCam.cpp
+++ /dev/null
@@ -1,1226 +0,0 @@
-/*
- * Copyright (c) 2010, Texas Instruments Incorporated
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "CPCam-JNI"
-#include <utils/Log.h>
-
-#include "jni.h"
-#include "JNIHelp.h"
-
-#include <utils/Vector.h>
-
-#include <gui/SurfaceTexture.h>
-
-#include <camera/Camera.h>
-#include <binder/IMemory.h>
-
-#ifdef ANDROID_API_JB_OR_LATER
-#include <gui/Surface.h>
-# define CAMHAL_LOGV ALOGV
-# define CAMHAL_LOGE ALOGE
-# define PREVIEW_TEXTURE_TYPE BufferQueue
-#else
-#include <surfaceflinger/Surface.h>
-# define CAMHAL_LOGV LOGV
-# define CAMHAL_LOGE LOGE
-# define PREVIEW_TEXTURE_TYPE SurfaceTexture
-#endif
-
-using namespace android;
-
-static JavaVM * sJvm = 0;
-
-extern JavaVM * getJavaVM() {
- return sJvm;
-}
-
-extern JNIEnv * getJniEnv() {
- assert(sJvm);
- JNIEnv * env;
- if (sJvm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) {
- return 0;
- }
- return env;
-}
-
-extern int register_com_ti_omap_android_cpcam_CPCamMetadata(JNIEnv* env);
-extern int register_android_graphics_CPCamBufferQueue(JNIEnv* env);
-
-struct fields_t {
- jfieldID context;
- jfieldID surface;
- jfieldID surfaceTexture;
- jfieldID facing;
- jfieldID orientation;
- jfieldID face_rect;
- jfieldID face_score;
- jfieldID rect_left;
- jfieldID rect_top;
- jfieldID rect_right;
- jfieldID rect_bottom;
- jmethodID post_event;
- jmethodID rect_constructor;
- jmethodID face_constructor;
- jfieldID exposure_time;
- jfieldID analog_gain;
- jfieldID faces;
- jmethodID metadata_constructor;
- jfieldID bufferQueue;
-};
-
-static fields_t fields;
-static Mutex sLock;
-
-// provides persistent context for calls from native code to Java
-class JNICPCamContext: public CameraListener
-{
-public:
- JNICPCamContext(JNIEnv* env, jobject weak_this, jclass clazz, const sp<Camera>& camera);
- ~JNICPCamContext() { release(); }
- virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2);
- virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
- camera_frame_metadata_t *metadata);
- virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
- void postMetadata(JNIEnv *env, int32_t msgType, camera_frame_metadata_t *metadata);
- void addCallbackBuffer(JNIEnv *env, jbyteArray cbb, int msgType);
- void setCallbackMode(JNIEnv *env, bool installed, bool manualMode);
- sp<Camera> getCamera() { Mutex::Autolock _l(mLock); return mCamera; }
- bool isRawImageCallbackBufferAvailable() const;
- void release();
-
-private:
- void copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType);
- void clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers);
- void clearCallbackBuffers_l(JNIEnv *env);
- jbyteArray getCallbackBuffer(JNIEnv *env, Vector<jbyteArray> *buffers, size_t bufferSize);
-
- jobject mCameraJObjectWeak; // weak reference to java object
- jclass mCameraJClass; // strong reference to java class
- sp<Camera> mCamera; // strong reference to native object
- jclass mFaceClass; // strong reference to Face class
- jclass mMetadataClass; // strong reference to Metadata class
- jclass mRectClass; // strong reference to Rect class
- Mutex mLock;
-
- /*
- * Global reference application-managed raw image buffer queue.
- *
- * Manual-only mode is supported for raw image callbacks, which is
- * set whenever method addCallbackBuffer() with msgType =
- * CAMERA_MSG_RAW_IMAGE is called; otherwise, null is returned
- * with raw image callbacks.
- */
- Vector<jbyteArray> mRawImageCallbackBuffers;
-
- /*
- * Application-managed preview buffer queue and the flags
- * associated with the usage of the preview buffer callback.
- */
- Vector<jbyteArray> mCallbackBuffers; // Global reference application managed byte[]
- bool mManualBufferMode; // Whether to use application managed buffers.
- bool mManualCameraCallbackSet; // Whether the callback has been set, used to
- // reduce unnecessary calls to set the callback.
-};
-
-bool JNICPCamContext::isRawImageCallbackBufferAvailable() const
-{
- return !mRawImageCallbackBuffers.isEmpty();
-}
-
-sp<Camera> get_native_camera(JNIEnv *env, jobject thiz, JNICPCamContext** pContext)
-{
- sp<Camera> camera;
- Mutex::Autolock _l(sLock);
- JNICPCamContext* context = reinterpret_cast<JNICPCamContext*>(env->GetIntField(thiz, fields.context));
- if (context != NULL) {
- camera = context->getCamera();
- }
- CAMHAL_LOGV("get_native_camera: context=%p, camera=%p", context, camera.get());
- if (camera == 0) {
- jniThrowRuntimeException(env, "Method called after release()");
- }
-
- if (pContext != NULL) *pContext = context;
- return camera;
-}
-
-JNICPCamContext::JNICPCamContext(JNIEnv* env, jobject weak_this, jclass clazz, const sp<Camera>& camera)
-{
- mCameraJObjectWeak = env->NewGlobalRef(weak_this);
- mCameraJClass = (jclass)env->NewGlobalRef(clazz);
- mCamera = camera;
-
- jclass faceClazz = env->FindClass("com/ti/omap/android/cpcam/CPCam$Face");
- mFaceClass = (jclass) env->NewGlobalRef(faceClazz);
-
- jclass metadataClazz = env->FindClass("com/ti/omap/android/cpcam/CPCam$Metadata");
- mMetadataClass = (jclass) env->NewGlobalRef(metadataClazz);
-
- jclass rectClazz = env->FindClass("android/graphics/Rect");
- mRectClass = (jclass) env->NewGlobalRef(rectClazz);
-
- mManualBufferMode = false;
- mManualCameraCallbackSet = false;
-}
-
-void JNICPCamContext::release()
-{
- CAMHAL_LOGV("release");
- Mutex::Autolock _l(mLock);
- JNIEnv *env = getJniEnv();
-
- if (mCameraJObjectWeak != NULL) {
- env->DeleteGlobalRef(mCameraJObjectWeak);
- mCameraJObjectWeak = NULL;
- }
- if (mCameraJClass != NULL) {
- env->DeleteGlobalRef(mCameraJClass);
- mCameraJClass = NULL;
- }
- if (mFaceClass != NULL) {
- env->DeleteGlobalRef(mFaceClass);
- mFaceClass = NULL;
- }
- if (mMetadataClass != NULL) {
- env->DeleteGlobalRef(mMetadataClass);
- mMetadataClass = NULL;
- }
- if (mRectClass != NULL) {
- env->DeleteGlobalRef(mRectClass);
- mRectClass = NULL;
- }
- clearCallbackBuffers_l(env);
- mCamera.clear();
-}
-
-void JNICPCamContext::notify(int32_t msgType, int32_t ext1, int32_t ext2)
-{
- CAMHAL_LOGV("notify");
-
- // VM pointer will be NULL if object is released
- Mutex::Autolock _l(mLock);
- if (mCameraJObjectWeak == NULL) {
- CAMHAL_LOGE("callback on dead camera object");
- return;
- }
- JNIEnv *env = getJniEnv();
-
- /*
- * If the notification or msgType is CAMERA_MSG_RAW_IMAGE_NOTIFY, change it
- * to CAMERA_MSG_RAW_IMAGE since CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed
- * to the Java app.
- */
- if (msgType == CAMERA_MSG_RAW_IMAGE_NOTIFY) {
- msgType = CAMERA_MSG_RAW_IMAGE;
- }
-
- env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
- mCameraJObjectWeak, msgType, ext1, ext2, NULL);
-}
-
-jbyteArray JNICPCamContext::getCallbackBuffer(
- JNIEnv* env, Vector<jbyteArray>* buffers, size_t bufferSize)
-{
- jbyteArray obj = NULL;
-
- // Vector access should be protected by lock in postData()
- if (!buffers->isEmpty()) {
- CAMHAL_LOGV("Using callback buffer from queue of length %d", buffers->size());
- jbyteArray globalBuffer = buffers->itemAt(0);
- buffers->removeAt(0);
-
- obj = (jbyteArray)env->NewLocalRef(globalBuffer);
- env->DeleteGlobalRef(globalBuffer);
-
- if (obj != NULL) {
- jsize bufferLength = env->GetArrayLength(obj);
- if ((int)bufferLength < (int)bufferSize) {
- CAMHAL_LOGE("Callback buffer was too small! Expected %d bytes, but got %d bytes!",
- bufferSize, bufferLength);
- env->DeleteLocalRef(obj);
- return NULL;
- }
- }
- }
-
- return obj;
-}
-
-void JNICPCamContext::copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType)
-{
- jbyteArray obj = NULL;
-
- // allocate Java byte array and copy data
- if (dataPtr != NULL) {
- ssize_t offset;
- size_t size;
- sp<IMemoryHeap> heap = dataPtr->getMemory(&offset, &size);
- CAMHAL_LOGV("copyAndPost: off=%ld, size=%d", offset, size);
- uint8_t *heapBase = (uint8_t*)heap->base();
-
- if (heapBase != NULL) {
- const jbyte* data = reinterpret_cast<const jbyte*>(heapBase + offset);
-
- if (msgType == CAMERA_MSG_RAW_IMAGE) {
- obj = getCallbackBuffer(env, &mRawImageCallbackBuffers, size);
- } else if (msgType == CAMERA_MSG_PREVIEW_FRAME && mManualBufferMode) {
- obj = getCallbackBuffer(env, &mCallbackBuffers, size);
-
- if (mCallbackBuffers.isEmpty()) {
- CAMHAL_LOGV("Out of buffers, clearing callback!");
- mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
- mManualCameraCallbackSet = false;
-
- if (obj == NULL) {
- return;
- }
- }
- } else {
- CAMHAL_LOGV("Allocating callback buffer");
- obj = env->NewByteArray(size);
- }
-
- if (obj == NULL) {
- CAMHAL_LOGE("Couldn't allocate byte array for JPEG data");
- env->ExceptionClear();
- } else {
- env->SetByteArrayRegion(obj, 0, size, data);
- }
- } else {
- CAMHAL_LOGE("image heap is NULL");
- }
- }
-
- // post image data to Java
- env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
- mCameraJObjectWeak, msgType, 0, 0, obj);
- if (obj) {
- env->DeleteLocalRef(obj);
- }
-}
-
-void JNICPCamContext::postData(int32_t msgType, const sp<IMemory>& dataPtr,
- camera_frame_metadata_t *metadata)
-{
- // VM pointer will be NULL if object is released
- Mutex::Autolock _l(mLock);
- JNIEnv *env = getJniEnv();
- if (mCameraJObjectWeak == NULL) {
- CAMHAL_LOGE("callback on dead camera object");
- return;
- }
-
- int32_t dataMsgType = msgType & ~CAMERA_MSG_PREVIEW_METADATA;
-
- // return data based on callback type
- switch (dataMsgType) {
- case CAMERA_MSG_VIDEO_FRAME:
- // should never happen
- break;
-
- // For backward-compatibility purpose, if there is no callback
- // buffer for raw image, the callback returns null.
- case CAMERA_MSG_RAW_IMAGE:
- CAMHAL_LOGV("rawCallback");
- if (mRawImageCallbackBuffers.isEmpty()) {
- env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
- mCameraJObjectWeak, dataMsgType, 0, 0, NULL);
- } else {
- copyAndPost(env, dataPtr, dataMsgType);
- }
- break;
-
- // There is no data.
- case 0:
- break;
-
- default:
- CAMHAL_LOGV("dataCallback(%d, %p)", dataMsgType, dataPtr.get());
- copyAndPost(env, dataPtr, dataMsgType);
- break;
- }
-
- // post frame metadata to Java
- if (metadata && (msgType & CAMERA_MSG_PREVIEW_METADATA)) {
- postMetadata(env, CAMERA_MSG_PREVIEW_METADATA, metadata);
- }
-}
-
-void JNICPCamContext::postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr)
-{
- // TODO: plumb up to Java. For now, just drop the timestamp
- postData(msgType, dataPtr, NULL);
-}
-
-void JNICPCamContext::postMetadata(JNIEnv *env, int32_t msgType, camera_frame_metadata_t *metadata)
-{
- jobject meta_obj = NULL;
- meta_obj = (jobject) env->NewObject(mMetadataClass, fields.metadata_constructor);
- if (meta_obj == NULL) {
- CAMHAL_LOGE("Couldn't allocate metadata class");
- return;
- }
-
- env->SetIntField(meta_obj, fields.exposure_time, metadata->exposure_time);
- env->SetIntField(meta_obj, fields.analog_gain, metadata->analog_gain);
-
- jobjectArray faces_obj = NULL;
- faces_obj = (jobjectArray) env->NewObjectArray(metadata->number_of_faces,
- mFaceClass, NULL);
- if (faces_obj == NULL) {
- CAMHAL_LOGE("Couldn't allocate face metadata array");
- goto err_alloc_faces;
- }
-
- for (int i = 0; i < metadata->number_of_faces; i++) {
- jobject face = env->NewObject(mFaceClass, fields.face_constructor);
- env->SetObjectArrayElement(faces_obj, i, face);
-
- jobject rect = env->NewObject(mRectClass, fields.rect_constructor);
- env->SetIntField(rect, fields.rect_left, metadata->faces[i].rect[0]);
- env->SetIntField(rect, fields.rect_top, metadata->faces[i].rect[1]);
- env->SetIntField(rect, fields.rect_right, metadata->faces[i].rect[2]);
- env->SetIntField(rect, fields.rect_bottom, metadata->faces[i].rect[3]);
-
- env->SetObjectField(face, fields.face_rect, rect);
- env->SetIntField(face, fields.face_score, metadata->faces[i].score);
-
- env->DeleteLocalRef(face);
- env->DeleteLocalRef(rect);
- }
-
- env->SetObjectField(meta_obj, fields.faces, faces_obj);
-
- env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
- mCameraJObjectWeak, msgType, CAMERA_MSG_PREVIEW_METADATA, 0, meta_obj);
-
- env->DeleteLocalRef(faces_obj);
-err_alloc_faces:
- env->DeleteLocalRef(meta_obj);
- return;
-}
-
-void JNICPCamContext::setCallbackMode(JNIEnv *env, bool installed, bool manualMode)
-{
- Mutex::Autolock _l(mLock);
- mManualBufferMode = manualMode;
- mManualCameraCallbackSet = false;
-
- // In order to limit the over usage of binder threads, all non-manual buffer
- // callbacks use CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER mode now.
- //
- // Continuous callbacks will have the callback re-registered from handleMessage.
- // Manual buffer mode will operate as fast as possible, relying on the finite supply
- // of buffers for throttling.
-
- if (!installed) {
- mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
- clearCallbackBuffers_l(env, &mCallbackBuffers);
- } else if (mManualBufferMode) {
- if (!mCallbackBuffers.isEmpty()) {
- mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
- mManualCameraCallbackSet = true;
- }
- } else {
- mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER);
- clearCallbackBuffers_l(env, &mCallbackBuffers);
- }
-}
-
-void JNICPCamContext::addCallbackBuffer(
- JNIEnv *env, jbyteArray cbb, int msgType)
-{
- CAMHAL_LOGV("addCallbackBuffer: 0x%x", msgType);
- if (cbb != NULL) {
- Mutex::Autolock _l(mLock);
- switch (msgType) {
- case CAMERA_MSG_PREVIEW_FRAME: {
- jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb);
- mCallbackBuffers.push(callbackBuffer);
-
- CAMHAL_LOGV("Adding callback buffer to queue, %d total",
- mCallbackBuffers.size());
-
- // We want to make sure the camera knows we're ready for the
- // next frame. This may have come unset had we not had a
- // callbackbuffer ready for it last time.
- if (mManualBufferMode && !mManualCameraCallbackSet) {
- mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
- mManualCameraCallbackSet = true;
- }
- break;
- }
- case CAMERA_MSG_RAW_IMAGE: {
- jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb);
- mRawImageCallbackBuffers.push(callbackBuffer);
- break;
- }
- default: {
- jniThrowException(env,
- "java/lang/IllegalArgumentException",
- "Unsupported message type");
- return;
- }
- }
- } else {
- CAMHAL_LOGE("Null byte array!");
- }
-}
-
-void JNICPCamContext::clearCallbackBuffers_l(JNIEnv *env)
-{
- clearCallbackBuffers_l(env, &mCallbackBuffers);
- clearCallbackBuffers_l(env, &mRawImageCallbackBuffers);
-}
-
-void JNICPCamContext::clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers) {
- CAMHAL_LOGV("Clearing callback buffers, %d remained", buffers->size());
- while (!buffers->isEmpty()) {
- env->DeleteGlobalRef(buffers->top());
- buffers->pop();
- }
-}
-
-static jint com_ti_omap_android_cpcam_CPCam_getNumberOfCameras(JNIEnv *env, jobject thiz)
-{
- return Camera::getNumberOfCameras();
-}
-
-static void com_ti_omap_android_cpcam_CPCam_getCameraInfo(JNIEnv *env, jobject thiz,
- jint cameraId, jobject info_obj)
-{
- CameraInfo cameraInfo;
- status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
- if (rc != NO_ERROR) {
- jniThrowRuntimeException(env, "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 com_ti_omap_android_cpcam_CPCam_native_setup(JNIEnv *env, jobject thiz,
- jobject weak_this, jint cameraId)
-{
- sp<Camera> camera = Camera::connect(cameraId);
-
- if (camera == NULL) {
- jniThrowRuntimeException(env, "Fail to connect to camera service");
- return;
- }
-
- // make sure camera hardware is alive
- if (camera->getStatus() != NO_ERROR) {
- jniThrowRuntimeException(env, "Camera initialization failed");
- return;
- }
-
- jclass clazz = env->GetObjectClass(thiz);
- if (clazz == NULL) {
- jniThrowRuntimeException(env, "Can't find com/ti/omap/android/cpcam/CPCam");
- return;
- }
-
- // We use a weak reference so the Camera object can be garbage collected.
- // The reference is only used as a proxy for callbacks.
- sp<JNICPCamContext> context = new JNICPCamContext(env, weak_this, clazz, camera);
- context->incStrong(thiz);
- camera->setListener(context);
-
- // save context in opaque field
- env->SetIntField(thiz, fields.context, (int)context.get());
-
- // Fill bufferQueue field since CPCamBufferQueue should be loaded by now
- clazz = env->FindClass("com/ti/omap/android/cpcam/CPCamBufferQueue");
- fields.bufferQueue = env->GetFieldID(clazz, "mBufferQueue", "I");
- if (fields.bufferQueue == NULL) {
- CAMHAL_LOGE("Can't find com/ti/omap/android/cpcam/CPCamBufferQueue.mBufferQueue");
- jniThrowRuntimeException(env, "Can't find com/ti/omap/android/cpcam/CPCamBufferQueue.mBufferQueue");
- }
-
-}
-
-// disconnect from camera service
-// It's okay to call this when the native camera context is already null.
-// This handles the case where the user has called release() and the
-// finalizer is invoked later.
-static void com_ti_omap_android_cpcam_CPCam_release(JNIEnv *env, jobject thiz)
-{
- // TODO: Change to CAMHAL_LOGV
- CAMHAL_LOGV("release camera");
- JNICPCamContext* context = NULL;
- sp<Camera> camera;
- {
- Mutex::Autolock _l(sLock);
- context = reinterpret_cast<JNICPCamContext*>(env->GetIntField(thiz, fields.context));
-
- // Make sure we do not attempt to callback on a deleted Java object.
- env->SetIntField(thiz, fields.context, 0);
- }
-
- // clean up if release has not been called before
- if (context != NULL) {
- camera = context->getCamera();
- context->release();
- CAMHAL_LOGV("native_release: context=%p camera=%p", context, camera.get());
-
- // clear callbacks
- if (camera != NULL) {
- camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
- camera->disconnect();
- }
-
- // remove context to prevent further Java access
- context->decStrong(thiz);
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_setPreviewDisplay(JNIEnv *env, jobject thiz, jobject jSurface)
-{
- CAMHAL_LOGV("setPreviewDisplay");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- sp<Surface> surface = NULL;
- if (jSurface != NULL) {
- surface = reinterpret_cast<Surface*>(env->GetIntField(jSurface, fields.surface));
- }
- if (camera->setPreviewDisplay(surface) != NO_ERROR) {
- jniThrowException(env, "java/io/IOException", "setPreviewDisplay failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_setPreviewTexture(JNIEnv *env,
- jobject thiz, jobject jSurfaceTexture)
-{
- CAMHAL_LOGV("setPreviewTexture");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- sp<PREVIEW_TEXTURE_TYPE> previewTexture = NULL;
-
- if (jSurfaceTexture != NULL) {
- sp<SurfaceTexture> surfaceTexture = reinterpret_cast<SurfaceTexture*>(env->GetIntField(
- jSurfaceTexture, fields.surfaceTexture));
- if (surfaceTexture == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException",
- "SurfaceTexture already released in setPreviewTexture");
- return;
- }
-#ifdef ANDROID_API_JB_OR_LATER
- previewTexture = surfaceTexture->getBufferQueue();
-#else
- previewTexture = surfaceTexture;
-#endif
- }
-
- if (camera->setPreviewTexture(previewTexture) != NO_ERROR) {
- jniThrowException(env, "java/io/IOException",
- "setPreviewTexture failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_setBufferSource(JNIEnv *env,
- jobject thiz, jobject jTapIn, jobject jTapOut)
-{
- CAMHAL_LOGV("setBufferSource");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- sp<PREVIEW_TEXTURE_TYPE> tapOut = NULL;
- if (jTapOut!= NULL) {
- tapOut = reinterpret_cast<PREVIEW_TEXTURE_TYPE *>(env->GetIntField(
- jTapOut, fields.bufferQueue));
- if (tapOut == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException",
- "SurfaceTexture already released in setPreviewTexture");
- return;
- }
- }
-
- sp<PREVIEW_TEXTURE_TYPE> tapIn = NULL;
- if (jTapIn != NULL) {
- tapIn = reinterpret_cast<PREVIEW_TEXTURE_TYPE *>(env->GetIntField(
- jTapIn, fields.bufferQueue));
- if (tapIn == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException",
- "SurfaceTexture already released in setPreviewTexture");
- return;
- }
- }
-
- if (camera->setBufferSource(tapIn, tapOut) != NO_ERROR) { // tapin not enabled yet
- jniThrowException(env, "java/io/IOException",
- "setBufferSource failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_releaseBufferSource(JNIEnv *env,
- jobject thiz, jobject jTapIn, jobject jTapOut)
-{
- CAMHAL_LOGV("releaseBufferSource");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- sp<PREVIEW_TEXTURE_TYPE> tapOut = NULL;
- if (jTapOut!= NULL) {
- tapOut = reinterpret_cast<PREVIEW_TEXTURE_TYPE *>(env->GetIntField(
- jTapOut, fields.bufferQueue));
- if (tapOut == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException",
- "Tap out already released in releaseBufferSource");
- return;
- }
- }
-
- sp<PREVIEW_TEXTURE_TYPE> tapIn = NULL;
- if (jTapIn != NULL) {
- tapIn = reinterpret_cast<PREVIEW_TEXTURE_TYPE *>(env->GetIntField(
- jTapIn, fields.bufferQueue));
- if (tapIn == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException",
- "Tap in already released in releaseBufferSource");
- return;
- }
- }
-
- if (camera->releaseBufferSource(tapIn, tapOut) != NO_ERROR) {
- jniThrowException(env, "java/io/IOException",
- "releaseBufferSource failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_reprocess(JNIEnv *env,
- jobject thiz, jint msgType, jstring jShotParams)
-{
- const char *shotParams = (jShotParams) ? env->GetStringUTFChars(jShotParams, NULL) : NULL;
- String8 params(shotParams ? shotParams: "");
-
- CAMHAL_LOGV("reprocess");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- if (camera->reprocess(msgType, params) != NO_ERROR) {
- jniThrowException(env, "java/io/IOException",
- "reprocess failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_startPreview(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("startPreview");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- if (camera->startPreview() != NO_ERROR) {
- jniThrowRuntimeException(env, "startPreview failed");
- return;
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_stopPreview(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("stopPreview");
- sp<Camera> c = get_native_camera(env, thiz, NULL);
- if (c == 0) return;
-
- c->stopPreview();
-}
-
-static bool com_ti_omap_android_cpcam_CPCam_previewEnabled(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("previewEnabled");
- sp<Camera> c = get_native_camera(env, thiz, NULL);
- if (c == 0) return false;
-
- return c->previewEnabled();
-}
-
-static void com_ti_omap_android_cpcam_CPCam_setHasPreviewCallback(JNIEnv *env, jobject thiz, jboolean installed, jboolean manualBuffer)
-{
- CAMHAL_LOGV("setHasPreviewCallback: installed:%d, manualBuffer:%d", (int)installed, (int)manualBuffer);
- // Important: Only install preview_callback if the Java code has called
- // setPreviewCallback() with a non-null value, otherwise we'd pay to memcpy
- // each preview frame for nothing.
- JNICPCamContext* context;
- sp<Camera> camera = get_native_camera(env, thiz, &context);
- if (camera == 0) return;
-
- // setCallbackMode will take care of setting the context flags and calling
- // camera->setPreviewCallbackFlags within a mutex for us.
- context->setCallbackMode(env, installed, manualBuffer);
-}
-
-static void com_ti_omap_android_cpcam_CPCam_addCallbackBuffer(JNIEnv *env, jobject thiz, jbyteArray bytes, int msgType) {
- CAMHAL_LOGV("addCallbackBuffer: 0x%x", msgType);
-
- JNICPCamContext* context = reinterpret_cast<JNICPCamContext*>(env->GetIntField(thiz, fields.context));
-
- if (context != NULL) {
- context->addCallbackBuffer(env, bytes, msgType);
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_autoFocus(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("autoFocus");
- JNICPCamContext* context;
- sp<Camera> c = get_native_camera(env, thiz, &context);
- if (c == 0) return;
-
- if (c->autoFocus() != NO_ERROR) {
- jniThrowRuntimeException(env, "autoFocus failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_cancelAutoFocus(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("cancelAutoFocus");
- JNICPCamContext* context;
- sp<Camera> c = get_native_camera(env, thiz, &context);
- if (c == 0) return;
-
- if (c->cancelAutoFocus() != NO_ERROR) {
- jniThrowRuntimeException(env, "cancelAutoFocus failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_takePicture(JNIEnv *env, jobject thiz, int msgType, jstring params)
-{
- CAMHAL_LOGV("takePicture");
- JNICPCamContext* context;
- sp<Camera> camera = get_native_camera(env, thiz, &context);
- if (camera == 0) return;
-
- String8 params8;
- if (params) {
- const jchar* str = env->GetStringCritical(params, 0);
- params8 = String8(str, env->GetStringLength(params));
- env->ReleaseStringCritical(params, str);
- }
-
- /*
- * When CAMERA_MSG_RAW_IMAGE is requested, if the raw image callback
- * buffer is available, CAMERA_MSG_RAW_IMAGE is enabled to get the
- * notification _and_ the data; otherwise, CAMERA_MSG_RAW_IMAGE_NOTIFY
- * is enabled to receive the callback notification but no data.
- *
- * Note that CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed to the
- * Java application.
- */
- if (msgType & CAMERA_MSG_RAW_IMAGE) {
- CAMHAL_LOGV("Enable raw image callback buffer");
- if (!context->isRawImageCallbackBufferAvailable()) {
- CAMHAL_LOGV("Enable raw image notification, since no callback buffer exists");
- msgType &= ~CAMERA_MSG_RAW_IMAGE;
- msgType |= CAMERA_MSG_RAW_IMAGE_NOTIFY;
- }
- }
-
- if (camera->takePictureWithParameters(msgType, params8) != NO_ERROR) {
- jniThrowRuntimeException(env, "takePicture failed");
- return;
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_setParameters(JNIEnv *env, jobject thiz, jstring params)
-{
- CAMHAL_LOGV("setParameters");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- const jchar* str = env->GetStringCritical(params, 0);
- String8 params8;
- if (params) {
- params8 = String8(str, env->GetStringLength(params));
- env->ReleaseStringCritical(params, str);
- }
- if (camera->setParameters(params8) != NO_ERROR) {
- jniThrowRuntimeException(env, "setParameters failed");
- return;
- }
-}
-
-static jstring com_ti_omap_android_cpcam_CPCam_getParameters(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("getParameters");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return 0;
-
- String8 params8 = camera->getParameters();
- if (params8.isEmpty()) {
- jniThrowRuntimeException(env, "getParameters failed (empty parameters)");
- return 0;
- }
- return env->NewStringUTF(params8.string());
-}
-
-static void com_ti_omap_android_cpcam_CPCam_reconnect(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("reconnect");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- if (camera->reconnect() != NO_ERROR) {
- jniThrowException(env, "java/io/IOException", "reconnect failed");
- return;
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_lock(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("lock");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- if (camera->lock() != NO_ERROR) {
- jniThrowRuntimeException(env, "lock failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_unlock(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("unlock");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- if (camera->unlock() != NO_ERROR) {
- jniThrowRuntimeException(env, "unlock failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_startSmoothZoom(JNIEnv *env, jobject thiz, jint value)
-{
- CAMHAL_LOGV("startSmoothZoom");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- status_t rc = camera->sendCommand(CAMERA_CMD_START_SMOOTH_ZOOM, value, 0);
- if (rc == BAD_VALUE) {
- char msg[64];
- sprintf(msg, "invalid zoom value=%d", value);
- jniThrowException(env, "java/lang/IllegalArgumentException", msg);
- } else if (rc != NO_ERROR) {
- jniThrowRuntimeException(env, "start smooth zoom failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_stopSmoothZoom(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("stopSmoothZoom");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- if (camera->sendCommand(CAMERA_CMD_STOP_SMOOTH_ZOOM, 0, 0) != NO_ERROR) {
- jniThrowRuntimeException(env, "stop smooth zoom failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_setDisplayOrientation(JNIEnv *env, jobject thiz,
- jint value)
-{
- CAMHAL_LOGV("setDisplayOrientation");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- if (camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION, value, 0) != NO_ERROR) {
- jniThrowRuntimeException(env, "set display orientation failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_startFaceDetection(JNIEnv *env, jobject thiz,
- jint type)
-{
- CAMHAL_LOGV("startFaceDetection");
- JNICPCamContext* context;
- sp<Camera> camera = get_native_camera(env, thiz, &context);
- if (camera == 0) return;
-
- status_t rc = camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, type, 0);
- if (rc == BAD_VALUE) {
- char msg[64];
- snprintf(msg, sizeof(msg), "invalid face detection type=%d", type);
- jniThrowException(env, "java/lang/IllegalArgumentException", msg);
- } else if (rc != NO_ERROR) {
- jniThrowRuntimeException(env, "start face detection failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_stopFaceDetection(JNIEnv *env, jobject thiz)
-{
- CAMHAL_LOGV("stopFaceDetection");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- if (camera->sendCommand(CAMERA_CMD_STOP_FACE_DETECTION, 0, 0) != NO_ERROR) {
- jniThrowRuntimeException(env, "stop face detection failed");
- }
-}
-
-static void com_ti_omap_android_cpcam_CPCam_enableFocusMoveCallback(JNIEnv *env, jobject thiz, jint enable)
-{
- ALOGV("enableFocusMoveCallback");
- sp<Camera> camera = get_native_camera(env, thiz, NULL);
- if (camera == 0) return;
-
- if (camera->sendCommand(CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG, enable, 0) != NO_ERROR) {
- jniThrowRuntimeException(env, "enable focus move callback failed");
- }
-}
-
-//-------------------------------------------------
-
-static JNINativeMethod cpcamMethods[] = {
- { "getNumberOfCameras",
- "()I",
- (void *)com_ti_omap_android_cpcam_CPCam_getNumberOfCameras },
- { "getCameraInfo",
- "(ILcom/ti/omap/android/cpcam/CPCam$CameraInfo;)V",
- (void*)com_ti_omap_android_cpcam_CPCam_getCameraInfo },
- { "native_setup",
- "(Ljava/lang/Object;I)V",
- (void*)com_ti_omap_android_cpcam_CPCam_native_setup },
- { "native_release",
- "()V",
- (void*)com_ti_omap_android_cpcam_CPCam_release },
- { "setPreviewDisplay",
- "(Landroid/view/Surface;)V",
- (void *)com_ti_omap_android_cpcam_CPCam_setPreviewDisplay },
- { "setPreviewTexture",
- "(Landroid/graphics/SurfaceTexture;)V",
- (void *)com_ti_omap_android_cpcam_CPCam_setPreviewTexture },
- { "setBufferSource",
- "(Lcom/ti/omap/android/cpcam/CPCamBufferQueue;Lcom/ti/omap/android/cpcam/CPCamBufferQueue;)V",
- (void *)com_ti_omap_android_cpcam_CPCam_setBufferSource },
- { "releaseBufferSource",
- "(Lcom/ti/omap/android/cpcam/CPCamBufferQueue;Lcom/ti/omap/android/cpcam/CPCamBufferQueue;)V",
- (void *)com_ti_omap_android_cpcam_CPCam_releaseBufferSource },
- { "native_reprocess",
- "(ILjava/lang/String;)V",
- (void *)com_ti_omap_android_cpcam_CPCam_reprocess },
- { "startPreview",
- "()V",
- (void *)com_ti_omap_android_cpcam_CPCam_startPreview },
- { "_stopPreview",
- "()V",
- (void *)com_ti_omap_android_cpcam_CPCam_stopPreview },
- { "previewEnabled",
- "()Z",
- (void *)com_ti_omap_android_cpcam_CPCam_previewEnabled },
- { "setHasPreviewCallback",
- "(ZZ)V",
- (void *)com_ti_omap_android_cpcam_CPCam_setHasPreviewCallback },
- { "_addCallbackBuffer",
- "([BI)V",
- (void *)com_ti_omap_android_cpcam_CPCam_addCallbackBuffer },
- { "native_autoFocus",
- "()V",
- (void *)com_ti_omap_android_cpcam_CPCam_autoFocus },
- { "native_cancelAutoFocus",
- "()V",
- (void *)com_ti_omap_android_cpcam_CPCam_cancelAutoFocus },
- { "native_takePicture",
- "(ILjava/lang/String;)V",
- (void *)com_ti_omap_android_cpcam_CPCam_takePicture },
- { "native_setParameters",
- "(Ljava/lang/String;)V",
- (void *)com_ti_omap_android_cpcam_CPCam_setParameters },
- { "native_getParameters",
- "()Ljava/lang/String;",
- (void *)com_ti_omap_android_cpcam_CPCam_getParameters },
- { "reconnect",
- "()V",
- (void*)com_ti_omap_android_cpcam_CPCam_reconnect },
- { "lock",
- "()V",
- (void*)com_ti_omap_android_cpcam_CPCam_lock },
- { "unlock",
- "()V",
- (void*)com_ti_omap_android_cpcam_CPCam_unlock },
- { "startSmoothZoom",
- "(I)V",
- (void *)com_ti_omap_android_cpcam_CPCam_startSmoothZoom },
- { "stopSmoothZoom",
- "()V",
- (void *)com_ti_omap_android_cpcam_CPCam_stopSmoothZoom },
- { "setDisplayOrientation",
- "(I)V",
- (void *)com_ti_omap_android_cpcam_CPCam_setDisplayOrientation },
- { "_startFaceDetection",
- "(I)V",
- (void *)com_ti_omap_android_cpcam_CPCam_startFaceDetection },
- { "_stopFaceDetection",
- "()V",
- (void *)com_ti_omap_android_cpcam_CPCam_stopFaceDetection},
- { "enableFocusMoveCallback",
- "(I)V",
- (void *)com_ti_omap_android_cpcam_CPCam_enableFocusMoveCallback},
-};
-
-struct field {
- const char *class_name;
- const char *field_name;
- const char *field_type;
- jfieldID *jfield;
-};
-
-static int find_fields(JNIEnv *env, field *fields, int count)
-{
- for (int i = 0; i < count; i++) {
- field *f = &fields[i];
- jclass clazz = env->FindClass(f->class_name);
- if (clazz == NULL) {
- CAMHAL_LOGE("Can't find %s", f->class_name);
- return -1;
- }
-
- jfieldID field = env->GetFieldID(clazz, f->field_name, f->field_type);
- if (field == NULL) {
- CAMHAL_LOGE("Can't find %s.%s", f->class_name, f->field_name);
- return -1;
- }
-
- *(f->jfield) = field;
- }
-
- return 0;
-}
-
-// Get all the required offsets in java class and register native functions
-int registerCPCamMethods(JNIEnv *env)
-{
- field fields_to_find[] = {
- { "com/ti/omap/android/cpcam/CPCam", "mNativeContext", "I", &fields.context },
- { "android/view/Surface", ANDROID_VIEW_SURFACE_JNI_ID, "I", &fields.surface },
- { "android/graphics/SurfaceTexture",
- ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I", &fields.surfaceTexture },
- { "com/ti/omap/android/cpcam/CPCam$CameraInfo", "facing", "I", &fields.facing },
- { "com/ti/omap/android/cpcam/CPCam$CameraInfo", "orientation", "I", &fields.orientation },
- { "com/ti/omap/android/cpcam/CPCam$Face", "rect", "Landroid/graphics/Rect;", &fields.face_rect },
- { "com/ti/omap/android/cpcam/CPCam$Face", "score", "I", &fields.face_score },
- { "android/graphics/Rect", "left", "I", &fields.rect_left },
- { "android/graphics/Rect", "top", "I", &fields.rect_top },
- { "android/graphics/Rect", "right", "I", &fields.rect_right },
- { "android/graphics/Rect", "bottom", "I", &fields.rect_bottom },
- { "com/ti/omap/android/cpcam/CPCam$Metadata", "exposureTime", "I", &fields.exposure_time },
- { "com/ti/omap/android/cpcam/CPCam$Metadata", "analogGain", "I", &fields.analog_gain },
- { "com/ti/omap/android/cpcam/CPCam$Metadata", "faces", "[Lcom/ti/omap/android/cpcam/CPCam$Face;", &fields.faces },
- };
-
- if (find_fields(env, fields_to_find, NELEM(fields_to_find)) < 0)
- return -1;
-
- jclass clazz = env->FindClass("com/ti/omap/android/cpcam/CPCam");
- fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
- "(Ljava/lang/Object;IIILjava/lang/Object;)V");
- if (fields.post_event == NULL) {
- CAMHAL_LOGE("Can't find com/ti/omap/android/cpcam/CPCam.postEventFromNative");
- return -1;
- }
-
- clazz = env->FindClass("android/graphics/Rect");
- fields.rect_constructor = env->GetMethodID(clazz, "<init>", "()V");
- if (fields.rect_constructor == NULL) {
- CAMHAL_LOGE("Can't find android/graphics/Rect.Rect()");
- return -1;
- }
-
- clazz = env->FindClass("com/ti/omap/android/cpcam/CPCam$Face");
- fields.face_constructor = env->GetMethodID(clazz, "<init>", "()V");
- if (fields.face_constructor == NULL) {
- CAMHAL_LOGE("Can't find com/ti/omap/android/cpcam/CPCam$Face.Face()");
- return -1;
- }
-
- clazz = env->FindClass("com/ti/omap/android/cpcam/CPCam$Metadata");
- fields.metadata_constructor = env->GetMethodID(clazz, "<init>", "()V");
- if (fields.metadata_constructor == NULL) {
- CAMHAL_LOGE("Can't find com/ti/omap/android/cpcam/CPCam$Metadata.Metadata()");
- return -1;
- }
-
-/*
- // Register native functions
- return AndroidRuntime::registerNativeMethods(env, "com/ti/omap/android/cpcam/CPCam",
- camMethods, NELEM(camMethods));
-*/
- /* register all the methods */
- clazz = env->FindClass("com/ti/omap/android/cpcam/CPCam");
- if (env->RegisterNatives(clazz, cpcamMethods,
- sizeof(cpcamMethods) / sizeof(cpcamMethods[0])) != JNI_OK)
- {
- CAMHAL_LOGE("Failed registering methods for %s\n", "com/ti/omap/android/cpcam/CPCam");
- return -1;
- }
-
- return 0;
-}
-
-// ----------------------------------------------------------------------------
-
-/*
- * This is called by the VM when the shared library is first loaded.
- */
-jint JNI_OnLoad(JavaVM* vm, void* reserved) {
- JNIEnv* env = NULL;
- jint result = -1;
-
- if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
- CAMHAL_LOGE("ERROR: GetEnv failed\n");
- goto bail;
- }
- assert(env != NULL);
-
- if (registerCPCamMethods(env) != 0) {
- CAMHAL_LOGE("ERROR: PlatformLibrary native registration failed\n");
- goto bail;
- }
-
- if ( register_com_ti_omap_android_cpcam_CPCamMetadata(env) != 0 ) {
- CAMHAL_LOGE("ERROR: PlatformLibrary native Metadata registration failed\n");
- goto bail;
- }
-
- if (register_android_graphics_CPCamBufferQueue(env) != 0) {
- CAMHAL_LOGE("ERROR: PlatformLibrary native BufferQueue registration failed\n");
- goto bail;
- }
-
- /* success -- return valid version number */
- sJvm = vm;
- result = JNI_VERSION_1_4;
-
-bail:
- return result;
-}
diff --git a/cpcam/jni/com_ti_omap_android_cpcam_CPCamBufferQueue.cpp b/cpcam/jni/com_ti_omap_android_cpcam_CPCamBufferQueue.cpp
deleted file mode 100644
index 0c3a8bd..0000000
--- a/cpcam/jni/com_ti_omap_android_cpcam_CPCamBufferQueue.cpp
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "BufferQueue"
-
-#include <stdio.h>
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-
-#include <gui/BufferQueue.h>
-#include <gui/SurfaceTextureClient.h>
-
-#include <utils/Log.h>
-#include <utils/misc.h>
-
-#include "jni.h"
-#include "JNIHelp.h"
-
-#define CAMHAL_LOGV ALOGV
-#define CAMHAL_LOGE ALOGE
-
-// ----------------------------------------------------------------------------
-using namespace android;
-
-extern JavaVM * getJavaVM();
-extern JNIEnv * getJniEnv();
-
-static const char* const OutOfResourcesException =
- "com/ti/omap/android/cpcam/CPCamBufferQueue$OutOfResourcesException";
-static const char* const IllegalStateException = "java/lang/IllegalStateException";
-const char* const kCPCamBufferQueueClassPathName = "com/ti/omap/android/cpcam/CPCamBufferQueue";
-
-struct fields_t {
- jfieldID surfaceTexture;
- jmethodID postEvent;
- jfieldID rect_left;
- jfieldID rect_top;
- jfieldID rect_right;
- jfieldID rect_bottom;
- jfieldID bufferQueue;
- jfieldID context;
-};
-static fields_t fields;
-
-// ----------------------------------------------------------------------------
-
-static void CPCamBufferQueue_setCPCamBufferQueue(JNIEnv* env, jobject thiz,
- const sp<BufferQueue>& bufferQueue)
-{
- BufferQueue* const p =
- (BufferQueue*)env->GetIntField(thiz, fields.bufferQueue);
- if (bufferQueue.get()) {
- bufferQueue->incStrong(thiz);
- }
- if (p) {
- p->decStrong(thiz);
- }
- env->SetIntField(thiz, fields.bufferQueue, (int)bufferQueue.get());
-}
-
-sp<BufferQueue> CPCamBufferQueue_getCPCamBufferQueue(JNIEnv* env, jobject thiz)
-{
- sp<BufferQueue> bufferQueue(
- (BufferQueue*)env->GetIntField(thiz, fields.bufferQueue));
- return bufferQueue;
-}
-
-sp<ANativeWindow> android_CPCamBufferQueue_getNativeWindow(
- JNIEnv* env, jobject thiz)
-{
- sp<ISurfaceTexture> bufferQueue(CPCamBufferQueue_getCPCamBufferQueue(env, thiz));
- sp<SurfaceTextureClient> surfaceTextureClient(bufferQueue != NULL ?
- new SurfaceTextureClient(bufferQueue) : NULL);
- return surfaceTextureClient;
-}
-
-bool android_CPCamBufferQueue_isInstanceOf(JNIEnv* env, jobject thiz)
-{
- jclass bufferQueueClass = env->FindClass(kCPCamBufferQueueClassPathName);
- return env->IsInstanceOf(thiz, bufferQueueClass);
-}
-
-// ----------------------------------------------------------------------------
-
-class JNICPCamBufferQueueContext : public BufferQueue::ProxyConsumerListener
-{
-public:
- JNICPCamBufferQueueContext(JNIEnv* env, jobject weakThiz, jclass clazz);
- virtual ~JNICPCamBufferQueueContext();
- virtual void onFrameAvailable();
- virtual void onBuffersReleased();
- void saveBuffer(unsigned int slot, sp<GraphicBuffer> gbuf);
- sp<GraphicBuffer> retrieveBuffer(unsigned int slot);
-
-private:
- static JNIEnv* getJNIEnv(bool* needsDetach);
- static void detachJNI();
-
- jobject mWeakThiz;
- jclass mClazz;
-
- BufferQueue::BufferItem mBufferSlots[BufferQueue::NUM_BUFFER_SLOTS];
-};
-
-JNICPCamBufferQueueContext::JNICPCamBufferQueueContext(JNIEnv* env,
- jobject weakThiz, jclass clazz) :
- BufferQueue::ProxyConsumerListener(NULL),
- mWeakThiz(env->NewGlobalRef(weakThiz)),
- mClazz((jclass)env->NewGlobalRef(clazz))
-{}
-
-JNIEnv* JNICPCamBufferQueueContext::getJNIEnv(bool* needsDetach) {
- *needsDetach = false;
- JNIEnv* env = getJniEnv();
- if (env == NULL) {
- JavaVMAttachArgs args = {JNI_VERSION_1_4, NULL, NULL};
- int result = getJavaVM()->AttachCurrentThread(&env, (void*) &args);
- if (result != JNI_OK) {
- ALOGE("thread attach failed: %#x", result);
- return NULL;
- }
- *needsDetach = true;
- }
- return env;
-}
-
-void JNICPCamBufferQueueContext::detachJNI() {
- int result = getJavaVM()->DetachCurrentThread();
- if (result != JNI_OK) {
- ALOGE("thread detach failed: %#x", result);
- }
-}
-
-JNICPCamBufferQueueContext::~JNICPCamBufferQueueContext()
-{
- bool needsDetach = false;
- JNIEnv* env = getJNIEnv(&needsDetach);
- if (env != NULL) {
- env->DeleteGlobalRef(mWeakThiz);
- env->DeleteGlobalRef(mClazz);
- } else {
- ALOGW("leaking JNI object references");
- }
- if (needsDetach) {
- detachJNI();
- }
-}
-
-void JNICPCamBufferQueueContext::onFrameAvailable()
-{
- bool needsDetach = false;
- JNIEnv* env = getJNIEnv(&needsDetach);
- if (env != NULL) {
- env->CallStaticVoidMethod(mClazz, fields.postEvent, mWeakThiz);
- } else {
- ALOGW("onFrameAvailable event will not posted");
- }
- if (needsDetach) {
- detachJNI();
- }
-}
-
-void JNICPCamBufferQueueContext::onBuffersReleased()
-{
- for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
- mBufferSlots[i].mGraphicBuffer = 0;
- }
-}
-
-void JNICPCamBufferQueueContext::saveBuffer(unsigned int slot, sp<GraphicBuffer> gbuf)
-{
- if (slot < BufferQueue::NUM_BUFFER_SLOTS) {
- mBufferSlots[slot].mGraphicBuffer = gbuf;
- }
-}
-
-sp<GraphicBuffer> JNICPCamBufferQueueContext::retrieveBuffer(unsigned int slot)
-{
- sp<GraphicBuffer> gbuf = 0;
-
- if (slot < BufferQueue::NUM_BUFFER_SLOTS) {
- gbuf = mBufferSlots[slot].mGraphicBuffer;
- }
-
- return gbuf;
-}
-// ----------------------------------------------------------------------------
-
-static void CPCamBufferQueue_classInit(JNIEnv* env, jclass clazz)
-{
- fields.bufferQueue = env->GetFieldID(clazz, "mBufferQueue", "I");
- if (fields.bufferQueue == NULL) {
- ALOGE("can't find com/ti/omap/android/cpcam/CPCamBufferQueue.%s",
- "mBufferQueue");
- }
-
- fields.postEvent = env->GetStaticMethodID(clazz, "postEventFromNative",
- "(Ljava/lang/Object;)V");
- if (fields.postEvent == NULL) {
- ALOGE("can't find com/ti/omap/android/cpcam/CPCamBufferQueue.postEventFromNative");
- }
-
- fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
- if (fields.context == NULL) {
- ALOGE("can't find com/ti/omap/android/cpcam/CPCamBufferQueue.%s",
- "mNativeContext");
- }
- ALOGE("CPCamBufferQueue_classInit");
-}
-
-static void CPCamBufferQueue_init(JNIEnv* env, jobject thiz,
- jobject weakThiz, jboolean allowSynchronous)
-{
-#ifdef ANDROID_API_JB_MR1_OR_LATER
- sp<BufferQueue> bufferQueue(new BufferQueue(allowSynchronous));
-#else
- sp<BufferQueue> bufferQueue(new BufferQueue(allowSynchronous), 1);
-#endif
- if (bufferQueue == 0) {
- jniThrowException(env, OutOfResourcesException,
- "Unable to create native SurfaceTexture");
- return;
- }
-#ifdef ANDROID_API_JB_MR1_OR_LATER
- bufferQueue->setMaxAcquiredBufferCount(1);
-#endif
- CPCamBufferQueue_setCPCamBufferQueue(env, thiz, bufferQueue);
-
- jclass clazz = env->GetObjectClass(thiz);
- if (clazz == NULL) {
- jniThrowRuntimeException(env,
- "Can't find com/ti/omap/android/cpcam/SurfaceTexture");
- return;
- }
-
- sp<JNICPCamBufferQueueContext> ctx(new JNICPCamBufferQueueContext(env, weakThiz,
- clazz));
-
- status_t err = bufferQueue->consumerConnect(ctx);
- if (err != NO_ERROR) {
- jniThrowRuntimeException(env,
- "error connecting to BufferQueue");
- return;
- }
-
- // save context in opaque field
- env->SetIntField(thiz, fields.context, (int)ctx.get());
-
- // TODO(XXX): Need to figure out if we need to set these
- // mBufferQueue->setConsumerName(mName);
- // mBufferQueue->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
-}
-
-static void CPCamBufferQueue_finalize(JNIEnv* env, jobject thiz)
-{
- sp<BufferQueue> bufferQueue(CPCamBufferQueue_getCPCamBufferQueue(env, thiz));
- bufferQueue->consumerDisconnect();
- CPCamBufferQueue_setCPCamBufferQueue(env, thiz, 0);
-
- // Delete reference to context
- env->SetIntField(thiz, fields.context, 0);
-}
-
-static void CPCamBufferQueue_setDefaultBufferSize(
- JNIEnv* env, jobject thiz, jint width, jint height)
-{
- sp<BufferQueue> bufferQueue(CPCamBufferQueue_getCPCamBufferQueue(env, thiz));
- bufferQueue->setDefaultBufferSize(width, height);
-}
-
-static jint CPCamBufferQueue_acquireBuffer(JNIEnv* env, jobject thiz)
-{
- sp<BufferQueue> bufferQueue(CPCamBufferQueue_getCPCamBufferQueue(env, thiz));
- JNICPCamBufferQueueContext *ctx = NULL;
-
- BufferQueue::BufferItem item;
-
- status_t err = bufferQueue->acquireBuffer(&item);
- if (err == INVALID_OPERATION) {
- jniThrowException(env, IllegalStateException, "Unable to take reference to buffer (see "
- "logcat for details)");
- } else if (err != NO_ERROR) {
- jniThrowRuntimeException(env, "Error during takeCurrentBuffer (see logcat for details)");
- }
-
- ctx = reinterpret_cast<JNICPCamBufferQueueContext*>(env->GetIntField(thiz, fields.context));
-
- // Need to hold a reference to newly allocated buffers
- // mGraphicBuffer field is only filled the first time
- // we acquire the buffer
- if (ctx != NULL && item.mGraphicBuffer != NULL) {
- ctx->saveBuffer(item.mBuf, item.mGraphicBuffer);
- }
-
- return item.mBuf;
-}
-
-static void CPCamBufferQueue_releaseBuffer(JNIEnv* env, jobject thiz, jint slot)
-{
- sp<BufferQueue> bufferQueue(CPCamBufferQueue_getCPCamBufferQueue(env, thiz));
-
-#ifdef ANDROID_API_JB_MR1_OR_LATER
- bufferQueue->releaseBuffer(slot, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, Fence::NO_FENCE);
-#else
- bufferQueue->releaseBuffer(slot, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR);
-#endif
-}
-
-static void CPCamBufferQueue_getCropRect(JNIEnv* env, jobject thiz,
- jint slot, jobject rect)
-{
- sp<BufferQueue> bufferQueue(CPCamBufferQueue_getCPCamBufferQueue(env, thiz));
- BufferQueue::BufferItem item;
-
- status_t err = bufferQueue->getBuffer(slot, &item);
- if (err == INVALID_OPERATION) {
- jniThrowException(env, IllegalStateException, "Unable to take reference to buffer (see "
- "logcat for details)");
- } else if (err != NO_ERROR) {
- jniThrowRuntimeException(env, "Error during takeCurrentBuffer (see logcat for details)");
- }
-
- jclass clazz = env->GetObjectClass(rect);
- if (clazz != 0) {
- env->SetIntField(rect, fields.rect_left, item.mCrop.left);
- env->SetIntField(rect, fields.rect_top, item.mCrop.top);
- env->SetIntField(rect, fields.rect_right, item.mCrop.right);
- env->SetIntField(rect, fields.rect_bottom, item.mCrop.bottom);
- }
-}
-
-static jlong CPCamBufferQueue_getTimestamp(JNIEnv* env, jobject thiz, jint slot)
-{
- sp<BufferQueue> bufferQueue(CPCamBufferQueue_getCPCamBufferQueue(env, thiz));
- BufferQueue::BufferItem item;
-
- status_t err = bufferQueue->getBuffer(slot, &item);
- if (err == INVALID_OPERATION) {
- jniThrowException(env, IllegalStateException, "Unable to take reference to buffer (see "
- "logcat for details)");
- } else if (err != NO_ERROR) {
- jniThrowRuntimeException(env, "Error during takeCurrentBuffer (see logcat for details)");
- }
-
- return item.mTimestamp;
-}
-
-static void CPCamBufferQueue_release(JNIEnv* env, jobject thiz)
-{
- sp<BufferQueue> bufferQueue(CPCamBufferQueue_getCPCamBufferQueue(env, thiz));
- bufferQueue->consumerDisconnect();
-
- // Delete reference to context
- env->SetIntField(thiz, fields.context, 0);
-}
-
-static jstring CPCamBufferQueue_getId(JNIEnv* env, jobject thiz)
-{
- sp<BufferQueue> bufferQueue(CPCamBufferQueue_getCPCamBufferQueue(env, thiz));
- String8 id = bufferQueue->getId();
- return env->NewStringUTF(id.string());
-}
-
-// ----------------------------------------------------------------------------
-
-static JNINativeMethod gCPCamBufferQueueMethods[] = {
- {"nativeClassInit", "()V", (void*)CPCamBufferQueue_classInit },
- {"nativeInit", "(Ljava/lang/Object;Z)V", (void*)CPCamBufferQueue_init },
- {"nativeFinalize", "()V", (void*)CPCamBufferQueue_finalize },
- {"nativeSetDefaultBufferSize", "(II)V", (void*)CPCamBufferQueue_setDefaultBufferSize },
- {"nativeAcquireBuffer", "()I", (void*)CPCamBufferQueue_acquireBuffer },
- {"nativeReleaseBuffer", "(I)V", (void*)CPCamBufferQueue_releaseBuffer },
- {"nativeGetTimestamp", "(I)J", (void*)CPCamBufferQueue_getTimestamp },
- {"nativeRelease", "()V", (void*)CPCamBufferQueue_release },
- {"nativeGetId", "()Ljava/lang/String;", (void*)CPCamBufferQueue_getId },
-};
-
-struct field {
- const char *class_name;
- const char *field_name;
- const char *field_type;
- jfieldID *jfield;
-};
-
-static int find_fields(JNIEnv *env, field *fields, int count)
-{
- for (int i = 0; i < count; i++) {
- field *f = &fields[i];
- jclass clazz = env->FindClass(f->class_name);
- if (clazz == NULL) {
- CAMHAL_LOGE("Can't find %s", f->class_name);
- return -1;
- }
-
- jfieldID field = env->GetFieldID(clazz, f->field_name, f->field_type);
- if (field == NULL) {
- CAMHAL_LOGE("Can't find %s.%s", f->class_name, f->field_name);
- return -1;
- }
-
- *(f->jfield) = field;
- }
-
- return 0;
-}
-
-int register_android_graphics_CPCamBufferQueue(JNIEnv* env)
-{
- int err = 0;
- jclass clazz;
-
- field fields_to_find[] = {
- { "android/graphics/Rect", "left", "I", &fields.rect_left },
- { "android/graphics/Rect", "top", "I", &fields.rect_top },
- { "android/graphics/Rect", "right", "I", &fields.rect_right },
- { "android/graphics/Rect", "bottom", "I", &fields.rect_bottom },
- };
-
- if (find_fields(env, fields_to_find, NELEM(fields_to_find)) < 0)
- return -1;
-
- clazz = env->FindClass(kCPCamBufferQueueClassPathName);
- if (env->RegisterNatives(clazz, gCPCamBufferQueueMethods,
- NELEM(gCPCamBufferQueueMethods)) != JNI_OK)
- {
- ALOGE("Failed registering methods for %s\n", kCPCamBufferQueueClassPathName);
- return -1;
- }
-
- return err;
-}
diff --git a/cpcam/jni/com_ti_omap_android_cpcam_CPCamMetadata.cpp b/cpcam/jni/com_ti_omap_android_cpcam_CPCamMetadata.cpp
deleted file mode 100644
index 4c4c217..0000000
--- a/cpcam/jni/com_ti_omap_android_cpcam_CPCamMetadata.cpp
+++ /dev/null
@@ -1,629 +0,0 @@
-/*
-**
-** Copyright 2008, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#include "jni.h"
-#include "JNIHelp.h"
-
-#include <gui/SurfaceTexture.h>
-#include <camera/CameraMetadata.h>
-
-#include <binder/IMemory.h>
-#include <binder/MemoryBase.h>
-#include <binder/MemoryHeapBase.h>
-
-#ifdef ANDROID_API_JB_OR_LATER
-#include <gui/BufferQueue.h>
-# define CAMHAL_LOGV ALOGV
-# define CAMHAL_LOGE ALOGE
-# define METADATA_ACCESS_TYPE BufferQueue
-#else
-# define CAMHAL_LOGV LOGV
-# define CAMHAL_LOGE LOGE
-# define METADATA_ACCESS_TYPE SurfaceTexture
-#endif
-
-const char* const kMetadataAccessClassPathName = "com/ti/omap/android/cpcam/CPCamBufferQueue";
-const char* const kMetadataAccessJNIID = "mBufferQueue";
-
-using namespace android;
-
-const char* const kMetadataClassPathName = "com/ti/omap/android/cpcam/CPCamMetadata";
-
-struct fields_t {
- jmethodID metadataInit;
- jmethodID rectInit;
- jmethodID bscPositionInit;
- jmethodID h3aInit;
- jfieldID frameNumber;
- jfieldID shotNumber;
- jfieldID analogGain;
- jfieldID analogGainReq;
- jfieldID analogGainMin;
- jfieldID analogGainMax;
- jfieldID analogGainDev;
- jfieldID analogGainError;
- jfieldID exposureTime;
- jfieldID exposureTimeReq;
- jfieldID exposureTimeMin;
- jfieldID exposureTimeMax;
- jfieldID exposureTimeDev;
- jfieldID exposureTimeError;
- jfieldID exposureCompensationReq;
- jfieldID exposureDev;
- jfieldID timestamp;
- jfieldID awbTemp;
- jfieldID gainR;
- jfieldID gainGR;
- jfieldID gainGB;
- jfieldID gainB;
- jfieldID offsetR;
- jfieldID offsetGR;
- jfieldID offsetGB;
- jfieldID offsetB;
- jfieldID lscTableApplied;
- jfieldID faces;
- jfieldID numberOfFaces;
- jfieldID auxImageWidth;
- jfieldID auxImageHeight;
- jfieldID bscColorElement;
- jfieldID bscRowPosition;
- jfieldID bscColPosition;
- jfieldID afBayeRGBPosition;
- jfieldID afEnableAFPeakMode;
- jfieldID afEnableAFVertical;
- jfieldID afPaxelWindow;
- jfieldID aewbMode;
- jfieldID aewbThresholdPixelValue;
- jfieldID aewbPaxelWindow;
- jfieldID aewbAccumulationShift;
- jfieldID lscTable;
- jfieldID auxImage;
- jfieldID bscRowSum;
- jfieldID bscColSum;
- jfieldID afPaxelStatistics;
- jfieldID aewbPaxelStatistics;
- jfieldID bscPositionVectors;
- jfieldID bscPositionShift;
- jfieldID bscPositionVerticalPosition;
- jfieldID bscPositionHorizontalPosition;
- jfieldID bscPositionVerticalNumber;
- jfieldID bscPositionHorizontalNumber;
- jfieldID bscPositionVerticalSkip;
- jfieldID bscPositionHorizontalSkip;
- jfieldID h3aVerticalPosition;
- jfieldID h3aVerticalSize;
- jfieldID h3aHorizontalPosition;
- jfieldID h3aHorizontalSize;
- jfieldID h3aVerticalCount;
- jfieldID h3aVeticalIncrement;
- jfieldID h3aHorizontalCount;
- jfieldID h3aHorizontalIncrement;
-
-};
-
-static fields_t fields;
-
-static void Metadata_Init(JNIEnv* env, jclass clazz)
-{
-
- jclass metaDataClazz = env->FindClass("com/ti/omap/android/cpcam/CPCamMetadata");
- if ( NULL == metaDataClazz ) {
- CAMHAL_LOGE("Couldn't find CPCamMetadata class");
- }
-
- fields.metadataInit = env->GetMethodID(metaDataClazz, "<init>", "()V");
- if ( NULL == fields.metadataInit ) {
- CAMHAL_LOGE("Couldn't find Metadata constructor");
- }
-
- jclass rectClazz = env->FindClass("android/graphics/Rect");
- if ( NULL == rectClazz ) {
- CAMHAL_LOGE("Couldn't find Rect class");
- }
-
- fields.rectInit = env->GetMethodID(rectClazz, "<init>", "(IIII)V");
- if ( NULL == fields.rectInit ) {
- CAMHAL_LOGE("Couldn't find Rect constructor");
- }
-
- fields.frameNumber = env->GetFieldID(metaDataClazz, "frameNumber", "I");
- if ( NULL == fields.frameNumber ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.shotNumber = env->GetFieldID(metaDataClazz, "shotNumber", "I");
- if ( NULL == fields.shotNumber ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.analogGain = env->GetFieldID(metaDataClazz, "analogGain", "I");
- if ( NULL == fields.analogGain ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.analogGainReq = env->GetFieldID(metaDataClazz, "analogGainReq", "I");
- if ( NULL == fields.analogGainReq ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.analogGainMin = env->GetFieldID(metaDataClazz, "analogGainMin", "I");
- if ( NULL == fields.analogGainMin ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.analogGainMax = env->GetFieldID(metaDataClazz, "analogGainMax", "I");
- if ( NULL == fields.analogGainMax ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.analogGainDev = env->GetFieldID(metaDataClazz, "analogGainDev", "I");
- if ( NULL == fields.analogGainDev ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.analogGainError = env->GetFieldID(metaDataClazz, "analogGainError", "I");
- if ( NULL == fields.analogGainError ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.exposureTime = env->GetFieldID(metaDataClazz, "exposureTime", "I");
- if ( NULL == fields.exposureTime ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.exposureTimeReq = env->GetFieldID(metaDataClazz, "exposureTimeReq", "I");
- if ( NULL == fields.exposureTimeReq ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.exposureTimeMin = env->GetFieldID(metaDataClazz, "exposureTimeMin", "I");
- if ( NULL == fields.exposureTimeMin ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.exposureTimeMax = env->GetFieldID(metaDataClazz, "exposureTimeMax", "I");
- if ( NULL == fields.exposureTimeMax ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.exposureTimeDev = env->GetFieldID(metaDataClazz, "exposureTimeDev", "I");
- if ( NULL == fields.exposureTimeDev ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.exposureTimeError = env->GetFieldID(metaDataClazz, "exposureTimeError", "I");
- if ( NULL == fields.exposureTimeError ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.exposureCompensationReq = env->GetFieldID(metaDataClazz, "exposureCompensationReq", "I");
- if ( NULL == fields.exposureCompensationReq ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.exposureDev = env->GetFieldID(metaDataClazz, "exposureDev", "I");
- if ( NULL == fields.exposureDev ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.timestamp = env->GetFieldID(metaDataClazz, "timestamp", "J");
- if ( NULL == fields.timestamp ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.awbTemp = env->GetFieldID(metaDataClazz, "awbTemp", "I");
- if ( NULL == fields.awbTemp ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.gainR = env->GetFieldID(metaDataClazz, "gainR", "I");
- if ( NULL == fields.gainR ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.gainGR = env->GetFieldID(metaDataClazz, "gainGR", "I");
- if ( NULL == fields.gainGR ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.gainGB = env->GetFieldID(metaDataClazz, "gainGB", "I");
- if ( NULL == fields.gainGB ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.gainB = env->GetFieldID(metaDataClazz, "gainB", "I");
- if ( NULL == fields.gainB ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.offsetR = env->GetFieldID(metaDataClazz, "offsetR", "I");
- if ( NULL == fields.offsetR ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.offsetGR = env->GetFieldID(metaDataClazz, "offsetGR", "I");
- if ( NULL == fields.offsetGR ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.offsetGB = env->GetFieldID(metaDataClazz, "offsetGB", "I");
- if ( NULL == fields.offsetGB ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.offsetB = env->GetFieldID(metaDataClazz, "offsetB", "I");
- if ( NULL == fields.offsetB ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.lscTableApplied = env->GetFieldID(metaDataClazz, "lscTableApplied", "I");
- if ( NULL == fields.lscTableApplied ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.faces = env->GetFieldID(metaDataClazz, "faces", "Ljava/nio/ByteBuffer;");
- if ( NULL == fields.faces ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.numberOfFaces = env->GetFieldID(metaDataClazz, "numberOfFaces", "I");
- if ( NULL == fields.numberOfFaces ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.auxImageWidth = env->GetFieldID(metaDataClazz, "auxImageWidth", "I");
- if ( NULL == fields.auxImageWidth ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.auxImageHeight = env->GetFieldID(metaDataClazz, "auxImageHeight", "I");
- if ( NULL == fields.auxImageHeight ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.bscColorElement = env->GetFieldID(metaDataClazz, "bscColorElement", "I");
- if ( NULL == fields.bscColorElement ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- jclass bscPositionClazz = env->FindClass("com/ti/omap/android/cpcam/CPCamMetadata$BSCPosition");
- if ( NULL == bscPositionClazz ) {
- CAMHAL_LOGE("Couldn't find BSCPosition class");
- }
-
- fields.bscPositionInit = env->GetMethodID(bscPositionClazz, "<init>", "()V");
- if ( NULL == fields.bscPositionInit ) {
- CAMHAL_LOGE("Couldn't find BSCPosition constructor");
- }
-
- fields.bscPositionVectors = env->GetFieldID(bscPositionClazz, "vectors", "I");
- if ( NULL == fields.bscPositionVectors ) {
- CAMHAL_LOGE("Couldn't allocate BSCPosition field");
- }
-
- fields.bscPositionShift = env->GetFieldID(bscPositionClazz, "shift", "I");
- if ( NULL == fields.bscPositionShift ) {
- CAMHAL_LOGE("Couldn't allocate BSCPosition field");
- }
-
- fields.bscPositionVerticalPosition = env->GetFieldID(bscPositionClazz,
- "verticalPosition",
- "I");
- if ( NULL == fields.bscPositionVerticalPosition ) {
- CAMHAL_LOGE("Couldn't allocate BSCPosition field");
- }
-
- fields.bscPositionHorizontalPosition = env->GetFieldID(bscPositionClazz,
- "horizontalPosition",
- "I");
- if ( NULL == fields.bscPositionHorizontalPosition ) {
- CAMHAL_LOGE("Couldn't allocate BSCPosition field");
- }
-
- fields.bscPositionVerticalNumber = env->GetFieldID(bscPositionClazz,
- "verticalNumber",
- "I");
- if ( NULL == fields.bscPositionVerticalNumber ) {
- CAMHAL_LOGE("Couldn't allocate BSCPosition field");
- }
-
- fields.bscPositionHorizontalNumber = env->GetFieldID(bscPositionClazz,
- "horizontalNumber",
- "I");
- if ( NULL == fields.bscPositionHorizontalNumber ) {
- CAMHAL_LOGE("Couldn't allocate BSCPosition field");
- }
-
- fields.bscPositionVerticalSkip = env->GetFieldID(bscPositionClazz,
- "verticalSkip",
- "I");
- if ( NULL == fields.bscPositionVerticalSkip ) {
- CAMHAL_LOGE("Couldn't allocate BSCPosition field");
- }
-
- fields.bscPositionHorizontalSkip = env->GetFieldID(bscPositionClazz,
- "horizontalSkip",
- "I");
- if ( NULL == fields.bscPositionHorizontalSkip ) {
- CAMHAL_LOGE("Couldn't allocate BSCPosition field");
- }
-
- fields.bscRowPosition = env->GetFieldID(metaDataClazz,
- "bscRowPosition",
- "Lcom/ti/omap/android/cpcam/CPCamMetadata$BSCPosition;");
- if ( NULL == fields.bscRowPosition ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.bscColPosition = env->GetFieldID(metaDataClazz,
- "bscColPosition",
- "Lcom/ti/omap/android/cpcam/CPCamMetadata$BSCPosition;");
- if ( NULL == fields.bscColPosition ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.afBayeRGBPosition = env->GetFieldID(metaDataClazz, "afBayeRGBPosition", "I");
- if ( NULL == fields.afBayeRGBPosition ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.afEnableAFPeakMode = env->GetFieldID(metaDataClazz, "afEnableAFPeakMode", "I");
- if ( NULL == fields.afEnableAFPeakMode ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.afEnableAFVertical = env->GetFieldID(metaDataClazz, "afEnableAFVertical", "I");
- if ( NULL == fields.afEnableAFVertical ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.afPaxelWindow = env->GetFieldID(metaDataClazz,
- "afPaxelWindow",
- "Lcom/ti/omap/android/cpcam/CPCamMetadata$H3AConfig;");
- if ( NULL == fields.afPaxelWindow ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- jclass h3aConfigClazz = env->FindClass("com/ti/omap/android/cpcam/CPCamMetadata$H3AConfig");
- if ( NULL == h3aConfigClazz ) {
- CAMHAL_LOGE("Couldn't find H3AConfig class");
- }
-
- fields.h3aVerticalPosition = env->GetFieldID(h3aConfigClazz, "verticalPosition", "I");
- if ( NULL == fields.h3aVerticalPosition ) {
- CAMHAL_LOGE("Couldn't allocate H3AConfig field");
- }
-
- fields.h3aVerticalSize = env->GetFieldID(h3aConfigClazz, "verticalSize", "I");
- if ( NULL == fields.h3aVerticalSize ) {
- CAMHAL_LOGE("Couldn't allocate H3AConfig field");
- }
-
- fields.h3aHorizontalPosition = env->GetFieldID(h3aConfigClazz, "horizontalPosition", "I");
- if ( NULL == fields.h3aHorizontalPosition ) {
- CAMHAL_LOGE("Couldn't allocate H3AConfig field");
- }
-
- fields.h3aHorizontalSize = env->GetFieldID(h3aConfigClazz, "horizontalSize", "I");
- if ( NULL == fields.h3aHorizontalSize ) {
- CAMHAL_LOGE("Couldn't allocate H3AConfig field");
- }
-
- fields.h3aVerticalCount = env->GetFieldID(h3aConfigClazz, "verticalCount", "I");
- if ( NULL == fields.h3aVerticalCount ) {
- CAMHAL_LOGE("Couldn't allocate H3AConfig field");
- }
-
- fields.h3aVeticalIncrement = env->GetFieldID(h3aConfigClazz, "veticalIncrement", "I");
- if ( NULL == fields.h3aVeticalIncrement ) {
- CAMHAL_LOGE("Couldn't allocate H3AConfig field");
- }
-
- fields.h3aHorizontalCount = env->GetFieldID(h3aConfigClazz, "horizontalCount", "I");
- if ( NULL == fields.h3aHorizontalCount ) {
- CAMHAL_LOGE("Couldn't allocate H3AConfig field");
- }
-
- fields.h3aHorizontalIncrement = env->GetFieldID(h3aConfigClazz, "horizontalIncrement", "I");
- if ( NULL == fields.h3aHorizontalIncrement ) {
- CAMHAL_LOGE("Couldn't allocate H3AConfig field");
- }
-
- fields.h3aInit = env->GetMethodID(h3aConfigClazz, "<init>", "()V");
- if ( NULL == fields.h3aInit ) {
- CAMHAL_LOGE("Couldn't find H3AConfig constructor");
- }
-
- fields.aewbMode = env->GetFieldID(metaDataClazz, "aewbMode", "I");
- if ( NULL == fields.aewbMode ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.aewbThresholdPixelValue = env->GetFieldID(metaDataClazz, "aewbThresholdPixelValue", "I");
- if ( NULL == fields.aewbThresholdPixelValue ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.aewbAccumulationShift = env->GetFieldID(metaDataClazz, "aewbAccumulationShift", "I");
- if ( NULL == fields.aewbAccumulationShift ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.aewbPaxelWindow = env->GetFieldID(metaDataClazz,
- "aewbPaxelWindow",
- "Lcom/ti/omap/android/cpcam/CPCamMetadata$H3AConfig;");
- if ( NULL == fields.aewbPaxelWindow ) {
- CAMHAL_LOGE("Couldn't allocate Metadata field");
- }
-
- fields.lscTable = env->GetFieldID(metaDataClazz, "lscTable", "Ljava/nio/ByteBuffer;");
- if ( NULL == fields.lscTable ) {
- CAMHAL_LOGE("Couldn't find Metadata field");
- }
-
- fields.auxImage = env->GetFieldID(metaDataClazz, "auxImage", "Ljava/nio/ByteBuffer;");
- if ( NULL == fields.auxImage ) {
- CAMHAL_LOGE("Couldn't find Metadata field");
- }
-
- fields.bscRowSum = env->GetFieldID(metaDataClazz, "bscRowSum", "Ljava/nio/ByteBuffer;");
- if ( NULL == fields.bscRowSum ) {
- CAMHAL_LOGE("Couldn't find Metadata field");
- }
-
- fields.bscColSum = env->GetFieldID(metaDataClazz, "bscColSum", "Ljava/nio/ByteBuffer;");
- if ( NULL == fields.bscColSum ) {
- CAMHAL_LOGE("Couldn't find Metadata field");
- }
-
- fields.afPaxelStatistics = env->GetFieldID(metaDataClazz,
- "afPaxelStatistics",
- "Ljava/nio/ByteBuffer;");
- if ( NULL == fields.afPaxelStatistics ) {
- CAMHAL_LOGE("Couldn't find Metadata field");
- }
-
- fields.aewbPaxelStatistics = env->GetFieldID(metaDataClazz,
- "aewbPaxelStatistics",
- "Ljava/nio/ByteBuffer;");
- if ( NULL == fields.aewbPaxelStatistics ) {
- CAMHAL_LOGE("Couldn't find Metadata field");
- }
-
-}
-
-static jobject Metadata_retrieveMetadata(JNIEnv* env, jclass clazz, jobject st, jint slot)
-{
-
- jclass stClazz = env->FindClass(kMetadataAccessClassPathName);
- if (stClazz == NULL) {
- return NULL;
- }
-
- jfieldID context = env->GetFieldID(stClazz, kMetadataAccessJNIID, "I");
- if ( context == NULL ) {
- return NULL;
- }
-
- sp<METADATA_ACCESS_TYPE> access = NULL;
- if ( st != NULL ) {
- access = reinterpret_cast<METADATA_ACCESS_TYPE *>(env->GetIntField(st, context));
- }
-
-#ifdef ANDROID_API_JB_OR_LATER
- BufferQueue::BufferItem item;
- access->getBuffer(slot, &item);
- sp<IMemory> data = item.mMetadata;
-#else
- sp<IMemory> data = access->getMetadata();
-#endif
-
- ssize_t offset;
- size_t size;
-
- if ( NULL == data.get() ) {
- return NULL;
- }
-
- sp<IMemoryHeap> heap = data->getMemory(&offset, &size);
- camera_metadata_t * meta = static_cast<camera_metadata_t *> (heap->base());
-
- jclass h3aConfigClazz = env->FindClass("com/ti/omap/android/cpcam/CPCamMetadata$H3AConfig");
- if ( NULL == h3aConfigClazz ) {
- CAMHAL_LOGE("Couldn't find H3AConfig class");
- return NULL;
- }
-
- jclass metaDataClazz = env->FindClass(kMetadataClassPathName);
- if ( NULL == metaDataClazz ) {
- CAMHAL_LOGE("Couldn't find Metadata class");
- return NULL;
- }
-
- jobject objMeta = (jobject) env->NewObject(metaDataClazz,
- fields.metadataInit);
- if ( NULL == objMeta ) {
- CAMHAL_LOGE("Couldn't allocate Metadata object");
- return NULL;
- }
-
- if ( 0 < meta->lsc_table_size ) {
- jobject nioLSCTable = env->NewDirectByteBuffer((uint8_t *)meta + meta->lsc_table_offset,
- meta->lsc_table_size);
- if ( NULL == nioLSCTable ) {
- CAMHAL_LOGE("Couldn't allocate NIO LSC table");
- return NULL;
- }
- env->SetObjectField(objMeta, fields.lscTable, nioLSCTable);
- env->DeleteLocalRef(nioLSCTable);
- env->SetIntField(objMeta, fields.lscTableApplied, meta->lsc_table_applied);
- }
-
- jobject nioFaces = env->NewDirectByteBuffer((uint8_t *)meta + meta->faces_offset,
- meta->number_of_faces * sizeof(camera_metadata_face_t));
- if ( NULL == nioFaces ) {
- CAMHAL_LOGE("Couldn't allocate NIO Face array");
- return NULL;
- }
- env->SetObjectField(objMeta, fields.faces, nioFaces);
- env->DeleteLocalRef(nioFaces);
- env->SetIntField(objMeta, fields.numberOfFaces, meta->number_of_faces);
-
- env->SetIntField(objMeta, fields.frameNumber, meta->frame_number);
- env->SetIntField(objMeta, fields.shotNumber, meta->shot_number);
- env->SetIntField(objMeta, fields.analogGain, meta->analog_gain);
- env->SetIntField(objMeta, fields.analogGainReq, meta->analog_gain_req);
- env->SetIntField(objMeta, fields.analogGainMin, meta->analog_gain_min);
- env->SetIntField(objMeta, fields.analogGainMax, meta->analog_gain_max);
- env->SetIntField(objMeta, fields.analogGainDev, meta->analog_gain_dev);
- env->SetIntField(objMeta, fields.analogGainError, meta->analog_gain_error);
- env->SetIntField(objMeta, fields.exposureTime, meta->exposure_time);
- env->SetIntField(objMeta, fields.exposureTimeReq, meta->exposure_time_req);
- env->SetIntField(objMeta, fields.exposureTimeMin, meta->exposure_time_min);
- env->SetIntField(objMeta, fields.exposureTimeMax, meta->exposure_time_max);
- env->SetIntField(objMeta, fields.exposureTimeDev, meta->exposure_time_dev);
- env->SetIntField(objMeta, fields.exposureTimeError, meta->exposure_time_error);
- env->SetIntField(objMeta, fields.exposureCompensationReq, meta->exposure_compensation_req);
- env->SetIntField(objMeta, fields.exposureDev, meta->exposure_dev);
- env->SetLongField(objMeta, fields.timestamp, meta->timestamp);
- env->SetIntField(objMeta, fields.awbTemp, meta->awb_temp);
- env->SetIntField(objMeta, fields.gainR, meta->gain_r);
- env->SetIntField(objMeta, fields.gainGR, meta->gain_gr);
- env->SetIntField(objMeta, fields.gainGB, meta->gain_gb);
- env->SetIntField(objMeta, fields.gainB, meta->gain_b);
- env->SetIntField(objMeta, fields.offsetR, meta->offset_r);
- env->SetIntField(objMeta, fields.offsetGR, meta->offset_gr);
- env->SetIntField(objMeta, fields.offsetGB, meta->offset_gb);
- env->SetIntField(objMeta, fields.offsetB, meta->offset_b);
-
- return objMeta;
-}
-
-static JNINativeMethod gMetadataMethods[] = {
- {"nativeClassInit", "()V", (void*)Metadata_Init },
- {"nativeRetrieveMetadata", "(Lcom/ti/omap/android/cpcam/CPCamBufferQueue;I)Lcom/ti/omap/android/cpcam/CPCamMetadata;", (void*)Metadata_retrieveMetadata },
-};
-
-int register_com_ti_omap_android_cpcam_CPCamMetadata(JNIEnv* env)
-{
- int err = 0;
- err = jniRegisterNativeMethods(env,
- kMetadataClassPathName,
- gMetadataMethods,
- NELEM(gMetadataMethods));
- return err;
-}