blob: ca03dae4fc912d61ede2e1a9e545122805fd1f5f [file] [log] [blame]
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08001/*
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 Talvala2f1a2e42013-07-25 17:12:05 -070017package android.hardware.camera2;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080018
Igor Murashkin9c595172014-05-12 13:56:20 -070019import android.hardware.camera2.params.StreamConfigurationMap;
20import android.graphics.ImageFormat;
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -070021import android.os.Handler;
Zhijun He599be612013-09-27 13:43:25 -070022import android.view.Surface;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080023
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080024import java.util.List;
25
26/**
27 * <p>The CameraDevice class is an interface to a single camera connected to an
28 * Android device, allowing for fine-grain control of image capture and
29 * post-processing at high frame rates.</p>
30 *
31 * <p>Your application must declare the
32 * {@link android.Manifest.permission#CAMERA Camera} permission in its manifest
33 * in order to access camera devices.</p>
34 *
35 * <p>A given camera device may provide support at one of two levels: limited or
36 * full. If a device only supports the limited level, then Camera2 exposes a
37 * feature set that is roughly equivalent to the older
38 * {@link android.hardware.Camera Camera} API, although with a cleaner and more
39 * efficient interface. Devices that implement the full level of support
40 * provide substantially improved capabilities over the older camera
41 * API. Applications that target the limited level devices will run unchanged on
42 * the full-level devices; if your application requires a full-level device for
43 * proper operation, declare the "android.hardware.camera2.full" feature in your
44 * manifest.</p>
45 *
46 * @see CameraManager#openCamera
47 * @see android.Manifest.permission#CAMERA
48 */
Igor Murashkin70725502013-06-25 20:27:06 +000049public interface CameraDevice extends AutoCloseable {
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080050
51 /**
52 * Create a request suitable for a camera preview window. Specifically, this
53 * means that high frame rate is given priority over the highest-quality
54 * post-processing. These requests would normally be used with the
55 * {@link #setRepeatingRequest} method.
56 *
57 * @see #createCaptureRequest
58 */
59 public static final int TEMPLATE_PREVIEW = 1;
60
61 /**
Zhijun Heb8b77bf2013-06-28 16:30:12 -070062 * Create a request suitable for still image capture. Specifically, this
63 * means prioritizing image quality over frame rate. These requests would
64 * commonly be used with the {@link #capture} method.
65 *
66 * @see #createCaptureRequest
67 */
68 public static final int TEMPLATE_STILL_CAPTURE = 2;
69
70 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080071 * Create a request suitable for video recording. Specifically, this means
72 * that a stable frame rate is used, and post-processing is set for
73 * recording quality. These requests would commonly be used with the
74 * {@link #setRepeatingRequest} method.
75 *
76 * @see #createCaptureRequest
77 */
Zhijun Heb8b77bf2013-06-28 16:30:12 -070078 public static final int TEMPLATE_RECORD = 3;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080079
80 /**
81 * Create a request suitable for still image capture while recording
82 * video. Specifically, this means maximizing image quality without
83 * disrupting the ongoing recording. These requests would commonly be used
84 * with the {@link #capture} method while a request based on
85 * {@link #TEMPLATE_RECORD} is is in use with {@link #setRepeatingRequest}.
86 *
87 * @see #createCaptureRequest
88 */
89 public static final int TEMPLATE_VIDEO_SNAPSHOT = 4;
90
91 /**
Zhijun Hebbae94a2013-09-13 11:32:20 -070092 * Create a request suitable for zero shutter lag still capture. This means
93 * means maximizing image quality without compromising preview frame rate.
94 * AE/AWB/AF should be on auto mode.
95 *
96 * @see #createCaptureRequest
Zhijun Hebbae94a2013-09-13 11:32:20 -070097 */
98 public static final int TEMPLATE_ZERO_SHUTTER_LAG = 5;
99
100 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800101 * A basic template for direct application control of capture
102 * parameters. All automatic control is disabled (auto-exposure, auto-white
103 * balance, auto-focus), and post-processing parameters are set to preview
104 * quality. The manual capture parameters (exposure, sensitivity, and so on)
105 * are set to reasonable defaults, but should be overriden by the
106 * application depending on the intended use case.
107 *
108 * @see #createCaptureRequest
109 */
Zhijun Hebbae94a2013-09-13 11:32:20 -0700110 public static final int TEMPLATE_MANUAL = 6;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800111
112 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700113 * 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 Murashkin68f40062013-09-10 12:15:54 -0700119 * CameraCharacteristics fixed properties} with {@link
120 * CameraManager#getCameraCharacteristics}.</p>
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700121 *
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 Murashkin68f40062013-09-10 12:15:54 -0700127 * @see CameraManager#getCameraCharacteristics
Zhijun He599be612013-09-27 13:43:25 -0700128 * @see CameraManager#getCameraIdList
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700129 */
130 public String getId();
131
132 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800133 * <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 Murashkin9c595172014-05-12 13:56:20 -0700152 * {@link StreamConfigurationMap#getOutputSizes(Class) processed sizes}
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800153 * 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 Murashkin9c595172014-05-12 13:56:20 -0700160 * {@link StreamConfigurationMap#getOutputSizes(Class) processed sizes}
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800161 * 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 Murashkin9c595172014-05-12 13:56:20 -0700167 * {@link StreamConfigurationMap#getOutputSizes(Class) processed sizes}
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800168 * </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 Murashkin9c595172014-05-12 13:56:20 -0700176 * {@link StreamConfigurationMap#getOutputSizes(int) processed sizes}. Then
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800177 * obtain the Surface with
178 * {@link android.renderscript.Allocation#getSurface}.</li>
179 *
Igor Murashkin9c595172014-05-12 13:56:20 -0700180 * <li>For access to uncompressed or {@link ImageFormat#JPEG JPEG} data in the application:
181 * Create a {@link android.media.ImageReader} object with the desired
182 * {@link StreamConfigurationMap#getOutputFormats() image format}, and a size from the matching
183 * {@link StreamConfigurationMap#getOutputSizes(int) processed size} and {@code format}.
184 * Then obtain a {@link Surface} from it.</li>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800185 * </ul>
186 *
187 * </p>
188 *
189 * <p>This function can take several hundred milliseconds to execute, since
190 * camera hardware may need to be powered on or reconfigured.</p>
191 *
Igor Murashkin53f91c52013-08-09 16:26:14 -0700192 * <p>The camera device will query each Surface's size and formats upon this
193 * call, so they must be set to a valid setting at this time (in particular:
Igor Murashkin94814212014-04-17 18:37:06 -0700194 * if the format is user-visible, it must be one of
195 * {@link StreamConfigurationMap#getOutputFormats}; and the size must be one of
196 * {@link StreamConfigurationMap#getOutputSizes(int)}).</p>
Igor Murashkin53f91c52013-08-09 16:26:14 -0700197 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700198 * <p>When this method is called with valid Surfaces, the device will transition to the {@link
199 * StateListener#onBusy busy state}. Once configuration is complete, the device will transition
200 * into the {@link StateListener#onIdle idle state}. Capture requests using the newly-configured
201 * Surfaces may then be submitted with {@link #capture}, {@link #captureBurst}, {@link
202 * #setRepeatingRequest}, or {@link #setRepeatingBurst}.</p>
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700203 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700204 * <p>If this method is called while the camera device is still actively processing previously
205 * submitted captures, then the following sequence of events occurs: The device transitions to
206 * the busy state and calls the {@link StateListener#onBusy} callback. Second, if a repeating
207 * request is set it is cleared. Third, the device finishes up all in-flight and pending
208 * requests. Finally, once the device is idle, it then reconfigures its outputs, and calls the
209 * {@link StateListener#onIdle} method once it is again ready to accept capture
210 * requests. Therefore, no submitted work is discarded. To idle as fast as possible, use {@link
211 * #flush} and wait for the idle callback before calling configureOutputs. This will discard
212 * work, but reaches the new configuration sooner.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800213 *
214 * <p>Using larger resolution outputs, or more outputs, can result in slower
215 * output rate from the device.</p>
216 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700217 * <p>Configuring the outputs with an empty or null list will transition the camera into an
218 * {@link StateListener#onUnconfigured unconfigured state} instead of the {@link
219 * StateListener#onIdle idle state}. </p>
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700220 *
221 * <p>Calling configureOutputs with the same arguments as the last call to
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700222 * configureOutputs has no effect, and the {@link StateListener#onBusy busy}
223 * and {@link StateListener#onIdle idle} state transitions will happen
224 * immediately.</p>
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700225 *
Benjamin Hendricks24eb8a32013-08-15 12:46:22 -0700226 * @param outputs The new set of Surfaces that should be made available as
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800227 * targets for captured image data.
228 *
229 * @throws IllegalArgumentException if the set of output Surfaces do not
230 * meet the requirements
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700231 * @throws CameraAccessException if the camera device is no longer connected or has
232 * encountered a fatal error
233 * @throws IllegalStateException if the camera device is not idle, or
234 * if the camera device has been closed
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700235 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700236 * @see StateListener#onBusy
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700237 * @see StateListener#onIdle
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700238 * @see StateListener#onActive
239 * @see StateListener#onUnconfigured
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700240 * @see #stopRepeating
241 * @see #flush
Igor Murashkin94814212014-04-17 18:37:06 -0700242 * @see StreamConfigurationMap#getOutputFormats()
243 * @see StreamConfigurationMap#getOutputSizes(int)
244 * @see StreamConfigurationMap#getOutputSizes(Class)
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800245 */
Igor Murashkin70725502013-06-25 20:27:06 +0000246 public void configureOutputs(List<Surface> outputs) throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800247
248 /**
Eino-Ville Talvala70c22072013-08-27 12:09:04 -0700249 * <p>Create a {@link CaptureRequest.Builder} for new capture requests,
250 * initialized with template for a target use case. The settings are chosen
251 * to be the best options for the specific camera device, so it is not
252 * recommended to reuse the same request for a different camera device;
253 * create a builder specific for that device and template and override the
254 * settings as desired, instead.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800255 *
256 * @param templateType An enumeration selecting the use case for this
257 * request; one of the CameraDevice.TEMPLATE_ values.
Eino-Ville Talvala70c22072013-08-27 12:09:04 -0700258 * @return a builder for a capture request, initialized with default
259 * settings for that template, and no output streams
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800260 *
261 * @throws IllegalArgumentException if the templateType is not in the list
262 * of supported templates.
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700263 * @throws CameraAccessException if the camera device is no longer connected or has
264 * encountered a fatal error
265 * @throws IllegalStateException if the camera device has been closed
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800266 *
267 * @see #TEMPLATE_PREVIEW
268 * @see #TEMPLATE_RECORD
269 * @see #TEMPLATE_STILL_CAPTURE
270 * @see #TEMPLATE_VIDEO_SNAPSHOT
271 * @see #TEMPLATE_MANUAL
272 */
Eino-Ville Talvala70c22072013-08-27 12:09:04 -0700273 public CaptureRequest.Builder createCaptureRequest(int templateType)
Igor Murashkin70725502013-06-25 20:27:06 +0000274 throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800275
276 /**
277 * <p>Submit a request for an image to be captured by this CameraDevice.</p>
278 *
279 * <p>The request defines all the parameters for capturing the single image,
280 * including sensor, lens, flash, and post-processing settings.</p>
281 *
282 * <p>Each request will produce one {@link CaptureResult} and produce new
Eino-Ville Talvala70c22072013-08-27 12:09:04 -0700283 * frames for one or more target Surfaces, set with the CaptureRequest
284 * builder's {@link CaptureRequest.Builder#addTarget} method. The target
285 * surfaces must be configured as active outputs with
286 * {@link #configureOutputs} before calling this method.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800287 *
288 * <p>Multiple requests can be in progress at once. They are processed in
289 * first-in, first-out order, with minimal delays between each
290 * capture. Requests submitted through this method have higher priority than
291 * those submitted through {@link #setRepeatingRequest} or
292 * {@link #setRepeatingBurst}, and will be processed as soon as the current
293 * repeat/repeatBurst processing completes.</p>
294 *
Benjamin Hendricks24eb8a32013-08-15 12:46:22 -0700295 * @param request the settings for this capture
296 * @param listener The callback object to notify once this request has been
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800297 * processed. If null, no metadata will be produced for this capture,
298 * although image data will still be produced.
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700299 * @param handler the handler on which the listener should be invoked, or
300 * {@code null} to use the current thread's {@link android.os.Looper
301 * looper}.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800302 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700303 * @return int A unique capture sequence ID used by
304 * {@link CaptureListener#onCaptureSequenceCompleted}.
305 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700306 * @throws CameraAccessException if the camera device is no longer connected or has
307 * encountered a fatal error
308 * @throws IllegalStateException if the camera is currently busy or unconfigured,
309 * or the camera device has been closed.
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700310 * @throws IllegalArgumentException If the request targets Surfaces not
311 * currently configured as outputs. Or if the handler is null, the listener
312 * is not null, and the calling thread has no looper.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800313 *
314 * @see #captureBurst
315 * @see #setRepeatingRequest
316 * @see #setRepeatingBurst
317 */
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700318 public int capture(CaptureRequest request, CaptureListener listener, Handler handler)
Igor Murashkin70725502013-06-25 20:27:06 +0000319 throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800320
321 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700322 * Submit a list of requests to be captured in sequence as a burst. The
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800323 * burst will be captured in the minimum amount of time possible, and will
324 * not be interleaved with requests submitted by other capture or repeat
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700325 * calls.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800326 *
327 * <p>The requests will be captured in order, each capture producing one
Eino-Ville Talvala70c22072013-08-27 12:09:04 -0700328 * {@link CaptureResult} and image buffers for one or more target
329 * {@link android.view.Surface surfaces}. The target surfaces for each
330 * request (set with {@link CaptureRequest.Builder#addTarget}) must be
331 * configured as active outputs with {@link #configureOutputs} before
332 * calling this method.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800333 *
334 * <p>The main difference between this method and simply calling
335 * {@link #capture} repeatedly is that this method guarantees that no
336 * other requests will be interspersed with the burst.</p>
337 *
Benjamin Hendricks24eb8a32013-08-15 12:46:22 -0700338 * @param requests the list of settings for this burst capture
339 * @param listener The callback object to notify each time one of the
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800340 * requests in the burst has been processed. If null, no metadata will be
341 * produced for any requests in this burst, although image data will still
342 * be produced.
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700343 * @param handler the handler on which the listener should be invoked, or
344 * {@code null} to use the current thread's {@link android.os.Looper
345 * looper}.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800346 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700347 * @return int A unique capture sequence ID used by
348 * {@link CaptureListener#onCaptureSequenceCompleted}.
349 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700350 * @throws CameraAccessException if the camera device is no longer connected or has
351 * encountered a fatal error
352 * @throws IllegalStateException if the camera is currently busy or unconfigured,
353 * or the camera device has been closed.
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700354 * @throws IllegalArgumentException If the requests target Surfaces not
355 * currently configured as outputs. Or if the handler is null, the listener
356 * is not null, and the calling thread has no looper.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800357 *
358 * @see #capture
359 * @see #setRepeatingRequest
360 * @see #setRepeatingBurst
361 */
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700362 public int captureBurst(List<CaptureRequest> requests, CaptureListener listener,
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700363 Handler handler) throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800364
365 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700366 * Request endlessly repeating capture of images by this CameraDevice.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800367 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700368 * <p>With this method, the CameraDevice will continually capture images
369 * using the settings in the provided {@link CaptureRequest}, at the maximum
370 * rate possible.</p>
371 *
372 * <p>Repeating requests are a simple way for an application to maintain a
373 * preview or other continuous stream of frames, without having to
374 * continually submit identical requests through {@link #capture}.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800375 *
376 * <p>Repeat requests have lower priority than those submitted
377 * through {@link #capture} or {@link #captureBurst}, so if
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700378 * {@link #capture} is called when a repeating request is active, the
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800379 * capture request will be processed before any further repeating
380 * requests are processed.<p>
381 *
382 * <p>Repeating requests are a simple way for an application to maintain a
383 * preview or other continuous stream of frames, without having to submit
384 * requests through {@link #capture} at video rates.</p>
385 *
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700386 * <p>To stop the repeating capture, call {@link #stopRepeating}. Calling
387 * {@link #flush} will also clear the request.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800388 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700389 * <p>Calling this method will replace any earlier repeating request or
390 * burst set up by this method or {@link #setRepeatingBurst}, although any
391 * in-progress burst will be completed before the new repeat request will be
392 * used.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800393 *
394 * @param request the request to repeat indefinitely
Benjamin Hendricks24eb8a32013-08-15 12:46:22 -0700395 * @param listener The callback object to notify every time the
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800396 * request finishes processing. If null, no metadata will be
397 * produced for this stream of requests, although image data will
398 * still be produced.
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700399 * @param handler the handler on which the listener should be invoked, or
400 * {@code null} to use the current thread's {@link android.os.Looper
401 * looper}.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800402 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700403 * @return int A unique capture sequence ID used by
404 * {@link CaptureListener#onCaptureSequenceCompleted}.
405 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700406 * @throws CameraAccessException if the camera device is no longer connected or has
407 * encountered a fatal error
408 * @throws IllegalStateException if the camera is currently busy or unconfigured,
409 * or the camera device has been closed.
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700410 * @throws IllegalArgumentException If the requests reference Surfaces not
411 * currently configured as outputs. Or if the handler is null, the listener
412 * is not null, and the calling thread has no looper.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800413 *
414 * @see #capture
415 * @see #captureBurst
416 * @see #setRepeatingBurst
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700417 * @see #stopRepeating
418 * @see #flush
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800419 */
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700420 public int setRepeatingRequest(CaptureRequest request, CaptureListener listener,
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700421 Handler handler) throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800422
423 /**
424 * <p>Request endlessly repeating capture of a sequence of images by this
425 * CameraDevice.</p>
426 *
427 * <p>With this method, the CameraDevice will continually capture images,
428 * cycling through the settings in the provided list of
429 * {@link CaptureRequest CaptureRequests}, at the maximum rate possible.</p>
430 *
431 * <p>If a request is submitted through {@link #capture} or
432 * {@link #captureBurst}, the current repetition of the request list will be
433 * completed before the higher-priority request is handled. This guarantees
434 * that the application always receives a complete repeat burst captured in
435 * minimal time, instead of bursts interleaved with higher-priority
436 * captures, or incomplete captures.</p>
437 *
438 * <p>Repeating burst requests are a simple way for an application to
439 * maintain a preview or other continuous stream of frames where each
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700440 * request is different in a predicatable way, without having to continually
441 * submit requests through {@link #captureBurst} .</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800442 *
443 * <p>To stop the repeating capture, call {@link #stopRepeating}. Any
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700444 * ongoing burst will still be completed, however. Calling
445 * {@link #flush} will also clear the request.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800446 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700447 * <p>Calling this method will replace a previously-set repeating request or
448 * burst set up by this method or {@link #setRepeatingRequest}, although any
449 * in-progress burst will be completed before the new repeat burst will be
450 * used.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800451 *
Benjamin Hendricks24eb8a32013-08-15 12:46:22 -0700452 * @param requests the list of requests to cycle through indefinitely
453 * @param listener The callback object to notify each time one of the
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800454 * requests in the repeating bursts has finished processing. If null, no
455 * metadata will be produced for this stream of requests, although image
456 * data will still be produced.
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700457 * @param handler the handler on which the listener should be invoked, or
458 * {@code null} to use the current thread's {@link android.os.Looper
459 * looper}.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800460 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700461 * @return int A unique capture sequence ID used by
462 * {@link CaptureListener#onCaptureSequenceCompleted}.
463 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700464 * @throws CameraAccessException if the camera device is no longer connected or has
465 * encountered a fatal error
466 * @throws IllegalStateException if the camera is currently busy or unconfigured,
467 * or the camera device has been closed.
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700468 * @throws IllegalArgumentException If the requests reference Surfaces not
469 * currently configured as outputs. Or if the handler is null, the listener
470 * is not null, and the calling thread has no looper.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800471 *
472 * @see #capture
473 * @see #captureBurst
474 * @see #setRepeatingRequest
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700475 * @see #stopRepeating
476 * @see #flush
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800477 */
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700478 public int setRepeatingBurst(List<CaptureRequest> requests, CaptureListener listener,
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700479 Handler handler) throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800480
481 /**
482 * <p>Cancel any ongoing repeating capture set by either
483 * {@link #setRepeatingRequest setRepeatingRequest} or
484 * {@link #setRepeatingBurst}. Has no effect on requests submitted through
485 * {@link #capture capture} or {@link #captureBurst captureBurst}.</p>
486 *
487 * <p>Any currently in-flight captures will still complete, as will any
488 * burst that is mid-capture. To ensure that the device has finished
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700489 * processing all of its capture requests and is in idle state, wait for the
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700490 * {@link StateListener#onIdle} callback after calling this
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700491 * method..</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800492 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700493 * @throws CameraAccessException if the camera device is no longer connected or has
494 * encountered a fatal error
495 * @throws IllegalStateException if the camera is currently busy or unconfigured,
496 * or the camera device has been closed.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800497 *
498 * @see #setRepeatingRequest
499 * @see #setRepeatingBurst
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700500 * @see StateListener#onIdle
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800501 */
Igor Murashkin70725502013-06-25 20:27:06 +0000502 public void stopRepeating() throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800503
504 /**
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700505 * Flush all captures currently pending and in-progress as fast as
506 * possible.
507 *
508 * <p>The camera device will discard all of its current work as fast as
509 * possible. Some in-flight captures may complete successfully and call
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700510 * {@link CaptureListener#onCaptureCompleted}, while others will trigger
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700511 * their {@link CaptureListener#onCaptureFailed} callbacks. If a repeating
512 * request or a repeating burst is set, it will be cleared by the flush.</p>
513 *
514 * <p>This method is the fastest way to idle the camera device for
515 * reconfiguration with {@link #configureOutputs}, at the cost of discarding
516 * in-progress work. Once the flush is complete, the idle callback will be
517 * called.</p>
518 *
519 * <p>Flushing will introduce at least a brief pause in the stream of data
520 * from the camera device, since once the flush is complete, the first new
521 * request has to make it through the entire camera pipeline before new
522 * output buffers are produced.</p>
523 *
524 * <p>This means that using {@code flush()} to simply remove pending
525 * requests is not recommended; it's best used for quickly switching output
526 * configurations, or for cancelling long in-progress requests (such as a
527 * multi-second capture).</p>
528 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700529 * @throws CameraAccessException if the camera device is no longer connected or has
530 * encountered a fatal error
531 * @throws IllegalStateException if the camera is not idle/active,
532 * or the camera device has been closed.
533 *
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700534 * @see #setRepeatingRequest
535 * @see #setRepeatingBurst
536 * @see #configureOutputs
537 */
538 public void flush() throws CameraAccessException;
539
540 /**
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700541 * Close the connection to this camera device.
542 *
543 * <p>After this call, all calls to
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800544 * the camera device interface will throw a {@link IllegalStateException},
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700545 * except for calls to close(). Once the device has fully shut down, the
546 * {@link StateListener#onClosed} callback will be called, and the camera is
547 * free to be re-opened.</p>
548 *
549 * <p>After this call, besides the final {@link StateListener#onClosed} call, no calls to the
550 * device's {@link StateListener} will occur, and any remaining submitted capture requests will
551 * not fire their {@link CaptureListener} callbacks.</p>
552 *
553 * <p>To shut down as fast as possible, call the {@link #flush} method and then {@link #close}
554 * once the flush completes. This will discard some capture requests, but results in faster
555 * shutdown.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800556 */
Igor Murashkine363fbb2013-06-25 20:26:06 +0000557 @Override
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700558 public void close();
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800559
560 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700561 * <p>A listener for tracking the progress of a {@link CaptureRequest}
562 * submitted to the camera device.</p>
563 *
564 * <p>This listener is called when a request triggers a capture to start,
565 * and when the capture is complete. In case on an error capturing an image,
566 * the error method is triggered instead of the completion method.</p>
567 *
568 * @see #capture
569 * @see #captureBurst
570 * @see #setRepeatingRequest
571 * @see #setRepeatingBurst
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800572 */
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700573 public static abstract class CaptureListener {
574
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800575 /**
Jianing Wei5a4b02b2014-04-11 09:59:24 -0700576 * This constant is used to indicate that no images were captured for
577 * the request.
578 *
579 * @hide
580 */
581 public static final int NO_FRAMES_CAPTURED = -1;
582
583 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700584 * This method is called when the camera device has started capturing
585 * the output image for the request, at the beginning of image exposure.
586 *
587 * <p>This callback is invoked right as the capture of a frame begins,
588 * so it is the most appropriate time for playing a shutter sound,
589 * or triggering UI indicators of capture.</p>
590 *
591 * <p>The request that is being used for this capture is provided, along
592 * with the actual timestamp for the start of exposure. This timestamp
593 * matches the timestamp that will be included in
594 * {@link CaptureResult#SENSOR_TIMESTAMP the result timestamp field},
595 * and in the buffers sent to each output Surface. These buffer
596 * timestamps are accessible through, for example,
597 * {@link android.media.Image#getTimestamp() Image.getTimestamp()} or
598 * {@link android.graphics.SurfaceTexture#getTimestamp()}.</p>
599 *
600 * <p>For the simplest way to play a shutter sound camera shutter or a
601 * video recording start/stop sound, see the
602 * {@link android.media.MediaActionSound} class.</p>
603 *
604 * <p>The default implementation of this method does nothing.</p>
605 *
606 * @param camera the CameraDevice sending the callback
607 * @param request the request for the capture that just begun
608 * @param timestamp the timestamp at start of capture, in nanoseconds.
609 *
610 * @see android.media.MediaActionSound
611 */
612 public void onCaptureStarted(CameraDevice camera,
613 CaptureRequest request, long timestamp) {
614 // default empty implementation
615 }
616
617 /**
Eino-Ville Talvala7a313102013-11-07 14:45:06 -0800618 * This method is called when some results from an image capture are
619 * available.
620 *
621 * <p>The result provided here will contain some subset of the fields of
622 * a full result. Multiple onCapturePartial calls may happen per
623 * capture; a given result field will only be present in one partial
624 * capture at most. The final onCaptureCompleted call will always
625 * contain all the fields, whether onCapturePartial was called or
626 * not.</p>
627 *
628 * <p>The default implementation of this method does nothing.</p>
629 *
630 * @param camera The CameraDevice sending the callback.
631 * @param request The request that was given to the CameraDevice
632 * @param result The partial output metadata from the capture, which
633 * includes a subset of the CaptureResult fields.
634 *
635 * @see #capture
636 * @see #captureBurst
637 * @see #setRepeatingRequest
638 * @see #setRepeatingBurst
639 *
640 * @hide
641 */
642 public void onCapturePartial(CameraDevice camera,
643 CaptureRequest request, CaptureResult result) {
644 // default empty implementation
645 }
646
647 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700648 * This method is called when an image capture has completed and the
649 * result metadata is available.
650 *
651 * <p>The default implementation of this method does nothing.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800652 *
653 * @param camera The CameraDevice sending the callback.
654 * @param request The request that was given to the CameraDevice
655 * @param result The output metadata from the capture, including the
656 * final capture parameters and the state of the camera system during
657 * capture.
658 *
659 * @see #capture
660 * @see #captureBurst
661 * @see #setRepeatingRequest
662 * @see #setRepeatingBurst
663 */
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700664 public void onCaptureCompleted(CameraDevice camera,
665 CaptureRequest request, CaptureResult result) {
666 // default empty implementation
667 }
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800668
669 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700670 * This method is called instead of {@link #onCaptureCompleted} when the
671 * camera device failed to produce a {@link CaptureResult} for the
672 * request.
673 *
674 * <p>Other requests are unaffected, and some or all image buffers from
675 * the capture may have been pushed to their respective output
676 * streams.</p>
677 *
678 * <p>The default implementation of this method does nothing.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800679 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700680 * @param camera
681 * The CameraDevice sending the callback.
682 * @param request
683 * The request that was given to the CameraDevice
684 * @param failure
685 * The output failure from the capture, including the failure reason
686 * and the frame number.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800687 *
688 * @see #capture
689 * @see #captureBurst
690 * @see #setRepeatingRequest
691 * @see #setRepeatingBurst
692 */
693 public void onCaptureFailed(CameraDevice camera,
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700694 CaptureRequest request, CaptureFailure failure) {
695 // default empty implementation
696 }
697
698 /**
699 * This method is called independently of the others in CaptureListener,
700 * when a capture sequence finishes and all {@link CaptureResult}
701 * or {@link CaptureFailure} for it have been returned via this listener.
702 *
703 * @param camera
704 * The CameraDevice sending the callback.
705 * @param sequenceId
706 * A sequence ID returned by the {@link #capture} family of functions.
Jianing Wei5a4b02b2014-04-11 09:59:24 -0700707 * @param lastFrameNumber
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700708 * The last frame number (returned by {@link CaptureResult#getFrameNumber}
709 * or {@link CaptureFailure#getFrameNumber}) in the capture sequence.
Jianing Wei5a4b02b2014-04-11 09:59:24 -0700710 * The last frame number may be equal to NO_FRAMES_CAPTURED if no images
711 * were captured for this sequence. This can happen, for example, when a
712 * repeating request or burst is cleared right after being set.
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700713 *
714 * @see CaptureResult#getFrameNumber()
715 * @see CaptureFailure#getFrameNumber()
716 * @see CaptureResult#getSequenceId()
717 * @see CaptureFailure#getSequenceId()
718 */
719 public void onCaptureSequenceCompleted(CameraDevice camera,
Jianing Wei5a4b02b2014-04-11 09:59:24 -0700720 int sequenceId, int lastFrameNumber) {
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700721 // default empty implementation
722 }
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800723 }
724
725 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700726 * A listener for notifications about the state of a camera
727 * device.
728 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700729 * <p>A listener must be provided to the {@link CameraManager#openCamera}
730 * method to open a camera device.</p>
731 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700732 * <p>These events include notifications about the device becoming idle (
733 * allowing for {@link #configureOutputs} to be called), about device
734 * disconnection, and about unexpected device errors.</p>
735 *
736 * <p>Events about the progress of specific {@link CaptureRequest
737 * CaptureRequests} are provided through a {@link CaptureListener} given to
738 * the {@link #capture}, {@link #captureBurst}, {@link
739 * #setRepeatingRequest}, or {@link #setRepeatingBurst} methods.
740 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700741 * @see CameraManager#openCamera
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800742 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700743 public static abstract class StateListener {
744 /**
745 * An error code that can be reported by {@link #onError}
746 * indicating that the camera device is in use already.
747 *
748 * <p>
749 * This error can be produced when opening the camera fails.
750 * </p>
751 *
752 * @see #onError
753 */
754 public static final int ERROR_CAMERA_IN_USE = 1;
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700755
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800756 /**
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700757 * An error code that can be reported by {@link #onError}
758 * indicating that the camera device could not be opened
759 * because there are too many other open camera devices.
760 *
761 * <p>
762 * The system-wide limit for number of open cameras has been reached,
763 * and more camera devices cannot be opened until previous instances are
764 * closed.
765 * </p>
766 *
767 * <p>
768 * This error can be produced when opening the camera fails.
769 * </p>
770 *
771 * @see #onError
772 */
773 public static final int ERROR_MAX_CAMERAS_IN_USE = 2;
774
775 /**
776 * An error code that can be reported by {@link #onError}
777 * indicating that the camera device could not be opened due to a device
778 * policy.
779 *
780 * @see android.app.admin.DevicePolicyManager#setCameraDisabled(android.content.ComponentName, boolean)
781 * @see #onError
782 */
783 public static final int ERROR_CAMERA_DISABLED = 3;
784
785 /**
786 * An error code that can be reported by {@link #onError}
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700787 * indicating that the camera device has encountered a fatal error.
788 *
789 * <p>The camera device needs to be re-opened to be used again.</p>
790 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700791 * @see #onError
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700792 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700793 public static final int ERROR_CAMERA_DEVICE = 4;
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700794
795 /**
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700796 * An error code that can be reported by {@link #onError}
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700797 * indicating that the camera service has encountered a fatal error.
798 *
799 * <p>The Android device may need to be shut down and restarted to restore
800 * camera function, or there may be a persistent hardware problem.</p>
801 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700802 * <p>An attempt at recovery <i>may</i> be possible by closing the
803 * CameraDevice and the CameraManager, and trying to acquire all resources
804 * again from scratch.</p>
805 *
806 * @see #onError
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700807 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700808 public static final int ERROR_CAMERA_SERVICE = 5;
809
810 /**
811 * The method called when a camera device has finished opening.
812 *
813 * <p>An opened camera will immediately afterwards transition into
814 * {@link #onUnconfigured}.</p>
815 *
816 * @param camera the camera device that has become opened
817 */
818 public abstract void onOpened(CameraDevice camera); // Must implement
819
820 /**
821 * The method called when a camera device has no outputs configured.
822 *
823 * <p>An unconfigured camera device needs to be configured with
824 * {@link CameraDevice#configureOutputs} before being able to
825 * submit any capture request.</p>
826 *
827 * <p>This state may be entered by a newly opened camera or by
828 * calling {@link CameraDevice#configureOutputs} with a null/empty
829 * list of Surfaces when idle.</p>
830 *
831 * <p>Any attempts to submit a capture request while in this state
832 * will result in an {@link IllegalStateException} being thrown.</p>
833 *
834 * <p>The default implementation of this method does nothing.</p>
835 *
836 * @param camera the camera device has that become unconfigured
837 */
838 public void onUnconfigured(CameraDevice camera) {
839 // Default empty implementation
840 }
841
842 /**
843 * The method called when a camera device begins processing
844 * {@link CaptureRequest capture requests}.
845 *
846 * <p>A camera may not be re-configured while in this state. The camera
847 * will transition to the idle state once all pending captures have
848 * completed. If a repeating request is set, the camera will remain active
849 * until it is cleared and the remaining requests finish processing. To
850 * transition to the idle state as quickly as possible, call {@link #flush()},
851 * which will idle the camera device as quickly as possible, likely canceling
852 * most in-progress captures.</p>
853 *
854 * <p>All calls except for {@link CameraDevice#configureOutputs} are
855 * legal while in this state.
856 * </p>
857 *
858 * <p>The default implementation of this method does nothing.</p>
859 *
860 * @param camera the camera device that has become active
861 *
862 * @see CameraDevice#capture
863 * @see CameraDevice#captureBurst
864 * @see CameraDevice#setRepeatingBurst
865 * @see CameraDevice#setRepeatingRequest
866 */
867 public void onActive(CameraDevice camera) {
868 // Default empty implementation
869 }
870
871 /**
872 * The method called when a camera device is busy.
873 *
874 * <p>A camera becomes busy while it's outputs are being configured
875 * (after a call to {@link CameraDevice#configureOutputs} or while it's
876 * being flushed (after a call to {@link CameraDevice#flush}.</p>
877 *
878 * <p>Once the on-going operations are complete, the camera will automatically
879 * transition into {@link #onIdle} if there is at least one configured output,
880 * or {@link #onUnconfigured} otherwise.</p>
881 *
882 * <p>Any attempts to manipulate the camera while its is busy
883 * will result in an {@link IllegalStateException} being thrown.</p>
884 *
885 * <p>Only the following methods are valid to call while in this state:
886 * <ul>
887 * <li>{@link CameraDevice#getId}</li>
888 * <li>{@link CameraDevice#createCaptureRequest}</li>
889 * <li>{@link CameraDevice#close}</li>
890 * </ul>
891 * </p>
892 *
893 * <p>The default implementation of this method does nothing.</p>
894 *
895 * @param camera the camera device that has become busy
896 *
897 * @see CameraDevice#configureOutputs
898 * @see CameraDevice#flush
899 */
900 public void onBusy(CameraDevice camera) {
901 // Default empty implementation
902 }
903
904 /**
905 * The method called when a camera device has been closed with
906 * {@link CameraDevice#close}.
907 *
908 * <p>Any attempt to call methods on this CameraDevice in the
909 * future will throw a {@link IllegalStateException}.</p>
910 *
911 * <p>The default implementation of this method does nothing.</p>
912 *
913 * @param camera the camera device that has become closed
914 */
915 public void onClosed(CameraDevice camera) {
916 // Default empty implementation
917 }
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700918
919 /**
920 * The method called when a camera device has finished processing all
921 * submitted capture requests and has reached an idle state.
922 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700923 * <p>An idle camera device can have its outputs changed by calling {@link
924 * CameraDevice#configureOutputs}, which will transition it into the busy state.</p>
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700925 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700926 * <p>To idle and reconfigure outputs without canceling any submitted
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700927 * capture requests, the application needs to clear its repeating
928 * request/burst, if set, with {@link CameraDevice#stopRepeating}, and
929 * then wait for this callback to be called before calling {@link
930 * CameraDevice#configureOutputs}.</p>
931 *
932 * <p>To idle and reconfigure a camera device as fast as possible, the
933 * {@link CameraDevice#flush} method can be used, which will discard all
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700934 * pending and in-progress capture requests. Once the {@link
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700935 * CameraDevice#flush} method is called, the application must wait for
936 * this callback to fire before calling {@link
937 * CameraDevice#configureOutputs}.</p>
938 *
939 * <p>The default implementation of this method does nothing.</p>
940 *
941 * @param camera the camera device that has become idle
942 *
943 * @see CameraDevice#configureOutputs
944 * @see CameraDevice#stopRepeating
945 * @see CameraDevice#flush
946 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700947 public void onIdle(CameraDevice camera) {
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700948 // Default empty implementation
949 }
950
951 /**
952 * The method called when a camera device is no longer available for
953 * use.
954 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700955 * <p>This callback may be called instead of {@link #onOpened}
956 * if opening the camera fails.</p>
957 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700958 * <p>Any attempt to call methods on this CameraDevice will throw a
959 * {@link CameraAccessException}. The disconnection could be due to a
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800960 * change in security policy or permissions; the physical disconnection
961 * of a removable camera device; or the camera being needed for a
962 * higher-priority use case.</p>
963 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700964 * <p>There may still be capture listener callbacks that are called
965 * after this method is called, or new image buffers that are delivered
966 * to active outputs.</p>
967 *
968 * <p>The default implementation logs a notice to the system log
969 * about the disconnection.</p>
970 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700971 * <p>You should clean up the camera with {@link CameraDevice#close} after
972 * this happens, as it is not recoverable until opening the camera again
973 * after it becomes {@link CameraManager.AvailabilityListener#onCameraAvailable available}.
974 * </p>
975 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700976 * @param camera the device that has been disconnected
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800977 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700978 public abstract void onDisconnected(CameraDevice camera); // Must implement
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800979
980 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700981 * The method called when a camera device has encountered a serious error.
982 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700983 * <p>This callback may be called instead of {@link #onOpened}
984 * if opening the camera fails.</p>
985 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700986 * <p>This indicates a failure of the camera device or camera service in
987 * some way. Any attempt to call methods on this CameraDevice in the
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700988 * future will throw a {@link CameraAccessException} with the
989 * {@link CameraAccessException#CAMERA_ERROR CAMERA_ERROR} reason.
990 * </p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800991 *
992 * <p>There may still be capture completion or camera stream listeners
993 * that will be called after this error is received.</p>
994 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700995 * <p>You should clean up the camera with {@link CameraDevice#close} after
996 * this happens. Further attempts at recovery are error-code specific.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800997 *
998 * @param camera The device reporting the error
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700999 * @param error The error code, one of the
1000 * {@code CameraDeviceListener.ERROR_*} values.
1001 *
1002 * @see #ERROR_CAMERA_DEVICE
1003 * @see #ERROR_CAMERA_SERVICE
Igor Murashkin5c9eaf62013-09-10 19:35:24 -07001004 * @see #ERROR_CAMERA_DISABLED
1005 * @see #ERROR_CAMERA_IN_USE
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08001006 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -07001007 public abstract void onError(CameraDevice camera, int error); // Must implement
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08001008 }
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08001009}