Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Eino-Ville Talvala | 2f1a2e4 | 2013-07-25 17:12:05 -0700 | [diff] [blame] | 17 | package android.hardware.camera2; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 18 | |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 19 | import android.os.Handler; |
Zhijun He | 599be61 | 2013-09-27 13:43:25 -0700 | [diff] [blame] | 20 | import android.view.Surface; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 21 | |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 22 | import java.util.List; |
| 23 | |
| 24 | /** |
| 25 | * <p>The CameraDevice class is an interface to a single camera connected to an |
| 26 | * Android device, allowing for fine-grain control of image capture and |
| 27 | * post-processing at high frame rates.</p> |
| 28 | * |
| 29 | * <p>Your application must declare the |
| 30 | * {@link android.Manifest.permission#CAMERA Camera} permission in its manifest |
| 31 | * in order to access camera devices.</p> |
| 32 | * |
| 33 | * <p>A given camera device may provide support at one of two levels: limited or |
| 34 | * full. If a device only supports the limited level, then Camera2 exposes a |
| 35 | * feature set that is roughly equivalent to the older |
| 36 | * {@link android.hardware.Camera Camera} API, although with a cleaner and more |
| 37 | * efficient interface. Devices that implement the full level of support |
| 38 | * provide substantially improved capabilities over the older camera |
| 39 | * API. Applications that target the limited level devices will run unchanged on |
| 40 | * the full-level devices; if your application requires a full-level device for |
| 41 | * proper operation, declare the "android.hardware.camera2.full" feature in your |
| 42 | * manifest.</p> |
| 43 | * |
| 44 | * @see CameraManager#openCamera |
| 45 | * @see android.Manifest.permission#CAMERA |
| 46 | */ |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 47 | public interface CameraDevice extends AutoCloseable { |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Create a request suitable for a camera preview window. Specifically, this |
| 51 | * means that high frame rate is given priority over the highest-quality |
| 52 | * post-processing. These requests would normally be used with the |
| 53 | * {@link #setRepeatingRequest} method. |
| 54 | * |
| 55 | * @see #createCaptureRequest |
| 56 | */ |
| 57 | public static final int TEMPLATE_PREVIEW = 1; |
| 58 | |
| 59 | /** |
Zhijun He | b8b77bf | 2013-06-28 16:30:12 -0700 | [diff] [blame] | 60 | * Create a request suitable for still image capture. Specifically, this |
| 61 | * means prioritizing image quality over frame rate. These requests would |
| 62 | * commonly be used with the {@link #capture} method. |
| 63 | * |
| 64 | * @see #createCaptureRequest |
| 65 | */ |
| 66 | public static final int TEMPLATE_STILL_CAPTURE = 2; |
| 67 | |
| 68 | /** |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 69 | * Create a request suitable for video recording. Specifically, this means |
| 70 | * that a stable frame rate is used, and post-processing is set for |
| 71 | * recording quality. These requests would commonly be used with the |
| 72 | * {@link #setRepeatingRequest} method. |
| 73 | * |
| 74 | * @see #createCaptureRequest |
| 75 | */ |
Zhijun He | b8b77bf | 2013-06-28 16:30:12 -0700 | [diff] [blame] | 76 | public static final int TEMPLATE_RECORD = 3; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Create a request suitable for still image capture while recording |
| 80 | * video. Specifically, this means maximizing image quality without |
| 81 | * disrupting the ongoing recording. These requests would commonly be used |
| 82 | * with the {@link #capture} method while a request based on |
| 83 | * {@link #TEMPLATE_RECORD} is is in use with {@link #setRepeatingRequest}. |
| 84 | * |
| 85 | * @see #createCaptureRequest |
| 86 | */ |
| 87 | public static final int TEMPLATE_VIDEO_SNAPSHOT = 4; |
| 88 | |
| 89 | /** |
Zhijun He | bbae94a | 2013-09-13 11:32:20 -0700 | [diff] [blame] | 90 | * Create a request suitable for zero shutter lag still capture. This means |
| 91 | * means maximizing image quality without compromising preview frame rate. |
| 92 | * AE/AWB/AF should be on auto mode. |
| 93 | * |
| 94 | * @see #createCaptureRequest |
| 95 | * @hide |
| 96 | */ |
| 97 | public static final int TEMPLATE_ZERO_SHUTTER_LAG = 5; |
| 98 | |
| 99 | /** |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 100 | * A basic template for direct application control of capture |
| 101 | * parameters. All automatic control is disabled (auto-exposure, auto-white |
| 102 | * balance, auto-focus), and post-processing parameters are set to preview |
| 103 | * quality. The manual capture parameters (exposure, sensitivity, and so on) |
| 104 | * are set to reasonable defaults, but should be overriden by the |
| 105 | * application depending on the intended use case. |
| 106 | * |
| 107 | * @see #createCaptureRequest |
Zhijun He | bbae94a | 2013-09-13 11:32:20 -0700 | [diff] [blame] | 108 | * @hide |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 109 | */ |
Zhijun He | bbae94a | 2013-09-13 11:32:20 -0700 | [diff] [blame] | 110 | public static final int TEMPLATE_MANUAL = 6; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 111 | |
| 112 | /** |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 113 | * Get the ID of this camera device. |
| 114 | * |
| 115 | * <p>This matches the ID given to {@link CameraManager#openCamera} to instantiate this |
| 116 | * this camera device.</p> |
| 117 | * |
| 118 | * <p>This ID can be used to query the camera device's {@link |
Igor Murashkin | 68f4006 | 2013-09-10 12:15:54 -0700 | [diff] [blame] | 119 | * CameraCharacteristics fixed properties} with {@link |
| 120 | * CameraManager#getCameraCharacteristics}.</p> |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 121 | * |
| 122 | * <p>This method can be called even if the device has been closed or has encountered |
| 123 | * a serious error.</p> |
| 124 | * |
| 125 | * @return the ID for this camera device |
| 126 | * |
Igor Murashkin | 68f4006 | 2013-09-10 12:15:54 -0700 | [diff] [blame] | 127 | * @see CameraManager#getCameraCharacteristics |
Zhijun He | 599be61 | 2013-09-27 13:43:25 -0700 | [diff] [blame] | 128 | * @see CameraManager#getCameraIdList |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 129 | */ |
| 130 | public String getId(); |
| 131 | |
| 132 | /** |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 133 | * <p>Set up a new output set of Surfaces for the camera device.</p> |
| 134 | * |
| 135 | * <p>The configuration determines the set of potential output Surfaces for |
| 136 | * the camera device for each capture request. A given request may use all |
| 137 | * or a only some of the outputs. This method must be called before requests |
| 138 | * can be submitted to the camera with {@link #capture capture}, |
| 139 | * {@link #captureBurst captureBurst}, |
| 140 | * {@link #setRepeatingRequest setRepeatingRequest}, or |
| 141 | * {@link #setRepeatingBurst setRepeatingBurst}.</p> |
| 142 | * |
| 143 | * <p>Surfaces suitable for inclusion as a camera output can be created for |
| 144 | * various use cases and targets:</p> |
| 145 | * |
| 146 | * <ul> |
| 147 | * |
| 148 | * <li>For drawing to a {@link android.view.SurfaceView SurfaceView}: Set |
| 149 | * the size of the Surface with |
| 150 | * {@link android.view.SurfaceHolder#setFixedSize} to be one of the |
| 151 | * supported |
Igor Murashkin | 68f4006 | 2013-09-10 12:15:54 -0700 | [diff] [blame] | 152 | * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES processed sizes} |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 153 | * before calling {@link android.view.SurfaceHolder#getSurface}.</li> |
| 154 | * |
| 155 | * <li>For accessing through an OpenGL texture via a |
| 156 | * {@link android.graphics.SurfaceTexture SurfaceTexture}: Set the size of |
| 157 | * the SurfaceTexture with |
| 158 | * {@link android.graphics.SurfaceTexture#setDefaultBufferSize} to be one |
| 159 | * of the supported |
Igor Murashkin | 68f4006 | 2013-09-10 12:15:54 -0700 | [diff] [blame] | 160 | * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES processed sizes} |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 161 | * before creating a Surface from the SurfaceTexture with |
| 162 | * {@link Surface#Surface}.</li> |
| 163 | * |
| 164 | * <li>For recording with {@link android.media.MediaCodec}: Call |
| 165 | * {@link android.media.MediaCodec#createInputSurface} after configuring |
| 166 | * the media codec to use one of the |
Igor Murashkin | 68f4006 | 2013-09-10 12:15:54 -0700 | [diff] [blame] | 167 | * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES processed sizes} |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 168 | * </li> |
| 169 | * |
| 170 | * <li>For recording with {@link android.media.MediaRecorder}: TODO</li> |
| 171 | * |
| 172 | * <li>For efficient YUV processing with {@link android.renderscript}: |
| 173 | * Create a RenderScript |
| 174 | * {@link android.renderscript.Allocation Allocation} with a supported YUV |
| 175 | * type, the IO_INPUT flag, and one of the supported |
Igor Murashkin | 68f4006 | 2013-09-10 12:15:54 -0700 | [diff] [blame] | 176 | * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES processed sizes}. Then |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 177 | * obtain the Surface with |
| 178 | * {@link android.renderscript.Allocation#getSurface}.</li> |
| 179 | * |
Eino-Ville Talvala | 5a32b20c | 2013-08-08 12:38:36 -0700 | [diff] [blame] | 180 | * <li>For access to uncompressed or JPEG data in the application: Create a |
| 181 | * {@link android.media.ImageReader} object with the desired |
Igor Murashkin | 68f4006 | 2013-09-10 12:15:54 -0700 | [diff] [blame] | 182 | * {@link CameraCharacteristics#SCALER_AVAILABLE_FORMATS image format}, and a |
Eino-Ville Talvala | 5a32b20c | 2013-08-08 12:38:36 -0700 | [diff] [blame] | 183 | * size from the matching |
Igor Murashkin | 68f4006 | 2013-09-10 12:15:54 -0700 | [diff] [blame] | 184 | * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES processed}, |
| 185 | * {@link CameraCharacteristics#SCALER_AVAILABLE_JPEG_SIZES jpeg}. Then obtain |
Eino-Ville Talvala | 5a32b20c | 2013-08-08 12:38:36 -0700 | [diff] [blame] | 186 | * a Surface from it.</li> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 187 | * |
| 188 | * </ul> |
| 189 | * |
| 190 | * </p> |
| 191 | * |
| 192 | * <p>This function can take several hundred milliseconds to execute, since |
| 193 | * camera hardware may need to be powered on or reconfigured.</p> |
| 194 | * |
Igor Murashkin | 53f91c5 | 2013-08-09 16:26:14 -0700 | [diff] [blame] | 195 | * <p>The camera device will query each Surface's size and formats upon this |
| 196 | * call, so they must be set to a valid setting at this time (in particular: |
| 197 | * if the format is user-visible, it must be one of android.scaler.availableFormats; |
| 198 | * and the size must be one of android.scaler.available[Processed|Jpeg]Sizes).</p> |
| 199 | * |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 200 | * <p>When this method is called with valid Surfaces, the device will transition to the {@link |
| 201 | * StateListener#onBusy busy state}. Once configuration is complete, the device will transition |
| 202 | * into the {@link StateListener#onIdle idle state}. Capture requests using the newly-configured |
| 203 | * Surfaces may then be submitted with {@link #capture}, {@link #captureBurst}, {@link |
| 204 | * #setRepeatingRequest}, or {@link #setRepeatingBurst}.</p> |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 205 | * |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 206 | * <p>If this method is called while the camera device is still actively processing previously |
| 207 | * submitted captures, then the following sequence of events occurs: The device transitions to |
| 208 | * the busy state and calls the {@link StateListener#onBusy} callback. Second, if a repeating |
| 209 | * request is set it is cleared. Third, the device finishes up all in-flight and pending |
| 210 | * requests. Finally, once the device is idle, it then reconfigures its outputs, and calls the |
| 211 | * {@link StateListener#onIdle} method once it is again ready to accept capture |
| 212 | * requests. Therefore, no submitted work is discarded. To idle as fast as possible, use {@link |
| 213 | * #flush} and wait for the idle callback before calling configureOutputs. This will discard |
| 214 | * work, but reaches the new configuration sooner.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 215 | * |
| 216 | * <p>Using larger resolution outputs, or more outputs, can result in slower |
| 217 | * output rate from the device.</p> |
| 218 | * |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 219 | * <p>Configuring the outputs with an empty or null list will transition the camera into an |
| 220 | * {@link StateListener#onUnconfigured unconfigured state} instead of the {@link |
| 221 | * StateListener#onIdle idle state}. </p> |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 222 | * |
| 223 | * <p>Calling configureOutputs with the same arguments as the last call to |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 224 | * configureOutputs has no effect, and the {@link StateListener#onBusy busy} |
| 225 | * and {@link StateListener#onIdle idle} state transitions will happen |
| 226 | * immediately.</p> |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 227 | * |
Benjamin Hendricks | 24eb8a3 | 2013-08-15 12:46:22 -0700 | [diff] [blame] | 228 | * @param outputs The new set of Surfaces that should be made available as |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 229 | * targets for captured image data. |
| 230 | * |
| 231 | * @throws IllegalArgumentException if the set of output Surfaces do not |
| 232 | * meet the requirements |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 233 | * @throws CameraAccessException if the camera device is no longer connected or has |
| 234 | * encountered a fatal error |
| 235 | * @throws IllegalStateException if the camera device is not idle, or |
| 236 | * if the camera device has been closed |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 237 | * |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 238 | * @see StateListener#onBusy |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 239 | * @see StateListener#onIdle |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 240 | * @see StateListener#onActive |
| 241 | * @see StateListener#onUnconfigured |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 242 | * @see #stopRepeating |
| 243 | * @see #flush |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 244 | */ |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 245 | public void configureOutputs(List<Surface> outputs) throws CameraAccessException; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 246 | |
| 247 | /** |
Eino-Ville Talvala | 70c2207 | 2013-08-27 12:09:04 -0700 | [diff] [blame] | 248 | * <p>Create a {@link CaptureRequest.Builder} for new capture requests, |
| 249 | * initialized with template for a target use case. The settings are chosen |
| 250 | * to be the best options for the specific camera device, so it is not |
| 251 | * recommended to reuse the same request for a different camera device; |
| 252 | * create a builder specific for that device and template and override the |
| 253 | * settings as desired, instead.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 254 | * |
| 255 | * @param templateType An enumeration selecting the use case for this |
| 256 | * request; one of the CameraDevice.TEMPLATE_ values. |
Eino-Ville Talvala | 70c2207 | 2013-08-27 12:09:04 -0700 | [diff] [blame] | 257 | * @return a builder for a capture request, initialized with default |
| 258 | * settings for that template, and no output streams |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 259 | * |
| 260 | * @throws IllegalArgumentException if the templateType is not in the list |
| 261 | * of supported templates. |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 262 | * @throws CameraAccessException if the camera device is no longer connected or has |
| 263 | * encountered a fatal error |
| 264 | * @throws IllegalStateException if the camera device has been closed |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 265 | * |
| 266 | * @see #TEMPLATE_PREVIEW |
| 267 | * @see #TEMPLATE_RECORD |
| 268 | * @see #TEMPLATE_STILL_CAPTURE |
| 269 | * @see #TEMPLATE_VIDEO_SNAPSHOT |
| 270 | * @see #TEMPLATE_MANUAL |
| 271 | */ |
Eino-Ville Talvala | 70c2207 | 2013-08-27 12:09:04 -0700 | [diff] [blame] | 272 | public CaptureRequest.Builder createCaptureRequest(int templateType) |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 273 | throws CameraAccessException; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 274 | |
| 275 | /** |
| 276 | * <p>Submit a request for an image to be captured by this CameraDevice.</p> |
| 277 | * |
| 278 | * <p>The request defines all the parameters for capturing the single image, |
| 279 | * including sensor, lens, flash, and post-processing settings.</p> |
| 280 | * |
| 281 | * <p>Each request will produce one {@link CaptureResult} and produce new |
Eino-Ville Talvala | 70c2207 | 2013-08-27 12:09:04 -0700 | [diff] [blame] | 282 | * frames for one or more target Surfaces, set with the CaptureRequest |
| 283 | * builder's {@link CaptureRequest.Builder#addTarget} method. The target |
| 284 | * surfaces must be configured as active outputs with |
| 285 | * {@link #configureOutputs} before calling this method.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 286 | * |
| 287 | * <p>Multiple requests can be in progress at once. They are processed in |
| 288 | * first-in, first-out order, with minimal delays between each |
| 289 | * capture. Requests submitted through this method have higher priority than |
| 290 | * those submitted through {@link #setRepeatingRequest} or |
| 291 | * {@link #setRepeatingBurst}, and will be processed as soon as the current |
| 292 | * repeat/repeatBurst processing completes.</p> |
| 293 | * |
Benjamin Hendricks | 24eb8a3 | 2013-08-15 12:46:22 -0700 | [diff] [blame] | 294 | * @param request the settings for this capture |
| 295 | * @param listener The callback object to notify once this request has been |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 296 | * processed. If null, no metadata will be produced for this capture, |
| 297 | * although image data will still be produced. |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 298 | * @param handler the handler on which the listener should be invoked, or |
| 299 | * {@code null} to use the current thread's {@link android.os.Looper |
| 300 | * looper}. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 301 | * |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 302 | * @return int A unique capture sequence ID used by |
| 303 | * {@link CaptureListener#onCaptureSequenceCompleted}. |
| 304 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 305 | * @throws CameraAccessException if the camera device is no longer connected or has |
| 306 | * encountered a fatal error |
| 307 | * @throws IllegalStateException if the camera is currently busy or unconfigured, |
| 308 | * or the camera device has been closed. |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 309 | * @throws IllegalArgumentException If the request targets Surfaces not |
| 310 | * currently configured as outputs. Or if the handler is null, the listener |
| 311 | * is not null, and the calling thread has no looper. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 312 | * |
| 313 | * @see #captureBurst |
| 314 | * @see #setRepeatingRequest |
| 315 | * @see #setRepeatingBurst |
| 316 | */ |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 317 | public int capture(CaptureRequest request, CaptureListener listener, Handler handler) |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 318 | throws CameraAccessException; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 319 | |
| 320 | /** |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 321 | * Submit a list of requests to be captured in sequence as a burst. The |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 322 | * burst will be captured in the minimum amount of time possible, and will |
| 323 | * not be interleaved with requests submitted by other capture or repeat |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 324 | * calls. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 325 | * |
| 326 | * <p>The requests will be captured in order, each capture producing one |
Eino-Ville Talvala | 70c2207 | 2013-08-27 12:09:04 -0700 | [diff] [blame] | 327 | * {@link CaptureResult} and image buffers for one or more target |
| 328 | * {@link android.view.Surface surfaces}. The target surfaces for each |
| 329 | * request (set with {@link CaptureRequest.Builder#addTarget}) must be |
| 330 | * configured as active outputs with {@link #configureOutputs} before |
| 331 | * calling this method.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 332 | * |
| 333 | * <p>The main difference between this method and simply calling |
| 334 | * {@link #capture} repeatedly is that this method guarantees that no |
| 335 | * other requests will be interspersed with the burst.</p> |
| 336 | * |
Benjamin Hendricks | 24eb8a3 | 2013-08-15 12:46:22 -0700 | [diff] [blame] | 337 | * @param requests the list of settings for this burst capture |
| 338 | * @param listener The callback object to notify each time one of the |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 339 | * requests in the burst has been processed. If null, no metadata will be |
| 340 | * produced for any requests in this burst, although image data will still |
| 341 | * be produced. |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 342 | * @param handler the handler on which the listener should be invoked, or |
| 343 | * {@code null} to use the current thread's {@link android.os.Looper |
| 344 | * looper}. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 345 | * |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 346 | * @return int A unique capture sequence ID used by |
| 347 | * {@link CaptureListener#onCaptureSequenceCompleted}. |
| 348 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 349 | * @throws CameraAccessException if the camera device is no longer connected or has |
| 350 | * encountered a fatal error |
| 351 | * @throws IllegalStateException if the camera is currently busy or unconfigured, |
| 352 | * or the camera device has been closed. |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 353 | * @throws IllegalArgumentException If the requests target Surfaces not |
| 354 | * currently configured as outputs. Or if the handler is null, the listener |
| 355 | * is not null, and the calling thread has no looper. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 356 | * |
| 357 | * @see #capture |
| 358 | * @see #setRepeatingRequest |
| 359 | * @see #setRepeatingBurst |
| 360 | */ |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 361 | public int captureBurst(List<CaptureRequest> requests, CaptureListener listener, |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 362 | Handler handler) throws CameraAccessException; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 363 | |
| 364 | /** |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 365 | * Request endlessly repeating capture of images by this CameraDevice. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 366 | * |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 367 | * <p>With this method, the CameraDevice will continually capture images |
| 368 | * using the settings in the provided {@link CaptureRequest}, at the maximum |
| 369 | * rate possible.</p> |
| 370 | * |
| 371 | * <p>Repeating requests are a simple way for an application to maintain a |
| 372 | * preview or other continuous stream of frames, without having to |
| 373 | * continually submit identical requests through {@link #capture}.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 374 | * |
| 375 | * <p>Repeat requests have lower priority than those submitted |
| 376 | * through {@link #capture} or {@link #captureBurst}, so if |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 377 | * {@link #capture} is called when a repeating request is active, the |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 378 | * capture request will be processed before any further repeating |
| 379 | * requests are processed.<p> |
| 380 | * |
| 381 | * <p>Repeating requests are a simple way for an application to maintain a |
| 382 | * preview or other continuous stream of frames, without having to submit |
| 383 | * requests through {@link #capture} at video rates.</p> |
| 384 | * |
Eino-Ville Talvala | 8ebd52b | 2013-08-13 12:09:44 -0700 | [diff] [blame] | 385 | * <p>To stop the repeating capture, call {@link #stopRepeating}. Calling |
| 386 | * {@link #flush} will also clear the request.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 387 | * |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 388 | * <p>Calling this method will replace any earlier repeating request or |
| 389 | * burst set up by this method or {@link #setRepeatingBurst}, although any |
| 390 | * in-progress burst will be completed before the new repeat request will be |
| 391 | * used.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 392 | * |
| 393 | * @param request the request to repeat indefinitely |
Benjamin Hendricks | 24eb8a3 | 2013-08-15 12:46:22 -0700 | [diff] [blame] | 394 | * @param listener The callback object to notify every time the |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 395 | * request finishes processing. If null, no metadata will be |
| 396 | * produced for this stream of requests, although image data will |
| 397 | * still be produced. |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 398 | * @param handler the handler on which the listener should be invoked, or |
| 399 | * {@code null} to use the current thread's {@link android.os.Looper |
| 400 | * looper}. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 401 | * |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 402 | * @return int A unique capture sequence ID used by |
| 403 | * {@link CaptureListener#onCaptureSequenceCompleted}. |
| 404 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 405 | * @throws CameraAccessException if the camera device is no longer connected or has |
| 406 | * encountered a fatal error |
| 407 | * @throws IllegalStateException if the camera is currently busy or unconfigured, |
| 408 | * or the camera device has been closed. |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 409 | * @throws IllegalArgumentException If the requests reference Surfaces not |
| 410 | * currently configured as outputs. Or if the handler is null, the listener |
| 411 | * is not null, and the calling thread has no looper. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 412 | * |
| 413 | * @see #capture |
| 414 | * @see #captureBurst |
| 415 | * @see #setRepeatingBurst |
Eino-Ville Talvala | 8ebd52b | 2013-08-13 12:09:44 -0700 | [diff] [blame] | 416 | * @see #stopRepeating |
| 417 | * @see #flush |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 418 | */ |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 419 | public int setRepeatingRequest(CaptureRequest request, CaptureListener listener, |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 420 | Handler handler) throws CameraAccessException; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 421 | |
| 422 | /** |
| 423 | * <p>Request endlessly repeating capture of a sequence of images by this |
| 424 | * CameraDevice.</p> |
| 425 | * |
| 426 | * <p>With this method, the CameraDevice will continually capture images, |
| 427 | * cycling through the settings in the provided list of |
| 428 | * {@link CaptureRequest CaptureRequests}, at the maximum rate possible.</p> |
| 429 | * |
| 430 | * <p>If a request is submitted through {@link #capture} or |
| 431 | * {@link #captureBurst}, the current repetition of the request list will be |
| 432 | * completed before the higher-priority request is handled. This guarantees |
| 433 | * that the application always receives a complete repeat burst captured in |
| 434 | * minimal time, instead of bursts interleaved with higher-priority |
| 435 | * captures, or incomplete captures.</p> |
| 436 | * |
| 437 | * <p>Repeating burst requests are a simple way for an application to |
| 438 | * maintain a preview or other continuous stream of frames where each |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 439 | * request is different in a predicatable way, without having to continually |
| 440 | * submit requests through {@link #captureBurst} .</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 441 | * |
| 442 | * <p>To stop the repeating capture, call {@link #stopRepeating}. Any |
Eino-Ville Talvala | 8ebd52b | 2013-08-13 12:09:44 -0700 | [diff] [blame] | 443 | * ongoing burst will still be completed, however. Calling |
| 444 | * {@link #flush} will also clear the request.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 445 | * |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 446 | * <p>Calling this method will replace a previously-set repeating request or |
| 447 | * burst set up by this method or {@link #setRepeatingRequest}, although any |
| 448 | * in-progress burst will be completed before the new repeat burst will be |
| 449 | * used.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 450 | * |
Benjamin Hendricks | 24eb8a3 | 2013-08-15 12:46:22 -0700 | [diff] [blame] | 451 | * @param requests the list of requests to cycle through indefinitely |
| 452 | * @param listener The callback object to notify each time one of the |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 453 | * requests in the repeating bursts has finished processing. If null, no |
| 454 | * metadata will be produced for this stream of requests, although image |
| 455 | * data will still be produced. |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 456 | * @param handler the handler on which the listener should be invoked, or |
| 457 | * {@code null} to use the current thread's {@link android.os.Looper |
| 458 | * looper}. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 459 | * |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 460 | * @return int A unique capture sequence ID used by |
| 461 | * {@link CaptureListener#onCaptureSequenceCompleted}. |
| 462 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 463 | * @throws CameraAccessException if the camera device is no longer connected or has |
| 464 | * encountered a fatal error |
| 465 | * @throws IllegalStateException if the camera is currently busy or unconfigured, |
| 466 | * or the camera device has been closed. |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 467 | * @throws IllegalArgumentException If the requests reference Surfaces not |
| 468 | * currently configured as outputs. Or if the handler is null, the listener |
| 469 | * is not null, and the calling thread has no looper. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 470 | * |
| 471 | * @see #capture |
| 472 | * @see #captureBurst |
| 473 | * @see #setRepeatingRequest |
Eino-Ville Talvala | 8ebd52b | 2013-08-13 12:09:44 -0700 | [diff] [blame] | 474 | * @see #stopRepeating |
| 475 | * @see #flush |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 476 | */ |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 477 | public int setRepeatingBurst(List<CaptureRequest> requests, CaptureListener listener, |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 478 | Handler handler) throws CameraAccessException; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 479 | |
| 480 | /** |
| 481 | * <p>Cancel any ongoing repeating capture set by either |
| 482 | * {@link #setRepeatingRequest setRepeatingRequest} or |
| 483 | * {@link #setRepeatingBurst}. Has no effect on requests submitted through |
| 484 | * {@link #capture capture} or {@link #captureBurst captureBurst}.</p> |
| 485 | * |
| 486 | * <p>Any currently in-flight captures will still complete, as will any |
| 487 | * burst that is mid-capture. To ensure that the device has finished |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 488 | * processing all of its capture requests and is in idle state, wait for the |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 489 | * {@link StateListener#onIdle} callback after calling this |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 490 | * method..</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 491 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 492 | * @throws CameraAccessException if the camera device is no longer connected or has |
| 493 | * encountered a fatal error |
| 494 | * @throws IllegalStateException if the camera is currently busy or unconfigured, |
| 495 | * or the camera device has been closed. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 496 | * |
| 497 | * @see #setRepeatingRequest |
| 498 | * @see #setRepeatingBurst |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 499 | * @see StateListener#onIdle |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 500 | */ |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 501 | public void stopRepeating() throws CameraAccessException; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 502 | |
| 503 | /** |
Eino-Ville Talvala | 8ebd52b | 2013-08-13 12:09:44 -0700 | [diff] [blame] | 504 | * Flush all captures currently pending and in-progress as fast as |
| 505 | * possible. |
| 506 | * |
| 507 | * <p>The camera device will discard all of its current work as fast as |
| 508 | * possible. Some in-flight captures may complete successfully and call |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 509 | * {@link CaptureListener#onCaptureCompleted}, while others will trigger |
Eino-Ville Talvala | 8ebd52b | 2013-08-13 12:09:44 -0700 | [diff] [blame] | 510 | * their {@link CaptureListener#onCaptureFailed} callbacks. If a repeating |
| 511 | * request or a repeating burst is set, it will be cleared by the flush.</p> |
| 512 | * |
| 513 | * <p>This method is the fastest way to idle the camera device for |
| 514 | * reconfiguration with {@link #configureOutputs}, at the cost of discarding |
| 515 | * in-progress work. Once the flush is complete, the idle callback will be |
| 516 | * called.</p> |
| 517 | * |
| 518 | * <p>Flushing will introduce at least a brief pause in the stream of data |
| 519 | * from the camera device, since once the flush is complete, the first new |
| 520 | * request has to make it through the entire camera pipeline before new |
| 521 | * output buffers are produced.</p> |
| 522 | * |
| 523 | * <p>This means that using {@code flush()} to simply remove pending |
| 524 | * requests is not recommended; it's best used for quickly switching output |
| 525 | * configurations, or for cancelling long in-progress requests (such as a |
| 526 | * multi-second capture).</p> |
| 527 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 528 | * @throws CameraAccessException if the camera device is no longer connected or has |
| 529 | * encountered a fatal error |
| 530 | * @throws IllegalStateException if the camera is not idle/active, |
| 531 | * or the camera device has been closed. |
| 532 | * |
Eino-Ville Talvala | 8ebd52b | 2013-08-13 12:09:44 -0700 | [diff] [blame] | 533 | * @see #setRepeatingRequest |
| 534 | * @see #setRepeatingBurst |
| 535 | * @see #configureOutputs |
| 536 | */ |
| 537 | public void flush() throws CameraAccessException; |
| 538 | |
| 539 | /** |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 540 | * Close the connection to this camera device. |
| 541 | * |
| 542 | * <p>After this call, all calls to |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 543 | * the camera device interface will throw a {@link IllegalStateException}, |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 544 | * except for calls to close(). Once the device has fully shut down, the |
| 545 | * {@link StateListener#onClosed} callback will be called, and the camera is |
| 546 | * free to be re-opened.</p> |
| 547 | * |
| 548 | * <p>After this call, besides the final {@link StateListener#onClosed} call, no calls to the |
| 549 | * device's {@link StateListener} will occur, and any remaining submitted capture requests will |
| 550 | * not fire their {@link CaptureListener} callbacks.</p> |
| 551 | * |
| 552 | * <p>To shut down as fast as possible, call the {@link #flush} method and then {@link #close} |
| 553 | * once the flush completes. This will discard some capture requests, but results in faster |
| 554 | * shutdown.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 555 | */ |
Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 556 | @Override |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 557 | public void close(); |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 558 | |
| 559 | /** |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 560 | * <p>A listener for tracking the progress of a {@link CaptureRequest} |
| 561 | * submitted to the camera device.</p> |
| 562 | * |
| 563 | * <p>This listener is called when a request triggers a capture to start, |
| 564 | * and when the capture is complete. In case on an error capturing an image, |
| 565 | * the error method is triggered instead of the completion method.</p> |
| 566 | * |
| 567 | * @see #capture |
| 568 | * @see #captureBurst |
| 569 | * @see #setRepeatingRequest |
| 570 | * @see #setRepeatingBurst |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 571 | */ |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 572 | public static abstract class CaptureListener { |
| 573 | |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 574 | /** |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 575 | * This method is called when the camera device has started capturing |
| 576 | * the output image for the request, at the beginning of image exposure. |
| 577 | * |
| 578 | * <p>This callback is invoked right as the capture of a frame begins, |
| 579 | * so it is the most appropriate time for playing a shutter sound, |
| 580 | * or triggering UI indicators of capture.</p> |
| 581 | * |
| 582 | * <p>The request that is being used for this capture is provided, along |
| 583 | * with the actual timestamp for the start of exposure. This timestamp |
| 584 | * matches the timestamp that will be included in |
| 585 | * {@link CaptureResult#SENSOR_TIMESTAMP the result timestamp field}, |
| 586 | * and in the buffers sent to each output Surface. These buffer |
| 587 | * timestamps are accessible through, for example, |
| 588 | * {@link android.media.Image#getTimestamp() Image.getTimestamp()} or |
| 589 | * {@link android.graphics.SurfaceTexture#getTimestamp()}.</p> |
| 590 | * |
| 591 | * <p>For the simplest way to play a shutter sound camera shutter or a |
| 592 | * video recording start/stop sound, see the |
| 593 | * {@link android.media.MediaActionSound} class.</p> |
| 594 | * |
| 595 | * <p>The default implementation of this method does nothing.</p> |
| 596 | * |
| 597 | * @param camera the CameraDevice sending the callback |
| 598 | * @param request the request for the capture that just begun |
| 599 | * @param timestamp the timestamp at start of capture, in nanoseconds. |
| 600 | * |
| 601 | * @see android.media.MediaActionSound |
| 602 | */ |
| 603 | public void onCaptureStarted(CameraDevice camera, |
| 604 | CaptureRequest request, long timestamp) { |
| 605 | // default empty implementation |
| 606 | } |
| 607 | |
| 608 | /** |
Eino-Ville Talvala | 7a31310 | 2013-11-07 14:45:06 -0800 | [diff] [blame] | 609 | * This method is called when some results from an image capture are |
| 610 | * available. |
| 611 | * |
| 612 | * <p>The result provided here will contain some subset of the fields of |
| 613 | * a full result. Multiple onCapturePartial calls may happen per |
| 614 | * capture; a given result field will only be present in one partial |
| 615 | * capture at most. The final onCaptureCompleted call will always |
| 616 | * contain all the fields, whether onCapturePartial was called or |
| 617 | * not.</p> |
| 618 | * |
| 619 | * <p>The default implementation of this method does nothing.</p> |
| 620 | * |
| 621 | * @param camera The CameraDevice sending the callback. |
| 622 | * @param request The request that was given to the CameraDevice |
| 623 | * @param result The partial output metadata from the capture, which |
| 624 | * includes a subset of the CaptureResult fields. |
| 625 | * |
| 626 | * @see #capture |
| 627 | * @see #captureBurst |
| 628 | * @see #setRepeatingRequest |
| 629 | * @see #setRepeatingBurst |
| 630 | * |
| 631 | * @hide |
| 632 | */ |
| 633 | public void onCapturePartial(CameraDevice camera, |
| 634 | CaptureRequest request, CaptureResult result) { |
| 635 | // default empty implementation |
| 636 | } |
| 637 | |
| 638 | /** |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 639 | * This method is called when an image capture has completed and the |
| 640 | * result metadata is available. |
| 641 | * |
| 642 | * <p>The default implementation of this method does nothing.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 643 | * |
| 644 | * @param camera The CameraDevice sending the callback. |
| 645 | * @param request The request that was given to the CameraDevice |
| 646 | * @param result The output metadata from the capture, including the |
| 647 | * final capture parameters and the state of the camera system during |
| 648 | * capture. |
| 649 | * |
| 650 | * @see #capture |
| 651 | * @see #captureBurst |
| 652 | * @see #setRepeatingRequest |
| 653 | * @see #setRepeatingBurst |
| 654 | */ |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 655 | public void onCaptureCompleted(CameraDevice camera, |
| 656 | CaptureRequest request, CaptureResult result) { |
| 657 | // default empty implementation |
| 658 | } |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 659 | |
| 660 | /** |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 661 | * This method is called instead of {@link #onCaptureCompleted} when the |
| 662 | * camera device failed to produce a {@link CaptureResult} for the |
| 663 | * request. |
| 664 | * |
| 665 | * <p>Other requests are unaffected, and some or all image buffers from |
| 666 | * the capture may have been pushed to their respective output |
| 667 | * streams.</p> |
| 668 | * |
| 669 | * <p>The default implementation of this method does nothing.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 670 | * |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 671 | * @param camera |
| 672 | * The CameraDevice sending the callback. |
| 673 | * @param request |
| 674 | * The request that was given to the CameraDevice |
| 675 | * @param failure |
| 676 | * The output failure from the capture, including the failure reason |
| 677 | * and the frame number. |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 678 | * |
| 679 | * @see #capture |
| 680 | * @see #captureBurst |
| 681 | * @see #setRepeatingRequest |
| 682 | * @see #setRepeatingBurst |
| 683 | */ |
| 684 | public void onCaptureFailed(CameraDevice camera, |
Igor Murashkin | 6bbf9dc | 2013-09-05 12:22:00 -0700 | [diff] [blame] | 685 | CaptureRequest request, CaptureFailure failure) { |
| 686 | // default empty implementation |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * This method is called independently of the others in CaptureListener, |
| 691 | * when a capture sequence finishes and all {@link CaptureResult} |
| 692 | * or {@link CaptureFailure} for it have been returned via this listener. |
| 693 | * |
| 694 | * @param camera |
| 695 | * The CameraDevice sending the callback. |
| 696 | * @param sequenceId |
| 697 | * A sequence ID returned by the {@link #capture} family of functions. |
| 698 | * @param frameNumber |
| 699 | * The last frame number (returned by {@link CaptureResult#getFrameNumber} |
| 700 | * or {@link CaptureFailure#getFrameNumber}) in the capture sequence. |
| 701 | * |
| 702 | * @see CaptureResult#getFrameNumber() |
| 703 | * @see CaptureFailure#getFrameNumber() |
| 704 | * @see CaptureResult#getSequenceId() |
| 705 | * @see CaptureFailure#getSequenceId() |
| 706 | */ |
| 707 | public void onCaptureSequenceCompleted(CameraDevice camera, |
| 708 | int sequenceId, int frameNumber) { |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 709 | // default empty implementation |
| 710 | } |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /** |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 714 | * A listener for notifications about the state of a camera |
| 715 | * device. |
| 716 | * |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 717 | * <p>A listener must be provided to the {@link CameraManager#openCamera} |
| 718 | * method to open a camera device.</p> |
| 719 | * |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 720 | * <p>These events include notifications about the device becoming idle ( |
| 721 | * allowing for {@link #configureOutputs} to be called), about device |
| 722 | * disconnection, and about unexpected device errors.</p> |
| 723 | * |
| 724 | * <p>Events about the progress of specific {@link CaptureRequest |
| 725 | * CaptureRequests} are provided through a {@link CaptureListener} given to |
| 726 | * the {@link #capture}, {@link #captureBurst}, {@link |
| 727 | * #setRepeatingRequest}, or {@link #setRepeatingBurst} methods. |
| 728 | * |
Eino-Ville Talvala | 868d904 | 2013-10-03 11:15:21 -0700 | [diff] [blame] | 729 | * @see CameraManager#openCamera |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 730 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 731 | public static abstract class StateListener { |
| 732 | /** |
| 733 | * An error code that can be reported by {@link #onError} |
| 734 | * indicating that the camera device is in use already. |
| 735 | * |
| 736 | * <p> |
| 737 | * This error can be produced when opening the camera fails. |
| 738 | * </p> |
| 739 | * |
| 740 | * @see #onError |
| 741 | */ |
| 742 | public static final int ERROR_CAMERA_IN_USE = 1; |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 743 | |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 744 | /** |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 745 | * An error code that can be reported by {@link #onError} |
| 746 | * indicating that the camera device could not be opened |
| 747 | * because there are too many other open camera devices. |
| 748 | * |
| 749 | * <p> |
| 750 | * The system-wide limit for number of open cameras has been reached, |
| 751 | * and more camera devices cannot be opened until previous instances are |
| 752 | * closed. |
| 753 | * </p> |
| 754 | * |
| 755 | * <p> |
| 756 | * This error can be produced when opening the camera fails. |
| 757 | * </p> |
| 758 | * |
| 759 | * @see #onError |
| 760 | */ |
| 761 | public static final int ERROR_MAX_CAMERAS_IN_USE = 2; |
| 762 | |
| 763 | /** |
| 764 | * An error code that can be reported by {@link #onError} |
| 765 | * indicating that the camera device could not be opened due to a device |
| 766 | * policy. |
| 767 | * |
| 768 | * @see android.app.admin.DevicePolicyManager#setCameraDisabled(android.content.ComponentName, boolean) |
| 769 | * @see #onError |
| 770 | */ |
| 771 | public static final int ERROR_CAMERA_DISABLED = 3; |
| 772 | |
| 773 | /** |
| 774 | * An error code that can be reported by {@link #onError} |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 775 | * indicating that the camera device has encountered a fatal error. |
| 776 | * |
| 777 | * <p>The camera device needs to be re-opened to be used again.</p> |
| 778 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 779 | * @see #onError |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 780 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 781 | public static final int ERROR_CAMERA_DEVICE = 4; |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 782 | |
| 783 | /** |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 784 | * An error code that can be reported by {@link #onError} |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 785 | * indicating that the camera service has encountered a fatal error. |
| 786 | * |
| 787 | * <p>The Android device may need to be shut down and restarted to restore |
| 788 | * camera function, or there may be a persistent hardware problem.</p> |
| 789 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 790 | * <p>An attempt at recovery <i>may</i> be possible by closing the |
| 791 | * CameraDevice and the CameraManager, and trying to acquire all resources |
| 792 | * again from scratch.</p> |
| 793 | * |
| 794 | * @see #onError |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 795 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 796 | public static final int ERROR_CAMERA_SERVICE = 5; |
| 797 | |
| 798 | /** |
| 799 | * The method called when a camera device has finished opening. |
| 800 | * |
| 801 | * <p>An opened camera will immediately afterwards transition into |
| 802 | * {@link #onUnconfigured}.</p> |
| 803 | * |
| 804 | * @param camera the camera device that has become opened |
| 805 | */ |
| 806 | public abstract void onOpened(CameraDevice camera); // Must implement |
| 807 | |
| 808 | /** |
| 809 | * The method called when a camera device has no outputs configured. |
| 810 | * |
| 811 | * <p>An unconfigured camera device needs to be configured with |
| 812 | * {@link CameraDevice#configureOutputs} before being able to |
| 813 | * submit any capture request.</p> |
| 814 | * |
| 815 | * <p>This state may be entered by a newly opened camera or by |
| 816 | * calling {@link CameraDevice#configureOutputs} with a null/empty |
| 817 | * list of Surfaces when idle.</p> |
| 818 | * |
| 819 | * <p>Any attempts to submit a capture request while in this state |
| 820 | * will result in an {@link IllegalStateException} being thrown.</p> |
| 821 | * |
| 822 | * <p>The default implementation of this method does nothing.</p> |
| 823 | * |
| 824 | * @param camera the camera device has that become unconfigured |
| 825 | */ |
| 826 | public void onUnconfigured(CameraDevice camera) { |
| 827 | // Default empty implementation |
| 828 | } |
| 829 | |
| 830 | /** |
| 831 | * The method called when a camera device begins processing |
| 832 | * {@link CaptureRequest capture requests}. |
| 833 | * |
| 834 | * <p>A camera may not be re-configured while in this state. The camera |
| 835 | * will transition to the idle state once all pending captures have |
| 836 | * completed. If a repeating request is set, the camera will remain active |
| 837 | * until it is cleared and the remaining requests finish processing. To |
| 838 | * transition to the idle state as quickly as possible, call {@link #flush()}, |
| 839 | * which will idle the camera device as quickly as possible, likely canceling |
| 840 | * most in-progress captures.</p> |
| 841 | * |
| 842 | * <p>All calls except for {@link CameraDevice#configureOutputs} are |
| 843 | * legal while in this state. |
| 844 | * </p> |
| 845 | * |
| 846 | * <p>The default implementation of this method does nothing.</p> |
| 847 | * |
| 848 | * @param camera the camera device that has become active |
| 849 | * |
| 850 | * @see CameraDevice#capture |
| 851 | * @see CameraDevice#captureBurst |
| 852 | * @see CameraDevice#setRepeatingBurst |
| 853 | * @see CameraDevice#setRepeatingRequest |
| 854 | */ |
| 855 | public void onActive(CameraDevice camera) { |
| 856 | // Default empty implementation |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * The method called when a camera device is busy. |
| 861 | * |
| 862 | * <p>A camera becomes busy while it's outputs are being configured |
| 863 | * (after a call to {@link CameraDevice#configureOutputs} or while it's |
| 864 | * being flushed (after a call to {@link CameraDevice#flush}.</p> |
| 865 | * |
| 866 | * <p>Once the on-going operations are complete, the camera will automatically |
| 867 | * transition into {@link #onIdle} if there is at least one configured output, |
| 868 | * or {@link #onUnconfigured} otherwise.</p> |
| 869 | * |
| 870 | * <p>Any attempts to manipulate the camera while its is busy |
| 871 | * will result in an {@link IllegalStateException} being thrown.</p> |
| 872 | * |
| 873 | * <p>Only the following methods are valid to call while in this state: |
| 874 | * <ul> |
| 875 | * <li>{@link CameraDevice#getId}</li> |
| 876 | * <li>{@link CameraDevice#createCaptureRequest}</li> |
| 877 | * <li>{@link CameraDevice#close}</li> |
| 878 | * </ul> |
| 879 | * </p> |
| 880 | * |
| 881 | * <p>The default implementation of this method does nothing.</p> |
| 882 | * |
| 883 | * @param camera the camera device that has become busy |
| 884 | * |
| 885 | * @see CameraDevice#configureOutputs |
| 886 | * @see CameraDevice#flush |
| 887 | */ |
| 888 | public void onBusy(CameraDevice camera) { |
| 889 | // Default empty implementation |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * The method called when a camera device has been closed with |
| 894 | * {@link CameraDevice#close}. |
| 895 | * |
| 896 | * <p>Any attempt to call methods on this CameraDevice in the |
| 897 | * future will throw a {@link IllegalStateException}.</p> |
| 898 | * |
| 899 | * <p>The default implementation of this method does nothing.</p> |
| 900 | * |
| 901 | * @param camera the camera device that has become closed |
| 902 | */ |
| 903 | public void onClosed(CameraDevice camera) { |
| 904 | // Default empty implementation |
| 905 | } |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 906 | |
| 907 | /** |
| 908 | * The method called when a camera device has finished processing all |
| 909 | * submitted capture requests and has reached an idle state. |
| 910 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 911 | * <p>An idle camera device can have its outputs changed by calling {@link |
| 912 | * CameraDevice#configureOutputs}, which will transition it into the busy state.</p> |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 913 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 914 | * <p>To idle and reconfigure outputs without canceling any submitted |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 915 | * capture requests, the application needs to clear its repeating |
| 916 | * request/burst, if set, with {@link CameraDevice#stopRepeating}, and |
| 917 | * then wait for this callback to be called before calling {@link |
| 918 | * CameraDevice#configureOutputs}.</p> |
| 919 | * |
| 920 | * <p>To idle and reconfigure a camera device as fast as possible, the |
| 921 | * {@link CameraDevice#flush} method can be used, which will discard all |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 922 | * pending and in-progress capture requests. Once the {@link |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 923 | * CameraDevice#flush} method is called, the application must wait for |
| 924 | * this callback to fire before calling {@link |
| 925 | * CameraDevice#configureOutputs}.</p> |
| 926 | * |
| 927 | * <p>The default implementation of this method does nothing.</p> |
| 928 | * |
| 929 | * @param camera the camera device that has become idle |
| 930 | * |
| 931 | * @see CameraDevice#configureOutputs |
| 932 | * @see CameraDevice#stopRepeating |
| 933 | * @see CameraDevice#flush |
| 934 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 935 | public void onIdle(CameraDevice camera) { |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 936 | // Default empty implementation |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * The method called when a camera device is no longer available for |
| 941 | * use. |
| 942 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 943 | * <p>This callback may be called instead of {@link #onOpened} |
| 944 | * if opening the camera fails.</p> |
| 945 | * |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 946 | * <p>Any attempt to call methods on this CameraDevice will throw a |
| 947 | * {@link CameraAccessException}. The disconnection could be due to a |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 948 | * change in security policy or permissions; the physical disconnection |
| 949 | * of a removable camera device; or the camera being needed for a |
| 950 | * higher-priority use case.</p> |
| 951 | * |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 952 | * <p>There may still be capture listener callbacks that are called |
| 953 | * after this method is called, or new image buffers that are delivered |
| 954 | * to active outputs.</p> |
| 955 | * |
| 956 | * <p>The default implementation logs a notice to the system log |
| 957 | * about the disconnection.</p> |
| 958 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 959 | * <p>You should clean up the camera with {@link CameraDevice#close} after |
| 960 | * this happens, as it is not recoverable until opening the camera again |
| 961 | * after it becomes {@link CameraManager.AvailabilityListener#onCameraAvailable available}. |
| 962 | * </p> |
| 963 | * |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 964 | * @param camera the device that has been disconnected |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 965 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 966 | public abstract void onDisconnected(CameraDevice camera); // Must implement |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 967 | |
| 968 | /** |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 969 | * The method called when a camera device has encountered a serious error. |
| 970 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 971 | * <p>This callback may be called instead of {@link #onOpened} |
| 972 | * if opening the camera fails.</p> |
| 973 | * |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 974 | * <p>This indicates a failure of the camera device or camera service in |
| 975 | * some way. Any attempt to call methods on this CameraDevice in the |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 976 | * future will throw a {@link CameraAccessException} with the |
| 977 | * {@link CameraAccessException#CAMERA_ERROR CAMERA_ERROR} reason. |
| 978 | * </p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 979 | * |
| 980 | * <p>There may still be capture completion or camera stream listeners |
| 981 | * that will be called after this error is received.</p> |
| 982 | * |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 983 | * <p>You should clean up the camera with {@link CameraDevice#close} after |
| 984 | * this happens. Further attempts at recovery are error-code specific.</p> |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 985 | * |
| 986 | * @param camera The device reporting the error |
Eino-Ville Talvala | 4af73c2 | 2013-08-14 10:35:46 -0700 | [diff] [blame] | 987 | * @param error The error code, one of the |
| 988 | * {@code CameraDeviceListener.ERROR_*} values. |
| 989 | * |
| 990 | * @see #ERROR_CAMERA_DEVICE |
| 991 | * @see #ERROR_CAMERA_SERVICE |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 992 | * @see #ERROR_CAMERA_DISABLED |
| 993 | * @see #ERROR_CAMERA_IN_USE |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 994 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 995 | public abstract void onError(CameraDevice camera, int error); // Must implement |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 996 | } |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 997 | } |