blob: 9da18d2f403cf3eec36462bfc4fdbe38f0cc4bfd [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.
Igor Murashkin5df2f622014-01-10 14:18:45 -0800106 *
107 * - add partial result support. process_capture_result may be called
108 * multiple times with a subset of the available result before the full
109 * result is available.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800110 */
111
112/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700113 * S2. Startup and general expected operation sequence:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800114 *
115 * 1. Framework calls camera_module_t->common.open(), which returns a
116 * hardware_device_t structure.
117 *
118 * 2. Framework inspects the hardware_device_t->version field, and instantiates
119 * the appropriate handler for that version of the camera hardware device. In
120 * case the version is CAMERA_DEVICE_API_VERSION_3_0, the device is cast to
121 * a camera3_device_t.
122 *
123 * 3. Framework calls camera3_device_t->ops->initialize() with the framework
124 * callback function pointers. This will only be called this one time after
125 * open(), before any other functions in the ops structure are called.
126 *
127 * 4. The framework calls camera3_device_t->ops->configure_streams() with a list
128 * of input/output streams to the HAL device.
129 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800130 * 5. <= CAMERA_DEVICE_API_VERSION_3_1:
131 *
132 * The framework allocates gralloc buffers and calls
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800133 * camera3_device_t->ops->register_stream_buffers() for at least one of the
134 * output streams listed in configure_streams. The same stream is registered
135 * only once.
136 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800137 * >= CAMERA_DEVICE_API_VERSION_3_2:
138 *
139 * camera3_device_t->ops->register_stream_buffers() is not called and must
140 * be NULL.
141 *
142 * 6. The framework requests default settings for some number of use cases with
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800143 * calls to camera3_device_t->ops->construct_default_request_settings(). This
144 * may occur any time after step 3.
145 *
146 * 7. The framework constructs and sends the first capture request to the HAL,
147 * with settings based on one of the sets of default settings, and with at
148 * least one output stream, which has been registered earlier by the
149 * framework. This is sent to the HAL with
150 * camera3_device_t->ops->process_capture_request(). The HAL must block the
151 * return of this call until it is ready for the next request to be sent.
152 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800153 * >= CAMERA_DEVICE_API_VERSION_3_2:
154 *
155 * The buffer_handle_t provided in the camera3_stream_buffer_t array
156 * in the camera3_capture_request_t may be new and never-before-seen
157 * by the HAL on any given new request.
158 *
159 * 8. The framework continues to submit requests, and call
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800160 * construct_default_request_settings to get default settings buffers for
161 * other use cases.
162 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800163 * <= CAMERA_DEVICE_API_VERSION_3_1:
164 *
165 * The framework may call register_stream_buffers() at this time for
166 * not-yet-registered streams.
167 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800168 * 9. When the capture of a request begins (sensor starts exposing for the
169 * capture), the HAL calls camera3_callback_ops_t->notify() with the SHUTTER
170 * event, including the frame number and the timestamp for start of exposure.
Igor Murashkin5df2f622014-01-10 14:18:45 -0800171 *
172 * <= CAMERA_DEVICE_API_VERSION_3_1:
173 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -0700174 * This notify call must be made before the first call to
175 * process_capture_result() for that frame number.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800176 *
Igor Murashkin5df2f622014-01-10 14:18:45 -0800177 * >= CAMERA_DEVICE_API_VERSION_3_2:
178 *
179 * The camera3_callback_ops_t->notify() call with the SHUTTER event should
180 * be made as early as possible since the framework will be unable to
181 * deliver gralloc buffers to the application layer (for that frame) until
182 * it has a valid timestamp for the start of exposure.
183 *
184 * Both partial metadata results and the gralloc buffers may be sent to the
185 * framework at any time before or after the SHUTTER event.
186 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800187 * 10. After some pipeline delay, the HAL begins to return completed captures to
188 * the framework with camera3_callback_ops_t->process_capture_result(). These
189 * are returned in the same order as the requests were submitted. Multiple
190 * requests can be in flight at once, depending on the pipeline depth of the
191 * camera HAL device.
192 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800193 * >= CAMERA_DEVICE_API_VERSION_3_2:
194 *
195 * Once a buffer is returned by process_capture_result as part of the
196 * camera3_stream_buffer_t array, and the fence specified by release_fence
197 * has been signaled (this is a no-op for -1 fences), the ownership of that
198 * buffer is considered to be transferred back to the framework. After that,
199 * the HAL must no longer retain that particular buffer, and the
200 * framework may clean up the memory for it immediately.
201 *
Igor Murashkin5df2f622014-01-10 14:18:45 -0800202 * process_capture_result may be called multiple times for a single frame,
203 * each time with a new disjoint piece of metadata and/or set of gralloc
204 * buffers. The framework will accumulate these partial metadata results
205 * into one result.
206 *
207 * In particular, it is legal for a process_capture_result to be called
208 * simultaneously for both a frame N and a frame N+1 as long as the
209 * above rule holds for gralloc buffers.
210 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800211 * 11. After some time, the framework may stop submitting new requests, wait for
212 * the existing captures to complete (all buffers filled, all results
213 * returned), and then call configure_streams() again. This resets the camera
214 * hardware and pipeline for a new set of input/output streams. Some streams
215 * may be reused from the previous configuration; if these streams' buffers
216 * had already been registered with the HAL, they will not be registered
217 * again. The framework then continues from step 7, if at least one
218 * registered output stream remains (otherwise, step 5 is required first).
219 *
220 * 12. Alternatively, the framework may call camera3_device_t->common->close()
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -0800221 * to end the camera session. This may be called at any time when no other
222 * calls from the framework are active, although the call may block until all
223 * in-flight captures have completed (all results returned, all buffers
224 * filled). After the close call returns, no more calls to the
225 * camera3_callback_ops_t functions are allowed from the HAL. Once the
226 * close() call is underway, the framework may not call any other HAL device
227 * functions.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800228 *
229 * 13. In case of an error or other asynchronous event, the HAL must call
230 * camera3_callback_ops_t->notify() with the appropriate error/event
231 * message. After returning from a fatal device-wide error notification, the
232 * HAL should act as if close() had been called on it. However, the HAL must
233 * either cancel or complete all outstanding captures before calling
234 * notify(), so that once notify() is called with a fatal error, the
235 * framework will not receive further callbacks from the device. Methods
236 * besides close() should return -ENODEV or NULL after the notify() method
237 * returns from a fatal error message.
238 */
239
240/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700241 * S3. Operational modes:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800242 *
243 * The camera 3 HAL device can implement one of two possible operational modes;
244 * limited and full. Full support is expected from new higher-end
245 * devices. Limited mode has hardware requirements roughly in line with those
246 * for a camera HAL device v1 implementation, and is expected from older or
247 * inexpensive devices. Full is a strict superset of limited, and they share the
248 * same essential operational flow, as documented above.
249 *
250 * The HAL must indicate its level of support with the
251 * android.info.supportedHardwareLevel static metadata entry, with 0 indicating
252 * limited mode, and 1 indicating full mode support.
253 *
254 * Roughly speaking, limited-mode devices do not allow for application control
255 * of capture settings (3A control only), high-rate capture of high-resolution
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700256 * images, raw sensor readout, or support for YUV output streams above maximum
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800257 * recording resolution (JPEG only for large images).
258 *
259 * ** Details of limited mode behavior:
260 *
261 * - Limited-mode devices do not need to implement accurate synchronization
262 * between capture request settings and the actual image data
263 * captured. Instead, changes to settings may take effect some time in the
264 * future, and possibly not for the same output frame for each settings
265 * entry. Rapid changes in settings may result in some settings never being
266 * used for a capture. However, captures that include high-resolution output
267 * buffers ( > 1080p ) have to use the settings as specified (but see below
268 * for processing rate).
269 *
270 * - Limited-mode devices do not need to support most of the
271 * settings/result/static info metadata. Full-mode devices must support all
272 * metadata fields listed in TODO. Specifically, only the following settings
273 * are expected to be consumed or produced by a limited-mode HAL device:
274 *
275 * android.control.aeAntibandingMode (controls)
276 * android.control.aeExposureCompensation (controls)
277 * android.control.aeLock (controls)
278 * android.control.aeMode (controls)
279 * [OFF means ON_FLASH_TORCH - TODO]
280 * android.control.aeRegions (controls)
281 * android.control.aeTargetFpsRange (controls)
282 * android.control.afMode (controls)
283 * [OFF means infinity focus]
284 * android.control.afRegions (controls)
285 * android.control.awbLock (controls)
286 * android.control.awbMode (controls)
287 * [OFF not supported]
288 * android.control.awbRegions (controls)
289 * android.control.captureIntent (controls)
290 * android.control.effectMode (controls)
291 * android.control.mode (controls)
292 * [OFF not supported]
293 * android.control.sceneMode (controls)
294 * android.control.videoStabilizationMode (controls)
295 * android.control.aeAvailableAntibandingModes (static)
296 * android.control.aeAvailableModes (static)
297 * android.control.aeAvailableTargetFpsRanges (static)
298 * android.control.aeCompensationRange (static)
299 * android.control.aeCompensationStep (static)
300 * android.control.afAvailableModes (static)
301 * android.control.availableEffects (static)
302 * android.control.availableSceneModes (static)
303 * android.control.availableVideoStabilizationModes (static)
304 * android.control.awbAvailableModes (static)
305 * android.control.maxRegions (static)
306 * android.control.sceneModeOverrides (static)
307 * android.control.aeRegions (dynamic)
308 * android.control.aeState (dynamic)
309 * android.control.afMode (dynamic)
310 * android.control.afRegions (dynamic)
311 * android.control.afState (dynamic)
312 * android.control.awbMode (dynamic)
313 * android.control.awbRegions (dynamic)
314 * android.control.awbState (dynamic)
315 * android.control.mode (dynamic)
316 *
317 * android.flash.info.available (static)
318 *
319 * android.info.supportedHardwareLevel (static)
320 *
321 * android.jpeg.gpsCoordinates (controls)
322 * android.jpeg.gpsProcessingMethod (controls)
323 * android.jpeg.gpsTimestamp (controls)
324 * android.jpeg.orientation (controls)
325 * android.jpeg.quality (controls)
326 * android.jpeg.thumbnailQuality (controls)
327 * android.jpeg.thumbnailSize (controls)
328 * android.jpeg.availableThumbnailSizes (static)
329 * android.jpeg.maxSize (static)
330 * android.jpeg.gpsCoordinates (dynamic)
331 * android.jpeg.gpsProcessingMethod (dynamic)
332 * android.jpeg.gpsTimestamp (dynamic)
333 * android.jpeg.orientation (dynamic)
334 * android.jpeg.quality (dynamic)
335 * android.jpeg.size (dynamic)
336 * android.jpeg.thumbnailQuality (dynamic)
337 * android.jpeg.thumbnailSize (dynamic)
338 *
339 * android.lens.info.minimumFocusDistance (static)
340 *
341 * android.request.id (controls)
342 * android.request.id (dynamic)
343 *
344 * android.scaler.cropRegion (controls)
345 * [ignores (x,y), assumes center-zoom]
346 * android.scaler.availableFormats (static)
347 * [RAW not supported]
348 * android.scaler.availableJpegMinDurations (static)
349 * android.scaler.availableJpegSizes (static)
350 * android.scaler.availableMaxDigitalZoom (static)
351 * android.scaler.availableProcessedMinDurations (static)
352 * android.scaler.availableProcessedSizes (static)
353 * [full resolution not supported]
354 * android.scaler.maxDigitalZoom (static)
355 * android.scaler.cropRegion (dynamic)
356 *
357 * android.sensor.orientation (static)
358 * android.sensor.timestamp (dynamic)
359 *
360 * android.statistics.faceDetectMode (controls)
361 * android.statistics.info.availableFaceDetectModes (static)
362 * android.statistics.faceDetectMode (dynamic)
363 * android.statistics.faceIds (dynamic)
364 * android.statistics.faceLandmarks (dynamic)
365 * android.statistics.faceRectangles (dynamic)
366 * android.statistics.faceScores (dynamic)
367 *
368 * - Captures in limited mode that include high-resolution (> 1080p) output
369 * buffers may block in process_capture_request() until all the output buffers
370 * have been filled. A full-mode HAL device must process sequences of
371 * high-resolution requests at the rate indicated in the static metadata for
372 * that pixel format. The HAL must still call process_capture_result() to
373 * provide the output; the framework must simply be prepared for
374 * process_capture_request() to block until after process_capture_result() for
375 * that request completes for high-resolution captures for limited-mode
376 * devices.
377 *
378 */
379
380/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700381 * S4. 3A modes and state machines:
382 *
383 * While the actual 3A algorithms are up to the HAL implementation, a high-level
384 * state machine description is defined by the HAL interface, to allow the HAL
385 * device and the framework to communicate about the current state of 3A, and to
386 * trigger 3A events.
387 *
388 * When the device is opened, all the individual 3A states must be
389 * STATE_INACTIVE. Stream configuration does not reset 3A. For example, locked
390 * focus must be maintained across the configure() call.
391 *
392 * Triggering a 3A action involves simply setting the relevant trigger entry in
393 * the settings for the next request to indicate start of trigger. For example,
394 * the trigger for starting an autofocus scan is setting the entry
395 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTROL_AF_TRIGGER_START for one
396 * request, and cancelling an autofocus scan is triggered by setting
397 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTRL_AF_TRIGGER_CANCEL. Otherwise,
398 * the entry will not exist, or be set to ANDROID_CONTROL_AF_TRIGGER_IDLE. Each
399 * request with a trigger entry set to a non-IDLE value will be treated as an
400 * independent triggering event.
401 *
402 * At the top level, 3A is controlled by the ANDROID_CONTROL_MODE setting, which
403 * selects between no 3A (ANDROID_CONTROL_MODE_OFF), normal AUTO mode
404 * (ANDROID_CONTROL_MODE_AUTO), and using the scene mode setting
405 * (ANDROID_CONTROL_USE_SCENE_MODE).
406 *
407 * - In OFF mode, each of the individual AE/AF/AWB modes are effectively OFF,
408 * and none of the capture controls may be overridden by the 3A routines.
409 *
410 * - In AUTO mode, Auto-focus, auto-exposure, and auto-whitebalance all run
411 * their own independent algorithms, and have their own mode, state, and
412 * trigger metadata entries, as listed in the next section.
413 *
414 * - In USE_SCENE_MODE, the value of the ANDROID_CONTROL_SCENE_MODE entry must
415 * be used to determine the behavior of 3A routines. In SCENE_MODEs other than
416 * FACE_PRIORITY, the HAL must override the values of
417 * ANDROId_CONTROL_AE/AWB/AF_MODE to be the mode it prefers for the selected
418 * SCENE_MODE. For example, the HAL may prefer SCENE_MODE_NIGHT to use
419 * CONTINUOUS_FOCUS AF mode. Any user selection of AE/AWB/AF_MODE when scene
420 * must be ignored for these scene modes.
421 *
422 * - For SCENE_MODE_FACE_PRIORITY, the AE/AWB/AF_MODE controls work as in
423 * ANDROID_CONTROL_MODE_AUTO, but the 3A routines must bias toward metering
424 * and focusing on any detected faces in the scene.
425 *
426 * S4.1. Auto-focus settings and result entries:
427 *
428 * Main metadata entries:
429 *
430 * ANDROID_CONTROL_AF_MODE: Control for selecting the current autofocus
431 * mode. Set by the framework in the request settings.
432 *
433 * AF_MODE_OFF: AF is disabled; the framework/app directly controls lens
434 * position.
435 *
436 * AF_MODE_AUTO: Single-sweep autofocus. No lens movement unless AF is
437 * triggered.
438 *
439 * AF_MODE_MACRO: Single-sweep up-close autofocus. No lens movement unless
440 * AF is triggered.
441 *
442 * AF_MODE_CONTINUOUS_VIDEO: Smooth continuous focusing, for recording
443 * video. Triggering immediately locks focus in current
444 * position. Canceling resumes cotinuous focusing.
445 *
446 * AF_MODE_CONTINUOUS_PICTURE: Fast continuous focusing, for
447 * zero-shutter-lag still capture. Triggering locks focus once currently
448 * active sweep concludes. Canceling resumes continuous focusing.
449 *
450 * AF_MODE_EDOF: Advanced extended depth of field focusing. There is no
451 * autofocus scan, so triggering one or canceling one has no effect.
452 * Images are focused automatically by the HAL.
453 *
454 * ANDROID_CONTROL_AF_STATE: Dynamic metadata describing the current AF
455 * algorithm state, reported by the HAL in the result metadata.
456 *
457 * AF_STATE_INACTIVE: No focusing has been done, or algorithm was
458 * reset. Lens is not moving. Always the state for MODE_OFF or MODE_EDOF.
459 * When the device is opened, it must start in this state.
460 *
461 * AF_STATE_PASSIVE_SCAN: A continuous focus algorithm is currently scanning
462 * for good focus. The lens is moving.
463 *
464 * AF_STATE_PASSIVE_FOCUSED: A continuous focus algorithm believes it is
465 * well focused. The lens is not moving. The HAL may spontaneously leave
466 * this state.
467 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700468 * AF_STATE_PASSIVE_UNFOCUSED: A continuous focus algorithm believes it is
469 * not well focused. The lens is not moving. The HAL may spontaneously
470 * leave this state.
471 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700472 * AF_STATE_ACTIVE_SCAN: A scan triggered by the user is underway.
473 *
474 * AF_STATE_FOCUSED_LOCKED: The AF algorithm believes it is focused. The
475 * lens is not moving.
476 *
477 * AF_STATE_NOT_FOCUSED_LOCKED: The AF algorithm has been unable to
478 * focus. The lens is not moving.
479 *
480 * ANDROID_CONTROL_AF_TRIGGER: Control for starting an autofocus scan, the
481 * meaning of which is mode- and state- dependent. Set by the framework in
482 * the request settings.
483 *
484 * AF_TRIGGER_IDLE: No current trigger.
485 *
486 * AF_TRIGGER_START: Trigger start of AF scan. Effect is mode and state
487 * dependent.
488 *
489 * AF_TRIGGER_CANCEL: Cancel current AF scan if any, and reset algorithm to
490 * default.
491 *
492 * Additional metadata entries:
493 *
494 * ANDROID_CONTROL_AF_REGIONS: Control for selecting the regions of the FOV
495 * that should be used to determine good focus. This applies to all AF
496 * modes that scan for focus. Set by the framework in the request
497 * settings.
498 *
499 * S4.2. Auto-exposure settings and result entries:
500 *
501 * Main metadata entries:
502 *
503 * ANDROID_CONTROL_AE_MODE: Control for selecting the current auto-exposure
504 * mode. Set by the framework in the request settings.
505 *
506 * AE_MODE_OFF: Autoexposure is disabled; the user controls exposure, gain,
507 * frame duration, and flash.
508 *
509 * AE_MODE_ON: Standard autoexposure, with flash control disabled. User may
510 * set flash to fire or to torch mode.
511 *
512 * AE_MODE_ON_AUTO_FLASH: Standard autoexposure, with flash on at HAL's
513 * discretion for precapture and still capture. User control of flash
514 * disabled.
515 *
516 * AE_MODE_ON_ALWAYS_FLASH: Standard autoexposure, with flash always fired
517 * for capture, and at HAL's discretion for precapture.. User control of
518 * flash disabled.
519 *
520 * AE_MODE_ON_AUTO_FLASH_REDEYE: Standard autoexposure, with flash on at
521 * HAL's discretion for precapture and still capture. Use a flash burst
522 * at end of precapture sequence to reduce redeye in the final
523 * picture. User control of flash disabled.
524 *
525 * ANDROID_CONTROL_AE_STATE: Dynamic metadata describing the current AE
526 * algorithm state, reported by the HAL in the result metadata.
527 *
528 * AE_STATE_INACTIVE: Initial AE state after mode switch. When the device is
529 * opened, it must start in this state.
530 *
531 * AE_STATE_SEARCHING: AE is not converged to a good value, and is adjusting
532 * exposure parameters.
533 *
534 * AE_STATE_CONVERGED: AE has found good exposure values for the current
535 * scene, and the exposure parameters are not changing. HAL may
536 * spontaneously leave this state to search for better solution.
537 *
538 * AE_STATE_LOCKED: AE has been locked with the AE_LOCK control. Exposure
539 * values are not changing.
540 *
541 * AE_STATE_FLASH_REQUIRED: The HAL has converged exposure, but believes
542 * flash is required for a sufficiently bright picture. Used for
543 * determining if a zero-shutter-lag frame can be used.
544 *
545 * AE_STATE_PRECAPTURE: The HAL is in the middle of a precapture
546 * sequence. Depending on AE mode, this mode may involve firing the
547 * flash for metering, or a burst of flash pulses for redeye reduction.
548 *
549 * ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER: Control for starting a metering
550 * sequence before capturing a high-quality image. Set by the framework in
551 * the request settings.
552 *
553 * PRECAPTURE_TRIGGER_IDLE: No current trigger.
554 *
555 * PRECAPTURE_TRIGGER_START: Start a precapture sequence. The HAL should
556 * use the subsequent requests to measure good exposure/white balance
557 * for an upcoming high-resolution capture.
558 *
559 * Additional metadata entries:
560 *
561 * ANDROID_CONTROL_AE_LOCK: Control for locking AE controls to their current
562 * values
563 *
564 * ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION: Control for adjusting AE
565 * algorithm target brightness point.
566 *
567 * ANDROID_CONTROL_AE_TARGET_FPS_RANGE: Control for selecting the target frame
568 * rate range for the AE algorithm. The AE routine cannot change the frame
569 * rate to be outside these bounds.
570 *
571 * ANDROID_CONTROL_AE_REGIONS: Control for selecting the regions of the FOV
572 * that should be used to determine good exposure levels. This applies to
573 * all AE modes besides OFF.
574 *
575 * S4.3. Auto-whitebalance settings and result entries:
576 *
577 * Main metadata entries:
578 *
579 * ANDROID_CONTROL_AWB_MODE: Control for selecting the current white-balance
580 * mode.
581 *
582 * AWB_MODE_OFF: Auto-whitebalance is disabled. User controls color matrix.
583 *
584 * AWB_MODE_AUTO: Automatic white balance is enabled; 3A controls color
585 * transform, possibly using more complex transforms than a simple
586 * matrix.
587 *
588 * AWB_MODE_INCANDESCENT: Fixed white balance settings good for indoor
589 * incandescent (tungsten) lighting, roughly 2700K.
590 *
591 * AWB_MODE_FLUORESCENT: Fixed white balance settings good for fluorescent
592 * lighting, roughly 5000K.
593 *
594 * AWB_MODE_WARM_FLUORESCENT: Fixed white balance settings good for
595 * fluorescent lighting, roughly 3000K.
596 *
597 * AWB_MODE_DAYLIGHT: Fixed white balance settings good for daylight,
598 * roughly 5500K.
599 *
600 * AWB_MODE_CLOUDY_DAYLIGHT: Fixed white balance settings good for clouded
601 * daylight, roughly 6500K.
602 *
603 * AWB_MODE_TWILIGHT: Fixed white balance settings good for
604 * near-sunset/sunrise, roughly 15000K.
605 *
606 * AWB_MODE_SHADE: Fixed white balance settings good for areas indirectly
607 * lit by the sun, roughly 7500K.
608 *
609 * ANDROID_CONTROL_AWB_STATE: Dynamic metadata describing the current AWB
610 * algorithm state, reported by the HAL in the result metadata.
611 *
612 * AWB_STATE_INACTIVE: Initial AWB state after mode switch. When the device
613 * is opened, it must start in this state.
614 *
615 * AWB_STATE_SEARCHING: AWB is not converged to a good value, and is
616 * changing color adjustment parameters.
617 *
618 * AWB_STATE_CONVERGED: AWB has found good color adjustment values for the
619 * current scene, and the parameters are not changing. HAL may
620 * spontaneously leave this state to search for better solution.
621 *
622 * AWB_STATE_LOCKED: AWB has been locked with the AWB_LOCK control. Color
623 * adjustment values are not changing.
624 *
625 * Additional metadata entries:
626 *
627 * ANDROID_CONTROL_AWB_LOCK: Control for locking AWB color adjustments to
628 * their current values.
629 *
630 * ANDROID_CONTROL_AWB_REGIONS: Control for selecting the regions of the FOV
631 * that should be used to determine good color balance. This applies only
632 * to auto-WB mode.
633 *
634 * S4.4. General state machine transition notes
635 *
636 * Switching between AF, AE, or AWB modes always resets the algorithm's state
637 * to INACTIVE. Similarly, switching between CONTROL_MODE or
638 * CONTROL_SCENE_MODE if CONTROL_MODE == USE_SCENE_MODE resets all the
639 * algorithm states to INACTIVE.
640 *
641 * The tables below are per-mode.
642 *
643 * S4.5. AF state machines
644 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700645 * when enabling AF or changing AF mode
646 *| state | trans. cause | new state | notes |
647 *+--------------------+---------------+--------------------+------------------+
648 *| Any | AF mode change| INACTIVE | |
649 *+--------------------+---------------+--------------------+------------------+
650 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700651 * mode = AF_MODE_OFF or AF_MODE_EDOF
652 *| state | trans. cause | new state | notes |
653 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700654 *| INACTIVE | | INACTIVE | Never changes |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700655 *+--------------------+---------------+--------------------+------------------+
656 *
657 * mode = AF_MODE_AUTO or AF_MODE_MACRO
658 *| state | trans. cause | new state | notes |
659 *+--------------------+---------------+--------------------+------------------+
660 *| INACTIVE | AF_TRIGGER | ACTIVE_SCAN | Start AF sweep |
661 *| | | | Lens now moving |
662 *+--------------------+---------------+--------------------+------------------+
663 *| ACTIVE_SCAN | AF sweep done | FOCUSED_LOCKED | If AF successful |
664 *| | | | Lens now locked |
665 *+--------------------+---------------+--------------------+------------------+
666 *| ACTIVE_SCAN | AF sweep done | NOT_FOCUSED_LOCKED | If AF successful |
667 *| | | | Lens now locked |
668 *+--------------------+---------------+--------------------+------------------+
669 *| ACTIVE_SCAN | AF_CANCEL | INACTIVE | Cancel/reset AF |
670 *| | | | Lens now locked |
671 *+--------------------+---------------+--------------------+------------------+
672 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
673 *+--------------------+---------------+--------------------+------------------+
674 *| FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
675 *| | | | Lens now moving |
676 *+--------------------+---------------+--------------------+------------------+
677 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
678 *+--------------------+---------------+--------------------+------------------+
679 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
680 *| | | | Lens now moving |
681 *+--------------------+---------------+--------------------+------------------+
682 *| All states | mode change | INACTIVE | |
683 *+--------------------+---------------+--------------------+------------------+
684 *
685 * mode = AF_MODE_CONTINUOUS_VIDEO
686 *| state | trans. cause | new state | notes |
687 *+--------------------+---------------+--------------------+------------------+
688 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
689 *| | new scan | | Lens now moving |
690 *+--------------------+---------------+--------------------+------------------+
691 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
692 *| | | | Lens now locked |
693 *+--------------------+---------------+--------------------+------------------+
694 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
695 *| | current scan | | Lens now locked |
696 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700697 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
698 *| | current scan | | Lens now locked |
699 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700700 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
701 *| | | | if focus is good |
702 *| | | | Lens now locked |
703 *+--------------------+---------------+--------------------+------------------+
704 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
705 *| | | | if focus is bad |
706 *| | | | Lens now locked |
707 *+--------------------+---------------+--------------------+------------------+
708 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
709 *| | | | position |
710 *| | | | Lens now locked |
711 *+--------------------+---------------+--------------------+------------------+
712 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
713 *| | new scan | | Lens now moving |
714 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700715 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
716 *| | new scan | | Lens now moving |
717 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700718 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700719 *| | | | Lens now locked |
720 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700721 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700722 *| | | | Lens now locked |
723 *+--------------------+---------------+--------------------+------------------+
724 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
725 *+--------------------+---------------+--------------------+------------------+
726 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
727 *+--------------------+---------------+--------------------+------------------+
728 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
729 *+--------------------+---------------+--------------------+------------------+
730 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
731 *+--------------------+---------------+--------------------+------------------+
732 *
733 * mode = AF_MODE_CONTINUOUS_PICTURE
734 *| state | trans. cause | new state | notes |
735 *+--------------------+---------------+--------------------+------------------+
736 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
737 *| | new scan | | Lens now moving |
738 *+--------------------+---------------+--------------------+------------------+
739 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
740 *| | | | Lens now locked |
741 *+--------------------+---------------+--------------------+------------------+
742 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
743 *| | current scan | | Lens now locked |
744 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700745 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
746 *| | current scan | | Lens now locked |
747 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700748 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Eventual trans. |
749 *| | | | once focus good |
750 *| | | | Lens now locked |
751 *+--------------------+---------------+--------------------+------------------+
752 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Eventual trans. |
753 *| | | | if cannot focus |
754 *| | | | Lens now locked |
755 *+--------------------+---------------+--------------------+------------------+
756 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
757 *| | | | position |
758 *| | | | Lens now locked |
759 *+--------------------+---------------+--------------------+------------------+
760 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
761 *| | new scan | | Lens now moving |
762 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700763 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
764 *| | new scan | | Lens now moving |
765 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700766 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700767 *| | | | Lens now locked |
768 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700769 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700770 *| | | | Lens now locked |
771 *+--------------------+---------------+--------------------+------------------+
772 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
773 *+--------------------+---------------+--------------------+------------------+
774 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
775 *+--------------------+---------------+--------------------+------------------+
776 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
777 *+--------------------+---------------+--------------------+------------------+
778 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
779 *+--------------------+---------------+--------------------+------------------+
780 *
781 * S4.6. AE and AWB state machines
782 *
783 * The AE and AWB state machines are mostly identical. AE has additional
784 * FLASH_REQUIRED and PRECAPTURE states. So rows below that refer to those two
785 * states should be ignored for the AWB state machine.
786 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700787 * when enabling AE/AWB or changing AE/AWB mode
788 *| state | trans. cause | new state | notes |
789 *+--------------------+---------------+--------------------+------------------+
790 *| Any | mode change | INACTIVE | |
791 *+--------------------+---------------+--------------------+------------------+
792 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700793 * mode = AE_MODE_OFF / AWB mode not AUTO
794 *| state | trans. cause | new state | notes |
795 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700796 *| INACTIVE | | INACTIVE | AE/AWB disabled |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700797 *+--------------------+---------------+--------------------+------------------+
798 *
799 * mode = AE_MODE_ON_* / AWB_MODE_AUTO
800 *| state | trans. cause | new state | notes |
801 *+--------------------+---------------+--------------------+------------------+
802 *| INACTIVE | HAL initiates | SEARCHING | |
803 *| | AE/AWB scan | | |
804 *+--------------------+---------------+--------------------+------------------+
805 *| INACTIVE | AE/AWB_LOCK | LOCKED | values locked |
806 *| | on | | |
807 *+--------------------+---------------+--------------------+------------------+
808 *| SEARCHING | HAL finishes | CONVERGED | good values, not |
809 *| | AE/AWB scan | | changing |
810 *+--------------------+---------------+--------------------+------------------+
811 *| SEARCHING | HAL finishes | FLASH_REQUIRED | converged but too|
812 *| | AE scan | | dark w/o flash |
813 *+--------------------+---------------+--------------------+------------------+
814 *| SEARCHING | AE/AWB_LOCK | LOCKED | values locked |
815 *| | on | | |
816 *+--------------------+---------------+--------------------+------------------+
817 *| CONVERGED | HAL initiates | SEARCHING | values locked |
818 *| | AE/AWB scan | | |
819 *+--------------------+---------------+--------------------+------------------+
820 *| CONVERGED | AE/AWB_LOCK | LOCKED | values locked |
821 *| | on | | |
822 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala73dba5e2013-05-21 16:29:14 -0700823 *| FLASH_REQUIRED | HAL initiates | SEARCHING | values locked |
824 *| | AE/AWB scan | | |
825 *+--------------------+---------------+--------------------+------------------+
826 *| FLASH_REQUIRED | AE/AWB_LOCK | LOCKED | values locked |
827 *| | on | | |
828 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700829 *| LOCKED | AE/AWB_LOCK | SEARCHING | values not good |
830 *| | off | | after unlock |
831 *+--------------------+---------------+--------------------+------------------+
832 *| LOCKED | AE/AWB_LOCK | CONVERGED | values good |
833 *| | off | | after unlock |
834 *+--------------------+---------------+--------------------+------------------+
835 *| LOCKED | AE_LOCK | FLASH_REQUIRED | exposure good, |
836 *| | off | | but too dark |
837 *+--------------------+---------------+--------------------+------------------+
838 *| All AE states | PRECAPTURE_ | PRECAPTURE | Start precapture |
839 *| | START | | sequence |
840 *+--------------------+---------------+--------------------+------------------+
841 *| PRECAPTURE | Sequence done.| CONVERGED | Ready for high- |
842 *| | AE_LOCK off | | quality capture |
843 *+--------------------+---------------+--------------------+------------------+
844 *| PRECAPTURE | Sequence done.| LOCKED | Ready for high- |
845 *| | AE_LOCK on | | quality capture |
846 *+--------------------+---------------+--------------------+------------------+
847 *
848 */
849
850/**
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700851 * S5. Cropping:
852 *
853 * Cropping of the full pixel array (for digital zoom and other use cases where
854 * a smaller FOV is desirable) is communicated through the
855 * ANDROID_SCALER_CROP_REGION setting. This is a per-request setting, and can
856 * change on a per-request basis, which is critical for implementing smooth
857 * digital zoom.
858 *
859 * The region is defined as a rectangle (x, y, width, height), with (x, y)
860 * describing the top-left corner of the rectangle. The rectangle is defined on
861 * the coordinate system of the sensor active pixel array, with (0,0) being the
862 * top-left pixel of the active pixel array. Therefore, the width and height
863 * cannot be larger than the dimensions reported in the
864 * ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY static info field. The minimum allowed
865 * width and height are reported by the HAL through the
866 * ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes the
867 * maximum supported zoom factor. Therefore, the minimum crop region width and
868 * height are:
869 *
870 * {width, height} =
871 * { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
872 * ANDROID_SCALER_MAX_DIGITAL_ZOOM),
873 * floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
874 * ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
875 *
876 * If the crop region needs to fulfill specific requirements (for example, it
877 * needs to start on even coordinates, and its width/height needs to be even),
878 * the HAL must do the necessary rounding and write out the final crop region
879 * used in the output result metadata. Similarly, if the HAL implements video
880 * stabilization, it must adjust the result crop region to describe the region
881 * actually included in the output after video stabilization is applied. In
882 * general, a camera-using application must be able to determine the field of
883 * view it is receiving based on the crop region, the dimensions of the image
884 * sensor, and the lens focal length.
885 *
886 * Since the crop region applies to all streams, which may have different aspect
887 * ratios than the crop region, the exact sensor region used for each stream may
888 * be smaller than the crop region. Specifically, each stream should maintain
889 * square pixels and its aspect ratio by minimally further cropping the defined
890 * crop region. If the stream's aspect ratio is wider than the crop region, the
891 * stream should be further cropped vertically, and if the stream's aspect ratio
892 * is narrower than the crop region, the stream should be further cropped
893 * horizontally.
894 *
895 * In all cases, the stream crop must be centered within the full crop region,
896 * and each stream is only either cropped horizontally or vertical relative to
897 * the full crop region, never both.
898 *
899 * For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
900 * 1280x720 stream (16:9 aspect), below demonstrates the expected output regions
901 * for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
902 * 1500 pixel array) sensor.
903 *
904 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
905 *
906 * 640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)
907 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
908 *
909 * 0 1000 2000
910 * +---------+---------+---------+----------+
911 * | Active pixel array |
912 * | |
913 * | |
914 * + +-------------------+ + 375
915 * | | | |
916 * | O===================O |
917 * | I 1280x720 stream I |
918 * + I I + 750
919 * | I I |
920 * | O===================O |
921 * | | | |
922 * + +-------------------+ + 1125
923 * | Crop region, 640x480 stream |
924 * | |
925 * | |
926 * +---------+---------+---------+----------+ 1500
927 *
928 * Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)
929 *
930 * 640x480 stream crop: (666, 375, 1000, 750) (marked with =)
931 * 1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
932 *
933 * 0 1000 2000
934 * +---------+---------+---------+----------+
935 * | Active pixel array |
936 * | |
937 * | |
938 * + +---O==================O---+ + 375
939 * | | I 640x480 stream I | |
940 * | | I I | |
941 * | | I I | |
942 * + | I I | + 750
943 * | | I I | |
944 * | | I I | |
945 * | | I I | |
946 * + +---O==================O---+ + 1125
947 * | Crop region, 1280x720 stream |
948 * | |
949 * | |
950 * +---------+---------+---------+----------+ 1500
951 *
952 * Crop region: (500, 375, 750, 750) (1:1 aspect ratio)
953 *
954 * 640x480 stream crop: (500, 469, 750, 562) (marked with =)
955 * 1280x720 stream crop: (500, 543, 750, 414) (marged with #)
956 *
957 * 0 1000 2000
958 * +---------+---------+---------+----------+
959 * | Active pixel array |
960 * | |
961 * | |
962 * + +--------------+ + 375
963 * | O==============O |
964 * | ################ |
965 * | # # |
966 * + # # + 750
967 * | # # |
968 * | ################ 1280x720 |
969 * | O==============O 640x480 |
970 * + +--------------+ + 1125
971 * | Crop region |
972 * | |
973 * | |
974 * +---------+---------+---------+----------+ 1500
975 *
976 * And a final example, a 1024x1024 square aspect ratio stream instead of the
977 * 480p stream:
978 *
979 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
980 *
981 * 1024x1024 stream crop: (625, 375, 750, 750) (marked with #)
982 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
983 *
984 * 0 1000 2000
985 * +---------+---------+---------+----------+
986 * | Active pixel array |
987 * | |
988 * | 1024x1024 stream |
989 * + +--###############--+ + 375
990 * | | # # | |
991 * | O===================O |
992 * | I 1280x720 stream I |
993 * + I I + 750
994 * | I I |
995 * | O===================O |
996 * | | # # | |
997 * + +--###############--+ + 1125
998 * | Crop region |
999 * | |
1000 * | |
1001 * +---------+---------+---------+----------+ 1500
1002 *
1003 */
1004
1005/**
1006 * S6. Error management:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001007 *
1008 * Camera HAL device ops functions that have a return value will all return
1009 * -ENODEV / NULL in case of a serious error. This means the device cannot
1010 * continue operation, and must be closed by the framework. Once this error is
Alex Rayd5ddbc92013-02-15 13:47:24 -08001011 * returned by some method, or if notify() is called with ERROR_DEVICE, only
1012 * the close() method can be called successfully. All other methods will return
1013 * -ENODEV / NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001014 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001015 * If a device op is called in the wrong sequence, for example if the framework
1016 * calls configure_streams() is called before initialize(), the device must
1017 * return -ENOSYS from the call, and do nothing.
1018 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001019 * Transient errors in image capture must be reported through notify() as follows:
1020 *
1021 * - The failure of an entire capture to occur must be reported by the HAL by
1022 * calling notify() with ERROR_REQUEST. Individual errors for the result
1023 * metadata or the output buffers must not be reported in this case.
1024 *
1025 * - If the metadata for a capture cannot be produced, but some image buffers
1026 * were filled, the HAL must call notify() with ERROR_RESULT.
1027 *
1028 * - If an output image buffer could not be filled, but either the metadata was
1029 * produced or some other buffers were filled, the HAL must call notify() with
1030 * ERROR_BUFFER for each failed buffer.
1031 *
1032 * In each of these transient failure cases, the HAL must still call
1033 * process_capture_result, with valid output buffer_handle_t. If the result
1034 * metadata could not be produced, it should be NULL. If some buffers could not
1035 * be filled, their sync fences must be set to the error state.
1036 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001037 * Invalid input arguments result in -EINVAL from the appropriate methods. In
1038 * that case, the framework must act as if that call had never been made.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001039 *
1040 */
1041
Zhijun He2dde4682014-01-09 09:11:49 -08001042/**
Zhijun He709e5872014-01-17 15:25:21 -08001043 * S7. Key Performance Indicator (KPI) glossary:
Zhijun He2dde4682014-01-09 09:11:49 -08001044 *
Zhijun He709e5872014-01-17 15:25:21 -08001045 * This includes some critical definitions that are used by KPI metrics.
Zhijun He2dde4682014-01-09 09:11:49 -08001046 *
1047 * Pipeline Latency:
1048 * For a given capture request, the duration from the framework calling
1049 * process_capture_request to the HAL sending capture result and all buffers
1050 * back by process_capture_result call. To make the Pipeline Latency measure
1051 * independent of frame rate, it is measured by frame count.
1052 *
1053 * For example, when frame rate is 30 (fps), the frame duration (time interval
1054 * between adjacent frame capture time) is 33 (ms).
1055 * If it takes 5 frames for framework to get the result and buffers back for
1056 * a given request, then the Pipeline Latency is 5 (frames), instead of
1057 * 5 x 33 = 165 (ms).
1058 *
1059 * The Pipeline Latency is determined by android.request.pipelineDepth and
1060 * android.request.pipelineMaxDepth, see their definitions for more details.
1061 *
1062 */
1063
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001064__BEGIN_DECLS
1065
1066struct camera3_device;
1067
1068/**********************************************************************
1069 *
1070 * Camera3 stream and stream buffer definitions.
1071 *
1072 * These structs and enums define the handles and contents of the input and
1073 * output streams connecting the HAL to various framework and application buffer
1074 * consumers. Each stream is backed by a gralloc buffer queue.
1075 *
1076 */
1077
1078/**
1079 * camera3_stream_type_t:
1080 *
1081 * The type of the camera stream, which defines whether the camera HAL device is
1082 * the producer or the consumer for that stream, and how the buffers of the
1083 * stream relate to the other streams.
1084 */
1085typedef enum camera3_stream_type {
1086 /**
1087 * This stream is an output stream; the camera HAL device will be
1088 * responsible for filling buffers from this stream with newly captured or
1089 * reprocessed image data.
1090 */
1091 CAMERA3_STREAM_OUTPUT = 0,
1092
1093 /**
1094 * This stream is an input stream; the camera HAL device will be responsible
1095 * for reading buffers from this stream and sending them through the camera
1096 * processing pipeline, as if the buffer was a newly captured image from the
1097 * imager.
1098 */
1099 CAMERA3_STREAM_INPUT = 1,
1100
1101 /**
1102 * This stream can be used for input and output. Typically, the stream is
1103 * used as an output stream, but occasionally one already-filled buffer may
1104 * be sent back to the HAL device for reprocessing.
1105 *
1106 * This kind of stream is meant generally for zero-shutter-lag features,
1107 * where copying the captured image from the output buffer to the
1108 * reprocessing input buffer would be expensive. The stream will be used by
1109 * the framework as follows:
1110 *
1111 * 1. The framework includes a buffer from this stream as output buffer in a
1112 * request as normal.
1113 *
1114 * 2. Once the HAL device returns a filled output buffer to the framework,
1115 * the framework may do one of two things with the filled buffer:
1116 *
1117 * 2. a. The framework uses the filled data, and returns the now-used buffer
1118 * to the stream queue for reuse. This behavior exactly matches the
1119 * OUTPUT type of stream.
1120 *
1121 * 2. b. The framework wants to reprocess the filled data, and uses the
1122 * buffer as an input buffer for a request. Once the HAL device has
1123 * used the reprocessing buffer, it then returns it to the
1124 * framework. The framework then returns the now-used buffer to the
1125 * stream queue for reuse.
1126 *
1127 * 3. The HAL device will be given the buffer again as an output buffer for
1128 * a request at some future point.
1129 *
1130 * Note that the HAL will always be reprocessing data it produced.
1131 *
1132 */
1133 CAMERA3_STREAM_BIDIRECTIONAL = 2,
1134
1135 /**
1136 * Total number of framework-defined stream types
1137 */
1138 CAMERA3_NUM_STREAM_TYPES
1139
1140} camera3_stream_type_t;
1141
1142/**
1143 * camera3_stream_t:
1144 *
1145 * A handle to a single camera input or output stream. A stream is defined by
1146 * the framework by its buffer resolution and format, and additionally by the
1147 * HAL with the gralloc usage flags and the maximum in-flight buffer count.
1148 *
1149 * The stream structures are owned by the framework, but pointers to a
1150 * camera3_stream passed into the HAL by configure_streams() are valid until the
1151 * end of the first subsequent configure_streams() call that _does not_ include
1152 * that camera3_stream as an argument, or until the end of the close() call.
1153 *
1154 * All camera3_stream framework-controlled members are immutable once the
1155 * camera3_stream is passed into configure_streams(). The HAL may only change
1156 * the HAL-controlled parameters during a configure_streams() call, except for
1157 * the contents of the private pointer.
1158 *
1159 * If a configure_streams() call returns a non-fatal error, all active streams
1160 * remain valid as if configure_streams() had not been called.
1161 *
1162 * The endpoint of the stream is not visible to the camera HAL device.
Alex Ray2ce219a2013-06-14 15:09:30 -07001163 * In DEVICE_API_VERSION_3_1, this was changed to share consumer usage flags
1164 * on streams where the camera is a producer (OUTPUT and BIDIRECTIONAL stream
1165 * types) see the usage field below.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001166 */
1167typedef struct camera3_stream {
1168
1169 /*****
1170 * Set by framework before configure_streams()
1171 */
1172
1173 /**
1174 * The type of the stream, one of the camera3_stream_type_t values.
1175 */
1176 int stream_type;
1177
1178 /**
1179 * The width in pixels of the buffers in this stream
1180 */
1181 uint32_t width;
1182
1183 /**
1184 * The height in pixels of the buffers in this stream
1185 */
1186 uint32_t height;
1187
1188 /**
1189 * The pixel format for the buffers in this stream. Format is a value from
1190 * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
1191 * from device-specific headers.
1192 *
1193 * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
1194 * gralloc module will select a format based on the usage flags provided by
1195 * the camera device and the other endpoint of the stream.
1196 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001197 * <= CAMERA_DEVICE_API_VERSION_3_1:
1198 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001199 * The camera HAL device must inspect the buffers handed to it in the
1200 * subsequent register_stream_buffers() call to obtain the
1201 * implementation-specific format details, if necessary.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001202 *
1203 * >= CAMERA_DEVICE_API_VERSION_3_2:
1204 *
1205 * register_stream_buffers() won't be called by the framework, so the HAL
1206 * should configure the ISP and sensor pipeline based purely on the sizes,
1207 * usage flags, and formats for the configured streams.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001208 */
1209 int format;
1210
1211 /*****
1212 * Set by HAL during configure_streams().
1213 */
1214
1215 /**
1216 * The gralloc usage flags for this stream, as needed by the HAL. The usage
1217 * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
1218 * headers.
1219 *
1220 * For output streams, these are the HAL's producer usage flags. For input
1221 * streams, these are the HAL's consumer usage flags. The usage flags from
1222 * the producer and the consumer will be combined together and then passed
1223 * to the platform gralloc HAL module for allocating the gralloc buffers for
1224 * each stream.
Alex Ray2ce219a2013-06-14 15:09:30 -07001225 *
1226 * Version information:
1227 *
1228 * == CAMERA_DEVICE_API_VERSION_3_0:
1229 *
1230 * No initial value guaranteed when passed via configure_streams().
1231 * HAL may not use this field as input, and must write over this field
1232 * with its usage flags.
1233 *
1234 * >= CAMERA_DEVICE_API_VERSION_3_1:
1235 *
1236 * For stream_type OUTPUT and BIDIRECTIONAL, when passed via
1237 * configure_streams(), the initial value of this is the consumer's
1238 * usage flags. The HAL may use these consumer flags to decide stream
1239 * configuration.
1240 * For stream_type INPUT, when passed via configure_streams(), the initial
1241 * value of this is 0.
1242 * For all streams passed via configure_streams(), the HAL must write
1243 * over this field with its usage flags.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001244 */
1245 uint32_t usage;
1246
1247 /**
1248 * The maximum number of buffers the HAL device may need to have dequeued at
1249 * the same time. The HAL device may not have more buffers in-flight from
1250 * this stream than this value.
1251 */
1252 uint32_t max_buffers;
1253
1254 /**
1255 * A handle to HAL-private information for the stream. Will not be inspected
1256 * by the framework code.
1257 */
1258 void *priv;
1259
1260} camera3_stream_t;
1261
1262/**
1263 * camera3_stream_configuration_t:
1264 *
1265 * A structure of stream definitions, used by configure_streams(). This
1266 * structure defines all the output streams and the reprocessing input
1267 * stream for the current camera use case.
1268 */
1269typedef struct camera3_stream_configuration {
1270 /**
1271 * The total number of streams requested by the framework. This includes
1272 * both input and output streams. The number of streams will be at least 1,
1273 * and there will be at least one output-capable stream.
1274 */
1275 uint32_t num_streams;
1276
1277 /**
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001278 * An array of camera stream pointers, defining the input/output
1279 * configuration for the camera HAL device.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001280 *
1281 * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
1282 * in a single configuration.
1283 *
1284 * At least one output-capable stream must be defined (OUTPUT or
1285 * BIDIRECTIONAL).
1286 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001287 camera3_stream_t **streams;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001288
1289} camera3_stream_configuration_t;
1290
1291/**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001292 * camera3_buffer_status_t:
1293 *
1294 * The current status of a single stream buffer.
1295 */
1296typedef enum camera3_buffer_status {
1297 /**
1298 * The buffer is in a normal state, and can be used after waiting on its
1299 * sync fence.
1300 */
1301 CAMERA3_BUFFER_STATUS_OK = 0,
1302
1303 /**
1304 * The buffer does not contain valid data, and the data in it should not be
1305 * used. The sync fence must still be waited on before reusing the buffer.
1306 */
1307 CAMERA3_BUFFER_STATUS_ERROR = 1
1308
1309} camera3_buffer_status_t;
1310
1311/**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001312 * camera3_stream_buffer_t:
1313 *
1314 * A single buffer from a camera3 stream. It includes a handle to its parent
1315 * stream, the handle to the gralloc buffer itself, and sync fences
1316 *
1317 * The buffer does not specify whether it is to be used for input or output;
1318 * that is determined by its parent stream type and how the buffer is passed to
1319 * the HAL device.
1320 */
1321typedef struct camera3_stream_buffer {
1322 /**
1323 * The handle of the stream this buffer is associated with
1324 */
1325 camera3_stream_t *stream;
1326
1327 /**
1328 * The native handle to the buffer
1329 */
1330 buffer_handle_t *buffer;
1331
1332 /**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001333 * Current state of the buffer, one of the camera3_buffer_status_t
1334 * values. The framework will not pass buffers to the HAL that are in an
1335 * error state. In case a buffer could not be filled by the HAL, it must
1336 * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
1337 * framework with process_capture_result().
1338 */
1339 int status;
1340
1341 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001342 * The acquire sync fence for this buffer. The HAL must wait on this fence
1343 * fd before attempting to read from or write to this buffer.
1344 *
1345 * The framework may be set to -1 to indicate that no waiting is necessary
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001346 * for this buffer.
1347 *
1348 * When the HAL returns an output buffer to the framework with
1349 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
1350 * never waits on the acquire_fence due to an error in filling a buffer,
1351 * when calling process_capture_result() the HAL must set the release_fence
1352 * of the buffer to be the acquire_fence passed to it by the framework. This
1353 * will allow the framework to wait on the fence before reusing the buffer.
1354 *
1355 * For input buffers, the HAL must not change the acquire_fence field during
1356 * the process_capture_request() call.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001357 */
1358 int acquire_fence;
1359
1360 /**
1361 * The release sync fence for this buffer. The HAL must set this fence when
1362 * returning buffers to the framework, or write -1 to indicate that no
1363 * waiting is required for this buffer.
1364 *
1365 * For the input buffer, the release fence must be set by the
1366 * process_capture_request() call. For the output buffers, the fences must
1367 * be set in the output_buffers array passed to process_capture_result().
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001368 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001369 * >= CAMERA_DEVICE_API_VERSION_3_2:
1370 *
1371 * After signaling the release_fence for this buffer, the HAL
1372 * should not make any further attempts to access this buffer as the
1373 * ownership has been fully transferred back to the framework.
1374 *
1375 * If a fence of -1 was specified then the ownership of this buffer
1376 * is transferred back immediately upon the call of process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001377 */
1378 int release_fence;
1379
1380} camera3_stream_buffer_t;
1381
1382/**
1383 * camera3_stream_buffer_set_t:
1384 *
1385 * The complete set of gralloc buffers for a stream. This structure is given to
1386 * register_stream_buffers() to allow the camera HAL device to register/map/etc
1387 * newly allocated stream buffers.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001388 *
1389 * >= CAMERA_DEVICE_API_VERSION_3_2:
1390 *
1391 * Deprecated (and not used). In particular,
1392 * register_stream_buffers is also deprecated and will never be invoked.
1393 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001394 */
1395typedef struct camera3_stream_buffer_set {
1396 /**
1397 * The stream handle for the stream these buffers belong to
1398 */
1399 camera3_stream_t *stream;
1400
1401 /**
1402 * The number of buffers in this stream. It is guaranteed to be at least
1403 * stream->max_buffers.
1404 */
1405 uint32_t num_buffers;
1406
1407 /**
1408 * The array of gralloc buffer handles for this stream. If the stream format
1409 * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
1410 * should inspect the passed-in buffers to determine any platform-private
1411 * pixel format information.
1412 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001413 buffer_handle_t **buffers;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001414
1415} camera3_stream_buffer_set_t;
1416
1417/**
1418 * camera3_jpeg_blob:
1419 *
1420 * Transport header for compressed JPEG buffers in output streams.
1421 *
1422 * To capture JPEG images, a stream is created using the pixel format
1423 * HAL_PIXEL_FORMAT_BLOB, and the static metadata field android.jpeg.maxSize is
1424 * used as the buffer size. Since compressed JPEG images are of variable size,
1425 * the HAL needs to include the final size of the compressed image using this
1426 * structure inside the output stream buffer. The JPEG blob ID field must be set
1427 * to CAMERA3_JPEG_BLOB_ID.
1428 *
1429 * Transport header should be at the end of the JPEG output stream buffer. That
1430 * means the jpeg_blob_id must start at byte[android.jpeg.maxSize -
1431 * sizeof(camera3_jpeg_blob)]. Any HAL using this transport header must
1432 * account for it in android.jpeg.maxSize. The JPEG data itself starts at
1433 * the beginning of the buffer and should be jpeg_size bytes long.
1434 */
1435typedef struct camera3_jpeg_blob {
1436 uint16_t jpeg_blob_id;
1437 uint32_t jpeg_size;
1438} camera3_jpeg_blob_t;
1439
1440enum {
1441 CAMERA3_JPEG_BLOB_ID = 0x00FF
1442};
1443
1444/**********************************************************************
1445 *
1446 * Message definitions for the HAL notify() callback.
1447 *
1448 * These definitions are used for the HAL notify callback, to signal
1449 * asynchronous events from the HAL device to the Android framework.
1450 *
1451 */
1452
1453/**
1454 * camera3_msg_type:
1455 *
1456 * Indicates the type of message sent, which specifies which member of the
1457 * message union is valid.
1458 *
1459 */
1460typedef enum camera3_msg_type {
1461 /**
1462 * An error has occurred. camera3_notify_msg.message.error contains the
1463 * error information.
1464 */
1465 CAMERA3_MSG_ERROR = 1,
1466
1467 /**
1468 * The exposure of a given request has
1469 * begun. camera3_notify_msg.message.shutter contains the information
1470 * the capture.
1471 */
1472 CAMERA3_MSG_SHUTTER = 2,
1473
1474 /**
1475 * Number of framework message types
1476 */
1477 CAMERA3_NUM_MESSAGES
1478
1479} camera3_msg_type_t;
1480
1481/**
1482 * Defined error codes for CAMERA_MSG_ERROR
1483 */
1484typedef enum camera3_error_msg_code {
1485 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001486 * A serious failure occured. No further frames or buffer streams will
1487 * be produced by the device. Device should be treated as closed. The
1488 * client must reopen the device to use it again. The frame_number field
1489 * is unused.
1490 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001491 CAMERA3_MSG_ERROR_DEVICE = 1,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001492
1493 /**
1494 * An error has occurred in processing a request. No output (metadata or
1495 * buffers) will be produced for this request. The frame_number field
1496 * specifies which request has been dropped. Subsequent requests are
1497 * unaffected, and the device remains operational.
1498 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001499 CAMERA3_MSG_ERROR_REQUEST = 2,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001500
1501 /**
1502 * An error has occurred in producing an output result metadata buffer
1503 * for a request, but output stream buffers for it will still be
1504 * available. Subsequent requests are unaffected, and the device remains
1505 * operational. The frame_number field specifies the request for which
1506 * result metadata won't be available.
1507 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001508 CAMERA3_MSG_ERROR_RESULT = 3,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001509
1510 /**
1511 * An error has occurred in placing an output buffer into a stream for a
1512 * request. The frame metadata and other buffers may still be
1513 * available. Subsequent requests are unaffected, and the device remains
1514 * operational. The frame_number field specifies the request for which the
1515 * buffer was dropped, and error_stream contains a pointer to the stream
1516 * that dropped the frame.u
1517 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001518 CAMERA3_MSG_ERROR_BUFFER = 4,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001519
1520 /**
1521 * Number of error types
1522 */
1523 CAMERA3_MSG_NUM_ERRORS
1524
1525} camera3_error_msg_code_t;
1526
1527/**
1528 * camera3_error_msg_t:
1529 *
1530 * Message contents for CAMERA3_MSG_ERROR
1531 */
1532typedef struct camera3_error_msg {
1533 /**
1534 * Frame number of the request the error applies to. 0 if the frame number
1535 * isn't applicable to the error.
1536 */
1537 uint32_t frame_number;
1538
1539 /**
1540 * Pointer to the stream that had a failure. NULL if the stream isn't
1541 * applicable to the error.
1542 */
1543 camera3_stream_t *error_stream;
1544
1545 /**
1546 * The code for this error; one of the CAMERA_MSG_ERROR enum values.
1547 */
1548 int error_code;
1549
1550} camera3_error_msg_t;
1551
1552/**
1553 * camera3_shutter_msg_t:
1554 *
1555 * Message contents for CAMERA3_MSG_SHUTTER
1556 */
1557typedef struct camera3_shutter_msg {
1558 /**
1559 * Frame number of the request that has begun exposure
1560 */
1561 uint32_t frame_number;
1562
1563 /**
1564 * Timestamp for the start of capture. This must match the capture result
1565 * metadata's sensor exposure start timestamp.
1566 */
1567 uint64_t timestamp;
1568
1569} camera3_shutter_msg_t;
1570
1571/**
1572 * camera3_notify_msg_t:
1573 *
1574 * The message structure sent to camera3_callback_ops_t.notify()
1575 */
1576typedef struct camera3_notify_msg {
1577
1578 /**
1579 * The message type. One of camera3_notify_msg_type, or a private extension.
1580 */
1581 int type;
1582
1583 union {
1584 /**
1585 * Error message contents. Valid if type is CAMERA3_MSG_ERROR
1586 */
1587 camera3_error_msg_t error;
1588
1589 /**
1590 * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
1591 */
1592 camera3_shutter_msg_t shutter;
1593
1594 /**
1595 * Generic message contents. Used to ensure a minimum size for custom
1596 * message types.
1597 */
1598 uint8_t generic[32];
1599 } message;
1600
1601} camera3_notify_msg_t;
1602
1603/**********************************************************************
1604 *
1605 * Capture request/result definitions for the HAL process_capture_request()
1606 * method, and the process_capture_result() callback.
1607 *
1608 */
1609
1610/**
1611 * camera3_request_template_t:
1612 *
1613 * Available template types for
1614 * camera3_device_ops.construct_default_request_settings()
1615 */
1616typedef enum camera3_request_template {
1617 /**
1618 * Standard camera preview operation with 3A on auto.
1619 */
1620 CAMERA3_TEMPLATE_PREVIEW = 1,
1621
1622 /**
1623 * Standard camera high-quality still capture with 3A and flash on auto.
1624 */
1625 CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
1626
1627 /**
1628 * Standard video recording plus preview with 3A on auto, torch off.
1629 */
1630 CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
1631
1632 /**
1633 * High-quality still capture while recording video. Application will
1634 * include preview, video record, and full-resolution YUV or JPEG streams in
1635 * request. Must not cause stuttering on video stream. 3A on auto.
1636 */
1637 CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
1638
1639 /**
1640 * Zero-shutter-lag mode. Application will request preview and
1641 * full-resolution data for each frame, and reprocess it to JPEG when a
1642 * still image is requested by user. Settings should provide highest-quality
1643 * full-resolution images without compromising preview frame rate. 3A on
1644 * auto.
1645 */
1646 CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
1647
Zhijun Heb0c939f2013-12-13 15:56:33 -08001648 /**
1649 * A basic template for direct application control of capture
1650 * parameters. All automatic control is disabled (auto-exposure, auto-white
1651 * balance, auto-focus), and post-processing parameters are set to preview
1652 * quality. The manual capture parameters (exposure, sensitivity, etc.)
1653 * are set to reasonable defaults, but should be overridden by the
1654 * application depending on the intended use case.
1655 */
1656 CAMERA3_TEMPLATE_MANUAL = 6,
1657
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001658 /* Total number of templates */
1659 CAMERA3_TEMPLATE_COUNT,
1660
1661 /**
1662 * First value for vendor-defined request templates
1663 */
1664 CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
1665
1666} camera3_request_template_t;
1667
1668/**
1669 * camera3_capture_request_t:
1670 *
1671 * A single request for image capture/buffer reprocessing, sent to the Camera
1672 * HAL device by the framework in process_capture_request().
1673 *
1674 * The request contains the settings to be used for this capture, and the set of
1675 * output buffers to write the resulting image data in. It may optionally
1676 * contain an input buffer, in which case the request is for reprocessing that
1677 * input buffer instead of capturing a new image with the camera sensor. The
1678 * capture is identified by the frame_number.
1679 *
1680 * In response, the camera HAL device must send a camera3_capture_result
1681 * structure asynchronously to the framework, using the process_capture_result()
1682 * callback.
1683 */
1684typedef struct camera3_capture_request {
1685 /**
1686 * The frame number is an incrementing integer set by the framework to
1687 * uniquely identify this capture. It needs to be returned in the result
1688 * call, and is also used to identify the request in asynchronous
1689 * notifications sent to camera3_callback_ops_t.notify().
1690 */
1691 uint32_t frame_number;
1692
1693 /**
1694 * The settings buffer contains the capture and processing parameters for
1695 * the request. As a special case, a NULL settings buffer indicates that the
1696 * settings are identical to the most-recently submitted capture request. A
1697 * NULL buffer cannot be used as the first submitted request after a
1698 * configure_streams() call.
1699 */
1700 const camera_metadata_t *settings;
1701
1702 /**
1703 * The input stream buffer to use for this request, if any.
1704 *
1705 * If input_buffer is NULL, then the request is for a new capture from the
1706 * imager. If input_buffer is valid, the request is for reprocessing the
1707 * image contained in input_buffer.
1708 *
1709 * In the latter case, the HAL must set the release_fence of the
1710 * input_buffer to a valid sync fence, or to -1 if the HAL does not support
1711 * sync, before process_capture_request() returns.
1712 *
1713 * The HAL is required to wait on the acquire sync fence of the input buffer
1714 * before accessing it.
1715 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001716 * <= CAMERA_DEVICE_API_VERSION_3_1:
1717 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001718 * Any input buffer included here will have been registered with the HAL
1719 * through register_stream_buffers() before its inclusion in a request.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001720 *
1721 * >= CAMERA_DEVICE_API_VERSION_3_2:
1722 *
1723 * The buffers will not have been pre-registered with the HAL.
1724 * Subsequent requests may reuse buffers, or provide entirely new buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001725 */
1726 camera3_stream_buffer_t *input_buffer;
1727
1728 /**
1729 * The number of output buffers for this capture request. Must be at least
1730 * 1.
1731 */
1732 uint32_t num_output_buffers;
1733
1734 /**
1735 * An array of num_output_buffers stream buffers, to be filled with image
1736 * data from this capture/reprocess. The HAL must wait on the acquire fences
Igor Murashkin78aa1262014-01-09 16:23:43 -08001737 * of each stream buffer before writing to them.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001738 *
1739 * The HAL takes ownership of the actual buffer_handle_t entries in
1740 * output_buffers; the framework does not access them until they are
1741 * returned in a camera3_capture_result_t.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001742 *
1743 * <= CAMERA_DEVICE_API_VERSION_3_1:
1744 *
1745 * All the buffers included here will have been registered with the HAL
1746 * through register_stream_buffers() before their inclusion in a request.
1747 *
1748 * >= CAMERA_DEVICE_API_VERSION_3_2:
1749 *
1750 * Any or all of the buffers included here may be brand new in this
1751 * request (having never before seen by the HAL).
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001752 */
1753 const camera3_stream_buffer_t *output_buffers;
1754
1755} camera3_capture_request_t;
1756
1757/**
1758 * camera3_capture_result_t:
1759 *
1760 * The result of a single capture/reprocess by the camera HAL device. This is
1761 * sent to the framework asynchronously with process_capture_result(), in
1762 * response to a single capture request sent to the HAL with
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001763 * process_capture_request(). Multiple process_capture_result() calls may be
Igor Murashkin5df2f622014-01-10 14:18:45 -08001764 * performed by the HAL for each request.
1765 *
1766 * Each call, all with the same frame
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001767 * number, may contain some subset of the output buffers, and/or the result
1768 * metadata. The metadata may only be provided once for a given frame number;
1769 * all other calls must set the result metadata to NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001770 *
1771 * The result structure contains the output metadata from this capture, and the
1772 * set of output buffers that have been/will be filled for this capture. Each
1773 * output buffer may come with a release sync fence that the framework will wait
1774 * on before reading, in case the buffer has not yet been filled by the HAL.
1775 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08001776 * >= CAMERA_DEVICE_API_VERSION_3_2:
1777 *
1778 * The metadata may be provided multiple times for a single frame number. The
1779 * framework will accumulate together the final result set by combining each
1780 * partial result together into the total result set.
1781 *
1782 * Performance considerations:
1783 *
1784 * Applications will also receive these partial results immediately, so sending
1785 * partial results is a highly recommended performance optimization to avoid
1786 * the total pipeline latency before sending the results for what is known very
1787 * early on in the pipeline.
1788 *
1789 * A typical use case might be calculating the AF state halfway through the
1790 * pipeline; by sending the state back to the framework immediately, we get a
1791 * 50% performance increase and perceived responsiveness of the auto-focus.
1792 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001793 */
1794typedef struct camera3_capture_result {
1795 /**
1796 * The frame number is an incrementing integer set by the framework in the
1797 * submitted request to uniquely identify this capture. It is also used to
1798 * identify the request in asynchronous notifications sent to
1799 * camera3_callback_ops_t.notify().
1800 */
1801 uint32_t frame_number;
1802
1803 /**
1804 * The result metadata for this capture. This contains information about the
1805 * final capture parameters, the state of the capture and post-processing
1806 * hardware, the state of the 3A algorithms, if enabled, and the output of
1807 * any enabled statistics units.
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001808 *
1809 * Only one call to process_capture_result() with a given frame_number may
1810 * include the result metadata. All other calls for the same frame_number
1811 * must set this to NULL.
1812 *
1813 * If there was an error producing the result metadata, result must be an
1814 * empty metadata buffer, and notify() must be called with ERROR_RESULT.
Igor Murashkin5df2f622014-01-10 14:18:45 -08001815 *
1816 * >= CAMERA_DEVICE_API_VERSION_3_2:
1817 *
1818 * Multiple calls to process_capture_result() with a given frame_number
1819 * may include the result metadata.
1820 *
1821 * Partial metadata submitted should not include any metadata key returned
1822 * in a previous partial result for a given frame. Each new partial result
1823 * for that frame must also set a distinct partial_result value.
1824 *
1825 * If notify has been called with ERROR_RESULT, all further partial
1826 * results for that frame are ignored by the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001827 */
1828 const camera_metadata_t *result;
1829
1830 /**
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001831 * The number of output buffers returned in this result structure. Must be
1832 * less than or equal to the matching capture request's count. If this is
1833 * less than the buffer count in the capture request, at least one more call
1834 * to process_capture_result with the same frame_number must be made, to
1835 * return the remaining output buffers to the framework. This may only be
1836 * zero if the structure includes valid result metadata.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001837 */
1838 uint32_t num_output_buffers;
1839
1840 /**
1841 * The handles for the output stream buffers for this capture. They may not
1842 * yet be filled at the time the HAL calls process_capture_result(); the
1843 * framework will wait on the release sync fences provided by the HAL before
1844 * reading the buffers.
1845 *
1846 * The HAL must set the stream buffer's release sync fence to a valid sync
1847 * fd, or to -1 if the buffer has already been filled.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001848 *
1849 * If the HAL encounters an error while processing the buffer, and the
1850 * buffer is not filled, the buffer's status field must be set to
1851 * CAMERA3_BUFFER_STATUS_ERROR. If the HAL did not wait on the acquire fence
1852 * before encountering the error, the acquire fence should be copied into
1853 * the release fence, to allow the framework to wait on the fence before
1854 * reusing the buffer.
1855 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001856 * The acquire fence must be set to -1 for all output buffers. If
1857 * num_output_buffers is zero, this may be NULL. In that case, at least one
1858 * more process_capture_result call must be made by the HAL to provide the
1859 * output buffers.
Igor Murashkin5df2f622014-01-10 14:18:45 -08001860 *
1861 * When process_capture_result is called with a new buffer for a frame,
1862 * all previous frames' buffers for that corresponding stream must have been
1863 * already delivered (the fences need not have yet been signaled).
1864 *
1865 * >= CAMERA_DEVICE_API_VERSION_3_2:
1866 *
1867 * Gralloc buffers for a frame may be sent to framework before the
1868 * corresponding SHUTTER-notify.
1869 *
1870 * Performance considerations:
1871 *
1872 * Buffers delivered to the framework will not be dispatched to the
1873 * application layer until a start of exposure timestamp has been received
1874 * via a SHUTTER notify() call. It is highly recommended to
1875 * dispatch that call as early as possible.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001876 */
1877 const camera3_stream_buffer_t *output_buffers;
1878
Igor Murashkin5df2f622014-01-10 14:18:45 -08001879 /**
1880 * >= CAMERA_DEVICE_API_VERSION_3_2:
1881 *
1882 * In order to take advantage of partial results, the HAL must set the
1883 * static metadata android.request.partialResultCount to the number of
1884 * partial results it will send for each frame.
1885 *
1886 * Each new capture result with a partial result must set
1887 * this field (partial_result) to a distinct inclusive value between
1888 * 1 and android.request.partialResultCount.
1889 *
1890 * HALs not wishing to take advantage of this feature must not
1891 * set an android.request.partialResultCount or partial_result to a value
1892 * other than 1.
1893 *
1894 * This value must be set to 0 when a capture result contains buffers only
1895 * and no metadata.
1896 */
1897 uint32_t partial_result;
1898
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001899} camera3_capture_result_t;
1900
1901/**********************************************************************
1902 *
1903 * Callback methods for the HAL to call into the framework.
1904 *
1905 * These methods are used to return metadata and image buffers for a completed
1906 * or failed captures, and to notify the framework of asynchronous events such
1907 * as errors.
1908 *
1909 * The framework will not call back into the HAL from within these callbacks,
1910 * and these calls will not block for extended periods.
1911 *
1912 */
1913typedef struct camera3_callback_ops {
1914
1915 /**
1916 * process_capture_result:
1917 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001918 * Send results from a completed capture to the framework.
1919 * process_capture_result() may be invoked multiple times by the HAL in
1920 * response to a single capture request. This allows, for example, the
1921 * metadata and low-resolution buffers to be returned in one call, and
1922 * post-processed JPEG buffers in a later call, once it is available. Each
1923 * call must include the frame number of the request it is returning
1924 * metadata or buffers for.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001925 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001926 * A component (buffer or metadata) of the complete result may only be
1927 * included in one process_capture_result call. A buffer for each stream,
1928 * and the result metadata, must be returned by the HAL for each request in
1929 * one of the process_capture_result calls, even in case of errors producing
1930 * some of the output. A call to process_capture_result() with neither
1931 * output buffers or result metadata is not allowed.
1932 *
1933 * The order of returning metadata and buffers for a single result does not
1934 * matter, but buffers for a given stream must be returned in FIFO order. So
1935 * the buffer for request 5 for stream A must always be returned before the
1936 * buffer for request 6 for stream A. This also applies to the result
1937 * metadata; the metadata for request 5 must be returned before the metadata
1938 * for request 6.
1939 *
1940 * However, different streams are independent of each other, so it is
1941 * acceptable and expected that the buffer for request 5 for stream A may be
1942 * returned after the buffer for request 6 for stream B is. And it is
1943 * acceptable that the result metadata for request 6 for stream B is
1944 * returned before the buffer for request 5 for stream A is.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001945 *
1946 * The HAL retains ownership of result structure, which only needs to be
1947 * valid to access during this call. The framework will copy whatever it
1948 * needs before this call returns.
1949 *
1950 * The output buffers do not need to be filled yet; the framework will wait
1951 * on the stream buffer release sync fence before reading the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001952 * data. Therefore, this method should be called by the HAL as soon as
1953 * possible, even if some or all of the output buffers are still in
1954 * being filled. The HAL must include valid release sync fences into each
1955 * output_buffers stream buffer entry, or -1 if that stream buffer is
1956 * already filled.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001957 *
1958 * If the result buffer cannot be constructed for a request, the HAL should
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001959 * return an empty metadata buffer, but still provide the output buffers and
1960 * their sync fences. In addition, notify() must be called with an
1961 * ERROR_RESULT message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001962 *
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001963 * If an output buffer cannot be filled, its status field must be set to
1964 * STATUS_ERROR. In addition, notify() must be called with a ERROR_BUFFER
1965 * message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001966 *
1967 * If the entire capture has failed, then this method still needs to be
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001968 * called to return the output buffers to the framework. All the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001969 * statuses should be STATUS_ERROR, and the result metadata should be an
1970 * empty buffer. In addition, notify() must be called with a ERROR_REQUEST
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001971 * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
1972 * should not be sent.
1973 *
Zhijun He2dde4682014-01-09 09:11:49 -08001974 * Performance requirements:
1975 *
1976 * This is a non-blocking call. The framework will return this call in 5ms.
1977 *
1978 * The pipeline latency (see S7 for definition) should be less than or equal to
1979 * 4 frame intervals, and must be less than or equal to 8 frame intervals.
1980 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001981 */
1982 void (*process_capture_result)(const struct camera3_callback_ops *,
1983 const camera3_capture_result_t *result);
1984
1985 /**
1986 * notify:
1987 *
1988 * Asynchronous notification callback from the HAL, fired for various
1989 * reasons. Only for information independent of frame capture, or that
1990 * require specific timing. The ownership of the message structure remains
1991 * with the HAL, and the msg only needs to be valid for the duration of this
1992 * call.
1993 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08001994 * Multiple threads may call notify() simultaneously.
1995 *
1996 * <= CAMERA_DEVICE_API_VERSION_3_1:
1997 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07001998 * The notification for the start of exposure for a given request must be
1999 * sent by the HAL before the first call to process_capture_result() for
2000 * that request is made.
2001 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002002 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002003 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002004 * Buffers delivered to the framework will not be dispatched to the
2005 * application layer until a start of exposure timestamp has been received
2006 * via a SHUTTER notify() call. It is highly recommended to
2007 * dispatch this call as early as possible.
2008 *
2009 * ------------------------------------------------------------------------
Zhijun He2dde4682014-01-09 09:11:49 -08002010 * Performance requirements:
2011 *
2012 * This is a non-blocking call. The framework will return this call in 5ms.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002013 */
2014 void (*notify)(const struct camera3_callback_ops *,
2015 const camera3_notify_msg_t *msg);
2016
2017} camera3_callback_ops_t;
2018
2019/**********************************************************************
2020 *
2021 * Camera device operations
2022 *
2023 */
2024typedef struct camera3_device_ops {
2025
2026 /**
2027 * initialize:
2028 *
2029 * One-time initialization to pass framework callback function pointers to
2030 * the HAL. Will be called once after a successful open() call, before any
2031 * other functions are called on the camera3_device_ops structure.
2032 *
Zhijun He2dde4682014-01-09 09:11:49 -08002033 * Performance requirements:
2034 *
2035 * This should be a non-blocking call. The HAL should return from this call
2036 * in 5ms, and must return from this call in 10ms.
2037 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002038 * Return values:
2039 *
2040 * 0: On successful initialization
2041 *
2042 * -ENODEV: If initialization fails. Only close() can be called successfully
2043 * by the framework after this.
2044 */
2045 int (*initialize)(const struct camera3_device *,
2046 const camera3_callback_ops_t *callback_ops);
2047
2048 /**********************************************************************
2049 * Stream management
2050 */
2051
2052 /**
2053 * configure_streams:
2054 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002055 * CAMERA_DEVICE_API_VERSION_3_0 only:
2056 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002057 * Reset the HAL camera device processing pipeline and set up new input and
2058 * output streams. This call replaces any existing stream configuration with
2059 * the streams defined in the stream_list. This method will be called at
2060 * least once after initialize() before a request is submitted with
2061 * process_capture_request().
2062 *
2063 * The stream_list must contain at least one output-capable stream, and may
2064 * not contain more than one input-capable stream.
2065 *
2066 * The stream_list may contain streams that are also in the currently-active
2067 * set of streams (from the previous call to configure_stream()). These
2068 * streams will already have valid values for usage, max_buffers, and the
Igor Murashkin78aa1262014-01-09 16:23:43 -08002069 * private pointer.
2070 *
2071 * If such a stream has already had its buffers registered,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002072 * register_stream_buffers() will not be called again for the stream, and
2073 * buffers from the stream can be immediately included in input requests.
2074 *
2075 * If the HAL needs to change the stream configuration for an existing
2076 * stream due to the new configuration, it may rewrite the values of usage
Igor Murashkin78aa1262014-01-09 16:23:43 -08002077 * and/or max_buffers during the configure call.
2078 *
2079 * The framework will detect such a change, and will then reallocate the
2080 * stream buffers, and call register_stream_buffers() again before using
2081 * buffers from that stream in a request.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002082 *
2083 * If a currently-active stream is not included in stream_list, the HAL may
2084 * safely remove any references to that stream. It will not be reused in a
2085 * later configure() call by the framework, and all the gralloc buffers for
2086 * it will be freed after the configure_streams() call returns.
2087 *
2088 * The stream_list structure is owned by the framework, and may not be
2089 * accessed once this call completes. The address of an individual
2090 * camera3_stream_t structure will remain valid for access by the HAL until
2091 * the end of the first configure_stream() call which no longer includes
2092 * that camera3_stream_t in the stream_list argument. The HAL may not change
2093 * values in the stream structure outside of the private pointer, except for
2094 * the usage and max_buffers members during the configure_streams() call
2095 * itself.
2096 *
2097 * If the stream is new, the usage, max_buffer, and private pointer fields
2098 * of the stream structure will all be set to 0. The HAL device must set
2099 * these fields before the configure_streams() call returns. These fields
2100 * are then used by the framework and the platform gralloc module to
2101 * allocate the gralloc buffers for each stream.
2102 *
2103 * Before such a new stream can have its buffers included in a capture
2104 * request, the framework will call register_stream_buffers() with that
2105 * stream. However, the framework is not required to register buffers for
2106 * _all_ streams before submitting a request. This allows for quick startup
2107 * of (for example) a preview stream, with allocation for other streams
2108 * happening later or concurrently.
2109 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002110 * ------------------------------------------------------------------------
2111 * CAMERA_DEVICE_API_VERSION_3_1 only:
2112 *
2113 * Reset the HAL camera device processing pipeline and set up new input and
2114 * output streams. This call replaces any existing stream configuration with
2115 * the streams defined in the stream_list. This method will be called at
2116 * least once after initialize() before a request is submitted with
2117 * process_capture_request().
2118 *
2119 * The stream_list must contain at least one output-capable stream, and may
2120 * not contain more than one input-capable stream.
2121 *
2122 * The stream_list may contain streams that are also in the currently-active
2123 * set of streams (from the previous call to configure_stream()). These
2124 * streams will already have valid values for usage, max_buffers, and the
2125 * private pointer.
2126 *
2127 * If such a stream has already had its buffers registered,
2128 * register_stream_buffers() will not be called again for the stream, and
2129 * buffers from the stream can be immediately included in input requests.
2130 *
2131 * If the HAL needs to change the stream configuration for an existing
2132 * stream due to the new configuration, it may rewrite the values of usage
2133 * and/or max_buffers during the configure call.
2134 *
2135 * The framework will detect such a change, and will then reallocate the
2136 * stream buffers, and call register_stream_buffers() again before using
2137 * buffers from that stream in a request.
2138 *
2139 * If a currently-active stream is not included in stream_list, the HAL may
2140 * safely remove any references to that stream. It will not be reused in a
2141 * later configure() call by the framework, and all the gralloc buffers for
2142 * it will be freed after the configure_streams() call returns.
2143 *
2144 * The stream_list structure is owned by the framework, and may not be
2145 * accessed once this call completes. The address of an individual
2146 * camera3_stream_t structure will remain valid for access by the HAL until
2147 * the end of the first configure_stream() call which no longer includes
2148 * that camera3_stream_t in the stream_list argument. The HAL may not change
2149 * values in the stream structure outside of the private pointer, except for
2150 * the usage and max_buffers members during the configure_streams() call
2151 * itself.
2152 *
2153 * If the stream is new, max_buffer, and private pointer fields of the
2154 * stream structure will all be set to 0. The usage will be set to the
2155 * consumer usage flags. The HAL device must set these fields before the
2156 * configure_streams() call returns. These fields are then used by the
2157 * framework and the platform gralloc module to allocate the gralloc
2158 * buffers for each stream.
2159 *
2160 * Before such a new stream can have its buffers included in a capture
2161 * request, the framework will call register_stream_buffers() with that
2162 * stream. However, the framework is not required to register buffers for
2163 * _all_ streams before submitting a request. This allows for quick startup
2164 * of (for example) a preview stream, with allocation for other streams
2165 * happening later or concurrently.
2166 *
2167 * ------------------------------------------------------------------------
2168 * >= CAMERA_DEVICE_API_VERSION_3_2:
2169 *
2170 * Reset the HAL camera device processing pipeline and set up new input and
2171 * output streams. This call replaces any existing stream configuration with
2172 * the streams defined in the stream_list. This method will be called at
2173 * least once after initialize() before a request is submitted with
2174 * process_capture_request().
2175 *
2176 * The stream_list must contain at least one output-capable stream, and may
2177 * not contain more than one input-capable stream.
2178 *
2179 * The stream_list may contain streams that are also in the currently-active
2180 * set of streams (from the previous call to configure_stream()). These
2181 * streams will already have valid values for usage, max_buffers, and the
2182 * private pointer.
2183 *
2184 * If the HAL needs to change the stream configuration for an existing
2185 * stream due to the new configuration, it may rewrite the values of usage
2186 * and/or max_buffers during the configure call.
2187 *
2188 * The framework will detect such a change, and may then reallocate the
2189 * stream buffers before using buffers from that stream in a request.
2190 *
2191 * If a currently-active stream is not included in stream_list, the HAL may
2192 * safely remove any references to that stream. It will not be reused in a
2193 * later configure() call by the framework, and all the gralloc buffers for
2194 * it will be freed after the configure_streams() call returns.
2195 *
2196 * The stream_list structure is owned by the framework, and may not be
2197 * accessed once this call completes. The address of an individual
2198 * camera3_stream_t structure will remain valid for access by the HAL until
2199 * the end of the first configure_stream() call which no longer includes
2200 * that camera3_stream_t in the stream_list argument. The HAL may not change
2201 * values in the stream structure outside of the private pointer, except for
2202 * the usage and max_buffers members during the configure_streams() call
2203 * itself.
2204 *
2205 * If the stream is new, max_buffer, and private pointer fields of the
2206 * stream structure will all be set to 0. The usage will be set to the
2207 * consumer usage flags. The HAL device must set these fields before the
2208 * configure_streams() call returns. These fields are then used by the
2209 * framework and the platform gralloc module to allocate the gralloc
2210 * buffers for each stream.
2211 *
2212 * Newly allocated buffers may be included in a capture request at any time
2213 * by the framework. Once a gralloc buffer is returned to the framework
2214 * with process_capture_result (and its respective release_fence has been
2215 * signaled) the framework may free or reuse it at any time.
2216 *
2217 * ------------------------------------------------------------------------
2218 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002219 * Preconditions:
2220 *
2221 * The framework will only call this method when no captures are being
2222 * processed. That is, all results have been returned to the framework, and
2223 * all in-flight input and output buffers have been returned and their
2224 * release sync fences have been signaled by the HAL. The framework will not
2225 * submit new requests for capture while the configure_streams() call is
2226 * underway.
2227 *
2228 * Postconditions:
2229 *
2230 * The HAL device must configure itself to provide maximum possible output
2231 * frame rate given the sizes and formats of the output streams, as
2232 * documented in the camera device's static metadata.
2233 *
Zhijun He2dde4682014-01-09 09:11:49 -08002234 * Performance requirements:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002235 *
2236 * This call is expected to be heavyweight and possibly take several hundred
2237 * milliseconds to complete, since it may require resetting and
2238 * reconfiguring the image sensor and the camera processing pipeline.
2239 * Nevertheless, the HAL device should attempt to minimize the
2240 * reconfiguration delay to minimize the user-visible pauses during
2241 * application operational mode changes (such as switching from still
2242 * capture to video recording).
2243 *
Zhijun He2dde4682014-01-09 09:11:49 -08002244 * The HAL should return from this call in 500ms, and must return from this
2245 * call in 1000ms.
2246 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002247 * Return values:
2248 *
2249 * 0: On successful stream configuration
2250 *
2251 * -EINVAL: If the requested stream configuration is invalid. Some examples
2252 * of invalid stream configurations include:
2253 *
2254 * - Including more than 1 input-capable stream (INPUT or
2255 * BIDIRECTIONAL)
2256 *
2257 * - Not including any output-capable streams (OUTPUT or
2258 * BIDIRECTIONAL)
2259 *
2260 * - Including streams with unsupported formats, or an unsupported
2261 * size for that format.
2262 *
2263 * - Including too many output streams of a certain format.
2264 *
Eino-Ville Talvala7effe0c2013-02-15 12:09:48 -08002265 * Note that the framework submitting an invalid stream
2266 * configuration is not normal operation, since stream
2267 * configurations are checked before configure. An invalid
2268 * configuration means that a bug exists in the framework code, or
2269 * there is a mismatch between the HAL's static metadata and the
2270 * requirements on streams.
2271 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002272 * -ENODEV: If there has been a fatal error and the device is no longer
2273 * operational. Only close() can be called successfully by the
2274 * framework after this error is returned.
2275 */
2276 int (*configure_streams)(const struct camera3_device *,
2277 camera3_stream_configuration_t *stream_list);
2278
2279 /**
2280 * register_stream_buffers:
2281 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002282 * >= CAMERA_DEVICE_API_VERSION_3_2:
2283 *
2284 * DEPRECATED. This will not be called and must be set to NULL.
2285 *
2286 * <= CAMERA_DEVICE_API_VERSION_3_1:
2287 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002288 * Register buffers for a given stream with the HAL device. This method is
2289 * called by the framework after a new stream is defined by
2290 * configure_streams, and before buffers from that stream are included in a
2291 * capture request. If the same stream is listed in a subsequent
2292 * configure_streams() call, register_stream_buffers will _not_ be called
2293 * again for that stream.
2294 *
2295 * The framework does not need to register buffers for all configured
2296 * streams before it submits the first capture request. This allows quick
2297 * startup for preview (or similar use cases) while other streams are still
2298 * being allocated.
2299 *
2300 * This method is intended to allow the HAL device to map or otherwise
2301 * prepare the buffers for later use. The buffers passed in will already be
2302 * locked for use. At the end of the call, all the buffers must be ready to
2303 * be returned to the stream. The buffer_set argument is only valid for the
2304 * duration of this call.
2305 *
2306 * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
2307 * the camera HAL should inspect the passed-in buffers here to determine any
2308 * platform-private pixel format information.
2309 *
Zhijun He2dde4682014-01-09 09:11:49 -08002310 * Performance requirements:
2311 *
2312 * This should be a non-blocking call. The HAL should return from this call
2313 * in 1ms, and must return from this call in 5ms.
2314 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002315 * Return values:
2316 *
2317 * 0: On successful registration of the new stream buffers
2318 *
2319 * -EINVAL: If the stream_buffer_set does not refer to a valid active
2320 * stream, or if the buffers array is invalid.
2321 *
2322 * -ENOMEM: If there was a failure in registering the buffers. The framework
2323 * must consider all the stream buffers to be unregistered, and can
2324 * try to register again later.
2325 *
2326 * -ENODEV: If there is a fatal error, and the device is no longer
2327 * operational. Only close() can be called successfully by the
2328 * framework after this error is returned.
2329 */
2330 int (*register_stream_buffers)(const struct camera3_device *,
2331 const camera3_stream_buffer_set_t *buffer_set);
2332
2333 /**********************************************************************
2334 * Request creation and submission
2335 */
2336
2337 /**
2338 * construct_default_request_settings:
2339 *
2340 * Create capture settings for standard camera use cases.
2341 *
2342 * The device must return a settings buffer that is configured to meet the
2343 * requested use case, which must be one of the CAMERA3_TEMPLATE_*
2344 * enums. All request control fields must be included.
2345 *
2346 * The HAL retains ownership of this structure, but the pointer to the
2347 * structure must be valid until the device is closed. The framework and the
2348 * HAL may not modify the buffer once it is returned by this call. The same
2349 * buffer may be returned for subsequent calls for the same template, or for
2350 * other templates.
2351 *
Zhijun He2dde4682014-01-09 09:11:49 -08002352 * Performance requirements:
2353 *
2354 * This should be a non-blocking call. The HAL should return from this call
2355 * in 1ms, and must return from this call in 5ms.
2356 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002357 * Return values:
2358 *
2359 * Valid metadata: On successful creation of a default settings
2360 * buffer.
2361 *
2362 * NULL: In case of a fatal error. After this is returned, only
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002363 * the close() method can be called successfully by the
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002364 * framework.
2365 */
2366 const camera_metadata_t* (*construct_default_request_settings)(
2367 const struct camera3_device *,
2368 int type);
2369
2370 /**
2371 * process_capture_request:
2372 *
2373 * Send a new capture request to the HAL. The HAL should not return from
2374 * this call until it is ready to accept the next request to process. Only
2375 * one call to process_capture_request() will be made at a time by the
2376 * framework, and the calls will all be from the same thread. The next call
2377 * to process_capture_request() will be made as soon as a new request and
2378 * its associated buffers are available. In a normal preview scenario, this
2379 * means the function will be called again by the framework almost
2380 * instantly.
2381 *
2382 * The actual request processing is asynchronous, with the results of
2383 * capture being returned by the HAL through the process_capture_result()
2384 * call. This call requires the result metadata to be available, but output
2385 * buffers may simply provide sync fences to wait on. Multiple requests are
2386 * expected to be in flight at once, to maintain full output frame rate.
2387 *
2388 * The framework retains ownership of the request structure. It is only
2389 * guaranteed to be valid during this call. The HAL device must make copies
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002390 * of the information it needs to retain for the capture processing. The HAL
2391 * is responsible for waiting on and closing the buffers' fences and
2392 * returning the buffer handles to the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002393 *
2394 * The HAL must write the file descriptor for the input buffer's release
2395 * sync fence into input_buffer->release_fence, if input_buffer is not
2396 * NULL. If the HAL returns -1 for the input buffer release sync fence, the
2397 * framework is free to immediately reuse the input buffer. Otherwise, the
2398 * framework will wait on the sync fence before refilling and reusing the
2399 * input buffer.
2400 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002401 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002402 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002403 * The input/output buffers provided by the framework in each request
2404 * may be brand new (having never before seen by the HAL).
2405 *
2406 * ------------------------------------------------------------------------
2407 * Performance considerations:
2408 *
2409 * Handling a new buffer should be extremely lightweight and there should be
2410 * no frame rate degradation or frame jitter introduced.
2411 *
2412 * This call must return fast enough to ensure that the requested frame
2413 * rate can be sustained, especially for streaming cases (post-processing
2414 * quality settings set to FAST). The HAL should return this call in 1
2415 * frame interval, and must return from this call in 4 frame intervals.
Zhijun He2dde4682014-01-09 09:11:49 -08002416 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002417 * Return values:
2418 *
2419 * 0: On a successful start to processing the capture request
2420 *
2421 * -EINVAL: If the input is malformed (the settings are NULL when not
2422 * allowed, there are 0 output buffers, etc) and capture processing
2423 * cannot start. Failures during request processing should be
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002424 * handled by calling camera3_callback_ops_t.notify(). In case of
2425 * this error, the framework will retain responsibility for the
2426 * stream buffers' fences and the buffer handles; the HAL should
2427 * not close the fences or return these buffers with
2428 * process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002429 *
2430 * -ENODEV: If the camera device has encountered a serious error. After this
2431 * error is returned, only the close() method can be successfully
2432 * called by the framework.
2433 *
2434 */
2435 int (*process_capture_request)(const struct camera3_device *,
2436 camera3_capture_request_t *request);
2437
2438 /**********************************************************************
2439 * Miscellaneous methods
2440 */
2441
2442 /**
2443 * get_metadata_vendor_tag_ops:
2444 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002445 * Get methods to query for vendor extension metadata tag information. The
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002446 * HAL should fill in all the vendor tag operation methods, or leave ops
2447 * unchanged if no vendor tags are defined.
2448 *
2449 * The definition of vendor_tag_query_ops_t can be found in
2450 * system/media/camera/include/system/camera_metadata.h.
2451 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -08002452 * >= CAMERA_DEVICE_API_VERSION_3_2:
2453 * DEPRECATED. This function has been deprecated and should be set to
2454 * NULL by the HAL. Please implement get_vendor_tag_ops in camera_common.h
2455 * instead.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002456 */
2457 void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
2458 vendor_tag_query_ops_t* ops);
2459
2460 /**
2461 * dump:
2462 *
2463 * Print out debugging state for the camera device. This will be called by
2464 * the framework when the camera service is asked for a debug dump, which
2465 * happens when using the dumpsys tool, or when capturing a bugreport.
2466 *
2467 * The passed-in file descriptor can be used to write debugging text using
2468 * dprintf() or write(). The text should be in ASCII encoding only.
Zhijun He2dde4682014-01-09 09:11:49 -08002469 *
2470 * Performance requirements:
2471 *
2472 * This must be a non-blocking call. The HAL should return from this call
2473 * in 1ms, must return from this call in 10ms. This call must avoid
2474 * deadlocks, as it may be called at any point during camera operation.
2475 * Any synchronization primitives used (such as mutex locks or semaphores)
2476 * should be acquired with a timeout.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002477 */
2478 void (*dump)(const struct camera3_device *, int fd);
2479
Alex Ray5f2fd852013-06-24 11:28:05 -07002480 /**
2481 * flush:
2482 *
2483 * Flush all currently in-process captures and all buffers in the pipeline
2484 * on the given device. The framework will use this to dump all state as
2485 * quickly as possible in order to prepare for a configure_streams() call.
2486 *
2487 * No buffers are required to be successfully returned, so every buffer
2488 * held at the time of flush() (whether sucessfully filled or not) may be
2489 * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed
2490 * to return valid (STATUS_OK) buffers during this call, provided they are
2491 * succesfully filled.
2492 *
2493 * All requests currently in the HAL are expected to be returned as soon as
2494 * possible. Not-in-process requests should return errors immediately. Any
2495 * interruptible hardware blocks should be stopped, and any uninterruptible
2496 * blocks should be waited on.
2497 *
2498 * flush() should only return when there are no more outstanding buffers or
2499 * requests left in the HAL. The framework may call configure_streams (as
2500 * the HAL state is now quiesced) or may issue new requests.
2501 *
Zhijun He2dde4682014-01-09 09:11:49 -08002502 * Performance requirements:
2503 *
2504 * The HAL should return from this call in 100ms, and must return from this
2505 * call in 1000ms. And this call must not be blocked longer than pipeline
2506 * latency (see S7 for definition).
Alex Ray5f2fd852013-06-24 11:28:05 -07002507 *
2508 * Version information:
2509 *
2510 * only available if device version >= CAMERA_DEVICE_API_VERSION_3_1.
2511 *
2512 * Return values:
2513 *
2514 * 0: On a successful flush of the camera HAL.
2515 *
2516 * -EINVAL: If the input is malformed (the device is not valid).
2517 *
2518 * -ENODEV: If the camera device has encountered a serious error. After this
2519 * error is returned, only the close() method can be successfully
2520 * called by the framework.
2521 */
2522 int (*flush)(const struct camera3_device *);
2523
2524 /* reserved for future use */
2525 void *reserved[8];
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002526} camera3_device_ops_t;
2527
2528/**********************************************************************
2529 *
2530 * Camera device definition
2531 *
2532 */
2533typedef struct camera3_device {
2534 /**
2535 * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
2536 * device as implementing version 3.0 of the camera device HAL.
Zhijun He2dde4682014-01-09 09:11:49 -08002537 *
2538 * Performance requirements:
2539 *
2540 * common.open should return in 200ms, and must return in 500ms.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002541 */
2542 hw_device_t common;
2543 camera3_device_ops_t *ops;
2544 void *priv;
2545} camera3_device_t;
2546
2547__END_DECLS
2548
2549#endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */