blob: b0240901c6f77cc7f0d81ed03ae8f71ef46d8dbf [file] [log] [blame]
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_INCLUDE_CAMERA3_H
18#define ANDROID_INCLUDE_CAMERA3_H
19
Eino-Ville Talvala7effe0c2013-02-15 12:09:48 -080020#include <system/camera_metadata.h>
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080021#include "camera_common.h"
22
23/**
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080024 * Camera device HAL 3.2 [ CAMERA_DEVICE_API_VERSION_3_2 ]
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080025 *
26 * EXPERIMENTAL.
27 *
28 * Supports the android.hardware.Camera API.
29 *
30 * Camera devices that support this version of the HAL must return
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080031 * CAMERA_DEVICE_API_VERSION_3_2 in camera_device_t.common.version and in
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080032 * camera_info_t.device_version (from camera_module_t.get_camera_info).
33 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080034 * CAMERA_DEVICE_API_VERSION_3_2:
35 * Camera modules that may contain version 3.2 devices must implement at
36 * least version 2.2 of the camera module interface (as defined by
37 * camera_module_t.common.module_api_version).
38 *
39 * <= CAMERA_DEVICE_API_VERSION_3_1:
40 * Camera modules that may contain version 3.1 (or 3.0) devices must
41 * implement at least version 2.0 of the camera module interface
42 * (as defined by camera_module_t.common.module_api_version).
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080043 *
44 * See camera_common.h for more versioning details.
45 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070046 * Documentation index:
47 * S1. Version history
48 * S2. Startup and operation sequencing
49 * S3. Operational modes
50 * S4. 3A modes and state machines
Eino-Ville Talvalab6059442013-04-29 15:26:16 -070051 * S5. Cropping
52 * S6. Error management
Zhijun He709e5872014-01-17 15:25:21 -080053 * S7. Key Performance Indicator (KPI) glossary
Zhijun Hebc358682014-01-23 14:42:54 -080054 * S8. Sample Use Cases
Ruben Brunk2d96c742014-03-18 13:39:17 -070055 * S9. Notes on Controls and Metadata
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070056 */
57
58/**
59 * S1. Version history:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080060 *
61 * 1.0: Initial Android camera HAL (Android 4.0) [camera.h]:
62 *
63 * - Converted from C++ CameraHardwareInterface abstraction layer.
64 *
65 * - Supports android.hardware.Camera API.
66 *
67 * 2.0: Initial release of expanded-capability HAL (Android 4.2) [camera2.h]:
68 *
69 * - Sufficient for implementing existing android.hardware.Camera API.
70 *
71 * - Allows for ZSL queue in camera service layer
72 *
73 * - Not tested for any new features such manual capture control, Bayer RAW
74 * capture, reprocessing of RAW data.
75 *
76 * 3.0: First revision of expanded-capability HAL:
77 *
78 * - Major version change since the ABI is completely different. No change to
79 * the required hardware capabilities or operational model from 2.0.
80 *
81 * - Reworked input request and stream queue interfaces: Framework calls into
82 * HAL with next request and stream buffers already dequeued. Sync framework
83 * support is included, necessary for efficient implementations.
84 *
85 * - Moved triggers into requests, most notifications into results.
86 *
87 * - Consolidated all callbacks into framework into one structure, and all
88 * setup methods into a single initialize() call.
89 *
90 * - Made stream configuration into a single call to simplify stream
91 * management. Bidirectional streams replace STREAM_FROM_STREAM construct.
92 *
93 * - Limited mode semantics for older/limited hardware devices.
Alex Ray2ce219a2013-06-14 15:09:30 -070094 *
95 * 3.1: Minor revision of expanded-capability HAL:
96 *
97 * - configure_streams passes consumer usage flags to the HAL.
Alex Ray5f2fd852013-06-24 11:28:05 -070098 *
99 * - flush call to drop all in-flight requests/buffers as fast as possible.
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800100 *
101 * 3.2: Minor revision of expanded-capability HAL:
102 *
103 * - Deprecates get_metadata_vendor_tag_ops. Please use get_vendor_tag_ops
104 * in camera_common.h instead.
Igor Murashkin78aa1262014-01-09 16:23:43 -0800105 *
106 * - register_stream_buffers deprecated. All gralloc buffers provided
107 * by framework to HAL in process_capture_request may be new at any time.
Igor Murashkin5df2f622014-01-10 14:18:45 -0800108 *
109 * - add partial result support. process_capture_result may be called
110 * multiple times with a subset of the available result before the full
111 * result is available.
Zhijun Hebc358682014-01-23 14:42:54 -0800112 *
113 * - add manual template to camera3_request_template. The applications may
114 * use this template to control the capture settings directly.
115 *
116 * - Rework the bidirectional and input stream specifications.
117 *
Zhijun Heceac9e32014-02-05 20:49:45 -0800118 * - change the input buffer return path. The buffer is returned in
119 * process_capture_result instead of process_capture_request.
120 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800121 */
122
123/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700124 * S2. Startup and general expected operation sequence:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800125 *
126 * 1. Framework calls camera_module_t->common.open(), which returns a
127 * hardware_device_t structure.
128 *
129 * 2. Framework inspects the hardware_device_t->version field, and instantiates
130 * the appropriate handler for that version of the camera hardware device. In
131 * case the version is CAMERA_DEVICE_API_VERSION_3_0, the device is cast to
132 * a camera3_device_t.
133 *
134 * 3. Framework calls camera3_device_t->ops->initialize() with the framework
135 * callback function pointers. This will only be called this one time after
136 * open(), before any other functions in the ops structure are called.
137 *
138 * 4. The framework calls camera3_device_t->ops->configure_streams() with a list
139 * of input/output streams to the HAL device.
140 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800141 * 5. <= CAMERA_DEVICE_API_VERSION_3_1:
142 *
143 * The framework allocates gralloc buffers and calls
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800144 * camera3_device_t->ops->register_stream_buffers() for at least one of the
145 * output streams listed in configure_streams. The same stream is registered
146 * only once.
147 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800148 * >= CAMERA_DEVICE_API_VERSION_3_2:
149 *
150 * camera3_device_t->ops->register_stream_buffers() is not called and must
151 * be NULL.
152 *
153 * 6. The framework requests default settings for some number of use cases with
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800154 * calls to camera3_device_t->ops->construct_default_request_settings(). This
155 * may occur any time after step 3.
156 *
157 * 7. The framework constructs and sends the first capture request to the HAL,
158 * with settings based on one of the sets of default settings, and with at
159 * least one output stream, which has been registered earlier by the
160 * framework. This is sent to the HAL with
161 * camera3_device_t->ops->process_capture_request(). The HAL must block the
162 * return of this call until it is ready for the next request to be sent.
163 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800164 * >= CAMERA_DEVICE_API_VERSION_3_2:
165 *
166 * The buffer_handle_t provided in the camera3_stream_buffer_t array
167 * in the camera3_capture_request_t may be new and never-before-seen
168 * by the HAL on any given new request.
169 *
170 * 8. The framework continues to submit requests, and call
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800171 * construct_default_request_settings to get default settings buffers for
172 * other use cases.
173 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800174 * <= CAMERA_DEVICE_API_VERSION_3_1:
175 *
176 * The framework may call register_stream_buffers() at this time for
177 * not-yet-registered streams.
178 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800179 * 9. When the capture of a request begins (sensor starts exposing for the
180 * capture), the HAL calls camera3_callback_ops_t->notify() with the SHUTTER
181 * event, including the frame number and the timestamp for start of exposure.
Igor Murashkin5df2f622014-01-10 14:18:45 -0800182 *
183 * <= CAMERA_DEVICE_API_VERSION_3_1:
184 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -0700185 * This notify call must be made before the first call to
186 * process_capture_result() for that frame number.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800187 *
Igor Murashkin5df2f622014-01-10 14:18:45 -0800188 * >= CAMERA_DEVICE_API_VERSION_3_2:
189 *
190 * The camera3_callback_ops_t->notify() call with the SHUTTER event should
191 * be made as early as possible since the framework will be unable to
192 * deliver gralloc buffers to the application layer (for that frame) until
193 * it has a valid timestamp for the start of exposure.
194 *
195 * Both partial metadata results and the gralloc buffers may be sent to the
196 * framework at any time before or after the SHUTTER event.
197 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800198 * 10. After some pipeline delay, the HAL begins to return completed captures to
199 * the framework with camera3_callback_ops_t->process_capture_result(). These
200 * are returned in the same order as the requests were submitted. Multiple
201 * requests can be in flight at once, depending on the pipeline depth of the
202 * camera HAL device.
203 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800204 * >= CAMERA_DEVICE_API_VERSION_3_2:
205 *
206 * Once a buffer is returned by process_capture_result as part of the
207 * camera3_stream_buffer_t array, and the fence specified by release_fence
208 * has been signaled (this is a no-op for -1 fences), the ownership of that
209 * buffer is considered to be transferred back to the framework. After that,
210 * the HAL must no longer retain that particular buffer, and the
211 * framework may clean up the memory for it immediately.
212 *
Igor Murashkin5df2f622014-01-10 14:18:45 -0800213 * process_capture_result may be called multiple times for a single frame,
214 * each time with a new disjoint piece of metadata and/or set of gralloc
215 * buffers. The framework will accumulate these partial metadata results
216 * into one result.
217 *
218 * In particular, it is legal for a process_capture_result to be called
219 * simultaneously for both a frame N and a frame N+1 as long as the
Zhijun Heceac9e32014-02-05 20:49:45 -0800220 * above rule holds for gralloc buffers (both input and output).
Igor Murashkin5df2f622014-01-10 14:18:45 -0800221 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800222 * 11. After some time, the framework may stop submitting new requests, wait for
223 * the existing captures to complete (all buffers filled, all results
224 * returned), and then call configure_streams() again. This resets the camera
225 * hardware and pipeline for a new set of input/output streams. Some streams
226 * may be reused from the previous configuration; if these streams' buffers
227 * had already been registered with the HAL, they will not be registered
228 * again. The framework then continues from step 7, if at least one
229 * registered output stream remains (otherwise, step 5 is required first).
230 *
231 * 12. Alternatively, the framework may call camera3_device_t->common->close()
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -0800232 * to end the camera session. This may be called at any time when no other
233 * calls from the framework are active, although the call may block until all
234 * in-flight captures have completed (all results returned, all buffers
235 * filled). After the close call returns, no more calls to the
236 * camera3_callback_ops_t functions are allowed from the HAL. Once the
237 * close() call is underway, the framework may not call any other HAL device
238 * functions.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800239 *
240 * 13. In case of an error or other asynchronous event, the HAL must call
241 * camera3_callback_ops_t->notify() with the appropriate error/event
242 * message. After returning from a fatal device-wide error notification, the
243 * HAL should act as if close() had been called on it. However, the HAL must
244 * either cancel or complete all outstanding captures before calling
245 * notify(), so that once notify() is called with a fatal error, the
246 * framework will not receive further callbacks from the device. Methods
247 * besides close() should return -ENODEV or NULL after the notify() method
248 * returns from a fatal error message.
249 */
250
251/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700252 * S3. Operational modes:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800253 *
254 * The camera 3 HAL device can implement one of two possible operational modes;
255 * limited and full. Full support is expected from new higher-end
256 * devices. Limited mode has hardware requirements roughly in line with those
257 * for a camera HAL device v1 implementation, and is expected from older or
258 * inexpensive devices. Full is a strict superset of limited, and they share the
259 * same essential operational flow, as documented above.
260 *
261 * The HAL must indicate its level of support with the
262 * android.info.supportedHardwareLevel static metadata entry, with 0 indicating
263 * limited mode, and 1 indicating full mode support.
264 *
265 * Roughly speaking, limited-mode devices do not allow for application control
266 * of capture settings (3A control only), high-rate capture of high-resolution
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700267 * images, raw sensor readout, or support for YUV output streams above maximum
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800268 * recording resolution (JPEG only for large images).
269 *
270 * ** Details of limited mode behavior:
271 *
272 * - Limited-mode devices do not need to implement accurate synchronization
273 * between capture request settings and the actual image data
274 * captured. Instead, changes to settings may take effect some time in the
275 * future, and possibly not for the same output frame for each settings
276 * entry. Rapid changes in settings may result in some settings never being
277 * used for a capture. However, captures that include high-resolution output
278 * buffers ( > 1080p ) have to use the settings as specified (but see below
279 * for processing rate).
280 *
281 * - Limited-mode devices do not need to support most of the
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700282 * settings/result/static info metadata. Specifically, only the following settings
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800283 * are expected to be consumed or produced by a limited-mode HAL device:
284 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700285 * android.control.aeAntibandingMode (controls and dynamic)
286 * android.control.aeExposureCompensation (controls and dynamic)
287 * android.control.aeLock (controls and dynamic)
288 * android.control.aeMode (controls and dynamic)
289 * android.control.aeRegions (controls and dynamic)
290 * android.control.aeTargetFpsRange (controls and dynamic)
291 * android.control.aePrecaptureTrigger (controls and dynamic)
292 * android.control.afMode (controls and dynamic)
293 * android.control.afRegions (controls and dynamic)
294 * android.control.awbLock (controls and dynamic)
295 * android.control.awbMode (controls and dynamic)
296 * android.control.awbRegions (controls and dynamic)
297 * android.control.captureIntent (controls and dynamic)
298 * android.control.effectMode (controls and dynamic)
299 * android.control.mode (controls and dynamic)
300 * android.control.sceneMode (controls and dynamic)
301 * android.control.videoStabilizationMode (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800302 * android.control.aeAvailableAntibandingModes (static)
303 * android.control.aeAvailableModes (static)
304 * android.control.aeAvailableTargetFpsRanges (static)
305 * android.control.aeCompensationRange (static)
306 * android.control.aeCompensationStep (static)
307 * android.control.afAvailableModes (static)
308 * android.control.availableEffects (static)
309 * android.control.availableSceneModes (static)
310 * android.control.availableVideoStabilizationModes (static)
311 * android.control.awbAvailableModes (static)
312 * android.control.maxRegions (static)
313 * android.control.sceneModeOverrides (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800314 * android.control.aeState (dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800315 * android.control.afState (dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800316 * android.control.awbState (dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800317 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700318 * android.flash.mode (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800319 * android.flash.info.available (static)
320 *
321 * android.info.supportedHardwareLevel (static)
322 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700323 * android.jpeg.gpsCoordinates (controls and dynamic)
324 * android.jpeg.gpsProcessingMethod (controls and dynamic)
325 * android.jpeg.gpsTimestamp (controls and dynamic)
326 * android.jpeg.orientation (controls and dynamic)
327 * android.jpeg.quality (controls and dynamic)
328 * android.jpeg.thumbnailQuality (controls and dynamic)
329 * android.jpeg.thumbnailSize (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800330 * android.jpeg.availableThumbnailSizes (static)
331 * android.jpeg.maxSize (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800332 *
333 * android.lens.info.minimumFocusDistance (static)
334 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700335 * android.request.id (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800336 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700337 * android.scaler.cropRegion (controls and dynamic)
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -0800338 * android.scaler.availableStreamConfigurations (static)
339 * android.scaler.availableMinFrameDurations (static)
340 * android.scaler.availableStallDurations (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800341 * android.scaler.availableMaxDigitalZoom (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800342 * android.scaler.maxDigitalZoom (static)
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700343 * android.scaler.croppingType (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800344 *
345 * android.sensor.orientation (static)
346 * android.sensor.timestamp (dynamic)
347 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700348 * android.statistics.faceDetectMode (controls and dynamic)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800349 * android.statistics.info.availableFaceDetectModes (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800350 * android.statistics.faceIds (dynamic)
351 * android.statistics.faceLandmarks (dynamic)
352 * android.statistics.faceRectangles (dynamic)
353 * android.statistics.faceScores (dynamic)
354 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700355 * android.sync.frameNumber (dynamic)
356 * android.sync.maxLatency (static)
357 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800358 * - Captures in limited mode that include high-resolution (> 1080p) output
359 * buffers may block in process_capture_request() until all the output buffers
360 * have been filled. A full-mode HAL device must process sequences of
361 * high-resolution requests at the rate indicated in the static metadata for
362 * that pixel format. The HAL must still call process_capture_result() to
363 * provide the output; the framework must simply be prepared for
364 * process_capture_request() to block until after process_capture_result() for
365 * that request completes for high-resolution captures for limited-mode
366 * devices.
367 *
Zhijun He1ab5c5e2014-05-26 17:35:50 -0700368 * - Full-mode devices must support below additional capabilities:
369 * - 30fps at maximum resolution is preferred, more than 20fps is required.
370 * - Per frame control (android.sync.maxLatency == PER_FRAME_CONTROL).
371 * - Sensor manual control metadata. See MANUAL_SENSOR defined in
372 * android.request.availableCapabilities.
373 * - Post-processing manual control metadata. See MANUAL_POST_PROCESSING defined
374 * in android.request.availableCapabilities.
375 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800376 */
377
378/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700379 * S4. 3A modes and state machines:
380 *
381 * While the actual 3A algorithms are up to the HAL implementation, a high-level
382 * state machine description is defined by the HAL interface, to allow the HAL
383 * device and the framework to communicate about the current state of 3A, and to
384 * trigger 3A events.
385 *
386 * When the device is opened, all the individual 3A states must be
387 * STATE_INACTIVE. Stream configuration does not reset 3A. For example, locked
388 * focus must be maintained across the configure() call.
389 *
390 * Triggering a 3A action involves simply setting the relevant trigger entry in
391 * the settings for the next request to indicate start of trigger. For example,
392 * the trigger for starting an autofocus scan is setting the entry
393 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTROL_AF_TRIGGER_START for one
394 * request, and cancelling an autofocus scan is triggered by setting
395 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTRL_AF_TRIGGER_CANCEL. Otherwise,
396 * the entry will not exist, or be set to ANDROID_CONTROL_AF_TRIGGER_IDLE. Each
397 * request with a trigger entry set to a non-IDLE value will be treated as an
398 * independent triggering event.
399 *
400 * At the top level, 3A is controlled by the ANDROID_CONTROL_MODE setting, which
401 * selects between no 3A (ANDROID_CONTROL_MODE_OFF), normal AUTO mode
402 * (ANDROID_CONTROL_MODE_AUTO), and using the scene mode setting
403 * (ANDROID_CONTROL_USE_SCENE_MODE).
404 *
405 * - In OFF mode, each of the individual AE/AF/AWB modes are effectively OFF,
406 * and none of the capture controls may be overridden by the 3A routines.
407 *
408 * - In AUTO mode, Auto-focus, auto-exposure, and auto-whitebalance all run
409 * their own independent algorithms, and have their own mode, state, and
410 * trigger metadata entries, as listed in the next section.
411 *
412 * - In USE_SCENE_MODE, the value of the ANDROID_CONTROL_SCENE_MODE entry must
413 * be used to determine the behavior of 3A routines. In SCENE_MODEs other than
414 * FACE_PRIORITY, the HAL must override the values of
415 * ANDROId_CONTROL_AE/AWB/AF_MODE to be the mode it prefers for the selected
416 * SCENE_MODE. For example, the HAL may prefer SCENE_MODE_NIGHT to use
417 * CONTINUOUS_FOCUS AF mode. Any user selection of AE/AWB/AF_MODE when scene
418 * must be ignored for these scene modes.
419 *
420 * - For SCENE_MODE_FACE_PRIORITY, the AE/AWB/AF_MODE controls work as in
421 * ANDROID_CONTROL_MODE_AUTO, but the 3A routines must bias toward metering
422 * and focusing on any detected faces in the scene.
423 *
424 * S4.1. Auto-focus settings and result entries:
425 *
426 * Main metadata entries:
427 *
428 * ANDROID_CONTROL_AF_MODE: Control for selecting the current autofocus
429 * mode. Set by the framework in the request settings.
430 *
431 * AF_MODE_OFF: AF is disabled; the framework/app directly controls lens
432 * position.
433 *
434 * AF_MODE_AUTO: Single-sweep autofocus. No lens movement unless AF is
435 * triggered.
436 *
437 * AF_MODE_MACRO: Single-sweep up-close autofocus. No lens movement unless
438 * AF is triggered.
439 *
440 * AF_MODE_CONTINUOUS_VIDEO: Smooth continuous focusing, for recording
441 * video. Triggering immediately locks focus in current
442 * position. Canceling resumes cotinuous focusing.
443 *
444 * AF_MODE_CONTINUOUS_PICTURE: Fast continuous focusing, for
445 * zero-shutter-lag still capture. Triggering locks focus once currently
446 * active sweep concludes. Canceling resumes continuous focusing.
447 *
448 * AF_MODE_EDOF: Advanced extended depth of field focusing. There is no
449 * autofocus scan, so triggering one or canceling one has no effect.
450 * Images are focused automatically by the HAL.
451 *
452 * ANDROID_CONTROL_AF_STATE: Dynamic metadata describing the current AF
453 * algorithm state, reported by the HAL in the result metadata.
454 *
455 * AF_STATE_INACTIVE: No focusing has been done, or algorithm was
456 * reset. Lens is not moving. Always the state for MODE_OFF or MODE_EDOF.
457 * When the device is opened, it must start in this state.
458 *
459 * AF_STATE_PASSIVE_SCAN: A continuous focus algorithm is currently scanning
460 * for good focus. The lens is moving.
461 *
462 * AF_STATE_PASSIVE_FOCUSED: A continuous focus algorithm believes it is
463 * well focused. The lens is not moving. The HAL may spontaneously leave
464 * this state.
465 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700466 * AF_STATE_PASSIVE_UNFOCUSED: A continuous focus algorithm believes it is
467 * not well focused. The lens is not moving. The HAL may spontaneously
468 * leave this state.
469 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700470 * AF_STATE_ACTIVE_SCAN: A scan triggered by the user is underway.
471 *
472 * AF_STATE_FOCUSED_LOCKED: The AF algorithm believes it is focused. The
473 * lens is not moving.
474 *
475 * AF_STATE_NOT_FOCUSED_LOCKED: The AF algorithm has been unable to
476 * focus. The lens is not moving.
477 *
478 * ANDROID_CONTROL_AF_TRIGGER: Control for starting an autofocus scan, the
479 * meaning of which is mode- and state- dependent. Set by the framework in
480 * the request settings.
481 *
482 * AF_TRIGGER_IDLE: No current trigger.
483 *
484 * AF_TRIGGER_START: Trigger start of AF scan. Effect is mode and state
485 * dependent.
486 *
487 * AF_TRIGGER_CANCEL: Cancel current AF scan if any, and reset algorithm to
488 * default.
489 *
490 * Additional metadata entries:
491 *
492 * ANDROID_CONTROL_AF_REGIONS: Control for selecting the regions of the FOV
493 * that should be used to determine good focus. This applies to all AF
494 * modes that scan for focus. Set by the framework in the request
495 * settings.
496 *
497 * S4.2. Auto-exposure settings and result entries:
498 *
499 * Main metadata entries:
500 *
501 * ANDROID_CONTROL_AE_MODE: Control for selecting the current auto-exposure
502 * mode. Set by the framework in the request settings.
503 *
504 * AE_MODE_OFF: Autoexposure is disabled; the user controls exposure, gain,
505 * frame duration, and flash.
506 *
507 * AE_MODE_ON: Standard autoexposure, with flash control disabled. User may
508 * set flash to fire or to torch mode.
509 *
510 * AE_MODE_ON_AUTO_FLASH: Standard autoexposure, with flash on at HAL's
511 * discretion for precapture and still capture. User control of flash
512 * disabled.
513 *
514 * AE_MODE_ON_ALWAYS_FLASH: Standard autoexposure, with flash always fired
515 * for capture, and at HAL's discretion for precapture.. User control of
516 * flash disabled.
517 *
518 * AE_MODE_ON_AUTO_FLASH_REDEYE: Standard autoexposure, with flash on at
519 * HAL's discretion for precapture and still capture. Use a flash burst
520 * at end of precapture sequence to reduce redeye in the final
521 * picture. User control of flash disabled.
522 *
523 * ANDROID_CONTROL_AE_STATE: Dynamic metadata describing the current AE
524 * algorithm state, reported by the HAL in the result metadata.
525 *
526 * AE_STATE_INACTIVE: Initial AE state after mode switch. When the device is
527 * opened, it must start in this state.
528 *
529 * AE_STATE_SEARCHING: AE is not converged to a good value, and is adjusting
530 * exposure parameters.
531 *
532 * AE_STATE_CONVERGED: AE has found good exposure values for the current
533 * scene, and the exposure parameters are not changing. HAL may
534 * spontaneously leave this state to search for better solution.
535 *
536 * AE_STATE_LOCKED: AE has been locked with the AE_LOCK control. Exposure
537 * values are not changing.
538 *
539 * AE_STATE_FLASH_REQUIRED: The HAL has converged exposure, but believes
540 * flash is required for a sufficiently bright picture. Used for
541 * determining if a zero-shutter-lag frame can be used.
542 *
543 * AE_STATE_PRECAPTURE: The HAL is in the middle of a precapture
544 * sequence. Depending on AE mode, this mode may involve firing the
545 * flash for metering, or a burst of flash pulses for redeye reduction.
546 *
547 * ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER: Control for starting a metering
548 * sequence before capturing a high-quality image. Set by the framework in
549 * the request settings.
550 *
551 * PRECAPTURE_TRIGGER_IDLE: No current trigger.
552 *
553 * PRECAPTURE_TRIGGER_START: Start a precapture sequence. The HAL should
554 * use the subsequent requests to measure good exposure/white balance
555 * for an upcoming high-resolution capture.
556 *
557 * Additional metadata entries:
558 *
559 * ANDROID_CONTROL_AE_LOCK: Control for locking AE controls to their current
560 * values
561 *
562 * ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION: Control for adjusting AE
563 * algorithm target brightness point.
564 *
565 * ANDROID_CONTROL_AE_TARGET_FPS_RANGE: Control for selecting the target frame
566 * rate range for the AE algorithm. The AE routine cannot change the frame
567 * rate to be outside these bounds.
568 *
569 * ANDROID_CONTROL_AE_REGIONS: Control for selecting the regions of the FOV
570 * that should be used to determine good exposure levels. This applies to
571 * all AE modes besides OFF.
572 *
573 * S4.3. Auto-whitebalance settings and result entries:
574 *
575 * Main metadata entries:
576 *
577 * ANDROID_CONTROL_AWB_MODE: Control for selecting the current white-balance
578 * mode.
579 *
580 * AWB_MODE_OFF: Auto-whitebalance is disabled. User controls color matrix.
581 *
582 * AWB_MODE_AUTO: Automatic white balance is enabled; 3A controls color
583 * transform, possibly using more complex transforms than a simple
584 * matrix.
585 *
586 * AWB_MODE_INCANDESCENT: Fixed white balance settings good for indoor
587 * incandescent (tungsten) lighting, roughly 2700K.
588 *
589 * AWB_MODE_FLUORESCENT: Fixed white balance settings good for fluorescent
590 * lighting, roughly 5000K.
591 *
592 * AWB_MODE_WARM_FLUORESCENT: Fixed white balance settings good for
593 * fluorescent lighting, roughly 3000K.
594 *
595 * AWB_MODE_DAYLIGHT: Fixed white balance settings good for daylight,
596 * roughly 5500K.
597 *
598 * AWB_MODE_CLOUDY_DAYLIGHT: Fixed white balance settings good for clouded
599 * daylight, roughly 6500K.
600 *
601 * AWB_MODE_TWILIGHT: Fixed white balance settings good for
602 * near-sunset/sunrise, roughly 15000K.
603 *
604 * AWB_MODE_SHADE: Fixed white balance settings good for areas indirectly
605 * lit by the sun, roughly 7500K.
606 *
607 * ANDROID_CONTROL_AWB_STATE: Dynamic metadata describing the current AWB
608 * algorithm state, reported by the HAL in the result metadata.
609 *
610 * AWB_STATE_INACTIVE: Initial AWB state after mode switch. When the device
611 * is opened, it must start in this state.
612 *
613 * AWB_STATE_SEARCHING: AWB is not converged to a good value, and is
614 * changing color adjustment parameters.
615 *
616 * AWB_STATE_CONVERGED: AWB has found good color adjustment values for the
617 * current scene, and the parameters are not changing. HAL may
618 * spontaneously leave this state to search for better solution.
619 *
620 * AWB_STATE_LOCKED: AWB has been locked with the AWB_LOCK control. Color
621 * adjustment values are not changing.
622 *
623 * Additional metadata entries:
624 *
625 * ANDROID_CONTROL_AWB_LOCK: Control for locking AWB color adjustments to
626 * their current values.
627 *
628 * ANDROID_CONTROL_AWB_REGIONS: Control for selecting the regions of the FOV
629 * that should be used to determine good color balance. This applies only
630 * to auto-WB mode.
631 *
632 * S4.4. General state machine transition notes
633 *
634 * Switching between AF, AE, or AWB modes always resets the algorithm's state
635 * to INACTIVE. Similarly, switching between CONTROL_MODE or
636 * CONTROL_SCENE_MODE if CONTROL_MODE == USE_SCENE_MODE resets all the
637 * algorithm states to INACTIVE.
638 *
639 * The tables below are per-mode.
640 *
641 * S4.5. AF state machines
642 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700643 * when enabling AF or changing AF mode
644 *| state | trans. cause | new state | notes |
645 *+--------------------+---------------+--------------------+------------------+
646 *| Any | AF mode change| INACTIVE | |
647 *+--------------------+---------------+--------------------+------------------+
648 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700649 * mode = AF_MODE_OFF or AF_MODE_EDOF
650 *| state | trans. cause | new state | notes |
651 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700652 *| INACTIVE | | INACTIVE | Never changes |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700653 *+--------------------+---------------+--------------------+------------------+
654 *
655 * mode = AF_MODE_AUTO or AF_MODE_MACRO
656 *| state | trans. cause | new state | notes |
657 *+--------------------+---------------+--------------------+------------------+
658 *| INACTIVE | AF_TRIGGER | ACTIVE_SCAN | Start AF sweep |
659 *| | | | Lens now moving |
660 *+--------------------+---------------+--------------------+------------------+
661 *| ACTIVE_SCAN | AF sweep done | FOCUSED_LOCKED | If AF successful |
662 *| | | | Lens now locked |
663 *+--------------------+---------------+--------------------+------------------+
664 *| ACTIVE_SCAN | AF sweep done | NOT_FOCUSED_LOCKED | If AF successful |
665 *| | | | Lens now locked |
666 *+--------------------+---------------+--------------------+------------------+
667 *| ACTIVE_SCAN | AF_CANCEL | INACTIVE | Cancel/reset AF |
668 *| | | | Lens now locked |
669 *+--------------------+---------------+--------------------+------------------+
670 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
671 *+--------------------+---------------+--------------------+------------------+
672 *| FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
673 *| | | | Lens now moving |
674 *+--------------------+---------------+--------------------+------------------+
675 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
676 *+--------------------+---------------+--------------------+------------------+
677 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
678 *| | | | Lens now moving |
679 *+--------------------+---------------+--------------------+------------------+
680 *| All states | mode change | INACTIVE | |
681 *+--------------------+---------------+--------------------+------------------+
682 *
683 * mode = AF_MODE_CONTINUOUS_VIDEO
684 *| state | trans. cause | new state | notes |
685 *+--------------------+---------------+--------------------+------------------+
686 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
687 *| | new scan | | Lens now moving |
688 *+--------------------+---------------+--------------------+------------------+
689 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
690 *| | | | Lens now locked |
691 *+--------------------+---------------+--------------------+------------------+
692 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
693 *| | current scan | | Lens now locked |
694 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700695 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
696 *| | current scan | | Lens now locked |
697 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700698 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
699 *| | | | if focus is good |
700 *| | | | Lens now locked |
701 *+--------------------+---------------+--------------------+------------------+
702 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
703 *| | | | if focus is bad |
704 *| | | | Lens now locked |
705 *+--------------------+---------------+--------------------+------------------+
706 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
707 *| | | | position |
708 *| | | | Lens now locked |
709 *+--------------------+---------------+--------------------+------------------+
710 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
711 *| | new scan | | Lens now moving |
712 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700713 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
714 *| | new scan | | Lens now moving |
715 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700716 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700717 *| | | | Lens now locked |
718 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700719 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700720 *| | | | Lens now locked |
721 *+--------------------+---------------+--------------------+------------------+
722 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
723 *+--------------------+---------------+--------------------+------------------+
724 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
725 *+--------------------+---------------+--------------------+------------------+
726 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
727 *+--------------------+---------------+--------------------+------------------+
728 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
729 *+--------------------+---------------+--------------------+------------------+
730 *
731 * mode = AF_MODE_CONTINUOUS_PICTURE
732 *| state | trans. cause | new state | notes |
733 *+--------------------+---------------+--------------------+------------------+
734 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
735 *| | new scan | | Lens now moving |
736 *+--------------------+---------------+--------------------+------------------+
737 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
738 *| | | | Lens now locked |
739 *+--------------------+---------------+--------------------+------------------+
740 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
741 *| | current scan | | Lens now locked |
742 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700743 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
744 *| | current scan | | Lens now locked |
745 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700746 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Eventual trans. |
747 *| | | | once focus good |
748 *| | | | Lens now locked |
749 *+--------------------+---------------+--------------------+------------------+
750 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Eventual trans. |
751 *| | | | if cannot focus |
752 *| | | | Lens now locked |
753 *+--------------------+---------------+--------------------+------------------+
754 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
755 *| | | | position |
756 *| | | | Lens now locked |
757 *+--------------------+---------------+--------------------+------------------+
758 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
759 *| | new scan | | Lens now moving |
760 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700761 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
762 *| | new scan | | Lens now moving |
763 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700764 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700765 *| | | | Lens now locked |
766 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700767 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700768 *| | | | Lens now locked |
769 *+--------------------+---------------+--------------------+------------------+
770 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
771 *+--------------------+---------------+--------------------+------------------+
772 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
773 *+--------------------+---------------+--------------------+------------------+
774 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
775 *+--------------------+---------------+--------------------+------------------+
776 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
777 *+--------------------+---------------+--------------------+------------------+
778 *
779 * S4.6. AE and AWB state machines
780 *
781 * The AE and AWB state machines are mostly identical. AE has additional
782 * FLASH_REQUIRED and PRECAPTURE states. So rows below that refer to those two
783 * states should be ignored for the AWB state machine.
784 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700785 * when enabling AE/AWB or changing AE/AWB mode
786 *| state | trans. cause | new state | notes |
787 *+--------------------+---------------+--------------------+------------------+
788 *| Any | mode change | INACTIVE | |
789 *+--------------------+---------------+--------------------+------------------+
790 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700791 * mode = AE_MODE_OFF / AWB mode not AUTO
792 *| state | trans. cause | new state | notes |
793 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700794 *| INACTIVE | | INACTIVE | AE/AWB disabled |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700795 *+--------------------+---------------+--------------------+------------------+
796 *
797 * mode = AE_MODE_ON_* / AWB_MODE_AUTO
798 *| state | trans. cause | new state | notes |
799 *+--------------------+---------------+--------------------+------------------+
800 *| INACTIVE | HAL initiates | SEARCHING | |
801 *| | AE/AWB scan | | |
802 *+--------------------+---------------+--------------------+------------------+
803 *| INACTIVE | AE/AWB_LOCK | LOCKED | values locked |
804 *| | on | | |
805 *+--------------------+---------------+--------------------+------------------+
806 *| SEARCHING | HAL finishes | CONVERGED | good values, not |
807 *| | AE/AWB scan | | changing |
808 *+--------------------+---------------+--------------------+------------------+
809 *| SEARCHING | HAL finishes | FLASH_REQUIRED | converged but too|
810 *| | AE scan | | dark w/o flash |
811 *+--------------------+---------------+--------------------+------------------+
812 *| SEARCHING | AE/AWB_LOCK | LOCKED | values locked |
813 *| | on | | |
814 *+--------------------+---------------+--------------------+------------------+
815 *| CONVERGED | HAL initiates | SEARCHING | values locked |
816 *| | AE/AWB scan | | |
817 *+--------------------+---------------+--------------------+------------------+
818 *| CONVERGED | AE/AWB_LOCK | LOCKED | values locked |
819 *| | on | | |
820 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala73dba5e2013-05-21 16:29:14 -0700821 *| FLASH_REQUIRED | HAL initiates | SEARCHING | values locked |
822 *| | AE/AWB scan | | |
823 *+--------------------+---------------+--------------------+------------------+
824 *| FLASH_REQUIRED | AE/AWB_LOCK | LOCKED | values locked |
825 *| | on | | |
826 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700827 *| LOCKED | AE/AWB_LOCK | SEARCHING | values not good |
828 *| | off | | after unlock |
829 *+--------------------+---------------+--------------------+------------------+
830 *| LOCKED | AE/AWB_LOCK | CONVERGED | values good |
831 *| | off | | after unlock |
832 *+--------------------+---------------+--------------------+------------------+
833 *| LOCKED | AE_LOCK | FLASH_REQUIRED | exposure good, |
834 *| | off | | but too dark |
835 *+--------------------+---------------+--------------------+------------------+
836 *| All AE states | PRECAPTURE_ | PRECAPTURE | Start precapture |
837 *| | START | | sequence |
838 *+--------------------+---------------+--------------------+------------------+
839 *| PRECAPTURE | Sequence done.| CONVERGED | Ready for high- |
840 *| | AE_LOCK off | | quality capture |
841 *+--------------------+---------------+--------------------+------------------+
842 *| PRECAPTURE | Sequence done.| LOCKED | Ready for high- |
843 *| | AE_LOCK on | | quality capture |
844 *+--------------------+---------------+--------------------+------------------+
845 *
846 */
847
848/**
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700849 * S5. Cropping:
850 *
851 * Cropping of the full pixel array (for digital zoom and other use cases where
852 * a smaller FOV is desirable) is communicated through the
853 * ANDROID_SCALER_CROP_REGION setting. This is a per-request setting, and can
854 * change on a per-request basis, which is critical for implementing smooth
855 * digital zoom.
856 *
857 * The region is defined as a rectangle (x, y, width, height), with (x, y)
858 * describing the top-left corner of the rectangle. The rectangle is defined on
859 * the coordinate system of the sensor active pixel array, with (0,0) being the
860 * top-left pixel of the active pixel array. Therefore, the width and height
861 * cannot be larger than the dimensions reported in the
862 * ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY static info field. The minimum allowed
863 * width and height are reported by the HAL through the
864 * ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes the
865 * maximum supported zoom factor. Therefore, the minimum crop region width and
866 * height are:
867 *
868 * {width, height} =
869 * { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
870 * ANDROID_SCALER_MAX_DIGITAL_ZOOM),
871 * floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
872 * ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
873 *
874 * If the crop region needs to fulfill specific requirements (for example, it
875 * needs to start on even coordinates, and its width/height needs to be even),
876 * the HAL must do the necessary rounding and write out the final crop region
877 * used in the output result metadata. Similarly, if the HAL implements video
878 * stabilization, it must adjust the result crop region to describe the region
879 * actually included in the output after video stabilization is applied. In
880 * general, a camera-using application must be able to determine the field of
881 * view it is receiving based on the crop region, the dimensions of the image
882 * sensor, and the lens focal length.
883 *
Zhijun Hef1ee67e2014-05-21 11:18:51 -0700884 * It is assumed that the cropping is applied after raw to other color space
885 * conversion. Raw streams (RAW16 and RAW_OPAQUE) don't have this conversion stage,
886 * and are not croppable. Therefore, the crop region must be ignored by the HAL
887 * for raw streams.
888 *
889 * Since the crop region applies to all non-raw streams, which may have different aspect
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700890 * ratios than the crop region, the exact sensor region used for each stream may
891 * be smaller than the crop region. Specifically, each stream should maintain
892 * square pixels and its aspect ratio by minimally further cropping the defined
893 * crop region. If the stream's aspect ratio is wider than the crop region, the
894 * stream should be further cropped vertically, and if the stream's aspect ratio
895 * is narrower than the crop region, the stream should be further cropped
896 * horizontally.
897 *
898 * In all cases, the stream crop must be centered within the full crop region,
899 * and each stream is only either cropped horizontally or vertical relative to
900 * the full crop region, never both.
901 *
902 * For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
903 * 1280x720 stream (16:9 aspect), below demonstrates the expected output regions
904 * for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
905 * 1500 pixel array) sensor.
906 *
907 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
908 *
909 * 640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)
910 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
911 *
912 * 0 1000 2000
913 * +---------+---------+---------+----------+
914 * | Active pixel array |
915 * | |
916 * | |
917 * + +-------------------+ + 375
918 * | | | |
919 * | O===================O |
920 * | I 1280x720 stream I |
921 * + I I + 750
922 * | I I |
923 * | O===================O |
924 * | | | |
925 * + +-------------------+ + 1125
926 * | Crop region, 640x480 stream |
927 * | |
928 * | |
929 * +---------+---------+---------+----------+ 1500
930 *
931 * Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)
932 *
933 * 640x480 stream crop: (666, 375, 1000, 750) (marked with =)
934 * 1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
935 *
936 * 0 1000 2000
937 * +---------+---------+---------+----------+
938 * | Active pixel array |
939 * | |
940 * | |
941 * + +---O==================O---+ + 375
942 * | | I 640x480 stream I | |
943 * | | I I | |
944 * | | I I | |
945 * + | I I | + 750
946 * | | I I | |
947 * | | I I | |
948 * | | I I | |
949 * + +---O==================O---+ + 1125
950 * | Crop region, 1280x720 stream |
951 * | |
952 * | |
953 * +---------+---------+---------+----------+ 1500
954 *
955 * Crop region: (500, 375, 750, 750) (1:1 aspect ratio)
956 *
957 * 640x480 stream crop: (500, 469, 750, 562) (marked with =)
958 * 1280x720 stream crop: (500, 543, 750, 414) (marged with #)
959 *
960 * 0 1000 2000
961 * +---------+---------+---------+----------+
962 * | Active pixel array |
963 * | |
964 * | |
965 * + +--------------+ + 375
966 * | O==============O |
967 * | ################ |
968 * | # # |
969 * + # # + 750
970 * | # # |
971 * | ################ 1280x720 |
972 * | O==============O 640x480 |
973 * + +--------------+ + 1125
974 * | Crop region |
975 * | |
976 * | |
977 * +---------+---------+---------+----------+ 1500
978 *
979 * And a final example, a 1024x1024 square aspect ratio stream instead of the
980 * 480p stream:
981 *
982 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
983 *
984 * 1024x1024 stream crop: (625, 375, 750, 750) (marked with #)
985 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
986 *
987 * 0 1000 2000
988 * +---------+---------+---------+----------+
989 * | Active pixel array |
990 * | |
991 * | 1024x1024 stream |
992 * + +--###############--+ + 375
993 * | | # # | |
994 * | O===================O |
995 * | I 1280x720 stream I |
996 * + I I + 750
997 * | I I |
998 * | O===================O |
999 * | | # # | |
1000 * + +--###############--+ + 1125
1001 * | Crop region |
1002 * | |
1003 * | |
1004 * +---------+---------+---------+----------+ 1500
1005 *
1006 */
1007
1008/**
1009 * S6. Error management:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001010 *
1011 * Camera HAL device ops functions that have a return value will all return
1012 * -ENODEV / NULL in case of a serious error. This means the device cannot
1013 * continue operation, and must be closed by the framework. Once this error is
Alex Rayd5ddbc92013-02-15 13:47:24 -08001014 * returned by some method, or if notify() is called with ERROR_DEVICE, only
1015 * the close() method can be called successfully. All other methods will return
1016 * -ENODEV / NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001017 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001018 * If a device op is called in the wrong sequence, for example if the framework
1019 * calls configure_streams() is called before initialize(), the device must
1020 * return -ENOSYS from the call, and do nothing.
1021 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001022 * Transient errors in image capture must be reported through notify() as follows:
1023 *
1024 * - The failure of an entire capture to occur must be reported by the HAL by
1025 * calling notify() with ERROR_REQUEST. Individual errors for the result
1026 * metadata or the output buffers must not be reported in this case.
1027 *
1028 * - If the metadata for a capture cannot be produced, but some image buffers
1029 * were filled, the HAL must call notify() with ERROR_RESULT.
1030 *
1031 * - If an output image buffer could not be filled, but either the metadata was
1032 * produced or some other buffers were filled, the HAL must call notify() with
1033 * ERROR_BUFFER for each failed buffer.
1034 *
1035 * In each of these transient failure cases, the HAL must still call
Zhijun Heceac9e32014-02-05 20:49:45 -08001036 * process_capture_result, with valid output and input (if an input buffer was
1037 * submitted) buffer_handle_t. If the result metadata could not be produced, it
1038 * should be NULL. If some buffers could not be filled, they must be returned with
1039 * process_capture_result in the error state, their release fences must be set to
1040 * the acquire fences passed by the framework, or -1 if they have been waited on by
1041 * the HAL already.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001042 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001043 * Invalid input arguments result in -EINVAL from the appropriate methods. In
1044 * that case, the framework must act as if that call had never been made.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001045 *
1046 */
1047
Zhijun He2dde4682014-01-09 09:11:49 -08001048/**
Zhijun He709e5872014-01-17 15:25:21 -08001049 * S7. Key Performance Indicator (KPI) glossary:
Zhijun He2dde4682014-01-09 09:11:49 -08001050 *
Zhijun He709e5872014-01-17 15:25:21 -08001051 * This includes some critical definitions that are used by KPI metrics.
Zhijun He2dde4682014-01-09 09:11:49 -08001052 *
1053 * Pipeline Latency:
1054 * For a given capture request, the duration from the framework calling
1055 * process_capture_request to the HAL sending capture result and all buffers
1056 * back by process_capture_result call. To make the Pipeline Latency measure
1057 * independent of frame rate, it is measured by frame count.
1058 *
1059 * For example, when frame rate is 30 (fps), the frame duration (time interval
1060 * between adjacent frame capture time) is 33 (ms).
1061 * If it takes 5 frames for framework to get the result and buffers back for
1062 * a given request, then the Pipeline Latency is 5 (frames), instead of
1063 * 5 x 33 = 165 (ms).
1064 *
1065 * The Pipeline Latency is determined by android.request.pipelineDepth and
1066 * android.request.pipelineMaxDepth, see their definitions for more details.
1067 *
1068 */
1069
Zhijun Hebc358682014-01-23 14:42:54 -08001070/**
1071 * S8. Sample Use Cases:
1072 *
1073 * This includes some typical use case examples the camera HAL may support.
1074 *
1075 * S8.1 Zero Shutter Lag (ZSL) with CAMERA3_STREAM_INPUT stream.
1076 *
1077 * When Zero Shutter Lag (ZSL) is supported by the camera device, the INPUT stream
1078 * can be used for application/framework implemented ZSL use case. This kind of stream
1079 * will be used by the framework as follows:
1080 *
1081 * 1. Framework configures an opaque raw format output stream that is used to
1082 * produce the ZSL output buffers. The stream pixel format will be
1083 * HAL_PIXEL_FORMAT_RAW_OPAQUE.
1084 *
1085 * 2. Framework configures an opaque raw format input stream that is used to
1086 * send the reprocess ZSL buffers to the HAL. The stream pixel format will
1087 * also be HAL_PIXEL_FORMAT_RAW_OPAQUE.
1088 *
1089 * 3. Framework configures a YUV/JPEG output stream that is used to receive the
1090 * reprocessed data. The stream pixel format will be YCbCr_420/HAL_PIXEL_FORMAT_BLOB.
1091 *
1092 * 4. Framework picks a ZSL buffer from the output stream when a ZSL capture is
1093 * issued by the application, and sends the data back as an input buffer in a
1094 * reprocessing request, then sends to the HAL for reprocessing.
1095 *
1096 * 5. The HAL sends back the output JPEG result to framework.
1097 *
1098 * The HAL can select the actual raw buffer format and configure the ISP pipeline
1099 * appropriately based on the HAL_PIXEL_FORMAT_RAW_OPAQUE format. See this format
1100 * definition for more details.
1101 *
1102 * S8.2 Zero Shutter Lag (ZSL) with CAMERA3_STREAM_BIDIRECTIONAL stream.
1103 *
1104 * For this use case, the bidirectional stream will be used by the framework as follows:
1105 *
1106 * 1. The framework includes a buffer from this stream as output buffer in a
1107 * request as normal.
1108 *
1109 * 2. Once the HAL device returns a filled output buffer to the framework,
1110 * the framework may do one of two things with the filled buffer:
1111 *
1112 * 2. a. The framework uses the filled data, and returns the now-used buffer
1113 * to the stream queue for reuse. This behavior exactly matches the
1114 * OUTPUT type of stream.
1115 *
1116 * 2. b. The framework wants to reprocess the filled data, and uses the
1117 * buffer as an input buffer for a request. Once the HAL device has
1118 * used the reprocessing buffer, it then returns it to the
1119 * framework. The framework then returns the now-used buffer to the
1120 * stream queue for reuse.
1121 *
1122 * 3. The HAL device will be given the buffer again as an output buffer for
1123 * a request at some future point.
1124 *
1125 * For ZSL use case, the pixel format for bidirectional stream will be
Zhijun He52a18892014-06-30 10:35:58 -07001126 * HAL_PIXEL_FORMAT_RAW_OPAQUE or HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED if it
1127 * is listed in android.scaler.availableInputOutputFormatsMap. When
1128 * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, the gralloc
1129 * usage flags for the consumer endpoint will be set to GRALLOC_USAGE_HW_CAMERA_ZSL.
1130 * A configuration stream list that has BIDIRECTIONAL stream used as input, will
1131 * usually also have a distinct OUTPUT stream to get the reprocessing data. For example,
1132 * for the ZSL use case, the stream list might be configured with the following:
Zhijun Hebc358682014-01-23 14:42:54 -08001133 *
1134 * - A HAL_PIXEL_FORMAT_RAW_OPAQUE bidirectional stream is used
1135 * as input.
1136 * - And a HAL_PIXEL_FORMAT_BLOB (JPEG) output stream.
1137 *
1138 */
1139
Ruben Brunk2d96c742014-03-18 13:39:17 -07001140/**
1141 * S9. Notes on Controls and Metadata
1142 *
1143 * This section contains notes about the interpretation and usage of various metadata tags.
1144 *
1145 * S9.1 HIGH_QUALITY and FAST modes.
1146 *
1147 * Many camera post-processing blocks may be listed as having HIGH_QUALITY,
1148 * FAST, and OFF operating modes. These blocks will typically also have an
1149 * 'available modes' tag representing which of these operating modes are
1150 * available on a given device. The general policy regarding implementing
1151 * these modes is as follows:
1152 *
1153 * 1. Operating mode controls of hardware blocks that cannot be disabled
1154 * must not list OFF in their corresponding 'available modes' tags.
1155 *
1156 * 2. OFF will always be included in their corresponding 'available modes'
1157 * tag if it is possible to disable that hardware block.
1158 *
1159 * 3. FAST must always be included in the 'available modes' tags for all
1160 * post-processing blocks supported on the device. If a post-processing
1161 * block also has a slower and higher quality operating mode that does
1162 * not meet the framerate requirements for FAST mode, HIGH_QUALITY should
1163 * be included in the 'available modes' tag to represent this operating
1164 * mode.
1165 */
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001166__BEGIN_DECLS
1167
1168struct camera3_device;
1169
1170/**********************************************************************
1171 *
1172 * Camera3 stream and stream buffer definitions.
1173 *
1174 * These structs and enums define the handles and contents of the input and
1175 * output streams connecting the HAL to various framework and application buffer
1176 * consumers. Each stream is backed by a gralloc buffer queue.
1177 *
1178 */
1179
1180/**
1181 * camera3_stream_type_t:
1182 *
1183 * The type of the camera stream, which defines whether the camera HAL device is
1184 * the producer or the consumer for that stream, and how the buffers of the
1185 * stream relate to the other streams.
1186 */
1187typedef enum camera3_stream_type {
1188 /**
1189 * This stream is an output stream; the camera HAL device will be
1190 * responsible for filling buffers from this stream with newly captured or
1191 * reprocessed image data.
1192 */
1193 CAMERA3_STREAM_OUTPUT = 0,
1194
1195 /**
1196 * This stream is an input stream; the camera HAL device will be responsible
1197 * for reading buffers from this stream and sending them through the camera
1198 * processing pipeline, as if the buffer was a newly captured image from the
1199 * imager.
Zhijun Hebc358682014-01-23 14:42:54 -08001200 *
1201 * The pixel format for input stream can be any format reported by
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001202 * android.scaler.availableInputOutputFormatsMap. The pixel format of the
1203 * output stream that is used to produce the reprocessing data may be any
1204 * format reported by android.scaler.availableStreamConfigurations. The
1205 * supported input/output stream combinations depends the camera device
1206 * capabilities, see android.scaler.availableInputOutputFormatsMap for
1207 * stream map details.
Zhijun Hebc358682014-01-23 14:42:54 -08001208 *
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001209 * This kind of stream is generally used to reprocess data into higher
1210 * quality images (that otherwise would cause a frame rate performance
1211 * loss), or to do off-line reprocessing.
Zhijun Hebc358682014-01-23 14:42:54 -08001212 *
1213 * A typical use case is Zero Shutter Lag (ZSL), see S8.1 for more details.
1214 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001215 */
1216 CAMERA3_STREAM_INPUT = 1,
1217
1218 /**
1219 * This stream can be used for input and output. Typically, the stream is
1220 * used as an output stream, but occasionally one already-filled buffer may
1221 * be sent back to the HAL device for reprocessing.
1222 *
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001223 * This kind of stream is meant generally for Zero Shutter Lag (ZSL)
1224 * features, where copying the captured image from the output buffer to the
Zhijun Hebc358682014-01-23 14:42:54 -08001225 * reprocessing input buffer would be expensive. See S8.2 for more details.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001226 *
1227 * Note that the HAL will always be reprocessing data it produced.
1228 *
1229 */
1230 CAMERA3_STREAM_BIDIRECTIONAL = 2,
1231
1232 /**
1233 * Total number of framework-defined stream types
1234 */
1235 CAMERA3_NUM_STREAM_TYPES
1236
1237} camera3_stream_type_t;
1238
1239/**
1240 * camera3_stream_t:
1241 *
1242 * A handle to a single camera input or output stream. A stream is defined by
1243 * the framework by its buffer resolution and format, and additionally by the
1244 * HAL with the gralloc usage flags and the maximum in-flight buffer count.
1245 *
1246 * The stream structures are owned by the framework, but pointers to a
1247 * camera3_stream passed into the HAL by configure_streams() are valid until the
1248 * end of the first subsequent configure_streams() call that _does not_ include
1249 * that camera3_stream as an argument, or until the end of the close() call.
1250 *
1251 * All camera3_stream framework-controlled members are immutable once the
1252 * camera3_stream is passed into configure_streams(). The HAL may only change
1253 * the HAL-controlled parameters during a configure_streams() call, except for
1254 * the contents of the private pointer.
1255 *
1256 * If a configure_streams() call returns a non-fatal error, all active streams
1257 * remain valid as if configure_streams() had not been called.
1258 *
1259 * The endpoint of the stream is not visible to the camera HAL device.
Alex Ray2ce219a2013-06-14 15:09:30 -07001260 * In DEVICE_API_VERSION_3_1, this was changed to share consumer usage flags
1261 * on streams where the camera is a producer (OUTPUT and BIDIRECTIONAL stream
1262 * types) see the usage field below.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001263 */
1264typedef struct camera3_stream {
1265
1266 /*****
1267 * Set by framework before configure_streams()
1268 */
1269
1270 /**
1271 * The type of the stream, one of the camera3_stream_type_t values.
1272 */
1273 int stream_type;
1274
1275 /**
1276 * The width in pixels of the buffers in this stream
1277 */
1278 uint32_t width;
1279
1280 /**
1281 * The height in pixels of the buffers in this stream
1282 */
1283 uint32_t height;
1284
1285 /**
1286 * The pixel format for the buffers in this stream. Format is a value from
1287 * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
1288 * from device-specific headers.
1289 *
1290 * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
1291 * gralloc module will select a format based on the usage flags provided by
1292 * the camera device and the other endpoint of the stream.
1293 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001294 * <= CAMERA_DEVICE_API_VERSION_3_1:
1295 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001296 * The camera HAL device must inspect the buffers handed to it in the
1297 * subsequent register_stream_buffers() call to obtain the
1298 * implementation-specific format details, if necessary.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001299 *
1300 * >= CAMERA_DEVICE_API_VERSION_3_2:
1301 *
1302 * register_stream_buffers() won't be called by the framework, so the HAL
1303 * should configure the ISP and sensor pipeline based purely on the sizes,
1304 * usage flags, and formats for the configured streams.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001305 */
1306 int format;
1307
1308 /*****
1309 * Set by HAL during configure_streams().
1310 */
1311
1312 /**
1313 * The gralloc usage flags for this stream, as needed by the HAL. The usage
1314 * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
1315 * headers.
1316 *
1317 * For output streams, these are the HAL's producer usage flags. For input
1318 * streams, these are the HAL's consumer usage flags. The usage flags from
1319 * the producer and the consumer will be combined together and then passed
1320 * to the platform gralloc HAL module for allocating the gralloc buffers for
1321 * each stream.
Alex Ray2ce219a2013-06-14 15:09:30 -07001322 *
1323 * Version information:
1324 *
1325 * == CAMERA_DEVICE_API_VERSION_3_0:
1326 *
1327 * No initial value guaranteed when passed via configure_streams().
1328 * HAL may not use this field as input, and must write over this field
1329 * with its usage flags.
1330 *
1331 * >= CAMERA_DEVICE_API_VERSION_3_1:
1332 *
1333 * For stream_type OUTPUT and BIDIRECTIONAL, when passed via
1334 * configure_streams(), the initial value of this is the consumer's
1335 * usage flags. The HAL may use these consumer flags to decide stream
1336 * configuration.
1337 * For stream_type INPUT, when passed via configure_streams(), the initial
1338 * value of this is 0.
1339 * For all streams passed via configure_streams(), the HAL must write
1340 * over this field with its usage flags.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001341 */
1342 uint32_t usage;
1343
1344 /**
1345 * The maximum number of buffers the HAL device may need to have dequeued at
1346 * the same time. The HAL device may not have more buffers in-flight from
1347 * this stream than this value.
1348 */
1349 uint32_t max_buffers;
1350
1351 /**
1352 * A handle to HAL-private information for the stream. Will not be inspected
1353 * by the framework code.
1354 */
1355 void *priv;
1356
1357} camera3_stream_t;
1358
1359/**
1360 * camera3_stream_configuration_t:
1361 *
1362 * A structure of stream definitions, used by configure_streams(). This
1363 * structure defines all the output streams and the reprocessing input
1364 * stream for the current camera use case.
1365 */
1366typedef struct camera3_stream_configuration {
1367 /**
1368 * The total number of streams requested by the framework. This includes
1369 * both input and output streams. The number of streams will be at least 1,
1370 * and there will be at least one output-capable stream.
1371 */
1372 uint32_t num_streams;
1373
1374 /**
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001375 * An array of camera stream pointers, defining the input/output
1376 * configuration for the camera HAL device.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001377 *
1378 * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
1379 * in a single configuration.
1380 *
1381 * At least one output-capable stream must be defined (OUTPUT or
1382 * BIDIRECTIONAL).
1383 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001384 camera3_stream_t **streams;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001385
1386} camera3_stream_configuration_t;
1387
1388/**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001389 * camera3_buffer_status_t:
1390 *
1391 * The current status of a single stream buffer.
1392 */
1393typedef enum camera3_buffer_status {
1394 /**
1395 * The buffer is in a normal state, and can be used after waiting on its
1396 * sync fence.
1397 */
1398 CAMERA3_BUFFER_STATUS_OK = 0,
1399
1400 /**
1401 * The buffer does not contain valid data, and the data in it should not be
1402 * used. The sync fence must still be waited on before reusing the buffer.
1403 */
1404 CAMERA3_BUFFER_STATUS_ERROR = 1
1405
1406} camera3_buffer_status_t;
1407
1408/**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001409 * camera3_stream_buffer_t:
1410 *
1411 * A single buffer from a camera3 stream. It includes a handle to its parent
1412 * stream, the handle to the gralloc buffer itself, and sync fences
1413 *
1414 * The buffer does not specify whether it is to be used for input or output;
1415 * that is determined by its parent stream type and how the buffer is passed to
1416 * the HAL device.
1417 */
1418typedef struct camera3_stream_buffer {
1419 /**
1420 * The handle of the stream this buffer is associated with
1421 */
1422 camera3_stream_t *stream;
1423
1424 /**
1425 * The native handle to the buffer
1426 */
1427 buffer_handle_t *buffer;
1428
1429 /**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001430 * Current state of the buffer, one of the camera3_buffer_status_t
1431 * values. The framework will not pass buffers to the HAL that are in an
1432 * error state. In case a buffer could not be filled by the HAL, it must
1433 * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
1434 * framework with process_capture_result().
1435 */
1436 int status;
1437
1438 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001439 * The acquire sync fence for this buffer. The HAL must wait on this fence
1440 * fd before attempting to read from or write to this buffer.
1441 *
1442 * The framework may be set to -1 to indicate that no waiting is necessary
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001443 * for this buffer.
1444 *
1445 * When the HAL returns an output buffer to the framework with
1446 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
1447 * never waits on the acquire_fence due to an error in filling a buffer,
1448 * when calling process_capture_result() the HAL must set the release_fence
1449 * of the buffer to be the acquire_fence passed to it by the framework. This
1450 * will allow the framework to wait on the fence before reusing the buffer.
1451 *
1452 * For input buffers, the HAL must not change the acquire_fence field during
1453 * the process_capture_request() call.
Zhijun Heceac9e32014-02-05 20:49:45 -08001454 *
1455 * >= CAMERA_DEVICE_API_VERSION_3_2:
1456 *
1457 * When the HAL returns an input buffer to the framework with
1458 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001459 * never waits on input buffer acquire fence due to an error, the sync
1460 * fences should be handled similarly to the way they are handled for output
1461 * buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001462 */
1463 int acquire_fence;
1464
1465 /**
1466 * The release sync fence for this buffer. The HAL must set this fence when
1467 * returning buffers to the framework, or write -1 to indicate that no
1468 * waiting is required for this buffer.
1469 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001470 * For the output buffers, the fences must be set in the output_buffers
1471 * array passed to process_capture_result().
1472 *
1473 * <= CAMERA_DEVICE_API_VERSION_3_1:
1474 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001475 * For the input buffer, the release fence must be set by the
Zhijun Heceac9e32014-02-05 20:49:45 -08001476 * process_capture_request() call.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001477 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001478 * >= CAMERA_DEVICE_API_VERSION_3_2:
1479 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001480 * For the input buffer, the fences must be set in the input_buffer
1481 * passed to process_capture_result().
1482 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001483 * After signaling the release_fence for this buffer, the HAL
1484 * should not make any further attempts to access this buffer as the
1485 * ownership has been fully transferred back to the framework.
1486 *
1487 * If a fence of -1 was specified then the ownership of this buffer
1488 * is transferred back immediately upon the call of process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001489 */
1490 int release_fence;
1491
1492} camera3_stream_buffer_t;
1493
1494/**
1495 * camera3_stream_buffer_set_t:
1496 *
1497 * The complete set of gralloc buffers for a stream. This structure is given to
1498 * register_stream_buffers() to allow the camera HAL device to register/map/etc
1499 * newly allocated stream buffers.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001500 *
1501 * >= CAMERA_DEVICE_API_VERSION_3_2:
1502 *
1503 * Deprecated (and not used). In particular,
1504 * register_stream_buffers is also deprecated and will never be invoked.
1505 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001506 */
1507typedef struct camera3_stream_buffer_set {
1508 /**
1509 * The stream handle for the stream these buffers belong to
1510 */
1511 camera3_stream_t *stream;
1512
1513 /**
1514 * The number of buffers in this stream. It is guaranteed to be at least
1515 * stream->max_buffers.
1516 */
1517 uint32_t num_buffers;
1518
1519 /**
1520 * The array of gralloc buffer handles for this stream. If the stream format
1521 * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
1522 * should inspect the passed-in buffers to determine any platform-private
1523 * pixel format information.
1524 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001525 buffer_handle_t **buffers;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001526
1527} camera3_stream_buffer_set_t;
1528
1529/**
1530 * camera3_jpeg_blob:
1531 *
1532 * Transport header for compressed JPEG buffers in output streams.
1533 *
1534 * To capture JPEG images, a stream is created using the pixel format
Zhijun He44a89152014-04-24 14:34:53 -07001535 * HAL_PIXEL_FORMAT_BLOB. The buffer size for the stream is calculated by the
1536 * framework, based on the static metadata field android.jpeg.maxSize. Since
1537 * compressed JPEG images are of variable size, the HAL needs to include the
1538 * final size of the compressed image using this structure inside the output
1539 * stream buffer. The JPEG blob ID field must be set to CAMERA3_JPEG_BLOB_ID.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001540 *
Zhijun He44a89152014-04-24 14:34:53 -07001541 * Transport header should be at the end of the JPEG output stream buffer. That
1542 * means the jpeg_blob_id must start at byte[buffer_size -
1543 * sizeof(camera3_jpeg_blob)], where the buffer_size is the size of gralloc buffer.
1544 * Any HAL using this transport header must account for it in android.jpeg.maxSize
1545 * The JPEG data itself starts at the beginning of the buffer and should be
1546 * jpeg_size bytes long.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001547 */
1548typedef struct camera3_jpeg_blob {
1549 uint16_t jpeg_blob_id;
1550 uint32_t jpeg_size;
1551} camera3_jpeg_blob_t;
1552
1553enum {
1554 CAMERA3_JPEG_BLOB_ID = 0x00FF
1555};
1556
1557/**********************************************************************
1558 *
1559 * Message definitions for the HAL notify() callback.
1560 *
1561 * These definitions are used for the HAL notify callback, to signal
1562 * asynchronous events from the HAL device to the Android framework.
1563 *
1564 */
1565
1566/**
1567 * camera3_msg_type:
1568 *
1569 * Indicates the type of message sent, which specifies which member of the
1570 * message union is valid.
1571 *
1572 */
1573typedef enum camera3_msg_type {
1574 /**
1575 * An error has occurred. camera3_notify_msg.message.error contains the
1576 * error information.
1577 */
1578 CAMERA3_MSG_ERROR = 1,
1579
1580 /**
1581 * The exposure of a given request has
1582 * begun. camera3_notify_msg.message.shutter contains the information
1583 * the capture.
1584 */
1585 CAMERA3_MSG_SHUTTER = 2,
1586
1587 /**
1588 * Number of framework message types
1589 */
1590 CAMERA3_NUM_MESSAGES
1591
1592} camera3_msg_type_t;
1593
1594/**
1595 * Defined error codes for CAMERA_MSG_ERROR
1596 */
1597typedef enum camera3_error_msg_code {
1598 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001599 * A serious failure occured. No further frames or buffer streams will
1600 * be produced by the device. Device should be treated as closed. The
1601 * client must reopen the device to use it again. The frame_number field
1602 * is unused.
1603 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001604 CAMERA3_MSG_ERROR_DEVICE = 1,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001605
1606 /**
1607 * An error has occurred in processing a request. No output (metadata or
1608 * buffers) will be produced for this request. The frame_number field
1609 * specifies which request has been dropped. Subsequent requests are
1610 * unaffected, and the device remains operational.
1611 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001612 CAMERA3_MSG_ERROR_REQUEST = 2,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001613
1614 /**
1615 * An error has occurred in producing an output result metadata buffer
1616 * for a request, but output stream buffers for it will still be
1617 * available. Subsequent requests are unaffected, and the device remains
1618 * operational. The frame_number field specifies the request for which
1619 * result metadata won't be available.
1620 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001621 CAMERA3_MSG_ERROR_RESULT = 3,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001622
1623 /**
1624 * An error has occurred in placing an output buffer into a stream for a
1625 * request. The frame metadata and other buffers may still be
1626 * available. Subsequent requests are unaffected, and the device remains
1627 * operational. The frame_number field specifies the request for which the
1628 * buffer was dropped, and error_stream contains a pointer to the stream
1629 * that dropped the frame.u
1630 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001631 CAMERA3_MSG_ERROR_BUFFER = 4,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001632
1633 /**
1634 * Number of error types
1635 */
1636 CAMERA3_MSG_NUM_ERRORS
1637
1638} camera3_error_msg_code_t;
1639
1640/**
1641 * camera3_error_msg_t:
1642 *
1643 * Message contents for CAMERA3_MSG_ERROR
1644 */
1645typedef struct camera3_error_msg {
1646 /**
1647 * Frame number of the request the error applies to. 0 if the frame number
1648 * isn't applicable to the error.
1649 */
1650 uint32_t frame_number;
1651
1652 /**
1653 * Pointer to the stream that had a failure. NULL if the stream isn't
1654 * applicable to the error.
1655 */
1656 camera3_stream_t *error_stream;
1657
1658 /**
1659 * The code for this error; one of the CAMERA_MSG_ERROR enum values.
1660 */
1661 int error_code;
1662
1663} camera3_error_msg_t;
1664
1665/**
1666 * camera3_shutter_msg_t:
1667 *
1668 * Message contents for CAMERA3_MSG_SHUTTER
1669 */
1670typedef struct camera3_shutter_msg {
1671 /**
1672 * Frame number of the request that has begun exposure
1673 */
1674 uint32_t frame_number;
1675
1676 /**
1677 * Timestamp for the start of capture. This must match the capture result
1678 * metadata's sensor exposure start timestamp.
1679 */
1680 uint64_t timestamp;
1681
1682} camera3_shutter_msg_t;
1683
1684/**
1685 * camera3_notify_msg_t:
1686 *
1687 * The message structure sent to camera3_callback_ops_t.notify()
1688 */
1689typedef struct camera3_notify_msg {
1690
1691 /**
1692 * The message type. One of camera3_notify_msg_type, or a private extension.
1693 */
1694 int type;
1695
1696 union {
1697 /**
1698 * Error message contents. Valid if type is CAMERA3_MSG_ERROR
1699 */
1700 camera3_error_msg_t error;
1701
1702 /**
1703 * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
1704 */
1705 camera3_shutter_msg_t shutter;
1706
1707 /**
1708 * Generic message contents. Used to ensure a minimum size for custom
1709 * message types.
1710 */
1711 uint8_t generic[32];
1712 } message;
1713
1714} camera3_notify_msg_t;
1715
1716/**********************************************************************
1717 *
1718 * Capture request/result definitions for the HAL process_capture_request()
1719 * method, and the process_capture_result() callback.
1720 *
1721 */
1722
1723/**
1724 * camera3_request_template_t:
1725 *
1726 * Available template types for
1727 * camera3_device_ops.construct_default_request_settings()
1728 */
1729typedef enum camera3_request_template {
1730 /**
1731 * Standard camera preview operation with 3A on auto.
1732 */
1733 CAMERA3_TEMPLATE_PREVIEW = 1,
1734
1735 /**
1736 * Standard camera high-quality still capture with 3A and flash on auto.
1737 */
1738 CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
1739
1740 /**
1741 * Standard video recording plus preview with 3A on auto, torch off.
1742 */
1743 CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
1744
1745 /**
1746 * High-quality still capture while recording video. Application will
1747 * include preview, video record, and full-resolution YUV or JPEG streams in
1748 * request. Must not cause stuttering on video stream. 3A on auto.
1749 */
1750 CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
1751
1752 /**
1753 * Zero-shutter-lag mode. Application will request preview and
1754 * full-resolution data for each frame, and reprocess it to JPEG when a
1755 * still image is requested by user. Settings should provide highest-quality
1756 * full-resolution images without compromising preview frame rate. 3A on
1757 * auto.
1758 */
1759 CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
1760
Zhijun Heb0c939f2013-12-13 15:56:33 -08001761 /**
1762 * A basic template for direct application control of capture
1763 * parameters. All automatic control is disabled (auto-exposure, auto-white
1764 * balance, auto-focus), and post-processing parameters are set to preview
1765 * quality. The manual capture parameters (exposure, sensitivity, etc.)
1766 * are set to reasonable defaults, but should be overridden by the
1767 * application depending on the intended use case.
1768 */
1769 CAMERA3_TEMPLATE_MANUAL = 6,
1770
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001771 /* Total number of templates */
1772 CAMERA3_TEMPLATE_COUNT,
1773
1774 /**
1775 * First value for vendor-defined request templates
1776 */
1777 CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
1778
1779} camera3_request_template_t;
1780
1781/**
1782 * camera3_capture_request_t:
1783 *
1784 * A single request for image capture/buffer reprocessing, sent to the Camera
1785 * HAL device by the framework in process_capture_request().
1786 *
1787 * The request contains the settings to be used for this capture, and the set of
1788 * output buffers to write the resulting image data in. It may optionally
1789 * contain an input buffer, in which case the request is for reprocessing that
1790 * input buffer instead of capturing a new image with the camera sensor. The
1791 * capture is identified by the frame_number.
1792 *
1793 * In response, the camera HAL device must send a camera3_capture_result
1794 * structure asynchronously to the framework, using the process_capture_result()
1795 * callback.
1796 */
1797typedef struct camera3_capture_request {
1798 /**
1799 * The frame number is an incrementing integer set by the framework to
1800 * uniquely identify this capture. It needs to be returned in the result
1801 * call, and is also used to identify the request in asynchronous
1802 * notifications sent to camera3_callback_ops_t.notify().
1803 */
1804 uint32_t frame_number;
1805
1806 /**
1807 * The settings buffer contains the capture and processing parameters for
1808 * the request. As a special case, a NULL settings buffer indicates that the
1809 * settings are identical to the most-recently submitted capture request. A
1810 * NULL buffer cannot be used as the first submitted request after a
1811 * configure_streams() call.
1812 */
1813 const camera_metadata_t *settings;
1814
1815 /**
1816 * The input stream buffer to use for this request, if any.
1817 *
1818 * If input_buffer is NULL, then the request is for a new capture from the
1819 * imager. If input_buffer is valid, the request is for reprocessing the
1820 * image contained in input_buffer.
1821 *
1822 * In the latter case, the HAL must set the release_fence of the
1823 * input_buffer to a valid sync fence, or to -1 if the HAL does not support
1824 * sync, before process_capture_request() returns.
1825 *
1826 * The HAL is required to wait on the acquire sync fence of the input buffer
1827 * before accessing it.
1828 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001829 * <= CAMERA_DEVICE_API_VERSION_3_1:
1830 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001831 * Any input buffer included here will have been registered with the HAL
1832 * through register_stream_buffers() before its inclusion in a request.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001833 *
1834 * >= CAMERA_DEVICE_API_VERSION_3_2:
1835 *
1836 * The buffers will not have been pre-registered with the HAL.
1837 * Subsequent requests may reuse buffers, or provide entirely new buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001838 */
1839 camera3_stream_buffer_t *input_buffer;
1840
1841 /**
1842 * The number of output buffers for this capture request. Must be at least
1843 * 1.
1844 */
1845 uint32_t num_output_buffers;
1846
1847 /**
1848 * An array of num_output_buffers stream buffers, to be filled with image
1849 * data from this capture/reprocess. The HAL must wait on the acquire fences
Igor Murashkin78aa1262014-01-09 16:23:43 -08001850 * of each stream buffer before writing to them.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001851 *
1852 * The HAL takes ownership of the actual buffer_handle_t entries in
1853 * output_buffers; the framework does not access them until they are
1854 * returned in a camera3_capture_result_t.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001855 *
1856 * <= CAMERA_DEVICE_API_VERSION_3_1:
1857 *
1858 * All the buffers included here will have been registered with the HAL
1859 * through register_stream_buffers() before their inclusion in a request.
1860 *
1861 * >= CAMERA_DEVICE_API_VERSION_3_2:
1862 *
1863 * Any or all of the buffers included here may be brand new in this
1864 * request (having never before seen by the HAL).
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001865 */
1866 const camera3_stream_buffer_t *output_buffers;
1867
1868} camera3_capture_request_t;
1869
1870/**
1871 * camera3_capture_result_t:
1872 *
1873 * The result of a single capture/reprocess by the camera HAL device. This is
1874 * sent to the framework asynchronously with process_capture_result(), in
1875 * response to a single capture request sent to the HAL with
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001876 * process_capture_request(). Multiple process_capture_result() calls may be
Igor Murashkin5df2f622014-01-10 14:18:45 -08001877 * performed by the HAL for each request.
1878 *
1879 * Each call, all with the same frame
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001880 * number, may contain some subset of the output buffers, and/or the result
1881 * metadata. The metadata may only be provided once for a given frame number;
1882 * all other calls must set the result metadata to NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001883 *
1884 * The result structure contains the output metadata from this capture, and the
1885 * set of output buffers that have been/will be filled for this capture. Each
1886 * output buffer may come with a release sync fence that the framework will wait
1887 * on before reading, in case the buffer has not yet been filled by the HAL.
1888 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08001889 * >= CAMERA_DEVICE_API_VERSION_3_2:
1890 *
1891 * The metadata may be provided multiple times for a single frame number. The
1892 * framework will accumulate together the final result set by combining each
1893 * partial result together into the total result set.
1894 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001895 * If an input buffer is given in a request, the HAL must return it in one of
1896 * the process_capture_result calls, and the call may be to just return the input
1897 * buffer, without metadata and output buffers; the sync fences must be handled
1898 * the same way they are done for output buffers.
1899 *
1900 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08001901 * Performance considerations:
1902 *
1903 * Applications will also receive these partial results immediately, so sending
1904 * partial results is a highly recommended performance optimization to avoid
1905 * the total pipeline latency before sending the results for what is known very
1906 * early on in the pipeline.
1907 *
1908 * A typical use case might be calculating the AF state halfway through the
1909 * pipeline; by sending the state back to the framework immediately, we get a
1910 * 50% performance increase and perceived responsiveness of the auto-focus.
1911 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001912 */
1913typedef struct camera3_capture_result {
1914 /**
1915 * The frame number is an incrementing integer set by the framework in the
1916 * submitted request to uniquely identify this capture. It is also used to
1917 * identify the request in asynchronous notifications sent to
1918 * camera3_callback_ops_t.notify().
1919 */
1920 uint32_t frame_number;
1921
1922 /**
1923 * The result metadata for this capture. This contains information about the
1924 * final capture parameters, the state of the capture and post-processing
1925 * hardware, the state of the 3A algorithms, if enabled, and the output of
1926 * any enabled statistics units.
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001927 *
1928 * Only one call to process_capture_result() with a given frame_number may
1929 * include the result metadata. All other calls for the same frame_number
1930 * must set this to NULL.
1931 *
1932 * If there was an error producing the result metadata, result must be an
1933 * empty metadata buffer, and notify() must be called with ERROR_RESULT.
Igor Murashkin5df2f622014-01-10 14:18:45 -08001934 *
1935 * >= CAMERA_DEVICE_API_VERSION_3_2:
1936 *
1937 * Multiple calls to process_capture_result() with a given frame_number
1938 * may include the result metadata.
1939 *
1940 * Partial metadata submitted should not include any metadata key returned
1941 * in a previous partial result for a given frame. Each new partial result
1942 * for that frame must also set a distinct partial_result value.
1943 *
1944 * If notify has been called with ERROR_RESULT, all further partial
1945 * results for that frame are ignored by the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001946 */
1947 const camera_metadata_t *result;
1948
1949 /**
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001950 * The number of output buffers returned in this result structure. Must be
1951 * less than or equal to the matching capture request's count. If this is
1952 * less than the buffer count in the capture request, at least one more call
1953 * to process_capture_result with the same frame_number must be made, to
1954 * return the remaining output buffers to the framework. This may only be
Zhijun He52a18892014-06-30 10:35:58 -07001955 * zero if the structure includes valid result metadata or an input buffer
1956 * is returned in this result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001957 */
1958 uint32_t num_output_buffers;
1959
1960 /**
1961 * The handles for the output stream buffers for this capture. They may not
1962 * yet be filled at the time the HAL calls process_capture_result(); the
1963 * framework will wait on the release sync fences provided by the HAL before
1964 * reading the buffers.
1965 *
1966 * The HAL must set the stream buffer's release sync fence to a valid sync
1967 * fd, or to -1 if the buffer has already been filled.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001968 *
1969 * If the HAL encounters an error while processing the buffer, and the
1970 * buffer is not filled, the buffer's status field must be set to
1971 * CAMERA3_BUFFER_STATUS_ERROR. If the HAL did not wait on the acquire fence
1972 * before encountering the error, the acquire fence should be copied into
1973 * the release fence, to allow the framework to wait on the fence before
1974 * reusing the buffer.
1975 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001976 * The acquire fence must be set to -1 for all output buffers. If
1977 * num_output_buffers is zero, this may be NULL. In that case, at least one
1978 * more process_capture_result call must be made by the HAL to provide the
1979 * output buffers.
Igor Murashkin5df2f622014-01-10 14:18:45 -08001980 *
1981 * When process_capture_result is called with a new buffer for a frame,
1982 * all previous frames' buffers for that corresponding stream must have been
1983 * already delivered (the fences need not have yet been signaled).
1984 *
1985 * >= CAMERA_DEVICE_API_VERSION_3_2:
1986 *
1987 * Gralloc buffers for a frame may be sent to framework before the
1988 * corresponding SHUTTER-notify.
1989 *
1990 * Performance considerations:
1991 *
1992 * Buffers delivered to the framework will not be dispatched to the
1993 * application layer until a start of exposure timestamp has been received
1994 * via a SHUTTER notify() call. It is highly recommended to
1995 * dispatch that call as early as possible.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001996 */
1997 const camera3_stream_buffer_t *output_buffers;
1998
Igor Murashkin5df2f622014-01-10 14:18:45 -08001999 /**
2000 * >= CAMERA_DEVICE_API_VERSION_3_2:
2001 *
Zhijun Heceac9e32014-02-05 20:49:45 -08002002 * The handle for the input stream buffer for this capture. It may not
2003 * yet be consumed at the time the HAL calls process_capture_result(); the
2004 * framework will wait on the release sync fences provided by the HAL before
2005 * reusing the buffer.
2006 *
2007 * The HAL should handle the sync fences the same way they are done for
2008 * output_buffers.
2009 *
2010 * Only one input buffer is allowed to be sent per request. Similarly to
2011 * output buffers, the ordering of returned input buffers must be
2012 * maintained by the HAL.
2013 *
2014 * Performance considerations:
2015 *
2016 * The input buffer should be returned as early as possible. If the HAL
2017 * supports sync fences, it can call process_capture_result to hand it back
2018 * with sync fences being set appropriately. If the sync fences are not
2019 * supported, the buffer can only be returned when it is consumed, which
2020 * may take long time; the HAL may choose to copy this input buffer to make
2021 * the buffer return sooner.
2022 */
2023 const camera3_stream_buffer_t *input_buffer;
2024
2025 /**
2026 * >= CAMERA_DEVICE_API_VERSION_3_2:
2027 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002028 * In order to take advantage of partial results, the HAL must set the
2029 * static metadata android.request.partialResultCount to the number of
2030 * partial results it will send for each frame.
2031 *
2032 * Each new capture result with a partial result must set
2033 * this field (partial_result) to a distinct inclusive value between
2034 * 1 and android.request.partialResultCount.
2035 *
2036 * HALs not wishing to take advantage of this feature must not
2037 * set an android.request.partialResultCount or partial_result to a value
2038 * other than 1.
2039 *
2040 * This value must be set to 0 when a capture result contains buffers only
2041 * and no metadata.
2042 */
2043 uint32_t partial_result;
2044
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002045} camera3_capture_result_t;
2046
2047/**********************************************************************
2048 *
2049 * Callback methods for the HAL to call into the framework.
2050 *
2051 * These methods are used to return metadata and image buffers for a completed
2052 * or failed captures, and to notify the framework of asynchronous events such
2053 * as errors.
2054 *
2055 * The framework will not call back into the HAL from within these callbacks,
2056 * and these calls will not block for extended periods.
2057 *
2058 */
2059typedef struct camera3_callback_ops {
2060
2061 /**
2062 * process_capture_result:
2063 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002064 * Send results from a completed capture to the framework.
2065 * process_capture_result() may be invoked multiple times by the HAL in
2066 * response to a single capture request. This allows, for example, the
2067 * metadata and low-resolution buffers to be returned in one call, and
2068 * post-processed JPEG buffers in a later call, once it is available. Each
2069 * call must include the frame number of the request it is returning
2070 * metadata or buffers for.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002071 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002072 * A component (buffer or metadata) of the complete result may only be
2073 * included in one process_capture_result call. A buffer for each stream,
2074 * and the result metadata, must be returned by the HAL for each request in
2075 * one of the process_capture_result calls, even in case of errors producing
2076 * some of the output. A call to process_capture_result() with neither
2077 * output buffers or result metadata is not allowed.
2078 *
2079 * The order of returning metadata and buffers for a single result does not
2080 * matter, but buffers for a given stream must be returned in FIFO order. So
2081 * the buffer for request 5 for stream A must always be returned before the
2082 * buffer for request 6 for stream A. This also applies to the result
2083 * metadata; the metadata for request 5 must be returned before the metadata
2084 * for request 6.
2085 *
2086 * However, different streams are independent of each other, so it is
2087 * acceptable and expected that the buffer for request 5 for stream A may be
2088 * returned after the buffer for request 6 for stream B is. And it is
2089 * acceptable that the result metadata for request 6 for stream B is
2090 * returned before the buffer for request 5 for stream A is.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002091 *
2092 * The HAL retains ownership of result structure, which only needs to be
2093 * valid to access during this call. The framework will copy whatever it
2094 * needs before this call returns.
2095 *
2096 * The output buffers do not need to be filled yet; the framework will wait
2097 * on the stream buffer release sync fence before reading the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002098 * data. Therefore, this method should be called by the HAL as soon as
2099 * possible, even if some or all of the output buffers are still in
2100 * being filled. The HAL must include valid release sync fences into each
2101 * output_buffers stream buffer entry, or -1 if that stream buffer is
2102 * already filled.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002103 *
2104 * If the result buffer cannot be constructed for a request, the HAL should
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002105 * return an empty metadata buffer, but still provide the output buffers and
2106 * their sync fences. In addition, notify() must be called with an
2107 * ERROR_RESULT message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002108 *
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08002109 * If an output buffer cannot be filled, its status field must be set to
2110 * STATUS_ERROR. In addition, notify() must be called with a ERROR_BUFFER
2111 * message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002112 *
2113 * If the entire capture has failed, then this method still needs to be
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08002114 * called to return the output buffers to the framework. All the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002115 * statuses should be STATUS_ERROR, and the result metadata should be an
2116 * empty buffer. In addition, notify() must be called with a ERROR_REQUEST
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002117 * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
2118 * should not be sent.
2119 *
Zhijun He2dde4682014-01-09 09:11:49 -08002120 * Performance requirements:
2121 *
2122 * This is a non-blocking call. The framework will return this call in 5ms.
2123 *
2124 * The pipeline latency (see S7 for definition) should be less than or equal to
2125 * 4 frame intervals, and must be less than or equal to 8 frame intervals.
2126 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002127 */
2128 void (*process_capture_result)(const struct camera3_callback_ops *,
2129 const camera3_capture_result_t *result);
2130
2131 /**
2132 * notify:
2133 *
2134 * Asynchronous notification callback from the HAL, fired for various
2135 * reasons. Only for information independent of frame capture, or that
2136 * require specific timing. The ownership of the message structure remains
2137 * with the HAL, and the msg only needs to be valid for the duration of this
2138 * call.
2139 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002140 * Multiple threads may call notify() simultaneously.
2141 *
2142 * <= CAMERA_DEVICE_API_VERSION_3_1:
2143 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002144 * The notification for the start of exposure for a given request must be
2145 * sent by the HAL before the first call to process_capture_result() for
2146 * that request is made.
2147 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002148 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002149 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002150 * Buffers delivered to the framework will not be dispatched to the
2151 * application layer until a start of exposure timestamp has been received
2152 * via a SHUTTER notify() call. It is highly recommended to
2153 * dispatch this call as early as possible.
2154 *
2155 * ------------------------------------------------------------------------
Zhijun He2dde4682014-01-09 09:11:49 -08002156 * Performance requirements:
2157 *
2158 * This is a non-blocking call. The framework will return this call in 5ms.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002159 */
2160 void (*notify)(const struct camera3_callback_ops *,
2161 const camera3_notify_msg_t *msg);
2162
2163} camera3_callback_ops_t;
2164
2165/**********************************************************************
2166 *
2167 * Camera device operations
2168 *
2169 */
2170typedef struct camera3_device_ops {
2171
2172 /**
2173 * initialize:
2174 *
2175 * One-time initialization to pass framework callback function pointers to
2176 * the HAL. Will be called once after a successful open() call, before any
2177 * other functions are called on the camera3_device_ops structure.
2178 *
Zhijun He2dde4682014-01-09 09:11:49 -08002179 * Performance requirements:
2180 *
2181 * This should be a non-blocking call. The HAL should return from this call
2182 * in 5ms, and must return from this call in 10ms.
2183 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002184 * Return values:
2185 *
2186 * 0: On successful initialization
2187 *
2188 * -ENODEV: If initialization fails. Only close() can be called successfully
2189 * by the framework after this.
2190 */
2191 int (*initialize)(const struct camera3_device *,
2192 const camera3_callback_ops_t *callback_ops);
2193
2194 /**********************************************************************
2195 * Stream management
2196 */
2197
2198 /**
2199 * configure_streams:
2200 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002201 * CAMERA_DEVICE_API_VERSION_3_0 only:
2202 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002203 * Reset the HAL camera device processing pipeline and set up new input and
2204 * output streams. This call replaces any existing stream configuration with
2205 * the streams defined in the stream_list. This method will be called at
2206 * least once after initialize() before a request is submitted with
2207 * process_capture_request().
2208 *
2209 * The stream_list must contain at least one output-capable stream, and may
2210 * not contain more than one input-capable stream.
2211 *
2212 * The stream_list may contain streams that are also in the currently-active
2213 * set of streams (from the previous call to configure_stream()). These
2214 * streams will already have valid values for usage, max_buffers, and the
Igor Murashkin78aa1262014-01-09 16:23:43 -08002215 * private pointer.
2216 *
2217 * If such a stream has already had its buffers registered,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002218 * register_stream_buffers() will not be called again for the stream, and
2219 * buffers from the stream can be immediately included in input requests.
2220 *
2221 * If the HAL needs to change the stream configuration for an existing
2222 * stream due to the new configuration, it may rewrite the values of usage
Igor Murashkin78aa1262014-01-09 16:23:43 -08002223 * and/or max_buffers during the configure call.
2224 *
2225 * The framework will detect such a change, and will then reallocate the
2226 * stream buffers, and call register_stream_buffers() again before using
2227 * buffers from that stream in a request.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002228 *
2229 * If a currently-active stream is not included in stream_list, the HAL may
2230 * safely remove any references to that stream. It will not be reused in a
2231 * later configure() call by the framework, and all the gralloc buffers for
2232 * it will be freed after the configure_streams() call returns.
2233 *
2234 * The stream_list structure is owned by the framework, and may not be
2235 * accessed once this call completes. The address of an individual
2236 * camera3_stream_t structure will remain valid for access by the HAL until
2237 * the end of the first configure_stream() call which no longer includes
2238 * that camera3_stream_t in the stream_list argument. The HAL may not change
2239 * values in the stream structure outside of the private pointer, except for
2240 * the usage and max_buffers members during the configure_streams() call
2241 * itself.
2242 *
2243 * If the stream is new, the usage, max_buffer, and private pointer fields
2244 * of the stream structure will all be set to 0. The HAL device must set
2245 * these fields before the configure_streams() call returns. These fields
2246 * are then used by the framework and the platform gralloc module to
2247 * allocate the gralloc buffers for each stream.
2248 *
2249 * Before such a new stream can have its buffers included in a capture
2250 * request, the framework will call register_stream_buffers() with that
2251 * stream. However, the framework is not required to register buffers for
2252 * _all_ streams before submitting a request. This allows for quick startup
2253 * of (for example) a preview stream, with allocation for other streams
2254 * happening later or concurrently.
2255 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002256 * ------------------------------------------------------------------------
2257 * CAMERA_DEVICE_API_VERSION_3_1 only:
2258 *
2259 * Reset the HAL camera device processing pipeline and set up new input and
2260 * output streams. This call replaces any existing stream configuration with
2261 * the streams defined in the stream_list. This method will be called at
2262 * least once after initialize() before a request is submitted with
2263 * process_capture_request().
2264 *
2265 * The stream_list must contain at least one output-capable stream, and may
2266 * not contain more than one input-capable stream.
2267 *
2268 * The stream_list may contain streams that are also in the currently-active
2269 * set of streams (from the previous call to configure_stream()). These
2270 * streams will already have valid values for usage, max_buffers, and the
2271 * private pointer.
2272 *
2273 * If such a stream has already had its buffers registered,
2274 * register_stream_buffers() will not be called again for the stream, and
2275 * buffers from the stream can be immediately included in input requests.
2276 *
2277 * If the HAL needs to change the stream configuration for an existing
2278 * stream due to the new configuration, it may rewrite the values of usage
2279 * and/or max_buffers during the configure call.
2280 *
2281 * The framework will detect such a change, and will then reallocate the
2282 * stream buffers, and call register_stream_buffers() again before using
2283 * buffers from that stream in a request.
2284 *
2285 * If a currently-active stream is not included in stream_list, the HAL may
2286 * safely remove any references to that stream. It will not be reused in a
2287 * later configure() call by the framework, and all the gralloc buffers for
2288 * it will be freed after the configure_streams() call returns.
2289 *
2290 * The stream_list structure is owned by the framework, and may not be
2291 * accessed once this call completes. The address of an individual
2292 * camera3_stream_t structure will remain valid for access by the HAL until
2293 * the end of the first configure_stream() call which no longer includes
2294 * that camera3_stream_t in the stream_list argument. The HAL may not change
2295 * values in the stream structure outside of the private pointer, except for
2296 * the usage and max_buffers members during the configure_streams() call
2297 * itself.
2298 *
2299 * If the stream is new, max_buffer, and private pointer fields of the
2300 * stream structure will all be set to 0. The usage will be set to the
2301 * consumer usage flags. The HAL device must set these fields before the
2302 * configure_streams() call returns. These fields are then used by the
2303 * framework and the platform gralloc module to allocate the gralloc
2304 * buffers for each stream.
2305 *
2306 * Before such a new stream can have its buffers included in a capture
2307 * request, the framework will call register_stream_buffers() with that
2308 * stream. However, the framework is not required to register buffers for
2309 * _all_ streams before submitting a request. This allows for quick startup
2310 * of (for example) a preview stream, with allocation for other streams
2311 * happening later or concurrently.
2312 *
2313 * ------------------------------------------------------------------------
2314 * >= CAMERA_DEVICE_API_VERSION_3_2:
2315 *
2316 * Reset the HAL camera device processing pipeline and set up new input and
2317 * output streams. This call replaces any existing stream configuration with
2318 * the streams defined in the stream_list. This method will be called at
2319 * least once after initialize() before a request is submitted with
2320 * process_capture_request().
2321 *
2322 * The stream_list must contain at least one output-capable stream, and may
2323 * not contain more than one input-capable stream.
2324 *
2325 * The stream_list may contain streams that are also in the currently-active
2326 * set of streams (from the previous call to configure_stream()). These
2327 * streams will already have valid values for usage, max_buffers, and the
2328 * private pointer.
2329 *
2330 * If the HAL needs to change the stream configuration for an existing
2331 * stream due to the new configuration, it may rewrite the values of usage
2332 * and/or max_buffers during the configure call.
2333 *
2334 * The framework will detect such a change, and may then reallocate the
2335 * stream buffers before using buffers from that stream in a request.
2336 *
2337 * If a currently-active stream is not included in stream_list, the HAL may
2338 * safely remove any references to that stream. It will not be reused in a
2339 * later configure() call by the framework, and all the gralloc buffers for
2340 * it will be freed after the configure_streams() call returns.
2341 *
2342 * The stream_list structure is owned by the framework, and may not be
2343 * accessed once this call completes. The address of an individual
2344 * camera3_stream_t structure will remain valid for access by the HAL until
2345 * the end of the first configure_stream() call which no longer includes
2346 * that camera3_stream_t in the stream_list argument. The HAL may not change
2347 * values in the stream structure outside of the private pointer, except for
2348 * the usage and max_buffers members during the configure_streams() call
2349 * itself.
2350 *
2351 * If the stream is new, max_buffer, and private pointer fields of the
2352 * stream structure will all be set to 0. The usage will be set to the
2353 * consumer usage flags. The HAL device must set these fields before the
2354 * configure_streams() call returns. These fields are then used by the
2355 * framework and the platform gralloc module to allocate the gralloc
2356 * buffers for each stream.
2357 *
2358 * Newly allocated buffers may be included in a capture request at any time
2359 * by the framework. Once a gralloc buffer is returned to the framework
2360 * with process_capture_result (and its respective release_fence has been
2361 * signaled) the framework may free or reuse it at any time.
2362 *
2363 * ------------------------------------------------------------------------
2364 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002365 * Preconditions:
2366 *
2367 * The framework will only call this method when no captures are being
2368 * processed. That is, all results have been returned to the framework, and
2369 * all in-flight input and output buffers have been returned and their
2370 * release sync fences have been signaled by the HAL. The framework will not
2371 * submit new requests for capture while the configure_streams() call is
2372 * underway.
2373 *
2374 * Postconditions:
2375 *
2376 * The HAL device must configure itself to provide maximum possible output
2377 * frame rate given the sizes and formats of the output streams, as
2378 * documented in the camera device's static metadata.
2379 *
Zhijun He2dde4682014-01-09 09:11:49 -08002380 * Performance requirements:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002381 *
2382 * This call is expected to be heavyweight and possibly take several hundred
2383 * milliseconds to complete, since it may require resetting and
2384 * reconfiguring the image sensor and the camera processing pipeline.
2385 * Nevertheless, the HAL device should attempt to minimize the
2386 * reconfiguration delay to minimize the user-visible pauses during
2387 * application operational mode changes (such as switching from still
2388 * capture to video recording).
2389 *
Zhijun He2dde4682014-01-09 09:11:49 -08002390 * The HAL should return from this call in 500ms, and must return from this
2391 * call in 1000ms.
2392 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002393 * Return values:
2394 *
2395 * 0: On successful stream configuration
2396 *
2397 * -EINVAL: If the requested stream configuration is invalid. Some examples
2398 * of invalid stream configurations include:
2399 *
2400 * - Including more than 1 input-capable stream (INPUT or
2401 * BIDIRECTIONAL)
2402 *
2403 * - Not including any output-capable streams (OUTPUT or
2404 * BIDIRECTIONAL)
2405 *
2406 * - Including streams with unsupported formats, or an unsupported
2407 * size for that format.
2408 *
2409 * - Including too many output streams of a certain format.
2410 *
Eino-Ville Talvala7effe0c2013-02-15 12:09:48 -08002411 * Note that the framework submitting an invalid stream
2412 * configuration is not normal operation, since stream
2413 * configurations are checked before configure. An invalid
2414 * configuration means that a bug exists in the framework code, or
2415 * there is a mismatch between the HAL's static metadata and the
2416 * requirements on streams.
2417 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002418 * -ENODEV: If there has been a fatal error and the device is no longer
2419 * operational. Only close() can be called successfully by the
2420 * framework after this error is returned.
2421 */
2422 int (*configure_streams)(const struct camera3_device *,
2423 camera3_stream_configuration_t *stream_list);
2424
2425 /**
2426 * register_stream_buffers:
2427 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002428 * >= CAMERA_DEVICE_API_VERSION_3_2:
2429 *
2430 * DEPRECATED. This will not be called and must be set to NULL.
2431 *
2432 * <= CAMERA_DEVICE_API_VERSION_3_1:
2433 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002434 * Register buffers for a given stream with the HAL device. This method is
2435 * called by the framework after a new stream is defined by
2436 * configure_streams, and before buffers from that stream are included in a
2437 * capture request. If the same stream is listed in a subsequent
2438 * configure_streams() call, register_stream_buffers will _not_ be called
2439 * again for that stream.
2440 *
2441 * The framework does not need to register buffers for all configured
2442 * streams before it submits the first capture request. This allows quick
2443 * startup for preview (or similar use cases) while other streams are still
2444 * being allocated.
2445 *
2446 * This method is intended to allow the HAL device to map or otherwise
2447 * prepare the buffers for later use. The buffers passed in will already be
2448 * locked for use. At the end of the call, all the buffers must be ready to
2449 * be returned to the stream. The buffer_set argument is only valid for the
2450 * duration of this call.
2451 *
2452 * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
2453 * the camera HAL should inspect the passed-in buffers here to determine any
2454 * platform-private pixel format information.
2455 *
Zhijun He2dde4682014-01-09 09:11:49 -08002456 * Performance requirements:
2457 *
2458 * This should be a non-blocking call. The HAL should return from this call
2459 * in 1ms, and must return from this call in 5ms.
2460 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002461 * Return values:
2462 *
2463 * 0: On successful registration of the new stream buffers
2464 *
2465 * -EINVAL: If the stream_buffer_set does not refer to a valid active
2466 * stream, or if the buffers array is invalid.
2467 *
2468 * -ENOMEM: If there was a failure in registering the buffers. The framework
2469 * must consider all the stream buffers to be unregistered, and can
2470 * try to register again later.
2471 *
2472 * -ENODEV: If there is a fatal error, and the device is no longer
2473 * operational. Only close() can be called successfully by the
2474 * framework after this error is returned.
2475 */
2476 int (*register_stream_buffers)(const struct camera3_device *,
2477 const camera3_stream_buffer_set_t *buffer_set);
2478
2479 /**********************************************************************
2480 * Request creation and submission
2481 */
2482
2483 /**
2484 * construct_default_request_settings:
2485 *
2486 * Create capture settings for standard camera use cases.
2487 *
2488 * The device must return a settings buffer that is configured to meet the
2489 * requested use case, which must be one of the CAMERA3_TEMPLATE_*
2490 * enums. All request control fields must be included.
2491 *
2492 * The HAL retains ownership of this structure, but the pointer to the
2493 * structure must be valid until the device is closed. The framework and the
2494 * HAL may not modify the buffer once it is returned by this call. The same
2495 * buffer may be returned for subsequent calls for the same template, or for
2496 * other templates.
2497 *
Zhijun He2dde4682014-01-09 09:11:49 -08002498 * Performance requirements:
2499 *
2500 * This should be a non-blocking call. The HAL should return from this call
2501 * in 1ms, and must return from this call in 5ms.
2502 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002503 * Return values:
2504 *
2505 * Valid metadata: On successful creation of a default settings
2506 * buffer.
2507 *
2508 * NULL: In case of a fatal error. After this is returned, only
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002509 * the close() method can be called successfully by the
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002510 * framework.
2511 */
2512 const camera_metadata_t* (*construct_default_request_settings)(
2513 const struct camera3_device *,
2514 int type);
2515
2516 /**
2517 * process_capture_request:
2518 *
2519 * Send a new capture request to the HAL. The HAL should not return from
2520 * this call until it is ready to accept the next request to process. Only
2521 * one call to process_capture_request() will be made at a time by the
2522 * framework, and the calls will all be from the same thread. The next call
2523 * to process_capture_request() will be made as soon as a new request and
2524 * its associated buffers are available. In a normal preview scenario, this
2525 * means the function will be called again by the framework almost
2526 * instantly.
2527 *
2528 * The actual request processing is asynchronous, with the results of
2529 * capture being returned by the HAL through the process_capture_result()
2530 * call. This call requires the result metadata to be available, but output
2531 * buffers may simply provide sync fences to wait on. Multiple requests are
2532 * expected to be in flight at once, to maintain full output frame rate.
2533 *
2534 * The framework retains ownership of the request structure. It is only
2535 * guaranteed to be valid during this call. The HAL device must make copies
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002536 * of the information it needs to retain for the capture processing. The HAL
2537 * is responsible for waiting on and closing the buffers' fences and
2538 * returning the buffer handles to the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002539 *
2540 * The HAL must write the file descriptor for the input buffer's release
2541 * sync fence into input_buffer->release_fence, if input_buffer is not
2542 * NULL. If the HAL returns -1 for the input buffer release sync fence, the
2543 * framework is free to immediately reuse the input buffer. Otherwise, the
2544 * framework will wait on the sync fence before refilling and reusing the
2545 * input buffer.
2546 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002547 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002548 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002549 * The input/output buffers provided by the framework in each request
2550 * may be brand new (having never before seen by the HAL).
2551 *
2552 * ------------------------------------------------------------------------
2553 * Performance considerations:
2554 *
2555 * Handling a new buffer should be extremely lightweight and there should be
2556 * no frame rate degradation or frame jitter introduced.
2557 *
2558 * This call must return fast enough to ensure that the requested frame
2559 * rate can be sustained, especially for streaming cases (post-processing
2560 * quality settings set to FAST). The HAL should return this call in 1
2561 * frame interval, and must return from this call in 4 frame intervals.
Zhijun He2dde4682014-01-09 09:11:49 -08002562 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002563 * Return values:
2564 *
2565 * 0: On a successful start to processing the capture request
2566 *
2567 * -EINVAL: If the input is malformed (the settings are NULL when not
2568 * allowed, there are 0 output buffers, etc) and capture processing
2569 * cannot start. Failures during request processing should be
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002570 * handled by calling camera3_callback_ops_t.notify(). In case of
2571 * this error, the framework will retain responsibility for the
2572 * stream buffers' fences and the buffer handles; the HAL should
2573 * not close the fences or return these buffers with
2574 * process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002575 *
2576 * -ENODEV: If the camera device has encountered a serious error. After this
2577 * error is returned, only the close() method can be successfully
2578 * called by the framework.
2579 *
2580 */
2581 int (*process_capture_request)(const struct camera3_device *,
2582 camera3_capture_request_t *request);
2583
2584 /**********************************************************************
2585 * Miscellaneous methods
2586 */
2587
2588 /**
2589 * get_metadata_vendor_tag_ops:
2590 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002591 * Get methods to query for vendor extension metadata tag information. The
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002592 * HAL should fill in all the vendor tag operation methods, or leave ops
2593 * unchanged if no vendor tags are defined.
2594 *
2595 * The definition of vendor_tag_query_ops_t can be found in
2596 * system/media/camera/include/system/camera_metadata.h.
2597 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -08002598 * >= CAMERA_DEVICE_API_VERSION_3_2:
2599 * DEPRECATED. This function has been deprecated and should be set to
2600 * NULL by the HAL. Please implement get_vendor_tag_ops in camera_common.h
2601 * instead.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002602 */
2603 void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
2604 vendor_tag_query_ops_t* ops);
2605
2606 /**
2607 * dump:
2608 *
2609 * Print out debugging state for the camera device. This will be called by
2610 * the framework when the camera service is asked for a debug dump, which
2611 * happens when using the dumpsys tool, or when capturing a bugreport.
2612 *
2613 * The passed-in file descriptor can be used to write debugging text using
2614 * dprintf() or write(). The text should be in ASCII encoding only.
Zhijun He2dde4682014-01-09 09:11:49 -08002615 *
2616 * Performance requirements:
2617 *
2618 * This must be a non-blocking call. The HAL should return from this call
2619 * in 1ms, must return from this call in 10ms. This call must avoid
2620 * deadlocks, as it may be called at any point during camera operation.
2621 * Any synchronization primitives used (such as mutex locks or semaphores)
2622 * should be acquired with a timeout.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002623 */
2624 void (*dump)(const struct camera3_device *, int fd);
2625
Alex Ray5f2fd852013-06-24 11:28:05 -07002626 /**
2627 * flush:
2628 *
2629 * Flush all currently in-process captures and all buffers in the pipeline
2630 * on the given device. The framework will use this to dump all state as
2631 * quickly as possible in order to prepare for a configure_streams() call.
2632 *
2633 * No buffers are required to be successfully returned, so every buffer
Zhijun He5a5fbf42014-01-27 14:49:44 -08002634 * held at the time of flush() (whether successfully filled or not) may be
Alex Ray5f2fd852013-06-24 11:28:05 -07002635 * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed
Zhijun He5a5fbf42014-01-27 14:49:44 -08002636 * to return valid (CAMERA3_BUFFER_STATUS_OK) buffers during this call,
2637 * provided they are successfully filled.
Alex Ray5f2fd852013-06-24 11:28:05 -07002638 *
2639 * All requests currently in the HAL are expected to be returned as soon as
2640 * possible. Not-in-process requests should return errors immediately. Any
2641 * interruptible hardware blocks should be stopped, and any uninterruptible
2642 * blocks should be waited on.
2643 *
Zhijun He5a5fbf42014-01-27 14:49:44 -08002644 * More specifically, the HAL must follow below requirements for various cases:
2645 *
2646 * 1. For captures that are too late for the HAL to cancel/stop, and will be
2647 * completed normally by the HAL; i.e. the HAL can send shutter/notify and
2648 * process_capture_result and buffers as normal.
2649 *
2650 * 2. For pending requests that have not done any processing, the HAL must call notify
2651 * CAMERA3_MSG_ERROR_REQUEST, and return all the output buffers with
2652 * process_capture_result in the error state (CAMERA3_BUFFER_STATUS_ERROR).
2653 * The HAL must not place the release fence into an error state, instead,
2654 * the release fences must be set to the acquire fences passed by the framework,
2655 * or -1 if they have been waited on by the HAL already. This is also the path
2656 * to follow for any captures for which the HAL already called notify() with
2657 * CAMERA3_MSG_SHUTTER but won't be producing any metadata/valid buffers for.
2658 * After CAMERA3_MSG_ERROR_REQUEST, for a given frame, only process_capture_results with
2659 * buffers in CAMERA3_BUFFER_STATUS_ERROR are allowed. No further notifys or
2660 * process_capture_result with non-null metadata is allowed.
2661 *
2662 * 3. For partially completed pending requests that will not have all the output
2663 * buffers or perhaps missing metadata, the HAL should follow below:
2664 *
2665 * 3.1. Call notify with CAMERA3_MSG_ERROR_RESULT if some of the expected result
2666 * metadata (i.e. one or more partial metadata) won't be available for the capture.
2667 *
2668 * 3.2. Call notify with CAMERA3_MSG_ERROR_BUFFER for every buffer that won't
2669 * be produced for the capture.
2670 *
2671 * 3.3 Call notify with CAMERA3_MSG_SHUTTER with the capture timestamp before
2672 * any buffers/metadata are returned with process_capture_result.
2673 *
2674 * 3.4 For captures that will produce some results, the HAL must not call
2675 * CAMERA3_MSG_ERROR_REQUEST, since that indicates complete failure.
2676 *
2677 * 3.5. Valid buffers/metadata should be passed to the framework as normal.
2678 *
2679 * 3.6. Failed buffers should be returned to the framework as described for case 2.
2680 * But failed buffers do not have to follow the strict ordering valid buffers do,
2681 * and may be out-of-order with respect to valid buffers. For example, if buffers
2682 * A, B, C, D, E are sent, D and E are failed, then A, E, B, D, C is an acceptable
2683 * return order.
2684 *
2685 * 3.7. For fully-missing metadata, calling CAMERA3_MSG_ERROR_RESULT is sufficient, no
2686 * need to call process_capture_result with NULL metadata or equivalent.
2687 *
Alex Ray5f2fd852013-06-24 11:28:05 -07002688 * flush() should only return when there are no more outstanding buffers or
Zhijun He5a5fbf42014-01-27 14:49:44 -08002689 * requests left in the HAL. The framework may call configure_streams (as
Alex Ray5f2fd852013-06-24 11:28:05 -07002690 * the HAL state is now quiesced) or may issue new requests.
2691 *
Zhijun He5a5fbf42014-01-27 14:49:44 -08002692 * Note that it's sufficient to only support fully-succeeded and fully-failed result cases.
2693 * However, it is highly desirable to support the partial failure cases as well, as it
2694 * could help improve the flush call overall performance.
2695 *
Zhijun He2dde4682014-01-09 09:11:49 -08002696 * Performance requirements:
2697 *
2698 * The HAL should return from this call in 100ms, and must return from this
2699 * call in 1000ms. And this call must not be blocked longer than pipeline
2700 * latency (see S7 for definition).
Alex Ray5f2fd852013-06-24 11:28:05 -07002701 *
2702 * Version information:
2703 *
2704 * only available if device version >= CAMERA_DEVICE_API_VERSION_3_1.
2705 *
2706 * Return values:
2707 *
2708 * 0: On a successful flush of the camera HAL.
2709 *
2710 * -EINVAL: If the input is malformed (the device is not valid).
2711 *
2712 * -ENODEV: If the camera device has encountered a serious error. After this
2713 * error is returned, only the close() method can be successfully
2714 * called by the framework.
2715 */
2716 int (*flush)(const struct camera3_device *);
2717
2718 /* reserved for future use */
2719 void *reserved[8];
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002720} camera3_device_ops_t;
2721
2722/**********************************************************************
2723 *
2724 * Camera device definition
2725 *
2726 */
2727typedef struct camera3_device {
2728 /**
2729 * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
2730 * device as implementing version 3.0 of the camera device HAL.
Zhijun He2dde4682014-01-09 09:11:49 -08002731 *
2732 * Performance requirements:
2733 *
Zhijun He06da1b32014-02-10 16:04:23 -08002734 * Camera open (common.module->common.methods->open) should return in 200ms, and must return
2735 * in 500ms.
Zhijun He2020ee22014-01-31 11:35:45 -08002736 * Camera close (common.close) should return in 200ms, and must return in 500ms.
2737 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002738 */
2739 hw_device_t common;
2740 camera3_device_ops_t *ops;
2741 void *priv;
2742} camera3_device_t;
2743
2744__END_DECLS
2745
2746#endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */