blob: 32a7399a4b62e9283aaeb3db59e7643f21c83f56 [file] [log] [blame]
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -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
17#ifndef ANDROID_INCLUDE_CAMERA3_H
18#define ANDROID_INCLUDE_CAMERA3_H
19
Eino-Ville Talvala7effe0c2013-02-15 12:09:48 -080020#include <system/camera_metadata.h>
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080021#include "camera_common.h"
22
23/**
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080024 * Camera device HAL 3.2 [ CAMERA_DEVICE_API_VERSION_3_2 ]
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080025 *
26 * EXPERIMENTAL.
27 *
28 * Supports the android.hardware.Camera API.
29 *
30 * Camera devices that support this version of the HAL must return
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080031 * CAMERA_DEVICE_API_VERSION_3_2 in camera_device_t.common.version and in
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080032 * camera_info_t.device_version (from camera_module_t.get_camera_info).
33 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080034 * CAMERA_DEVICE_API_VERSION_3_2:
35 * Camera modules that may contain version 3.2 devices must implement at
36 * least version 2.2 of the camera module interface (as defined by
37 * camera_module_t.common.module_api_version).
38 *
39 * <= CAMERA_DEVICE_API_VERSION_3_1:
40 * Camera modules that may contain version 3.1 (or 3.0) devices must
41 * implement at least version 2.0 of the camera module interface
42 * (as defined by camera_module_t.common.module_api_version).
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080043 *
44 * See camera_common.h for more versioning details.
45 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070046 * Documentation index:
47 * S1. Version history
48 * S2. Startup and operation sequencing
49 * S3. Operational modes
50 * S4. 3A modes and state machines
Eino-Ville Talvalab6059442013-04-29 15:26:16 -070051 * S5. Cropping
52 * S6. Error management
Zhijun He709e5872014-01-17 15:25:21 -080053 * S7. Key Performance Indicator (KPI) glossary
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070054 */
55
56/**
57 * S1. Version history:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080058 *
59 * 1.0: Initial Android camera HAL (Android 4.0) [camera.h]:
60 *
61 * - Converted from C++ CameraHardwareInterface abstraction layer.
62 *
63 * - Supports android.hardware.Camera API.
64 *
65 * 2.0: Initial release of expanded-capability HAL (Android 4.2) [camera2.h]:
66 *
67 * - Sufficient for implementing existing android.hardware.Camera API.
68 *
69 * - Allows for ZSL queue in camera service layer
70 *
71 * - Not tested for any new features such manual capture control, Bayer RAW
72 * capture, reprocessing of RAW data.
73 *
74 * 3.0: First revision of expanded-capability HAL:
75 *
76 * - Major version change since the ABI is completely different. No change to
77 * the required hardware capabilities or operational model from 2.0.
78 *
79 * - Reworked input request and stream queue interfaces: Framework calls into
80 * HAL with next request and stream buffers already dequeued. Sync framework
81 * support is included, necessary for efficient implementations.
82 *
83 * - Moved triggers into requests, most notifications into results.
84 *
85 * - Consolidated all callbacks into framework into one structure, and all
86 * setup methods into a single initialize() call.
87 *
88 * - Made stream configuration into a single call to simplify stream
89 * management. Bidirectional streams replace STREAM_FROM_STREAM construct.
90 *
91 * - Limited mode semantics for older/limited hardware devices.
Alex Ray2ce219a2013-06-14 15:09:30 -070092 *
93 * 3.1: Minor revision of expanded-capability HAL:
94 *
95 * - configure_streams passes consumer usage flags to the HAL.
Alex Ray5f2fd852013-06-24 11:28:05 -070096 *
97 * - flush call to drop all in-flight requests/buffers as fast as possible.
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080098 *
99 * 3.2: Minor revision of expanded-capability HAL:
100 *
101 * - Deprecates get_metadata_vendor_tag_ops. Please use get_vendor_tag_ops
102 * in camera_common.h instead.
Igor Murashkin78aa1262014-01-09 16:23:43 -0800103 *
104 * - register_stream_buffers deprecated. All gralloc buffers provided
105 * by framework to HAL in process_capture_request may be new at any time.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800106 */
107
108/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700109 * S2. Startup and general expected operation sequence:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800110 *
111 * 1. Framework calls camera_module_t->common.open(), which returns a
112 * hardware_device_t structure.
113 *
114 * 2. Framework inspects the hardware_device_t->version field, and instantiates
115 * the appropriate handler for that version of the camera hardware device. In
116 * case the version is CAMERA_DEVICE_API_VERSION_3_0, the device is cast to
117 * a camera3_device_t.
118 *
119 * 3. Framework calls camera3_device_t->ops->initialize() with the framework
120 * callback function pointers. This will only be called this one time after
121 * open(), before any other functions in the ops structure are called.
122 *
123 * 4. The framework calls camera3_device_t->ops->configure_streams() with a list
124 * of input/output streams to the HAL device.
125 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800126 * 5. <= CAMERA_DEVICE_API_VERSION_3_1:
127 *
128 * The framework allocates gralloc buffers and calls
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800129 * camera3_device_t->ops->register_stream_buffers() for at least one of the
130 * output streams listed in configure_streams. The same stream is registered
131 * only once.
132 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800133 * >= CAMERA_DEVICE_API_VERSION_3_2:
134 *
135 * camera3_device_t->ops->register_stream_buffers() is not called and must
136 * be NULL.
137 *
138 * 6. The framework requests default settings for some number of use cases with
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800139 * calls to camera3_device_t->ops->construct_default_request_settings(). This
140 * may occur any time after step 3.
141 *
142 * 7. The framework constructs and sends the first capture request to the HAL,
143 * with settings based on one of the sets of default settings, and with at
144 * least one output stream, which has been registered earlier by the
145 * framework. This is sent to the HAL with
146 * camera3_device_t->ops->process_capture_request(). The HAL must block the
147 * return of this call until it is ready for the next request to be sent.
148 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800149 * >= CAMERA_DEVICE_API_VERSION_3_2:
150 *
151 * The buffer_handle_t provided in the camera3_stream_buffer_t array
152 * in the camera3_capture_request_t may be new and never-before-seen
153 * by the HAL on any given new request.
154 *
155 * 8. The framework continues to submit requests, and call
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800156 * construct_default_request_settings to get default settings buffers for
157 * other use cases.
158 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800159 * <= CAMERA_DEVICE_API_VERSION_3_1:
160 *
161 * The framework may call register_stream_buffers() at this time for
162 * not-yet-registered streams.
163 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800164 * 9. When the capture of a request begins (sensor starts exposing for the
165 * capture), the HAL calls camera3_callback_ops_t->notify() with the SHUTTER
166 * event, including the frame number and the timestamp for start of exposure.
Eino-Ville Talvala71af1022013-04-22 14:19:21 -0700167 * This notify call must be made before the first call to
168 * process_capture_result() for that frame number.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800169 *
170 * 10. After some pipeline delay, the HAL begins to return completed captures to
171 * the framework with camera3_callback_ops_t->process_capture_result(). These
172 * are returned in the same order as the requests were submitted. Multiple
173 * requests can be in flight at once, depending on the pipeline depth of the
174 * camera HAL device.
175 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800176 * >= CAMERA_DEVICE_API_VERSION_3_2:
177 *
178 * Once a buffer is returned by process_capture_result as part of the
179 * camera3_stream_buffer_t array, and the fence specified by release_fence
180 * has been signaled (this is a no-op for -1 fences), the ownership of that
181 * buffer is considered to be transferred back to the framework. After that,
182 * the HAL must no longer retain that particular buffer, and the
183 * framework may clean up the memory for it immediately.
184 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800185 * 11. After some time, the framework may stop submitting new requests, wait for
186 * the existing captures to complete (all buffers filled, all results
187 * returned), and then call configure_streams() again. This resets the camera
188 * hardware and pipeline for a new set of input/output streams. Some streams
189 * may be reused from the previous configuration; if these streams' buffers
190 * had already been registered with the HAL, they will not be registered
191 * again. The framework then continues from step 7, if at least one
192 * registered output stream remains (otherwise, step 5 is required first).
193 *
194 * 12. Alternatively, the framework may call camera3_device_t->common->close()
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -0800195 * to end the camera session. This may be called at any time when no other
196 * calls from the framework are active, although the call may block until all
197 * in-flight captures have completed (all results returned, all buffers
198 * filled). After the close call returns, no more calls to the
199 * camera3_callback_ops_t functions are allowed from the HAL. Once the
200 * close() call is underway, the framework may not call any other HAL device
201 * functions.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800202 *
203 * 13. In case of an error or other asynchronous event, the HAL must call
204 * camera3_callback_ops_t->notify() with the appropriate error/event
205 * message. After returning from a fatal device-wide error notification, the
206 * HAL should act as if close() had been called on it. However, the HAL must
207 * either cancel or complete all outstanding captures before calling
208 * notify(), so that once notify() is called with a fatal error, the
209 * framework will not receive further callbacks from the device. Methods
210 * besides close() should return -ENODEV or NULL after the notify() method
211 * returns from a fatal error message.
212 */
213
214/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700215 * S3. Operational modes:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800216 *
217 * The camera 3 HAL device can implement one of two possible operational modes;
218 * limited and full. Full support is expected from new higher-end
219 * devices. Limited mode has hardware requirements roughly in line with those
220 * for a camera HAL device v1 implementation, and is expected from older or
221 * inexpensive devices. Full is a strict superset of limited, and they share the
222 * same essential operational flow, as documented above.
223 *
224 * The HAL must indicate its level of support with the
225 * android.info.supportedHardwareLevel static metadata entry, with 0 indicating
226 * limited mode, and 1 indicating full mode support.
227 *
228 * Roughly speaking, limited-mode devices do not allow for application control
229 * of capture settings (3A control only), high-rate capture of high-resolution
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700230 * images, raw sensor readout, or support for YUV output streams above maximum
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800231 * recording resolution (JPEG only for large images).
232 *
233 * ** Details of limited mode behavior:
234 *
235 * - Limited-mode devices do not need to implement accurate synchronization
236 * between capture request settings and the actual image data
237 * captured. Instead, changes to settings may take effect some time in the
238 * future, and possibly not for the same output frame for each settings
239 * entry. Rapid changes in settings may result in some settings never being
240 * used for a capture. However, captures that include high-resolution output
241 * buffers ( > 1080p ) have to use the settings as specified (but see below
242 * for processing rate).
243 *
244 * - Limited-mode devices do not need to support most of the
245 * settings/result/static info metadata. Full-mode devices must support all
246 * metadata fields listed in TODO. Specifically, only the following settings
247 * are expected to be consumed or produced by a limited-mode HAL device:
248 *
249 * android.control.aeAntibandingMode (controls)
250 * android.control.aeExposureCompensation (controls)
251 * android.control.aeLock (controls)
252 * android.control.aeMode (controls)
253 * [OFF means ON_FLASH_TORCH - TODO]
254 * android.control.aeRegions (controls)
255 * android.control.aeTargetFpsRange (controls)
256 * android.control.afMode (controls)
257 * [OFF means infinity focus]
258 * android.control.afRegions (controls)
259 * android.control.awbLock (controls)
260 * android.control.awbMode (controls)
261 * [OFF not supported]
262 * android.control.awbRegions (controls)
263 * android.control.captureIntent (controls)
264 * android.control.effectMode (controls)
265 * android.control.mode (controls)
266 * [OFF not supported]
267 * android.control.sceneMode (controls)
268 * android.control.videoStabilizationMode (controls)
269 * android.control.aeAvailableAntibandingModes (static)
270 * android.control.aeAvailableModes (static)
271 * android.control.aeAvailableTargetFpsRanges (static)
272 * android.control.aeCompensationRange (static)
273 * android.control.aeCompensationStep (static)
274 * android.control.afAvailableModes (static)
275 * android.control.availableEffects (static)
276 * android.control.availableSceneModes (static)
277 * android.control.availableVideoStabilizationModes (static)
278 * android.control.awbAvailableModes (static)
279 * android.control.maxRegions (static)
280 * android.control.sceneModeOverrides (static)
281 * android.control.aeRegions (dynamic)
282 * android.control.aeState (dynamic)
283 * android.control.afMode (dynamic)
284 * android.control.afRegions (dynamic)
285 * android.control.afState (dynamic)
286 * android.control.awbMode (dynamic)
287 * android.control.awbRegions (dynamic)
288 * android.control.awbState (dynamic)
289 * android.control.mode (dynamic)
290 *
291 * android.flash.info.available (static)
292 *
293 * android.info.supportedHardwareLevel (static)
294 *
295 * android.jpeg.gpsCoordinates (controls)
296 * android.jpeg.gpsProcessingMethod (controls)
297 * android.jpeg.gpsTimestamp (controls)
298 * android.jpeg.orientation (controls)
299 * android.jpeg.quality (controls)
300 * android.jpeg.thumbnailQuality (controls)
301 * android.jpeg.thumbnailSize (controls)
302 * android.jpeg.availableThumbnailSizes (static)
303 * android.jpeg.maxSize (static)
304 * android.jpeg.gpsCoordinates (dynamic)
305 * android.jpeg.gpsProcessingMethod (dynamic)
306 * android.jpeg.gpsTimestamp (dynamic)
307 * android.jpeg.orientation (dynamic)
308 * android.jpeg.quality (dynamic)
309 * android.jpeg.size (dynamic)
310 * android.jpeg.thumbnailQuality (dynamic)
311 * android.jpeg.thumbnailSize (dynamic)
312 *
313 * android.lens.info.minimumFocusDistance (static)
314 *
315 * android.request.id (controls)
316 * android.request.id (dynamic)
317 *
318 * android.scaler.cropRegion (controls)
319 * [ignores (x,y), assumes center-zoom]
320 * android.scaler.availableFormats (static)
321 * [RAW not supported]
322 * android.scaler.availableJpegMinDurations (static)
323 * android.scaler.availableJpegSizes (static)
324 * android.scaler.availableMaxDigitalZoom (static)
325 * android.scaler.availableProcessedMinDurations (static)
326 * android.scaler.availableProcessedSizes (static)
327 * [full resolution not supported]
328 * android.scaler.maxDigitalZoom (static)
329 * android.scaler.cropRegion (dynamic)
330 *
331 * android.sensor.orientation (static)
332 * android.sensor.timestamp (dynamic)
333 *
334 * android.statistics.faceDetectMode (controls)
335 * android.statistics.info.availableFaceDetectModes (static)
336 * android.statistics.faceDetectMode (dynamic)
337 * android.statistics.faceIds (dynamic)
338 * android.statistics.faceLandmarks (dynamic)
339 * android.statistics.faceRectangles (dynamic)
340 * android.statistics.faceScores (dynamic)
341 *
342 * - Captures in limited mode that include high-resolution (> 1080p) output
343 * buffers may block in process_capture_request() until all the output buffers
344 * have been filled. A full-mode HAL device must process sequences of
345 * high-resolution requests at the rate indicated in the static metadata for
346 * that pixel format. The HAL must still call process_capture_result() to
347 * provide the output; the framework must simply be prepared for
348 * process_capture_request() to block until after process_capture_result() for
349 * that request completes for high-resolution captures for limited-mode
350 * devices.
351 *
352 */
353
354/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700355 * S4. 3A modes and state machines:
356 *
357 * While the actual 3A algorithms are up to the HAL implementation, a high-level
358 * state machine description is defined by the HAL interface, to allow the HAL
359 * device and the framework to communicate about the current state of 3A, and to
360 * trigger 3A events.
361 *
362 * When the device is opened, all the individual 3A states must be
363 * STATE_INACTIVE. Stream configuration does not reset 3A. For example, locked
364 * focus must be maintained across the configure() call.
365 *
366 * Triggering a 3A action involves simply setting the relevant trigger entry in
367 * the settings for the next request to indicate start of trigger. For example,
368 * the trigger for starting an autofocus scan is setting the entry
369 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTROL_AF_TRIGGER_START for one
370 * request, and cancelling an autofocus scan is triggered by setting
371 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTRL_AF_TRIGGER_CANCEL. Otherwise,
372 * the entry will not exist, or be set to ANDROID_CONTROL_AF_TRIGGER_IDLE. Each
373 * request with a trigger entry set to a non-IDLE value will be treated as an
374 * independent triggering event.
375 *
376 * At the top level, 3A is controlled by the ANDROID_CONTROL_MODE setting, which
377 * selects between no 3A (ANDROID_CONTROL_MODE_OFF), normal AUTO mode
378 * (ANDROID_CONTROL_MODE_AUTO), and using the scene mode setting
379 * (ANDROID_CONTROL_USE_SCENE_MODE).
380 *
381 * - In OFF mode, each of the individual AE/AF/AWB modes are effectively OFF,
382 * and none of the capture controls may be overridden by the 3A routines.
383 *
384 * - In AUTO mode, Auto-focus, auto-exposure, and auto-whitebalance all run
385 * their own independent algorithms, and have their own mode, state, and
386 * trigger metadata entries, as listed in the next section.
387 *
388 * - In USE_SCENE_MODE, the value of the ANDROID_CONTROL_SCENE_MODE entry must
389 * be used to determine the behavior of 3A routines. In SCENE_MODEs other than
390 * FACE_PRIORITY, the HAL must override the values of
391 * ANDROId_CONTROL_AE/AWB/AF_MODE to be the mode it prefers for the selected
392 * SCENE_MODE. For example, the HAL may prefer SCENE_MODE_NIGHT to use
393 * CONTINUOUS_FOCUS AF mode. Any user selection of AE/AWB/AF_MODE when scene
394 * must be ignored for these scene modes.
395 *
396 * - For SCENE_MODE_FACE_PRIORITY, the AE/AWB/AF_MODE controls work as in
397 * ANDROID_CONTROL_MODE_AUTO, but the 3A routines must bias toward metering
398 * and focusing on any detected faces in the scene.
399 *
400 * S4.1. Auto-focus settings and result entries:
401 *
402 * Main metadata entries:
403 *
404 * ANDROID_CONTROL_AF_MODE: Control for selecting the current autofocus
405 * mode. Set by the framework in the request settings.
406 *
407 * AF_MODE_OFF: AF is disabled; the framework/app directly controls lens
408 * position.
409 *
410 * AF_MODE_AUTO: Single-sweep autofocus. No lens movement unless AF is
411 * triggered.
412 *
413 * AF_MODE_MACRO: Single-sweep up-close autofocus. No lens movement unless
414 * AF is triggered.
415 *
416 * AF_MODE_CONTINUOUS_VIDEO: Smooth continuous focusing, for recording
417 * video. Triggering immediately locks focus in current
418 * position. Canceling resumes cotinuous focusing.
419 *
420 * AF_MODE_CONTINUOUS_PICTURE: Fast continuous focusing, for
421 * zero-shutter-lag still capture. Triggering locks focus once currently
422 * active sweep concludes. Canceling resumes continuous focusing.
423 *
424 * AF_MODE_EDOF: Advanced extended depth of field focusing. There is no
425 * autofocus scan, so triggering one or canceling one has no effect.
426 * Images are focused automatically by the HAL.
427 *
428 * ANDROID_CONTROL_AF_STATE: Dynamic metadata describing the current AF
429 * algorithm state, reported by the HAL in the result metadata.
430 *
431 * AF_STATE_INACTIVE: No focusing has been done, or algorithm was
432 * reset. Lens is not moving. Always the state for MODE_OFF or MODE_EDOF.
433 * When the device is opened, it must start in this state.
434 *
435 * AF_STATE_PASSIVE_SCAN: A continuous focus algorithm is currently scanning
436 * for good focus. The lens is moving.
437 *
438 * AF_STATE_PASSIVE_FOCUSED: A continuous focus algorithm believes it is
439 * well focused. The lens is not moving. The HAL may spontaneously leave
440 * this state.
441 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700442 * AF_STATE_PASSIVE_UNFOCUSED: A continuous focus algorithm believes it is
443 * not well focused. The lens is not moving. The HAL may spontaneously
444 * leave this state.
445 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700446 * AF_STATE_ACTIVE_SCAN: A scan triggered by the user is underway.
447 *
448 * AF_STATE_FOCUSED_LOCKED: The AF algorithm believes it is focused. The
449 * lens is not moving.
450 *
451 * AF_STATE_NOT_FOCUSED_LOCKED: The AF algorithm has been unable to
452 * focus. The lens is not moving.
453 *
454 * ANDROID_CONTROL_AF_TRIGGER: Control for starting an autofocus scan, the
455 * meaning of which is mode- and state- dependent. Set by the framework in
456 * the request settings.
457 *
458 * AF_TRIGGER_IDLE: No current trigger.
459 *
460 * AF_TRIGGER_START: Trigger start of AF scan. Effect is mode and state
461 * dependent.
462 *
463 * AF_TRIGGER_CANCEL: Cancel current AF scan if any, and reset algorithm to
464 * default.
465 *
466 * Additional metadata entries:
467 *
468 * ANDROID_CONTROL_AF_REGIONS: Control for selecting the regions of the FOV
469 * that should be used to determine good focus. This applies to all AF
470 * modes that scan for focus. Set by the framework in the request
471 * settings.
472 *
473 * S4.2. Auto-exposure settings and result entries:
474 *
475 * Main metadata entries:
476 *
477 * ANDROID_CONTROL_AE_MODE: Control for selecting the current auto-exposure
478 * mode. Set by the framework in the request settings.
479 *
480 * AE_MODE_OFF: Autoexposure is disabled; the user controls exposure, gain,
481 * frame duration, and flash.
482 *
483 * AE_MODE_ON: Standard autoexposure, with flash control disabled. User may
484 * set flash to fire or to torch mode.
485 *
486 * AE_MODE_ON_AUTO_FLASH: Standard autoexposure, with flash on at HAL's
487 * discretion for precapture and still capture. User control of flash
488 * disabled.
489 *
490 * AE_MODE_ON_ALWAYS_FLASH: Standard autoexposure, with flash always fired
491 * for capture, and at HAL's discretion for precapture.. User control of
492 * flash disabled.
493 *
494 * AE_MODE_ON_AUTO_FLASH_REDEYE: Standard autoexposure, with flash on at
495 * HAL's discretion for precapture and still capture. Use a flash burst
496 * at end of precapture sequence to reduce redeye in the final
497 * picture. User control of flash disabled.
498 *
499 * ANDROID_CONTROL_AE_STATE: Dynamic metadata describing the current AE
500 * algorithm state, reported by the HAL in the result metadata.
501 *
502 * AE_STATE_INACTIVE: Initial AE state after mode switch. When the device is
503 * opened, it must start in this state.
504 *
505 * AE_STATE_SEARCHING: AE is not converged to a good value, and is adjusting
506 * exposure parameters.
507 *
508 * AE_STATE_CONVERGED: AE has found good exposure values for the current
509 * scene, and the exposure parameters are not changing. HAL may
510 * spontaneously leave this state to search for better solution.
511 *
512 * AE_STATE_LOCKED: AE has been locked with the AE_LOCK control. Exposure
513 * values are not changing.
514 *
515 * AE_STATE_FLASH_REQUIRED: The HAL has converged exposure, but believes
516 * flash is required for a sufficiently bright picture. Used for
517 * determining if a zero-shutter-lag frame can be used.
518 *
519 * AE_STATE_PRECAPTURE: The HAL is in the middle of a precapture
520 * sequence. Depending on AE mode, this mode may involve firing the
521 * flash for metering, or a burst of flash pulses for redeye reduction.
522 *
523 * ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER: Control for starting a metering
524 * sequence before capturing a high-quality image. Set by the framework in
525 * the request settings.
526 *
527 * PRECAPTURE_TRIGGER_IDLE: No current trigger.
528 *
529 * PRECAPTURE_TRIGGER_START: Start a precapture sequence. The HAL should
530 * use the subsequent requests to measure good exposure/white balance
531 * for an upcoming high-resolution capture.
532 *
533 * Additional metadata entries:
534 *
535 * ANDROID_CONTROL_AE_LOCK: Control for locking AE controls to their current
536 * values
537 *
538 * ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION: Control for adjusting AE
539 * algorithm target brightness point.
540 *
541 * ANDROID_CONTROL_AE_TARGET_FPS_RANGE: Control for selecting the target frame
542 * rate range for the AE algorithm. The AE routine cannot change the frame
543 * rate to be outside these bounds.
544 *
545 * ANDROID_CONTROL_AE_REGIONS: Control for selecting the regions of the FOV
546 * that should be used to determine good exposure levels. This applies to
547 * all AE modes besides OFF.
548 *
549 * S4.3. Auto-whitebalance settings and result entries:
550 *
551 * Main metadata entries:
552 *
553 * ANDROID_CONTROL_AWB_MODE: Control for selecting the current white-balance
554 * mode.
555 *
556 * AWB_MODE_OFF: Auto-whitebalance is disabled. User controls color matrix.
557 *
558 * AWB_MODE_AUTO: Automatic white balance is enabled; 3A controls color
559 * transform, possibly using more complex transforms than a simple
560 * matrix.
561 *
562 * AWB_MODE_INCANDESCENT: Fixed white balance settings good for indoor
563 * incandescent (tungsten) lighting, roughly 2700K.
564 *
565 * AWB_MODE_FLUORESCENT: Fixed white balance settings good for fluorescent
566 * lighting, roughly 5000K.
567 *
568 * AWB_MODE_WARM_FLUORESCENT: Fixed white balance settings good for
569 * fluorescent lighting, roughly 3000K.
570 *
571 * AWB_MODE_DAYLIGHT: Fixed white balance settings good for daylight,
572 * roughly 5500K.
573 *
574 * AWB_MODE_CLOUDY_DAYLIGHT: Fixed white balance settings good for clouded
575 * daylight, roughly 6500K.
576 *
577 * AWB_MODE_TWILIGHT: Fixed white balance settings good for
578 * near-sunset/sunrise, roughly 15000K.
579 *
580 * AWB_MODE_SHADE: Fixed white balance settings good for areas indirectly
581 * lit by the sun, roughly 7500K.
582 *
583 * ANDROID_CONTROL_AWB_STATE: Dynamic metadata describing the current AWB
584 * algorithm state, reported by the HAL in the result metadata.
585 *
586 * AWB_STATE_INACTIVE: Initial AWB state after mode switch. When the device
587 * is opened, it must start in this state.
588 *
589 * AWB_STATE_SEARCHING: AWB is not converged to a good value, and is
590 * changing color adjustment parameters.
591 *
592 * AWB_STATE_CONVERGED: AWB has found good color adjustment values for the
593 * current scene, and the parameters are not changing. HAL may
594 * spontaneously leave this state to search for better solution.
595 *
596 * AWB_STATE_LOCKED: AWB has been locked with the AWB_LOCK control. Color
597 * adjustment values are not changing.
598 *
599 * Additional metadata entries:
600 *
601 * ANDROID_CONTROL_AWB_LOCK: Control for locking AWB color adjustments to
602 * their current values.
603 *
604 * ANDROID_CONTROL_AWB_REGIONS: Control for selecting the regions of the FOV
605 * that should be used to determine good color balance. This applies only
606 * to auto-WB mode.
607 *
608 * S4.4. General state machine transition notes
609 *
610 * Switching between AF, AE, or AWB modes always resets the algorithm's state
611 * to INACTIVE. Similarly, switching between CONTROL_MODE or
612 * CONTROL_SCENE_MODE if CONTROL_MODE == USE_SCENE_MODE resets all the
613 * algorithm states to INACTIVE.
614 *
615 * The tables below are per-mode.
616 *
617 * S4.5. AF state machines
618 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700619 * when enabling AF or changing AF mode
620 *| state | trans. cause | new state | notes |
621 *+--------------------+---------------+--------------------+------------------+
622 *| Any | AF mode change| INACTIVE | |
623 *+--------------------+---------------+--------------------+------------------+
624 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700625 * mode = AF_MODE_OFF or AF_MODE_EDOF
626 *| state | trans. cause | new state | notes |
627 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700628 *| INACTIVE | | INACTIVE | Never changes |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700629 *+--------------------+---------------+--------------------+------------------+
630 *
631 * mode = AF_MODE_AUTO or AF_MODE_MACRO
632 *| state | trans. cause | new state | notes |
633 *+--------------------+---------------+--------------------+------------------+
634 *| INACTIVE | AF_TRIGGER | ACTIVE_SCAN | Start AF sweep |
635 *| | | | Lens now moving |
636 *+--------------------+---------------+--------------------+------------------+
637 *| ACTIVE_SCAN | AF sweep done | FOCUSED_LOCKED | If AF successful |
638 *| | | | Lens now locked |
639 *+--------------------+---------------+--------------------+------------------+
640 *| ACTIVE_SCAN | AF sweep done | NOT_FOCUSED_LOCKED | If AF successful |
641 *| | | | Lens now locked |
642 *+--------------------+---------------+--------------------+------------------+
643 *| ACTIVE_SCAN | AF_CANCEL | INACTIVE | Cancel/reset AF |
644 *| | | | Lens now locked |
645 *+--------------------+---------------+--------------------+------------------+
646 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
647 *+--------------------+---------------+--------------------+------------------+
648 *| FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
649 *| | | | Lens now moving |
650 *+--------------------+---------------+--------------------+------------------+
651 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
652 *+--------------------+---------------+--------------------+------------------+
653 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
654 *| | | | Lens now moving |
655 *+--------------------+---------------+--------------------+------------------+
656 *| All states | mode change | INACTIVE | |
657 *+--------------------+---------------+--------------------+------------------+
658 *
659 * mode = AF_MODE_CONTINUOUS_VIDEO
660 *| state | trans. cause | new state | notes |
661 *+--------------------+---------------+--------------------+------------------+
662 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
663 *| | new scan | | Lens now moving |
664 *+--------------------+---------------+--------------------+------------------+
665 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
666 *| | | | Lens now locked |
667 *+--------------------+---------------+--------------------+------------------+
668 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
669 *| | current scan | | Lens now locked |
670 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700671 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
672 *| | current scan | | Lens now locked |
673 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700674 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
675 *| | | | if focus is good |
676 *| | | | Lens now locked |
677 *+--------------------+---------------+--------------------+------------------+
678 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
679 *| | | | if focus is bad |
680 *| | | | Lens now locked |
681 *+--------------------+---------------+--------------------+------------------+
682 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
683 *| | | | position |
684 *| | | | Lens now locked |
685 *+--------------------+---------------+--------------------+------------------+
686 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
687 *| | new scan | | Lens now moving |
688 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700689 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
690 *| | new scan | | Lens now moving |
691 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700692 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700693 *| | | | Lens now locked |
694 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700695 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700696 *| | | | Lens now locked |
697 *+--------------------+---------------+--------------------+------------------+
698 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
699 *+--------------------+---------------+--------------------+------------------+
700 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
701 *+--------------------+---------------+--------------------+------------------+
702 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
703 *+--------------------+---------------+--------------------+------------------+
704 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
705 *+--------------------+---------------+--------------------+------------------+
706 *
707 * mode = AF_MODE_CONTINUOUS_PICTURE
708 *| state | trans. cause | new state | notes |
709 *+--------------------+---------------+--------------------+------------------+
710 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
711 *| | new scan | | Lens now moving |
712 *+--------------------+---------------+--------------------+------------------+
713 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
714 *| | | | Lens now locked |
715 *+--------------------+---------------+--------------------+------------------+
716 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
717 *| | current scan | | Lens now locked |
718 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700719 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
720 *| | current scan | | Lens now locked |
721 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700722 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Eventual trans. |
723 *| | | | once focus good |
724 *| | | | Lens now locked |
725 *+--------------------+---------------+--------------------+------------------+
726 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Eventual trans. |
727 *| | | | if cannot focus |
728 *| | | | Lens now locked |
729 *+--------------------+---------------+--------------------+------------------+
730 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
731 *| | | | position |
732 *| | | | Lens now locked |
733 *+--------------------+---------------+--------------------+------------------+
734 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
735 *| | new scan | | Lens now moving |
736 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700737 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
738 *| | new scan | | Lens now moving |
739 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700740 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700741 *| | | | Lens now locked |
742 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700743 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700744 *| | | | Lens now locked |
745 *+--------------------+---------------+--------------------+------------------+
746 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
747 *+--------------------+---------------+--------------------+------------------+
748 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
749 *+--------------------+---------------+--------------------+------------------+
750 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
751 *+--------------------+---------------+--------------------+------------------+
752 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
753 *+--------------------+---------------+--------------------+------------------+
754 *
755 * S4.6. AE and AWB state machines
756 *
757 * The AE and AWB state machines are mostly identical. AE has additional
758 * FLASH_REQUIRED and PRECAPTURE states. So rows below that refer to those two
759 * states should be ignored for the AWB state machine.
760 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700761 * when enabling AE/AWB or changing AE/AWB mode
762 *| state | trans. cause | new state | notes |
763 *+--------------------+---------------+--------------------+------------------+
764 *| Any | mode change | INACTIVE | |
765 *+--------------------+---------------+--------------------+------------------+
766 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700767 * mode = AE_MODE_OFF / AWB mode not AUTO
768 *| state | trans. cause | new state | notes |
769 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700770 *| INACTIVE | | INACTIVE | AE/AWB disabled |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700771 *+--------------------+---------------+--------------------+------------------+
772 *
773 * mode = AE_MODE_ON_* / AWB_MODE_AUTO
774 *| state | trans. cause | new state | notes |
775 *+--------------------+---------------+--------------------+------------------+
776 *| INACTIVE | HAL initiates | SEARCHING | |
777 *| | AE/AWB scan | | |
778 *+--------------------+---------------+--------------------+------------------+
779 *| INACTIVE | AE/AWB_LOCK | LOCKED | values locked |
780 *| | on | | |
781 *+--------------------+---------------+--------------------+------------------+
782 *| SEARCHING | HAL finishes | CONVERGED | good values, not |
783 *| | AE/AWB scan | | changing |
784 *+--------------------+---------------+--------------------+------------------+
785 *| SEARCHING | HAL finishes | FLASH_REQUIRED | converged but too|
786 *| | AE scan | | dark w/o flash |
787 *+--------------------+---------------+--------------------+------------------+
788 *| SEARCHING | AE/AWB_LOCK | LOCKED | values locked |
789 *| | on | | |
790 *+--------------------+---------------+--------------------+------------------+
791 *| CONVERGED | HAL initiates | SEARCHING | values locked |
792 *| | AE/AWB scan | | |
793 *+--------------------+---------------+--------------------+------------------+
794 *| CONVERGED | AE/AWB_LOCK | LOCKED | values locked |
795 *| | on | | |
796 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala73dba5e2013-05-21 16:29:14 -0700797 *| FLASH_REQUIRED | HAL initiates | SEARCHING | values locked |
798 *| | AE/AWB scan | | |
799 *+--------------------+---------------+--------------------+------------------+
800 *| FLASH_REQUIRED | AE/AWB_LOCK | LOCKED | values locked |
801 *| | on | | |
802 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700803 *| LOCKED | AE/AWB_LOCK | SEARCHING | values not good |
804 *| | off | | after unlock |
805 *+--------------------+---------------+--------------------+------------------+
806 *| LOCKED | AE/AWB_LOCK | CONVERGED | values good |
807 *| | off | | after unlock |
808 *+--------------------+---------------+--------------------+------------------+
809 *| LOCKED | AE_LOCK | FLASH_REQUIRED | exposure good, |
810 *| | off | | but too dark |
811 *+--------------------+---------------+--------------------+------------------+
812 *| All AE states | PRECAPTURE_ | PRECAPTURE | Start precapture |
813 *| | START | | sequence |
814 *+--------------------+---------------+--------------------+------------------+
815 *| PRECAPTURE | Sequence done.| CONVERGED | Ready for high- |
816 *| | AE_LOCK off | | quality capture |
817 *+--------------------+---------------+--------------------+------------------+
818 *| PRECAPTURE | Sequence done.| LOCKED | Ready for high- |
819 *| | AE_LOCK on | | quality capture |
820 *+--------------------+---------------+--------------------+------------------+
821 *
822 */
823
824/**
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700825 * S5. Cropping:
826 *
827 * Cropping of the full pixel array (for digital zoom and other use cases where
828 * a smaller FOV is desirable) is communicated through the
829 * ANDROID_SCALER_CROP_REGION setting. This is a per-request setting, and can
830 * change on a per-request basis, which is critical for implementing smooth
831 * digital zoom.
832 *
833 * The region is defined as a rectangle (x, y, width, height), with (x, y)
834 * describing the top-left corner of the rectangle. The rectangle is defined on
835 * the coordinate system of the sensor active pixel array, with (0,0) being the
836 * top-left pixel of the active pixel array. Therefore, the width and height
837 * cannot be larger than the dimensions reported in the
838 * ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY static info field. The minimum allowed
839 * width and height are reported by the HAL through the
840 * ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes the
841 * maximum supported zoom factor. Therefore, the minimum crop region width and
842 * height are:
843 *
844 * {width, height} =
845 * { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
846 * ANDROID_SCALER_MAX_DIGITAL_ZOOM),
847 * floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
848 * ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
849 *
850 * If the crop region needs to fulfill specific requirements (for example, it
851 * needs to start on even coordinates, and its width/height needs to be even),
852 * the HAL must do the necessary rounding and write out the final crop region
853 * used in the output result metadata. Similarly, if the HAL implements video
854 * stabilization, it must adjust the result crop region to describe the region
855 * actually included in the output after video stabilization is applied. In
856 * general, a camera-using application must be able to determine the field of
857 * view it is receiving based on the crop region, the dimensions of the image
858 * sensor, and the lens focal length.
859 *
860 * Since the crop region applies to all streams, which may have different aspect
861 * ratios than the crop region, the exact sensor region used for each stream may
862 * be smaller than the crop region. Specifically, each stream should maintain
863 * square pixels and its aspect ratio by minimally further cropping the defined
864 * crop region. If the stream's aspect ratio is wider than the crop region, the
865 * stream should be further cropped vertically, and if the stream's aspect ratio
866 * is narrower than the crop region, the stream should be further cropped
867 * horizontally.
868 *
869 * In all cases, the stream crop must be centered within the full crop region,
870 * and each stream is only either cropped horizontally or vertical relative to
871 * the full crop region, never both.
872 *
873 * For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
874 * 1280x720 stream (16:9 aspect), below demonstrates the expected output regions
875 * for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
876 * 1500 pixel array) sensor.
877 *
878 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
879 *
880 * 640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)
881 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
882 *
883 * 0 1000 2000
884 * +---------+---------+---------+----------+
885 * | Active pixel array |
886 * | |
887 * | |
888 * + +-------------------+ + 375
889 * | | | |
890 * | O===================O |
891 * | I 1280x720 stream I |
892 * + I I + 750
893 * | I I |
894 * | O===================O |
895 * | | | |
896 * + +-------------------+ + 1125
897 * | Crop region, 640x480 stream |
898 * | |
899 * | |
900 * +---------+---------+---------+----------+ 1500
901 *
902 * Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)
903 *
904 * 640x480 stream crop: (666, 375, 1000, 750) (marked with =)
905 * 1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
906 *
907 * 0 1000 2000
908 * +---------+---------+---------+----------+
909 * | Active pixel array |
910 * | |
911 * | |
912 * + +---O==================O---+ + 375
913 * | | I 640x480 stream I | |
914 * | | I I | |
915 * | | I I | |
916 * + | I I | + 750
917 * | | I I | |
918 * | | I I | |
919 * | | I I | |
920 * + +---O==================O---+ + 1125
921 * | Crop region, 1280x720 stream |
922 * | |
923 * | |
924 * +---------+---------+---------+----------+ 1500
925 *
926 * Crop region: (500, 375, 750, 750) (1:1 aspect ratio)
927 *
928 * 640x480 stream crop: (500, 469, 750, 562) (marked with =)
929 * 1280x720 stream crop: (500, 543, 750, 414) (marged with #)
930 *
931 * 0 1000 2000
932 * +---------+---------+---------+----------+
933 * | Active pixel array |
934 * | |
935 * | |
936 * + +--------------+ + 375
937 * | O==============O |
938 * | ################ |
939 * | # # |
940 * + # # + 750
941 * | # # |
942 * | ################ 1280x720 |
943 * | O==============O 640x480 |
944 * + +--------------+ + 1125
945 * | Crop region |
946 * | |
947 * | |
948 * +---------+---------+---------+----------+ 1500
949 *
950 * And a final example, a 1024x1024 square aspect ratio stream instead of the
951 * 480p stream:
952 *
953 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
954 *
955 * 1024x1024 stream crop: (625, 375, 750, 750) (marked with #)
956 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
957 *
958 * 0 1000 2000
959 * +---------+---------+---------+----------+
960 * | Active pixel array |
961 * | |
962 * | 1024x1024 stream |
963 * + +--###############--+ + 375
964 * | | # # | |
965 * | O===================O |
966 * | I 1280x720 stream I |
967 * + I I + 750
968 * | I I |
969 * | O===================O |
970 * | | # # | |
971 * + +--###############--+ + 1125
972 * | Crop region |
973 * | |
974 * | |
975 * +---------+---------+---------+----------+ 1500
976 *
977 */
978
979/**
980 * S6. Error management:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800981 *
982 * Camera HAL device ops functions that have a return value will all return
983 * -ENODEV / NULL in case of a serious error. This means the device cannot
984 * continue operation, and must be closed by the framework. Once this error is
Alex Rayd5ddbc92013-02-15 13:47:24 -0800985 * returned by some method, or if notify() is called with ERROR_DEVICE, only
986 * the close() method can be called successfully. All other methods will return
987 * -ENODEV / NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800988 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700989 * If a device op is called in the wrong sequence, for example if the framework
990 * calls configure_streams() is called before initialize(), the device must
991 * return -ENOSYS from the call, and do nothing.
992 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800993 * Transient errors in image capture must be reported through notify() as follows:
994 *
995 * - The failure of an entire capture to occur must be reported by the HAL by
996 * calling notify() with ERROR_REQUEST. Individual errors for the result
997 * metadata or the output buffers must not be reported in this case.
998 *
999 * - If the metadata for a capture cannot be produced, but some image buffers
1000 * were filled, the HAL must call notify() with ERROR_RESULT.
1001 *
1002 * - If an output image buffer could not be filled, but either the metadata was
1003 * produced or some other buffers were filled, the HAL must call notify() with
1004 * ERROR_BUFFER for each failed buffer.
1005 *
1006 * In each of these transient failure cases, the HAL must still call
1007 * process_capture_result, with valid output buffer_handle_t. If the result
1008 * metadata could not be produced, it should be NULL. If some buffers could not
1009 * be filled, their sync fences must be set to the error state.
1010 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001011 * Invalid input arguments result in -EINVAL from the appropriate methods. In
1012 * that case, the framework must act as if that call had never been made.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001013 *
1014 */
1015
Zhijun He2dde4682014-01-09 09:11:49 -08001016/**
Zhijun He709e5872014-01-17 15:25:21 -08001017 * S7. Key Performance Indicator (KPI) glossary:
Zhijun He2dde4682014-01-09 09:11:49 -08001018 *
Zhijun He709e5872014-01-17 15:25:21 -08001019 * This includes some critical definitions that are used by KPI metrics.
Zhijun He2dde4682014-01-09 09:11:49 -08001020 *
1021 * Pipeline Latency:
1022 * For a given capture request, the duration from the framework calling
1023 * process_capture_request to the HAL sending capture result and all buffers
1024 * back by process_capture_result call. To make the Pipeline Latency measure
1025 * independent of frame rate, it is measured by frame count.
1026 *
1027 * For example, when frame rate is 30 (fps), the frame duration (time interval
1028 * between adjacent frame capture time) is 33 (ms).
1029 * If it takes 5 frames for framework to get the result and buffers back for
1030 * a given request, then the Pipeline Latency is 5 (frames), instead of
1031 * 5 x 33 = 165 (ms).
1032 *
1033 * The Pipeline Latency is determined by android.request.pipelineDepth and
1034 * android.request.pipelineMaxDepth, see their definitions for more details.
1035 *
1036 */
1037
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001038__BEGIN_DECLS
1039
1040struct camera3_device;
1041
1042/**********************************************************************
1043 *
1044 * Camera3 stream and stream buffer definitions.
1045 *
1046 * These structs and enums define the handles and contents of the input and
1047 * output streams connecting the HAL to various framework and application buffer
1048 * consumers. Each stream is backed by a gralloc buffer queue.
1049 *
1050 */
1051
1052/**
1053 * camera3_stream_type_t:
1054 *
1055 * The type of the camera stream, which defines whether the camera HAL device is
1056 * the producer or the consumer for that stream, and how the buffers of the
1057 * stream relate to the other streams.
1058 */
1059typedef enum camera3_stream_type {
1060 /**
1061 * This stream is an output stream; the camera HAL device will be
1062 * responsible for filling buffers from this stream with newly captured or
1063 * reprocessed image data.
1064 */
1065 CAMERA3_STREAM_OUTPUT = 0,
1066
1067 /**
1068 * This stream is an input stream; the camera HAL device will be responsible
1069 * for reading buffers from this stream and sending them through the camera
1070 * processing pipeline, as if the buffer was a newly captured image from the
1071 * imager.
1072 */
1073 CAMERA3_STREAM_INPUT = 1,
1074
1075 /**
1076 * This stream can be used for input and output. Typically, the stream is
1077 * used as an output stream, but occasionally one already-filled buffer may
1078 * be sent back to the HAL device for reprocessing.
1079 *
1080 * This kind of stream is meant generally for zero-shutter-lag features,
1081 * where copying the captured image from the output buffer to the
1082 * reprocessing input buffer would be expensive. The stream will be used by
1083 * the framework as follows:
1084 *
1085 * 1. The framework includes a buffer from this stream as output buffer in a
1086 * request as normal.
1087 *
1088 * 2. Once the HAL device returns a filled output buffer to the framework,
1089 * the framework may do one of two things with the filled buffer:
1090 *
1091 * 2. a. The framework uses the filled data, and returns the now-used buffer
1092 * to the stream queue for reuse. This behavior exactly matches the
1093 * OUTPUT type of stream.
1094 *
1095 * 2. b. The framework wants to reprocess the filled data, and uses the
1096 * buffer as an input buffer for a request. Once the HAL device has
1097 * used the reprocessing buffer, it then returns it to the
1098 * framework. The framework then returns the now-used buffer to the
1099 * stream queue for reuse.
1100 *
1101 * 3. The HAL device will be given the buffer again as an output buffer for
1102 * a request at some future point.
1103 *
1104 * Note that the HAL will always be reprocessing data it produced.
1105 *
1106 */
1107 CAMERA3_STREAM_BIDIRECTIONAL = 2,
1108
1109 /**
1110 * Total number of framework-defined stream types
1111 */
1112 CAMERA3_NUM_STREAM_TYPES
1113
1114} camera3_stream_type_t;
1115
1116/**
1117 * camera3_stream_t:
1118 *
1119 * A handle to a single camera input or output stream. A stream is defined by
1120 * the framework by its buffer resolution and format, and additionally by the
1121 * HAL with the gralloc usage flags and the maximum in-flight buffer count.
1122 *
1123 * The stream structures are owned by the framework, but pointers to a
1124 * camera3_stream passed into the HAL by configure_streams() are valid until the
1125 * end of the first subsequent configure_streams() call that _does not_ include
1126 * that camera3_stream as an argument, or until the end of the close() call.
1127 *
1128 * All camera3_stream framework-controlled members are immutable once the
1129 * camera3_stream is passed into configure_streams(). The HAL may only change
1130 * the HAL-controlled parameters during a configure_streams() call, except for
1131 * the contents of the private pointer.
1132 *
1133 * If a configure_streams() call returns a non-fatal error, all active streams
1134 * remain valid as if configure_streams() had not been called.
1135 *
1136 * The endpoint of the stream is not visible to the camera HAL device.
Alex Ray2ce219a2013-06-14 15:09:30 -07001137 * In DEVICE_API_VERSION_3_1, this was changed to share consumer usage flags
1138 * on streams where the camera is a producer (OUTPUT and BIDIRECTIONAL stream
1139 * types) see the usage field below.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001140 */
1141typedef struct camera3_stream {
1142
1143 /*****
1144 * Set by framework before configure_streams()
1145 */
1146
1147 /**
1148 * The type of the stream, one of the camera3_stream_type_t values.
1149 */
1150 int stream_type;
1151
1152 /**
1153 * The width in pixels of the buffers in this stream
1154 */
1155 uint32_t width;
1156
1157 /**
1158 * The height in pixels of the buffers in this stream
1159 */
1160 uint32_t height;
1161
1162 /**
1163 * The pixel format for the buffers in this stream. Format is a value from
1164 * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
1165 * from device-specific headers.
1166 *
1167 * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
1168 * gralloc module will select a format based on the usage flags provided by
1169 * the camera device and the other endpoint of the stream.
1170 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001171 * <= CAMERA_DEVICE_API_VERSION_3_1:
1172 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001173 * The camera HAL device must inspect the buffers handed to it in the
1174 * subsequent register_stream_buffers() call to obtain the
1175 * implementation-specific format details, if necessary.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001176 *
1177 * >= CAMERA_DEVICE_API_VERSION_3_2:
1178 *
1179 * register_stream_buffers() won't be called by the framework, so the HAL
1180 * should configure the ISP and sensor pipeline based purely on the sizes,
1181 * usage flags, and formats for the configured streams.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001182 */
1183 int format;
1184
1185 /*****
1186 * Set by HAL during configure_streams().
1187 */
1188
1189 /**
1190 * The gralloc usage flags for this stream, as needed by the HAL. The usage
1191 * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
1192 * headers.
1193 *
1194 * For output streams, these are the HAL's producer usage flags. For input
1195 * streams, these are the HAL's consumer usage flags. The usage flags from
1196 * the producer and the consumer will be combined together and then passed
1197 * to the platform gralloc HAL module for allocating the gralloc buffers for
1198 * each stream.
Alex Ray2ce219a2013-06-14 15:09:30 -07001199 *
1200 * Version information:
1201 *
1202 * == CAMERA_DEVICE_API_VERSION_3_0:
1203 *
1204 * No initial value guaranteed when passed via configure_streams().
1205 * HAL may not use this field as input, and must write over this field
1206 * with its usage flags.
1207 *
1208 * >= CAMERA_DEVICE_API_VERSION_3_1:
1209 *
1210 * For stream_type OUTPUT and BIDIRECTIONAL, when passed via
1211 * configure_streams(), the initial value of this is the consumer's
1212 * usage flags. The HAL may use these consumer flags to decide stream
1213 * configuration.
1214 * For stream_type INPUT, when passed via configure_streams(), the initial
1215 * value of this is 0.
1216 * For all streams passed via configure_streams(), the HAL must write
1217 * over this field with its usage flags.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001218 */
1219 uint32_t usage;
1220
1221 /**
1222 * The maximum number of buffers the HAL device may need to have dequeued at
1223 * the same time. The HAL device may not have more buffers in-flight from
1224 * this stream than this value.
1225 */
1226 uint32_t max_buffers;
1227
1228 /**
1229 * A handle to HAL-private information for the stream. Will not be inspected
1230 * by the framework code.
1231 */
1232 void *priv;
1233
1234} camera3_stream_t;
1235
1236/**
1237 * camera3_stream_configuration_t:
1238 *
1239 * A structure of stream definitions, used by configure_streams(). This
1240 * structure defines all the output streams and the reprocessing input
1241 * stream for the current camera use case.
1242 */
1243typedef struct camera3_stream_configuration {
1244 /**
1245 * The total number of streams requested by the framework. This includes
1246 * both input and output streams. The number of streams will be at least 1,
1247 * and there will be at least one output-capable stream.
1248 */
1249 uint32_t num_streams;
1250
1251 /**
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001252 * An array of camera stream pointers, defining the input/output
1253 * configuration for the camera HAL device.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001254 *
1255 * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
1256 * in a single configuration.
1257 *
1258 * At least one output-capable stream must be defined (OUTPUT or
1259 * BIDIRECTIONAL).
1260 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001261 camera3_stream_t **streams;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001262
1263} camera3_stream_configuration_t;
1264
1265/**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001266 * camera3_buffer_status_t:
1267 *
1268 * The current status of a single stream buffer.
1269 */
1270typedef enum camera3_buffer_status {
1271 /**
1272 * The buffer is in a normal state, and can be used after waiting on its
1273 * sync fence.
1274 */
1275 CAMERA3_BUFFER_STATUS_OK = 0,
1276
1277 /**
1278 * The buffer does not contain valid data, and the data in it should not be
1279 * used. The sync fence must still be waited on before reusing the buffer.
1280 */
1281 CAMERA3_BUFFER_STATUS_ERROR = 1
1282
1283} camera3_buffer_status_t;
1284
1285/**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001286 * camera3_stream_buffer_t:
1287 *
1288 * A single buffer from a camera3 stream. It includes a handle to its parent
1289 * stream, the handle to the gralloc buffer itself, and sync fences
1290 *
1291 * The buffer does not specify whether it is to be used for input or output;
1292 * that is determined by its parent stream type and how the buffer is passed to
1293 * the HAL device.
1294 */
1295typedef struct camera3_stream_buffer {
1296 /**
1297 * The handle of the stream this buffer is associated with
1298 */
1299 camera3_stream_t *stream;
1300
1301 /**
1302 * The native handle to the buffer
1303 */
1304 buffer_handle_t *buffer;
1305
1306 /**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001307 * Current state of the buffer, one of the camera3_buffer_status_t
1308 * values. The framework will not pass buffers to the HAL that are in an
1309 * error state. In case a buffer could not be filled by the HAL, it must
1310 * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
1311 * framework with process_capture_result().
1312 */
1313 int status;
1314
1315 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001316 * The acquire sync fence for this buffer. The HAL must wait on this fence
1317 * fd before attempting to read from or write to this buffer.
1318 *
1319 * The framework may be set to -1 to indicate that no waiting is necessary
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001320 * for this buffer.
1321 *
1322 * When the HAL returns an output buffer to the framework with
1323 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
1324 * never waits on the acquire_fence due to an error in filling a buffer,
1325 * when calling process_capture_result() the HAL must set the release_fence
1326 * of the buffer to be the acquire_fence passed to it by the framework. This
1327 * will allow the framework to wait on the fence before reusing the buffer.
1328 *
1329 * For input buffers, the HAL must not change the acquire_fence field during
1330 * the process_capture_request() call.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001331 */
1332 int acquire_fence;
1333
1334 /**
1335 * The release sync fence for this buffer. The HAL must set this fence when
1336 * returning buffers to the framework, or write -1 to indicate that no
1337 * waiting is required for this buffer.
1338 *
1339 * For the input buffer, the release fence must be set by the
1340 * process_capture_request() call. For the output buffers, the fences must
1341 * be set in the output_buffers array passed to process_capture_result().
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001342 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001343 * >= CAMERA_DEVICE_API_VERSION_3_2:
1344 *
1345 * After signaling the release_fence for this buffer, the HAL
1346 * should not make any further attempts to access this buffer as the
1347 * ownership has been fully transferred back to the framework.
1348 *
1349 * If a fence of -1 was specified then the ownership of this buffer
1350 * is transferred back immediately upon the call of process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001351 */
1352 int release_fence;
1353
1354} camera3_stream_buffer_t;
1355
1356/**
1357 * camera3_stream_buffer_set_t:
1358 *
1359 * The complete set of gralloc buffers for a stream. This structure is given to
1360 * register_stream_buffers() to allow the camera HAL device to register/map/etc
1361 * newly allocated stream buffers.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001362 *
1363 * >= CAMERA_DEVICE_API_VERSION_3_2:
1364 *
1365 * Deprecated (and not used). In particular,
1366 * register_stream_buffers is also deprecated and will never be invoked.
1367 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001368 */
1369typedef struct camera3_stream_buffer_set {
1370 /**
1371 * The stream handle for the stream these buffers belong to
1372 */
1373 camera3_stream_t *stream;
1374
1375 /**
1376 * The number of buffers in this stream. It is guaranteed to be at least
1377 * stream->max_buffers.
1378 */
1379 uint32_t num_buffers;
1380
1381 /**
1382 * The array of gralloc buffer handles for this stream. If the stream format
1383 * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
1384 * should inspect the passed-in buffers to determine any platform-private
1385 * pixel format information.
1386 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001387 buffer_handle_t **buffers;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001388
1389} camera3_stream_buffer_set_t;
1390
1391/**
1392 * camera3_jpeg_blob:
1393 *
1394 * Transport header for compressed JPEG buffers in output streams.
1395 *
1396 * To capture JPEG images, a stream is created using the pixel format
1397 * HAL_PIXEL_FORMAT_BLOB, and the static metadata field android.jpeg.maxSize is
1398 * used as the buffer size. Since compressed JPEG images are of variable size,
1399 * the HAL needs to include the final size of the compressed image using this
1400 * structure inside the output stream buffer. The JPEG blob ID field must be set
1401 * to CAMERA3_JPEG_BLOB_ID.
1402 *
1403 * Transport header should be at the end of the JPEG output stream buffer. That
1404 * means the jpeg_blob_id must start at byte[android.jpeg.maxSize -
1405 * sizeof(camera3_jpeg_blob)]. Any HAL using this transport header must
1406 * account for it in android.jpeg.maxSize. The JPEG data itself starts at
1407 * the beginning of the buffer and should be jpeg_size bytes long.
1408 */
1409typedef struct camera3_jpeg_blob {
1410 uint16_t jpeg_blob_id;
1411 uint32_t jpeg_size;
1412} camera3_jpeg_blob_t;
1413
1414enum {
1415 CAMERA3_JPEG_BLOB_ID = 0x00FF
1416};
1417
1418/**********************************************************************
1419 *
1420 * Message definitions for the HAL notify() callback.
1421 *
1422 * These definitions are used for the HAL notify callback, to signal
1423 * asynchronous events from the HAL device to the Android framework.
1424 *
1425 */
1426
1427/**
1428 * camera3_msg_type:
1429 *
1430 * Indicates the type of message sent, which specifies which member of the
1431 * message union is valid.
1432 *
1433 */
1434typedef enum camera3_msg_type {
1435 /**
1436 * An error has occurred. camera3_notify_msg.message.error contains the
1437 * error information.
1438 */
1439 CAMERA3_MSG_ERROR = 1,
1440
1441 /**
1442 * The exposure of a given request has
1443 * begun. camera3_notify_msg.message.shutter contains the information
1444 * the capture.
1445 */
1446 CAMERA3_MSG_SHUTTER = 2,
1447
1448 /**
1449 * Number of framework message types
1450 */
1451 CAMERA3_NUM_MESSAGES
1452
1453} camera3_msg_type_t;
1454
1455/**
1456 * Defined error codes for CAMERA_MSG_ERROR
1457 */
1458typedef enum camera3_error_msg_code {
1459 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001460 * A serious failure occured. No further frames or buffer streams will
1461 * be produced by the device. Device should be treated as closed. The
1462 * client must reopen the device to use it again. The frame_number field
1463 * is unused.
1464 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001465 CAMERA3_MSG_ERROR_DEVICE = 1,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001466
1467 /**
1468 * An error has occurred in processing a request. No output (metadata or
1469 * buffers) will be produced for this request. The frame_number field
1470 * specifies which request has been dropped. Subsequent requests are
1471 * unaffected, and the device remains operational.
1472 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001473 CAMERA3_MSG_ERROR_REQUEST = 2,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001474
1475 /**
1476 * An error has occurred in producing an output result metadata buffer
1477 * for a request, but output stream buffers for it will still be
1478 * available. Subsequent requests are unaffected, and the device remains
1479 * operational. The frame_number field specifies the request for which
1480 * result metadata won't be available.
1481 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001482 CAMERA3_MSG_ERROR_RESULT = 3,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001483
1484 /**
1485 * An error has occurred in placing an output buffer into a stream for a
1486 * request. The frame metadata and other buffers may still be
1487 * available. Subsequent requests are unaffected, and the device remains
1488 * operational. The frame_number field specifies the request for which the
1489 * buffer was dropped, and error_stream contains a pointer to the stream
1490 * that dropped the frame.u
1491 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001492 CAMERA3_MSG_ERROR_BUFFER = 4,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001493
1494 /**
1495 * Number of error types
1496 */
1497 CAMERA3_MSG_NUM_ERRORS
1498
1499} camera3_error_msg_code_t;
1500
1501/**
1502 * camera3_error_msg_t:
1503 *
1504 * Message contents for CAMERA3_MSG_ERROR
1505 */
1506typedef struct camera3_error_msg {
1507 /**
1508 * Frame number of the request the error applies to. 0 if the frame number
1509 * isn't applicable to the error.
1510 */
1511 uint32_t frame_number;
1512
1513 /**
1514 * Pointer to the stream that had a failure. NULL if the stream isn't
1515 * applicable to the error.
1516 */
1517 camera3_stream_t *error_stream;
1518
1519 /**
1520 * The code for this error; one of the CAMERA_MSG_ERROR enum values.
1521 */
1522 int error_code;
1523
1524} camera3_error_msg_t;
1525
1526/**
1527 * camera3_shutter_msg_t:
1528 *
1529 * Message contents for CAMERA3_MSG_SHUTTER
1530 */
1531typedef struct camera3_shutter_msg {
1532 /**
1533 * Frame number of the request that has begun exposure
1534 */
1535 uint32_t frame_number;
1536
1537 /**
1538 * Timestamp for the start of capture. This must match the capture result
1539 * metadata's sensor exposure start timestamp.
1540 */
1541 uint64_t timestamp;
1542
1543} camera3_shutter_msg_t;
1544
1545/**
1546 * camera3_notify_msg_t:
1547 *
1548 * The message structure sent to camera3_callback_ops_t.notify()
1549 */
1550typedef struct camera3_notify_msg {
1551
1552 /**
1553 * The message type. One of camera3_notify_msg_type, or a private extension.
1554 */
1555 int type;
1556
1557 union {
1558 /**
1559 * Error message contents. Valid if type is CAMERA3_MSG_ERROR
1560 */
1561 camera3_error_msg_t error;
1562
1563 /**
1564 * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
1565 */
1566 camera3_shutter_msg_t shutter;
1567
1568 /**
1569 * Generic message contents. Used to ensure a minimum size for custom
1570 * message types.
1571 */
1572 uint8_t generic[32];
1573 } message;
1574
1575} camera3_notify_msg_t;
1576
1577/**********************************************************************
1578 *
1579 * Capture request/result definitions for the HAL process_capture_request()
1580 * method, and the process_capture_result() callback.
1581 *
1582 */
1583
1584/**
1585 * camera3_request_template_t:
1586 *
1587 * Available template types for
1588 * camera3_device_ops.construct_default_request_settings()
1589 */
1590typedef enum camera3_request_template {
1591 /**
1592 * Standard camera preview operation with 3A on auto.
1593 */
1594 CAMERA3_TEMPLATE_PREVIEW = 1,
1595
1596 /**
1597 * Standard camera high-quality still capture with 3A and flash on auto.
1598 */
1599 CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
1600
1601 /**
1602 * Standard video recording plus preview with 3A on auto, torch off.
1603 */
1604 CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
1605
1606 /**
1607 * High-quality still capture while recording video. Application will
1608 * include preview, video record, and full-resolution YUV or JPEG streams in
1609 * request. Must not cause stuttering on video stream. 3A on auto.
1610 */
1611 CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
1612
1613 /**
1614 * Zero-shutter-lag mode. Application will request preview and
1615 * full-resolution data for each frame, and reprocess it to JPEG when a
1616 * still image is requested by user. Settings should provide highest-quality
1617 * full-resolution images without compromising preview frame rate. 3A on
1618 * auto.
1619 */
1620 CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
1621
Zhijun Heb0c939f2013-12-13 15:56:33 -08001622 /**
1623 * A basic template for direct application control of capture
1624 * parameters. All automatic control is disabled (auto-exposure, auto-white
1625 * balance, auto-focus), and post-processing parameters are set to preview
1626 * quality. The manual capture parameters (exposure, sensitivity, etc.)
1627 * are set to reasonable defaults, but should be overridden by the
1628 * application depending on the intended use case.
1629 */
1630 CAMERA3_TEMPLATE_MANUAL = 6,
1631
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001632 /* Total number of templates */
1633 CAMERA3_TEMPLATE_COUNT,
1634
1635 /**
1636 * First value for vendor-defined request templates
1637 */
1638 CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
1639
1640} camera3_request_template_t;
1641
1642/**
1643 * camera3_capture_request_t:
1644 *
1645 * A single request for image capture/buffer reprocessing, sent to the Camera
1646 * HAL device by the framework in process_capture_request().
1647 *
1648 * The request contains the settings to be used for this capture, and the set of
1649 * output buffers to write the resulting image data in. It may optionally
1650 * contain an input buffer, in which case the request is for reprocessing that
1651 * input buffer instead of capturing a new image with the camera sensor. The
1652 * capture is identified by the frame_number.
1653 *
1654 * In response, the camera HAL device must send a camera3_capture_result
1655 * structure asynchronously to the framework, using the process_capture_result()
1656 * callback.
1657 */
1658typedef struct camera3_capture_request {
1659 /**
1660 * The frame number is an incrementing integer set by the framework to
1661 * uniquely identify this capture. It needs to be returned in the result
1662 * call, and is also used to identify the request in asynchronous
1663 * notifications sent to camera3_callback_ops_t.notify().
1664 */
1665 uint32_t frame_number;
1666
1667 /**
1668 * The settings buffer contains the capture and processing parameters for
1669 * the request. As a special case, a NULL settings buffer indicates that the
1670 * settings are identical to the most-recently submitted capture request. A
1671 * NULL buffer cannot be used as the first submitted request after a
1672 * configure_streams() call.
1673 */
1674 const camera_metadata_t *settings;
1675
1676 /**
1677 * The input stream buffer to use for this request, if any.
1678 *
1679 * If input_buffer is NULL, then the request is for a new capture from the
1680 * imager. If input_buffer is valid, the request is for reprocessing the
1681 * image contained in input_buffer.
1682 *
1683 * In the latter case, the HAL must set the release_fence of the
1684 * input_buffer to a valid sync fence, or to -1 if the HAL does not support
1685 * sync, before process_capture_request() returns.
1686 *
1687 * The HAL is required to wait on the acquire sync fence of the input buffer
1688 * before accessing it.
1689 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001690 * <= CAMERA_DEVICE_API_VERSION_3_1:
1691 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001692 * Any input buffer included here will have been registered with the HAL
1693 * through register_stream_buffers() before its inclusion in a request.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001694 *
1695 * >= CAMERA_DEVICE_API_VERSION_3_2:
1696 *
1697 * The buffers will not have been pre-registered with the HAL.
1698 * Subsequent requests may reuse buffers, or provide entirely new buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001699 */
1700 camera3_stream_buffer_t *input_buffer;
1701
1702 /**
1703 * The number of output buffers for this capture request. Must be at least
1704 * 1.
1705 */
1706 uint32_t num_output_buffers;
1707
1708 /**
1709 * An array of num_output_buffers stream buffers, to be filled with image
1710 * data from this capture/reprocess. The HAL must wait on the acquire fences
Igor Murashkin78aa1262014-01-09 16:23:43 -08001711 * of each stream buffer before writing to them.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001712 *
1713 * The HAL takes ownership of the actual buffer_handle_t entries in
1714 * output_buffers; the framework does not access them until they are
1715 * returned in a camera3_capture_result_t.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001716 *
1717 * <= CAMERA_DEVICE_API_VERSION_3_1:
1718 *
1719 * All the buffers included here will have been registered with the HAL
1720 * through register_stream_buffers() before their inclusion in a request.
1721 *
1722 * >= CAMERA_DEVICE_API_VERSION_3_2:
1723 *
1724 * Any or all of the buffers included here may be brand new in this
1725 * request (having never before seen by the HAL).
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001726 */
1727 const camera3_stream_buffer_t *output_buffers;
1728
1729} camera3_capture_request_t;
1730
1731/**
1732 * camera3_capture_result_t:
1733 *
1734 * The result of a single capture/reprocess by the camera HAL device. This is
1735 * sent to the framework asynchronously with process_capture_result(), in
1736 * response to a single capture request sent to the HAL with
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001737 * process_capture_request(). Multiple process_capture_result() calls may be
1738 * performed by the HAL for each request. Each call, all with the same frame
1739 * number, may contain some subset of the output buffers, and/or the result
1740 * metadata. The metadata may only be provided once for a given frame number;
1741 * all other calls must set the result metadata to NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001742 *
1743 * The result structure contains the output metadata from this capture, and the
1744 * set of output buffers that have been/will be filled for this capture. Each
1745 * output buffer may come with a release sync fence that the framework will wait
1746 * on before reading, in case the buffer has not yet been filled by the HAL.
1747 *
1748 */
1749typedef struct camera3_capture_result {
1750 /**
1751 * The frame number is an incrementing integer set by the framework in the
1752 * submitted request to uniquely identify this capture. It is also used to
1753 * identify the request in asynchronous notifications sent to
1754 * camera3_callback_ops_t.notify().
1755 */
1756 uint32_t frame_number;
1757
1758 /**
1759 * The result metadata for this capture. This contains information about the
1760 * final capture parameters, the state of the capture and post-processing
1761 * hardware, the state of the 3A algorithms, if enabled, and the output of
1762 * any enabled statistics units.
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001763 *
1764 * Only one call to process_capture_result() with a given frame_number may
1765 * include the result metadata. All other calls for the same frame_number
1766 * must set this to NULL.
1767 *
1768 * If there was an error producing the result metadata, result must be an
1769 * empty metadata buffer, and notify() must be called with ERROR_RESULT.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001770 */
1771 const camera_metadata_t *result;
1772
1773 /**
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001774 * The number of output buffers returned in this result structure. Must be
1775 * less than or equal to the matching capture request's count. If this is
1776 * less than the buffer count in the capture request, at least one more call
1777 * to process_capture_result with the same frame_number must be made, to
1778 * return the remaining output buffers to the framework. This may only be
1779 * zero if the structure includes valid result metadata.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001780 */
1781 uint32_t num_output_buffers;
1782
1783 /**
1784 * The handles for the output stream buffers for this capture. They may not
1785 * yet be filled at the time the HAL calls process_capture_result(); the
1786 * framework will wait on the release sync fences provided by the HAL before
1787 * reading the buffers.
1788 *
1789 * The HAL must set the stream buffer's release sync fence to a valid sync
1790 * fd, or to -1 if the buffer has already been filled.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001791 *
1792 * If the HAL encounters an error while processing the buffer, and the
1793 * buffer is not filled, the buffer's status field must be set to
1794 * CAMERA3_BUFFER_STATUS_ERROR. If the HAL did not wait on the acquire fence
1795 * before encountering the error, the acquire fence should be copied into
1796 * the release fence, to allow the framework to wait on the fence before
1797 * reusing the buffer.
1798 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001799 * The acquire fence must be set to -1 for all output buffers. If
1800 * num_output_buffers is zero, this may be NULL. In that case, at least one
1801 * more process_capture_result call must be made by the HAL to provide the
1802 * output buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001803 */
1804 const camera3_stream_buffer_t *output_buffers;
1805
1806} camera3_capture_result_t;
1807
1808/**********************************************************************
1809 *
1810 * Callback methods for the HAL to call into the framework.
1811 *
1812 * These methods are used to return metadata and image buffers for a completed
1813 * or failed captures, and to notify the framework of asynchronous events such
1814 * as errors.
1815 *
1816 * The framework will not call back into the HAL from within these callbacks,
1817 * and these calls will not block for extended periods.
1818 *
1819 */
1820typedef struct camera3_callback_ops {
1821
1822 /**
1823 * process_capture_result:
1824 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001825 * Send results from a completed capture to the framework.
1826 * process_capture_result() may be invoked multiple times by the HAL in
1827 * response to a single capture request. This allows, for example, the
1828 * metadata and low-resolution buffers to be returned in one call, and
1829 * post-processed JPEG buffers in a later call, once it is available. Each
1830 * call must include the frame number of the request it is returning
1831 * metadata or buffers for.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001832 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001833 * A component (buffer or metadata) of the complete result may only be
1834 * included in one process_capture_result call. A buffer for each stream,
1835 * and the result metadata, must be returned by the HAL for each request in
1836 * one of the process_capture_result calls, even in case of errors producing
1837 * some of the output. A call to process_capture_result() with neither
1838 * output buffers or result metadata is not allowed.
1839 *
1840 * The order of returning metadata and buffers for a single result does not
1841 * matter, but buffers for a given stream must be returned in FIFO order. So
1842 * the buffer for request 5 for stream A must always be returned before the
1843 * buffer for request 6 for stream A. This also applies to the result
1844 * metadata; the metadata for request 5 must be returned before the metadata
1845 * for request 6.
1846 *
1847 * However, different streams are independent of each other, so it is
1848 * acceptable and expected that the buffer for request 5 for stream A may be
1849 * returned after the buffer for request 6 for stream B is. And it is
1850 * acceptable that the result metadata for request 6 for stream B is
1851 * returned before the buffer for request 5 for stream A is.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001852 *
1853 * The HAL retains ownership of result structure, which only needs to be
1854 * valid to access during this call. The framework will copy whatever it
1855 * needs before this call returns.
1856 *
1857 * The output buffers do not need to be filled yet; the framework will wait
1858 * on the stream buffer release sync fence before reading the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001859 * data. Therefore, this method should be called by the HAL as soon as
1860 * possible, even if some or all of the output buffers are still in
1861 * being filled. The HAL must include valid release sync fences into each
1862 * output_buffers stream buffer entry, or -1 if that stream buffer is
1863 * already filled.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001864 *
1865 * If the result buffer cannot be constructed for a request, the HAL should
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001866 * return an empty metadata buffer, but still provide the output buffers and
1867 * their sync fences. In addition, notify() must be called with an
1868 * ERROR_RESULT message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001869 *
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001870 * If an output buffer cannot be filled, its status field must be set to
1871 * STATUS_ERROR. In addition, notify() must be called with a ERROR_BUFFER
1872 * message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001873 *
1874 * If the entire capture has failed, then this method still needs to be
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001875 * called to return the output buffers to the framework. All the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001876 * statuses should be STATUS_ERROR, and the result metadata should be an
1877 * empty buffer. In addition, notify() must be called with a ERROR_REQUEST
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001878 * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
1879 * should not be sent.
1880 *
Zhijun He2dde4682014-01-09 09:11:49 -08001881 * Performance requirements:
1882 *
1883 * This is a non-blocking call. The framework will return this call in 5ms.
1884 *
1885 * The pipeline latency (see S7 for definition) should be less than or equal to
1886 * 4 frame intervals, and must be less than or equal to 8 frame intervals.
1887 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001888 */
1889 void (*process_capture_result)(const struct camera3_callback_ops *,
1890 const camera3_capture_result_t *result);
1891
1892 /**
1893 * notify:
1894 *
1895 * Asynchronous notification callback from the HAL, fired for various
1896 * reasons. Only for information independent of frame capture, or that
1897 * require specific timing. The ownership of the message structure remains
1898 * with the HAL, and the msg only needs to be valid for the duration of this
1899 * call.
1900 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07001901 * The notification for the start of exposure for a given request must be
1902 * sent by the HAL before the first call to process_capture_result() for
1903 * that request is made.
1904 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001905 * Multiple threads may call notify() simultaneously.
Zhijun He2dde4682014-01-09 09:11:49 -08001906 *
1907 * Performance requirements:
1908 *
1909 * This is a non-blocking call. The framework will return this call in 5ms.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001910 */
1911 void (*notify)(const struct camera3_callback_ops *,
1912 const camera3_notify_msg_t *msg);
1913
1914} camera3_callback_ops_t;
1915
1916/**********************************************************************
1917 *
1918 * Camera device operations
1919 *
1920 */
1921typedef struct camera3_device_ops {
1922
1923 /**
1924 * initialize:
1925 *
1926 * One-time initialization to pass framework callback function pointers to
1927 * the HAL. Will be called once after a successful open() call, before any
1928 * other functions are called on the camera3_device_ops structure.
1929 *
Zhijun He2dde4682014-01-09 09:11:49 -08001930 * Performance requirements:
1931 *
1932 * This should be a non-blocking call. The HAL should return from this call
1933 * in 5ms, and must return from this call in 10ms.
1934 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001935 * Return values:
1936 *
1937 * 0: On successful initialization
1938 *
1939 * -ENODEV: If initialization fails. Only close() can be called successfully
1940 * by the framework after this.
1941 */
1942 int (*initialize)(const struct camera3_device *,
1943 const camera3_callback_ops_t *callback_ops);
1944
1945 /**********************************************************************
1946 * Stream management
1947 */
1948
1949 /**
1950 * configure_streams:
1951 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001952 * CAMERA_DEVICE_API_VERSION_3_0 only:
1953 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001954 * Reset the HAL camera device processing pipeline and set up new input and
1955 * output streams. This call replaces any existing stream configuration with
1956 * the streams defined in the stream_list. This method will be called at
1957 * least once after initialize() before a request is submitted with
1958 * process_capture_request().
1959 *
1960 * The stream_list must contain at least one output-capable stream, and may
1961 * not contain more than one input-capable stream.
1962 *
1963 * The stream_list may contain streams that are also in the currently-active
1964 * set of streams (from the previous call to configure_stream()). These
1965 * streams will already have valid values for usage, max_buffers, and the
Igor Murashkin78aa1262014-01-09 16:23:43 -08001966 * private pointer.
1967 *
1968 * If such a stream has already had its buffers registered,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001969 * register_stream_buffers() will not be called again for the stream, and
1970 * buffers from the stream can be immediately included in input requests.
1971 *
1972 * If the HAL needs to change the stream configuration for an existing
1973 * stream due to the new configuration, it may rewrite the values of usage
Igor Murashkin78aa1262014-01-09 16:23:43 -08001974 * and/or max_buffers during the configure call.
1975 *
1976 * The framework will detect such a change, and will then reallocate the
1977 * stream buffers, and call register_stream_buffers() again before using
1978 * buffers from that stream in a request.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001979 *
1980 * If a currently-active stream is not included in stream_list, the HAL may
1981 * safely remove any references to that stream. It will not be reused in a
1982 * later configure() call by the framework, and all the gralloc buffers for
1983 * it will be freed after the configure_streams() call returns.
1984 *
1985 * The stream_list structure is owned by the framework, and may not be
1986 * accessed once this call completes. The address of an individual
1987 * camera3_stream_t structure will remain valid for access by the HAL until
1988 * the end of the first configure_stream() call which no longer includes
1989 * that camera3_stream_t in the stream_list argument. The HAL may not change
1990 * values in the stream structure outside of the private pointer, except for
1991 * the usage and max_buffers members during the configure_streams() call
1992 * itself.
1993 *
1994 * If the stream is new, the usage, max_buffer, and private pointer fields
1995 * of the stream structure will all be set to 0. The HAL device must set
1996 * these fields before the configure_streams() call returns. These fields
1997 * are then used by the framework and the platform gralloc module to
1998 * allocate the gralloc buffers for each stream.
1999 *
2000 * Before such a new stream can have its buffers included in a capture
2001 * request, the framework will call register_stream_buffers() with that
2002 * stream. However, the framework is not required to register buffers for
2003 * _all_ streams before submitting a request. This allows for quick startup
2004 * of (for example) a preview stream, with allocation for other streams
2005 * happening later or concurrently.
2006 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002007 * ------------------------------------------------------------------------
2008 * CAMERA_DEVICE_API_VERSION_3_1 only:
2009 *
2010 * Reset the HAL camera device processing pipeline and set up new input and
2011 * output streams. This call replaces any existing stream configuration with
2012 * the streams defined in the stream_list. This method will be called at
2013 * least once after initialize() before a request is submitted with
2014 * process_capture_request().
2015 *
2016 * The stream_list must contain at least one output-capable stream, and may
2017 * not contain more than one input-capable stream.
2018 *
2019 * The stream_list may contain streams that are also in the currently-active
2020 * set of streams (from the previous call to configure_stream()). These
2021 * streams will already have valid values for usage, max_buffers, and the
2022 * private pointer.
2023 *
2024 * If such a stream has already had its buffers registered,
2025 * register_stream_buffers() will not be called again for the stream, and
2026 * buffers from the stream can be immediately included in input requests.
2027 *
2028 * If the HAL needs to change the stream configuration for an existing
2029 * stream due to the new configuration, it may rewrite the values of usage
2030 * and/or max_buffers during the configure call.
2031 *
2032 * The framework will detect such a change, and will then reallocate the
2033 * stream buffers, and call register_stream_buffers() again before using
2034 * buffers from that stream in a request.
2035 *
2036 * If a currently-active stream is not included in stream_list, the HAL may
2037 * safely remove any references to that stream. It will not be reused in a
2038 * later configure() call by the framework, and all the gralloc buffers for
2039 * it will be freed after the configure_streams() call returns.
2040 *
2041 * The stream_list structure is owned by the framework, and may not be
2042 * accessed once this call completes. The address of an individual
2043 * camera3_stream_t structure will remain valid for access by the HAL until
2044 * the end of the first configure_stream() call which no longer includes
2045 * that camera3_stream_t in the stream_list argument. The HAL may not change
2046 * values in the stream structure outside of the private pointer, except for
2047 * the usage and max_buffers members during the configure_streams() call
2048 * itself.
2049 *
2050 * If the stream is new, max_buffer, and private pointer fields of the
2051 * stream structure will all be set to 0. The usage will be set to the
2052 * consumer usage flags. The HAL device must set these fields before the
2053 * configure_streams() call returns. These fields are then used by the
2054 * framework and the platform gralloc module to allocate the gralloc
2055 * buffers for each stream.
2056 *
2057 * Before such a new stream can have its buffers included in a capture
2058 * request, the framework will call register_stream_buffers() with that
2059 * stream. However, the framework is not required to register buffers for
2060 * _all_ streams before submitting a request. This allows for quick startup
2061 * of (for example) a preview stream, with allocation for other streams
2062 * happening later or concurrently.
2063 *
2064 * ------------------------------------------------------------------------
2065 * >= CAMERA_DEVICE_API_VERSION_3_2:
2066 *
2067 * Reset the HAL camera device processing pipeline and set up new input and
2068 * output streams. This call replaces any existing stream configuration with
2069 * the streams defined in the stream_list. This method will be called at
2070 * least once after initialize() before a request is submitted with
2071 * process_capture_request().
2072 *
2073 * The stream_list must contain at least one output-capable stream, and may
2074 * not contain more than one input-capable stream.
2075 *
2076 * The stream_list may contain streams that are also in the currently-active
2077 * set of streams (from the previous call to configure_stream()). These
2078 * streams will already have valid values for usage, max_buffers, and the
2079 * private pointer.
2080 *
2081 * If the HAL needs to change the stream configuration for an existing
2082 * stream due to the new configuration, it may rewrite the values of usage
2083 * and/or max_buffers during the configure call.
2084 *
2085 * The framework will detect such a change, and may then reallocate the
2086 * stream buffers before using buffers from that stream in a request.
2087 *
2088 * If a currently-active stream is not included in stream_list, the HAL may
2089 * safely remove any references to that stream. It will not be reused in a
2090 * later configure() call by the framework, and all the gralloc buffers for
2091 * it will be freed after the configure_streams() call returns.
2092 *
2093 * The stream_list structure is owned by the framework, and may not be
2094 * accessed once this call completes. The address of an individual
2095 * camera3_stream_t structure will remain valid for access by the HAL until
2096 * the end of the first configure_stream() call which no longer includes
2097 * that camera3_stream_t in the stream_list argument. The HAL may not change
2098 * values in the stream structure outside of the private pointer, except for
2099 * the usage and max_buffers members during the configure_streams() call
2100 * itself.
2101 *
2102 * If the stream is new, max_buffer, and private pointer fields of the
2103 * stream structure will all be set to 0. The usage will be set to the
2104 * consumer usage flags. The HAL device must set these fields before the
2105 * configure_streams() call returns. These fields are then used by the
2106 * framework and the platform gralloc module to allocate the gralloc
2107 * buffers for each stream.
2108 *
2109 * Newly allocated buffers may be included in a capture request at any time
2110 * by the framework. Once a gralloc buffer is returned to the framework
2111 * with process_capture_result (and its respective release_fence has been
2112 * signaled) the framework may free or reuse it at any time.
2113 *
2114 * ------------------------------------------------------------------------
2115 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002116 * Preconditions:
2117 *
2118 * The framework will only call this method when no captures are being
2119 * processed. That is, all results have been returned to the framework, and
2120 * all in-flight input and output buffers have been returned and their
2121 * release sync fences have been signaled by the HAL. The framework will not
2122 * submit new requests for capture while the configure_streams() call is
2123 * underway.
2124 *
2125 * Postconditions:
2126 *
2127 * The HAL device must configure itself to provide maximum possible output
2128 * frame rate given the sizes and formats of the output streams, as
2129 * documented in the camera device's static metadata.
2130 *
Zhijun He2dde4682014-01-09 09:11:49 -08002131 * Performance requirements:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002132 *
2133 * This call is expected to be heavyweight and possibly take several hundred
2134 * milliseconds to complete, since it may require resetting and
2135 * reconfiguring the image sensor and the camera processing pipeline.
2136 * Nevertheless, the HAL device should attempt to minimize the
2137 * reconfiguration delay to minimize the user-visible pauses during
2138 * application operational mode changes (such as switching from still
2139 * capture to video recording).
2140 *
Zhijun He2dde4682014-01-09 09:11:49 -08002141 * The HAL should return from this call in 500ms, and must return from this
2142 * call in 1000ms.
2143 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002144 * Return values:
2145 *
2146 * 0: On successful stream configuration
2147 *
2148 * -EINVAL: If the requested stream configuration is invalid. Some examples
2149 * of invalid stream configurations include:
2150 *
2151 * - Including more than 1 input-capable stream (INPUT or
2152 * BIDIRECTIONAL)
2153 *
2154 * - Not including any output-capable streams (OUTPUT or
2155 * BIDIRECTIONAL)
2156 *
2157 * - Including streams with unsupported formats, or an unsupported
2158 * size for that format.
2159 *
2160 * - Including too many output streams of a certain format.
2161 *
Eino-Ville Talvala7effe0c2013-02-15 12:09:48 -08002162 * Note that the framework submitting an invalid stream
2163 * configuration is not normal operation, since stream
2164 * configurations are checked before configure. An invalid
2165 * configuration means that a bug exists in the framework code, or
2166 * there is a mismatch between the HAL's static metadata and the
2167 * requirements on streams.
2168 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002169 * -ENODEV: If there has been a fatal error and the device is no longer
2170 * operational. Only close() can be called successfully by the
2171 * framework after this error is returned.
2172 */
2173 int (*configure_streams)(const struct camera3_device *,
2174 camera3_stream_configuration_t *stream_list);
2175
2176 /**
2177 * register_stream_buffers:
2178 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002179 * >= CAMERA_DEVICE_API_VERSION_3_2:
2180 *
2181 * DEPRECATED. This will not be called and must be set to NULL.
2182 *
2183 * <= CAMERA_DEVICE_API_VERSION_3_1:
2184 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002185 * Register buffers for a given stream with the HAL device. This method is
2186 * called by the framework after a new stream is defined by
2187 * configure_streams, and before buffers from that stream are included in a
2188 * capture request. If the same stream is listed in a subsequent
2189 * configure_streams() call, register_stream_buffers will _not_ be called
2190 * again for that stream.
2191 *
2192 * The framework does not need to register buffers for all configured
2193 * streams before it submits the first capture request. This allows quick
2194 * startup for preview (or similar use cases) while other streams are still
2195 * being allocated.
2196 *
2197 * This method is intended to allow the HAL device to map or otherwise
2198 * prepare the buffers for later use. The buffers passed in will already be
2199 * locked for use. At the end of the call, all the buffers must be ready to
2200 * be returned to the stream. The buffer_set argument is only valid for the
2201 * duration of this call.
2202 *
2203 * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
2204 * the camera HAL should inspect the passed-in buffers here to determine any
2205 * platform-private pixel format information.
2206 *
Zhijun He2dde4682014-01-09 09:11:49 -08002207 * Performance requirements:
2208 *
2209 * This should be a non-blocking call. The HAL should return from this call
2210 * in 1ms, and must return from this call in 5ms.
2211 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002212 * Return values:
2213 *
2214 * 0: On successful registration of the new stream buffers
2215 *
2216 * -EINVAL: If the stream_buffer_set does not refer to a valid active
2217 * stream, or if the buffers array is invalid.
2218 *
2219 * -ENOMEM: If there was a failure in registering the buffers. The framework
2220 * must consider all the stream buffers to be unregistered, and can
2221 * try to register again later.
2222 *
2223 * -ENODEV: If there is a fatal error, and the device is no longer
2224 * operational. Only close() can be called successfully by the
2225 * framework after this error is returned.
2226 */
2227 int (*register_stream_buffers)(const struct camera3_device *,
2228 const camera3_stream_buffer_set_t *buffer_set);
2229
2230 /**********************************************************************
2231 * Request creation and submission
2232 */
2233
2234 /**
2235 * construct_default_request_settings:
2236 *
2237 * Create capture settings for standard camera use cases.
2238 *
2239 * The device must return a settings buffer that is configured to meet the
2240 * requested use case, which must be one of the CAMERA3_TEMPLATE_*
2241 * enums. All request control fields must be included.
2242 *
2243 * The HAL retains ownership of this structure, but the pointer to the
2244 * structure must be valid until the device is closed. The framework and the
2245 * HAL may not modify the buffer once it is returned by this call. The same
2246 * buffer may be returned for subsequent calls for the same template, or for
2247 * other templates.
2248 *
Zhijun He2dde4682014-01-09 09:11:49 -08002249 * Performance requirements:
2250 *
2251 * This should be a non-blocking call. The HAL should return from this call
2252 * in 1ms, and must return from this call in 5ms.
2253 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002254 * Return values:
2255 *
2256 * Valid metadata: On successful creation of a default settings
2257 * buffer.
2258 *
2259 * NULL: In case of a fatal error. After this is returned, only
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002260 * the close() method can be called successfully by the
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002261 * framework.
2262 */
2263 const camera_metadata_t* (*construct_default_request_settings)(
2264 const struct camera3_device *,
2265 int type);
2266
2267 /**
2268 * process_capture_request:
2269 *
2270 * Send a new capture request to the HAL. The HAL should not return from
2271 * this call until it is ready to accept the next request to process. Only
2272 * one call to process_capture_request() will be made at a time by the
2273 * framework, and the calls will all be from the same thread. The next call
2274 * to process_capture_request() will be made as soon as a new request and
2275 * its associated buffers are available. In a normal preview scenario, this
2276 * means the function will be called again by the framework almost
2277 * instantly.
2278 *
2279 * The actual request processing is asynchronous, with the results of
2280 * capture being returned by the HAL through the process_capture_result()
2281 * call. This call requires the result metadata to be available, but output
2282 * buffers may simply provide sync fences to wait on. Multiple requests are
2283 * expected to be in flight at once, to maintain full output frame rate.
2284 *
2285 * The framework retains ownership of the request structure. It is only
2286 * guaranteed to be valid during this call. The HAL device must make copies
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002287 * of the information it needs to retain for the capture processing. The HAL
2288 * is responsible for waiting on and closing the buffers' fences and
2289 * returning the buffer handles to the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002290 *
2291 * The HAL must write the file descriptor for the input buffer's release
2292 * sync fence into input_buffer->release_fence, if input_buffer is not
2293 * NULL. If the HAL returns -1 for the input buffer release sync fence, the
2294 * framework is free to immediately reuse the input buffer. Otherwise, the
2295 * framework will wait on the sync fence before refilling and reusing the
2296 * input buffer.
2297 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002298 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002299 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002300 * The input/output buffers provided by the framework in each request
2301 * may be brand new (having never before seen by the HAL).
2302 *
2303 * ------------------------------------------------------------------------
2304 * Performance considerations:
2305 *
2306 * Handling a new buffer should be extremely lightweight and there should be
2307 * no frame rate degradation or frame jitter introduced.
2308 *
2309 * This call must return fast enough to ensure that the requested frame
2310 * rate can be sustained, especially for streaming cases (post-processing
2311 * quality settings set to FAST). The HAL should return this call in 1
2312 * frame interval, and must return from this call in 4 frame intervals.
Zhijun He2dde4682014-01-09 09:11:49 -08002313 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002314 * Return values:
2315 *
2316 * 0: On a successful start to processing the capture request
2317 *
2318 * -EINVAL: If the input is malformed (the settings are NULL when not
2319 * allowed, there are 0 output buffers, etc) and capture processing
2320 * cannot start. Failures during request processing should be
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002321 * handled by calling camera3_callback_ops_t.notify(). In case of
2322 * this error, the framework will retain responsibility for the
2323 * stream buffers' fences and the buffer handles; the HAL should
2324 * not close the fences or return these buffers with
2325 * process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002326 *
2327 * -ENODEV: If the camera device has encountered a serious error. After this
2328 * error is returned, only the close() method can be successfully
2329 * called by the framework.
2330 *
2331 */
2332 int (*process_capture_request)(const struct camera3_device *,
2333 camera3_capture_request_t *request);
2334
2335 /**********************************************************************
2336 * Miscellaneous methods
2337 */
2338
2339 /**
2340 * get_metadata_vendor_tag_ops:
2341 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002342 * Get methods to query for vendor extension metadata tag information. The
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002343 * HAL should fill in all the vendor tag operation methods, or leave ops
2344 * unchanged if no vendor tags are defined.
2345 *
2346 * The definition of vendor_tag_query_ops_t can be found in
2347 * system/media/camera/include/system/camera_metadata.h.
2348 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -08002349 * >= CAMERA_DEVICE_API_VERSION_3_2:
2350 * DEPRECATED. This function has been deprecated and should be set to
2351 * NULL by the HAL. Please implement get_vendor_tag_ops in camera_common.h
2352 * instead.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002353 */
2354 void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
2355 vendor_tag_query_ops_t* ops);
2356
2357 /**
2358 * dump:
2359 *
2360 * Print out debugging state for the camera device. This will be called by
2361 * the framework when the camera service is asked for a debug dump, which
2362 * happens when using the dumpsys tool, or when capturing a bugreport.
2363 *
2364 * The passed-in file descriptor can be used to write debugging text using
2365 * dprintf() or write(). The text should be in ASCII encoding only.
Zhijun He2dde4682014-01-09 09:11:49 -08002366 *
2367 * Performance requirements:
2368 *
2369 * This must be a non-blocking call. The HAL should return from this call
2370 * in 1ms, must return from this call in 10ms. This call must avoid
2371 * deadlocks, as it may be called at any point during camera operation.
2372 * Any synchronization primitives used (such as mutex locks or semaphores)
2373 * should be acquired with a timeout.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002374 */
2375 void (*dump)(const struct camera3_device *, int fd);
2376
Alex Ray5f2fd852013-06-24 11:28:05 -07002377 /**
2378 * flush:
2379 *
2380 * Flush all currently in-process captures and all buffers in the pipeline
2381 * on the given device. The framework will use this to dump all state as
2382 * quickly as possible in order to prepare for a configure_streams() call.
2383 *
2384 * No buffers are required to be successfully returned, so every buffer
2385 * held at the time of flush() (whether sucessfully filled or not) may be
2386 * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed
2387 * to return valid (STATUS_OK) buffers during this call, provided they are
2388 * succesfully filled.
2389 *
2390 * All requests currently in the HAL are expected to be returned as soon as
2391 * possible. Not-in-process requests should return errors immediately. Any
2392 * interruptible hardware blocks should be stopped, and any uninterruptible
2393 * blocks should be waited on.
2394 *
2395 * flush() should only return when there are no more outstanding buffers or
2396 * requests left in the HAL. The framework may call configure_streams (as
2397 * the HAL state is now quiesced) or may issue new requests.
2398 *
Zhijun He2dde4682014-01-09 09:11:49 -08002399 * Performance requirements:
2400 *
2401 * The HAL should return from this call in 100ms, and must return from this
2402 * call in 1000ms. And this call must not be blocked longer than pipeline
2403 * latency (see S7 for definition).
Alex Ray5f2fd852013-06-24 11:28:05 -07002404 *
2405 * Version information:
2406 *
2407 * only available if device version >= CAMERA_DEVICE_API_VERSION_3_1.
2408 *
2409 * Return values:
2410 *
2411 * 0: On a successful flush of the camera HAL.
2412 *
2413 * -EINVAL: If the input is malformed (the device is not valid).
2414 *
2415 * -ENODEV: If the camera device has encountered a serious error. After this
2416 * error is returned, only the close() method can be successfully
2417 * called by the framework.
2418 */
2419 int (*flush)(const struct camera3_device *);
2420
2421 /* reserved for future use */
2422 void *reserved[8];
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002423} camera3_device_ops_t;
2424
2425/**********************************************************************
2426 *
2427 * Camera device definition
2428 *
2429 */
2430typedef struct camera3_device {
2431 /**
2432 * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
2433 * device as implementing version 3.0 of the camera device HAL.
Zhijun He2dde4682014-01-09 09:11:49 -08002434 *
2435 * Performance requirements:
2436 *
2437 * common.open should return in 200ms, and must return in 500ms.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002438 */
2439 hw_device_t common;
2440 camera3_device_ops_t *ops;
2441 void *priv;
2442} camera3_device_t;
2443
2444__END_DECLS
2445
2446#endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */