blob: 2c47ef647bc1f47a6d02f43532d3b6f3f3f1fbf7 [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/**
Zhijun Heebdf1282015-01-16 16:44:40 -080024 * Camera device HAL 3.3 [ CAMERA_DEVICE_API_VERSION_3_3 ]
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080025 *
Eino-Ville Talvalab5459832014-09-09 16:42:27 -070026 * This is the current recommended version of the camera device HAL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080027 *
Eino-Ville Talvalab5459832014-09-09 16:42:27 -070028 * Supports the android.hardware.Camera API, and as of v3.2, the
29 * android.hardware.camera2 API in LIMITED or FULL modes.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080030 *
31 * Camera devices that support this version of the HAL must return
Zhijun Heebdf1282015-01-16 16:44:40 -080032 * CAMERA_DEVICE_API_VERSION_3_3 in camera_device_t.common.version and in
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080033 * camera_info_t.device_version (from camera_module_t.get_camera_info).
34 *
Zhijun Heebdf1282015-01-16 16:44:40 -080035 * CAMERA_DEVICE_API_VERSION_3_3:
36 * Camera modules that may contain version 3.3 devices must implement at
37 * least version 2.2 of the camera module interface (as defined by
38 * camera_module_t.common.module_api_version).
39 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080040 * CAMERA_DEVICE_API_VERSION_3_2:
41 * Camera modules that may contain version 3.2 devices must implement at
42 * least version 2.2 of the camera module interface (as defined by
43 * camera_module_t.common.module_api_version).
44 *
45 * <= CAMERA_DEVICE_API_VERSION_3_1:
46 * Camera modules that may contain version 3.1 (or 3.0) devices must
47 * implement at least version 2.0 of the camera module interface
48 * (as defined by camera_module_t.common.module_api_version).
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080049 *
50 * See camera_common.h for more versioning details.
51 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070052 * Documentation index:
53 * S1. Version history
54 * S2. Startup and operation sequencing
55 * S3. Operational modes
56 * S4. 3A modes and state machines
Eino-Ville Talvalab6059442013-04-29 15:26:16 -070057 * S5. Cropping
58 * S6. Error management
Zhijun He709e5872014-01-17 15:25:21 -080059 * S7. Key Performance Indicator (KPI) glossary
Zhijun Hebc358682014-01-23 14:42:54 -080060 * S8. Sample Use Cases
Ruben Brunk2d96c742014-03-18 13:39:17 -070061 * S9. Notes on Controls and Metadata
Zhijun Heebdf1282015-01-16 16:44:40 -080062 * S10. Reprocessing flow and controls
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070063 */
64
65/**
66 * S1. Version history:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080067 *
68 * 1.0: Initial Android camera HAL (Android 4.0) [camera.h]:
69 *
70 * - Converted from C++ CameraHardwareInterface abstraction layer.
71 *
72 * - Supports android.hardware.Camera API.
73 *
74 * 2.0: Initial release of expanded-capability HAL (Android 4.2) [camera2.h]:
75 *
76 * - Sufficient for implementing existing android.hardware.Camera API.
77 *
78 * - Allows for ZSL queue in camera service layer
79 *
80 * - Not tested for any new features such manual capture control, Bayer RAW
81 * capture, reprocessing of RAW data.
82 *
83 * 3.0: First revision of expanded-capability HAL:
84 *
85 * - Major version change since the ABI is completely different. No change to
86 * the required hardware capabilities or operational model from 2.0.
87 *
88 * - Reworked input request and stream queue interfaces: Framework calls into
89 * HAL with next request and stream buffers already dequeued. Sync framework
90 * support is included, necessary for efficient implementations.
91 *
92 * - Moved triggers into requests, most notifications into results.
93 *
94 * - Consolidated all callbacks into framework into one structure, and all
95 * setup methods into a single initialize() call.
96 *
97 * - Made stream configuration into a single call to simplify stream
98 * management. Bidirectional streams replace STREAM_FROM_STREAM construct.
99 *
100 * - Limited mode semantics for older/limited hardware devices.
Alex Ray2ce219a2013-06-14 15:09:30 -0700101 *
102 * 3.1: Minor revision of expanded-capability HAL:
103 *
104 * - configure_streams passes consumer usage flags to the HAL.
Alex Ray5f2fd852013-06-24 11:28:05 -0700105 *
106 * - flush call to drop all in-flight requests/buffers as fast as possible.
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800107 *
108 * 3.2: Minor revision of expanded-capability HAL:
109 *
110 * - Deprecates get_metadata_vendor_tag_ops. Please use get_vendor_tag_ops
111 * in camera_common.h instead.
Igor Murashkin78aa1262014-01-09 16:23:43 -0800112 *
113 * - register_stream_buffers deprecated. All gralloc buffers provided
114 * by framework to HAL in process_capture_request may be new at any time.
Igor Murashkin5df2f622014-01-10 14:18:45 -0800115 *
116 * - add partial result support. process_capture_result may be called
117 * multiple times with a subset of the available result before the full
118 * result is available.
Zhijun Hebc358682014-01-23 14:42:54 -0800119 *
120 * - add manual template to camera3_request_template. The applications may
121 * use this template to control the capture settings directly.
122 *
123 * - Rework the bidirectional and input stream specifications.
124 *
Zhijun Heceac9e32014-02-05 20:49:45 -0800125 * - change the input buffer return path. The buffer is returned in
126 * process_capture_result instead of process_capture_request.
127 *
Zhijun Heebdf1282015-01-16 16:44:40 -0800128 * 3.3: Minor revision of expanded-capability HAL:
129 *
130 * - OPAQUE and YUV reprocessing API updates.
Eino-Ville Talvala453c7902015-03-06 13:22:03 -0800131 *
132 * - Basic support for depth output buffers
133 *
134 * - Addition of data_space field to camera3_stream_t.
135 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800136 */
137
138/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700139 * S2. Startup and general expected operation sequence:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800140 *
141 * 1. Framework calls camera_module_t->common.open(), which returns a
142 * hardware_device_t structure.
143 *
144 * 2. Framework inspects the hardware_device_t->version field, and instantiates
145 * the appropriate handler for that version of the camera hardware device. In
146 * case the version is CAMERA_DEVICE_API_VERSION_3_0, the device is cast to
147 * a camera3_device_t.
148 *
149 * 3. Framework calls camera3_device_t->ops->initialize() with the framework
150 * callback function pointers. This will only be called this one time after
151 * open(), before any other functions in the ops structure are called.
152 *
153 * 4. The framework calls camera3_device_t->ops->configure_streams() with a list
154 * of input/output streams to the HAL device.
155 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800156 * 5. <= CAMERA_DEVICE_API_VERSION_3_1:
157 *
158 * The framework allocates gralloc buffers and calls
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800159 * camera3_device_t->ops->register_stream_buffers() for at least one of the
160 * output streams listed in configure_streams. The same stream is registered
161 * only once.
162 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800163 * >= CAMERA_DEVICE_API_VERSION_3_2:
164 *
165 * camera3_device_t->ops->register_stream_buffers() is not called and must
166 * be NULL.
167 *
168 * 6. The framework requests default settings for some number of use cases with
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800169 * calls to camera3_device_t->ops->construct_default_request_settings(). This
170 * may occur any time after step 3.
171 *
172 * 7. The framework constructs and sends the first capture request to the HAL,
173 * with settings based on one of the sets of default settings, and with at
174 * least one output stream, which has been registered earlier by the
175 * framework. This is sent to the HAL with
176 * camera3_device_t->ops->process_capture_request(). The HAL must block the
177 * return of this call until it is ready for the next request to be sent.
178 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800179 * >= CAMERA_DEVICE_API_VERSION_3_2:
180 *
181 * The buffer_handle_t provided in the camera3_stream_buffer_t array
182 * in the camera3_capture_request_t may be new and never-before-seen
183 * by the HAL on any given new request.
184 *
185 * 8. The framework continues to submit requests, and call
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800186 * construct_default_request_settings to get default settings buffers for
187 * other use cases.
188 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800189 * <= CAMERA_DEVICE_API_VERSION_3_1:
190 *
191 * The framework may call register_stream_buffers() at this time for
192 * not-yet-registered streams.
193 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800194 * 9. When the capture of a request begins (sensor starts exposing for the
195 * capture), the HAL calls camera3_callback_ops_t->notify() with the SHUTTER
196 * event, including the frame number and the timestamp for start of exposure.
Igor Murashkin5df2f622014-01-10 14:18:45 -0800197 *
198 * <= CAMERA_DEVICE_API_VERSION_3_1:
199 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -0700200 * This notify call must be made before the first call to
201 * process_capture_result() for that frame number.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800202 *
Igor Murashkin5df2f622014-01-10 14:18:45 -0800203 * >= CAMERA_DEVICE_API_VERSION_3_2:
204 *
205 * The camera3_callback_ops_t->notify() call with the SHUTTER event should
206 * be made as early as possible since the framework will be unable to
207 * deliver gralloc buffers to the application layer (for that frame) until
208 * it has a valid timestamp for the start of exposure.
209 *
210 * Both partial metadata results and the gralloc buffers may be sent to the
211 * framework at any time before or after the SHUTTER event.
212 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800213 * 10. After some pipeline delay, the HAL begins to return completed captures to
214 * the framework with camera3_callback_ops_t->process_capture_result(). These
215 * are returned in the same order as the requests were submitted. Multiple
216 * requests can be in flight at once, depending on the pipeline depth of the
217 * camera HAL device.
218 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800219 * >= CAMERA_DEVICE_API_VERSION_3_2:
220 *
221 * Once a buffer is returned by process_capture_result as part of the
222 * camera3_stream_buffer_t array, and the fence specified by release_fence
223 * has been signaled (this is a no-op for -1 fences), the ownership of that
224 * buffer is considered to be transferred back to the framework. After that,
225 * the HAL must no longer retain that particular buffer, and the
226 * framework may clean up the memory for it immediately.
227 *
Igor Murashkin5df2f622014-01-10 14:18:45 -0800228 * process_capture_result may be called multiple times for a single frame,
229 * each time with a new disjoint piece of metadata and/or set of gralloc
230 * buffers. The framework will accumulate these partial metadata results
231 * into one result.
232 *
233 * In particular, it is legal for a process_capture_result to be called
234 * simultaneously for both a frame N and a frame N+1 as long as the
Zhijun Heceac9e32014-02-05 20:49:45 -0800235 * above rule holds for gralloc buffers (both input and output).
Igor Murashkin5df2f622014-01-10 14:18:45 -0800236 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800237 * 11. After some time, the framework may stop submitting new requests, wait for
238 * the existing captures to complete (all buffers filled, all results
239 * returned), and then call configure_streams() again. This resets the camera
240 * hardware and pipeline for a new set of input/output streams. Some streams
241 * may be reused from the previous configuration; if these streams' buffers
242 * had already been registered with the HAL, they will not be registered
243 * again. The framework then continues from step 7, if at least one
244 * registered output stream remains (otherwise, step 5 is required first).
245 *
246 * 12. Alternatively, the framework may call camera3_device_t->common->close()
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -0800247 * to end the camera session. This may be called at any time when no other
248 * calls from the framework are active, although the call may block until all
249 * in-flight captures have completed (all results returned, all buffers
250 * filled). After the close call returns, no more calls to the
251 * camera3_callback_ops_t functions are allowed from the HAL. Once the
252 * close() call is underway, the framework may not call any other HAL device
253 * functions.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800254 *
255 * 13. In case of an error or other asynchronous event, the HAL must call
256 * camera3_callback_ops_t->notify() with the appropriate error/event
257 * message. After returning from a fatal device-wide error notification, the
258 * HAL should act as if close() had been called on it. However, the HAL must
259 * either cancel or complete all outstanding captures before calling
260 * notify(), so that once notify() is called with a fatal error, the
261 * framework will not receive further callbacks from the device. Methods
262 * besides close() should return -ENODEV or NULL after the notify() method
263 * returns from a fatal error message.
264 */
265
266/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700267 * S3. Operational modes:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800268 *
269 * The camera 3 HAL device can implement one of two possible operational modes;
270 * limited and full. Full support is expected from new higher-end
271 * devices. Limited mode has hardware requirements roughly in line with those
272 * for a camera HAL device v1 implementation, and is expected from older or
273 * inexpensive devices. Full is a strict superset of limited, and they share the
274 * same essential operational flow, as documented above.
275 *
276 * The HAL must indicate its level of support with the
277 * android.info.supportedHardwareLevel static metadata entry, with 0 indicating
278 * limited mode, and 1 indicating full mode support.
279 *
280 * Roughly speaking, limited-mode devices do not allow for application control
281 * of capture settings (3A control only), high-rate capture of high-resolution
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700282 * images, raw sensor readout, or support for YUV output streams above maximum
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800283 * recording resolution (JPEG only for large images).
284 *
285 * ** Details of limited mode behavior:
286 *
287 * - Limited-mode devices do not need to implement accurate synchronization
288 * between capture request settings and the actual image data
289 * captured. Instead, changes to settings may take effect some time in the
290 * future, and possibly not for the same output frame for each settings
291 * entry. Rapid changes in settings may result in some settings never being
292 * used for a capture. However, captures that include high-resolution output
293 * buffers ( > 1080p ) have to use the settings as specified (but see below
294 * for processing rate).
295 *
296 * - Limited-mode devices do not need to support most of the
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700297 * settings/result/static info metadata. Specifically, only the following settings
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800298 * are expected to be consumed or produced by a limited-mode HAL device:
299 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700300 * android.control.aeAntibandingMode (controls and dynamic)
301 * android.control.aeExposureCompensation (controls and dynamic)
302 * android.control.aeLock (controls and dynamic)
303 * android.control.aeMode (controls and dynamic)
304 * android.control.aeRegions (controls and dynamic)
305 * android.control.aeTargetFpsRange (controls and dynamic)
306 * android.control.aePrecaptureTrigger (controls and dynamic)
307 * android.control.afMode (controls and dynamic)
308 * android.control.afRegions (controls and dynamic)
309 * android.control.awbLock (controls and dynamic)
310 * android.control.awbMode (controls and dynamic)
311 * android.control.awbRegions (controls and dynamic)
312 * android.control.captureIntent (controls and dynamic)
313 * android.control.effectMode (controls and dynamic)
314 * android.control.mode (controls and dynamic)
315 * android.control.sceneMode (controls and dynamic)
316 * android.control.videoStabilizationMode (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800317 * android.control.aeAvailableAntibandingModes (static)
318 * android.control.aeAvailableModes (static)
319 * android.control.aeAvailableTargetFpsRanges (static)
320 * android.control.aeCompensationRange (static)
321 * android.control.aeCompensationStep (static)
322 * android.control.afAvailableModes (static)
323 * android.control.availableEffects (static)
324 * android.control.availableSceneModes (static)
325 * android.control.availableVideoStabilizationModes (static)
326 * android.control.awbAvailableModes (static)
327 * android.control.maxRegions (static)
328 * android.control.sceneModeOverrides (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800329 * android.control.aeState (dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800330 * android.control.afState (dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800331 * android.control.awbState (dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800332 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700333 * android.flash.mode (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800334 * android.flash.info.available (static)
335 *
336 * android.info.supportedHardwareLevel (static)
337 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700338 * android.jpeg.gpsCoordinates (controls and dynamic)
339 * android.jpeg.gpsProcessingMethod (controls and dynamic)
340 * android.jpeg.gpsTimestamp (controls and dynamic)
341 * android.jpeg.orientation (controls and dynamic)
342 * android.jpeg.quality (controls and dynamic)
343 * android.jpeg.thumbnailQuality (controls and dynamic)
344 * android.jpeg.thumbnailSize (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800345 * android.jpeg.availableThumbnailSizes (static)
346 * android.jpeg.maxSize (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800347 *
348 * android.lens.info.minimumFocusDistance (static)
349 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700350 * android.request.id (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800351 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700352 * android.scaler.cropRegion (controls and dynamic)
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -0800353 * android.scaler.availableStreamConfigurations (static)
354 * android.scaler.availableMinFrameDurations (static)
355 * android.scaler.availableStallDurations (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800356 * android.scaler.availableMaxDigitalZoom (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800357 * android.scaler.maxDigitalZoom (static)
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700358 * android.scaler.croppingType (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800359 *
360 * android.sensor.orientation (static)
361 * android.sensor.timestamp (dynamic)
362 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700363 * android.statistics.faceDetectMode (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800364 * android.statistics.info.availableFaceDetectModes (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800365 * android.statistics.faceIds (dynamic)
366 * android.statistics.faceLandmarks (dynamic)
367 * android.statistics.faceRectangles (dynamic)
368 * android.statistics.faceScores (dynamic)
369 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700370 * android.sync.frameNumber (dynamic)
371 * android.sync.maxLatency (static)
372 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800373 * - Captures in limited mode that include high-resolution (> 1080p) output
374 * buffers may block in process_capture_request() until all the output buffers
375 * have been filled. A full-mode HAL device must process sequences of
376 * high-resolution requests at the rate indicated in the static metadata for
377 * that pixel format. The HAL must still call process_capture_result() to
378 * provide the output; the framework must simply be prepared for
379 * process_capture_request() to block until after process_capture_result() for
380 * that request completes for high-resolution captures for limited-mode
381 * devices.
382 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700383 * - Full-mode devices must support below additional capabilities:
384 * - 30fps at maximum resolution is preferred, more than 20fps is required.
385 * - Per frame control (android.sync.maxLatency == PER_FRAME_CONTROL).
386 * - Sensor manual control metadata. See MANUAL_SENSOR defined in
387 * android.request.availableCapabilities.
388 * - Post-processing manual control metadata. See MANUAL_POST_PROCESSING defined
389 * in android.request.availableCapabilities.
390 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800391 */
392
393/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700394 * S4. 3A modes and state machines:
395 *
396 * While the actual 3A algorithms are up to the HAL implementation, a high-level
397 * state machine description is defined by the HAL interface, to allow the HAL
398 * device and the framework to communicate about the current state of 3A, and to
399 * trigger 3A events.
400 *
401 * When the device is opened, all the individual 3A states must be
402 * STATE_INACTIVE. Stream configuration does not reset 3A. For example, locked
403 * focus must be maintained across the configure() call.
404 *
405 * Triggering a 3A action involves simply setting the relevant trigger entry in
406 * the settings for the next request to indicate start of trigger. For example,
407 * the trigger for starting an autofocus scan is setting the entry
408 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTROL_AF_TRIGGER_START for one
409 * request, and cancelling an autofocus scan is triggered by setting
410 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTRL_AF_TRIGGER_CANCEL. Otherwise,
411 * the entry will not exist, or be set to ANDROID_CONTROL_AF_TRIGGER_IDLE. Each
412 * request with a trigger entry set to a non-IDLE value will be treated as an
413 * independent triggering event.
414 *
415 * At the top level, 3A is controlled by the ANDROID_CONTROL_MODE setting, which
416 * selects between no 3A (ANDROID_CONTROL_MODE_OFF), normal AUTO mode
417 * (ANDROID_CONTROL_MODE_AUTO), and using the scene mode setting
418 * (ANDROID_CONTROL_USE_SCENE_MODE).
419 *
420 * - In OFF mode, each of the individual AE/AF/AWB modes are effectively OFF,
421 * and none of the capture controls may be overridden by the 3A routines.
422 *
423 * - In AUTO mode, Auto-focus, auto-exposure, and auto-whitebalance all run
424 * their own independent algorithms, and have their own mode, state, and
425 * trigger metadata entries, as listed in the next section.
426 *
427 * - In USE_SCENE_MODE, the value of the ANDROID_CONTROL_SCENE_MODE entry must
428 * be used to determine the behavior of 3A routines. In SCENE_MODEs other than
429 * FACE_PRIORITY, the HAL must override the values of
430 * ANDROId_CONTROL_AE/AWB/AF_MODE to be the mode it prefers for the selected
431 * SCENE_MODE. For example, the HAL may prefer SCENE_MODE_NIGHT to use
432 * CONTINUOUS_FOCUS AF mode. Any user selection of AE/AWB/AF_MODE when scene
433 * must be ignored for these scene modes.
434 *
435 * - For SCENE_MODE_FACE_PRIORITY, the AE/AWB/AF_MODE controls work as in
436 * ANDROID_CONTROL_MODE_AUTO, but the 3A routines must bias toward metering
437 * and focusing on any detected faces in the scene.
438 *
439 * S4.1. Auto-focus settings and result entries:
440 *
441 * Main metadata entries:
442 *
443 * ANDROID_CONTROL_AF_MODE: Control for selecting the current autofocus
444 * mode. Set by the framework in the request settings.
445 *
446 * AF_MODE_OFF: AF is disabled; the framework/app directly controls lens
447 * position.
448 *
449 * AF_MODE_AUTO: Single-sweep autofocus. No lens movement unless AF is
450 * triggered.
451 *
452 * AF_MODE_MACRO: Single-sweep up-close autofocus. No lens movement unless
453 * AF is triggered.
454 *
455 * AF_MODE_CONTINUOUS_VIDEO: Smooth continuous focusing, for recording
456 * video. Triggering immediately locks focus in current
457 * position. Canceling resumes cotinuous focusing.
458 *
459 * AF_MODE_CONTINUOUS_PICTURE: Fast continuous focusing, for
460 * zero-shutter-lag still capture. Triggering locks focus once currently
461 * active sweep concludes. Canceling resumes continuous focusing.
462 *
463 * AF_MODE_EDOF: Advanced extended depth of field focusing. There is no
464 * autofocus scan, so triggering one or canceling one has no effect.
465 * Images are focused automatically by the HAL.
466 *
467 * ANDROID_CONTROL_AF_STATE: Dynamic metadata describing the current AF
468 * algorithm state, reported by the HAL in the result metadata.
469 *
470 * AF_STATE_INACTIVE: No focusing has been done, or algorithm was
471 * reset. Lens is not moving. Always the state for MODE_OFF or MODE_EDOF.
472 * When the device is opened, it must start in this state.
473 *
474 * AF_STATE_PASSIVE_SCAN: A continuous focus algorithm is currently scanning
475 * for good focus. The lens is moving.
476 *
477 * AF_STATE_PASSIVE_FOCUSED: A continuous focus algorithm believes it is
478 * well focused. The lens is not moving. The HAL may spontaneously leave
479 * this state.
480 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700481 * AF_STATE_PASSIVE_UNFOCUSED: A continuous focus algorithm believes it is
482 * not well focused. The lens is not moving. The HAL may spontaneously
483 * leave this state.
484 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700485 * AF_STATE_ACTIVE_SCAN: A scan triggered by the user is underway.
486 *
487 * AF_STATE_FOCUSED_LOCKED: The AF algorithm believes it is focused. The
488 * lens is not moving.
489 *
490 * AF_STATE_NOT_FOCUSED_LOCKED: The AF algorithm has been unable to
491 * focus. The lens is not moving.
492 *
493 * ANDROID_CONTROL_AF_TRIGGER: Control for starting an autofocus scan, the
494 * meaning of which is mode- and state- dependent. Set by the framework in
495 * the request settings.
496 *
497 * AF_TRIGGER_IDLE: No current trigger.
498 *
499 * AF_TRIGGER_START: Trigger start of AF scan. Effect is mode and state
500 * dependent.
501 *
502 * AF_TRIGGER_CANCEL: Cancel current AF scan if any, and reset algorithm to
503 * default.
504 *
505 * Additional metadata entries:
506 *
507 * ANDROID_CONTROL_AF_REGIONS: Control for selecting the regions of the FOV
508 * that should be used to determine good focus. This applies to all AF
509 * modes that scan for focus. Set by the framework in the request
510 * settings.
511 *
512 * S4.2. Auto-exposure settings and result entries:
513 *
514 * Main metadata entries:
515 *
516 * ANDROID_CONTROL_AE_MODE: Control for selecting the current auto-exposure
517 * mode. Set by the framework in the request settings.
518 *
519 * AE_MODE_OFF: Autoexposure is disabled; the user controls exposure, gain,
520 * frame duration, and flash.
521 *
522 * AE_MODE_ON: Standard autoexposure, with flash control disabled. User may
523 * set flash to fire or to torch mode.
524 *
525 * AE_MODE_ON_AUTO_FLASH: Standard autoexposure, with flash on at HAL's
526 * discretion for precapture and still capture. User control of flash
527 * disabled.
528 *
529 * AE_MODE_ON_ALWAYS_FLASH: Standard autoexposure, with flash always fired
530 * for capture, and at HAL's discretion for precapture.. User control of
531 * flash disabled.
532 *
533 * AE_MODE_ON_AUTO_FLASH_REDEYE: Standard autoexposure, with flash on at
534 * HAL's discretion for precapture and still capture. Use a flash burst
535 * at end of precapture sequence to reduce redeye in the final
536 * picture. User control of flash disabled.
537 *
538 * ANDROID_CONTROL_AE_STATE: Dynamic metadata describing the current AE
539 * algorithm state, reported by the HAL in the result metadata.
540 *
541 * AE_STATE_INACTIVE: Initial AE state after mode switch. When the device is
542 * opened, it must start in this state.
543 *
544 * AE_STATE_SEARCHING: AE is not converged to a good value, and is adjusting
545 * exposure parameters.
546 *
547 * AE_STATE_CONVERGED: AE has found good exposure values for the current
548 * scene, and the exposure parameters are not changing. HAL may
549 * spontaneously leave this state to search for better solution.
550 *
551 * AE_STATE_LOCKED: AE has been locked with the AE_LOCK control. Exposure
552 * values are not changing.
553 *
554 * AE_STATE_FLASH_REQUIRED: The HAL has converged exposure, but believes
555 * flash is required for a sufficiently bright picture. Used for
556 * determining if a zero-shutter-lag frame can be used.
557 *
558 * AE_STATE_PRECAPTURE: The HAL is in the middle of a precapture
559 * sequence. Depending on AE mode, this mode may involve firing the
560 * flash for metering, or a burst of flash pulses for redeye reduction.
561 *
562 * ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER: Control for starting a metering
563 * sequence before capturing a high-quality image. Set by the framework in
564 * the request settings.
565 *
566 * PRECAPTURE_TRIGGER_IDLE: No current trigger.
567 *
568 * PRECAPTURE_TRIGGER_START: Start a precapture sequence. The HAL should
569 * use the subsequent requests to measure good exposure/white balance
570 * for an upcoming high-resolution capture.
571 *
572 * Additional metadata entries:
573 *
574 * ANDROID_CONTROL_AE_LOCK: Control for locking AE controls to their current
575 * values
576 *
577 * ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION: Control for adjusting AE
578 * algorithm target brightness point.
579 *
580 * ANDROID_CONTROL_AE_TARGET_FPS_RANGE: Control for selecting the target frame
581 * rate range for the AE algorithm. The AE routine cannot change the frame
582 * rate to be outside these bounds.
583 *
584 * ANDROID_CONTROL_AE_REGIONS: Control for selecting the regions of the FOV
585 * that should be used to determine good exposure levels. This applies to
586 * all AE modes besides OFF.
587 *
588 * S4.3. Auto-whitebalance settings and result entries:
589 *
590 * Main metadata entries:
591 *
592 * ANDROID_CONTROL_AWB_MODE: Control for selecting the current white-balance
593 * mode.
594 *
595 * AWB_MODE_OFF: Auto-whitebalance is disabled. User controls color matrix.
596 *
597 * AWB_MODE_AUTO: Automatic white balance is enabled; 3A controls color
598 * transform, possibly using more complex transforms than a simple
599 * matrix.
600 *
601 * AWB_MODE_INCANDESCENT: Fixed white balance settings good for indoor
602 * incandescent (tungsten) lighting, roughly 2700K.
603 *
604 * AWB_MODE_FLUORESCENT: Fixed white balance settings good for fluorescent
605 * lighting, roughly 5000K.
606 *
607 * AWB_MODE_WARM_FLUORESCENT: Fixed white balance settings good for
608 * fluorescent lighting, roughly 3000K.
609 *
610 * AWB_MODE_DAYLIGHT: Fixed white balance settings good for daylight,
611 * roughly 5500K.
612 *
613 * AWB_MODE_CLOUDY_DAYLIGHT: Fixed white balance settings good for clouded
614 * daylight, roughly 6500K.
615 *
616 * AWB_MODE_TWILIGHT: Fixed white balance settings good for
617 * near-sunset/sunrise, roughly 15000K.
618 *
619 * AWB_MODE_SHADE: Fixed white balance settings good for areas indirectly
620 * lit by the sun, roughly 7500K.
621 *
622 * ANDROID_CONTROL_AWB_STATE: Dynamic metadata describing the current AWB
623 * algorithm state, reported by the HAL in the result metadata.
624 *
625 * AWB_STATE_INACTIVE: Initial AWB state after mode switch. When the device
626 * is opened, it must start in this state.
627 *
628 * AWB_STATE_SEARCHING: AWB is not converged to a good value, and is
629 * changing color adjustment parameters.
630 *
631 * AWB_STATE_CONVERGED: AWB has found good color adjustment values for the
632 * current scene, and the parameters are not changing. HAL may
633 * spontaneously leave this state to search for better solution.
634 *
635 * AWB_STATE_LOCKED: AWB has been locked with the AWB_LOCK control. Color
636 * adjustment values are not changing.
637 *
638 * Additional metadata entries:
639 *
640 * ANDROID_CONTROL_AWB_LOCK: Control for locking AWB color adjustments to
641 * their current values.
642 *
643 * ANDROID_CONTROL_AWB_REGIONS: Control for selecting the regions of the FOV
644 * that should be used to determine good color balance. This applies only
645 * to auto-WB mode.
646 *
647 * S4.4. General state machine transition notes
648 *
649 * Switching between AF, AE, or AWB modes always resets the algorithm's state
650 * to INACTIVE. Similarly, switching between CONTROL_MODE or
651 * CONTROL_SCENE_MODE if CONTROL_MODE == USE_SCENE_MODE resets all the
652 * algorithm states to INACTIVE.
653 *
654 * The tables below are per-mode.
655 *
656 * S4.5. AF state machines
657 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700658 * when enabling AF or changing AF mode
659 *| state | trans. cause | new state | notes |
660 *+--------------------+---------------+--------------------+------------------+
661 *| Any | AF mode change| INACTIVE | |
662 *+--------------------+---------------+--------------------+------------------+
663 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700664 * mode = AF_MODE_OFF or AF_MODE_EDOF
665 *| state | trans. cause | new state | notes |
666 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700667 *| INACTIVE | | INACTIVE | Never changes |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700668 *+--------------------+---------------+--------------------+------------------+
669 *
670 * mode = AF_MODE_AUTO or AF_MODE_MACRO
671 *| state | trans. cause | new state | notes |
672 *+--------------------+---------------+--------------------+------------------+
673 *| INACTIVE | AF_TRIGGER | ACTIVE_SCAN | Start AF sweep |
674 *| | | | Lens now moving |
675 *+--------------------+---------------+--------------------+------------------+
676 *| ACTIVE_SCAN | AF sweep done | FOCUSED_LOCKED | If AF successful |
677 *| | | | Lens now locked |
678 *+--------------------+---------------+--------------------+------------------+
679 *| ACTIVE_SCAN | AF sweep done | NOT_FOCUSED_LOCKED | If AF successful |
680 *| | | | Lens now locked |
681 *+--------------------+---------------+--------------------+------------------+
682 *| ACTIVE_SCAN | AF_CANCEL | INACTIVE | Cancel/reset AF |
683 *| | | | Lens now locked |
684 *+--------------------+---------------+--------------------+------------------+
685 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
686 *+--------------------+---------------+--------------------+------------------+
687 *| FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
688 *| | | | Lens now moving |
689 *+--------------------+---------------+--------------------+------------------+
690 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
691 *+--------------------+---------------+--------------------+------------------+
692 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
693 *| | | | Lens now moving |
694 *+--------------------+---------------+--------------------+------------------+
695 *| All states | mode change | INACTIVE | |
696 *+--------------------+---------------+--------------------+------------------+
697 *
698 * mode = AF_MODE_CONTINUOUS_VIDEO
699 *| state | trans. cause | new state | notes |
700 *+--------------------+---------------+--------------------+------------------+
701 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
702 *| | new scan | | Lens now moving |
703 *+--------------------+---------------+--------------------+------------------+
704 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
705 *| | | | Lens now locked |
706 *+--------------------+---------------+--------------------+------------------+
707 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
708 *| | current scan | | Lens now locked |
709 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700710 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
711 *| | current scan | | Lens now locked |
712 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700713 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
714 *| | | | if focus is good |
715 *| | | | Lens now locked |
716 *+--------------------+---------------+--------------------+------------------+
717 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
718 *| | | | if focus is bad |
719 *| | | | Lens now locked |
720 *+--------------------+---------------+--------------------+------------------+
721 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
722 *| | | | position |
723 *| | | | Lens now locked |
724 *+--------------------+---------------+--------------------+------------------+
725 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
726 *| | new scan | | Lens now moving |
727 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700728 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
729 *| | new scan | | Lens now moving |
730 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700731 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700732 *| | | | Lens now locked |
733 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700734 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700735 *| | | | Lens now locked |
736 *+--------------------+---------------+--------------------+------------------+
737 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
738 *+--------------------+---------------+--------------------+------------------+
739 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
740 *+--------------------+---------------+--------------------+------------------+
741 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
742 *+--------------------+---------------+--------------------+------------------+
743 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
744 *+--------------------+---------------+--------------------+------------------+
745 *
746 * mode = AF_MODE_CONTINUOUS_PICTURE
747 *| state | trans. cause | new state | notes |
748 *+--------------------+---------------+--------------------+------------------+
749 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
750 *| | new scan | | Lens now moving |
751 *+--------------------+---------------+--------------------+------------------+
752 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
753 *| | | | Lens now locked |
754 *+--------------------+---------------+--------------------+------------------+
755 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
756 *| | current scan | | Lens now locked |
757 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700758 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
759 *| | current scan | | Lens now locked |
760 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700761 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Eventual trans. |
762 *| | | | once focus good |
763 *| | | | Lens now locked |
764 *+--------------------+---------------+--------------------+------------------+
765 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Eventual trans. |
766 *| | | | if cannot focus |
767 *| | | | Lens now locked |
768 *+--------------------+---------------+--------------------+------------------+
769 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
770 *| | | | position |
771 *| | | | Lens now locked |
772 *+--------------------+---------------+--------------------+------------------+
773 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
774 *| | new scan | | Lens now moving |
775 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700776 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
777 *| | new scan | | Lens now moving |
778 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700779 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700780 *| | | | Lens now locked |
781 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700782 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700783 *| | | | Lens now locked |
784 *+--------------------+---------------+--------------------+------------------+
785 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
786 *+--------------------+---------------+--------------------+------------------+
787 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
788 *+--------------------+---------------+--------------------+------------------+
789 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
790 *+--------------------+---------------+--------------------+------------------+
791 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
792 *+--------------------+---------------+--------------------+------------------+
793 *
794 * S4.6. AE and AWB state machines
795 *
796 * The AE and AWB state machines are mostly identical. AE has additional
797 * FLASH_REQUIRED and PRECAPTURE states. So rows below that refer to those two
798 * states should be ignored for the AWB state machine.
799 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700800 * when enabling AE/AWB or changing AE/AWB mode
801 *| state | trans. cause | new state | notes |
802 *+--------------------+---------------+--------------------+------------------+
803 *| Any | mode change | INACTIVE | |
804 *+--------------------+---------------+--------------------+------------------+
805 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700806 * mode = AE_MODE_OFF / AWB mode not AUTO
807 *| state | trans. cause | new state | notes |
808 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700809 *| INACTIVE | | INACTIVE | AE/AWB disabled |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700810 *+--------------------+---------------+--------------------+------------------+
811 *
812 * mode = AE_MODE_ON_* / AWB_MODE_AUTO
813 *| state | trans. cause | new state | notes |
814 *+--------------------+---------------+--------------------+------------------+
815 *| INACTIVE | HAL initiates | SEARCHING | |
816 *| | AE/AWB scan | | |
817 *+--------------------+---------------+--------------------+------------------+
818 *| INACTIVE | AE/AWB_LOCK | LOCKED | values locked |
819 *| | on | | |
820 *+--------------------+---------------+--------------------+------------------+
821 *| SEARCHING | HAL finishes | CONVERGED | good values, not |
822 *| | AE/AWB scan | | changing |
823 *+--------------------+---------------+--------------------+------------------+
824 *| SEARCHING | HAL finishes | FLASH_REQUIRED | converged but too|
825 *| | AE scan | | dark w/o flash |
826 *+--------------------+---------------+--------------------+------------------+
827 *| SEARCHING | AE/AWB_LOCK | LOCKED | values locked |
828 *| | on | | |
829 *+--------------------+---------------+--------------------+------------------+
830 *| CONVERGED | HAL initiates | SEARCHING | values locked |
831 *| | AE/AWB scan | | |
832 *+--------------------+---------------+--------------------+------------------+
833 *| CONVERGED | AE/AWB_LOCK | LOCKED | values locked |
834 *| | on | | |
835 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala73dba5e2013-05-21 16:29:14 -0700836 *| FLASH_REQUIRED | HAL initiates | SEARCHING | values locked |
837 *| | AE/AWB scan | | |
838 *+--------------------+---------------+--------------------+------------------+
839 *| FLASH_REQUIRED | AE/AWB_LOCK | LOCKED | values locked |
840 *| | on | | |
841 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700842 *| LOCKED | AE/AWB_LOCK | SEARCHING | values not good |
843 *| | off | | after unlock |
844 *+--------------------+---------------+--------------------+------------------+
845 *| LOCKED | AE/AWB_LOCK | CONVERGED | values good |
846 *| | off | | after unlock |
847 *+--------------------+---------------+--------------------+------------------+
848 *| LOCKED | AE_LOCK | FLASH_REQUIRED | exposure good, |
849 *| | off | | but too dark |
850 *+--------------------+---------------+--------------------+------------------+
851 *| All AE states | PRECAPTURE_ | PRECAPTURE | Start precapture |
852 *| | START | | sequence |
853 *+--------------------+---------------+--------------------+------------------+
854 *| PRECAPTURE | Sequence done.| CONVERGED | Ready for high- |
855 *| | AE_LOCK off | | quality capture |
856 *+--------------------+---------------+--------------------+------------------+
857 *| PRECAPTURE | Sequence done.| LOCKED | Ready for high- |
858 *| | AE_LOCK on | | quality capture |
859 *+--------------------+---------------+--------------------+------------------+
860 *
861 */
862
863/**
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700864 * S5. Cropping:
865 *
866 * Cropping of the full pixel array (for digital zoom and other use cases where
867 * a smaller FOV is desirable) is communicated through the
868 * ANDROID_SCALER_CROP_REGION setting. This is a per-request setting, and can
869 * change on a per-request basis, which is critical for implementing smooth
870 * digital zoom.
871 *
872 * The region is defined as a rectangle (x, y, width, height), with (x, y)
873 * describing the top-left corner of the rectangle. The rectangle is defined on
874 * the coordinate system of the sensor active pixel array, with (0,0) being the
875 * top-left pixel of the active pixel array. Therefore, the width and height
876 * cannot be larger than the dimensions reported in the
877 * ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY static info field. The minimum allowed
878 * width and height are reported by the HAL through the
879 * ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes the
880 * maximum supported zoom factor. Therefore, the minimum crop region width and
881 * height are:
882 *
883 * {width, height} =
884 * { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
885 * ANDROID_SCALER_MAX_DIGITAL_ZOOM),
886 * floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
887 * ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
888 *
889 * If the crop region needs to fulfill specific requirements (for example, it
890 * needs to start on even coordinates, and its width/height needs to be even),
891 * the HAL must do the necessary rounding and write out the final crop region
892 * used in the output result metadata. Similarly, if the HAL implements video
893 * stabilization, it must adjust the result crop region to describe the region
894 * actually included in the output after video stabilization is applied. In
895 * general, a camera-using application must be able to determine the field of
896 * view it is receiving based on the crop region, the dimensions of the image
897 * sensor, and the lens focal length.
898 *
Zhijun Hef1ee67e2014-05-21 11:18:51 -0700899 * It is assumed that the cropping is applied after raw to other color space
900 * conversion. Raw streams (RAW16 and RAW_OPAQUE) don't have this conversion stage,
901 * and are not croppable. Therefore, the crop region must be ignored by the HAL
902 * for raw streams.
903 *
904 * Since the crop region applies to all non-raw streams, which may have different aspect
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700905 * ratios than the crop region, the exact sensor region used for each stream may
906 * be smaller than the crop region. Specifically, each stream should maintain
907 * square pixels and its aspect ratio by minimally further cropping the defined
908 * crop region. If the stream's aspect ratio is wider than the crop region, the
909 * stream should be further cropped vertically, and if the stream's aspect ratio
910 * is narrower than the crop region, the stream should be further cropped
911 * horizontally.
912 *
913 * In all cases, the stream crop must be centered within the full crop region,
914 * and each stream is only either cropped horizontally or vertical relative to
915 * the full crop region, never both.
916 *
917 * For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
918 * 1280x720 stream (16:9 aspect), below demonstrates the expected output regions
919 * for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
920 * 1500 pixel array) sensor.
921 *
922 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
923 *
924 * 640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)
925 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
926 *
927 * 0 1000 2000
928 * +---------+---------+---------+----------+
929 * | Active pixel array |
930 * | |
931 * | |
932 * + +-------------------+ + 375
933 * | | | |
934 * | O===================O |
935 * | I 1280x720 stream I |
936 * + I I + 750
937 * | I I |
938 * | O===================O |
939 * | | | |
940 * + +-------------------+ + 1125
941 * | Crop region, 640x480 stream |
942 * | |
943 * | |
944 * +---------+---------+---------+----------+ 1500
945 *
946 * Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)
947 *
948 * 640x480 stream crop: (666, 375, 1000, 750) (marked with =)
949 * 1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
950 *
951 * 0 1000 2000
952 * +---------+---------+---------+----------+
953 * | Active pixel array |
954 * | |
955 * | |
956 * + +---O==================O---+ + 375
957 * | | I 640x480 stream I | |
958 * | | I I | |
959 * | | I I | |
960 * + | I I | + 750
961 * | | I I | |
962 * | | I I | |
963 * | | I I | |
964 * + +---O==================O---+ + 1125
965 * | Crop region, 1280x720 stream |
966 * | |
967 * | |
968 * +---------+---------+---------+----------+ 1500
969 *
970 * Crop region: (500, 375, 750, 750) (1:1 aspect ratio)
971 *
972 * 640x480 stream crop: (500, 469, 750, 562) (marked with =)
973 * 1280x720 stream crop: (500, 543, 750, 414) (marged with #)
974 *
975 * 0 1000 2000
976 * +---------+---------+---------+----------+
977 * | Active pixel array |
978 * | |
979 * | |
980 * + +--------------+ + 375
981 * | O==============O |
982 * | ################ |
983 * | # # |
984 * + # # + 750
985 * | # # |
986 * | ################ 1280x720 |
987 * | O==============O 640x480 |
988 * + +--------------+ + 1125
989 * | Crop region |
990 * | |
991 * | |
992 * +---------+---------+---------+----------+ 1500
993 *
994 * And a final example, a 1024x1024 square aspect ratio stream instead of the
995 * 480p stream:
996 *
997 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
998 *
999 * 1024x1024 stream crop: (625, 375, 750, 750) (marked with #)
1000 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
1001 *
1002 * 0 1000 2000
1003 * +---------+---------+---------+----------+
1004 * | Active pixel array |
1005 * | |
1006 * | 1024x1024 stream |
1007 * + +--###############--+ + 375
1008 * | | # # | |
1009 * | O===================O |
1010 * | I 1280x720 stream I |
1011 * + I I + 750
1012 * | I I |
1013 * | O===================O |
1014 * | | # # | |
1015 * + +--###############--+ + 1125
1016 * | Crop region |
1017 * | |
1018 * | |
1019 * +---------+---------+---------+----------+ 1500
1020 *
1021 */
1022
1023/**
1024 * S6. Error management:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001025 *
1026 * Camera HAL device ops functions that have a return value will all return
1027 * -ENODEV / NULL in case of a serious error. This means the device cannot
1028 * continue operation, and must be closed by the framework. Once this error is
Alex Rayd5ddbc92013-02-15 13:47:24 -08001029 * returned by some method, or if notify() is called with ERROR_DEVICE, only
1030 * the close() method can be called successfully. All other methods will return
1031 * -ENODEV / NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001032 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001033 * If a device op is called in the wrong sequence, for example if the framework
1034 * calls configure_streams() is called before initialize(), the device must
1035 * return -ENOSYS from the call, and do nothing.
1036 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001037 * Transient errors in image capture must be reported through notify() as follows:
1038 *
1039 * - The failure of an entire capture to occur must be reported by the HAL by
1040 * calling notify() with ERROR_REQUEST. Individual errors for the result
1041 * metadata or the output buffers must not be reported in this case.
1042 *
1043 * - If the metadata for a capture cannot be produced, but some image buffers
1044 * were filled, the HAL must call notify() with ERROR_RESULT.
1045 *
1046 * - If an output image buffer could not be filled, but either the metadata was
1047 * produced or some other buffers were filled, the HAL must call notify() with
1048 * ERROR_BUFFER for each failed buffer.
1049 *
1050 * In each of these transient failure cases, the HAL must still call
Zhijun Heceac9e32014-02-05 20:49:45 -08001051 * process_capture_result, with valid output and input (if an input buffer was
1052 * submitted) buffer_handle_t. If the result metadata could not be produced, it
1053 * should be NULL. If some buffers could not be filled, they must be returned with
1054 * process_capture_result in the error state, their release fences must be set to
1055 * the acquire fences passed by the framework, or -1 if they have been waited on by
1056 * the HAL already.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001057 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001058 * Invalid input arguments result in -EINVAL from the appropriate methods. In
1059 * that case, the framework must act as if that call had never been made.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001060 *
1061 */
1062
Zhijun He2dde4682014-01-09 09:11:49 -08001063/**
Zhijun He709e5872014-01-17 15:25:21 -08001064 * S7. Key Performance Indicator (KPI) glossary:
Zhijun He2dde4682014-01-09 09:11:49 -08001065 *
Zhijun He709e5872014-01-17 15:25:21 -08001066 * This includes some critical definitions that are used by KPI metrics.
Zhijun He2dde4682014-01-09 09:11:49 -08001067 *
1068 * Pipeline Latency:
1069 * For a given capture request, the duration from the framework calling
1070 * process_capture_request to the HAL sending capture result and all buffers
1071 * back by process_capture_result call. To make the Pipeline Latency measure
1072 * independent of frame rate, it is measured by frame count.
1073 *
1074 * For example, when frame rate is 30 (fps), the frame duration (time interval
1075 * between adjacent frame capture time) is 33 (ms).
1076 * If it takes 5 frames for framework to get the result and buffers back for
1077 * a given request, then the Pipeline Latency is 5 (frames), instead of
1078 * 5 x 33 = 165 (ms).
1079 *
1080 * The Pipeline Latency is determined by android.request.pipelineDepth and
1081 * android.request.pipelineMaxDepth, see their definitions for more details.
1082 *
1083 */
1084
Zhijun Hebc358682014-01-23 14:42:54 -08001085/**
1086 * S8. Sample Use Cases:
1087 *
1088 * This includes some typical use case examples the camera HAL may support.
1089 *
Zhijun Heb2bc0e52015-01-29 14:44:37 -08001090 * S8.1 Zero Shutter Lag (ZSL) with CAMERA3_STREAM_BIDIRECTIONAL stream.
Zhijun Hebc358682014-01-23 14:42:54 -08001091 *
1092 * For this use case, the bidirectional stream will be used by the framework as follows:
1093 *
1094 * 1. The framework includes a buffer from this stream as output buffer in a
1095 * request as normal.
1096 *
1097 * 2. Once the HAL device returns a filled output buffer to the framework,
1098 * the framework may do one of two things with the filled buffer:
1099 *
1100 * 2. a. The framework uses the filled data, and returns the now-used buffer
1101 * to the stream queue for reuse. This behavior exactly matches the
1102 * OUTPUT type of stream.
1103 *
1104 * 2. b. The framework wants to reprocess the filled data, and uses the
1105 * buffer as an input buffer for a request. Once the HAL device has
1106 * used the reprocessing buffer, it then returns it to the
1107 * framework. The framework then returns the now-used buffer to the
1108 * stream queue for reuse.
1109 *
1110 * 3. The HAL device will be given the buffer again as an output buffer for
1111 * a request at some future point.
1112 *
1113 * For ZSL use case, the pixel format for bidirectional stream will be
Zhijun He52a18892014-06-30 10:35:58 -07001114 * HAL_PIXEL_FORMAT_RAW_OPAQUE or HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED if it
1115 * is listed in android.scaler.availableInputOutputFormatsMap. When
1116 * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, the gralloc
1117 * usage flags for the consumer endpoint will be set to GRALLOC_USAGE_HW_CAMERA_ZSL.
1118 * A configuration stream list that has BIDIRECTIONAL stream used as input, will
1119 * usually also have a distinct OUTPUT stream to get the reprocessing data. For example,
1120 * for the ZSL use case, the stream list might be configured with the following:
Zhijun Hebc358682014-01-23 14:42:54 -08001121 *
1122 * - A HAL_PIXEL_FORMAT_RAW_OPAQUE bidirectional stream is used
1123 * as input.
1124 * - And a HAL_PIXEL_FORMAT_BLOB (JPEG) output stream.
1125 *
Zhijun Heebdf1282015-01-16 16:44:40 -08001126 * S8.2 ZSL (OPAQUE) reprocessing with CAMERA3_STREAM_INPUT stream.
1127 *
1128 * CAMERA_DEVICE_API_VERSION_3_3:
1129 * When OPAQUE_REPROCESSING capability is supported by the camera device, the INPUT stream
1130 * can be used for application/framework implemented use case like Zero Shutter Lag (ZSL).
1131 * This kind of stream will be used by the framework as follows:
1132 *
1133 * 1. Application/framework configures an opaque (RAW or YUV based) format output stream that is
1134 * used to produce the ZSL output buffers. The stream pixel format will be
1135 * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED.
1136 *
1137 * 2. Application/framework configures an opaque format input stream that is used to
1138 * send the reprocessing ZSL buffers to the HAL. The stream pixel format will
1139 * also be HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED.
1140 *
1141 * 3. Application/framework configures a YUV/JPEG output stream that is used to receive the
1142 * reprocessed data. The stream pixel format will be YCbCr_420/HAL_PIXEL_FORMAT_BLOB.
1143 *
1144 * 4. Application/framework picks a ZSL buffer from the ZSL output stream when a ZSL capture is
1145 * issued by the application, and sends the data back as an input buffer in a
1146 * reprocessing request, then sends to the HAL for reprocessing.
1147 *
1148 * 5. The HAL sends back the output YUV/JPEG result to framework.
1149 *
1150 * The HAL can select the actual opaque buffer format and configure the ISP pipeline
1151 * appropriately based on the HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED format and
1152 * the gralloc usage flag GRALLOC_USAGE_HW_CAMERA_ZSL.
1153
1154 * S8.3 YUV reprocessing with CAMERA3_STREAM_INPUT stream.
1155 *
1156 * When YUV reprocessing is supported by the HAL, the INPUT stream
1157 * can be used for the YUV reprocessing use cases like lucky-shot and image fusion.
1158 * This kind of stream will be used by the framework as follows:
1159 *
1160 * 1. Application/framework configures an YCbCr_420 format output stream that is
1161 * used to produce the output buffers.
1162 *
1163 * 2. Application/framework configures an YCbCr_420 format input stream that is used to
1164 * send the reprocessing YUV buffers to the HAL.
1165 *
1166 * 3. Application/framework configures a YUV/JPEG output stream that is used to receive the
1167 * reprocessed data. The stream pixel format will be YCbCr_420/HAL_PIXEL_FORMAT_BLOB.
1168 *
1169 * 4. Application/framework processes the output buffers (could be as simple as picking
1170 * an output buffer directly) from the output stream when a capture is issued, and sends
1171 * the data back as an input buffer in a reprocessing request, then sends to the HAL
1172 * for reprocessing.
1173 *
1174 * 5. The HAL sends back the output YUV/JPEG result to framework.
1175 *
Zhijun Hebc358682014-01-23 14:42:54 -08001176 */
1177
Ruben Brunk2d96c742014-03-18 13:39:17 -07001178/**
1179 * S9. Notes on Controls and Metadata
1180 *
1181 * This section contains notes about the interpretation and usage of various metadata tags.
1182 *
1183 * S9.1 HIGH_QUALITY and FAST modes.
1184 *
1185 * Many camera post-processing blocks may be listed as having HIGH_QUALITY,
1186 * FAST, and OFF operating modes. These blocks will typically also have an
1187 * 'available modes' tag representing which of these operating modes are
1188 * available on a given device. The general policy regarding implementing
1189 * these modes is as follows:
1190 *
1191 * 1. Operating mode controls of hardware blocks that cannot be disabled
1192 * must not list OFF in their corresponding 'available modes' tags.
1193 *
1194 * 2. OFF will always be included in their corresponding 'available modes'
1195 * tag if it is possible to disable that hardware block.
1196 *
1197 * 3. FAST must always be included in the 'available modes' tags for all
1198 * post-processing blocks supported on the device. If a post-processing
1199 * block also has a slower and higher quality operating mode that does
1200 * not meet the framerate requirements for FAST mode, HIGH_QUALITY should
1201 * be included in the 'available modes' tag to represent this operating
1202 * mode.
1203 */
Zhijun Heebdf1282015-01-16 16:44:40 -08001204
1205/**
1206 * S10. Reprocessing flow and controls
1207 *
1208 * This section describes the OPAQUE and YUV reprocessing flow and controls. OPAQUE reprocessing
1209 * uses an opaque format that is not directly application-visible, and the application can
1210 * only select some of the output buffers and send back to HAL for reprocessing, while YUV
1211 * reprocessing gives the application opportunity to process the buffers before reprocessing.
1212 *
1213 * S8 gives the stream configurations for the typical reprocessing uses cases,
1214 * this section specifies the buffer flow and controls in more details.
1215 *
1216 * S10.1 OPAQUE (typically for ZSL use case) reprocessing flow and controls
1217 *
1218 * For OPAQUE reprocessing (e.g. ZSL) use case, after the application creates the specific
1219 * output and input streams, runtime buffer flow and controls are specified as below:
1220 *
1221 * 1. Application starts output streaming by sending repeating requests for output
1222 * opaque buffers and preview. The buffers are held by an application
1223 * maintained circular buffer. The requests are based on CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG
1224 * capture template, which should have all necessary settings that guarantee output
1225 * frame rate is not slowed down relative to sensor output frame rate.
1226 *
1227 * 2. When a capture is issued, the application selects one output buffer based
1228 * on application buffer selection logic, e.g. good AE and AF statistics etc.
1229 * Application then creates an reprocess request based on the capture result associated
1230 * with this selected buffer. The selected output buffer is now added to this reprocess
1231 * request as an input buffer, the output buffer of this reprocess request should be
1232 * either JPEG output buffer or YUV output buffer, or both, depending on the application
1233 * choice.
1234 *
1235 * 3. Application then alters the reprocess settings to get best image quality. The HAL must
1236 * support and only support below controls if the HAL support OPAQUE_REPROCESSING capability:
1237 * - android.jpeg.* (if JPEG buffer is included as one of the output)
1238 * - android.noiseReduction.mode (change to HIGH_QUALITY if it is supported)
1239 * - android.edge.mode (change to HIGH_QUALITY if it is supported)
1240 * All other controls must be ignored by the HAL.
1241 * 4. HAL processed the input buffer and return the output buffers in the capture results
1242 * as normal.
1243 *
1244 * S10.2 YUV reprocessing flow and controls
1245 *
1246 * The YUV reprocessing buffer flow is similar as OPAQUE reprocessing, with below difference:
1247 *
1248 * 1. Application may want to have finer granularity control of the intermediate YUV images
1249 * (before reprocessing). For example, application may choose
1250 * - android.noiseReduction.mode == MINIMAL
1251 * to make sure the no YUV domain noise reduction has applied to the output YUV buffers,
1252 * then it can do its own advanced noise reduction on them. For OPAQUE reprocessing case, this
1253 * doesn't matter, as long as the final reprocessed image has the best quality.
1254 * 2. Application may modify the YUV output buffer data. For example, for image fusion use
1255 * case, where multiple output images are merged together to improve the signal-to-noise
1256 * ratio (SNR). The input buffer may be generated from multiple buffers by the application.
1257 * To avoid excessive amount of noise reduction and insufficient amount of edge enhancement
1258 * being applied to the input buffer, the application can hint the HAL how much effective
1259 * exposure time improvement has been done by the application, then the HAL can adjust the
1260 * noise reduction and edge enhancement paramters to get best reprocessed image quality.
1261 * Below tag can be used for this purpose:
1262 * - android.reprocess.effectiveExposureFactor
1263 * The value would be exposure time increase factor applied to the original output image,
1264 * for example, if there are N image merged, the exposure time increase factor would be up
1265 * to sqrt(N). See this tag spec for more details.
1266 *
1267 * S10.3 Reprocessing pipeline characteristics
1268 *
1269 * Reprocessing pipeline has below different characteristics comparing with normal output
1270 * pipeline:
1271 *
1272 * 1. The reprocessing result can be returned ahead of the pending normal output results. But
1273 * the FIFO ordering must be maintained for all reprocessing results. For example, there are
1274 * below requests (A stands for output requests, B stands for reprocessing requests)
1275 * being processed by the HAL:
1276 * A1, A2, A3, A4, B1, A5, B2, A6...
1277 * result of B1 can be returned before A1-A4, but result of B2 must be returned after B1.
1278 * 2. Single input rule: For a given reprocessing request, all output buffers must be from the
1279 * input buffer, rather than sensor output. For example, if a reprocess request include both
1280 * JPEG and preview buffers, all output buffers must be produced from the input buffer
1281 * included by the reprocessing request, rather than sensor. The HAL must not output preview
1282 * buffers from sensor, while output JPEG buffer from the input buffer.
1283 * 3. Input buffer will be from camera output directly (ZSL case) or indirectly(image fusion
1284 * case). For the case where buffer is modified, the size will remain same. The HAL can
1285 * notify CAMERA3_MSG_ERROR_REQUEST if buffer from unknown source is sent.
1286 * 4. Result as reprocessing request: The HAL can expect that a reprocessing request is a copy
1287 * of one of the output results with minor allowed setting changes. The HAL can notify
1288 * CAMERA3_MSG_ERROR_REQUEST if a request from unknown source is issued.
1289 * 5. Output buffers may not be used as inputs across the configure stream boundary, This is
1290 * because an opaque stream like the ZSL output stream may have different actual image size
1291 * inside of the ZSL buffer to save power and bandwidth for smaller resolution JPEG capture.
1292 * The HAL may notify CAMERA3_MSG_ERROR_REQUEST if this case occurs.
1293 * 6. HAL Reprocess requests error reporting during flush should follow the same rule specified
1294 * by flush() method.
1295 *
1296 */
1297
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001298__BEGIN_DECLS
1299
1300struct camera3_device;
1301
1302/**********************************************************************
1303 *
1304 * Camera3 stream and stream buffer definitions.
1305 *
1306 * These structs and enums define the handles and contents of the input and
1307 * output streams connecting the HAL to various framework and application buffer
1308 * consumers. Each stream is backed by a gralloc buffer queue.
1309 *
1310 */
1311
1312/**
1313 * camera3_stream_type_t:
1314 *
1315 * The type of the camera stream, which defines whether the camera HAL device is
1316 * the producer or the consumer for that stream, and how the buffers of the
1317 * stream relate to the other streams.
1318 */
1319typedef enum camera3_stream_type {
1320 /**
1321 * This stream is an output stream; the camera HAL device will be
1322 * responsible for filling buffers from this stream with newly captured or
1323 * reprocessed image data.
1324 */
1325 CAMERA3_STREAM_OUTPUT = 0,
1326
1327 /**
1328 * This stream is an input stream; the camera HAL device will be responsible
1329 * for reading buffers from this stream and sending them through the camera
1330 * processing pipeline, as if the buffer was a newly captured image from the
1331 * imager.
Zhijun Hebc358682014-01-23 14:42:54 -08001332 *
1333 * The pixel format for input stream can be any format reported by
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001334 * android.scaler.availableInputOutputFormatsMap. The pixel format of the
1335 * output stream that is used to produce the reprocessing data may be any
1336 * format reported by android.scaler.availableStreamConfigurations. The
1337 * supported input/output stream combinations depends the camera device
1338 * capabilities, see android.scaler.availableInputOutputFormatsMap for
1339 * stream map details.
Zhijun Hebc358682014-01-23 14:42:54 -08001340 *
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001341 * This kind of stream is generally used to reprocess data into higher
1342 * quality images (that otherwise would cause a frame rate performance
1343 * loss), or to do off-line reprocessing.
Zhijun Hebc358682014-01-23 14:42:54 -08001344 *
Zhijun Heebdf1282015-01-16 16:44:40 -08001345 * CAMERA_DEVICE_API_VERSION_3_3:
1346 * The typical use cases are OPAQUE (typically ZSL) and YUV reprocessing,
1347 * see S8.2, S8.3 and S10 for more details.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001348 */
1349 CAMERA3_STREAM_INPUT = 1,
1350
1351 /**
1352 * This stream can be used for input and output. Typically, the stream is
1353 * used as an output stream, but occasionally one already-filled buffer may
1354 * be sent back to the HAL device for reprocessing.
1355 *
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001356 * This kind of stream is meant generally for Zero Shutter Lag (ZSL)
1357 * features, where copying the captured image from the output buffer to the
Zhijun Heb2bc0e52015-01-29 14:44:37 -08001358 * reprocessing input buffer would be expensive. See S8.1 for more details.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001359 *
1360 * Note that the HAL will always be reprocessing data it produced.
1361 *
1362 */
1363 CAMERA3_STREAM_BIDIRECTIONAL = 2,
1364
1365 /**
1366 * Total number of framework-defined stream types
1367 */
1368 CAMERA3_NUM_STREAM_TYPES
1369
1370} camera3_stream_type_t;
1371
1372/**
1373 * camera3_stream_t:
1374 *
1375 * A handle to a single camera input or output stream. A stream is defined by
1376 * the framework by its buffer resolution and format, and additionally by the
1377 * HAL with the gralloc usage flags and the maximum in-flight buffer count.
1378 *
1379 * The stream structures are owned by the framework, but pointers to a
1380 * camera3_stream passed into the HAL by configure_streams() are valid until the
1381 * end of the first subsequent configure_streams() call that _does not_ include
1382 * that camera3_stream as an argument, or until the end of the close() call.
1383 *
1384 * All camera3_stream framework-controlled members are immutable once the
1385 * camera3_stream is passed into configure_streams(). The HAL may only change
1386 * the HAL-controlled parameters during a configure_streams() call, except for
1387 * the contents of the private pointer.
1388 *
1389 * If a configure_streams() call returns a non-fatal error, all active streams
1390 * remain valid as if configure_streams() had not been called.
1391 *
1392 * The endpoint of the stream is not visible to the camera HAL device.
Alex Ray2ce219a2013-06-14 15:09:30 -07001393 * In DEVICE_API_VERSION_3_1, this was changed to share consumer usage flags
1394 * on streams where the camera is a producer (OUTPUT and BIDIRECTIONAL stream
1395 * types) see the usage field below.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001396 */
1397typedef struct camera3_stream {
1398
1399 /*****
1400 * Set by framework before configure_streams()
1401 */
1402
1403 /**
1404 * The type of the stream, one of the camera3_stream_type_t values.
1405 */
1406 int stream_type;
1407
1408 /**
1409 * The width in pixels of the buffers in this stream
1410 */
1411 uint32_t width;
1412
1413 /**
1414 * The height in pixels of the buffers in this stream
1415 */
1416 uint32_t height;
1417
1418 /**
1419 * The pixel format for the buffers in this stream. Format is a value from
1420 * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
1421 * from device-specific headers.
1422 *
1423 * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
1424 * gralloc module will select a format based on the usage flags provided by
1425 * the camera device and the other endpoint of the stream.
1426 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001427 * <= CAMERA_DEVICE_API_VERSION_3_1:
1428 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001429 * The camera HAL device must inspect the buffers handed to it in the
1430 * subsequent register_stream_buffers() call to obtain the
1431 * implementation-specific format details, if necessary.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001432 *
1433 * >= CAMERA_DEVICE_API_VERSION_3_2:
1434 *
1435 * register_stream_buffers() won't be called by the framework, so the HAL
1436 * should configure the ISP and sensor pipeline based purely on the sizes,
1437 * usage flags, and formats for the configured streams.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001438 */
1439 int format;
1440
1441 /*****
1442 * Set by HAL during configure_streams().
1443 */
1444
1445 /**
1446 * The gralloc usage flags for this stream, as needed by the HAL. The usage
1447 * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
1448 * headers.
1449 *
1450 * For output streams, these are the HAL's producer usage flags. For input
1451 * streams, these are the HAL's consumer usage flags. The usage flags from
1452 * the producer and the consumer will be combined together and then passed
1453 * to the platform gralloc HAL module for allocating the gralloc buffers for
1454 * each stream.
Alex Ray2ce219a2013-06-14 15:09:30 -07001455 *
1456 * Version information:
1457 *
1458 * == CAMERA_DEVICE_API_VERSION_3_0:
1459 *
1460 * No initial value guaranteed when passed via configure_streams().
1461 * HAL may not use this field as input, and must write over this field
1462 * with its usage flags.
1463 *
1464 * >= CAMERA_DEVICE_API_VERSION_3_1:
1465 *
1466 * For stream_type OUTPUT and BIDIRECTIONAL, when passed via
1467 * configure_streams(), the initial value of this is the consumer's
1468 * usage flags. The HAL may use these consumer flags to decide stream
1469 * configuration.
1470 * For stream_type INPUT, when passed via configure_streams(), the initial
1471 * value of this is 0.
1472 * For all streams passed via configure_streams(), the HAL must write
1473 * over this field with its usage flags.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001474 */
1475 uint32_t usage;
1476
1477 /**
1478 * The maximum number of buffers the HAL device may need to have dequeued at
1479 * the same time. The HAL device may not have more buffers in-flight from
1480 * this stream than this value.
1481 */
1482 uint32_t max_buffers;
1483
1484 /**
1485 * A handle to HAL-private information for the stream. Will not be inspected
1486 * by the framework code.
1487 */
1488 void *priv;
1489
Eino-Ville Talvala453c7902015-03-06 13:22:03 -08001490 /**
1491 * A field that describes the contents of the buffer. The format and buffer
1492 * dimensions define the memory layout and structure of the stream buffers,
1493 * while dataSpace defines the meaning of the data within the buffer.
1494 *
1495 * For most formats, dataSpace defines the color space of the image data.
1496 * In addition, for some formats, dataSpace indicates whether image- or
1497 * depth-based data is requested. See system/core/include/system/graphics.h
1498 * for details of formats and valid dataSpace values for each format.
1499 *
1500 * Version information:
1501 *
1502 * < CAMERA_DEVICE_API_VERSION_3_3:
1503 *
1504 * Not defined and should not be accessed. dataSpace should be assumed to
1505 * be HAL_DATASPACE_UNKNOWN, and the appropriate color space, etc, should
1506 * be determined from the usage flags and the format.
1507 *
1508 * >= CAMERA_DEVICE_API_VERSION_3_3:
1509 *
1510 * Always set by the camera service. HAL must use this dataSpace to
1511 * configure the stream to the correct colorspace, or to select between
1512 * color and depth outputs if supported.
1513 */
1514 android_dataspace_t data_space;
1515
1516 /* reserved for future use */
1517 void *reserved[8];
1518
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001519} camera3_stream_t;
1520
1521/**
1522 * camera3_stream_configuration_t:
1523 *
1524 * A structure of stream definitions, used by configure_streams(). This
1525 * structure defines all the output streams and the reprocessing input
1526 * stream for the current camera use case.
1527 */
1528typedef struct camera3_stream_configuration {
1529 /**
1530 * The total number of streams requested by the framework. This includes
1531 * both input and output streams. The number of streams will be at least 1,
1532 * and there will be at least one output-capable stream.
1533 */
1534 uint32_t num_streams;
1535
1536 /**
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001537 * An array of camera stream pointers, defining the input/output
1538 * configuration for the camera HAL device.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001539 *
1540 * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
1541 * in a single configuration.
1542 *
1543 * At least one output-capable stream must be defined (OUTPUT or
1544 * BIDIRECTIONAL).
1545 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001546 camera3_stream_t **streams;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001547
1548} camera3_stream_configuration_t;
1549
1550/**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001551 * camera3_buffer_status_t:
1552 *
1553 * The current status of a single stream buffer.
1554 */
1555typedef enum camera3_buffer_status {
1556 /**
1557 * The buffer is in a normal state, and can be used after waiting on its
1558 * sync fence.
1559 */
1560 CAMERA3_BUFFER_STATUS_OK = 0,
1561
1562 /**
1563 * The buffer does not contain valid data, and the data in it should not be
1564 * used. The sync fence must still be waited on before reusing the buffer.
1565 */
1566 CAMERA3_BUFFER_STATUS_ERROR = 1
1567
1568} camera3_buffer_status_t;
1569
1570/**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001571 * camera3_stream_buffer_t:
1572 *
1573 * A single buffer from a camera3 stream. It includes a handle to its parent
1574 * stream, the handle to the gralloc buffer itself, and sync fences
1575 *
1576 * The buffer does not specify whether it is to be used for input or output;
1577 * that is determined by its parent stream type and how the buffer is passed to
1578 * the HAL device.
1579 */
1580typedef struct camera3_stream_buffer {
1581 /**
1582 * The handle of the stream this buffer is associated with
1583 */
1584 camera3_stream_t *stream;
1585
1586 /**
1587 * The native handle to the buffer
1588 */
1589 buffer_handle_t *buffer;
1590
1591 /**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001592 * Current state of the buffer, one of the camera3_buffer_status_t
1593 * values. The framework will not pass buffers to the HAL that are in an
1594 * error state. In case a buffer could not be filled by the HAL, it must
1595 * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
1596 * framework with process_capture_result().
1597 */
1598 int status;
1599
1600 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001601 * The acquire sync fence for this buffer. The HAL must wait on this fence
1602 * fd before attempting to read from or write to this buffer.
1603 *
1604 * The framework may be set to -1 to indicate that no waiting is necessary
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001605 * for this buffer.
1606 *
1607 * When the HAL returns an output buffer to the framework with
1608 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
1609 * never waits on the acquire_fence due to an error in filling a buffer,
1610 * when calling process_capture_result() the HAL must set the release_fence
1611 * of the buffer to be the acquire_fence passed to it by the framework. This
1612 * will allow the framework to wait on the fence before reusing the buffer.
1613 *
1614 * For input buffers, the HAL must not change the acquire_fence field during
1615 * the process_capture_request() call.
Zhijun Heceac9e32014-02-05 20:49:45 -08001616 *
1617 * >= CAMERA_DEVICE_API_VERSION_3_2:
1618 *
1619 * When the HAL returns an input buffer to the framework with
1620 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001621 * never waits on input buffer acquire fence due to an error, the sync
1622 * fences should be handled similarly to the way they are handled for output
1623 * buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001624 */
1625 int acquire_fence;
1626
1627 /**
1628 * The release sync fence for this buffer. The HAL must set this fence when
1629 * returning buffers to the framework, or write -1 to indicate that no
1630 * waiting is required for this buffer.
1631 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001632 * For the output buffers, the fences must be set in the output_buffers
1633 * array passed to process_capture_result().
1634 *
1635 * <= CAMERA_DEVICE_API_VERSION_3_1:
1636 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001637 * For the input buffer, the release fence must be set by the
Zhijun Heceac9e32014-02-05 20:49:45 -08001638 * process_capture_request() call.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001639 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001640 * >= CAMERA_DEVICE_API_VERSION_3_2:
1641 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001642 * For the input buffer, the fences must be set in the input_buffer
1643 * passed to process_capture_result().
1644 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001645 * After signaling the release_fence for this buffer, the HAL
1646 * should not make any further attempts to access this buffer as the
1647 * ownership has been fully transferred back to the framework.
1648 *
1649 * If a fence of -1 was specified then the ownership of this buffer
1650 * is transferred back immediately upon the call of process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001651 */
1652 int release_fence;
1653
1654} camera3_stream_buffer_t;
1655
1656/**
1657 * camera3_stream_buffer_set_t:
1658 *
1659 * The complete set of gralloc buffers for a stream. This structure is given to
1660 * register_stream_buffers() to allow the camera HAL device to register/map/etc
1661 * newly allocated stream buffers.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001662 *
1663 * >= CAMERA_DEVICE_API_VERSION_3_2:
1664 *
1665 * Deprecated (and not used). In particular,
1666 * register_stream_buffers is also deprecated and will never be invoked.
1667 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001668 */
1669typedef struct camera3_stream_buffer_set {
1670 /**
1671 * The stream handle for the stream these buffers belong to
1672 */
1673 camera3_stream_t *stream;
1674
1675 /**
1676 * The number of buffers in this stream. It is guaranteed to be at least
1677 * stream->max_buffers.
1678 */
1679 uint32_t num_buffers;
1680
1681 /**
1682 * The array of gralloc buffer handles for this stream. If the stream format
1683 * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
1684 * should inspect the passed-in buffers to determine any platform-private
1685 * pixel format information.
1686 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001687 buffer_handle_t **buffers;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001688
1689} camera3_stream_buffer_set_t;
1690
1691/**
1692 * camera3_jpeg_blob:
1693 *
1694 * Transport header for compressed JPEG buffers in output streams.
1695 *
1696 * To capture JPEG images, a stream is created using the pixel format
Zhijun He44a89152014-04-24 14:34:53 -07001697 * HAL_PIXEL_FORMAT_BLOB. The buffer size for the stream is calculated by the
1698 * framework, based on the static metadata field android.jpeg.maxSize. Since
1699 * compressed JPEG images are of variable size, the HAL needs to include the
1700 * final size of the compressed image using this structure inside the output
1701 * stream buffer. The JPEG blob ID field must be set to CAMERA3_JPEG_BLOB_ID.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001702 *
Zhijun He44a89152014-04-24 14:34:53 -07001703 * Transport header should be at the end of the JPEG output stream buffer. That
1704 * means the jpeg_blob_id must start at byte[buffer_size -
1705 * sizeof(camera3_jpeg_blob)], where the buffer_size is the size of gralloc buffer.
1706 * Any HAL using this transport header must account for it in android.jpeg.maxSize
1707 * The JPEG data itself starts at the beginning of the buffer and should be
1708 * jpeg_size bytes long.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001709 */
1710typedef struct camera3_jpeg_blob {
1711 uint16_t jpeg_blob_id;
1712 uint32_t jpeg_size;
1713} camera3_jpeg_blob_t;
1714
1715enum {
1716 CAMERA3_JPEG_BLOB_ID = 0x00FF
1717};
1718
1719/**********************************************************************
1720 *
1721 * Message definitions for the HAL notify() callback.
1722 *
1723 * These definitions are used for the HAL notify callback, to signal
1724 * asynchronous events from the HAL device to the Android framework.
1725 *
1726 */
1727
1728/**
1729 * camera3_msg_type:
1730 *
1731 * Indicates the type of message sent, which specifies which member of the
1732 * message union is valid.
1733 *
1734 */
1735typedef enum camera3_msg_type {
1736 /**
1737 * An error has occurred. camera3_notify_msg.message.error contains the
1738 * error information.
1739 */
1740 CAMERA3_MSG_ERROR = 1,
1741
1742 /**
1743 * The exposure of a given request has
1744 * begun. camera3_notify_msg.message.shutter contains the information
1745 * the capture.
1746 */
1747 CAMERA3_MSG_SHUTTER = 2,
1748
1749 /**
1750 * Number of framework message types
1751 */
1752 CAMERA3_NUM_MESSAGES
1753
1754} camera3_msg_type_t;
1755
1756/**
1757 * Defined error codes for CAMERA_MSG_ERROR
1758 */
1759typedef enum camera3_error_msg_code {
1760 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001761 * A serious failure occured. No further frames or buffer streams will
1762 * be produced by the device. Device should be treated as closed. The
1763 * client must reopen the device to use it again. The frame_number field
1764 * is unused.
1765 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001766 CAMERA3_MSG_ERROR_DEVICE = 1,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001767
1768 /**
1769 * An error has occurred in processing a request. No output (metadata or
1770 * buffers) will be produced for this request. The frame_number field
1771 * specifies which request has been dropped. Subsequent requests are
1772 * unaffected, and the device remains operational.
1773 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001774 CAMERA3_MSG_ERROR_REQUEST = 2,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001775
1776 /**
1777 * An error has occurred in producing an output result metadata buffer
1778 * for a request, but output stream buffers for it will still be
1779 * available. Subsequent requests are unaffected, and the device remains
1780 * operational. The frame_number field specifies the request for which
1781 * result metadata won't be available.
1782 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001783 CAMERA3_MSG_ERROR_RESULT = 3,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001784
1785 /**
1786 * An error has occurred in placing an output buffer into a stream for a
1787 * request. The frame metadata and other buffers may still be
1788 * available. Subsequent requests are unaffected, and the device remains
1789 * operational. The frame_number field specifies the request for which the
1790 * buffer was dropped, and error_stream contains a pointer to the stream
1791 * that dropped the frame.u
1792 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001793 CAMERA3_MSG_ERROR_BUFFER = 4,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001794
1795 /**
1796 * Number of error types
1797 */
1798 CAMERA3_MSG_NUM_ERRORS
1799
1800} camera3_error_msg_code_t;
1801
1802/**
1803 * camera3_error_msg_t:
1804 *
1805 * Message contents for CAMERA3_MSG_ERROR
1806 */
1807typedef struct camera3_error_msg {
1808 /**
1809 * Frame number of the request the error applies to. 0 if the frame number
1810 * isn't applicable to the error.
1811 */
1812 uint32_t frame_number;
1813
1814 /**
1815 * Pointer to the stream that had a failure. NULL if the stream isn't
1816 * applicable to the error.
1817 */
1818 camera3_stream_t *error_stream;
1819
1820 /**
1821 * The code for this error; one of the CAMERA_MSG_ERROR enum values.
1822 */
1823 int error_code;
1824
1825} camera3_error_msg_t;
1826
1827/**
1828 * camera3_shutter_msg_t:
1829 *
1830 * Message contents for CAMERA3_MSG_SHUTTER
1831 */
1832typedef struct camera3_shutter_msg {
1833 /**
1834 * Frame number of the request that has begun exposure
1835 */
1836 uint32_t frame_number;
1837
1838 /**
1839 * Timestamp for the start of capture. This must match the capture result
1840 * metadata's sensor exposure start timestamp.
1841 */
1842 uint64_t timestamp;
1843
1844} camera3_shutter_msg_t;
1845
1846/**
1847 * camera3_notify_msg_t:
1848 *
1849 * The message structure sent to camera3_callback_ops_t.notify()
1850 */
1851typedef struct camera3_notify_msg {
1852
1853 /**
1854 * The message type. One of camera3_notify_msg_type, or a private extension.
1855 */
1856 int type;
1857
1858 union {
1859 /**
1860 * Error message contents. Valid if type is CAMERA3_MSG_ERROR
1861 */
1862 camera3_error_msg_t error;
1863
1864 /**
1865 * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
1866 */
1867 camera3_shutter_msg_t shutter;
1868
1869 /**
1870 * Generic message contents. Used to ensure a minimum size for custom
1871 * message types.
1872 */
1873 uint8_t generic[32];
1874 } message;
1875
1876} camera3_notify_msg_t;
1877
1878/**********************************************************************
1879 *
1880 * Capture request/result definitions for the HAL process_capture_request()
1881 * method, and the process_capture_result() callback.
1882 *
1883 */
1884
1885/**
1886 * camera3_request_template_t:
1887 *
1888 * Available template types for
1889 * camera3_device_ops.construct_default_request_settings()
1890 */
1891typedef enum camera3_request_template {
1892 /**
1893 * Standard camera preview operation with 3A on auto.
1894 */
1895 CAMERA3_TEMPLATE_PREVIEW = 1,
1896
1897 /**
1898 * Standard camera high-quality still capture with 3A and flash on auto.
1899 */
1900 CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
1901
1902 /**
1903 * Standard video recording plus preview with 3A on auto, torch off.
1904 */
1905 CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
1906
1907 /**
1908 * High-quality still capture while recording video. Application will
1909 * include preview, video record, and full-resolution YUV or JPEG streams in
1910 * request. Must not cause stuttering on video stream. 3A on auto.
1911 */
1912 CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
1913
1914 /**
1915 * Zero-shutter-lag mode. Application will request preview and
1916 * full-resolution data for each frame, and reprocess it to JPEG when a
1917 * still image is requested by user. Settings should provide highest-quality
1918 * full-resolution images without compromising preview frame rate. 3A on
1919 * auto.
1920 */
1921 CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
1922
Zhijun Heb0c939f2013-12-13 15:56:33 -08001923 /**
1924 * A basic template for direct application control of capture
1925 * parameters. All automatic control is disabled (auto-exposure, auto-white
1926 * balance, auto-focus), and post-processing parameters are set to preview
1927 * quality. The manual capture parameters (exposure, sensitivity, etc.)
1928 * are set to reasonable defaults, but should be overridden by the
1929 * application depending on the intended use case.
1930 */
1931 CAMERA3_TEMPLATE_MANUAL = 6,
1932
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001933 /* Total number of templates */
1934 CAMERA3_TEMPLATE_COUNT,
1935
1936 /**
1937 * First value for vendor-defined request templates
1938 */
1939 CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
1940
1941} camera3_request_template_t;
1942
1943/**
1944 * camera3_capture_request_t:
1945 *
1946 * A single request for image capture/buffer reprocessing, sent to the Camera
1947 * HAL device by the framework in process_capture_request().
1948 *
1949 * The request contains the settings to be used for this capture, and the set of
1950 * output buffers to write the resulting image data in. It may optionally
1951 * contain an input buffer, in which case the request is for reprocessing that
1952 * input buffer instead of capturing a new image with the camera sensor. The
1953 * capture is identified by the frame_number.
1954 *
1955 * In response, the camera HAL device must send a camera3_capture_result
1956 * structure asynchronously to the framework, using the process_capture_result()
1957 * callback.
1958 */
1959typedef struct camera3_capture_request {
1960 /**
1961 * The frame number is an incrementing integer set by the framework to
1962 * uniquely identify this capture. It needs to be returned in the result
1963 * call, and is also used to identify the request in asynchronous
1964 * notifications sent to camera3_callback_ops_t.notify().
1965 */
1966 uint32_t frame_number;
1967
1968 /**
1969 * The settings buffer contains the capture and processing parameters for
1970 * the request. As a special case, a NULL settings buffer indicates that the
1971 * settings are identical to the most-recently submitted capture request. A
1972 * NULL buffer cannot be used as the first submitted request after a
1973 * configure_streams() call.
1974 */
1975 const camera_metadata_t *settings;
1976
1977 /**
1978 * The input stream buffer to use for this request, if any.
1979 *
1980 * If input_buffer is NULL, then the request is for a new capture from the
1981 * imager. If input_buffer is valid, the request is for reprocessing the
1982 * image contained in input_buffer.
1983 *
1984 * In the latter case, the HAL must set the release_fence of the
1985 * input_buffer to a valid sync fence, or to -1 if the HAL does not support
1986 * sync, before process_capture_request() returns.
1987 *
1988 * The HAL is required to wait on the acquire sync fence of the input buffer
1989 * before accessing it.
1990 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001991 * <= CAMERA_DEVICE_API_VERSION_3_1:
1992 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001993 * Any input buffer included here will have been registered with the HAL
1994 * through register_stream_buffers() before its inclusion in a request.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001995 *
1996 * >= CAMERA_DEVICE_API_VERSION_3_2:
1997 *
1998 * The buffers will not have been pre-registered with the HAL.
1999 * Subsequent requests may reuse buffers, or provide entirely new buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002000 */
2001 camera3_stream_buffer_t *input_buffer;
2002
2003 /**
2004 * The number of output buffers for this capture request. Must be at least
2005 * 1.
2006 */
2007 uint32_t num_output_buffers;
2008
2009 /**
2010 * An array of num_output_buffers stream buffers, to be filled with image
2011 * data from this capture/reprocess. The HAL must wait on the acquire fences
Igor Murashkin78aa1262014-01-09 16:23:43 -08002012 * of each stream buffer before writing to them.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002013 *
2014 * The HAL takes ownership of the actual buffer_handle_t entries in
2015 * output_buffers; the framework does not access them until they are
2016 * returned in a camera3_capture_result_t.
Igor Murashkin78aa1262014-01-09 16:23:43 -08002017 *
2018 * <= CAMERA_DEVICE_API_VERSION_3_1:
2019 *
2020 * All the buffers included here will have been registered with the HAL
2021 * through register_stream_buffers() before their inclusion in a request.
2022 *
2023 * >= CAMERA_DEVICE_API_VERSION_3_2:
2024 *
2025 * Any or all of the buffers included here may be brand new in this
2026 * request (having never before seen by the HAL).
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002027 */
2028 const camera3_stream_buffer_t *output_buffers;
2029
2030} camera3_capture_request_t;
2031
2032/**
2033 * camera3_capture_result_t:
2034 *
2035 * The result of a single capture/reprocess by the camera HAL device. This is
2036 * sent to the framework asynchronously with process_capture_result(), in
2037 * response to a single capture request sent to the HAL with
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002038 * process_capture_request(). Multiple process_capture_result() calls may be
Igor Murashkin5df2f622014-01-10 14:18:45 -08002039 * performed by the HAL for each request.
2040 *
2041 * Each call, all with the same frame
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002042 * number, may contain some subset of the output buffers, and/or the result
2043 * metadata. The metadata may only be provided once for a given frame number;
2044 * all other calls must set the result metadata to NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002045 *
2046 * The result structure contains the output metadata from this capture, and the
2047 * set of output buffers that have been/will be filled for this capture. Each
2048 * output buffer may come with a release sync fence that the framework will wait
2049 * on before reading, in case the buffer has not yet been filled by the HAL.
2050 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002051 * >= CAMERA_DEVICE_API_VERSION_3_2:
2052 *
2053 * The metadata may be provided multiple times for a single frame number. The
2054 * framework will accumulate together the final result set by combining each
2055 * partial result together into the total result set.
2056 *
Zhijun Heceac9e32014-02-05 20:49:45 -08002057 * If an input buffer is given in a request, the HAL must return it in one of
2058 * the process_capture_result calls, and the call may be to just return the input
2059 * buffer, without metadata and output buffers; the sync fences must be handled
2060 * the same way they are done for output buffers.
2061 *
2062 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002063 * Performance considerations:
2064 *
2065 * Applications will also receive these partial results immediately, so sending
2066 * partial results is a highly recommended performance optimization to avoid
2067 * the total pipeline latency before sending the results for what is known very
2068 * early on in the pipeline.
2069 *
2070 * A typical use case might be calculating the AF state halfway through the
2071 * pipeline; by sending the state back to the framework immediately, we get a
2072 * 50% performance increase and perceived responsiveness of the auto-focus.
2073 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002074 */
2075typedef struct camera3_capture_result {
2076 /**
2077 * The frame number is an incrementing integer set by the framework in the
2078 * submitted request to uniquely identify this capture. It is also used to
2079 * identify the request in asynchronous notifications sent to
2080 * camera3_callback_ops_t.notify().
2081 */
2082 uint32_t frame_number;
2083
2084 /**
2085 * The result metadata for this capture. This contains information about the
2086 * final capture parameters, the state of the capture and post-processing
2087 * hardware, the state of the 3A algorithms, if enabled, and the output of
2088 * any enabled statistics units.
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002089 *
2090 * Only one call to process_capture_result() with a given frame_number may
2091 * include the result metadata. All other calls for the same frame_number
2092 * must set this to NULL.
2093 *
2094 * If there was an error producing the result metadata, result must be an
2095 * empty metadata buffer, and notify() must be called with ERROR_RESULT.
Igor Murashkin5df2f622014-01-10 14:18:45 -08002096 *
2097 * >= CAMERA_DEVICE_API_VERSION_3_2:
2098 *
2099 * Multiple calls to process_capture_result() with a given frame_number
2100 * may include the result metadata.
2101 *
2102 * Partial metadata submitted should not include any metadata key returned
2103 * in a previous partial result for a given frame. Each new partial result
2104 * for that frame must also set a distinct partial_result value.
2105 *
2106 * If notify has been called with ERROR_RESULT, all further partial
2107 * results for that frame are ignored by the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002108 */
2109 const camera_metadata_t *result;
2110
2111 /**
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002112 * The number of output buffers returned in this result structure. Must be
2113 * less than or equal to the matching capture request's count. If this is
2114 * less than the buffer count in the capture request, at least one more call
2115 * to process_capture_result with the same frame_number must be made, to
2116 * return the remaining output buffers to the framework. This may only be
Zhijun He52a18892014-06-30 10:35:58 -07002117 * zero if the structure includes valid result metadata or an input buffer
2118 * is returned in this result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002119 */
2120 uint32_t num_output_buffers;
2121
2122 /**
2123 * The handles for the output stream buffers for this capture. They may not
2124 * yet be filled at the time the HAL calls process_capture_result(); the
2125 * framework will wait on the release sync fences provided by the HAL before
2126 * reading the buffers.
2127 *
2128 * The HAL must set the stream buffer's release sync fence to a valid sync
2129 * fd, or to -1 if the buffer has already been filled.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08002130 *
2131 * If the HAL encounters an error while processing the buffer, and the
2132 * buffer is not filled, the buffer's status field must be set to
2133 * CAMERA3_BUFFER_STATUS_ERROR. If the HAL did not wait on the acquire fence
2134 * before encountering the error, the acquire fence should be copied into
2135 * the release fence, to allow the framework to wait on the fence before
2136 * reusing the buffer.
2137 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002138 * The acquire fence must be set to -1 for all output buffers. If
2139 * num_output_buffers is zero, this may be NULL. In that case, at least one
2140 * more process_capture_result call must be made by the HAL to provide the
2141 * output buffers.
Igor Murashkin5df2f622014-01-10 14:18:45 -08002142 *
2143 * When process_capture_result is called with a new buffer for a frame,
2144 * all previous frames' buffers for that corresponding stream must have been
2145 * already delivered (the fences need not have yet been signaled).
2146 *
2147 * >= CAMERA_DEVICE_API_VERSION_3_2:
2148 *
2149 * Gralloc buffers for a frame may be sent to framework before the
2150 * corresponding SHUTTER-notify.
2151 *
2152 * Performance considerations:
2153 *
2154 * Buffers delivered to the framework will not be dispatched to the
2155 * application layer until a start of exposure timestamp has been received
2156 * via a SHUTTER notify() call. It is highly recommended to
2157 * dispatch that call as early as possible.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002158 */
2159 const camera3_stream_buffer_t *output_buffers;
2160
Igor Murashkin5df2f622014-01-10 14:18:45 -08002161 /**
2162 * >= CAMERA_DEVICE_API_VERSION_3_2:
2163 *
Zhijun Heceac9e32014-02-05 20:49:45 -08002164 * The handle for the input stream buffer for this capture. It may not
2165 * yet be consumed at the time the HAL calls process_capture_result(); the
2166 * framework will wait on the release sync fences provided by the HAL before
2167 * reusing the buffer.
2168 *
2169 * The HAL should handle the sync fences the same way they are done for
2170 * output_buffers.
2171 *
2172 * Only one input buffer is allowed to be sent per request. Similarly to
2173 * output buffers, the ordering of returned input buffers must be
2174 * maintained by the HAL.
2175 *
2176 * Performance considerations:
2177 *
2178 * The input buffer should be returned as early as possible. If the HAL
2179 * supports sync fences, it can call process_capture_result to hand it back
2180 * with sync fences being set appropriately. If the sync fences are not
2181 * supported, the buffer can only be returned when it is consumed, which
2182 * may take long time; the HAL may choose to copy this input buffer to make
2183 * the buffer return sooner.
2184 */
2185 const camera3_stream_buffer_t *input_buffer;
2186
2187 /**
2188 * >= CAMERA_DEVICE_API_VERSION_3_2:
2189 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002190 * In order to take advantage of partial results, the HAL must set the
2191 * static metadata android.request.partialResultCount to the number of
2192 * partial results it will send for each frame.
2193 *
2194 * Each new capture result with a partial result must set
2195 * this field (partial_result) to a distinct inclusive value between
2196 * 1 and android.request.partialResultCount.
2197 *
2198 * HALs not wishing to take advantage of this feature must not
2199 * set an android.request.partialResultCount or partial_result to a value
2200 * other than 1.
2201 *
2202 * This value must be set to 0 when a capture result contains buffers only
2203 * and no metadata.
2204 */
2205 uint32_t partial_result;
2206
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002207} camera3_capture_result_t;
2208
2209/**********************************************************************
2210 *
2211 * Callback methods for the HAL to call into the framework.
2212 *
2213 * These methods are used to return metadata and image buffers for a completed
2214 * or failed captures, and to notify the framework of asynchronous events such
2215 * as errors.
2216 *
2217 * The framework will not call back into the HAL from within these callbacks,
2218 * and these calls will not block for extended periods.
2219 *
2220 */
2221typedef struct camera3_callback_ops {
2222
2223 /**
2224 * process_capture_result:
2225 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002226 * Send results from a completed capture to the framework.
2227 * process_capture_result() may be invoked multiple times by the HAL in
2228 * response to a single capture request. This allows, for example, the
2229 * metadata and low-resolution buffers to be returned in one call, and
2230 * post-processed JPEG buffers in a later call, once it is available. Each
2231 * call must include the frame number of the request it is returning
2232 * metadata or buffers for.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002233 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002234 * A component (buffer or metadata) of the complete result may only be
2235 * included in one process_capture_result call. A buffer for each stream,
2236 * and the result metadata, must be returned by the HAL for each request in
2237 * one of the process_capture_result calls, even in case of errors producing
2238 * some of the output. A call to process_capture_result() with neither
2239 * output buffers or result metadata is not allowed.
2240 *
2241 * The order of returning metadata and buffers for a single result does not
2242 * matter, but buffers for a given stream must be returned in FIFO order. So
2243 * the buffer for request 5 for stream A must always be returned before the
2244 * buffer for request 6 for stream A. This also applies to the result
2245 * metadata; the metadata for request 5 must be returned before the metadata
2246 * for request 6.
2247 *
2248 * However, different streams are independent of each other, so it is
2249 * acceptable and expected that the buffer for request 5 for stream A may be
2250 * returned after the buffer for request 6 for stream B is. And it is
2251 * acceptable that the result metadata for request 6 for stream B is
2252 * returned before the buffer for request 5 for stream A is.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002253 *
2254 * The HAL retains ownership of result structure, which only needs to be
2255 * valid to access during this call. The framework will copy whatever it
2256 * needs before this call returns.
2257 *
2258 * The output buffers do not need to be filled yet; the framework will wait
2259 * on the stream buffer release sync fence before reading the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002260 * data. Therefore, this method should be called by the HAL as soon as
2261 * possible, even if some or all of the output buffers are still in
2262 * being filled. The HAL must include valid release sync fences into each
2263 * output_buffers stream buffer entry, or -1 if that stream buffer is
2264 * already filled.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002265 *
2266 * If the result buffer cannot be constructed for a request, the HAL should
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002267 * return an empty metadata buffer, but still provide the output buffers and
2268 * their sync fences. In addition, notify() must be called with an
2269 * ERROR_RESULT message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002270 *
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08002271 * If an output buffer cannot be filled, its status field must be set to
2272 * STATUS_ERROR. In addition, notify() must be called with a ERROR_BUFFER
2273 * message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002274 *
2275 * If the entire capture has failed, then this method still needs to be
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08002276 * called to return the output buffers to the framework. All the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002277 * statuses should be STATUS_ERROR, and the result metadata should be an
2278 * empty buffer. In addition, notify() must be called with a ERROR_REQUEST
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002279 * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
2280 * should not be sent.
2281 *
Zhijun He2dde4682014-01-09 09:11:49 -08002282 * Performance requirements:
2283 *
2284 * This is a non-blocking call. The framework will return this call in 5ms.
2285 *
2286 * The pipeline latency (see S7 for definition) should be less than or equal to
2287 * 4 frame intervals, and must be less than or equal to 8 frame intervals.
2288 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002289 */
2290 void (*process_capture_result)(const struct camera3_callback_ops *,
2291 const camera3_capture_result_t *result);
2292
2293 /**
2294 * notify:
2295 *
2296 * Asynchronous notification callback from the HAL, fired for various
2297 * reasons. Only for information independent of frame capture, or that
2298 * require specific timing. The ownership of the message structure remains
2299 * with the HAL, and the msg only needs to be valid for the duration of this
2300 * call.
2301 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002302 * Multiple threads may call notify() simultaneously.
2303 *
2304 * <= CAMERA_DEVICE_API_VERSION_3_1:
2305 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002306 * The notification for the start of exposure for a given request must be
2307 * sent by the HAL before the first call to process_capture_result() for
2308 * that request is made.
2309 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002310 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002311 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002312 * Buffers delivered to the framework will not be dispatched to the
2313 * application layer until a start of exposure timestamp has been received
2314 * via a SHUTTER notify() call. It is highly recommended to
2315 * dispatch this call as early as possible.
2316 *
2317 * ------------------------------------------------------------------------
Zhijun He2dde4682014-01-09 09:11:49 -08002318 * Performance requirements:
2319 *
2320 * This is a non-blocking call. The framework will return this call in 5ms.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002321 */
2322 void (*notify)(const struct camera3_callback_ops *,
2323 const camera3_notify_msg_t *msg);
2324
2325} camera3_callback_ops_t;
2326
2327/**********************************************************************
2328 *
2329 * Camera device operations
2330 *
2331 */
2332typedef struct camera3_device_ops {
2333
2334 /**
2335 * initialize:
2336 *
2337 * One-time initialization to pass framework callback function pointers to
2338 * the HAL. Will be called once after a successful open() call, before any
2339 * other functions are called on the camera3_device_ops structure.
2340 *
Zhijun He2dde4682014-01-09 09:11:49 -08002341 * Performance requirements:
2342 *
2343 * This should be a non-blocking call. The HAL should return from this call
2344 * in 5ms, and must return from this call in 10ms.
2345 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002346 * Return values:
2347 *
2348 * 0: On successful initialization
2349 *
2350 * -ENODEV: If initialization fails. Only close() can be called successfully
2351 * by the framework after this.
2352 */
2353 int (*initialize)(const struct camera3_device *,
2354 const camera3_callback_ops_t *callback_ops);
2355
2356 /**********************************************************************
2357 * Stream management
2358 */
2359
2360 /**
2361 * configure_streams:
2362 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002363 * CAMERA_DEVICE_API_VERSION_3_0 only:
2364 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002365 * Reset the HAL camera device processing pipeline and set up new input and
2366 * output streams. This call replaces any existing stream configuration with
2367 * the streams defined in the stream_list. This method will be called at
2368 * least once after initialize() before a request is submitted with
2369 * process_capture_request().
2370 *
2371 * The stream_list must contain at least one output-capable stream, and may
2372 * not contain more than one input-capable stream.
2373 *
2374 * The stream_list may contain streams that are also in the currently-active
2375 * set of streams (from the previous call to configure_stream()). These
2376 * streams will already have valid values for usage, max_buffers, and the
Igor Murashkin78aa1262014-01-09 16:23:43 -08002377 * private pointer.
2378 *
2379 * If such a stream has already had its buffers registered,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002380 * register_stream_buffers() will not be called again for the stream, and
2381 * buffers from the stream can be immediately included in input requests.
2382 *
2383 * If the HAL needs to change the stream configuration for an existing
2384 * stream due to the new configuration, it may rewrite the values of usage
Igor Murashkin78aa1262014-01-09 16:23:43 -08002385 * and/or max_buffers during the configure call.
2386 *
2387 * The framework will detect such a change, and will then reallocate the
2388 * stream buffers, and call register_stream_buffers() again before using
2389 * buffers from that stream in a request.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002390 *
2391 * If a currently-active stream is not included in stream_list, the HAL may
2392 * safely remove any references to that stream. It will not be reused in a
2393 * later configure() call by the framework, and all the gralloc buffers for
2394 * it will be freed after the configure_streams() call returns.
2395 *
2396 * The stream_list structure is owned by the framework, and may not be
2397 * accessed once this call completes. The address of an individual
2398 * camera3_stream_t structure will remain valid for access by the HAL until
2399 * the end of the first configure_stream() call which no longer includes
2400 * that camera3_stream_t in the stream_list argument. The HAL may not change
2401 * values in the stream structure outside of the private pointer, except for
2402 * the usage and max_buffers members during the configure_streams() call
2403 * itself.
2404 *
2405 * If the stream is new, the usage, max_buffer, and private pointer fields
2406 * of the stream structure will all be set to 0. The HAL device must set
2407 * these fields before the configure_streams() call returns. These fields
2408 * are then used by the framework and the platform gralloc module to
2409 * allocate the gralloc buffers for each stream.
2410 *
2411 * Before such a new stream can have its buffers included in a capture
2412 * request, the framework will call register_stream_buffers() with that
2413 * stream. However, the framework is not required to register buffers for
2414 * _all_ streams before submitting a request. This allows for quick startup
2415 * of (for example) a preview stream, with allocation for other streams
2416 * happening later or concurrently.
2417 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002418 * ------------------------------------------------------------------------
2419 * CAMERA_DEVICE_API_VERSION_3_1 only:
2420 *
2421 * Reset the HAL camera device processing pipeline and set up new input and
2422 * output streams. This call replaces any existing stream configuration with
2423 * the streams defined in the stream_list. This method will be called at
2424 * least once after initialize() before a request is submitted with
2425 * process_capture_request().
2426 *
2427 * The stream_list must contain at least one output-capable stream, and may
2428 * not contain more than one input-capable stream.
2429 *
2430 * The stream_list may contain streams that are also in the currently-active
2431 * set of streams (from the previous call to configure_stream()). These
2432 * streams will already have valid values for usage, max_buffers, and the
2433 * private pointer.
2434 *
2435 * If such a stream has already had its buffers registered,
2436 * register_stream_buffers() will not be called again for the stream, and
2437 * buffers from the stream can be immediately included in input requests.
2438 *
2439 * If the HAL needs to change the stream configuration for an existing
2440 * stream due to the new configuration, it may rewrite the values of usage
2441 * and/or max_buffers during the configure call.
2442 *
2443 * The framework will detect such a change, and will then reallocate the
2444 * stream buffers, and call register_stream_buffers() again before using
2445 * buffers from that stream in a request.
2446 *
2447 * If a currently-active stream is not included in stream_list, the HAL may
2448 * safely remove any references to that stream. It will not be reused in a
2449 * later configure() call by the framework, and all the gralloc buffers for
2450 * it will be freed after the configure_streams() call returns.
2451 *
2452 * The stream_list structure is owned by the framework, and may not be
2453 * accessed once this call completes. The address of an individual
2454 * camera3_stream_t structure will remain valid for access by the HAL until
2455 * the end of the first configure_stream() call which no longer includes
2456 * that camera3_stream_t in the stream_list argument. The HAL may not change
2457 * values in the stream structure outside of the private pointer, except for
2458 * the usage and max_buffers members during the configure_streams() call
2459 * itself.
2460 *
2461 * If the stream is new, max_buffer, and private pointer fields of the
2462 * stream structure will all be set to 0. The usage will be set to the
2463 * consumer usage flags. The HAL device must set these fields before the
2464 * configure_streams() call returns. These fields are then used by the
2465 * framework and the platform gralloc module to allocate the gralloc
2466 * buffers for each stream.
2467 *
2468 * Before such a new stream can have its buffers included in a capture
2469 * request, the framework will call register_stream_buffers() with that
2470 * stream. However, the framework is not required to register buffers for
2471 * _all_ streams before submitting a request. This allows for quick startup
2472 * of (for example) a preview stream, with allocation for other streams
2473 * happening later or concurrently.
2474 *
2475 * ------------------------------------------------------------------------
2476 * >= CAMERA_DEVICE_API_VERSION_3_2:
2477 *
2478 * Reset the HAL camera device processing pipeline and set up new input and
2479 * output streams. This call replaces any existing stream configuration with
2480 * the streams defined in the stream_list. This method will be called at
2481 * least once after initialize() before a request is submitted with
2482 * process_capture_request().
2483 *
2484 * The stream_list must contain at least one output-capable stream, and may
2485 * not contain more than one input-capable stream.
2486 *
2487 * The stream_list may contain streams that are also in the currently-active
2488 * set of streams (from the previous call to configure_stream()). These
2489 * streams will already have valid values for usage, max_buffers, and the
2490 * private pointer.
2491 *
2492 * If the HAL needs to change the stream configuration for an existing
2493 * stream due to the new configuration, it may rewrite the values of usage
2494 * and/or max_buffers during the configure call.
2495 *
2496 * The framework will detect such a change, and may then reallocate the
2497 * stream buffers before using buffers from that stream in a request.
2498 *
2499 * If a currently-active stream is not included in stream_list, the HAL may
2500 * safely remove any references to that stream. It will not be reused in a
2501 * later configure() call by the framework, and all the gralloc buffers for
2502 * it will be freed after the configure_streams() call returns.
2503 *
2504 * The stream_list structure is owned by the framework, and may not be
2505 * accessed once this call completes. The address of an individual
2506 * camera3_stream_t structure will remain valid for access by the HAL until
2507 * the end of the first configure_stream() call which no longer includes
2508 * that camera3_stream_t in the stream_list argument. The HAL may not change
2509 * values in the stream structure outside of the private pointer, except for
2510 * the usage and max_buffers members during the configure_streams() call
2511 * itself.
2512 *
2513 * If the stream is new, max_buffer, and private pointer fields of the
2514 * stream structure will all be set to 0. The usage will be set to the
2515 * consumer usage flags. The HAL device must set these fields before the
2516 * configure_streams() call returns. These fields are then used by the
2517 * framework and the platform gralloc module to allocate the gralloc
2518 * buffers for each stream.
2519 *
2520 * Newly allocated buffers may be included in a capture request at any time
2521 * by the framework. Once a gralloc buffer is returned to the framework
2522 * with process_capture_result (and its respective release_fence has been
2523 * signaled) the framework may free or reuse it at any time.
2524 *
2525 * ------------------------------------------------------------------------
2526 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002527 * Preconditions:
2528 *
2529 * The framework will only call this method when no captures are being
2530 * processed. That is, all results have been returned to the framework, and
2531 * all in-flight input and output buffers have been returned and their
2532 * release sync fences have been signaled by the HAL. The framework will not
2533 * submit new requests for capture while the configure_streams() call is
2534 * underway.
2535 *
2536 * Postconditions:
2537 *
2538 * The HAL device must configure itself to provide maximum possible output
2539 * frame rate given the sizes and formats of the output streams, as
2540 * documented in the camera device's static metadata.
2541 *
Zhijun He2dde4682014-01-09 09:11:49 -08002542 * Performance requirements:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002543 *
2544 * This call is expected to be heavyweight and possibly take several hundred
2545 * milliseconds to complete, since it may require resetting and
2546 * reconfiguring the image sensor and the camera processing pipeline.
2547 * Nevertheless, the HAL device should attempt to minimize the
2548 * reconfiguration delay to minimize the user-visible pauses during
2549 * application operational mode changes (such as switching from still
2550 * capture to video recording).
2551 *
Zhijun He2dde4682014-01-09 09:11:49 -08002552 * The HAL should return from this call in 500ms, and must return from this
2553 * call in 1000ms.
2554 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002555 * Return values:
2556 *
2557 * 0: On successful stream configuration
2558 *
2559 * -EINVAL: If the requested stream configuration is invalid. Some examples
2560 * of invalid stream configurations include:
2561 *
2562 * - Including more than 1 input-capable stream (INPUT or
2563 * BIDIRECTIONAL)
2564 *
2565 * - Not including any output-capable streams (OUTPUT or
2566 * BIDIRECTIONAL)
2567 *
2568 * - Including streams with unsupported formats, or an unsupported
2569 * size for that format.
2570 *
2571 * - Including too many output streams of a certain format.
2572 *
Eino-Ville Talvala7effe0c2013-02-15 12:09:48 -08002573 * Note that the framework submitting an invalid stream
2574 * configuration is not normal operation, since stream
2575 * configurations are checked before configure. An invalid
2576 * configuration means that a bug exists in the framework code, or
2577 * there is a mismatch between the HAL's static metadata and the
2578 * requirements on streams.
2579 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002580 * -ENODEV: If there has been a fatal error and the device is no longer
2581 * operational. Only close() can be called successfully by the
2582 * framework after this error is returned.
2583 */
2584 int (*configure_streams)(const struct camera3_device *,
2585 camera3_stream_configuration_t *stream_list);
2586
2587 /**
2588 * register_stream_buffers:
2589 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002590 * >= CAMERA_DEVICE_API_VERSION_3_2:
2591 *
2592 * DEPRECATED. This will not be called and must be set to NULL.
2593 *
2594 * <= CAMERA_DEVICE_API_VERSION_3_1:
2595 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002596 * Register buffers for a given stream with the HAL device. This method is
2597 * called by the framework after a new stream is defined by
2598 * configure_streams, and before buffers from that stream are included in a
2599 * capture request. If the same stream is listed in a subsequent
2600 * configure_streams() call, register_stream_buffers will _not_ be called
2601 * again for that stream.
2602 *
2603 * The framework does not need to register buffers for all configured
2604 * streams before it submits the first capture request. This allows quick
2605 * startup for preview (or similar use cases) while other streams are still
2606 * being allocated.
2607 *
2608 * This method is intended to allow the HAL device to map or otherwise
2609 * prepare the buffers for later use. The buffers passed in will already be
2610 * locked for use. At the end of the call, all the buffers must be ready to
2611 * be returned to the stream. The buffer_set argument is only valid for the
2612 * duration of this call.
2613 *
2614 * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
2615 * the camera HAL should inspect the passed-in buffers here to determine any
2616 * platform-private pixel format information.
2617 *
Zhijun He2dde4682014-01-09 09:11:49 -08002618 * Performance requirements:
2619 *
2620 * This should be a non-blocking call. The HAL should return from this call
2621 * in 1ms, and must return from this call in 5ms.
2622 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002623 * Return values:
2624 *
2625 * 0: On successful registration of the new stream buffers
2626 *
2627 * -EINVAL: If the stream_buffer_set does not refer to a valid active
2628 * stream, or if the buffers array is invalid.
2629 *
2630 * -ENOMEM: If there was a failure in registering the buffers. The framework
2631 * must consider all the stream buffers to be unregistered, and can
2632 * try to register again later.
2633 *
2634 * -ENODEV: If there is a fatal error, and the device is no longer
2635 * operational. Only close() can be called successfully by the
2636 * framework after this error is returned.
2637 */
2638 int (*register_stream_buffers)(const struct camera3_device *,
2639 const camera3_stream_buffer_set_t *buffer_set);
2640
2641 /**********************************************************************
2642 * Request creation and submission
2643 */
2644
2645 /**
2646 * construct_default_request_settings:
2647 *
2648 * Create capture settings for standard camera use cases.
2649 *
2650 * The device must return a settings buffer that is configured to meet the
2651 * requested use case, which must be one of the CAMERA3_TEMPLATE_*
2652 * enums. All request control fields must be included.
2653 *
2654 * The HAL retains ownership of this structure, but the pointer to the
2655 * structure must be valid until the device is closed. The framework and the
2656 * HAL may not modify the buffer once it is returned by this call. The same
2657 * buffer may be returned for subsequent calls for the same template, or for
2658 * other templates.
2659 *
Zhijun He2dde4682014-01-09 09:11:49 -08002660 * Performance requirements:
2661 *
2662 * This should be a non-blocking call. The HAL should return from this call
2663 * in 1ms, and must return from this call in 5ms.
2664 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002665 * Return values:
2666 *
2667 * Valid metadata: On successful creation of a default settings
2668 * buffer.
2669 *
2670 * NULL: In case of a fatal error. After this is returned, only
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002671 * the close() method can be called successfully by the
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002672 * framework.
2673 */
2674 const camera_metadata_t* (*construct_default_request_settings)(
2675 const struct camera3_device *,
2676 int type);
2677
2678 /**
2679 * process_capture_request:
2680 *
2681 * Send a new capture request to the HAL. The HAL should not return from
2682 * this call until it is ready to accept the next request to process. Only
2683 * one call to process_capture_request() will be made at a time by the
2684 * framework, and the calls will all be from the same thread. The next call
2685 * to process_capture_request() will be made as soon as a new request and
2686 * its associated buffers are available. In a normal preview scenario, this
2687 * means the function will be called again by the framework almost
2688 * instantly.
2689 *
2690 * The actual request processing is asynchronous, with the results of
2691 * capture being returned by the HAL through the process_capture_result()
2692 * call. This call requires the result metadata to be available, but output
2693 * buffers may simply provide sync fences to wait on. Multiple requests are
2694 * expected to be in flight at once, to maintain full output frame rate.
2695 *
2696 * The framework retains ownership of the request structure. It is only
2697 * guaranteed to be valid during this call. The HAL device must make copies
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002698 * of the information it needs to retain for the capture processing. The HAL
2699 * is responsible for waiting on and closing the buffers' fences and
2700 * returning the buffer handles to the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002701 *
2702 * The HAL must write the file descriptor for the input buffer's release
2703 * sync fence into input_buffer->release_fence, if input_buffer is not
2704 * NULL. If the HAL returns -1 for the input buffer release sync fence, the
2705 * framework is free to immediately reuse the input buffer. Otherwise, the
2706 * framework will wait on the sync fence before refilling and reusing the
2707 * input buffer.
2708 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002709 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002710 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002711 * The input/output buffers provided by the framework in each request
2712 * may be brand new (having never before seen by the HAL).
2713 *
2714 * ------------------------------------------------------------------------
2715 * Performance considerations:
2716 *
2717 * Handling a new buffer should be extremely lightweight and there should be
2718 * no frame rate degradation or frame jitter introduced.
2719 *
2720 * This call must return fast enough to ensure that the requested frame
2721 * rate can be sustained, especially for streaming cases (post-processing
2722 * quality settings set to FAST). The HAL should return this call in 1
2723 * frame interval, and must return from this call in 4 frame intervals.
Zhijun He2dde4682014-01-09 09:11:49 -08002724 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002725 * Return values:
2726 *
2727 * 0: On a successful start to processing the capture request
2728 *
2729 * -EINVAL: If the input is malformed (the settings are NULL when not
2730 * allowed, there are 0 output buffers, etc) and capture processing
2731 * cannot start. Failures during request processing should be
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002732 * handled by calling camera3_callback_ops_t.notify(). In case of
2733 * this error, the framework will retain responsibility for the
2734 * stream buffers' fences and the buffer handles; the HAL should
2735 * not close the fences or return these buffers with
2736 * process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002737 *
2738 * -ENODEV: If the camera device has encountered a serious error. After this
2739 * error is returned, only the close() method can be successfully
2740 * called by the framework.
2741 *
2742 */
2743 int (*process_capture_request)(const struct camera3_device *,
2744 camera3_capture_request_t *request);
2745
2746 /**********************************************************************
2747 * Miscellaneous methods
2748 */
2749
2750 /**
2751 * get_metadata_vendor_tag_ops:
2752 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002753 * Get methods to query for vendor extension metadata tag information. The
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002754 * HAL should fill in all the vendor tag operation methods, or leave ops
2755 * unchanged if no vendor tags are defined.
2756 *
2757 * The definition of vendor_tag_query_ops_t can be found in
2758 * system/media/camera/include/system/camera_metadata.h.
2759 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -08002760 * >= CAMERA_DEVICE_API_VERSION_3_2:
2761 * DEPRECATED. This function has been deprecated and should be set to
2762 * NULL by the HAL. Please implement get_vendor_tag_ops in camera_common.h
2763 * instead.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002764 */
2765 void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
2766 vendor_tag_query_ops_t* ops);
2767
2768 /**
2769 * dump:
2770 *
2771 * Print out debugging state for the camera device. This will be called by
2772 * the framework when the camera service is asked for a debug dump, which
2773 * happens when using the dumpsys tool, or when capturing a bugreport.
2774 *
2775 * The passed-in file descriptor can be used to write debugging text using
2776 * dprintf() or write(). The text should be in ASCII encoding only.
Zhijun He2dde4682014-01-09 09:11:49 -08002777 *
2778 * Performance requirements:
2779 *
2780 * This must be a non-blocking call. The HAL should return from this call
2781 * in 1ms, must return from this call in 10ms. This call must avoid
2782 * deadlocks, as it may be called at any point during camera operation.
2783 * Any synchronization primitives used (such as mutex locks or semaphores)
2784 * should be acquired with a timeout.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002785 */
2786 void (*dump)(const struct camera3_device *, int fd);
2787
Alex Ray5f2fd852013-06-24 11:28:05 -07002788 /**
2789 * flush:
2790 *
2791 * Flush all currently in-process captures and all buffers in the pipeline
2792 * on the given device. The framework will use this to dump all state as
2793 * quickly as possible in order to prepare for a configure_streams() call.
2794 *
2795 * No buffers are required to be successfully returned, so every buffer
Zhijun He5a5fbf42014-01-27 14:49:44 -08002796 * held at the time of flush() (whether successfully filled or not) may be
Alex Ray5f2fd852013-06-24 11:28:05 -07002797 * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed
Zhijun He5a5fbf42014-01-27 14:49:44 -08002798 * to return valid (CAMERA3_BUFFER_STATUS_OK) buffers during this call,
2799 * provided they are successfully filled.
Alex Ray5f2fd852013-06-24 11:28:05 -07002800 *
2801 * All requests currently in the HAL are expected to be returned as soon as
2802 * possible. Not-in-process requests should return errors immediately. Any
2803 * interruptible hardware blocks should be stopped, and any uninterruptible
2804 * blocks should be waited on.
2805 *
Zhijun He5a5fbf42014-01-27 14:49:44 -08002806 * More specifically, the HAL must follow below requirements for various cases:
2807 *
2808 * 1. For captures that are too late for the HAL to cancel/stop, and will be
2809 * completed normally by the HAL; i.e. the HAL can send shutter/notify and
2810 * process_capture_result and buffers as normal.
2811 *
2812 * 2. For pending requests that have not done any processing, the HAL must call notify
2813 * CAMERA3_MSG_ERROR_REQUEST, and return all the output buffers with
2814 * process_capture_result in the error state (CAMERA3_BUFFER_STATUS_ERROR).
2815 * The HAL must not place the release fence into an error state, instead,
2816 * the release fences must be set to the acquire fences passed by the framework,
2817 * or -1 if they have been waited on by the HAL already. This is also the path
2818 * to follow for any captures for which the HAL already called notify() with
2819 * CAMERA3_MSG_SHUTTER but won't be producing any metadata/valid buffers for.
2820 * After CAMERA3_MSG_ERROR_REQUEST, for a given frame, only process_capture_results with
2821 * buffers in CAMERA3_BUFFER_STATUS_ERROR are allowed. No further notifys or
2822 * process_capture_result with non-null metadata is allowed.
2823 *
2824 * 3. For partially completed pending requests that will not have all the output
2825 * buffers or perhaps missing metadata, the HAL should follow below:
2826 *
2827 * 3.1. Call notify with CAMERA3_MSG_ERROR_RESULT if some of the expected result
2828 * metadata (i.e. one or more partial metadata) won't be available for the capture.
2829 *
2830 * 3.2. Call notify with CAMERA3_MSG_ERROR_BUFFER for every buffer that won't
2831 * be produced for the capture.
2832 *
2833 * 3.3 Call notify with CAMERA3_MSG_SHUTTER with the capture timestamp before
2834 * any buffers/metadata are returned with process_capture_result.
2835 *
2836 * 3.4 For captures that will produce some results, the HAL must not call
2837 * CAMERA3_MSG_ERROR_REQUEST, since that indicates complete failure.
2838 *
2839 * 3.5. Valid buffers/metadata should be passed to the framework as normal.
2840 *
2841 * 3.6. Failed buffers should be returned to the framework as described for case 2.
2842 * But failed buffers do not have to follow the strict ordering valid buffers do,
2843 * and may be out-of-order with respect to valid buffers. For example, if buffers
2844 * A, B, C, D, E are sent, D and E are failed, then A, E, B, D, C is an acceptable
2845 * return order.
2846 *
2847 * 3.7. For fully-missing metadata, calling CAMERA3_MSG_ERROR_RESULT is sufficient, no
2848 * need to call process_capture_result with NULL metadata or equivalent.
2849 *
Alex Ray5f2fd852013-06-24 11:28:05 -07002850 * flush() should only return when there are no more outstanding buffers or
Zhijun He5a5fbf42014-01-27 14:49:44 -08002851 * requests left in the HAL. The framework may call configure_streams (as
Alex Ray5f2fd852013-06-24 11:28:05 -07002852 * the HAL state is now quiesced) or may issue new requests.
2853 *
Zhijun He5a5fbf42014-01-27 14:49:44 -08002854 * Note that it's sufficient to only support fully-succeeded and fully-failed result cases.
2855 * However, it is highly desirable to support the partial failure cases as well, as it
2856 * could help improve the flush call overall performance.
2857 *
Zhijun He2dde4682014-01-09 09:11:49 -08002858 * Performance requirements:
2859 *
2860 * The HAL should return from this call in 100ms, and must return from this
2861 * call in 1000ms. And this call must not be blocked longer than pipeline
2862 * latency (see S7 for definition).
Alex Ray5f2fd852013-06-24 11:28:05 -07002863 *
2864 * Version information:
2865 *
2866 * only available if device version >= CAMERA_DEVICE_API_VERSION_3_1.
2867 *
2868 * Return values:
2869 *
2870 * 0: On a successful flush of the camera HAL.
2871 *
2872 * -EINVAL: If the input is malformed (the device is not valid).
2873 *
2874 * -ENODEV: If the camera device has encountered a serious error. After this
2875 * error is returned, only the close() method can be successfully
2876 * called by the framework.
2877 */
2878 int (*flush)(const struct camera3_device *);
2879
2880 /* reserved for future use */
2881 void *reserved[8];
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002882} camera3_device_ops_t;
2883
2884/**********************************************************************
2885 *
2886 * Camera device definition
2887 *
2888 */
2889typedef struct camera3_device {
2890 /**
2891 * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
2892 * device as implementing version 3.0 of the camera device HAL.
Zhijun He2dde4682014-01-09 09:11:49 -08002893 *
2894 * Performance requirements:
2895 *
Zhijun He06da1b32014-02-10 16:04:23 -08002896 * Camera open (common.module->common.methods->open) should return in 200ms, and must return
2897 * in 500ms.
Zhijun He2020ee22014-01-31 11:35:45 -08002898 * Camera close (common.close) should return in 200ms, and must return in 500ms.
2899 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002900 */
2901 hw_device_t common;
2902 camera3_device_ops_t *ops;
2903 void *priv;
2904} camera3_device_t;
2905
2906__END_DECLS
2907
2908#endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */