blob: 42880afa409e8814412a60015ebbf5aa5177c4ee [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
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -070019import android.os.Handler;
Zhijun He599be612013-09-27 13:43:25 -070020import android.view.Surface;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080021
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080022import 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 Murashkin70725502013-06-25 20:27:06 +000047public interface CameraDevice extends AutoCloseable {
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080048
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 Heb8b77bf2013-06-28 16:30:12 -070060 * 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 Talvalab2675542012-12-12 13:29:45 -080069 * 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 Heb8b77bf2013-06-28 16:30:12 -070076 public static final int TEMPLATE_RECORD = 3;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080077
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 Hebbae94a2013-09-13 11:32:20 -070090 * 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 Talvalab2675542012-12-12 13:29:45 -0800100 * 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 Hebbae94a2013-09-13 11:32:20 -0700108 * @hide
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800109 */
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 Murashkin68f40062013-09-10 12:15:54 -0700152 * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES 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 Murashkin68f40062013-09-10 12:15:54 -0700160 * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES 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 Murashkin68f40062013-09-10 12:15:54 -0700167 * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES 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 Murashkin68f40062013-09-10 12:15:54 -0700176 * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES processed sizes}. Then
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800177 * obtain the Surface with
178 * {@link android.renderscript.Allocation#getSurface}.</li>
179 *
Eino-Ville Talvala5a32b20c2013-08-08 12:38:36 -0700180 * <li>For access to uncompressed or JPEG data in the application: Create a
181 * {@link android.media.ImageReader} object with the desired
Igor Murashkin68f40062013-09-10 12:15:54 -0700182 * {@link CameraCharacteristics#SCALER_AVAILABLE_FORMATS image format}, and a
Eino-Ville Talvala5a32b20c2013-08-08 12:38:36 -0700183 * size from the matching
Igor Murashkin68f40062013-09-10 12:15:54 -0700184 * {@link CameraCharacteristics#SCALER_AVAILABLE_PROCESSED_SIZES processed},
185 * {@link CameraCharacteristics#SCALER_AVAILABLE_JPEG_SIZES jpeg}. Then obtain
Eino-Ville Talvala5a32b20c2013-08-08 12:38:36 -0700186 * a Surface from it.</li>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800187 *
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 Murashkin53f91c52013-08-09 16:26:14 -0700195 * <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 Talvala868d9042013-10-03 11:15:21 -0700200 * <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 Talvala4af73c22013-08-14 10:35:46 -0700205 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700206 * <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 Talvalab2675542012-12-12 13:29:45 -0800215 *
216 * <p>Using larger resolution outputs, or more outputs, can result in slower
217 * output rate from the device.</p>
218 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700219 * <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 Murashkin5c9eaf62013-09-10 19:35:24 -0700222 *
223 * <p>Calling configureOutputs with the same arguments as the last call to
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700224 * configureOutputs has no effect, and the {@link StateListener#onBusy busy}
225 * and {@link StateListener#onIdle idle} state transitions will happen
226 * immediately.</p>
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700227 *
Benjamin Hendricks24eb8a32013-08-15 12:46:22 -0700228 * @param outputs The new set of Surfaces that should be made available as
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800229 * targets for captured image data.
230 *
231 * @throws IllegalArgumentException if the set of output Surfaces do not
232 * meet the requirements
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700233 * @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 Talvala4af73c22013-08-14 10:35:46 -0700237 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700238 * @see StateListener#onBusy
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700239 * @see StateListener#onIdle
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700240 * @see StateListener#onActive
241 * @see StateListener#onUnconfigured
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700242 * @see #stopRepeating
243 * @see #flush
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800244 */
Igor Murashkin70725502013-06-25 20:27:06 +0000245 public void configureOutputs(List<Surface> outputs) throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800246
247 /**
Eino-Ville Talvala70c22072013-08-27 12:09:04 -0700248 * <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 Talvalab2675542012-12-12 13:29:45 -0800254 *
255 * @param templateType An enumeration selecting the use case for this
256 * request; one of the CameraDevice.TEMPLATE_ values.
Eino-Ville Talvala70c22072013-08-27 12:09:04 -0700257 * @return a builder for a capture request, initialized with default
258 * settings for that template, and no output streams
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800259 *
260 * @throws IllegalArgumentException if the templateType is not in the list
261 * of supported templates.
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700262 * @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 Talvalab2675542012-12-12 13:29:45 -0800265 *
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 Talvala70c22072013-08-27 12:09:04 -0700272 public CaptureRequest.Builder createCaptureRequest(int templateType)
Igor Murashkin70725502013-06-25 20:27:06 +0000273 throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800274
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 Talvala70c22072013-08-27 12:09:04 -0700282 * 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 Talvalab2675542012-12-12 13:29:45 -0800286 *
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 Hendricks24eb8a32013-08-15 12:46:22 -0700294 * @param request the settings for this capture
295 * @param listener The callback object to notify once this request has been
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800296 * processed. If null, no metadata will be produced for this capture,
297 * although image data will still be produced.
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700298 * @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 Talvalab2675542012-12-12 13:29:45 -0800301 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700302 * @return int A unique capture sequence ID used by
303 * {@link CaptureListener#onCaptureSequenceCompleted}.
304 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700305 * @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 Talvala4af73c22013-08-14 10:35:46 -0700309 * @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 Talvalab2675542012-12-12 13:29:45 -0800312 *
313 * @see #captureBurst
314 * @see #setRepeatingRequest
315 * @see #setRepeatingBurst
316 */
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700317 public int capture(CaptureRequest request, CaptureListener listener, Handler handler)
Igor Murashkin70725502013-06-25 20:27:06 +0000318 throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800319
320 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700321 * Submit a list of requests to be captured in sequence as a burst. The
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800322 * 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 Talvala4af73c22013-08-14 10:35:46 -0700324 * calls.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800325 *
326 * <p>The requests will be captured in order, each capture producing one
Eino-Ville Talvala70c22072013-08-27 12:09:04 -0700327 * {@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 Talvalab2675542012-12-12 13:29:45 -0800332 *
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 Hendricks24eb8a32013-08-15 12:46:22 -0700337 * @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 Talvalab2675542012-12-12 13:29:45 -0800339 * 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 Talvala4af73c22013-08-14 10:35:46 -0700342 * @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 Talvalab2675542012-12-12 13:29:45 -0800345 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700346 * @return int A unique capture sequence ID used by
347 * {@link CaptureListener#onCaptureSequenceCompleted}.
348 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700349 * @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 Talvala4af73c22013-08-14 10:35:46 -0700353 * @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 Talvalab2675542012-12-12 13:29:45 -0800356 *
357 * @see #capture
358 * @see #setRepeatingRequest
359 * @see #setRepeatingBurst
360 */
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700361 public int captureBurst(List<CaptureRequest> requests, CaptureListener listener,
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700362 Handler handler) throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800363
364 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700365 * Request endlessly repeating capture of images by this CameraDevice.
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800366 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700367 * <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 Talvalab2675542012-12-12 13:29:45 -0800374 *
375 * <p>Repeat requests have lower priority than those submitted
376 * through {@link #capture} or {@link #captureBurst}, so if
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700377 * {@link #capture} is called when a repeating request is active, the
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800378 * 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 Talvala8ebd52b2013-08-13 12:09:44 -0700385 * <p>To stop the repeating capture, call {@link #stopRepeating}. Calling
386 * {@link #flush} will also clear the request.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800387 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700388 * <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 Talvalab2675542012-12-12 13:29:45 -0800392 *
393 * @param request the request to repeat indefinitely
Benjamin Hendricks24eb8a32013-08-15 12:46:22 -0700394 * @param listener The callback object to notify every time the
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800395 * 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 Talvala4af73c22013-08-14 10:35:46 -0700398 * @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 Talvalab2675542012-12-12 13:29:45 -0800401 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700402 * @return int A unique capture sequence ID used by
403 * {@link CaptureListener#onCaptureSequenceCompleted}.
404 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700405 * @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 Talvala4af73c22013-08-14 10:35:46 -0700409 * @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 Talvalab2675542012-12-12 13:29:45 -0800412 *
413 * @see #capture
414 * @see #captureBurst
415 * @see #setRepeatingBurst
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700416 * @see #stopRepeating
417 * @see #flush
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800418 */
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700419 public int setRepeatingRequest(CaptureRequest request, CaptureListener listener,
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700420 Handler handler) throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800421
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 Talvala4af73c22013-08-14 10:35:46 -0700439 * request is different in a predicatable way, without having to continually
440 * submit requests through {@link #captureBurst} .</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800441 *
442 * <p>To stop the repeating capture, call {@link #stopRepeating}. Any
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700443 * ongoing burst will still be completed, however. Calling
444 * {@link #flush} will also clear the request.</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800445 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700446 * <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 Talvalab2675542012-12-12 13:29:45 -0800450 *
Benjamin Hendricks24eb8a32013-08-15 12:46:22 -0700451 * @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 Talvalab2675542012-12-12 13:29:45 -0800453 * 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 Talvala4af73c22013-08-14 10:35:46 -0700456 * @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 Talvalab2675542012-12-12 13:29:45 -0800459 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700460 * @return int A unique capture sequence ID used by
461 * {@link CaptureListener#onCaptureSequenceCompleted}.
462 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700463 * @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 Talvala4af73c22013-08-14 10:35:46 -0700467 * @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 Talvalab2675542012-12-12 13:29:45 -0800470 *
471 * @see #capture
472 * @see #captureBurst
473 * @see #setRepeatingRequest
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700474 * @see #stopRepeating
475 * @see #flush
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800476 */
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700477 public int setRepeatingBurst(List<CaptureRequest> requests, CaptureListener listener,
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700478 Handler handler) throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800479
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 Talvala4af73c22013-08-14 10:35:46 -0700488 * processing all of its capture requests and is in idle state, wait for the
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700489 * {@link StateListener#onIdle} callback after calling this
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700490 * method..</p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800491 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700492 * @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 Talvalab2675542012-12-12 13:29:45 -0800496 *
497 * @see #setRepeatingRequest
498 * @see #setRepeatingBurst
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700499 * @see StateListener#onIdle
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800500 */
Igor Murashkin70725502013-06-25 20:27:06 +0000501 public void stopRepeating() throws CameraAccessException;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800502
503 /**
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700504 * 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 Talvala4af73c22013-08-14 10:35:46 -0700509 * {@link CaptureListener#onCaptureCompleted}, while others will trigger
Eino-Ville Talvala8ebd52b2013-08-13 12:09:44 -0700510 * 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 Murashkin5c9eaf62013-09-10 19:35:24 -0700528 * @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 Talvala8ebd52b2013-08-13 12:09:44 -0700533 * @see #setRepeatingRequest
534 * @see #setRepeatingBurst
535 * @see #configureOutputs
536 */
537 public void flush() throws CameraAccessException;
538
539 /**
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700540 * Close the connection to this camera device.
541 *
542 * <p>After this call, all calls to
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800543 * the camera device interface will throw a {@link IllegalStateException},
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700544 * 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 Talvalab2675542012-12-12 13:29:45 -0800555 */
Igor Murashkine363fbb2013-06-25 20:26:06 +0000556 @Override
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700557 public void close();
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800558
559 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700560 * <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 Talvalab2675542012-12-12 13:29:45 -0800571 */
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700572 public static abstract class CaptureListener {
573
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800574 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700575 * 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 Talvala7a313102013-11-07 14:45:06 -0800609 * 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 Talvala4af73c22013-08-14 10:35:46 -0700639 * 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 Talvalab2675542012-12-12 13:29:45 -0800643 *
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 Talvala4af73c22013-08-14 10:35:46 -0700655 public void onCaptureCompleted(CameraDevice camera,
656 CaptureRequest request, CaptureResult result) {
657 // default empty implementation
658 }
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800659
660 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700661 * 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 Talvalab2675542012-12-12 13:29:45 -0800670 *
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700671 * @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 Talvalab2675542012-12-12 13:29:45 -0800678 *
679 * @see #capture
680 * @see #captureBurst
681 * @see #setRepeatingRequest
682 * @see #setRepeatingBurst
683 */
684 public void onCaptureFailed(CameraDevice camera,
Igor Murashkin6bbf9dc2013-09-05 12:22:00 -0700685 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 Talvala4af73c22013-08-14 10:35:46 -0700709 // default empty implementation
710 }
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800711 }
712
713 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700714 * A listener for notifications about the state of a camera
715 * device.
716 *
Eino-Ville Talvala868d9042013-10-03 11:15:21 -0700717 * <p>A listener must be provided to the {@link CameraManager#openCamera}
718 * method to open a camera device.</p>
719 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700720 * <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 Talvala868d9042013-10-03 11:15:21 -0700729 * @see CameraManager#openCamera
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800730 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700731 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 Talvala4af73c22013-08-14 10:35:46 -0700743
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800744 /**
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700745 * 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 Talvala4af73c22013-08-14 10:35:46 -0700775 * 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 Murashkin5c9eaf62013-09-10 19:35:24 -0700779 * @see #onError
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700780 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700781 public static final int ERROR_CAMERA_DEVICE = 4;
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700782
783 /**
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700784 * An error code that can be reported by {@link #onError}
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700785 * 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 Murashkin5c9eaf62013-09-10 19:35:24 -0700790 * <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 Talvala4af73c22013-08-14 10:35:46 -0700795 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700796 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 Talvala4af73c22013-08-14 10:35:46 -0700906
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 Murashkin5c9eaf62013-09-10 19:35:24 -0700911 * <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 Talvala4af73c22013-08-14 10:35:46 -0700913 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700914 * <p>To idle and reconfigure outputs without canceling any submitted
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700915 * 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 Murashkin5c9eaf62013-09-10 19:35:24 -0700922 * pending and in-progress capture requests. Once the {@link
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700923 * 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 Murashkin5c9eaf62013-09-10 19:35:24 -0700935 public void onIdle(CameraDevice camera) {
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700936 // Default empty implementation
937 }
938
939 /**
940 * The method called when a camera device is no longer available for
941 * use.
942 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700943 * <p>This callback may be called instead of {@link #onOpened}
944 * if opening the camera fails.</p>
945 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700946 * <p>Any attempt to call methods on this CameraDevice will throw a
947 * {@link CameraAccessException}. The disconnection could be due to a
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800948 * 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 Talvala4af73c22013-08-14 10:35:46 -0700952 * <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 Murashkin5c9eaf62013-09-10 19:35:24 -0700959 * <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 Talvala4af73c22013-08-14 10:35:46 -0700964 * @param camera the device that has been disconnected
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800965 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700966 public abstract void onDisconnected(CameraDevice camera); // Must implement
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800967
968 /**
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700969 * The method called when a camera device has encountered a serious error.
970 *
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700971 * <p>This callback may be called instead of {@link #onOpened}
972 * if opening the camera fails.</p>
973 *
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700974 * <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 Murashkin5c9eaf62013-09-10 19:35:24 -0700976 * future will throw a {@link CameraAccessException} with the
977 * {@link CameraAccessException#CAMERA_ERROR CAMERA_ERROR} reason.
978 * </p>
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800979 *
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 Murashkin5c9eaf62013-09-10 19:35:24 -0700983 * <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 Talvalab2675542012-12-12 13:29:45 -0800985 *
986 * @param camera The device reporting the error
Eino-Ville Talvala4af73c22013-08-14 10:35:46 -0700987 * @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 Murashkin5c9eaf62013-09-10 19:35:24 -0700992 * @see #ERROR_CAMERA_DISABLED
993 * @see #ERROR_CAMERA_IN_USE
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800994 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700995 public abstract void onError(CameraDevice camera, int error); // Must implement
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800996 }
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800997}