summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/one
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2015-03-24 07:23:19 -0700
committerSteve Kondik <steve@cyngn.com>2015-03-24 07:23:19 -0700
commit6eaafbef54de3a9b70ec338512b537cd0f7b5d13 (patch)
tree69646095b714fc45fb7c4d8aeeae6dcaf8aa3d49 /src/com/android/camera/one
parent708b6b29c2cde2510b6cee475bbb91f0ac06c74f (diff)
parent6cb15e279f0fcecfab919a51b6a542bcef5bd2f1 (diff)
downloadandroid_packages_apps_Camera2-staging/cm-12.1.tar.gz
android_packages_apps_Camera2-staging/cm-12.1.tar.bz2
android_packages_apps_Camera2-staging/cm-12.1.zip
Merge branch 'lollipop-mr1-release' of https://android.googlesource.com/platform/packages/apps/Camera2 into cm-12.1staging/cm-12.1
Change-Id: I24fa423d91d8d441cbf5d9e75b98037584dd2fbc
Diffstat (limited to 'src/com/android/camera/one')
-rw-r--r--src/com/android/camera/one/OneCamera.java7
-rw-r--r--src/com/android/camera/one/OneCameraException.java29
-rw-r--r--src/com/android/camera/one/OneCameraManager.java42
-rw-r--r--src/com/android/camera/one/Settings3A.java12
-rw-r--r--src/com/android/camera/one/v2/AutoFocusHelper.java23
-rw-r--r--src/com/android/camera/one/v2/ImageCaptureManager.java20
6 files changed, 105 insertions, 28 deletions
diff --git a/src/com/android/camera/one/OneCamera.java b/src/com/android/camera/one/OneCamera.java
index 593dea4cd..743be3726 100644
--- a/src/com/android/camera/one/OneCamera.java
+++ b/src/com/android/camera/one/OneCamera.java
@@ -17,7 +17,6 @@
package com.android.camera.one;
import android.content.Context;
-import android.graphics.Bitmap;
import android.location.Location;
import android.net.Uri;
import android.view.Surface;
@@ -159,7 +158,7 @@ public interface OneCamera {
* Called when a thumbnail image is provided before the final image is
* finished.
*/
- public void onThumbnailResult(Bitmap bitmap);
+ public void onThumbnailResult(byte[] jpegData);
/**
* Called when the final picture is done taking
@@ -240,6 +239,10 @@ public interface OneCamera {
public Flash flashMode = Flash.AUTO;
/** The location of this capture. */
public Location location = null;
+ /** Zoom value. */
+ public float zoom = 1f;
+ /** Timer duration in seconds or null for no timer. */
+ public Float timerSeconds = null;
/** Set this to provide a debug folder for this capture. */
public File debugDataFolder;
diff --git a/src/com/android/camera/one/OneCameraException.java b/src/com/android/camera/one/OneCameraException.java
new file mode 100644
index 000000000..154acbe65
--- /dev/null
+++ b/src/com/android/camera/one/OneCameraException.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2014 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.android.camera.one;
+
+/**
+ * Used for exceptions thrown by OneCamera API. Use this for severe,
+ * irrecoverable errors only.
+ */
+public class OneCameraException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public OneCameraException(String message) {
+ super(message);
+ }
+}
diff --git a/src/com/android/camera/one/OneCameraManager.java b/src/com/android/camera/one/OneCameraManager.java
index ee505ae34..607e6a077 100644
--- a/src/com/android/camera/one/OneCameraManager.java
+++ b/src/com/android/camera/one/OneCameraManager.java
@@ -20,7 +20,6 @@ import android.content.Context;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
-import android.os.Build;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.view.WindowManager;
@@ -30,6 +29,7 @@ import com.android.camera.debug.Log;
import com.android.camera.debug.Log.Tag;
import com.android.camera.one.OneCamera.Facing;
import com.android.camera.one.OneCamera.OpenCallback;
+import com.android.camera.util.ApiHelper;
import com.android.camera.util.Size;
/**
@@ -66,24 +66,37 @@ public abstract class OneCameraManager {
/**
* Creates a camera manager that is based on Camera2 API, if available, or
* otherwise uses the portability layer API.
+ *
+ * @throws OneCameraException Thrown if an error occurred while trying to
+ * access the camera.
*/
- public static OneCameraManager get(CameraActivity activity) {
+ public static OneCameraManager get(CameraActivity activity) throws OneCameraException {
return create(activity);
}
/**
* Creates a new camera manager that is based on Camera2 API, if available,
* or otherwise uses the portability API.
+ *
+ * @throws OneCameraException Thrown if an error occurred while trying to
+ * access the camera.
*/
- private static OneCameraManager create(CameraActivity activity) {
+ private static OneCameraManager create(CameraActivity activity) throws OneCameraException {
DisplayMetrics displayMetrics = getDisplayMetrics(activity);
- CameraManager cameraManager = (CameraManager) activity
- .getSystemService(Context.CAMERA_SERVICE);
- int maxMemoryMB = activity.getServices().getMemoryManager()
- .getMaxAllowedNativeMemoryAllocation();
+ CameraManager cameraManager = null;
+
+ try {
+ cameraManager = ApiHelper.HAS_CAMERA_2_API ? (CameraManager) activity
+ .getSystemService(Context.CAMERA_SERVICE) : null;
+ } catch (IllegalStateException ex) {
+ cameraManager = null;
+ Log.e(TAG, "Could not get camera service v2", ex);
+ }
if (cameraManager != null && isCamera2Supported(cameraManager)) {
+ int maxMemoryMB = activity.getServices().getMemoryManager()
+ .getMaxAllowedNativeMemoryAllocation();
return new com.android.camera.one.v2.OneCameraManagerImpl(
- activity.getApplicationContext(), cameraManager, maxMemoryMB,
+ activity.getAndroidContext(), cameraManager, maxMemoryMB,
displayMetrics, activity.getSoundPlayer());
} else {
return new com.android.camera.one.v1.OneCameraManagerImpl();
@@ -98,13 +111,20 @@ public abstract class OneCameraManager {
* HAL (such as the Nexus 4, 7 or 10), this method returns false. It
* only returns true, if Camera2 is fully supported through newer
* HALs.
+ * @throws OneCameraException Thrown if an error occurred while trying to
+ * access the camera.
*/
- private static boolean isCamera2Supported(CameraManager cameraManager) {
- if (Build.VERSION.SDK_INT < 21) {
+ private static boolean isCamera2Supported(CameraManager cameraManager)
+ throws OneCameraException {
+ if (!ApiHelper.HAS_CAMERA_2_API) {
return false;
}
try {
- final String id = cameraManager.getCameraIdList()[0];
+ String[] cameraIds = cameraManager.getCameraIdList();
+ if (cameraIds.length == 0) {
+ throw new OneCameraException("Camera 2 API supported but no devices available.");
+ }
+ final String id = cameraIds[0];
// TODO: We should check for all the flags we need to ensure the
// device is capable of taking Camera2 API shots. For now, let's
// accept all device that are either 'partial' or 'full' devices
diff --git a/src/com/android/camera/one/Settings3A.java b/src/com/android/camera/one/Settings3A.java
index a8abf69cc..cdfaa524e 100644
--- a/src/com/android/camera/one/Settings3A.java
+++ b/src/com/android/camera/one/Settings3A.java
@@ -71,6 +71,12 @@ public class Settings3A {
private static final int FOCUS_HOLD_MILLIS = 3000;
/**
+ * The number of milliseconds to hold tap-to-expose/metering after the
+ * last payload frame is received before returning to continuous 3A.
+ */
+ private static final int GCAM_POST_SHOT_FOCUS_HOLD_MILLIS = 1000;
+
+ /**
* Width of touch metering region in [0,1] relative to shorter edge of the
* current crop region. Multiply this number by the number of pixels along
* shorter edge of the current crop region's width to get a value in pixels.
@@ -98,7 +104,7 @@ public class Settings3A {
* Was fixed at 15.0f prior to L release.
* </p>
*/
- private static final float GCAM_METERING_REGION_WEIGHT = 22.0f;
+ private static final float GCAM_METERING_REGION_WEIGHT = 45.0f;
public static float getAutoFocusRegionWidth() {
return AF_REGION_BOX;
@@ -123,4 +129,8 @@ public class Settings3A {
public static int getFocusHoldMillis() {
return FOCUS_HOLD_MILLIS;
}
+
+ public static int getGcamPostShotFocusHoldMillis() {
+ return GCAM_POST_SHOT_FOCUS_HOLD_MILLIS;
+ }
}
diff --git a/src/com/android/camera/one/v2/AutoFocusHelper.java b/src/com/android/camera/one/v2/AutoFocusHelper.java
index 8cfab6806..6416d7034 100644
--- a/src/com/android/camera/one/v2/AutoFocusHelper.java
+++ b/src/com/android/camera/one/v2/AutoFocusHelper.java
@@ -122,10 +122,9 @@ public class AutoFocusHelper {
* @param cropRegion Crop region of the image.
* @param sensorOrientation sensor orientation as defined by
* CameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION).
- *
- * */
- private static MeteringRectangle[] regionsForNormalizedCoord(float nx, float ny, float fraction,
- final Rect cropRegion, int sensorOrientation) {
+ */
+ private static MeteringRectangle[] regionsForNormalizedCoord(float nx, float ny,
+ float fraction, final Rect cropRegion, int sensorOrientation) {
// Compute half side length in pixels.
int minCropEdge = Math.min(cropRegion.width(), cropRegion.height());
int halfSideLength = (int) (0.5f * fraction * minCropEdge);
@@ -188,6 +187,22 @@ public class AutoFocusHelper {
}
/**
+ * [Gcam mode only]: Return AE region(s) for a sensor-referenced touch coordinate.
+ *
+ * <p>
+ * Normalized coordinates are referenced to portrait preview window with
+ * (0, 0) top left and (1, 1) bottom right. Rotation has no effect.
+ * </p>
+ *
+ * @return AE region(s).
+ */
+ public static MeteringRectangle[] gcamAERegionsForNormalizedCoord(float nx,
+ float ny, final Rect cropRegion, int sensorOrientation) {
+ return regionsForNormalizedCoord(nx, ny, Settings3A.getGcamMeteringRegionFraction(),
+ cropRegion, sensorOrientation);
+ }
+
+ /**
* Calculates sensor crop region for a zoom level (zoom >= 1.0).
*
* @return Crop region.
diff --git a/src/com/android/camera/one/v2/ImageCaptureManager.java b/src/com/android/camera/one/v2/ImageCaptureManager.java
index d84d95712..068707149 100644
--- a/src/com/android/camera/one/v2/ImageCaptureManager.java
+++ b/src/com/android/camera/one/v2/ImageCaptureManager.java
@@ -48,7 +48,7 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
* Implements {@link android.media.ImageReader.OnImageAvailableListener} and
- * {@link android.hardware.camera2.CameraCaptureSession.CaptureCallback} to
+ * {@link android.hardware.camera2.CameraCaptureSession.CaptureListener} to
* store the results of capture requests (both {@link Image}s and
* {@link TotalCaptureResult}s in a ring-buffer from which they may be saved.
* <br>
@@ -276,7 +276,7 @@ public class ImageCaptureManager extends CameraCaptureSession.CaptureCallback im
/**
* The set of constraints which must be satisfied for a newly acquired image
- * to be captured and sent to {@link #mPendingImageCaptureListener}. null if
+ * to be captured and sent to {@link #mPendingImageCaptureCallback}. null if
* there is no pending capture request.
*/
private List<ImageCaptureManager.CapturedImageConstraint> mPendingImageCaptureConstraints;
@@ -286,7 +286,7 @@ public class ImageCaptureManager extends CameraCaptureSession.CaptureCallback im
* image which satisfies {@link #mPendingImageCaptureConstraints}. null if
* there is no pending capture request.
*/
- private ImageCaptureManager.ImageCaptureListener mPendingImageCaptureListener;
+ private ImageCaptureManager.ImageCaptureListener mPendingImageCaptureCallback;
/**
* Map from CaptureResult key to the frame number of the capture result
@@ -310,11 +310,11 @@ public class ImageCaptureManager extends CameraCaptureSession.CaptureCallback im
* that this should probably be on a different thread than the
* one used for camera operations, such as capture requests and
* OnImageAvailable listeners, to avoid stalling the preview.
- * @param imageCaptureCallbackExecutor the executor on which to invoke image
+ * @param imageCaptureListenerExecutor the executor on which to invoke image
* capture listeners, {@link ImageCaptureListener}.
*/
ImageCaptureManager(int maxImages, Handler listenerHandler,
- Executor imageCaptureCallbackExecutor) {
+ Executor imageCaptureListenerExecutor) {
// Ensure that there are always 2 images available for the framework to
// continue processing frames.
// TODO Could we make this tighter?
@@ -322,7 +322,7 @@ public class ImageCaptureManager extends CameraCaptureSession.CaptureCallback im
maxImages - 2);
mListenerHandler = listenerHandler;
- mImageCaptureListenerExecutor = imageCaptureCallbackExecutor;
+ mImageCaptureListenerExecutor = imageCaptureListenerExecutor;
}
/**
@@ -551,7 +551,7 @@ public class ImageCaptureManager extends CameraCaptureSession.CaptureCallback im
*/
public void captureNextImage(final ImageCaptureListener onImageCaptured,
final List<CapturedImageConstraint> constraints) {
- mPendingImageCaptureListener = onImageCaptured;
+ mPendingImageCaptureCallback = onImageCaptured;
mPendingImageCaptureConstraints = constraints;
}
@@ -562,7 +562,7 @@ public class ImageCaptureManager extends CameraCaptureSession.CaptureCallback im
* should be captured if appropriate and possible.
*/
private void tryExecutePendingCaptureRequest(long newImageTimestamp) {
- if (mPendingImageCaptureListener != null) {
+ if (mPendingImageCaptureCallback != null) {
final Pair<Long, CapturedImage> pinnedImage = mCapturedImageBuffer.tryPin(
newImageTimestamp);
if (pinnedImage != null) {
@@ -588,11 +588,11 @@ public class ImageCaptureManager extends CameraCaptureSession.CaptureCallback im
// If we get here, the image satisfies all the necessary
// constraints.
- if (tryExecuteCaptureOrRelease(pinnedImage, mPendingImageCaptureListener)) {
+ if (tryExecuteCaptureOrRelease(pinnedImage, mPendingImageCaptureCallback)) {
// If we successfully handed the image off to the callback,
// remove the pending
// capture request.
- mPendingImageCaptureListener = null;
+ mPendingImageCaptureCallback = null;
mPendingImageCaptureConstraints = null;
}
}