The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.hardware; |
| 18 | |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 19 | import static android.system.OsConstants.*; |
| 20 | |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 22 | import android.annotation.SdkConstant; |
| 23 | import android.annotation.SdkConstant.SdkConstantType; |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 24 | import android.app.ActivityThread; |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 25 | import android.app.AppOpsManager; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 26 | import android.content.Context; |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 27 | import android.graphics.ImageFormat; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 28 | import android.graphics.Point; |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 29 | import android.graphics.Rect; |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 30 | import android.graphics.SurfaceTexture; |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 31 | import android.media.AudioAttributes; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 32 | import android.media.IAudioService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.os.Handler; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 34 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.os.Looper; |
| 36 | import android.os.Message; |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 37 | import android.os.Process; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 38 | import android.os.RemoteException; |
| 39 | import android.os.ServiceManager; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 40 | import android.renderscript.Allocation; |
| 41 | import android.renderscript.Element; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 42 | import android.renderscript.RSIllegalArgumentException; |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 43 | import android.renderscript.RenderScript; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 44 | import android.renderscript.Type; |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 45 | import android.text.TextUtils; |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 46 | import android.util.Log; |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 47 | import android.view.Surface; |
| 48 | import android.view.SurfaceHolder; |
| 49 | |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 50 | import com.android.internal.annotations.GuardedBy; |
| 51 | import com.android.internal.app.IAppOpsCallback; |
| 52 | import com.android.internal.app.IAppOpsService; |
| 53 | |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 54 | import java.io.IOException; |
| 55 | import java.lang.ref.WeakReference; |
| 56 | import java.util.ArrayList; |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 57 | import java.util.LinkedHashMap; |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 58 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 61 | * The Camera class is used to set image capture settings, start/stop preview, |
| 62 | * snap pictures, and retrieve frames for encoding for video. This class is a |
| 63 | * client for the Camera service, which manages the actual camera hardware. |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 64 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 65 | * <p>To access the device camera, you must declare the |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 66 | * {@link android.Manifest.permission#CAMERA} permission in your Android |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 67 | * Manifest. Also be sure to include the |
| 68 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 69 | * manifest element to declare camera features used by your application. |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 70 | * For example, if you use the camera and auto-focus feature, your Manifest |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 71 | * should include the following:</p> |
| 72 | * <pre> <uses-permission android:name="android.permission.CAMERA" /> |
| 73 | * <uses-feature android:name="android.hardware.camera" /> |
| 74 | * <uses-feature android:name="android.hardware.camera.autofocus" /></pre> |
| 75 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 76 | * <p>To take pictures with this class, use the following steps:</p> |
| 77 | * |
| 78 | * <ol> |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 79 | * <li>Obtain an instance of Camera from {@link #open(int)}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 80 | * |
| 81 | * <li>Get existing (default) settings with {@link #getParameters()}. |
| 82 | * |
| 83 | * <li>If necessary, modify the returned {@link Camera.Parameters} object and call |
| 84 | * {@link #setParameters(Camera.Parameters)}. |
| 85 | * |
Eino-Ville Talvala | 6c91e2c | 2016-03-25 11:54:39 -0700 | [diff] [blame] | 86 | * <li>Call {@link #setDisplayOrientation(int)} to ensure correct orientation of preview. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 87 | * |
| 88 | * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to |
| 89 | * {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera |
| 90 | * will be unable to start the preview. |
| 91 | * |
| 92 | * <li><b>Important</b>: Call {@link #startPreview()} to start updating the |
| 93 | * preview surface. Preview must be started before you can take a picture. |
| 94 | * |
| 95 | * <li>When you want, call {@link #takePicture(Camera.ShutterCallback, |
| 96 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to |
| 97 | * capture a photo. Wait for the callbacks to provide the actual image data. |
| 98 | * |
| 99 | * <li>After taking a picture, preview display will have stopped. To take more |
| 100 | * photos, call {@link #startPreview()} again first. |
| 101 | * |
| 102 | * <li>Call {@link #stopPreview()} to stop updating the preview surface. |
| 103 | * |
| 104 | * <li><b>Important:</b> Call {@link #release()} to release the camera for |
| 105 | * use by other applications. Applications should release the camera |
| 106 | * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()} |
| 107 | * it in {@link android.app.Activity#onResume()}). |
| 108 | * </ol> |
| 109 | * |
| 110 | * <p>To quickly switch to video recording mode, use these steps:</p> |
| 111 | * |
| 112 | * <ol> |
| 113 | * <li>Obtain and initialize a Camera and start preview as described above. |
| 114 | * |
| 115 | * <li>Call {@link #unlock()} to allow the media process to access the camera. |
| 116 | * |
| 117 | * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}. |
| 118 | * See {@link android.media.MediaRecorder} information about video recording. |
| 119 | * |
| 120 | * <li>When finished recording, call {@link #reconnect()} to re-acquire |
| 121 | * and re-lock the camera. |
| 122 | * |
| 123 | * <li>If desired, restart preview and take more photos or videos. |
| 124 | * |
| 125 | * <li>Call {@link #stopPreview()} and {@link #release()} as described above. |
| 126 | * </ol> |
| 127 | * |
| 128 | * <p>This class is not thread-safe, and is meant for use from one event thread. |
| 129 | * Most long-running operations (preview, focus, photo capture, etc) happen |
| 130 | * asynchronously and invoke callbacks as necessary. Callbacks will be invoked |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 131 | * on the event thread {@link #open(int)} was called from. This class's methods |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 132 | * must never be called from multiple threads at once.</p> |
| 133 | * |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 134 | * <p class="caution"><strong>Caution:</strong> Different Android-powered devices |
| 135 | * may have different hardware specifications, such as megapixel ratings and |
| 136 | * auto-focus capabilities. In order for your application to be compatible with |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 137 | * more devices, you should not make assumptions about the device camera |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 138 | * specifications.</p> |
Joe Fernandez | 6c5c3c3 | 2011-10-18 14:57:05 -0700 | [diff] [blame] | 139 | * |
| 140 | * <div class="special reference"> |
| 141 | * <h3>Developer Guides</h3> |
| 142 | * <p>For more information about using cameras, read the |
| 143 | * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p> |
| 144 | * </div> |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 145 | * |
| 146 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 147 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 149 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | public class Camera { |
| 151 | private static final String TAG = "Camera"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 152 | |
Wu-cheng Li | d2c2929 | 2010-05-28 17:32:41 +0800 | [diff] [blame] | 153 | // These match the enums in frameworks/base/include/camera/Camera.h |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 154 | private static final int CAMERA_MSG_ERROR = 0x001; |
| 155 | private static final int CAMERA_MSG_SHUTTER = 0x002; |
| 156 | private static final int CAMERA_MSG_FOCUS = 0x004; |
| 157 | private static final int CAMERA_MSG_ZOOM = 0x008; |
| 158 | private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010; |
| 159 | private static final int CAMERA_MSG_VIDEO_FRAME = 0x020; |
| 160 | private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040; |
| 161 | private static final int CAMERA_MSG_RAW_IMAGE = 0x080; |
| 162 | private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 163 | private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200; |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 164 | private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400; |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 165 | private static final int CAMERA_MSG_FOCUS_MOVE = 0x800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 167 | private long mNativeContext; // accessed by native methods |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | private EventHandler mEventHandler; |
| 169 | private ShutterCallback mShutterCallback; |
| 170 | private PictureCallback mRawImageCallback; |
| 171 | private PictureCallback mJpegCallback; |
| 172 | private PreviewCallback mPreviewCallback; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 173 | private boolean mUsingPreviewAllocation; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 174 | private PictureCallback mPostviewCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | private AutoFocusCallback mAutoFocusCallback; |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 176 | private AutoFocusMoveCallback mAutoFocusMoveCallback; |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 177 | private OnZoomChangeListener mZoomListener; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 178 | private FaceDetectionListener mFaceListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | private ErrorCallback mErrorCallback; |
| 180 | private boolean mOneShot; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 181 | private boolean mWithBuffer; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 182 | private boolean mFaceDetectionRunning = false; |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 183 | private final Object mAutoFocusCallbackLock = new Object(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 184 | |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 185 | private final Object mShutterSoundLock = new Object(); |
| 186 | // for AppOps |
| 187 | private @Nullable IAppOpsService mAppOps; |
| 188 | private IAppOpsCallback mAppOpsCallback; |
| 189 | @GuardedBy("mShutterSoundLock") |
| 190 | private boolean mHasAppOpsPlayAudio = true; |
| 191 | @GuardedBy("mShutterSoundLock") |
| 192 | private boolean mShutterSoundEnabledFromApp = true; |
| 193 | |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 194 | private static final int NO_ERROR = 0; |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | /** |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 197 | * Broadcast Action: A new picture is taken by the camera, and the entry of |
| 198 | * the picture has been added to the media store. |
| 199 | * {@link android.content.Intent#getData} is URI of the picture. |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 200 | * |
| 201 | * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and |
| 202 | * applications are recommended to use |
| 203 | * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri} |
| 204 | * instead.</p> |
| 205 | * |
| 206 | * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought |
| 207 | * back, but only for <em>registered</em> receivers. Apps that are actively running can |
Dianne Hackborn | c154195 | 2017-04-27 10:55:49 -0700 | [diff] [blame] | 208 | * again listen to the broadcast if they want an immediate clear signal about a picture |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 209 | * being taken, however anything doing heavy work (or needing to be launched) as a result of |
| 210 | * this should still use JobScheduler.</p> |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 211 | */ |
| 212 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 213 | public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE"; |
| 214 | |
| 215 | /** |
| 216 | * Broadcast Action: A new video is recorded by the camera, and the entry |
| 217 | * of the video has been added to the media store. |
| 218 | * {@link android.content.Intent#getData} is URI of the video. |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 219 | * |
| 220 | * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and |
| 221 | * applications are recommended to use |
| 222 | * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri} |
| 223 | * instead.</p> |
| 224 | * |
| 225 | * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought |
| 226 | * back, but only for <em>registered</em> receivers. Apps that are actively running can |
Dianne Hackborn | c154195 | 2017-04-27 10:55:49 -0700 | [diff] [blame] | 227 | * again listen to the broadcast if they want an immediate clear signal about a video |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 228 | * being taken, however anything doing heavy work (or needing to be launched) as a result of |
| 229 | * this should still use JobScheduler.</p> |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 230 | */ |
| 231 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 232 | public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO"; |
| 233 | |
| 234 | /** |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 235 | * Camera HAL device API version 1.0 |
| 236 | * @hide |
| 237 | */ |
| 238 | public static final int CAMERA_HAL_API_VERSION_1_0 = 0x100; |
| 239 | |
| 240 | /** |
| 241 | * A constant meaning the normal camera connect/open will be used. |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 242 | */ |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 243 | private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2; |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 244 | |
| 245 | /** |
| 246 | * Used to indicate HAL version un-specified. |
| 247 | */ |
| 248 | private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1; |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 249 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 250 | /** |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 251 | * Hardware face detection. It does not use much CPU. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 252 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 253 | private static final int CAMERA_FACE_DETECTION_HW = 0; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 254 | |
| 255 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 256 | * Software face detection. It uses some CPU. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 257 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 258 | private static final int CAMERA_FACE_DETECTION_SW = 1; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 259 | |
| 260 | /** |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 261 | * Returns the number of physical cameras available on this device. |
Yin-Chia Yeh | 564ae82 | 2018-02-08 16:24:27 -0800 | [diff] [blame] | 262 | * The return value of this method might change dynamically if the device |
| 263 | * supports external cameras and an external camera is connected or |
| 264 | * disconnected. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 265 | * |
Shuzhen Wang | e7d3cd0 | 2018-05-31 11:41:39 -0700 | [diff] [blame^] | 266 | * If there is a |
| 267 | * {@link android.hardware.camera2.CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA |
| 268 | * logical multi-camera} in the system, to maintain app backward compatibility, this method will |
| 269 | * only expose one camera for every logical camera and underlying physical cameras group. |
| 270 | * Use camera2 API to see all cameras. |
| 271 | * |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 272 | * @return total number of accessible camera devices, or 0 if there are no |
| 273 | * cameras or an error was encountered enumerating them. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | */ |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 275 | public native static int getNumberOfCameras(); |
| 276 | |
| 277 | /** |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 278 | * Returns the information about a particular camera. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 279 | * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 280 | * |
| 281 | * @throws RuntimeException if an invalid ID is provided, or if there is an |
| 282 | * error retrieving the information (generally due to a hardware or other |
| 283 | * low-level failure). |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 284 | */ |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 285 | public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) { |
| 286 | _getCameraInfo(cameraId, cameraInfo); |
| 287 | IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); |
| 288 | IAudioService audioService = IAudioService.Stub.asInterface(b); |
| 289 | try { |
| 290 | if (audioService.isCameraSoundForced()) { |
| 291 | // Only set this when sound is forced; otherwise let native code |
| 292 | // decide. |
| 293 | cameraInfo.canDisableShutterSound = false; |
| 294 | } |
| 295 | } catch (RemoteException e) { |
| 296 | Log.e(TAG, "Audio service is unavailable for queries"); |
| 297 | } |
| 298 | } |
| 299 | private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo); |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 300 | |
| 301 | /** |
| 302 | * Information about a camera |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 303 | * |
| 304 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 305 | * applications. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 306 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 307 | @Deprecated |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 308 | public static class CameraInfo { |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 309 | /** |
| 310 | * The facing of the camera is opposite to that of the screen. |
| 311 | */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 312 | public static final int CAMERA_FACING_BACK = 0; |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 313 | |
| 314 | /** |
| 315 | * The facing of the camera is the same as that of the screen. |
| 316 | */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 317 | public static final int CAMERA_FACING_FRONT = 1; |
| 318 | |
| 319 | /** |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 320 | * The direction that the camera faces. It should be |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 321 | * CAMERA_FACING_BACK or CAMERA_FACING_FRONT. |
| 322 | */ |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 323 | public int facing; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 324 | |
| 325 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 326 | * <p>The orientation of the camera image. The value is the angle that the |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 327 | * camera image needs to be rotated clockwise so it shows correctly on |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 328 | * the display in its natural orientation. It should be 0, 90, 180, or 270.</p> |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 329 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 330 | * <p>For example, suppose a device has a naturally tall screen. The |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 331 | * back-facing camera sensor is mounted in landscape. You are looking at |
| 332 | * the screen. If the top side of the camera sensor is aligned with the |
| 333 | * right edge of the screen in natural orientation, the value should be |
| 334 | * 90. If the top side of a front-facing camera sensor is aligned with |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 335 | * the right of the screen, the value should be 270.</p> |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 336 | * |
| 337 | * @see #setDisplayOrientation(int) |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 338 | * @see Parameters#setRotation(int) |
| 339 | * @see Parameters#setPreviewSize(int, int) |
| 340 | * @see Parameters#setPictureSize(int, int) |
| 341 | * @see Parameters#setJpegThumbnailSize(int, int) |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 342 | */ |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 343 | public int orientation; |
Eino-Ville Talvala | f7c6c5a | 2012-09-19 11:46:11 -0700 | [diff] [blame] | 344 | |
| 345 | /** |
| 346 | * <p>Whether the shutter sound can be disabled.</p> |
| 347 | * |
| 348 | * <p>On some devices, the camera shutter sound cannot be turned off |
| 349 | * through {@link #enableShutterSound enableShutterSound}. This field |
| 350 | * can be used to determine whether a call to disable the shutter sound |
| 351 | * will succeed.</p> |
| 352 | * |
| 353 | * <p>If this field is set to true, then a call of |
| 354 | * {@code enableShutterSound(false)} will be successful. If set to |
| 355 | * false, then that call will fail, and the shutter sound will be played |
| 356 | * when {@link Camera#takePicture takePicture} is called.</p> |
| 357 | */ |
| 358 | public boolean canDisableShutterSound; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 359 | }; |
| 360 | |
| 361 | /** |
Wu-cheng Li | a1c41e1 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 362 | * Creates a new Camera object to access a particular hardware camera. If |
| 363 | * the same camera is opened by other applications, this will throw a |
| 364 | * RuntimeException. |
| 365 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 366 | * <p>You must call {@link #release()} when you are done using the camera, |
| 367 | * otherwise it will remain locked and be unavailable to other applications. |
| 368 | * |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 369 | * <p>Your application should only have one Camera object active at a time |
| 370 | * for a particular hardware camera. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 371 | * |
| 372 | * <p>Callbacks from other methods are delivered to the event loop of the |
| 373 | * thread which called open(). If this thread has no event loop, then |
| 374 | * callbacks are delivered to the main application event loop. If there |
| 375 | * is no main application event loop, callbacks are not delivered. |
| 376 | * |
| 377 | * <p class="caution"><b>Caution:</b> On some devices, this method may |
| 378 | * take a long time to complete. It is best to call this method from a |
| 379 | * worker thread (possibly using {@link android.os.AsyncTask}) to avoid |
| 380 | * blocking the main application UI thread. |
| 381 | * |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 382 | * @param cameraId the hardware camera to access, between 0 and |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 383 | * {@link #getNumberOfCameras()}-1. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 384 | * @return a new Camera object, connected, locked and ready for use. |
Wu-cheng Li | a1c41e1 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 385 | * @throws RuntimeException if opening the camera fails (for example, if the |
| 386 | * camera is in use by another process or device policy manager has |
| 387 | * disabled the camera). |
Wu-cheng Li | facc8ce | 2011-06-17 13:09:40 +0800 | [diff] [blame] | 388 | * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName) |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 389 | */ |
| 390 | public static Camera open(int cameraId) { |
Wu-cheng Li | 7bc1b21 | 2012-04-19 12:23:31 +0800 | [diff] [blame] | 391 | return new Camera(cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 394 | /** |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 395 | * Creates a new Camera object to access the first back-facing camera on the |
| 396 | * device. If the device does not have a back-facing camera, this returns |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 397 | * null. Otherwise acts like the {@link #open(int)} call. |
| 398 | * |
| 399 | * @return a new Camera object for the first back-facing camera, or null if there is no |
| 400 | * backfacing camera |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 401 | * @see #open(int) |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 402 | */ |
| 403 | public static Camera open() { |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 404 | int numberOfCameras = getNumberOfCameras(); |
| 405 | CameraInfo cameraInfo = new CameraInfo(); |
| 406 | for (int i = 0; i < numberOfCameras; i++) { |
| 407 | getCameraInfo(i, cameraInfo); |
| 408 | if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { |
Wu-cheng Li | 7bc1b21 | 2012-04-19 12:23:31 +0800 | [diff] [blame] | 409 | return new Camera(i); |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | return null; |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 413 | } |
| 414 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 415 | /** |
| 416 | * Creates a new Camera object to access a particular hardware camera with |
| 417 | * given hal API version. If the same camera is opened by other applications |
| 418 | * or the hal API version is not supported by this device, this will throw a |
| 419 | * RuntimeException. |
| 420 | * <p> |
| 421 | * You must call {@link #release()} when you are done using the camera, |
| 422 | * otherwise it will remain locked and be unavailable to other applications. |
| 423 | * <p> |
| 424 | * Your application should only have one Camera object active at a time for |
| 425 | * a particular hardware camera. |
| 426 | * <p> |
| 427 | * Callbacks from other methods are delivered to the event loop of the |
| 428 | * thread which called open(). If this thread has no event loop, then |
| 429 | * callbacks are delivered to the main application event loop. If there is |
| 430 | * no main application event loop, callbacks are not delivered. |
| 431 | * <p class="caution"> |
| 432 | * <b>Caution:</b> On some devices, this method may take a long time to |
| 433 | * complete. It is best to call this method from a worker thread (possibly |
| 434 | * using {@link android.os.AsyncTask}) to avoid blocking the main |
| 435 | * application UI thread. |
| 436 | * |
| 437 | * @param cameraId The hardware camera to access, between 0 and |
| 438 | * {@link #getNumberOfCameras()}-1. |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 439 | * @param halVersion The HAL API version this camera device to be opened as. |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 440 | * @return a new Camera object, connected, locked and ready for use. |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 441 | * |
| 442 | * @throws IllegalArgumentException if the {@code halVersion} is invalid |
| 443 | * |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 444 | * @throws RuntimeException if opening the camera fails (for example, if the |
| 445 | * camera is in use by another process or device policy manager has disabled |
| 446 | * the camera). |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 447 | * |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 448 | * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName) |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 449 | * @see #CAMERA_HAL_API_VERSION_1_0 |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 450 | * |
| 451 | * @hide |
| 452 | */ |
| 453 | public static Camera openLegacy(int cameraId, int halVersion) { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 454 | if (halVersion < CAMERA_HAL_API_VERSION_1_0) { |
| 455 | throw new IllegalArgumentException("Invalid HAL version " + halVersion); |
| 456 | } |
| 457 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 458 | return new Camera(cameraId, halVersion); |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Create a legacy camera object. |
| 463 | * |
| 464 | * @param cameraId The hardware camera to access, between 0 and |
| 465 | * {@link #getNumberOfCameras()}-1. |
| 466 | * @param halVersion The HAL API version this camera device to be opened as. |
| 467 | */ |
| 468 | private Camera(int cameraId, int halVersion) { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 469 | int err = cameraInitVersion(cameraId, halVersion); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 470 | if (checkInitErrors(err)) { |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 471 | if (err == -EACCES) { |
| 472 | throw new RuntimeException("Fail to connect to camera service"); |
| 473 | } else if (err == -ENODEV) { |
| 474 | throw new RuntimeException("Camera initialization failed"); |
| 475 | } else if (err == -ENOSYS) { |
| 476 | throw new RuntimeException("Camera initialization failed because some methods" |
| 477 | + " are not implemented"); |
| 478 | } else if (err == -EOPNOTSUPP) { |
| 479 | throw new RuntimeException("Camera initialization failed because the hal" |
| 480 | + " version is not supported by this device"); |
| 481 | } else if (err == -EINVAL) { |
| 482 | throw new RuntimeException("Camera initialization failed because the input" |
| 483 | + " arugments are invalid"); |
| 484 | } else if (err == -EBUSY) { |
| 485 | throw new RuntimeException("Camera initialization failed because the camera" |
| 486 | + " device was already opened"); |
| 487 | } else if (err == -EUSERS) { |
| 488 | throw new RuntimeException("Camera initialization failed because the max" |
| 489 | + " number of camera devices were already opened"); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 490 | } |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 491 | // Should never hit this. |
| 492 | throw new RuntimeException("Unknown camera error"); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 496 | private int cameraInitVersion(int cameraId, int halVersion) { |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 497 | mShutterCallback = null; |
| 498 | mRawImageCallback = null; |
| 499 | mJpegCallback = null; |
| 500 | mPreviewCallback = null; |
| 501 | mPostviewCallback = null; |
| 502 | mUsingPreviewAllocation = false; |
| 503 | mZoomListener = null; |
| 504 | |
| 505 | Looper looper; |
| 506 | if ((looper = Looper.myLooper()) != null) { |
| 507 | mEventHandler = new EventHandler(this, looper); |
| 508 | } else if ((looper = Looper.getMainLooper()) != null) { |
| 509 | mEventHandler = new EventHandler(this, looper); |
| 510 | } else { |
| 511 | mEventHandler = null; |
| 512 | } |
| 513 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 514 | return native_setup(new WeakReference<Camera>(this), cameraId, halVersion, |
| 515 | ActivityThread.currentOpPackageName()); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 518 | private int cameraInitNormal(int cameraId) { |
| 519 | return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT); |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * Connect to the camera service using #connectLegacy |
| 524 | * |
| 525 | * <p> |
| 526 | * This acts the same as normal except that it will return |
| 527 | * the detailed error code if open fails instead of |
| 528 | * converting everything into {@code NO_INIT}.</p> |
| 529 | * |
| 530 | * <p>Intended to use by the camera2 shim only, do <i>not</i> use this for other code.</p> |
| 531 | * |
| 532 | * @return a detailed errno error code, or {@code NO_ERROR} on success |
| 533 | * |
| 534 | * @hide |
| 535 | */ |
| 536 | public int cameraInitUnspecified(int cameraId) { |
| 537 | return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_UNSPECIFIED); |
| 538 | } |
| 539 | |
| 540 | /** used by Camera#open, Camera#open(int) */ |
Wu-cheng Li | 7bc1b21 | 2012-04-19 12:23:31 +0800 | [diff] [blame] | 541 | Camera(int cameraId) { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 542 | int err = cameraInitNormal(cameraId); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 543 | if (checkInitErrors(err)) { |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 544 | if (err == -EACCES) { |
| 545 | throw new RuntimeException("Fail to connect to camera service"); |
| 546 | } else if (err == -ENODEV) { |
| 547 | throw new RuntimeException("Camera initialization failed"); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 548 | } |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 549 | // Should never hit this. |
| 550 | throw new RuntimeException("Unknown camera error"); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 551 | } |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 552 | initAppOps(); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 555 | |
| 556 | /** |
| 557 | * @hide |
| 558 | */ |
| 559 | public static boolean checkInitErrors(int err) { |
| 560 | return err != NO_ERROR; |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * @hide |
| 565 | */ |
| 566 | public static Camera openUninitialized() { |
| 567 | return new Camera(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 569 | |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 570 | /** |
| 571 | * An empty Camera for testing purpose. |
| 572 | */ |
| 573 | Camera() { |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 574 | initAppOps(); |
| 575 | } |
| 576 | |
| 577 | private void initAppOps() { |
| 578 | IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE); |
| 579 | mAppOps = IAppOpsService.Stub.asInterface(b); |
| 580 | // initialize mHasAppOpsPlayAudio |
| 581 | updateAppOpsPlayAudio(); |
| 582 | // register a callback to monitor whether the OP_PLAY_AUDIO is still allowed |
| 583 | mAppOpsCallback = new IAppOpsCallbackWrapper(this); |
| 584 | try { |
| 585 | mAppOps.startWatchingMode(AppOpsManager.OP_PLAY_AUDIO, |
| 586 | ActivityThread.currentPackageName(), mAppOpsCallback); |
| 587 | } catch (RemoteException e) { |
| 588 | Log.e(TAG, "Error registering appOps callback", e); |
| 589 | mHasAppOpsPlayAudio = false; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | private void releaseAppOps() { |
| 594 | try { |
| 595 | if (mAppOps != null) { |
| 596 | mAppOps.stopWatchingMode(mAppOpsCallback); |
| 597 | } |
| 598 | } catch (Exception e) { |
| 599 | // nothing to do here, the object is supposed to be released anyway |
| 600 | } |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 601 | } |
| 602 | |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 603 | @Override |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 604 | protected void finalize() { |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 605 | release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 607 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 608 | private native final int native_setup(Object camera_this, int cameraId, int halVersion, |
Eino-Ville Talvala | 788717c | 2013-02-15 18:30:15 -0800 | [diff] [blame] | 609 | String packageName); |
| 610 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | private native final void native_release(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | |
| 614 | /** |
| 615 | * Disconnects and releases the Camera object resources. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 616 | * |
| 617 | * <p>You must call this as soon as you're done with the Camera object.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 619 | public final void release() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | native_release(); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 621 | mFaceDetectionRunning = false; |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 622 | releaseAppOps(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 626 | * Unlocks the camera to allow another process to access it. |
| 627 | * Normally, the camera is locked to the process with an active Camera |
| 628 | * object until {@link #release()} is called. To allow rapid handoff |
| 629 | * between processes, you can call this method to release the camera |
| 630 | * temporarily for another process to use; once the other process is done |
| 631 | * you can call {@link #reconnect()} to reclaim the camera. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 633 | * <p>This must be done before calling |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 634 | * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be |
| 635 | * called after recording starts. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 637 | * <p>If you are not recording video, you probably do not need this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 639 | * @throws RuntimeException if the camera cannot be unlocked. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | */ |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 641 | public native final void unlock(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 644 | * Re-locks the camera to prevent other processes from accessing it. |
| 645 | * Camera objects are locked by default unless {@link #unlock()} is |
| 646 | * called. Normally {@link #reconnect()} is used instead. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 647 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 648 | * <p>Since API level 14, camera is automatically locked for applications in |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 649 | * {@link android.media.MediaRecorder#start()}. Applications can use the |
| 650 | * camera (ex: zoom) after recording starts. There is no need to call this |
| 651 | * after recording starts or stops. |
| 652 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 653 | * <p>If you are not recording video, you probably do not need this method. |
| 654 | * |
| 655 | * @throws RuntimeException if the camera cannot be re-locked (for |
| 656 | * example, if the camera is still in use by another process). |
| 657 | */ |
| 658 | public native final void lock(); |
| 659 | |
| 660 | /** |
| 661 | * Reconnects to the camera service after another process used it. |
| 662 | * After {@link #unlock()} is called, another process may use the |
| 663 | * camera; when the process is done, you must reconnect to the camera, |
| 664 | * which will re-acquire the lock and allow you to continue using the |
| 665 | * camera. |
| 666 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 667 | * <p>Since API level 14, camera is automatically locked for applications in |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 668 | * {@link android.media.MediaRecorder#start()}. Applications can use the |
| 669 | * camera (ex: zoom) after recording starts. There is no need to call this |
| 670 | * after recording starts or stops. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 671 | * |
| 672 | * <p>If you are not recording video, you probably do not need this method. |
| 673 | * |
| 674 | * @throws IOException if a connection cannot be re-established (for |
| 675 | * example, if the camera is still in use by another process). |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 676 | * @throws RuntimeException if release() has been called on this Camera |
| 677 | * instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 678 | */ |
| 679 | public native final void reconnect() throws IOException; |
| 680 | |
| 681 | /** |
| 682 | * Sets the {@link Surface} to be used for live preview. |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 683 | * Either a surface or surface texture is necessary for preview, and |
| 684 | * preview is necessary to take pictures. The same surface can be re-set |
| 685 | * without harm. Setting a preview surface will un-set any preview surface |
| 686 | * texture that was set via {@link #setPreviewTexture}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 687 | * |
| 688 | * <p>The {@link SurfaceHolder} must already contain a surface when this |
| 689 | * method is called. If you are using {@link android.view.SurfaceView}, |
| 690 | * you will need to register a {@link SurfaceHolder.Callback} with |
| 691 | * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for |
| 692 | * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before |
| 693 | * calling setPreviewDisplay() or starting preview. |
| 694 | * |
| 695 | * <p>This method must be called before {@link #startPreview()}. The |
| 696 | * one exception is that if the preview surface is not set (or set to null) |
| 697 | * before startPreview() is called, then this method may be called once |
| 698 | * with a non-null parameter to set the preview surface. (This allows |
| 699 | * camera setup and surface creation to happen in parallel, saving time.) |
| 700 | * The preview surface may not otherwise change while preview is running. |
| 701 | * |
| 702 | * @param holder containing the Surface on which to place the preview, |
| 703 | * or null to remove the preview surface |
| 704 | * @throws IOException if the method fails (for example, if the surface |
| 705 | * is unavailable or unsuitable). |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 706 | * @throws RuntimeException if release() has been called on this Camera |
| 707 | * instance. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | */ |
| 709 | public final void setPreviewDisplay(SurfaceHolder holder) throws IOException { |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 710 | if (holder != null) { |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 711 | setPreviewSurface(holder.getSurface()); |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 712 | } else { |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 713 | setPreviewSurface((Surface)null); |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 714 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | } |
| 716 | |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 717 | /** |
| 718 | * @hide |
| 719 | */ |
| 720 | public native final void setPreviewSurface(Surface surface) throws IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | |
| 722 | /** |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 723 | * Sets the {@link SurfaceTexture} to be used for live preview. |
| 724 | * Either a surface or surface texture is necessary for preview, and |
| 725 | * preview is necessary to take pictures. The same surface texture can be |
| 726 | * re-set without harm. Setting a preview surface texture will un-set any |
| 727 | * preview surface that was set via {@link #setPreviewDisplay}. |
| 728 | * |
| 729 | * <p>This method must be called before {@link #startPreview()}. The |
| 730 | * one exception is that if the preview surface texture is not set (or set |
| 731 | * to null) before startPreview() is called, then this method may be called |
| 732 | * once with a non-null parameter to set the preview surface. (This allows |
| 733 | * camera setup and surface creation to happen in parallel, saving time.) |
| 734 | * The preview surface texture may not otherwise change while preview is |
| 735 | * running. |
| 736 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 737 | * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a |
Eino-Ville Talvala | e309a0f | 2011-03-21 11:04:34 -0700 | [diff] [blame] | 738 | * SurfaceTexture set as the preview texture have an unspecified zero point, |
| 739 | * and cannot be directly compared between different cameras or different |
| 740 | * instances of the same camera, or across multiple runs of the same |
| 741 | * program. |
| 742 | * |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 743 | * <p>If you are using the preview data to create video or still images, |
| 744 | * strongly consider using {@link android.media.MediaActionSound} to |
| 745 | * properly indicate image capture or recording start/stop to the user.</p> |
| 746 | * |
| 747 | * @see android.media.MediaActionSound |
| 748 | * @see android.graphics.SurfaceTexture |
| 749 | * @see android.view.TextureView |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 750 | * @param surfaceTexture the {@link SurfaceTexture} to which the preview |
| 751 | * images are to be sent or null to remove the current preview surface |
| 752 | * texture |
| 753 | * @throws IOException if the method fails (for example, if the surface |
| 754 | * texture is unavailable or unsuitable). |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 755 | * @throws RuntimeException if release() has been called on this Camera |
| 756 | * instance. |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 757 | */ |
Glenn Kasten | dbc289d | 2011-02-09 10:15:44 -0800 | [diff] [blame] | 758 | public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException; |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 759 | |
| 760 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 761 | * Callback interface used to deliver copies of preview frames as |
| 762 | * they are displayed. |
| 763 | * |
| 764 | * @see #setPreviewCallback(Camera.PreviewCallback) |
| 765 | * @see #setOneShotPreviewCallback(Camera.PreviewCallback) |
| 766 | * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) |
| 767 | * @see #startPreview() |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 768 | * |
| 769 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 770 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 772 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 773 | public interface PreviewCallback |
| 774 | { |
| 775 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 776 | * Called as preview frames are displayed. This callback is invoked |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 777 | * on the event thread {@link #open(int)} was called from. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 779 | * <p>If using the {@link android.graphics.ImageFormat#YV12} format, |
| 780 | * refer to the equations in {@link Camera.Parameters#setPreviewFormat} |
| 781 | * for the arrangement of the pixel data in the preview callback |
| 782 | * buffers. |
| 783 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 784 | * @param data the contents of the preview frame in the format defined |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 785 | * by {@link android.graphics.ImageFormat}, which can be queried |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 786 | * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 787 | * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 788 | * is never called, the default will be the YCbCr_420_SP |
| 789 | * (NV21) format. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 790 | * @param camera the Camera service object. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | */ |
| 792 | void onPreviewFrame(byte[] data, Camera camera); |
| 793 | }; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 796 | * Starts capturing and drawing preview frames to the screen. |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 797 | * Preview will not actually start until a surface is supplied |
| 798 | * with {@link #setPreviewDisplay(SurfaceHolder)} or |
| 799 | * {@link #setPreviewTexture(SurfaceTexture)}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 800 | * |
| 801 | * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)}, |
| 802 | * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or |
| 803 | * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were |
| 804 | * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)} |
| 805 | * will be called when preview data becomes available. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 806 | * |
| 807 | * @throws RuntimeException if starting preview fails; usually this would be |
| 808 | * because of a hardware or other low-level error, or because release() |
| 809 | * has been called on this Camera instance. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 810 | */ |
| 811 | public native final void startPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 814 | * Stops capturing and drawing preview frames to the surface, and |
| 815 | * resets the camera for a future call to {@link #startPreview()}. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 816 | * |
| 817 | * @throws RuntimeException if stopping preview fails; usually this would be |
| 818 | * because of a hardware or other low-level error, or because release() |
| 819 | * has been called on this Camera instance. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | */ |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 821 | public final void stopPreview() { |
| 822 | _stopPreview(); |
| 823 | mFaceDetectionRunning = false; |
Chih-yu Huang | 664d72e | 2011-09-23 18:59:38 +0800 | [diff] [blame] | 824 | |
| 825 | mShutterCallback = null; |
| 826 | mRawImageCallback = null; |
| 827 | mPostviewCallback = null; |
| 828 | mJpegCallback = null; |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 829 | synchronized (mAutoFocusCallbackLock) { |
| 830 | mAutoFocusCallback = null; |
| 831 | } |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 832 | mAutoFocusMoveCallback = null; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | private native final void _stopPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 836 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | /** |
| 838 | * Return current preview state. |
| 839 | * |
| 840 | * FIXME: Unhide before release |
| 841 | * @hide |
| 842 | */ |
| 843 | public native final boolean previewEnabled(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 845 | /** |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 846 | * <p>Installs a callback to be invoked for every preview frame in addition |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 847 | * to displaying them on the screen. The callback will be repeatedly called |
| 848 | * for as long as preview is active. This method can be called at any time, |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 849 | * even while preview is live. Any other preview callbacks are |
| 850 | * overridden.</p> |
| 851 | * |
| 852 | * <p>If you are using the preview data to create video or still images, |
| 853 | * strongly consider using {@link android.media.MediaActionSound} to |
| 854 | * properly indicate image capture or recording start/stop to the user.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 856 | * @param cb a callback object that receives a copy of each preview frame, |
| 857 | * or null to stop receiving callbacks. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 858 | * @throws RuntimeException if release() has been called on this Camera |
| 859 | * instance. |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 860 | * @see android.media.MediaActionSound |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | */ |
| 862 | public final void setPreviewCallback(PreviewCallback cb) { |
| 863 | mPreviewCallback = cb; |
| 864 | mOneShot = false; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 865 | mWithBuffer = false; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 866 | if (cb != null) { |
| 867 | mUsingPreviewAllocation = false; |
| 868 | } |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 869 | // Always use one-shot mode. We fake camera preview mode by |
| 870 | // doing one-shot preview continuously. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 871 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /** |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 875 | * <p>Installs a callback to be invoked for the next preview frame in |
| 876 | * addition to displaying it on the screen. After one invocation, the |
| 877 | * callback is cleared. This method can be called any time, even when |
| 878 | * preview is live. Any other preview callbacks are overridden.</p> |
| 879 | * |
| 880 | * <p>If you are using the preview data to create video or still images, |
| 881 | * strongly consider using {@link android.media.MediaActionSound} to |
| 882 | * properly indicate image capture or recording start/stop to the user.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 884 | * @param cb a callback object that receives a copy of the next preview frame, |
| 885 | * or null to stop receiving callbacks. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 886 | * @throws RuntimeException if release() has been called on this Camera |
| 887 | * instance. |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 888 | * @see android.media.MediaActionSound |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | */ |
| 890 | public final void setOneShotPreviewCallback(PreviewCallback cb) { |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 891 | mPreviewCallback = cb; |
| 892 | mOneShot = true; |
| 893 | mWithBuffer = false; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 894 | if (cb != null) { |
| 895 | mUsingPreviewAllocation = false; |
| 896 | } |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 897 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | } |
| 899 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 900 | private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer); |
| 901 | |
| 902 | /** |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 903 | * <p>Installs a callback to be invoked for every preview frame, using |
| 904 | * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 905 | * displaying them on the screen. The callback will be repeatedly called |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 906 | * for as long as preview is active and buffers are available. Any other |
| 907 | * preview callbacks are overridden.</p> |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 908 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 909 | * <p>The purpose of this method is to improve preview efficiency and frame |
| 910 | * rate by allowing preview frame memory reuse. You must call |
| 911 | * {@link #addCallbackBuffer(byte[])} at some point -- before or after |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 912 | * calling this method -- or no callbacks will received.</p> |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 913 | * |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 914 | * <p>The buffer queue will be cleared if this method is called with a null |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 915 | * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called, |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 916 | * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is |
| 917 | * called.</p> |
| 918 | * |
| 919 | * <p>If you are using the preview data to create video or still images, |
| 920 | * strongly consider using {@link android.media.MediaActionSound} to |
| 921 | * properly indicate image capture or recording start/stop to the user.</p> |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 922 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 923 | * @param cb a callback object that receives a copy of the preview frame, |
| 924 | * or null to stop receiving callbacks and clear the buffer queue. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 925 | * @throws RuntimeException if release() has been called on this Camera |
| 926 | * instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 927 | * @see #addCallbackBuffer(byte[]) |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 928 | * @see android.media.MediaActionSound |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 929 | */ |
| 930 | public final void setPreviewCallbackWithBuffer(PreviewCallback cb) { |
| 931 | mPreviewCallback = cb; |
| 932 | mOneShot = false; |
| 933 | mWithBuffer = true; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 934 | if (cb != null) { |
| 935 | mUsingPreviewAllocation = false; |
| 936 | } |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 937 | setHasPreviewCallback(cb != null, true); |
| 938 | } |
| 939 | |
| 940 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 941 | * Adds a pre-allocated buffer to the preview callback buffer queue. |
| 942 | * Applications can add one or more buffers to the queue. When a preview |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 943 | * frame arrives and there is still at least one available buffer, the |
| 944 | * buffer will be used and removed from the queue. Then preview callback is |
| 945 | * invoked with the buffer. If a frame arrives and there is no buffer left, |
| 946 | * the frame is discarded. Applications should add buffers back when they |
| 947 | * finish processing the data in them. |
Wu-cheng Li | c10275a | 2010-03-09 13:49:21 -0800 | [diff] [blame] | 948 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 949 | * <p>For formats besides YV12, the size of the buffer is determined by |
| 950 | * multiplying the preview image width, height, and bytes per pixel. The |
| 951 | * width and height can be read from |
| 952 | * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be |
| 953 | * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / |
| 954 | * 8, using the image format from |
| 955 | * {@link Camera.Parameters#getPreviewFormat()}. |
| 956 | * |
| 957 | * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the |
| 958 | * size can be calculated using the equations listed in |
| 959 | * {@link Camera.Parameters#setPreviewFormat}. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 960 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 961 | * <p>This method is only necessary when |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 962 | * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 963 | * {@link #setPreviewCallback(PreviewCallback)} or |
| 964 | * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 965 | * are automatically allocated. When a supplied buffer is too small to |
| 966 | * hold the preview frame data, preview callback will return null and |
| 967 | * the buffer will be removed from the buffer queue. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 968 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 969 | * @param callbackBuffer the buffer to add to the queue. The size of the |
| 970 | * buffer must match the values described above. |
Wu-cheng Li | 5b9bcda | 2010-03-07 14:59:28 -0800 | [diff] [blame] | 971 | * @see #setPreviewCallbackWithBuffer(PreviewCallback) |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 972 | */ |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 973 | public final void addCallbackBuffer(byte[] callbackBuffer) |
| 974 | { |
| 975 | _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME); |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * Adds a pre-allocated buffer to the raw image callback buffer queue. |
| 980 | * Applications can add one or more buffers to the queue. When a raw image |
| 981 | * frame arrives and there is still at least one available buffer, the |
| 982 | * buffer will be used to hold the raw image data and removed from the |
| 983 | * queue. Then raw image callback is invoked with the buffer. If a raw |
| 984 | * image frame arrives but there is no buffer left, the frame is |
| 985 | * discarded. Applications should add buffers back when they finish |
| 986 | * processing the data in them by calling this method again in order |
| 987 | * to avoid running out of raw image callback buffers. |
| 988 | * |
| 989 | * <p>The size of the buffer is determined by multiplying the raw image |
| 990 | * width, height, and bytes per pixel. The width and height can be |
| 991 | * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel |
| 992 | * can be computed from |
| 993 | * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8, |
| 994 | * using the image format from {@link Camera.Parameters#getPreviewFormat()}. |
| 995 | * |
| 996 | * <p>This method is only necessary when the PictureCallbck for raw image |
| 997 | * is used while calling {@link #takePicture(Camera.ShutterCallback, |
| 998 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. |
| 999 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 1000 | * <p>Please note that by calling this method, the mode for |
| 1001 | * application-managed callback buffers is triggered. If this method has |
| 1002 | * never been called, null will be returned by the raw image callback since |
| 1003 | * there is no image callback buffer available. Furthermore, When a supplied |
| 1004 | * buffer is too small to hold the raw image data, raw image callback will |
| 1005 | * return null and the buffer will be removed from the buffer queue. |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1006 | * |
| 1007 | * @param callbackBuffer the buffer to add to the raw image callback buffer |
| 1008 | * queue. The size should be width * height * (bits per pixel) / 8. An |
| 1009 | * null callbackBuffer will be ignored and won't be added to the queue. |
| 1010 | * |
| 1011 | * @see #takePicture(Camera.ShutterCallback, |
| 1012 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. |
| 1013 | * |
| 1014 | * {@hide} |
| 1015 | */ |
| 1016 | public final void addRawImageCallbackBuffer(byte[] callbackBuffer) |
| 1017 | { |
| 1018 | addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE); |
| 1019 | } |
| 1020 | |
| 1021 | private final void addCallbackBuffer(byte[] callbackBuffer, int msgType) |
| 1022 | { |
| 1023 | // CAMERA_MSG_VIDEO_FRAME may be allowed in the future. |
| 1024 | if (msgType != CAMERA_MSG_PREVIEW_FRAME && |
| 1025 | msgType != CAMERA_MSG_RAW_IMAGE) { |
| 1026 | throw new IllegalArgumentException( |
| 1027 | "Unsupported message type: " + msgType); |
| 1028 | } |
| 1029 | |
| 1030 | _addCallbackBuffer(callbackBuffer, msgType); |
| 1031 | } |
| 1032 | |
| 1033 | private native final void _addCallbackBuffer( |
| 1034 | byte[] callbackBuffer, int msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 1036 | /** |
| 1037 | * <p>Create a {@link android.renderscript RenderScript} |
| 1038 | * {@link android.renderscript.Allocation Allocation} to use as a |
| 1039 | * destination of preview callback frames. Use |
| 1040 | * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use |
| 1041 | * the created Allocation as a destination for camera preview frames.</p> |
| 1042 | * |
| 1043 | * <p>The Allocation will be created with a YUV type, and its contents must |
| 1044 | * be accessed within Renderscript with the {@code rsGetElementAtYuv_*} |
| 1045 | * accessor methods. Its size will be based on the current |
| 1046 | * {@link Parameters#getPreviewSize preview size} configured for this |
| 1047 | * camera.</p> |
| 1048 | * |
| 1049 | * @param rs the RenderScript context for this Allocation. |
| 1050 | * @param usage additional usage flags to set for the Allocation. The usage |
| 1051 | * flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always |
| 1052 | * be set on the created Allocation, but additional flags may be provided |
| 1053 | * here. |
| 1054 | * @return a new YUV-type Allocation with dimensions equal to the current |
| 1055 | * preview size. |
| 1056 | * @throws RSIllegalArgumentException if the usage flags are not compatible |
| 1057 | * with an YUV Allocation. |
| 1058 | * @see #setPreviewCallbackAllocation |
| 1059 | * @hide |
| 1060 | */ |
| 1061 | public final Allocation createPreviewAllocation(RenderScript rs, int usage) |
| 1062 | throws RSIllegalArgumentException { |
| 1063 | Parameters p = getParameters(); |
| 1064 | Size previewSize = p.getPreviewSize(); |
| 1065 | Type.Builder yuvBuilder = new Type.Builder(rs, |
| 1066 | Element.createPixel(rs, |
| 1067 | Element.DataType.UNSIGNED_8, |
| 1068 | Element.DataKind.PIXEL_YUV)); |
| 1069 | // Use YV12 for wide compatibility. Changing this requires also |
| 1070 | // adjusting camera service's format selection. |
| 1071 | yuvBuilder.setYuvFormat(ImageFormat.YV12); |
| 1072 | yuvBuilder.setX(previewSize.width); |
| 1073 | yuvBuilder.setY(previewSize.height); |
| 1074 | |
| 1075 | Allocation a = Allocation.createTyped(rs, yuvBuilder.create(), |
| 1076 | usage | Allocation.USAGE_IO_INPUT); |
| 1077 | |
| 1078 | return a; |
| 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * <p>Set an {@link android.renderscript.Allocation Allocation} as the |
| 1083 | * target of preview callback data. Use this method for efficient processing |
| 1084 | * of camera preview data with RenderScript. The Allocation must be created |
| 1085 | * with the {@link #createPreviewAllocation createPreviewAllocation } |
| 1086 | * method.</p> |
| 1087 | * |
| 1088 | * <p>Setting a preview allocation will disable any active preview callbacks |
| 1089 | * set by {@link #setPreviewCallback setPreviewCallback} or |
| 1090 | * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and |
| 1091 | * vice versa. Using a preview allocation still requires an active standard |
| 1092 | * preview target to be set, either with |
| 1093 | * {@link #setPreviewTexture setPreviewTexture} or |
| 1094 | * {@link #setPreviewDisplay setPreviewDisplay}.</p> |
| 1095 | * |
| 1096 | * <p>To be notified when new frames are available to the Allocation, use |
| 1097 | * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To |
| 1098 | * update the frame currently accessible from the Allocation to the latest |
| 1099 | * preview frame, call |
| 1100 | * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p> |
| 1101 | * |
| 1102 | * <p>To disable preview into the Allocation, call this method with a |
| 1103 | * {@code null} parameter.</p> |
| 1104 | * |
| 1105 | * <p>Once a preview allocation is set, the preview size set by |
| 1106 | * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If |
| 1107 | * you wish to change the preview size, first remove the preview allocation |
| 1108 | * by calling {@code setPreviewCallbackAllocation(null)}, then change the |
| 1109 | * preview size, create a new preview Allocation with |
| 1110 | * {@link #createPreviewAllocation createPreviewAllocation}, and set it as |
| 1111 | * the new preview callback allocation target.</p> |
| 1112 | * |
| 1113 | * <p>If you are using the preview data to create video or still images, |
| 1114 | * strongly consider using {@link android.media.MediaActionSound} to |
| 1115 | * properly indicate image capture or recording start/stop to the user.</p> |
| 1116 | * |
| 1117 | * @param previewAllocation the allocation to use as destination for preview |
| 1118 | * @throws IOException if configuring the camera to use the Allocation for |
| 1119 | * preview fails. |
| 1120 | * @throws IllegalArgumentException if the Allocation's dimensions or other |
| 1121 | * parameters don't meet the requirements. |
| 1122 | * @see #createPreviewAllocation |
| 1123 | * @see #setPreviewCallback |
| 1124 | * @see #setPreviewCallbackWithBuffer |
| 1125 | * @hide |
| 1126 | */ |
| 1127 | public final void setPreviewCallbackAllocation(Allocation previewAllocation) |
| 1128 | throws IOException { |
| 1129 | Surface previewSurface = null; |
| 1130 | if (previewAllocation != null) { |
| 1131 | Parameters p = getParameters(); |
| 1132 | Size previewSize = p.getPreviewSize(); |
| 1133 | if (previewSize.width != previewAllocation.getType().getX() || |
| 1134 | previewSize.height != previewAllocation.getType().getY()) { |
| 1135 | throw new IllegalArgumentException( |
| 1136 | "Allocation dimensions don't match preview dimensions: " + |
| 1137 | "Allocation is " + |
| 1138 | previewAllocation.getType().getX() + |
| 1139 | ", " + |
| 1140 | previewAllocation.getType().getY() + |
| 1141 | ". Preview is " + previewSize.width + ", " + |
| 1142 | previewSize.height); |
| 1143 | } |
| 1144 | if ((previewAllocation.getUsage() & |
| 1145 | Allocation.USAGE_IO_INPUT) == 0) { |
| 1146 | throw new IllegalArgumentException( |
| 1147 | "Allocation usage does not include USAGE_IO_INPUT"); |
| 1148 | } |
| 1149 | if (previewAllocation.getType().getElement().getDataKind() != |
| 1150 | Element.DataKind.PIXEL_YUV) { |
| 1151 | throw new IllegalArgumentException( |
| 1152 | "Allocation is not of a YUV type"); |
| 1153 | } |
| 1154 | previewSurface = previewAllocation.getSurface(); |
| 1155 | mUsingPreviewAllocation = true; |
| 1156 | } else { |
| 1157 | mUsingPreviewAllocation = false; |
| 1158 | } |
| 1159 | setPreviewCallbackSurface(previewSurface); |
| 1160 | } |
| 1161 | |
| 1162 | private native final void setPreviewCallbackSurface(Surface s); |
| 1163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1164 | private class EventHandler extends Handler |
| 1165 | { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 1166 | private final Camera mCamera; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | |
| 1168 | public EventHandler(Camera c, Looper looper) { |
| 1169 | super(looper); |
| 1170 | mCamera = c; |
| 1171 | } |
| 1172 | |
| 1173 | @Override |
| 1174 | public void handleMessage(Message msg) { |
| 1175 | switch(msg.what) { |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1176 | case CAMERA_MSG_SHUTTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | if (mShutterCallback != null) { |
| 1178 | mShutterCallback.onShutter(); |
| 1179 | } |
| 1180 | return; |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1181 | |
| 1182 | case CAMERA_MSG_RAW_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1183 | if (mRawImageCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1185 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | return; |
| 1187 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1188 | case CAMERA_MSG_COMPRESSED_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1189 | if (mJpegCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1191 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | return; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1193 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1194 | case CAMERA_MSG_PREVIEW_FRAME: |
Eino-Ville Talvala | ca367b7 | 2012-05-30 16:01:33 -0700 | [diff] [blame] | 1195 | PreviewCallback pCb = mPreviewCallback; |
| 1196 | if (pCb != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | if (mOneShot) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 1198 | // Clear the callback variable before the callback |
| 1199 | // in case the app calls setPreviewCallback from |
| 1200 | // the callback function |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | mPreviewCallback = null; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 1202 | } else if (!mWithBuffer) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 1203 | // We're faking the camera preview mode to prevent |
| 1204 | // the app from being flooded with preview frames. |
| 1205 | // Set to oneshot mode again. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 1206 | setHasPreviewCallback(true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | } |
Eino-Ville Talvala | ca367b7 | 2012-05-30 16:01:33 -0700 | [diff] [blame] | 1208 | pCb.onPreviewFrame((byte[])msg.obj, mCamera); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | } |
| 1210 | return; |
| 1211 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1212 | case CAMERA_MSG_POSTVIEW_FRAME: |
| 1213 | if (mPostviewCallback != null) { |
| 1214 | mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera); |
| 1215 | } |
| 1216 | return; |
| 1217 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1218 | case CAMERA_MSG_FOCUS: |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1219 | AutoFocusCallback cb = null; |
| 1220 | synchronized (mAutoFocusCallbackLock) { |
| 1221 | cb = mAutoFocusCallback; |
| 1222 | } |
| 1223 | if (cb != null) { |
| 1224 | boolean success = msg.arg1 == 0 ? false : true; |
| 1225 | cb.onAutoFocus(success, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1226 | } |
| 1227 | return; |
| 1228 | |
| 1229 | case CAMERA_MSG_ZOOM: |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1230 | if (mZoomListener != null) { |
| 1231 | mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1232 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | return; |
| 1234 | |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1235 | case CAMERA_MSG_PREVIEW_METADATA: |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1236 | if (mFaceListener != null) { |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1237 | mFaceListener.onFaceDetection((Face[])msg.obj, mCamera); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1238 | } |
| 1239 | return; |
| 1240 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1241 | case CAMERA_MSG_ERROR : |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | Log.e(TAG, "Error " + msg.arg1); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1243 | if (mErrorCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | mErrorCallback.onError(msg.arg1, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | return; |
| 1247 | |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1248 | case CAMERA_MSG_FOCUS_MOVE: |
| 1249 | if (mAutoFocusMoveCallback != null) { |
| 1250 | mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera); |
| 1251 | } |
| 1252 | return; |
| 1253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1254 | default: |
| 1255 | Log.e(TAG, "Unknown message type " + msg.what); |
| 1256 | return; |
| 1257 | } |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | private static void postEventFromNative(Object camera_ref, |
| 1262 | int what, int arg1, int arg2, Object obj) |
| 1263 | { |
| 1264 | Camera c = (Camera)((WeakReference)camera_ref).get(); |
| 1265 | if (c == null) |
| 1266 | return; |
| 1267 | |
| 1268 | if (c.mEventHandler != null) { |
| 1269 | Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); |
| 1270 | c.mEventHandler.sendMessage(m); |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1275 | * Callback interface used to notify on completion of camera auto focus. |
| 1276 | * |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1277 | * <p>Devices that do not support auto-focus will receive a "fake" |
| 1278 | * callback to this interface. If your application needs auto-focus and |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1279 | * should not be installed on devices <em>without</em> auto-focus, you must |
| 1280 | * declare that your app uses the |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1281 | * {@code android.hardware.camera.autofocus} feature, in the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1282 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 1283 | * manifest element.</p> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1284 | * |
| 1285 | * @see #autoFocus(AutoFocusCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1286 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1287 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1289 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | public interface AutoFocusCallback |
| 1291 | { |
| 1292 | /** |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1293 | * Called when the camera auto focus completes. If the camera |
| 1294 | * does not support auto-focus and autoFocus is called, |
| 1295 | * onAutoFocus will be called immediately with a fake value of |
| 1296 | * <code>success</code> set to <code>true</code>. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1297 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 1298 | * The auto-focus routine does not lock auto-exposure and auto-white |
| 1299 | * balance after it completes. |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1300 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | * @param success true if focus was successful, false if otherwise |
| 1302 | * @param camera the Camera service object |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1303 | * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) |
| 1304 | * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1305 | */ |
| 1306 | void onAutoFocus(boolean success, Camera camera); |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1307 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | |
| 1309 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1310 | * Starts camera auto-focus and registers a callback function to run when |
| 1311 | * the camera is focused. This method is only valid when preview is active |
| 1312 | * (between {@link #startPreview()} and before {@link #stopPreview()}). |
| 1313 | * |
| 1314 | * <p>Callers should check |
| 1315 | * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if |
| 1316 | * this method should be called. If the camera does not support auto-focus, |
| 1317 | * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)} |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1318 | * callback will be called immediately. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1319 | * |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 1320 | * <p>If your application should not be installed |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1321 | * on devices without auto-focus, you must declare that your application |
| 1322 | * uses auto-focus with the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1323 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 1324 | * manifest element.</p> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1325 | * |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 1326 | * <p>If the current flash mode is not |
| 1327 | * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1328 | * fired during auto-focus, depending on the driver and camera hardware.<p> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1329 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1330 | * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()} |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 1331 | * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()} |
| 1332 | * do not change during and after autofocus. But auto-focus routine may stop |
| 1333 | * auto-exposure and auto-white balance transiently during focusing. |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1334 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1335 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 1336 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
| 1337 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 1338 | * the focus position. Applications must call cancelAutoFocus to reset the |
| 1339 | * focus.</p> |
| 1340 | * |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 1341 | * <p>If autofocus is successful, consider using |
| 1342 | * {@link android.media.MediaActionSound} to properly play back an autofocus |
| 1343 | * success sound to the user.</p> |
| 1344 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1345 | * @param cb the callback to run |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1346 | * @throws RuntimeException if starting autofocus fails; usually this would |
| 1347 | * be because of a hardware or other low-level error, or because |
| 1348 | * release() has been called on this Camera instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1349 | * @see #cancelAutoFocus() |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1350 | * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) |
| 1351 | * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 1352 | * @see android.media.MediaActionSound |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | */ |
| 1354 | public final void autoFocus(AutoFocusCallback cb) |
| 1355 | { |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1356 | synchronized (mAutoFocusCallbackLock) { |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1357 | mAutoFocusCallback = cb; |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1358 | } |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1359 | native_autoFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1360 | } |
| 1361 | private native final void native_autoFocus(); |
| 1362 | |
| 1363 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1364 | * Cancels any auto-focus function in progress. |
| 1365 | * Whether or not auto-focus is currently in progress, |
| 1366 | * this function will return the focus position to the default. |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 1367 | * If the camera does not support auto-focus, this is a no-op. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1368 | * |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1369 | * @throws RuntimeException if canceling autofocus fails; usually this would |
| 1370 | * be because of a hardware or other low-level error, or because |
| 1371 | * release() has been called on this Camera instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1372 | * @see #autoFocus(Camera.AutoFocusCallback) |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 1373 | */ |
| 1374 | public final void cancelAutoFocus() |
| 1375 | { |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1376 | synchronized (mAutoFocusCallbackLock) { |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1377 | mAutoFocusCallback = null; |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1378 | } |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1379 | native_cancelAutoFocus(); |
| 1380 | // CAMERA_MSG_FOCUS should be removed here because the following |
| 1381 | // scenario can happen: |
| 1382 | // - An application uses the same thread for autoFocus, cancelAutoFocus |
| 1383 | // and looper thread. |
| 1384 | // - The application calls autoFocus. |
| 1385 | // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue. |
| 1386 | // Before event handler's handleMessage() is invoked, the application |
| 1387 | // calls cancelAutoFocus and autoFocus. |
| 1388 | // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus |
| 1389 | // has been completed. But in fact it is not. |
| 1390 | // |
| 1391 | // As documented in the beginning of the file, apps should not use |
| 1392 | // multiple threads to call autoFocus and cancelAutoFocus at the same |
| 1393 | // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS |
| 1394 | // message after native_cancelAutoFocus is called. |
| 1395 | mEventHandler.removeMessages(CAMERA_MSG_FOCUS); |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 1396 | } |
| 1397 | private native final void native_cancelAutoFocus(); |
| 1398 | |
| 1399 | /** |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1400 | * Callback interface used to notify on auto focus start and stop. |
| 1401 | * |
Wu-cheng Li | 6574539 | 2012-04-12 18:07:16 +0800 | [diff] [blame] | 1402 | * <p>This is only supported in continuous autofocus modes -- {@link |
| 1403 | * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link |
| 1404 | * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show |
| 1405 | * autofocus animation based on this.</p> |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1406 | * |
| 1407 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1408 | * applications. |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1409 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1410 | @Deprecated |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1411 | public interface AutoFocusMoveCallback |
| 1412 | { |
| 1413 | /** |
| 1414 | * Called when the camera auto focus starts or stops. |
| 1415 | * |
| 1416 | * @param start true if focus starts to move, false if focus stops to move |
Wu-cheng Li | 6574539 | 2012-04-12 18:07:16 +0800 | [diff] [blame] | 1417 | * @param camera the Camera service object |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1418 | */ |
| 1419 | void onAutoFocusMoving(boolean start, Camera camera); |
| 1420 | } |
| 1421 | |
| 1422 | /** |
| 1423 | * Sets camera auto-focus move callback. |
| 1424 | * |
| 1425 | * @param cb the callback to run |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1426 | * @throws RuntimeException if enabling the focus move callback fails; |
| 1427 | * usually this would be because of a hardware or other low-level error, |
| 1428 | * or because release() has been called on this Camera instance. |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1429 | */ |
| 1430 | public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) { |
| 1431 | mAutoFocusMoveCallback = cb; |
| 1432 | enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0); |
| 1433 | } |
| 1434 | |
| 1435 | private native void enableFocusMoveCallback(int enable); |
| 1436 | |
| 1437 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1438 | * Callback interface used to signal the moment of actual image capture. |
| 1439 | * |
| 1440 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1441 | * |
| 1442 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1443 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1445 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | public interface ShutterCallback |
| 1447 | { |
| 1448 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1449 | * Called as near as possible to the moment when a photo is captured |
| 1450 | * from the sensor. This is a good opportunity to play a shutter sound |
| 1451 | * or give other feedback of camera operation. This may be some time |
| 1452 | * after the photo was triggered, but some time before the actual data |
| 1453 | * is available. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | */ |
| 1455 | void onShutter(); |
| 1456 | } |
| 1457 | |
| 1458 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1459 | * Callback interface used to supply image data from a photo capture. |
| 1460 | * |
| 1461 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1462 | * |
| 1463 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1464 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1465 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1466 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | public interface PictureCallback { |
| 1468 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1469 | * Called when image data is available after a picture is taken. |
| 1470 | * The format of the data depends on the context of the callback |
| 1471 | * and {@link Camera.Parameters} settings. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1472 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | * @param data a byte array of the picture data |
| 1474 | * @param camera the Camera service object |
| 1475 | */ |
| 1476 | void onPictureTaken(byte[] data, Camera camera); |
| 1477 | }; |
| 1478 | |
| 1479 | /** |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1480 | * Equivalent to <pre>takePicture(Shutter, raw, null, jpeg)</pre>. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1481 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1482 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | */ |
| 1484 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 1485 | PictureCallback jpeg) { |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1486 | takePicture(shutter, raw, null, jpeg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | } |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1488 | private native final void native_takePicture(int msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1490 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1491 | * Triggers an asynchronous image capture. The camera service will initiate |
| 1492 | * a series of callbacks to the application as the image capture progresses. |
| 1493 | * The shutter callback occurs after the image is captured. This can be used |
| 1494 | * to trigger a sound to let the user know that image has been captured. The |
| 1495 | * raw callback occurs when the raw image data is available (NOTE: the data |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1496 | * will be null if there is no raw image callback buffer available or the |
| 1497 | * raw image callback buffer is not large enough to hold the raw image). |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1498 | * The postview callback occurs when a scaled, fully processed postview |
| 1499 | * image is available (NOTE: not all hardware supports this). The jpeg |
| 1500 | * callback occurs when the compressed image is available. If the |
| 1501 | * application does not need a particular callback, a null can be passed |
| 1502 | * instead of a callback method. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1503 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1504 | * <p>This method is only valid when preview is active (after |
| 1505 | * {@link #startPreview()}). Preview will be stopped after the image is |
| 1506 | * taken; callers must call {@link #startPreview()} again if they want to |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 1507 | * re-start preview or take more pictures. This should not be called between |
| 1508 | * {@link android.media.MediaRecorder#start()} and |
| 1509 | * {@link android.media.MediaRecorder#stop()}. |
Wu-cheng Li | 40057ce | 2009-12-02 18:57:29 +0800 | [diff] [blame] | 1510 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1511 | * <p>After calling this method, you must not call {@link #startPreview()} |
| 1512 | * or take another picture until the JPEG callback has returned. |
| 1513 | * |
| 1514 | * @param shutter the callback for image capture moment, or null |
| 1515 | * @param raw the callback for raw (uncompressed) image data, or null |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1516 | * @param postview callback with postview image data, may be null |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1517 | * @param jpeg the callback for JPEG image data, or null |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1518 | * @throws RuntimeException if starting picture capture fails; usually this |
| 1519 | * would be because of a hardware or other low-level error, or because |
| 1520 | * release() has been called on this Camera instance. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1521 | */ |
| 1522 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 1523 | PictureCallback postview, PictureCallback jpeg) { |
| 1524 | mShutterCallback = shutter; |
| 1525 | mRawImageCallback = raw; |
| 1526 | mPostviewCallback = postview; |
| 1527 | mJpegCallback = jpeg; |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1528 | |
| 1529 | // If callback is not set, do not send me callbacks. |
| 1530 | int msgType = 0; |
| 1531 | if (mShutterCallback != null) { |
| 1532 | msgType |= CAMERA_MSG_SHUTTER; |
| 1533 | } |
| 1534 | if (mRawImageCallback != null) { |
| 1535 | msgType |= CAMERA_MSG_RAW_IMAGE; |
| 1536 | } |
| 1537 | if (mPostviewCallback != null) { |
| 1538 | msgType |= CAMERA_MSG_POSTVIEW_FRAME; |
| 1539 | } |
| 1540 | if (mJpegCallback != null) { |
| 1541 | msgType |= CAMERA_MSG_COMPRESSED_IMAGE; |
| 1542 | } |
| 1543 | |
| 1544 | native_takePicture(msgType); |
Wu-cheng Li | e9c6c9c | 2012-05-29 16:47:44 +0800 | [diff] [blame] | 1545 | mFaceDetectionRunning = false; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1549 | * Zooms to the requested value smoothly. The driver will notify {@link |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1550 | * OnZoomChangeListener} of the zoom value and whether zoom is stopped at |
| 1551 | * the time. For example, suppose the current zoom is 0 and startSmoothZoom |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1552 | * is called with value 3. The |
| 1553 | * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)} |
| 1554 | * method will be called three times with zoom values 1, 2, and 3. |
| 1555 | * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier. |
| 1556 | * Applications should not call startSmoothZoom again or change the zoom |
| 1557 | * value before zoom stops. If the supplied zoom value equals to the current |
| 1558 | * zoom value, no zoom callback will be generated. This method is supported |
| 1559 | * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported} |
| 1560 | * returns true. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1561 | * |
| 1562 | * @param value zoom value. The valid range is 0 to {@link |
| 1563 | * android.hardware.Camera.Parameters#getMaxZoom}. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 1564 | * @throws IllegalArgumentException if the zoom value is invalid. |
| 1565 | * @throws RuntimeException if the method fails. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1566 | * @see #setZoomChangeListener(OnZoomChangeListener) |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1567 | */ |
| 1568 | public native final void startSmoothZoom(int value); |
| 1569 | |
| 1570 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1571 | * Stops the smooth zoom. Applications should wait for the {@link |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1572 | * OnZoomChangeListener} to know when the zoom is actually stopped. This |
| 1573 | * method is supported if {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1574 | * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 1575 | * |
| 1576 | * @throws RuntimeException if the method fails. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1577 | */ |
| 1578 | public native final void stopSmoothZoom(); |
| 1579 | |
| 1580 | /** |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1581 | * Set the clockwise rotation of preview display in degrees. This affects |
| 1582 | * the preview frames and the picture displayed after snapshot. This method |
| 1583 | * is useful for portrait mode applications. Note that preview display of |
Wu-cheng Li | b982fb4 | 2010-10-19 17:19:09 +0800 | [diff] [blame] | 1584 | * front-facing cameras is flipped horizontally before the rotation, that |
| 1585 | * is, the image is reflected along the central vertical axis of the camera |
| 1586 | * sensor. So the users can see themselves as looking into a mirror. |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1587 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1588 | * <p>This does not affect the order of byte array passed in {@link |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1589 | * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This |
| 1590 | * method is not allowed to be called during preview. |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1591 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1592 | * <p>If you want to make the camera image show in the same orientation as |
| 1593 | * the display, you can use the following code. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1594 | * <pre> |
Chih-Chung Chang | 724c522 | 2010-06-14 18:57:15 +0800 | [diff] [blame] | 1595 | * public static void setCameraDisplayOrientation(Activity activity, |
| 1596 | * int cameraId, android.hardware.Camera camera) { |
| 1597 | * android.hardware.Camera.CameraInfo info = |
| 1598 | * new android.hardware.Camera.CameraInfo(); |
| 1599 | * android.hardware.Camera.getCameraInfo(cameraId, info); |
| 1600 | * int rotation = activity.getWindowManager().getDefaultDisplay() |
| 1601 | * .getRotation(); |
| 1602 | * int degrees = 0; |
| 1603 | * switch (rotation) { |
| 1604 | * case Surface.ROTATION_0: degrees = 0; break; |
| 1605 | * case Surface.ROTATION_90: degrees = 90; break; |
| 1606 | * case Surface.ROTATION_180: degrees = 180; break; |
| 1607 | * case Surface.ROTATION_270: degrees = 270; break; |
| 1608 | * } |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1609 | * |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1610 | * int result; |
| 1611 | * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { |
| 1612 | * result = (info.orientation + degrees) % 360; |
| 1613 | * result = (360 - result) % 360; // compensate the mirror |
| 1614 | * } else { // back-facing |
| 1615 | * result = (info.orientation - degrees + 360) % 360; |
| 1616 | * } |
Chih-Chung Chang | 724c522 | 2010-06-14 18:57:15 +0800 | [diff] [blame] | 1617 | * camera.setDisplayOrientation(result); |
| 1618 | * } |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1619 | * </pre> |
Wu-cheng Li | d303362 | 2011-10-07 13:13:54 +0800 | [diff] [blame] | 1620 | * |
| 1621 | * <p>Starting from API level 14, this method can be called when preview is |
| 1622 | * active. |
| 1623 | * |
Eino-Ville Talvala | 6c91e2c | 2016-03-25 11:54:39 -0700 | [diff] [blame] | 1624 | * <p><b>Note: </b>Before API level 24, the default value for orientation is 0. Starting in |
| 1625 | * API level 24, the default orientation will be such that applications in forced-landscape mode |
| 1626 | * will have correct preview orientation, which may be either a default of 0 or |
| 1627 | * 180. Applications that operate in portrait mode or allow for changing orientation must still |
| 1628 | * call this method after each orientation change to ensure correct preview display in all |
| 1629 | * cases.</p> |
| 1630 | * |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1631 | * @param degrees the angle that the picture will be rotated clockwise. |
Eino-Ville Talvala | 6c91e2c | 2016-03-25 11:54:39 -0700 | [diff] [blame] | 1632 | * Valid values are 0, 90, 180, and 270. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1633 | * @throws RuntimeException if setting orientation fails; usually this would |
| 1634 | * be because of a hardware or other low-level error, or because |
| 1635 | * release() has been called on this Camera instance. |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1636 | * @see #setPreviewDisplay(SurfaceHolder) |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1637 | */ |
| 1638 | public native final void setDisplayOrientation(int degrees); |
| 1639 | |
| 1640 | /** |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1641 | * <p>Enable or disable the default shutter sound when taking a picture.</p> |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1642 | * |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1643 | * <p>By default, the camera plays the system-defined camera shutter sound |
| 1644 | * when {@link #takePicture} is called. Using this method, the shutter sound |
| 1645 | * can be disabled. It is strongly recommended that an alternative shutter |
| 1646 | * sound is played in the {@link ShutterCallback} when the system shutter |
| 1647 | * sound is disabled.</p> |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1648 | * |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1649 | * <p>Note that devices may not always allow disabling the camera shutter |
| 1650 | * sound. If the shutter sound state cannot be set to the desired value, |
| 1651 | * this method will return false. {@link CameraInfo#canDisableShutterSound} |
| 1652 | * can be used to determine whether the device will allow the shutter sound |
| 1653 | * to be disabled.</p> |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1654 | * |
| 1655 | * @param enabled whether the camera should play the system shutter sound |
| 1656 | * when {@link #takePicture takePicture} is called. |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1657 | * @return {@code true} if the shutter sound state was successfully |
| 1658 | * changed. {@code false} if the shutter sound state could not be |
| 1659 | * changed. {@code true} is also returned if shutter sound playback |
| 1660 | * is already set to the requested state. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1661 | * @throws RuntimeException if the call fails; usually this would be because |
| 1662 | * of a hardware or other low-level error, or because release() has been |
| 1663 | * called on this Camera instance. |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1664 | * @see #takePicture |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1665 | * @see CameraInfo#canDisableShutterSound |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1666 | * @see ShutterCallback |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1667 | */ |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1668 | public final boolean enableShutterSound(boolean enabled) { |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1669 | boolean canDisableShutterSound = true; |
| 1670 | IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); |
| 1671 | IAudioService audioService = IAudioService.Stub.asInterface(b); |
| 1672 | try { |
| 1673 | if (audioService.isCameraSoundForced()) { |
| 1674 | canDisableShutterSound = false; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1675 | } |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1676 | } catch (RemoteException e) { |
| 1677 | Log.e(TAG, "Audio service is unavailable for queries"); |
| 1678 | } |
| 1679 | if (!enabled && !canDisableShutterSound) { |
| 1680 | return false; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1681 | } |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1682 | synchronized (mShutterSoundLock) { |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1683 | mShutterSoundEnabledFromApp = enabled; |
| 1684 | // Return the result of _enableShutterSound(enabled) in all cases. |
| 1685 | // If the shutter sound can be disabled, disable it when the device is in DnD mode. |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1686 | boolean ret = _enableShutterSound(enabled); |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1687 | if (enabled && !mHasAppOpsPlayAudio) { |
| 1688 | Log.i(TAG, "Shutter sound is not allowed by AppOpsManager"); |
| 1689 | if (canDisableShutterSound) { |
| 1690 | _enableShutterSound(false); |
| 1691 | } |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1692 | } |
| 1693 | return ret; |
| 1694 | } |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Igor Murashkin | 6653362 | 2014-08-19 14:51:47 -0700 | [diff] [blame] | 1697 | /** |
| 1698 | * Disable the shutter sound unconditionally. |
| 1699 | * |
| 1700 | * <p> |
| 1701 | * This is only guaranteed to work for legacy cameras |
| 1702 | * (i.e. initialized with {@link #cameraInitUnspecified}). Trying to call this on |
| 1703 | * a regular camera will force a conditional check in the camera service. |
| 1704 | * </p> |
| 1705 | * |
| 1706 | * @return {@code true} if the shutter sound state was successfully |
| 1707 | * changed. {@code false} if the shutter sound state could not be |
| 1708 | * changed. {@code true} is also returned if shutter sound playback |
| 1709 | * is already set to the requested state. |
| 1710 | * |
| 1711 | * @hide |
| 1712 | */ |
| 1713 | public final boolean disableShutterSound() { |
| 1714 | return _enableShutterSound(/*enabled*/false); |
| 1715 | } |
| 1716 | |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1717 | private native final boolean _enableShutterSound(boolean enabled); |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1718 | |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1719 | private static class IAppOpsCallbackWrapper extends IAppOpsCallback.Stub { |
| 1720 | private final WeakReference<Camera> mWeakCamera; |
| 1721 | |
| 1722 | IAppOpsCallbackWrapper(Camera camera) { |
| 1723 | mWeakCamera = new WeakReference<Camera>(camera); |
| 1724 | } |
| 1725 | |
| 1726 | @Override |
| 1727 | public void opChanged(int op, int uid, String packageName) { |
| 1728 | if (op == AppOpsManager.OP_PLAY_AUDIO) { |
| 1729 | final Camera camera = mWeakCamera.get(); |
| 1730 | if (camera != null) { |
| 1731 | camera.updateAppOpsPlayAudio(); |
| 1732 | } |
| 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | private void updateAppOpsPlayAudio() { |
| 1738 | synchronized (mShutterSoundLock) { |
| 1739 | boolean oldHasAppOpsPlayAudio = mHasAppOpsPlayAudio; |
| 1740 | try { |
| 1741 | int mode = AppOpsManager.MODE_IGNORED; |
| 1742 | if (mAppOps != null) { |
| 1743 | mode = mAppOps.checkAudioOperation(AppOpsManager.OP_PLAY_AUDIO, |
| 1744 | AudioAttributes.USAGE_ASSISTANCE_SONIFICATION, |
| 1745 | Process.myUid(), ActivityThread.currentPackageName()); |
| 1746 | } |
| 1747 | mHasAppOpsPlayAudio = mode == AppOpsManager.MODE_ALLOWED; |
| 1748 | } catch (RemoteException e) { |
| 1749 | Log.e(TAG, "AppOpsService check audio operation failed"); |
| 1750 | mHasAppOpsPlayAudio = false; |
| 1751 | } |
| 1752 | if (oldHasAppOpsPlayAudio != mHasAppOpsPlayAudio) { |
| 1753 | if (!mHasAppOpsPlayAudio) { |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1754 | IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); |
| 1755 | IAudioService audioService = IAudioService.Stub.asInterface(b); |
| 1756 | try { |
| 1757 | if (audioService.isCameraSoundForced()) { |
| 1758 | return; |
| 1759 | } |
| 1760 | } catch (RemoteException e) { |
| 1761 | Log.e(TAG, "Audio service is unavailable for queries"); |
| 1762 | } |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1763 | _enableShutterSound(false); |
| 1764 | } else { |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1765 | enableShutterSound(mShutterSoundEnabledFromApp); |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1766 | } |
| 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1771 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1772 | * Callback interface for zoom changes during a smooth zoom operation. |
| 1773 | * |
| 1774 | * @see #setZoomChangeListener(OnZoomChangeListener) |
| 1775 | * @see #startSmoothZoom(int) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1776 | * |
| 1777 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1778 | * applications. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1779 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1780 | @Deprecated |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1781 | public interface OnZoomChangeListener |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1782 | { |
| 1783 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1784 | * Called when the zoom value has changed during a smooth zoom. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1785 | * |
| 1786 | * @param zoomValue the current zoom value. In smooth zoom mode, camera |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1787 | * calls this for every new zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1788 | * @param stopped whether smooth zoom is stopped. If the value is true, |
| 1789 | * this is the last zoom update for the application. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1790 | * @param camera the Camera service object |
| 1791 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1792 | void onZoomChange(int zoomValue, boolean stopped, Camera camera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1793 | }; |
| 1794 | |
| 1795 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1796 | * Registers a listener to be notified when the zoom value is updated by the |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1797 | * camera driver during smooth zoom. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1798 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1799 | * @param listener the listener to notify |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1800 | * @see #startSmoothZoom(int) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1801 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1802 | public final void setZoomChangeListener(OnZoomChangeListener listener) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1803 | { |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1804 | mZoomListener = listener; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1805 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1806 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1807 | /** |
| 1808 | * Callback interface for face detected in the preview frame. |
| 1809 | * |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1810 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1811 | * applications. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1812 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1813 | @Deprecated |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1814 | public interface FaceDetectionListener |
| 1815 | { |
| 1816 | /** |
| 1817 | * Notify the listener of the detected faces in the preview frame. |
| 1818 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1819 | * @param faces The detected faces in a list |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1820 | * @param camera The {@link Camera} service object |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1821 | */ |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1822 | void onFaceDetection(Face[] faces, Camera camera); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1826 | * Registers a listener to be notified about the faces detected in the |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1827 | * preview frame. |
| 1828 | * |
| 1829 | * @param listener the listener to notify |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1830 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1831 | */ |
| 1832 | public final void setFaceDetectionListener(FaceDetectionListener listener) |
| 1833 | { |
| 1834 | mFaceListener = listener; |
| 1835 | } |
| 1836 | |
| 1837 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1838 | * Starts the face detection. This should be called after preview is started. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1839 | * The camera will notify {@link FaceDetectionListener} of the detected |
| 1840 | * faces in the preview frame. The detected faces may be the same as the |
| 1841 | * previous ones. Applications should call {@link #stopFaceDetection} to |
| 1842 | * stop the face detection. This method is supported if {@link |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1843 | * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1844 | * If the face detection has started, apps should not call this again. |
| 1845 | * |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1846 | * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)}, |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1847 | * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)} |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1848 | * have no effect. The camera uses the detected faces to do auto-white balance, |
| 1849 | * auto exposure, and autofocus. |
| 1850 | * |
| 1851 | * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera |
| 1852 | * will stop sending face callbacks. The last face callback indicates the |
| 1853 | * areas used to do autofocus. After focus completes, face detection will |
| 1854 | * resume sending face callbacks. If the apps call {@link |
| 1855 | * #cancelAutoFocus()}, the face callbacks will also resume.</p> |
| 1856 | * |
| 1857 | * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, |
| 1858 | * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming |
| 1859 | * preview with {@link #startPreview()}, the apps should call this method |
| 1860 | * again to resume face detection.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1861 | * |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1862 | * @throws IllegalArgumentException if the face detection is unsupported. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1863 | * @throws RuntimeException if the method fails or the face detection is |
| 1864 | * already running. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1865 | * @see FaceDetectionListener |
| 1866 | * @see #stopFaceDetection() |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1867 | * @see Parameters#getMaxNumDetectedFaces() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1868 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1869 | public final void startFaceDetection() { |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1870 | if (mFaceDetectionRunning) { |
| 1871 | throw new RuntimeException("Face detection is already running"); |
| 1872 | } |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1873 | _startFaceDetection(CAMERA_FACE_DETECTION_HW); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1874 | mFaceDetectionRunning = true; |
| 1875 | } |
| 1876 | |
| 1877 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1878 | * Stops the face detection. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1879 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1880 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1881 | */ |
| 1882 | public final void stopFaceDetection() { |
| 1883 | _stopFaceDetection(); |
| 1884 | mFaceDetectionRunning = false; |
| 1885 | } |
| 1886 | |
| 1887 | private native final void _startFaceDetection(int type); |
| 1888 | private native final void _stopFaceDetection(); |
| 1889 | |
| 1890 | /** |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1891 | * Information about a face identified through camera face detection. |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1892 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1893 | * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a |
| 1894 | * list of face objects for use in focusing and metering.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1895 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1896 | * @see FaceDetectionListener |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1897 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1898 | * applications. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1899 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1900 | @Deprecated |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1901 | public static class Face { |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1902 | /** |
| 1903 | * Create an empty face. |
| 1904 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1905 | public Face() { |
| 1906 | } |
| 1907 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1908 | /** |
| 1909 | * Bounds of the face. (-1000, -1000) represents the top-left of the |
| 1910 | * camera field of view, and (1000, 1000) represents the bottom-right of |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1911 | * the field of view. For example, suppose the size of the viewfinder UI |
| 1912 | * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0). |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1913 | * The corresponding viewfinder rect should be (0, 0, 400, 240). It is |
| 1914 | * guaranteed left < right and top < bottom. The coordinates can be |
| 1915 | * smaller than -1000 or bigger than 1000. But at least one vertex will |
| 1916 | * be within (-1000, -1000) and (1000, 1000). |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1917 | * |
| 1918 | * <p>The direction is relative to the sensor orientation, that is, what |
| 1919 | * the sensor sees. The direction is not affected by the rotation or |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1920 | * mirroring of {@link #setDisplayOrientation(int)}. The face bounding |
| 1921 | * rectangle does not provide any information about face orientation.</p> |
| 1922 | * |
| 1923 | * <p>Here is the matrix to convert driver coordinates to View coordinates |
| 1924 | * in pixels.</p> |
| 1925 | * <pre> |
| 1926 | * Matrix matrix = new Matrix(); |
| 1927 | * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId]; |
| 1928 | * // Need mirror for front camera. |
| 1929 | * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT); |
| 1930 | * matrix.setScale(mirror ? -1 : 1, 1); |
| 1931 | * // This is the value for android.hardware.Camera.setDisplayOrientation. |
| 1932 | * matrix.postRotate(displayOrientation); |
| 1933 | * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000). |
| 1934 | * // UI coordinates range from (0, 0) to (width, height). |
| 1935 | * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f); |
| 1936 | * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f); |
| 1937 | * </pre> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1938 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1939 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1940 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1941 | public Rect rect; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1942 | |
| 1943 | /** |
Eino-Ville Talvala | 8df3b2b | 2012-09-15 14:30:12 -0700 | [diff] [blame] | 1944 | * <p>The confidence level for the detection of the face. The range is 1 to |
| 1945 | * 100. 100 is the highest confidence.</p> |
| 1946 | * |
| 1947 | * <p>Depending on the device, even very low-confidence faces may be |
| 1948 | * listed, so applications should filter out faces with low confidence, |
| 1949 | * depending on the use case. For a typical point-and-shoot camera |
| 1950 | * application that wishes to display rectangles around detected faces, |
| 1951 | * filtering out faces with confidence less than 50 is recommended.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1952 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1953 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1954 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1955 | public int score; |
Wei Hua | d52b308 | 2011-08-19 13:01:51 -0700 | [diff] [blame] | 1956 | |
| 1957 | /** |
| 1958 | * An unique id per face while the face is visible to the tracker. If |
| 1959 | * the face leaves the field-of-view and comes back, it will get a new |
| 1960 | * id. This is an optional field, may not be supported on all devices. |
| 1961 | * If not supported, id will always be set to -1. The optional fields |
| 1962 | * are supported as a set. Either they are all valid, or none of them |
| 1963 | * are. |
| 1964 | */ |
| 1965 | public int id = -1; |
| 1966 | |
| 1967 | /** |
| 1968 | * The coordinates of the center of the left eye. The coordinates are in |
| 1969 | * the same space as the ones for {@link #rect}. This is an optional |
| 1970 | * field, may not be supported on all devices. If not supported, the |
| 1971 | * value will always be set to null. The optional fields are supported |
| 1972 | * as a set. Either they are all valid, or none of them are. |
| 1973 | */ |
| 1974 | public Point leftEye = null; |
| 1975 | |
| 1976 | /** |
| 1977 | * The coordinates of the center of the right eye. The coordinates are |
| 1978 | * in the same space as the ones for {@link #rect}.This is an optional |
| 1979 | * field, may not be supported on all devices. If not supported, the |
| 1980 | * value will always be set to null. The optional fields are supported |
| 1981 | * as a set. Either they are all valid, or none of them are. |
| 1982 | */ |
| 1983 | public Point rightEye = null; |
| 1984 | |
| 1985 | /** |
| 1986 | * The coordinates of the center of the mouth. The coordinates are in |
| 1987 | * the same space as the ones for {@link #rect}. This is an optional |
| 1988 | * field, may not be supported on all devices. If not supported, the |
| 1989 | * value will always be set to null. The optional fields are supported |
| 1990 | * as a set. Either they are all valid, or none of them are. |
| 1991 | */ |
| 1992 | public Point mouth = null; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1993 | } |
| 1994 | |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1995 | /** |
| 1996 | * Unspecified camera error. |
| 1997 | * @see Camera.ErrorCallback |
| 1998 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | public static final int CAMERA_ERROR_UNKNOWN = 1; |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2000 | |
| 2001 | /** |
Ruben Brunk | e91b925 | 2015-04-14 13:38:06 -0700 | [diff] [blame] | 2002 | * Camera was disconnected due to use by higher priority user. |
| 2003 | * @see Camera.ErrorCallback |
| 2004 | */ |
| 2005 | public static final int CAMERA_ERROR_EVICTED = 2; |
| 2006 | |
| 2007 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2008 | * Media server died. In this case, the application must release the |
| 2009 | * Camera object and instantiate a new one. |
| 2010 | * @see Camera.ErrorCallback |
| 2011 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2012 | public static final int CAMERA_ERROR_SERVER_DIED = 100; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2014 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2015 | * Callback interface for camera error notification. |
| 2016 | * |
| 2017 | * @see #setErrorCallback(ErrorCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2018 | * |
| 2019 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2020 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2022 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2023 | public interface ErrorCallback |
| 2024 | { |
| 2025 | /** |
| 2026 | * Callback for camera errors. |
| 2027 | * @param error error code: |
| 2028 | * <ul> |
| 2029 | * <li>{@link #CAMERA_ERROR_UNKNOWN} |
| 2030 | * <li>{@link #CAMERA_ERROR_SERVER_DIED} |
| 2031 | * </ul> |
| 2032 | * @param camera the Camera service object |
| 2033 | */ |
| 2034 | void onError(int error, Camera camera); |
| 2035 | }; |
| 2036 | |
| 2037 | /** |
| 2038 | * Registers a callback to be invoked when an error occurs. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2039 | * @param cb The callback to run |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | */ |
| 2041 | public final void setErrorCallback(ErrorCallback cb) |
| 2042 | { |
| 2043 | mErrorCallback = cb; |
| 2044 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2046 | private native final void native_setParameters(String params); |
| 2047 | private native final String native_getParameters(); |
| 2048 | |
| 2049 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2050 | * Changes the settings for this Camera service. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2051 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2052 | * @param params the Parameters to use for this Camera service |
Wu-cheng Li | 99a3f3e | 2010-11-19 15:56:16 +0800 | [diff] [blame] | 2053 | * @throws RuntimeException if any parameter is invalid or not supported. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2054 | * @see #getParameters() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2055 | */ |
| 2056 | public void setParameters(Parameters params) { |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 2057 | // If using preview allocations, don't allow preview size changes |
| 2058 | if (mUsingPreviewAllocation) { |
| 2059 | Size newPreviewSize = params.getPreviewSize(); |
| 2060 | Size currentPreviewSize = getParameters().getPreviewSize(); |
| 2061 | if (newPreviewSize.width != currentPreviewSize.width || |
| 2062 | newPreviewSize.height != currentPreviewSize.height) { |
| 2063 | throw new IllegalStateException("Cannot change preview size" + |
| 2064 | " while a preview allocation is configured."); |
| 2065 | } |
| 2066 | } |
| 2067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | native_setParameters(params.flatten()); |
| 2069 | } |
| 2070 | |
| 2071 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2072 | * Returns the current settings for this Camera service. |
| 2073 | * If modifications are made to the returned Parameters, they must be passed |
| 2074 | * to {@link #setParameters(Camera.Parameters)} to take effect. |
| 2075 | * |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 2076 | * @throws RuntimeException if reading parameters fails; usually this would |
| 2077 | * be because of a hardware or other low-level error, or because |
| 2078 | * release() has been called on this Camera instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2079 | * @see #setParameters(Camera.Parameters) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2080 | */ |
| 2081 | public Parameters getParameters() { |
| 2082 | Parameters p = new Parameters(); |
| 2083 | String s = native_getParameters(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | p.unflatten(s); |
| 2085 | return p; |
| 2086 | } |
| 2087 | |
| 2088 | /** |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 2089 | * Returns an empty {@link Parameters} for testing purpose. |
| 2090 | * |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 2091 | * @return a Parameter object. |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 2092 | * |
| 2093 | * @hide |
| 2094 | */ |
| 2095 | public static Parameters getEmptyParameters() { |
| 2096 | Camera camera = new Camera(); |
| 2097 | return camera.new Parameters(); |
| 2098 | } |
| 2099 | |
| 2100 | /** |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 2101 | * Returns a copied {@link Parameters}; for shim use only. |
| 2102 | * |
| 2103 | * @param parameters a non-{@code null} parameters |
| 2104 | * @return a Parameter object, with all the parameters copied from {@code parameters}. |
| 2105 | * |
| 2106 | * @throws NullPointerException if {@code parameters} was {@code null} |
| 2107 | * @hide |
| 2108 | */ |
| 2109 | public static Parameters getParametersCopy(Camera.Parameters parameters) { |
| 2110 | if (parameters == null) { |
| 2111 | throw new NullPointerException("parameters must not be null"); |
| 2112 | } |
| 2113 | |
| 2114 | Camera camera = parameters.getOuter(); |
| 2115 | Parameters p = camera.new Parameters(); |
| 2116 | p.copyFrom(parameters); |
| 2117 | |
| 2118 | return p; |
| 2119 | } |
| 2120 | |
| 2121 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2122 | * Image size (width and height dimensions). |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2123 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2124 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2125 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2126 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2127 | public class Size { |
| 2128 | /** |
| 2129 | * Sets the dimensions for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2130 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2131 | * @param w the photo width (pixels) |
| 2132 | * @param h the photo height (pixels) |
| 2133 | */ |
| 2134 | public Size(int w, int h) { |
| 2135 | width = w; |
| 2136 | height = h; |
| 2137 | } |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2138 | /** |
| 2139 | * Compares {@code obj} to this size. |
| 2140 | * |
| 2141 | * @param obj the object to compare this size with. |
| 2142 | * @return {@code true} if the width and height of {@code obj} is the |
| 2143 | * same as those of this size. {@code false} otherwise. |
| 2144 | */ |
| 2145 | @Override |
| 2146 | public boolean equals(Object obj) { |
| 2147 | if (!(obj instanceof Size)) { |
| 2148 | return false; |
| 2149 | } |
| 2150 | Size s = (Size) obj; |
| 2151 | return width == s.width && height == s.height; |
| 2152 | } |
| 2153 | @Override |
| 2154 | public int hashCode() { |
| 2155 | return width * 32713 + height; |
| 2156 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | /** width of the picture */ |
| 2158 | public int width; |
| 2159 | /** height of the picture */ |
| 2160 | public int height; |
| 2161 | }; |
| 2162 | |
| 2163 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2164 | * <p>The Area class is used for choosing specific metering and focus areas for |
| 2165 | * the camera to use when calculating auto-exposure, auto-white balance, and |
| 2166 | * auto-focus.</p> |
| 2167 | * |
| 2168 | * <p>To find out how many simultaneous areas a given camera supports, use |
| 2169 | * {@link Parameters#getMaxNumMeteringAreas()} and |
| 2170 | * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area |
| 2171 | * selection is unsupported, these methods will return 0.</p> |
| 2172 | * |
| 2173 | * <p>Each Area consists of a rectangle specifying its bounds, and a weight |
| 2174 | * that determines its importance. The bounds are relative to the camera's |
| 2175 | * current field of view. The coordinates are mapped so that (-1000, -1000) |
| 2176 | * is always the top-left corner of the current field of view, and (1000, |
| 2177 | * 1000) is always the bottom-right corner of the current field of |
| 2178 | * view. Setting Areas with bounds outside that range is not allowed. Areas |
| 2179 | * with zero or negative width or height are not allowed.</p> |
| 2180 | * |
| 2181 | * <p>The weight must range from 1 to 1000, and represents a weight for |
| 2182 | * every pixel in the area. This means that a large metering area with |
| 2183 | * the same weight as a smaller area will have more effect in the |
| 2184 | * metering result. Metering areas can overlap and the driver |
| 2185 | * will add the weights in the overlap region.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2186 | * |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2187 | * @see Parameters#setFocusAreas(List) |
| 2188 | * @see Parameters#getFocusAreas() |
| 2189 | * @see Parameters#getMaxNumFocusAreas() |
| 2190 | * @see Parameters#setMeteringAreas(List) |
| 2191 | * @see Parameters#getMeteringAreas() |
| 2192 | * @see Parameters#getMaxNumMeteringAreas() |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2193 | * |
| 2194 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2195 | * applications. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2196 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2197 | @Deprecated |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2198 | public static class Area { |
| 2199 | /** |
| 2200 | * Create an area with specified rectangle and weight. |
| 2201 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2202 | * @param rect the bounds of the area. |
| 2203 | * @param weight the weight of the area. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2204 | */ |
| 2205 | public Area(Rect rect, int weight) { |
| 2206 | this.rect = rect; |
| 2207 | this.weight = weight; |
| 2208 | } |
| 2209 | /** |
| 2210 | * Compares {@code obj} to this area. |
| 2211 | * |
| 2212 | * @param obj the object to compare this area with. |
| 2213 | * @return {@code true} if the rectangle and weight of {@code obj} is |
| 2214 | * the same as those of this area. {@code false} otherwise. |
| 2215 | */ |
| 2216 | @Override |
| 2217 | public boolean equals(Object obj) { |
| 2218 | if (!(obj instanceof Area)) { |
| 2219 | return false; |
| 2220 | } |
| 2221 | Area a = (Area) obj; |
| 2222 | if (rect == null) { |
| 2223 | if (a.rect != null) return false; |
| 2224 | } else { |
| 2225 | if (!rect.equals(a.rect)) return false; |
| 2226 | } |
| 2227 | return weight == a.weight; |
| 2228 | } |
| 2229 | |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2230 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2231 | * Bounds of the area. (-1000, -1000) represents the top-left of the |
| 2232 | * camera field of view, and (1000, 1000) represents the bottom-right of |
| 2233 | * the field of view. Setting bounds outside that range is not |
| 2234 | * allowed. Bounds with zero or negative width or height are not |
| 2235 | * allowed. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2236 | * |
| 2237 | * @see Parameters#getFocusAreas() |
| 2238 | * @see Parameters#getMeteringAreas() |
| 2239 | */ |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2240 | public Rect rect; |
| 2241 | |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2242 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2243 | * Weight of the area. The weight must range from 1 to 1000, and |
| 2244 | * represents a weight for every pixel in the area. This means that a |
| 2245 | * large metering area with the same weight as a smaller area will have |
| 2246 | * more effect in the metering result. Metering areas can overlap and |
| 2247 | * the driver will add the weights in the overlap region. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2248 | * |
| 2249 | * @see Parameters#getFocusAreas() |
| 2250 | * @see Parameters#getMeteringAreas() |
| 2251 | */ |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2252 | public int weight; |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2253 | } |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2254 | |
| 2255 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2256 | * Camera service settings. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2257 | * |
| 2258 | * <p>To make camera parameters take effect, applications have to call |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2259 | * {@link Camera#setParameters(Camera.Parameters)}. For example, after |
| 2260 | * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not |
| 2261 | * actually changed until {@link Camera#setParameters(Camera.Parameters)} |
| 2262 | * is called with the changed parameters object. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2263 | * |
| 2264 | * <p>Different devices may have different camera capabilities, such as |
| 2265 | * picture size or flash modes. The application should query the camera |
| 2266 | * capabilities before setting parameters. For example, the application |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2267 | * should call {@link Camera.Parameters#getSupportedColorEffects()} before |
| 2268 | * calling {@link Camera.Parameters#setColorEffect(String)}. If the |
| 2269 | * camera does not support color effects, |
| 2270 | * {@link Camera.Parameters#getSupportedColorEffects()} will return null. |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2271 | * |
| 2272 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2273 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2274 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2275 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2276 | public class Parameters { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2277 | // Parameter keys to communicate with the camera driver. |
| 2278 | private static final String KEY_PREVIEW_SIZE = "preview-size"; |
| 2279 | private static final String KEY_PREVIEW_FORMAT = "preview-format"; |
| 2280 | private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate"; |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2281 | private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2282 | private static final String KEY_PICTURE_SIZE = "picture-size"; |
| 2283 | private static final String KEY_PICTURE_FORMAT = "picture-format"; |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2284 | private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2285 | private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width"; |
| 2286 | private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height"; |
| 2287 | private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality"; |
| 2288 | private static final String KEY_JPEG_QUALITY = "jpeg-quality"; |
| 2289 | private static final String KEY_ROTATION = "rotation"; |
| 2290 | private static final String KEY_GPS_LATITUDE = "gps-latitude"; |
| 2291 | private static final String KEY_GPS_LONGITUDE = "gps-longitude"; |
| 2292 | private static final String KEY_GPS_ALTITUDE = "gps-altitude"; |
| 2293 | private static final String KEY_GPS_TIMESTAMP = "gps-timestamp"; |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 2294 | private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2295 | private static final String KEY_WHITE_BALANCE = "whitebalance"; |
| 2296 | private static final String KEY_EFFECT = "effect"; |
| 2297 | private static final String KEY_ANTIBANDING = "antibanding"; |
| 2298 | private static final String KEY_SCENE_MODE = "scene-mode"; |
| 2299 | private static final String KEY_FLASH_MODE = "flash-mode"; |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2300 | private static final String KEY_FOCUS_MODE = "focus-mode"; |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2301 | private static final String KEY_FOCUS_AREAS = "focus-areas"; |
| 2302 | private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas"; |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 2303 | private static final String KEY_FOCAL_LENGTH = "focal-length"; |
| 2304 | private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle"; |
| 2305 | private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle"; |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2306 | private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation"; |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2307 | private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation"; |
| 2308 | private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation"; |
| 2309 | private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step"; |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2310 | private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock"; |
| 2311 | private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported"; |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2312 | private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock"; |
| 2313 | private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported"; |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 2314 | private static final String KEY_METERING_AREAS = "metering-areas"; |
| 2315 | private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 2316 | private static final String KEY_ZOOM = "zoom"; |
| 2317 | private static final String KEY_MAX_ZOOM = "max-zoom"; |
| 2318 | private static final String KEY_ZOOM_RATIOS = "zoom-ratios"; |
| 2319 | private static final String KEY_ZOOM_SUPPORTED = "zoom-supported"; |
| 2320 | private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 2321 | private static final String KEY_FOCUS_DISTANCES = "focus-distances"; |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2322 | private static final String KEY_VIDEO_SIZE = "video-size"; |
| 2323 | private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO = |
| 2324 | "preferred-preview-size-for-video"; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 2325 | private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw"; |
| 2326 | private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw"; |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 2327 | private static final String KEY_RECORDING_HINT = "recording-hint"; |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 2328 | private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported"; |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 2329 | private static final String KEY_VIDEO_STABILIZATION = "video-stabilization"; |
| 2330 | private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 2331 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2332 | // Parameter key suffix for supported values. |
| 2333 | private static final String SUPPORTED_VALUES_SUFFIX = "-values"; |
| 2334 | |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 2335 | private static final String TRUE = "true"; |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2336 | private static final String FALSE = "false"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 2337 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2338 | // Values for white balance settings. |
| 2339 | public static final String WHITE_BALANCE_AUTO = "auto"; |
| 2340 | public static final String WHITE_BALANCE_INCANDESCENT = "incandescent"; |
| 2341 | public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent"; |
| 2342 | public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent"; |
| 2343 | public static final String WHITE_BALANCE_DAYLIGHT = "daylight"; |
| 2344 | public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight"; |
| 2345 | public static final String WHITE_BALANCE_TWILIGHT = "twilight"; |
| 2346 | public static final String WHITE_BALANCE_SHADE = "shade"; |
| 2347 | |
| 2348 | // Values for color effect settings. |
| 2349 | public static final String EFFECT_NONE = "none"; |
| 2350 | public static final String EFFECT_MONO = "mono"; |
| 2351 | public static final String EFFECT_NEGATIVE = "negative"; |
| 2352 | public static final String EFFECT_SOLARIZE = "solarize"; |
| 2353 | public static final String EFFECT_SEPIA = "sepia"; |
| 2354 | public static final String EFFECT_POSTERIZE = "posterize"; |
| 2355 | public static final String EFFECT_WHITEBOARD = "whiteboard"; |
| 2356 | public static final String EFFECT_BLACKBOARD = "blackboard"; |
| 2357 | public static final String EFFECT_AQUA = "aqua"; |
| 2358 | |
| 2359 | // Values for antibanding settings. |
| 2360 | public static final String ANTIBANDING_AUTO = "auto"; |
| 2361 | public static final String ANTIBANDING_50HZ = "50hz"; |
| 2362 | public static final String ANTIBANDING_60HZ = "60hz"; |
| 2363 | public static final String ANTIBANDING_OFF = "off"; |
| 2364 | |
| 2365 | // Values for flash mode settings. |
| 2366 | /** |
| 2367 | * Flash will not be fired. |
| 2368 | */ |
| 2369 | public static final String FLASH_MODE_OFF = "off"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2370 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2371 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2372 | * Flash will be fired automatically when required. The flash may be fired |
| 2373 | * during preview, auto-focus, or snapshot depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2374 | */ |
| 2375 | public static final String FLASH_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2376 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2377 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2378 | * Flash will always be fired during snapshot. The flash may also be |
| 2379 | * fired during preview or auto-focus depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2380 | */ |
| 2381 | public static final String FLASH_MODE_ON = "on"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2382 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2383 | /** |
| 2384 | * Flash will be fired in red-eye reduction mode. |
| 2385 | */ |
| 2386 | public static final String FLASH_MODE_RED_EYE = "red-eye"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2387 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2388 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2389 | * Constant emission of light during preview, auto-focus and snapshot. |
| 2390 | * This can also be used for video recording. |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2391 | */ |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2392 | public static final String FLASH_MODE_TORCH = "torch"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2393 | |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2394 | /** |
| 2395 | * Scene mode is off. |
| 2396 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2397 | public static final String SCENE_MODE_AUTO = "auto"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2398 | |
| 2399 | /** |
| 2400 | * Take photos of fast moving objects. Same as {@link |
| 2401 | * #SCENE_MODE_SPORTS}. |
| 2402 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2403 | public static final String SCENE_MODE_ACTION = "action"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2404 | |
| 2405 | /** |
| 2406 | * Take people pictures. |
| 2407 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2408 | public static final String SCENE_MODE_PORTRAIT = "portrait"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2409 | |
| 2410 | /** |
| 2411 | * Take pictures on distant objects. |
| 2412 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2413 | public static final String SCENE_MODE_LANDSCAPE = "landscape"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2414 | |
| 2415 | /** |
| 2416 | * Take photos at night. |
| 2417 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2418 | public static final String SCENE_MODE_NIGHT = "night"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2419 | |
| 2420 | /** |
| 2421 | * Take people pictures at night. |
| 2422 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2423 | public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2424 | |
| 2425 | /** |
| 2426 | * Take photos in a theater. Flash light is off. |
| 2427 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2428 | public static final String SCENE_MODE_THEATRE = "theatre"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2429 | |
| 2430 | /** |
| 2431 | * Take pictures on the beach. |
| 2432 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2433 | public static final String SCENE_MODE_BEACH = "beach"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2434 | |
| 2435 | /** |
| 2436 | * Take pictures on the snow. |
| 2437 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2438 | public static final String SCENE_MODE_SNOW = "snow"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2439 | |
| 2440 | /** |
| 2441 | * Take sunset photos. |
| 2442 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2443 | public static final String SCENE_MODE_SUNSET = "sunset"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2444 | |
| 2445 | /** |
| 2446 | * Avoid blurry pictures (for example, due to hand shake). |
| 2447 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2448 | public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2449 | |
| 2450 | /** |
| 2451 | * For shooting firework displays. |
| 2452 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2453 | public static final String SCENE_MODE_FIREWORKS = "fireworks"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2454 | |
| 2455 | /** |
| 2456 | * Take photos of fast moving objects. Same as {@link |
| 2457 | * #SCENE_MODE_ACTION}. |
| 2458 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2459 | public static final String SCENE_MODE_SPORTS = "sports"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2460 | |
| 2461 | /** |
| 2462 | * Take indoor low-light shot. |
| 2463 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2464 | public static final String SCENE_MODE_PARTY = "party"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2465 | |
| 2466 | /** |
| 2467 | * Capture the naturally warm color of scenes lit by candles. |
| 2468 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2469 | public static final String SCENE_MODE_CANDLELIGHT = "candlelight"; |
| 2470 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 2471 | /** |
| 2472 | * Applications are looking for a barcode. Camera driver will be |
| 2473 | * optimized for barcode reading. |
| 2474 | */ |
| 2475 | public static final String SCENE_MODE_BARCODE = "barcode"; |
| 2476 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2477 | /** |
Eino-Ville Talvala | da2f0ea | 2012-09-10 12:03:35 -0700 | [diff] [blame] | 2478 | * Capture a scene using high dynamic range imaging techniques. The |
| 2479 | * camera will return an image that has an extended dynamic range |
| 2480 | * compared to a regular capture. Capturing such an image may take |
| 2481 | * longer than a regular capture. |
Eino-Ville Talvala | da2f0ea | 2012-09-10 12:03:35 -0700 | [diff] [blame] | 2482 | */ |
| 2483 | public static final String SCENE_MODE_HDR = "hdr"; |
| 2484 | |
| 2485 | /** |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 2486 | * Auto-focus mode. Applications should call {@link |
| 2487 | * #autoFocus(AutoFocusCallback)} to start the focus in this mode. |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2488 | */ |
| 2489 | public static final String FOCUS_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2490 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2491 | /** |
| 2492 | * Focus is set at infinity. Applications should not call |
| 2493 | * {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 2494 | */ |
| 2495 | public static final String FOCUS_MODE_INFINITY = "infinity"; |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 2496 | |
| 2497 | /** |
| 2498 | * Macro (close-up) focus mode. Applications should call |
| 2499 | * {@link #autoFocus(AutoFocusCallback)} to start the focus in this |
| 2500 | * mode. |
| 2501 | */ |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2502 | public static final String FOCUS_MODE_MACRO = "macro"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2503 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2504 | /** |
| 2505 | * Focus is fixed. The camera is always in this mode if the focus is not |
| 2506 | * adjustable. If the camera has auto-focus, this mode can fix the |
| 2507 | * focus, which is usually at hyperfocal distance. Applications should |
| 2508 | * not call {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 2509 | */ |
| 2510 | public static final String FOCUS_MODE_FIXED = "fixed"; |
| 2511 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 2512 | /** |
| 2513 | * Extended depth of field (EDOF). Focusing is done digitally and |
| 2514 | * continuously. Applications should not call {@link |
| 2515 | * #autoFocus(AutoFocusCallback)} in this mode. |
| 2516 | */ |
| 2517 | public static final String FOCUS_MODE_EDOF = "edof"; |
| 2518 | |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2519 | /** |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 2520 | * Continuous auto focus mode intended for video recording. The camera |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2521 | * continuously tries to focus. This is the best choice for video |
| 2522 | * recording because the focus changes smoothly . Applications still can |
| 2523 | * call {@link #takePicture(Camera.ShutterCallback, |
| 2524 | * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the |
| 2525 | * subject may not be in focus. Auto focus starts when the parameter is |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 2526 | * set. |
| 2527 | * |
| 2528 | * <p>Since API level 14, applications can call {@link |
| 2529 | * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will |
| 2530 | * immediately return with a boolean that indicates whether the focus is |
| 2531 | * sharp or not. The focus position is locked after autoFocus call. If |
| 2532 | * applications want to resume the continuous focus, cancelAutoFocus |
| 2533 | * must be called. Restarting the preview will not resume the continuous |
| 2534 | * autofocus. To stop continuous focus, applications should change the |
| 2535 | * focus mode to other modes. |
| 2536 | * |
| 2537 | * @see #FOCUS_MODE_CONTINUOUS_PICTURE |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2538 | */ |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 2539 | public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video"; |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2540 | |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2541 | /** |
| 2542 | * Continuous auto focus mode intended for taking pictures. The camera |
| 2543 | * continuously tries to focus. The speed of focus change is more |
| 2544 | * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 2545 | * starts when the parameter is set. |
| 2546 | * |
Wu-cheng Li | 0f4f97b | 2011-10-27 18:07:01 +0800 | [diff] [blame] | 2547 | * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in |
| 2548 | * this mode. If the autofocus is in the middle of scanning, the focus |
| 2549 | * callback will return when it completes. If the autofocus is not |
| 2550 | * scanning, the focus callback will immediately return with a boolean |
| 2551 | * that indicates whether the focus is sharp or not. The apps can then |
| 2552 | * decide if they want to take a picture immediately or to change the |
| 2553 | * focus mode to auto, and run a full autofocus cycle. The focus |
| 2554 | * position is locked after autoFocus call. If applications want to |
| 2555 | * resume the continuous focus, cancelAutoFocus must be called. |
| 2556 | * Restarting the preview will not resume the continuous autofocus. To |
| 2557 | * stop continuous focus, applications should change the focus mode to |
| 2558 | * other modes. |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2559 | * |
| 2560 | * @see #FOCUS_MODE_CONTINUOUS_VIDEO |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2561 | */ |
| 2562 | public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture"; |
| 2563 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 2564 | // Indices for focus distance array. |
| 2565 | /** |
| 2566 | * The array index of near focus distance for use with |
| 2567 | * {@link #getFocusDistances(float[])}. |
| 2568 | */ |
| 2569 | public static final int FOCUS_DISTANCE_NEAR_INDEX = 0; |
| 2570 | |
| 2571 | /** |
| 2572 | * The array index of optimal focus distance for use with |
| 2573 | * {@link #getFocusDistances(float[])}. |
| 2574 | */ |
| 2575 | public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1; |
| 2576 | |
| 2577 | /** |
| 2578 | * The array index of far focus distance for use with |
| 2579 | * {@link #getFocusDistances(float[])}. |
| 2580 | */ |
| 2581 | public static final int FOCUS_DISTANCE_FAR_INDEX = 2; |
| 2582 | |
Wu-cheng Li | ca09961 | 2010-05-06 16:47:30 +0800 | [diff] [blame] | 2583 | /** |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2584 | * The array index of minimum preview fps for use with {@link |
| 2585 | * #getPreviewFpsRange(int[])} or {@link |
| 2586 | * #getSupportedPreviewFpsRange()}. |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2587 | */ |
| 2588 | public static final int PREVIEW_FPS_MIN_INDEX = 0; |
| 2589 | |
| 2590 | /** |
| 2591 | * The array index of maximum preview fps for use with {@link |
| 2592 | * #getPreviewFpsRange(int[])} or {@link |
| 2593 | * #getSupportedPreviewFpsRange()}. |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2594 | */ |
| 2595 | public static final int PREVIEW_FPS_MAX_INDEX = 1; |
| 2596 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2597 | // Formats for setPreviewFormat and setPictureFormat. |
| 2598 | private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp"; |
| 2599 | private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp"; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 2600 | private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv"; |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 2601 | private static final String PIXEL_FORMAT_YUV420P = "yuv420p"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2602 | private static final String PIXEL_FORMAT_RGB565 = "rgb565"; |
| 2603 | private static final String PIXEL_FORMAT_JPEG = "jpeg"; |
Wu-cheng Li | 70fb908 | 2011-08-02 17:49:50 +0800 | [diff] [blame] | 2604 | private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2605 | |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2606 | /** |
| 2607 | * Order matters: Keys that are {@link #set(String, String) set} later |
| 2608 | * will take precedence over keys that are set earlier (if the two keys |
| 2609 | * conflict with each other). |
| 2610 | * |
| 2611 | * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it |
| 2612 | * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later |
| 2613 | * is the one that will take precedence. |
| 2614 | * </p> |
| 2615 | */ |
| 2616 | private final LinkedHashMap<String, String> mMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | |
| 2618 | private Parameters() { |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2619 | mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | /** |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 2623 | * Overwrite existing parameters with a copy of the ones from {@code other}. |
| 2624 | * |
| 2625 | * <b>For use by the legacy shim only.</b> |
| 2626 | * |
| 2627 | * @hide |
| 2628 | */ |
| 2629 | public void copyFrom(Parameters other) { |
| 2630 | if (other == null) { |
| 2631 | throw new NullPointerException("other must not be null"); |
| 2632 | } |
| 2633 | |
| 2634 | mMap.putAll(other.mMap); |
| 2635 | } |
| 2636 | |
| 2637 | private Camera getOuter() { |
| 2638 | return Camera.this; |
| 2639 | } |
| 2640 | |
Ruben Brunk | d1f113d | 2014-07-11 11:46:20 -0700 | [diff] [blame] | 2641 | |
| 2642 | /** |
| 2643 | * Value equality check. |
| 2644 | * |
| 2645 | * @hide |
| 2646 | */ |
| 2647 | public boolean same(Parameters other) { |
| 2648 | if (this == other) { |
| 2649 | return true; |
| 2650 | } |
| 2651 | return other != null && Parameters.this.mMap.equals(other.mMap); |
| 2652 | } |
| 2653 | |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 2654 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | * Writes the current Parameters to the log. |
| 2656 | * @hide |
| 2657 | * @deprecated |
| 2658 | */ |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 2659 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2660 | public void dump() { |
| 2661 | Log.e(TAG, "dump: size=" + mMap.size()); |
| 2662 | for (String k : mMap.keySet()) { |
| 2663 | Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | /** |
| 2668 | * Creates a single string with all the parameters set in |
| 2669 | * this Parameters object. |
| 2670 | * <p>The {@link #unflatten(String)} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2671 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | * @return a String with all values from this Parameters object, in |
| 2673 | * semi-colon delimited key-value pairs |
| 2674 | */ |
| 2675 | public String flatten() { |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 2676 | StringBuilder flattened = new StringBuilder(128); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2677 | for (String k : mMap.keySet()) { |
| 2678 | flattened.append(k); |
| 2679 | flattened.append("="); |
| 2680 | flattened.append(mMap.get(k)); |
| 2681 | flattened.append(";"); |
| 2682 | } |
| 2683 | // chop off the extra semicolon at the end |
| 2684 | flattened.deleteCharAt(flattened.length()-1); |
| 2685 | return flattened.toString(); |
| 2686 | } |
| 2687 | |
| 2688 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2689 | * Takes a flattened string of parameters and adds each one to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | * this Parameters object. |
| 2691 | * <p>The {@link #flatten()} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2692 | * |
| 2693 | * @param flattened a String of parameters (key-value paired) that |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | * are semi-colon delimited |
| 2695 | */ |
| 2696 | public void unflatten(String flattened) { |
| 2697 | mMap.clear(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2698 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 2699 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';'); |
| 2700 | splitter.setString(flattened); |
| 2701 | for (String kv : splitter) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | int pos = kv.indexOf('='); |
| 2703 | if (pos == -1) { |
| 2704 | continue; |
| 2705 | } |
| 2706 | String k = kv.substring(0, pos); |
| 2707 | String v = kv.substring(pos + 1); |
| 2708 | mMap.put(k, v); |
| 2709 | } |
| 2710 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2712 | public void remove(String key) { |
| 2713 | mMap.remove(key); |
| 2714 | } |
| 2715 | |
| 2716 | /** |
| 2717 | * Sets a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2718 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2719 | * @param key the key name for the parameter |
| 2720 | * @param value the String value of the parameter |
| 2721 | */ |
| 2722 | public void set(String key, String value) { |
Eino-Ville Talvala | cb56923 | 2012-03-12 11:36:58 -0700 | [diff] [blame] | 2723 | if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) { |
| 2724 | Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2725 | return; |
| 2726 | } |
Eino-Ville Talvala | cb56923 | 2012-03-12 11:36:58 -0700 | [diff] [blame] | 2727 | if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) { |
| 2728 | Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2729 | return; |
| 2730 | } |
| 2731 | |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2732 | put(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | /** |
| 2736 | * Sets an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2737 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | * @param key the key name for the parameter |
| 2739 | * @param value the int value of the parameter |
| 2740 | */ |
| 2741 | public void set(String key, int value) { |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2742 | put(key, Integer.toString(value)); |
| 2743 | } |
| 2744 | |
| 2745 | private void put(String key, String value) { |
| 2746 | /* |
| 2747 | * Remove the key if it already exists. |
| 2748 | * |
| 2749 | * This way setting a new value for an already existing key will always move |
| 2750 | * that key to be ordered the latest in the map. |
| 2751 | */ |
| 2752 | mMap.remove(key); |
| 2753 | mMap.put(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | } |
| 2755 | |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 2756 | private void set(String key, List<Area> areas) { |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 2757 | if (areas == null) { |
| 2758 | set(key, "(0,0,0,0,0)"); |
| 2759 | } else { |
| 2760 | StringBuilder buffer = new StringBuilder(); |
| 2761 | for (int i = 0; i < areas.size(); i++) { |
| 2762 | Area area = areas.get(i); |
| 2763 | Rect rect = area.rect; |
| 2764 | buffer.append('('); |
| 2765 | buffer.append(rect.left); |
| 2766 | buffer.append(','); |
| 2767 | buffer.append(rect.top); |
| 2768 | buffer.append(','); |
| 2769 | buffer.append(rect.right); |
| 2770 | buffer.append(','); |
| 2771 | buffer.append(rect.bottom); |
| 2772 | buffer.append(','); |
| 2773 | buffer.append(area.weight); |
| 2774 | buffer.append(')'); |
| 2775 | if (i != areas.size() - 1) buffer.append(','); |
| 2776 | } |
| 2777 | set(key, buffer.toString()); |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 2778 | } |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 2779 | } |
| 2780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2781 | /** |
| 2782 | * Returns the value of a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2783 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2784 | * @param key the key name for the parameter |
| 2785 | * @return the String value of the parameter |
| 2786 | */ |
| 2787 | public String get(String key) { |
| 2788 | return mMap.get(key); |
| 2789 | } |
| 2790 | |
| 2791 | /** |
| 2792 | * Returns the value of an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2793 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2794 | * @param key the key name for the parameter |
| 2795 | * @return the int value of the parameter |
| 2796 | */ |
| 2797 | public int getInt(String key) { |
| 2798 | return Integer.parseInt(mMap.get(key)); |
| 2799 | } |
| 2800 | |
| 2801 | /** |
Wu-cheng Li | 26274fa | 2011-05-05 14:36:28 +0800 | [diff] [blame] | 2802 | * Sets the dimensions for preview pictures. If the preview has already |
| 2803 | * started, applications should stop the preview first before changing |
| 2804 | * preview size. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2805 | * |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2806 | * The sides of width and height are based on camera orientation. That |
| 2807 | * is, the preview size is the size before it is rotated by display |
| 2808 | * orientation. So applications need to consider the display orientation |
| 2809 | * while setting preview size. For example, suppose the camera supports |
| 2810 | * both 480x320 and 320x480 preview sizes. The application wants a 3:2 |
| 2811 | * preview ratio. If the display orientation is set to 0 or 180, preview |
| 2812 | * size should be set to 480x320. If the display orientation is set to |
| 2813 | * 90 or 270, preview size should be set to 320x480. The display |
| 2814 | * orientation should also be considered while setting picture size and |
| 2815 | * thumbnail size. |
| 2816 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2817 | * @param width the width of the pictures, in pixels |
| 2818 | * @param height the height of the pictures, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2819 | * @see #setDisplayOrientation(int) |
| 2820 | * @see #getCameraInfo(int, CameraInfo) |
| 2821 | * @see #setPictureSize(int, int) |
| 2822 | * @see #setJpegThumbnailSize(int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | */ |
| 2824 | public void setPreviewSize(int width, int height) { |
| 2825 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2826 | set(KEY_PREVIEW_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | /** |
| 2830 | * Returns the dimensions setting for preview pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2831 | * |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2832 | * @return a Size object with the width and height setting |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | * for the preview picture |
| 2834 | */ |
| 2835 | public Size getPreviewSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2836 | String pair = get(KEY_PREVIEW_SIZE); |
| 2837 | return strToSize(pair); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2841 | * Gets the supported preview sizes. |
| 2842 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2843 | * @return a list of Size object. This method will always return a list |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 2844 | * with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2845 | */ |
| 2846 | public List<Size> getSupportedPreviewSizes() { |
| 2847 | String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2848 | return splitSize(str); |
| 2849 | } |
| 2850 | |
| 2851 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2852 | * <p>Gets the supported video frame sizes that can be used by |
| 2853 | * MediaRecorder.</p> |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2854 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2855 | * <p>If the returned list is not null, the returned list will contain at |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2856 | * least one Size and one of the sizes in the returned list must be |
| 2857 | * passed to MediaRecorder.setVideoSize() for camcorder application if |
| 2858 | * camera is used as the video source. In this case, the size of the |
| 2859 | * preview can be different from the resolution of the recorded video |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2860 | * during video recording.</p> |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2861 | * |
| 2862 | * @return a list of Size object if camera has separate preview and |
| 2863 | * video output; otherwise, null is returned. |
| 2864 | * @see #getPreferredPreviewSizeForVideo() |
| 2865 | */ |
| 2866 | public List<Size> getSupportedVideoSizes() { |
| 2867 | String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2868 | return splitSize(str); |
| 2869 | } |
| 2870 | |
| 2871 | /** |
| 2872 | * Returns the preferred or recommended preview size (width and height) |
| 2873 | * in pixels for video recording. Camcorder applications should |
| 2874 | * set the preview size to a value that is not larger than the |
| 2875 | * preferred preview size. In other words, the product of the width |
| 2876 | * and height of the preview size should not be larger than that of |
| 2877 | * the preferred preview size. In addition, we recommend to choose a |
| 2878 | * preview size that has the same aspect ratio as the resolution of |
| 2879 | * video to be recorded. |
| 2880 | * |
| 2881 | * @return the preferred preview size (width and height) in pixels for |
| 2882 | * video recording if getSupportedVideoSizes() does not return |
| 2883 | * null; otherwise, null is returned. |
| 2884 | * @see #getSupportedVideoSizes() |
| 2885 | */ |
| 2886 | public Size getPreferredPreviewSizeForVideo() { |
| 2887 | String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); |
| 2888 | return strToSize(pair); |
| 2889 | } |
| 2890 | |
| 2891 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2892 | * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2893 | * applications set both width and height to 0, EXIF will not contain |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2894 | * thumbnail.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2895 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2896 | * <p>Applications need to consider the display orientation. See {@link |
| 2897 | * #setPreviewSize(int,int)} for reference.</p> |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2898 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | * @param width the width of the thumbnail, in pixels |
| 2900 | * @param height the height of the thumbnail, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2901 | * @see #setPreviewSize(int,int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2902 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2903 | public void setJpegThumbnailSize(int width, int height) { |
| 2904 | set(KEY_JPEG_THUMBNAIL_WIDTH, width); |
| 2905 | set(KEY_JPEG_THUMBNAIL_HEIGHT, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2909 | * Returns the dimensions for EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2911 | * @return a Size object with the height and width setting for the EXIF |
| 2912 | * thumbnails |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2914 | public Size getJpegThumbnailSize() { |
| 2915 | return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH), |
| 2916 | getInt(KEY_JPEG_THUMBNAIL_HEIGHT)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | /** |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2920 | * Gets the supported jpeg thumbnail sizes. |
| 2921 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2922 | * @return a list of Size object. This method will always return a list |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2923 | * with at least two elements. Size 0,0 (no thumbnail) is always |
| 2924 | * supported. |
| 2925 | */ |
| 2926 | public List<Size> getSupportedJpegThumbnailSizes() { |
| 2927 | String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2928 | return splitSize(str); |
| 2929 | } |
| 2930 | |
| 2931 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2932 | * Sets the quality of the EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2934 | * @param quality the JPEG quality of the EXIF thumbnail. The range is 1 |
| 2935 | * to 100, with 100 being the best. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2937 | public void setJpegThumbnailQuality(int quality) { |
| 2938 | set(KEY_JPEG_THUMBNAIL_QUALITY, quality); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2942 | * Returns the quality setting for the EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2944 | * @return the JPEG quality setting of the EXIF thumbnail. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2945 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2946 | public int getJpegThumbnailQuality() { |
| 2947 | return getInt(KEY_JPEG_THUMBNAIL_QUALITY); |
| 2948 | } |
| 2949 | |
| 2950 | /** |
| 2951 | * Sets Jpeg quality of captured picture. |
| 2952 | * |
| 2953 | * @param quality the JPEG quality of captured picture. The range is 1 |
| 2954 | * to 100, with 100 being the best. |
| 2955 | */ |
| 2956 | public void setJpegQuality(int quality) { |
| 2957 | set(KEY_JPEG_QUALITY, quality); |
| 2958 | } |
| 2959 | |
| 2960 | /** |
| 2961 | * Returns the quality setting for the JPEG picture. |
| 2962 | * |
| 2963 | * @return the JPEG picture quality setting. |
| 2964 | */ |
| 2965 | public int getJpegQuality() { |
| 2966 | return getInt(KEY_JPEG_QUALITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 2970 | * Sets the rate at which preview frames are received. This is the |
| 2971 | * target frame rate. The actual frame rate depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2972 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | * @param fps the frame rate (frames per second) |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2974 | * @deprecated replaced by {@link #setPreviewFpsRange(int,int)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2976 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | public void setPreviewFrameRate(int fps) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2978 | set(KEY_PREVIEW_FRAME_RATE, fps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 2982 | * Returns the setting for the rate at which preview frames are |
| 2983 | * received. This is the target frame rate. The actual frame rate |
| 2984 | * depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2985 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | * @return the frame rate setting (frames per second) |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2987 | * @deprecated replaced by {@link #getPreviewFpsRange(int[])} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2989 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2990 | public int getPreviewFrameRate() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2991 | return getInt(KEY_PREVIEW_FRAME_RATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2995 | * Gets the supported preview frame rates. |
| 2996 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2997 | * @return a list of supported preview frame rates. null if preview |
| 2998 | * frame rate setting is not supported. |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2999 | * @deprecated replaced by {@link #getSupportedPreviewFpsRange()} |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3000 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 3001 | @Deprecated |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3002 | public List<Integer> getSupportedPreviewFrameRates() { |
| 3003 | String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX); |
| 3004 | return splitInt(str); |
| 3005 | } |
| 3006 | |
| 3007 | /** |
Hai Guo | 4a68e3c | 2012-12-05 21:50:28 +0800 | [diff] [blame] | 3008 | * Sets the minimum and maximum preview fps. This controls the rate of |
Wu-cheng Li | 1620d11 | 2010-08-27 15:09:20 -0700 | [diff] [blame] | 3009 | * preview frames received in {@link PreviewCallback}. The minimum and |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3010 | * maximum preview fps must be one of the elements from {@link |
| 3011 | * #getSupportedPreviewFpsRange}. |
| 3012 | * |
| 3013 | * @param min the minimum preview fps (scaled by 1000). |
| 3014 | * @param max the maximum preview fps (scaled by 1000). |
| 3015 | * @throws RuntimeException if fps range is invalid. |
| 3016 | * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) |
| 3017 | * @see #getSupportedPreviewFpsRange() |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3018 | */ |
| 3019 | public void setPreviewFpsRange(int min, int max) { |
| 3020 | set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max); |
| 3021 | } |
| 3022 | |
| 3023 | /** |
| 3024 | * Returns the current minimum and maximum preview fps. The values are |
| 3025 | * one of the elements returned by {@link #getSupportedPreviewFpsRange}. |
| 3026 | * |
| 3027 | * @return range the minimum and maximum preview fps (scaled by 1000). |
| 3028 | * @see #PREVIEW_FPS_MIN_INDEX |
| 3029 | * @see #PREVIEW_FPS_MAX_INDEX |
| 3030 | * @see #getSupportedPreviewFpsRange() |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3031 | */ |
| 3032 | public void getPreviewFpsRange(int[] range) { |
| 3033 | if (range == null || range.length != 2) { |
| 3034 | throw new IllegalArgumentException( |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 3035 | "range must be an array with two elements."); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3036 | } |
| 3037 | splitInt(get(KEY_PREVIEW_FPS_RANGE), range); |
| 3038 | } |
| 3039 | |
| 3040 | /** |
| 3041 | * Gets the supported preview fps (frame-per-second) ranges. Each range |
| 3042 | * contains a minimum fps and maximum fps. If minimum fps equals to |
| 3043 | * maximum fps, the camera outputs frames in fixed frame rate. If not, |
| 3044 | * the camera outputs frames in auto frame rate. The actual frame rate |
| 3045 | * fluctuates between the minimum and the maximum. The values are |
| 3046 | * multiplied by 1000 and represented in integers. For example, if frame |
| 3047 | * rate is 26.623 frames per second, the value is 26623. |
| 3048 | * |
| 3049 | * @return a list of supported preview fps ranges. This method returns a |
| 3050 | * list with at least one element. Every element is an int array |
| 3051 | * of two values - minimum fps and maximum fps. The list is |
| 3052 | * sorted from small to large (first by maximum fps and then |
| 3053 | * minimum fps). |
| 3054 | * @see #PREVIEW_FPS_MIN_INDEX |
| 3055 | * @see #PREVIEW_FPS_MAX_INDEX |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3056 | */ |
| 3057 | public List<int[]> getSupportedPreviewFpsRange() { |
| 3058 | String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX); |
| 3059 | return splitRange(str); |
| 3060 | } |
| 3061 | |
| 3062 | /** |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 3063 | * Sets the image format for preview pictures. |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 3064 | * <p>If this is never called, the default format will be |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3065 | * {@link android.graphics.ImageFormat#NV21}, which |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 3066 | * uses the NV21 encoding format.</p> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 3067 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3068 | * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of |
| 3069 | * the available preview formats. |
| 3070 | * |
| 3071 | * <p>It is strongly recommended that either |
| 3072 | * {@link android.graphics.ImageFormat#NV21} or |
| 3073 | * {@link android.graphics.ImageFormat#YV12} is used, since |
| 3074 | * they are supported by all camera devices.</p> |
| 3075 | * |
| 3076 | * <p>For YV12, the image buffer that is received is not necessarily |
| 3077 | * tightly packed, as there may be padding at the end of each row of |
| 3078 | * pixel data, as described in |
| 3079 | * {@link android.graphics.ImageFormat#YV12}. For camera callback data, |
| 3080 | * it can be assumed that the stride of the Y and UV data is the |
| 3081 | * smallest possible that meets the alignment requirements. That is, if |
| 3082 | * the preview size is <var>width x height</var>, then the following |
| 3083 | * equations describe the buffer index for the beginning of row |
| 3084 | * <var>y</var> for the Y plane and row <var>c</var> for the U and V |
| 3085 | * planes: |
| 3086 | * |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 3087 | * <pre>{@code |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3088 | * yStride = (int) ceil(width / 16.0) * 16; |
| 3089 | * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16; |
| 3090 | * ySize = yStride * height; |
| 3091 | * uvSize = uvStride * height / 2; |
| 3092 | * yRowIndex = yStride * y; |
| 3093 | * uRowIndex = ySize + uvSize + uvStride * c; |
| 3094 | * vRowIndex = ySize + uvStride * c; |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 3095 | * size = ySize + uvSize * 2; |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3096 | * } |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 3097 | *</pre> |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3098 | * |
| 3099 | * @param pixel_format the desired preview picture format, defined by |
| 3100 | * one of the {@link android.graphics.ImageFormat} constants. (E.g., |
| 3101 | * <var>ImageFormat.NV21</var> (default), or |
| 3102 | * <var>ImageFormat.YV12</var>) |
| 3103 | * |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3104 | * @see android.graphics.ImageFormat |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3105 | * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3106 | */ |
| 3107 | public void setPreviewFormat(int pixel_format) { |
| 3108 | String s = cameraFormatForPixelFormat(pixel_format); |
| 3109 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3110 | throw new IllegalArgumentException( |
| 3111 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | } |
| 3113 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3114 | set(KEY_PREVIEW_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3118 | * Returns the image format for preview frames got from |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3119 | * {@link PreviewCallback}. |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 3120 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3121 | * @return the preview format. |
| 3122 | * @see android.graphics.ImageFormat |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3123 | * @see #setPreviewFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3124 | */ |
| 3125 | public int getPreviewFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3126 | return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT)); |
| 3127 | } |
| 3128 | |
| 3129 | /** |
Wu-cheng Li | f9293e7 | 2011-02-25 13:35:10 +0800 | [diff] [blame] | 3130 | * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21} |
| 3131 | * is always supported. {@link android.graphics.ImageFormat#YV12} |
| 3132 | * is always supported since API level 12. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3133 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3134 | * @return a list of supported preview formats. This method will always |
| 3135 | * return a list with at least one element. |
| 3136 | * @see android.graphics.ImageFormat |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3137 | * @see #setPreviewFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3138 | */ |
| 3139 | public List<Integer> getSupportedPreviewFormats() { |
| 3140 | String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX); |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3141 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 3142 | for (String s : split(str)) { |
| 3143 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3144 | if (f == ImageFormat.UNKNOWN) continue; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3145 | formats.add(f); |
| 3146 | } |
| 3147 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3151 | * <p>Sets the dimensions for pictures.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3152 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3153 | * <p>Applications need to consider the display orientation. See {@link |
| 3154 | * #setPreviewSize(int,int)} for reference.</p> |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3155 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3156 | * @param width the width for pictures, in pixels |
| 3157 | * @param height the height for pictures, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3158 | * @see #setPreviewSize(int,int) |
| 3159 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | */ |
| 3161 | public void setPictureSize(int width, int height) { |
| 3162 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3163 | set(KEY_PICTURE_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | /** |
| 3167 | * Returns the dimension setting for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3168 | * |
| 3169 | * @return a Size object with the height and width setting |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | * for pictures |
| 3171 | */ |
| 3172 | public Size getPictureSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3173 | String pair = get(KEY_PICTURE_SIZE); |
| 3174 | return strToSize(pair); |
| 3175 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3176 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3177 | /** |
| 3178 | * Gets the supported picture sizes. |
| 3179 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3180 | * @return a list of supported picture sizes. This method will always |
| 3181 | * return a list with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3182 | */ |
| 3183 | public List<Size> getSupportedPictureSizes() { |
| 3184 | String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 3185 | return splitSize(str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | /** |
| 3189 | * Sets the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3190 | * |
| 3191 | * @param pixel_format the desired picture format |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3192 | * (<var>ImageFormat.NV21</var>, |
| 3193 | * <var>ImageFormat.RGB_565</var>, or |
| 3194 | * <var>ImageFormat.JPEG</var>) |
| 3195 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | */ |
| 3197 | public void setPictureFormat(int pixel_format) { |
| 3198 | String s = cameraFormatForPixelFormat(pixel_format); |
| 3199 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3200 | throw new IllegalArgumentException( |
| 3201 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | } |
| 3203 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3204 | set(KEY_PICTURE_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | /** |
| 3208 | * Returns the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3209 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3210 | * @return the picture format |
| 3211 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3212 | */ |
| 3213 | public int getPictureFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3214 | return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); |
| 3215 | } |
| 3216 | |
| 3217 | /** |
| 3218 | * Gets the supported picture formats. |
| 3219 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3220 | * @return supported picture formats. This method will always return a |
| 3221 | * list with at least one element. |
| 3222 | * @see android.graphics.ImageFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3223 | */ |
| 3224 | public List<Integer> getSupportedPictureFormats() { |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 3225 | String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX); |
| 3226 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 3227 | for (String s : split(str)) { |
| 3228 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3229 | if (f == ImageFormat.UNKNOWN) continue; |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 3230 | formats.add(f); |
| 3231 | } |
| 3232 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | private String cameraFormatForPixelFormat(int pixel_format) { |
| 3236 | switch(pixel_format) { |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3237 | case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP; |
| 3238 | case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP; |
| 3239 | case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I; |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 3240 | case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P; |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3241 | case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565; |
| 3242 | case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG; |
| 3243 | default: return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | private int pixelFormatForCameraFormat(String format) { |
| 3248 | if (format == null) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3249 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3250 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3251 | if (format.equals(PIXEL_FORMAT_YUV422SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3252 | return ImageFormat.NV16; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3254 | if (format.equals(PIXEL_FORMAT_YUV420SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3255 | return ImageFormat.NV21; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3257 | if (format.equals(PIXEL_FORMAT_YUV422I)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3258 | return ImageFormat.YUY2; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3259 | |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 3260 | if (format.equals(PIXEL_FORMAT_YUV420P)) |
| 3261 | return ImageFormat.YV12; |
| 3262 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3263 | if (format.equals(PIXEL_FORMAT_RGB565)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3264 | return ImageFormat.RGB_565; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3266 | if (format.equals(PIXEL_FORMAT_JPEG)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3267 | return ImageFormat.JPEG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3268 | |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3269 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3270 | } |
| 3271 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3272 | /** |
Wu-cheng Li | 8969ea1 | 2012-04-20 17:38:09 +0800 | [diff] [blame] | 3273 | * Sets the clockwise rotation angle in degrees relative to the |
| 3274 | * orientation of the camera. This affects the pictures returned from |
| 3275 | * JPEG {@link PictureCallback}. The camera driver may set orientation |
| 3276 | * in the EXIF header without rotating the picture. Or the driver may |
| 3277 | * rotate the picture and the EXIF thumbnail. If the Jpeg picture is |
Igor Murashkin | a1b02db | 2013-06-11 15:25:20 -0700 | [diff] [blame] | 3278 | * rotated, the orientation in the EXIF header will be missing or 1 (row |
| 3279 | * #0 is top and column #0 is left side). |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3280 | * |
Igor Murashkin | a1b02db | 2013-06-11 15:25:20 -0700 | [diff] [blame] | 3281 | * <p> |
| 3282 | * If applications want to rotate the picture to match the orientation |
| 3283 | * of what users see, apps should use |
| 3284 | * {@link android.view.OrientationEventListener} and |
| 3285 | * {@link android.hardware.Camera.CameraInfo}. The value from |
| 3286 | * OrientationEventListener is relative to the natural orientation of |
| 3287 | * the device. CameraInfo.orientation is the angle between camera |
| 3288 | * orientation and natural device orientation. The sum of the two is the |
| 3289 | * rotation angle for back-facing camera. The difference of the two is |
| 3290 | * the rotation angle for front-facing camera. Note that the JPEG |
| 3291 | * pictures of front-facing cameras are not mirrored as in preview |
| 3292 | * display. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3293 | * |
Igor Murashkin | a1b02db | 2013-06-11 15:25:20 -0700 | [diff] [blame] | 3294 | * <p> |
| 3295 | * For example, suppose the natural orientation of the device is |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3296 | * portrait. The device is rotated 270 degrees clockwise, so the device |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 3297 | * orientation is 270. Suppose a back-facing camera sensor is mounted in |
| 3298 | * landscape and the top side of the camera sensor is aligned with the |
| 3299 | * right edge of the display in natural orientation. So the camera |
| 3300 | * orientation is 90. The rotation should be set to 0 (270 + 90). |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3301 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 3302 | * <p>The reference code is as follows. |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3303 | * |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 3304 | * <pre> |
Scott Main | 9a10bf0 | 2011-08-24 19:09:48 -0700 | [diff] [blame] | 3305 | * public void onOrientationChanged(int orientation) { |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3306 | * if (orientation == ORIENTATION_UNKNOWN) return; |
| 3307 | * android.hardware.Camera.CameraInfo info = |
| 3308 | * new android.hardware.Camera.CameraInfo(); |
| 3309 | * android.hardware.Camera.getCameraInfo(cameraId, info); |
| 3310 | * orientation = (orientation + 45) / 90 * 90; |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 3311 | * int rotation = 0; |
| 3312 | * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { |
| 3313 | * rotation = (info.orientation - orientation + 360) % 360; |
| 3314 | * } else { // back-facing camera |
| 3315 | * rotation = (info.orientation + orientation) % 360; |
| 3316 | * } |
| 3317 | * mParameters.setRotation(rotation); |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3318 | * } |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 3319 | * </pre> |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3320 | * |
| 3321 | * @param rotation The rotation angle in degrees relative to the |
| 3322 | * orientation of the camera. Rotation can only be 0, |
| 3323 | * 90, 180 or 270. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3324 | * @throws IllegalArgumentException if rotation value is invalid. |
| 3325 | * @see android.view.OrientationEventListener |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3326 | * @see #getCameraInfo(int, CameraInfo) |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3327 | */ |
| 3328 | public void setRotation(int rotation) { |
| 3329 | if (rotation == 0 || rotation == 90 || rotation == 180 |
| 3330 | || rotation == 270) { |
| 3331 | set(KEY_ROTATION, Integer.toString(rotation)); |
| 3332 | } else { |
| 3333 | throw new IllegalArgumentException( |
| 3334 | "Invalid rotation=" + rotation); |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | /** |
| 3339 | * Sets GPS latitude coordinate. This will be stored in JPEG EXIF |
| 3340 | * header. |
| 3341 | * |
| 3342 | * @param latitude GPS latitude coordinate. |
| 3343 | */ |
| 3344 | public void setGpsLatitude(double latitude) { |
| 3345 | set(KEY_GPS_LATITUDE, Double.toString(latitude)); |
| 3346 | } |
| 3347 | |
| 3348 | /** |
| 3349 | * Sets GPS longitude coordinate. This will be stored in JPEG EXIF |
| 3350 | * header. |
| 3351 | * |
| 3352 | * @param longitude GPS longitude coordinate. |
| 3353 | */ |
| 3354 | public void setGpsLongitude(double longitude) { |
| 3355 | set(KEY_GPS_LONGITUDE, Double.toString(longitude)); |
| 3356 | } |
| 3357 | |
| 3358 | /** |
| 3359 | * Sets GPS altitude. This will be stored in JPEG EXIF header. |
| 3360 | * |
| 3361 | * @param altitude GPS altitude in meters. |
| 3362 | */ |
| 3363 | public void setGpsAltitude(double altitude) { |
| 3364 | set(KEY_GPS_ALTITUDE, Double.toString(altitude)); |
| 3365 | } |
| 3366 | |
| 3367 | /** |
| 3368 | * Sets GPS timestamp. This will be stored in JPEG EXIF header. |
| 3369 | * |
| 3370 | * @param timestamp GPS timestamp (UTC in seconds since January 1, |
| 3371 | * 1970). |
| 3372 | */ |
| 3373 | public void setGpsTimestamp(long timestamp) { |
| 3374 | set(KEY_GPS_TIMESTAMP, Long.toString(timestamp)); |
| 3375 | } |
| 3376 | |
| 3377 | /** |
Eino-Ville Talvala | d840727 | 2015-11-08 18:27:20 -0800 | [diff] [blame] | 3378 | * Sets GPS processing method. The method will be stored in a UTF-8 string up to 31 bytes |
| 3379 | * long, in the JPEG EXIF header. |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 3380 | * |
| 3381 | * @param processing_method The processing method to get this location. |
| 3382 | */ |
| 3383 | public void setGpsProcessingMethod(String processing_method) { |
| 3384 | set(KEY_GPS_PROCESSING_METHOD, processing_method); |
| 3385 | } |
| 3386 | |
| 3387 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3388 | * Removes GPS latitude, longitude, altitude, and timestamp from the |
| 3389 | * parameters. |
| 3390 | */ |
| 3391 | public void removeGpsData() { |
| 3392 | remove(KEY_GPS_LATITUDE); |
| 3393 | remove(KEY_GPS_LONGITUDE); |
| 3394 | remove(KEY_GPS_ALTITUDE); |
| 3395 | remove(KEY_GPS_TIMESTAMP); |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 3396 | remove(KEY_GPS_PROCESSING_METHOD); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | /** |
| 3400 | * Gets the current white balance setting. |
| 3401 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3402 | * @return current white balance. null if white balance setting is not |
| 3403 | * supported. |
| 3404 | * @see #WHITE_BALANCE_AUTO |
| 3405 | * @see #WHITE_BALANCE_INCANDESCENT |
| 3406 | * @see #WHITE_BALANCE_FLUORESCENT |
| 3407 | * @see #WHITE_BALANCE_WARM_FLUORESCENT |
| 3408 | * @see #WHITE_BALANCE_DAYLIGHT |
| 3409 | * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT |
| 3410 | * @see #WHITE_BALANCE_TWILIGHT |
| 3411 | * @see #WHITE_BALANCE_SHADE |
| 3412 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3413 | */ |
| 3414 | public String getWhiteBalance() { |
| 3415 | return get(KEY_WHITE_BALANCE); |
| 3416 | } |
| 3417 | |
| 3418 | /** |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3419 | * Sets the white balance. Changing the setting will release the |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 3420 | * auto-white balance lock. It is recommended not to change white |
| 3421 | * balance and AWB lock at the same time. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3422 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3423 | * @param value new white balance. |
| 3424 | * @see #getWhiteBalance() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 3425 | * @see #setAutoWhiteBalanceLock(boolean) |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3426 | */ |
| 3427 | public void setWhiteBalance(String value) { |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 3428 | String oldValue = get(KEY_WHITE_BALANCE); |
| 3429 | if (same(value, oldValue)) return; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3430 | set(KEY_WHITE_BALANCE, value); |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3431 | set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3432 | } |
| 3433 | |
| 3434 | /** |
| 3435 | * Gets the supported white balance. |
| 3436 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3437 | * @return a list of supported white balance. null if white balance |
| 3438 | * setting is not supported. |
| 3439 | * @see #getWhiteBalance() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3440 | */ |
| 3441 | public List<String> getSupportedWhiteBalance() { |
| 3442 | String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX); |
| 3443 | return split(str); |
| 3444 | } |
| 3445 | |
| 3446 | /** |
| 3447 | * Gets the current color effect setting. |
| 3448 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3449 | * @return current color effect. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3450 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3451 | * @see #EFFECT_NONE |
| 3452 | * @see #EFFECT_MONO |
| 3453 | * @see #EFFECT_NEGATIVE |
| 3454 | * @see #EFFECT_SOLARIZE |
| 3455 | * @see #EFFECT_SEPIA |
| 3456 | * @see #EFFECT_POSTERIZE |
| 3457 | * @see #EFFECT_WHITEBOARD |
| 3458 | * @see #EFFECT_BLACKBOARD |
| 3459 | * @see #EFFECT_AQUA |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3460 | */ |
| 3461 | public String getColorEffect() { |
| 3462 | return get(KEY_EFFECT); |
| 3463 | } |
| 3464 | |
| 3465 | /** |
| 3466 | * Sets the current color effect setting. |
| 3467 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3468 | * @param value new color effect. |
| 3469 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3470 | */ |
| 3471 | public void setColorEffect(String value) { |
| 3472 | set(KEY_EFFECT, value); |
| 3473 | } |
| 3474 | |
| 3475 | /** |
| 3476 | * Gets the supported color effects. |
| 3477 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3478 | * @return a list of supported color effects. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3479 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3480 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3481 | */ |
| 3482 | public List<String> getSupportedColorEffects() { |
| 3483 | String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX); |
| 3484 | return split(str); |
| 3485 | } |
| 3486 | |
| 3487 | |
| 3488 | /** |
| 3489 | * Gets the current antibanding setting. |
| 3490 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3491 | * @return current antibanding. null if antibanding setting is not |
| 3492 | * supported. |
| 3493 | * @see #ANTIBANDING_AUTO |
| 3494 | * @see #ANTIBANDING_50HZ |
| 3495 | * @see #ANTIBANDING_60HZ |
| 3496 | * @see #ANTIBANDING_OFF |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3497 | */ |
| 3498 | public String getAntibanding() { |
| 3499 | return get(KEY_ANTIBANDING); |
| 3500 | } |
| 3501 | |
| 3502 | /** |
| 3503 | * Sets the antibanding. |
| 3504 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3505 | * @param antibanding new antibanding value. |
| 3506 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3507 | */ |
| 3508 | public void setAntibanding(String antibanding) { |
| 3509 | set(KEY_ANTIBANDING, antibanding); |
| 3510 | } |
| 3511 | |
| 3512 | /** |
| 3513 | * Gets the supported antibanding values. |
| 3514 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3515 | * @return a list of supported antibanding values. null if antibanding |
| 3516 | * setting is not supported. |
| 3517 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3518 | */ |
| 3519 | public List<String> getSupportedAntibanding() { |
| 3520 | String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX); |
| 3521 | return split(str); |
| 3522 | } |
| 3523 | |
| 3524 | /** |
| 3525 | * Gets the current scene mode setting. |
| 3526 | * |
| 3527 | * @return one of SCENE_MODE_XXX string constant. null if scene mode |
| 3528 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3529 | * @see #SCENE_MODE_AUTO |
| 3530 | * @see #SCENE_MODE_ACTION |
| 3531 | * @see #SCENE_MODE_PORTRAIT |
| 3532 | * @see #SCENE_MODE_LANDSCAPE |
| 3533 | * @see #SCENE_MODE_NIGHT |
| 3534 | * @see #SCENE_MODE_NIGHT_PORTRAIT |
| 3535 | * @see #SCENE_MODE_THEATRE |
| 3536 | * @see #SCENE_MODE_BEACH |
| 3537 | * @see #SCENE_MODE_SNOW |
| 3538 | * @see #SCENE_MODE_SUNSET |
| 3539 | * @see #SCENE_MODE_STEADYPHOTO |
| 3540 | * @see #SCENE_MODE_FIREWORKS |
| 3541 | * @see #SCENE_MODE_SPORTS |
| 3542 | * @see #SCENE_MODE_PARTY |
| 3543 | * @see #SCENE_MODE_CANDLELIGHT |
Eino-Ville Talvala | da2f0ea | 2012-09-10 12:03:35 -0700 | [diff] [blame] | 3544 | * @see #SCENE_MODE_BARCODE |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3545 | */ |
| 3546 | public String getSceneMode() { |
| 3547 | return get(KEY_SCENE_MODE); |
| 3548 | } |
| 3549 | |
| 3550 | /** |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 3551 | * Sets the scene mode. Changing scene mode may override other |
| 3552 | * parameters (such as flash mode, focus mode, white balance). For |
| 3553 | * example, suppose originally flash mode is on and supported flash |
| 3554 | * modes are on/off. In night scene mode, both flash mode and supported |
| 3555 | * flash mode may be changed to off. After setting scene mode, |
Wu-cheng Li | 2988ab7 | 2009-09-30 17:08:19 -0700 | [diff] [blame] | 3556 | * applications should call getParameters to know if some parameters are |
| 3557 | * changed. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3558 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3559 | * @param value scene mode. |
| 3560 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3561 | */ |
| 3562 | public void setSceneMode(String value) { |
| 3563 | set(KEY_SCENE_MODE, value); |
| 3564 | } |
| 3565 | |
| 3566 | /** |
| 3567 | * Gets the supported scene modes. |
| 3568 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3569 | * @return a list of supported scene modes. null if scene mode setting |
| 3570 | * is not supported. |
| 3571 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3572 | */ |
| 3573 | public List<String> getSupportedSceneModes() { |
| 3574 | String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX); |
| 3575 | return split(str); |
| 3576 | } |
| 3577 | |
| 3578 | /** |
| 3579 | * Gets the current flash mode setting. |
| 3580 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3581 | * @return current flash mode. null if flash mode setting is not |
| 3582 | * supported. |
| 3583 | * @see #FLASH_MODE_OFF |
| 3584 | * @see #FLASH_MODE_AUTO |
| 3585 | * @see #FLASH_MODE_ON |
| 3586 | * @see #FLASH_MODE_RED_EYE |
| 3587 | * @see #FLASH_MODE_TORCH |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3588 | */ |
| 3589 | public String getFlashMode() { |
| 3590 | return get(KEY_FLASH_MODE); |
| 3591 | } |
| 3592 | |
| 3593 | /** |
| 3594 | * Sets the flash mode. |
| 3595 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3596 | * @param value flash mode. |
| 3597 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3598 | */ |
| 3599 | public void setFlashMode(String value) { |
| 3600 | set(KEY_FLASH_MODE, value); |
| 3601 | } |
| 3602 | |
| 3603 | /** |
| 3604 | * Gets the supported flash modes. |
| 3605 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3606 | * @return a list of supported flash modes. null if flash mode setting |
| 3607 | * is not supported. |
| 3608 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3609 | */ |
| 3610 | public List<String> getSupportedFlashModes() { |
| 3611 | String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX); |
| 3612 | return split(str); |
| 3613 | } |
| 3614 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3615 | /** |
| 3616 | * Gets the current focus mode setting. |
| 3617 | * |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 3618 | * @return current focus mode. This method will always return a non-null |
| 3619 | * value. Applications should call {@link |
| 3620 | * #autoFocus(AutoFocusCallback)} to start the focus if focus |
| 3621 | * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3622 | * @see #FOCUS_MODE_AUTO |
| 3623 | * @see #FOCUS_MODE_INFINITY |
| 3624 | * @see #FOCUS_MODE_MACRO |
| 3625 | * @see #FOCUS_MODE_FIXED |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 3626 | * @see #FOCUS_MODE_EDOF |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 3627 | * @see #FOCUS_MODE_CONTINUOUS_VIDEO |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3628 | */ |
| 3629 | public String getFocusMode() { |
| 3630 | return get(KEY_FOCUS_MODE); |
| 3631 | } |
| 3632 | |
| 3633 | /** |
| 3634 | * Sets the focus mode. |
| 3635 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3636 | * @param value focus mode. |
| 3637 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3638 | */ |
| 3639 | public void setFocusMode(String value) { |
| 3640 | set(KEY_FOCUS_MODE, value); |
| 3641 | } |
| 3642 | |
| 3643 | /** |
| 3644 | * Gets the supported focus modes. |
| 3645 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3646 | * @return a list of supported focus modes. This method will always |
| 3647 | * return a list with at least one element. |
| 3648 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3649 | */ |
| 3650 | public List<String> getSupportedFocusModes() { |
| 3651 | String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX); |
| 3652 | return split(str); |
| 3653 | } |
| 3654 | |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3655 | /** |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 3656 | * Gets the focal length (in millimeter) of the camera. |
| 3657 | * |
Yin-Chia Yeh | bb85e1c | 2018-02-27 11:50:48 -0800 | [diff] [blame] | 3658 | * @return the focal length. Returns -1.0 when the device |
| 3659 | * doesn't report focal length information. |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 3660 | */ |
| 3661 | public float getFocalLength() { |
| 3662 | return Float.parseFloat(get(KEY_FOCAL_LENGTH)); |
| 3663 | } |
| 3664 | |
| 3665 | /** |
| 3666 | * Gets the horizontal angle of view in degrees. |
| 3667 | * |
Yin-Chia Yeh | 564ae82 | 2018-02-08 16:24:27 -0800 | [diff] [blame] | 3668 | * @return horizontal angle of view. Returns -1.0 when the device |
| 3669 | * doesn't report view angle information. |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 3670 | */ |
| 3671 | public float getHorizontalViewAngle() { |
| 3672 | return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE)); |
| 3673 | } |
| 3674 | |
| 3675 | /** |
| 3676 | * Gets the vertical angle of view in degrees. |
| 3677 | * |
Yin-Chia Yeh | 564ae82 | 2018-02-08 16:24:27 -0800 | [diff] [blame] | 3678 | * @return vertical angle of view. Returns -1.0 when the device |
| 3679 | * doesn't report view angle information. |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 3680 | */ |
| 3681 | public float getVerticalViewAngle() { |
| 3682 | return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE)); |
| 3683 | } |
| 3684 | |
| 3685 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3686 | * Gets the current exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3687 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3688 | * @return current exposure compensation index. The range is {@link |
| 3689 | * #getMinExposureCompensation} to {@link |
| 3690 | * #getMaxExposureCompensation}. 0 means exposure is not |
| 3691 | * adjusted. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3692 | */ |
| 3693 | public int getExposureCompensation() { |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3694 | return getInt(KEY_EXPOSURE_COMPENSATION, 0); |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3698 | * Sets the exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3699 | * |
Wu-cheng Li | 0402e7d | 2010-02-26 15:04:55 +0800 | [diff] [blame] | 3700 | * @param value exposure compensation index. The valid value range is |
| 3701 | * from {@link #getMinExposureCompensation} (inclusive) to {@link |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3702 | * #getMaxExposureCompensation} (inclusive). 0 means exposure is |
| 3703 | * not adjusted. Application should call |
| 3704 | * getMinExposureCompensation and getMaxExposureCompensation to |
| 3705 | * know if exposure compensation is supported. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3706 | */ |
| 3707 | public void setExposureCompensation(int value) { |
| 3708 | set(KEY_EXPOSURE_COMPENSATION, value); |
| 3709 | } |
| 3710 | |
| 3711 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3712 | * Gets the maximum exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3713 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3714 | * @return maximum exposure compensation index (>=0). If both this |
| 3715 | * method and {@link #getMinExposureCompensation} return 0, |
| 3716 | * exposure compensation is not supported. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3717 | */ |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3718 | public int getMaxExposureCompensation() { |
| 3719 | return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0); |
| 3720 | } |
| 3721 | |
| 3722 | /** |
| 3723 | * Gets the minimum exposure compensation index. |
| 3724 | * |
| 3725 | * @return minimum exposure compensation index (<=0). If both this |
| 3726 | * method and {@link #getMaxExposureCompensation} return 0, |
| 3727 | * exposure compensation is not supported. |
| 3728 | */ |
| 3729 | public int getMinExposureCompensation() { |
| 3730 | return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0); |
| 3731 | } |
| 3732 | |
| 3733 | /** |
| 3734 | * Gets the exposure compensation step. |
| 3735 | * |
| 3736 | * @return exposure compensation step. Applications can get EV by |
| 3737 | * multiplying the exposure compensation index and step. Ex: if |
| 3738 | * exposure compensation index is -6 and step is 0.333333333, EV |
| 3739 | * is -2. |
| 3740 | */ |
| 3741 | public float getExposureCompensationStep() { |
| 3742 | return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0); |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | /** |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3746 | * <p>Sets the auto-exposure lock state. Applications should check |
| 3747 | * {@link #isAutoExposureLockSupported} before using this method.</p> |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3748 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3749 | * <p>If set to true, the camera auto-exposure routine will immediately |
| 3750 | * pause until the lock is set to false. Exposure compensation settings |
| 3751 | * changes will still take effect while auto-exposure is locked.</p> |
| 3752 | * |
| 3753 | * <p>If auto-exposure is already locked, setting this to true again has |
| 3754 | * no effect (the driver will not recalculate exposure values).</p> |
| 3755 | * |
| 3756 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 3757 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3758 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 3759 | * lock.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3760 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3761 | * <p>Exposure compensation, auto-exposure lock, and auto-white balance |
| 3762 | * lock can be used to capture an exposure-bracketed burst of images, |
| 3763 | * for example.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3764 | * |
| 3765 | * <p>Auto-exposure state, including the lock state, will not be |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3766 | * maintained after camera {@link #release()} is called. Locking |
| 3767 | * auto-exposure after {@link #open()} but before the first call to |
| 3768 | * {@link #startPreview()} will not allow the auto-exposure routine to |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3769 | * run at all, and may result in severely over- or under-exposed |
| 3770 | * images.</p> |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3771 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3772 | * @param toggle new state of the auto-exposure lock. True means that |
| 3773 | * auto-exposure is locked, false means that the auto-exposure |
| 3774 | * routine is free to run normally. |
| 3775 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3776 | * @see #getAutoExposureLock() |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3777 | */ |
| 3778 | public void setAutoExposureLock(boolean toggle) { |
| 3779 | set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE); |
| 3780 | } |
| 3781 | |
| 3782 | /** |
| 3783 | * Gets the state of the auto-exposure lock. Applications should check |
| 3784 | * {@link #isAutoExposureLockSupported} before using this method. See |
| 3785 | * {@link #setAutoExposureLock} for details about the lock. |
| 3786 | * |
| 3787 | * @return State of the auto-exposure lock. Returns true if |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3788 | * auto-exposure is currently locked, and false otherwise. |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3789 | * |
| 3790 | * @see #setAutoExposureLock(boolean) |
| 3791 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3792 | */ |
| 3793 | public boolean getAutoExposureLock() { |
| 3794 | String str = get(KEY_AUTO_EXPOSURE_LOCK); |
| 3795 | return TRUE.equals(str); |
| 3796 | } |
| 3797 | |
| 3798 | /** |
| 3799 | * Returns true if auto-exposure locking is supported. Applications |
| 3800 | * should call this before trying to lock auto-exposure. See |
| 3801 | * {@link #setAutoExposureLock} for details about the lock. |
| 3802 | * |
| 3803 | * @return true if auto-exposure lock is supported. |
| 3804 | * @see #setAutoExposureLock(boolean) |
| 3805 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3806 | */ |
| 3807 | public boolean isAutoExposureLockSupported() { |
| 3808 | String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED); |
| 3809 | return TRUE.equals(str); |
| 3810 | } |
| 3811 | |
| 3812 | /** |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3813 | * <p>Sets the auto-white balance lock state. Applications should check |
| 3814 | * {@link #isAutoWhiteBalanceLockSupported} before using this |
| 3815 | * method.</p> |
| 3816 | * |
| 3817 | * <p>If set to true, the camera auto-white balance routine will |
| 3818 | * immediately pause until the lock is set to false.</p> |
| 3819 | * |
| 3820 | * <p>If auto-white balance is already locked, setting this to true |
| 3821 | * again has no effect (the driver will not recalculate white balance |
| 3822 | * values).</p> |
| 3823 | * |
| 3824 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 3825 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3826 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 3827 | * the lock.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3828 | * |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3829 | * <p> Changing the white balance mode with {@link #setWhiteBalance} |
| 3830 | * will release the auto-white balance lock if it is set.</p> |
| 3831 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3832 | * <p>Exposure compensation, AE lock, and AWB lock can be used to |
| 3833 | * capture an exposure-bracketed burst of images, for example. |
| 3834 | * Auto-white balance state, including the lock state, will not be |
| 3835 | * maintained after camera {@link #release()} is called. Locking |
| 3836 | * auto-white balance after {@link #open()} but before the first call to |
| 3837 | * {@link #startPreview()} will not allow the auto-white balance routine |
| 3838 | * to run at all, and may result in severely incorrect color in captured |
| 3839 | * images.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3840 | * |
| 3841 | * @param toggle new state of the auto-white balance lock. True means |
| 3842 | * that auto-white balance is locked, false means that the |
| 3843 | * auto-white balance routine is free to run normally. |
| 3844 | * |
| 3845 | * @see #getAutoWhiteBalanceLock() |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3846 | * @see #setWhiteBalance(String) |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3847 | */ |
| 3848 | public void setAutoWhiteBalanceLock(boolean toggle) { |
| 3849 | set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE); |
| 3850 | } |
| 3851 | |
| 3852 | /** |
| 3853 | * Gets the state of the auto-white balance lock. Applications should |
| 3854 | * check {@link #isAutoWhiteBalanceLockSupported} before using this |
| 3855 | * method. See {@link #setAutoWhiteBalanceLock} for details about the |
| 3856 | * lock. |
| 3857 | * |
| 3858 | * @return State of the auto-white balance lock. Returns true if |
| 3859 | * auto-white balance is currently locked, and false |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3860 | * otherwise. |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3861 | * |
| 3862 | * @see #setAutoWhiteBalanceLock(boolean) |
| 3863 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3864 | */ |
| 3865 | public boolean getAutoWhiteBalanceLock() { |
| 3866 | String str = get(KEY_AUTO_WHITEBALANCE_LOCK); |
| 3867 | return TRUE.equals(str); |
| 3868 | } |
| 3869 | |
| 3870 | /** |
| 3871 | * Returns true if auto-white balance locking is supported. Applications |
| 3872 | * should call this before trying to lock auto-white balance. See |
| 3873 | * {@link #setAutoWhiteBalanceLock} for details about the lock. |
| 3874 | * |
| 3875 | * @return true if auto-white balance lock is supported. |
| 3876 | * @see #setAutoWhiteBalanceLock(boolean) |
| 3877 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3878 | */ |
| 3879 | public boolean isAutoWhiteBalanceLockSupported() { |
| 3880 | String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED); |
| 3881 | return TRUE.equals(str); |
| 3882 | } |
| 3883 | |
| 3884 | /** |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3885 | * Gets current zoom value. This also works when smooth zoom is in |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3886 | * progress. Applications should check {@link #isZoomSupported} before |
| 3887 | * using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3888 | * |
| 3889 | * @return the current zoom value. The range is 0 to {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3890 | * #getMaxZoom}. 0 means the camera is not zoomed. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3891 | */ |
| 3892 | public int getZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3893 | return getInt(KEY_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3897 | * Sets current zoom value. If the camera is zoomed (value > 0), the |
| 3898 | * actual picture size may be smaller than picture size setting. |
| 3899 | * Applications can check the actual picture size after picture is |
| 3900 | * returned from {@link PictureCallback}. The preview size remains the |
| 3901 | * same in zoom. Applications should check {@link #isZoomSupported} |
| 3902 | * before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3903 | * |
| 3904 | * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3905 | */ |
| 3906 | public void setZoom(int value) { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3907 | set(KEY_ZOOM, value); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | /** |
| 3911 | * Returns true if zoom is supported. Applications should call this |
| 3912 | * before using other zoom methods. |
| 3913 | * |
| 3914 | * @return true if zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3915 | */ |
| 3916 | public boolean isZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3917 | String str = get(KEY_ZOOM_SUPPORTED); |
| 3918 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | /** |
| 3922 | * Gets the maximum zoom value allowed for snapshot. This is the maximum |
| 3923 | * value that applications can set to {@link #setZoom(int)}. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3924 | * Applications should call {@link #isZoomSupported} before using this |
| 3925 | * method. This value may change in different preview size. Applications |
| 3926 | * should call this again after setting preview size. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3927 | * |
| 3928 | * @return the maximum zoom value supported by the camera. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3929 | */ |
| 3930 | public int getMaxZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3931 | return getInt(KEY_MAX_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3935 | * Gets the zoom ratios of all zoom values. Applications should check |
| 3936 | * {@link #isZoomSupported} before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3937 | * |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3938 | * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is |
| 3939 | * returned as 320. The number of elements is {@link |
| 3940 | * #getMaxZoom} + 1. The list is sorted from small to large. The |
| 3941 | * first element is always 100. The last element is the zoom |
| 3942 | * ratio of the maximum zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3943 | */ |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3944 | public List<Integer> getZoomRatios() { |
| 3945 | return splitInt(get(KEY_ZOOM_RATIOS)); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | /** |
| 3949 | * Returns true if smooth zoom is supported. Applications should call |
| 3950 | * this before using other smooth zoom methods. |
| 3951 | * |
| 3952 | * @return true if smooth zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3953 | */ |
| 3954 | public boolean isSmoothZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3955 | String str = get(KEY_SMOOTH_ZOOM_SUPPORTED); |
| 3956 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3959 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3960 | * <p>Gets the distances from the camera to where an object appears to be |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3961 | * in focus. The object is sharpest at the optimal focus distance. The |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3962 | * depth of field is the far focus distance minus near focus distance.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3963 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3964 | * <p>Focus distances may change after calling {@link |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3965 | * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link |
| 3966 | * #startPreview()}. Applications can call {@link #getParameters()} |
| 3967 | * and this method anytime to get the latest focus distances. If the |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 3968 | * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3969 | * from time to time.</p> |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 3970 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3971 | * <p>This method is intended to estimate the distance between the camera |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 3972 | * and the subject. After autofocus, the subject distance may be within |
| 3973 | * near and far focus distance. However, the precision depends on the |
| 3974 | * camera hardware, autofocus algorithm, the focus area, and the scene. |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3975 | * The error can be large and it should be only used as a reference.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3976 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3977 | * <p>Far focus distance >= optimal focus distance >= near focus distance. |
Wu-cheng Li | 185cc45 | 2010-05-20 15:36:13 +0800 | [diff] [blame] | 3978 | * If the focus distance is infinity, the value will be |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3979 | * {@code Float.POSITIVE_INFINITY}.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3980 | * |
| 3981 | * @param output focus distances in meters. output must be a float |
| 3982 | * array with three elements. Near focus distance, optimal focus |
| 3983 | * distance, and far focus distance will be filled in the array. |
Wu-cheng Li | 185cc45 | 2010-05-20 15:36:13 +0800 | [diff] [blame] | 3984 | * @see #FOCUS_DISTANCE_NEAR_INDEX |
| 3985 | * @see #FOCUS_DISTANCE_OPTIMAL_INDEX |
| 3986 | * @see #FOCUS_DISTANCE_FAR_INDEX |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3987 | */ |
| 3988 | public void getFocusDistances(float[] output) { |
| 3989 | if (output == null || output.length != 3) { |
| 3990 | throw new IllegalArgumentException( |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 3991 | "output must be a float array with three elements."); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3992 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3993 | splitFloat(get(KEY_FOCUS_DISTANCES), output); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3994 | } |
| 3995 | |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3996 | /** |
| 3997 | * Gets the maximum number of focus areas supported. This is the maximum |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3998 | * length of the list in {@link #setFocusAreas(List)} and |
| 3999 | * {@link #getFocusAreas()}. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4000 | * |
| 4001 | * @return the maximum number of focus areas supported by the camera. |
| 4002 | * @see #getFocusAreas() |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4003 | */ |
| 4004 | public int getMaxNumFocusAreas() { |
| 4005 | return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0); |
| 4006 | } |
| 4007 | |
| 4008 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4009 | * <p>Gets the current focus areas. Camera driver uses the areas to decide |
| 4010 | * focus.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4011 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4012 | * <p>Before using this API or {@link #setFocusAreas(List)}, apps should |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4013 | * call {@link #getMaxNumFocusAreas()} to know the maximum number of |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4014 | * focus areas first. If the value is 0, focus area is not supported.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4015 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4016 | * <p>Each focus area is a rectangle with specified weight. The direction |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4017 | * is relative to the sensor orientation, that is, what the sensor sees. |
| 4018 | * The direction is not affected by the rotation or mirroring of |
| 4019 | * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle |
| 4020 | * range from -1000 to 1000. (-1000, -1000) is the upper left point. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 4021 | * (1000, 1000) is the lower right point. The width and height of focus |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4022 | * areas cannot be 0 or negative.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4023 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4024 | * <p>The weight must range from 1 to 1000. The weight should be |
Eino-Ville Talvala | 4e396e0 | 2011-04-21 09:23:15 -0700 | [diff] [blame] | 4025 | * interpreted as a per-pixel weight - all pixels in the area have the |
| 4026 | * specified weight. This means a small area with the same weight as a |
| 4027 | * larger area will have less influence on the focusing than the larger |
| 4028 | * area. Focus areas can partially overlap and the driver will add the |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4029 | * weights in the overlap region.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4030 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4031 | * <p>A special case of a {@code null} focus area list means the driver is |
| 4032 | * free to select focus targets as it wants. For example, the driver may |
| 4033 | * use more signals to select focus areas and change them |
| 4034 | * dynamically. Apps can set the focus area list to {@code null} if they |
| 4035 | * want the driver to completely control focusing.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4036 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4037 | * <p>Focus areas are relative to the current field of view |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4038 | * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) |
| 4039 | * represents the top of the currently visible camera frame. The focus |
| 4040 | * area cannot be set to be outside the current field of view, even |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4041 | * when using zoom.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4042 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4043 | * <p>Focus area only has effect if the current focus mode is |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 4044 | * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, |
| 4045 | * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or |
| 4046 | * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4047 | * |
| 4048 | * @return a list of current focus areas |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4049 | */ |
| 4050 | public List<Area> getFocusAreas() { |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4051 | return splitArea(get(KEY_FOCUS_AREAS)); |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | /** |
| 4055 | * Sets focus areas. See {@link #getFocusAreas()} for documentation. |
| 4056 | * |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4057 | * @param focusAreas the focus areas |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4058 | * @see #getFocusAreas() |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4059 | */ |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4060 | public void setFocusAreas(List<Area> focusAreas) { |
| 4061 | set(KEY_FOCUS_AREAS, focusAreas); |
| 4062 | } |
| 4063 | |
| 4064 | /** |
| 4065 | * Gets the maximum number of metering areas supported. This is the |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4066 | * maximum length of the list in {@link #setMeteringAreas(List)} and |
| 4067 | * {@link #getMeteringAreas()}. |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4068 | * |
| 4069 | * @return the maximum number of metering areas supported by the camera. |
| 4070 | * @see #getMeteringAreas() |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4071 | */ |
| 4072 | public int getMaxNumMeteringAreas() { |
| 4073 | return getInt(KEY_MAX_NUM_METERING_AREAS, 0); |
| 4074 | } |
| 4075 | |
| 4076 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4077 | * <p>Gets the current metering areas. Camera driver uses these areas to |
| 4078 | * decide exposure.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4079 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4080 | * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4081 | * call {@link #getMaxNumMeteringAreas()} to know the maximum number of |
| 4082 | * metering areas first. If the value is 0, metering area is not |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4083 | * supported.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4084 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4085 | * <p>Each metering area is a rectangle with specified weight. The |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4086 | * direction is relative to the sensor orientation, that is, what the |
| 4087 | * sensor sees. The direction is not affected by the rotation or |
| 4088 | * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the |
| 4089 | * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 4090 | * point. (1000, 1000) is the lower right point. The width and height of |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4091 | * metering areas cannot be 0 or negative.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4092 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4093 | * <p>The weight must range from 1 to 1000, and represents a weight for |
Eino-Ville Talvala | 4e396e0 | 2011-04-21 09:23:15 -0700 | [diff] [blame] | 4094 | * every pixel in the area. This means that a large metering area with |
| 4095 | * the same weight as a smaller area will have more effect in the |
| 4096 | * metering result. Metering areas can partially overlap and the driver |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4097 | * will add the weights in the overlap region.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4098 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4099 | * <p>A special case of a {@code null} metering area list means the driver |
| 4100 | * is free to meter as it chooses. For example, the driver may use more |
| 4101 | * signals to select metering areas and change them dynamically. Apps |
| 4102 | * can set the metering area list to {@code null} if they want the |
| 4103 | * driver to completely control metering.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4104 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4105 | * <p>Metering areas are relative to the current field of view |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4106 | * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) |
| 4107 | * represents the top of the currently visible camera frame. The |
| 4108 | * metering area cannot be set to be outside the current field of view, |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4109 | * even when using zoom.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4110 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4111 | * <p>No matter what metering areas are, the final exposure are compensated |
| 4112 | * by {@link #setExposureCompensation(int)}.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4113 | * |
| 4114 | * @return a list of current metering areas |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4115 | */ |
| 4116 | public List<Area> getMeteringAreas() { |
Wu-cheng Li | d8aab93 | 2011-06-21 11:50:43 +0800 | [diff] [blame] | 4117 | return splitArea(get(KEY_METERING_AREAS)); |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | /** |
| 4121 | * Sets metering areas. See {@link #getMeteringAreas()} for |
| 4122 | * documentation. |
| 4123 | * |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4124 | * @param meteringAreas the metering areas |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4125 | * @see #getMeteringAreas() |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4126 | */ |
| 4127 | public void setMeteringAreas(List<Area> meteringAreas) { |
| 4128 | set(KEY_METERING_AREAS, meteringAreas); |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4129 | } |
| 4130 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 4131 | /** |
| 4132 | * Gets the maximum number of detected faces supported. This is the |
| 4133 | * maximum length of the list returned from {@link FaceDetectionListener}. |
| 4134 | * If the return value is 0, face detection of the specified type is not |
| 4135 | * supported. |
| 4136 | * |
| 4137 | * @return the maximum number of detected face supported by the camera. |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 4138 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 4139 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 4140 | public int getMaxNumDetectedFaces() { |
| 4141 | return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 4142 | } |
| 4143 | |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4144 | /** |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 4145 | * Sets recording mode hint. This tells the camera that the intent of |
| 4146 | * the application is to record videos {@link |
| 4147 | * android.media.MediaRecorder#start()}, not to take still pictures |
| 4148 | * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, |
| 4149 | * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can |
| 4150 | * allow MediaRecorder.start() to start faster or with fewer glitches on |
| 4151 | * output. This should be called before starting preview for the best |
| 4152 | * result, but can be changed while the preview is active. The default |
| 4153 | * value is false. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4154 | * |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 4155 | * The app can still call takePicture() when the hint is true or call |
| 4156 | * MediaRecorder.start() when the hint is false. But the performance may |
| 4157 | * be worse. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4158 | * |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 4159 | * @param hint true if the apps intend to record videos using |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4160 | * {@link android.media.MediaRecorder}. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4161 | */ |
| 4162 | public void setRecordingHint(boolean hint) { |
| 4163 | set(KEY_RECORDING_HINT, hint ? TRUE : FALSE); |
| 4164 | } |
| 4165 | |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4166 | /** |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4167 | * <p>Returns true if video snapshot is supported. That is, applications |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4168 | * can call {@link #takePicture(Camera.ShutterCallback, |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4169 | * Camera.PictureCallback, Camera.PictureCallback, |
| 4170 | * Camera.PictureCallback)} during recording. Applications do not need |
| 4171 | * to call {@link #startPreview()} after taking a picture. The preview |
| 4172 | * will be still active. Other than that, taking a picture during |
| 4173 | * recording is identical to taking a picture normally. All settings and |
| 4174 | * methods related to takePicture work identically. Ex: |
| 4175 | * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()}, |
| 4176 | * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The |
| 4177 | * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and |
| 4178 | * {@link #FLASH_MODE_ON} also still work, but the video will record the |
| 4179 | * flash.</p> |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4180 | * |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4181 | * <p>Applications can set shutter callback as null to avoid the shutter |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4182 | * sound. It is also recommended to set raw picture and post view |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4183 | * callbacks to null to avoid the interrupt of preview display.</p> |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4184 | * |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4185 | * <p>Field-of-view of the recorded video may be different from that of the |
| 4186 | * captured pictures. The maximum size of a video snapshot may be |
| 4187 | * smaller than that for regular still captures. If the current picture |
| 4188 | * size is set higher than can be supported by video snapshot, the |
| 4189 | * picture will be captured at the maximum supported size instead.</p> |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4190 | * |
| 4191 | * @return true if video snapshot is supported. |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4192 | */ |
| 4193 | public boolean isVideoSnapshotSupported() { |
| 4194 | String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED); |
| 4195 | return TRUE.equals(str); |
| 4196 | } |
| 4197 | |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4198 | /** |
| 4199 | * <p>Enables and disables video stabilization. Use |
| 4200 | * {@link #isVideoStabilizationSupported} to determine if calling this |
| 4201 | * method is valid.</p> |
| 4202 | * |
| 4203 | * <p>Video stabilization reduces the shaking due to the motion of the |
| 4204 | * camera in both the preview stream and in recorded videos, including |
| 4205 | * data received from the preview callback. It does not reduce motion |
| 4206 | * blur in images captured with |
| 4207 | * {@link Camera#takePicture takePicture}.</p> |
| 4208 | * |
| 4209 | * <p>Video stabilization can be enabled and disabled while preview or |
| 4210 | * recording is active, but toggling it may cause a jump in the video |
| 4211 | * stream that may be undesirable in a recorded video.</p> |
| 4212 | * |
| 4213 | * @param toggle Set to true to enable video stabilization, and false to |
| 4214 | * disable video stabilization. |
| 4215 | * @see #isVideoStabilizationSupported() |
| 4216 | * @see #getVideoStabilization() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4217 | */ |
| 4218 | public void setVideoStabilization(boolean toggle) { |
| 4219 | set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE); |
| 4220 | } |
| 4221 | |
| 4222 | /** |
| 4223 | * Get the current state of video stabilization. See |
| 4224 | * {@link #setVideoStabilization} for details of video stabilization. |
| 4225 | * |
| 4226 | * @return true if video stabilization is enabled |
| 4227 | * @see #isVideoStabilizationSupported() |
| 4228 | * @see #setVideoStabilization(boolean) |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4229 | */ |
| 4230 | public boolean getVideoStabilization() { |
| 4231 | String str = get(KEY_VIDEO_STABILIZATION); |
| 4232 | return TRUE.equals(str); |
| 4233 | } |
| 4234 | |
| 4235 | /** |
| 4236 | * Returns true if video stabilization is supported. See |
| 4237 | * {@link #setVideoStabilization} for details of video stabilization. |
| 4238 | * |
| 4239 | * @return true if video stabilization is supported |
| 4240 | * @see #setVideoStabilization(boolean) |
| 4241 | * @see #getVideoStabilization() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4242 | */ |
| 4243 | public boolean isVideoStabilizationSupported() { |
| 4244 | String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED); |
| 4245 | return TRUE.equals(str); |
| 4246 | } |
| 4247 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4248 | // Splits a comma delimited string to an ArrayList of String. |
| 4249 | // Return null if the passing string is null or the size is 0. |
| 4250 | private ArrayList<String> split(String str) { |
| 4251 | if (str == null) return null; |
| 4252 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4253 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4254 | splitter.setString(str); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4255 | ArrayList<String> substrings = new ArrayList<String>(); |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4256 | for (String s : splitter) { |
| 4257 | substrings.add(s); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4258 | } |
| 4259 | return substrings; |
| 4260 | } |
| 4261 | |
| 4262 | // Splits a comma delimited string to an ArrayList of Integer. |
| 4263 | // Return null if the passing string is null or the size is 0. |
| 4264 | private ArrayList<Integer> splitInt(String str) { |
| 4265 | if (str == null) return null; |
| 4266 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4267 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4268 | splitter.setString(str); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4269 | ArrayList<Integer> substrings = new ArrayList<Integer>(); |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4270 | for (String s : splitter) { |
| 4271 | substrings.add(Integer.parseInt(s)); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4272 | } |
| 4273 | if (substrings.size() == 0) return null; |
| 4274 | return substrings; |
| 4275 | } |
| 4276 | |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4277 | private void splitInt(String str, int[] output) { |
| 4278 | if (str == null) return; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4279 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4280 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4281 | splitter.setString(str); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4282 | int index = 0; |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4283 | for (String s : splitter) { |
| 4284 | output[index++] = Integer.parseInt(s); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4285 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | // Splits a comma delimited string to an ArrayList of Float. |
| 4289 | private void splitFloat(String str, float[] output) { |
| 4290 | if (str == null) return; |
| 4291 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4292 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4293 | splitter.setString(str); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4294 | int index = 0; |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4295 | for (String s : splitter) { |
| 4296 | output[index++] = Float.parseFloat(s); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4297 | } |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4298 | } |
| 4299 | |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4300 | // Returns the value of a float parameter. |
| 4301 | private float getFloat(String key, float defaultValue) { |
| 4302 | try { |
| 4303 | return Float.parseFloat(mMap.get(key)); |
| 4304 | } catch (NumberFormatException ex) { |
| 4305 | return defaultValue; |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | // Returns the value of a integer parameter. |
| 4310 | private int getInt(String key, int defaultValue) { |
| 4311 | try { |
| 4312 | return Integer.parseInt(mMap.get(key)); |
| 4313 | } catch (NumberFormatException ex) { |
| 4314 | return defaultValue; |
| 4315 | } |
| 4316 | } |
| 4317 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4318 | // Splits a comma delimited string to an ArrayList of Size. |
| 4319 | // Return null if the passing string is null or the size is 0. |
| 4320 | private ArrayList<Size> splitSize(String str) { |
| 4321 | if (str == null) return null; |
| 4322 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4323 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4324 | splitter.setString(str); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4325 | ArrayList<Size> sizeList = new ArrayList<Size>(); |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4326 | for (String s : splitter) { |
| 4327 | Size size = strToSize(s); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4328 | if (size != null) sizeList.add(size); |
| 4329 | } |
| 4330 | if (sizeList.size() == 0) return null; |
| 4331 | return sizeList; |
| 4332 | } |
| 4333 | |
| 4334 | // Parses a string (ex: "480x320") to Size object. |
| 4335 | // Return null if the passing string is null. |
| 4336 | private Size strToSize(String str) { |
| 4337 | if (str == null) return null; |
| 4338 | |
| 4339 | int pos = str.indexOf('x'); |
| 4340 | if (pos != -1) { |
| 4341 | String width = str.substring(0, pos); |
| 4342 | String height = str.substring(pos + 1); |
| 4343 | return new Size(Integer.parseInt(width), |
| 4344 | Integer.parseInt(height)); |
| 4345 | } |
| 4346 | Log.e(TAG, "Invalid size parameter string=" + str); |
| 4347 | return null; |
| 4348 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4349 | |
| 4350 | // Splits a comma delimited string to an ArrayList of int array. |
| 4351 | // Example string: "(10000,26623),(10000,30000)". Return null if the |
| 4352 | // passing string is null or the size is 0. |
| 4353 | private ArrayList<int[]> splitRange(String str) { |
| 4354 | if (str == null || str.charAt(0) != '(' |
| 4355 | || str.charAt(str.length() - 1) != ')') { |
| 4356 | Log.e(TAG, "Invalid range list string=" + str); |
| 4357 | return null; |
| 4358 | } |
| 4359 | |
| 4360 | ArrayList<int[]> rangeList = new ArrayList<int[]>(); |
| 4361 | int endIndex, fromIndex = 1; |
| 4362 | do { |
| 4363 | int[] range = new int[2]; |
| 4364 | endIndex = str.indexOf("),(", fromIndex); |
| 4365 | if (endIndex == -1) endIndex = str.length() - 1; |
| 4366 | splitInt(str.substring(fromIndex, endIndex), range); |
| 4367 | rangeList.add(range); |
| 4368 | fromIndex = endIndex + 3; |
| 4369 | } while (endIndex != str.length() - 1); |
| 4370 | |
| 4371 | if (rangeList.size() == 0) return null; |
| 4372 | return rangeList; |
| 4373 | } |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4374 | |
| 4375 | // Splits a comma delimited string to an ArrayList of Area objects. |
| 4376 | // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4377 | // the passing string is null or the size is 0 or (0,0,0,0,0). |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4378 | private ArrayList<Area> splitArea(String str) { |
| 4379 | if (str == null || str.charAt(0) != '(' |
| 4380 | || str.charAt(str.length() - 1) != ')') { |
| 4381 | Log.e(TAG, "Invalid area string=" + str); |
| 4382 | return null; |
| 4383 | } |
| 4384 | |
| 4385 | ArrayList<Area> result = new ArrayList<Area>(); |
| 4386 | int endIndex, fromIndex = 1; |
| 4387 | int[] array = new int[5]; |
| 4388 | do { |
| 4389 | endIndex = str.indexOf("),(", fromIndex); |
| 4390 | if (endIndex == -1) endIndex = str.length() - 1; |
| 4391 | splitInt(str.substring(fromIndex, endIndex), array); |
| 4392 | Rect rect = new Rect(array[0], array[1], array[2], array[3]); |
| 4393 | result.add(new Area(rect, array[4])); |
| 4394 | fromIndex = endIndex + 3; |
| 4395 | } while (endIndex != str.length() - 1); |
| 4396 | |
| 4397 | if (result.size() == 0) return null; |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4398 | |
| 4399 | if (result.size() == 1) { |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 4400 | Area area = result.get(0); |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4401 | Rect rect = area.rect; |
| 4402 | if (rect.left == 0 && rect.top == 0 && rect.right == 0 |
| 4403 | && rect.bottom == 0 && area.weight == 0) { |
| 4404 | return null; |
| 4405 | } |
| 4406 | } |
| 4407 | |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4408 | return result; |
| 4409 | } |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 4410 | |
| 4411 | private boolean same(String s1, String s2) { |
| 4412 | if (s1 == null && s2 == null) return true; |
| 4413 | if (s1 != null && s1.equals(s2)) return true; |
| 4414 | return false; |
| 4415 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | }; |
| 4417 | } |