blob: b326e9227f96257987ea93767c28c9d95f4f06bb [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
282 * settings/result/static info metadata. Full-mode devices must support all
283 * metadata fields listed in TODO. Specifically, only the following settings
284 * are expected to be consumed or produced by a limited-mode HAL device:
285 *
286 * android.control.aeAntibandingMode (controls)
287 * android.control.aeExposureCompensation (controls)
288 * android.control.aeLock (controls)
289 * android.control.aeMode (controls)
290 * [OFF means ON_FLASH_TORCH - TODO]
291 * android.control.aeRegions (controls)
292 * android.control.aeTargetFpsRange (controls)
293 * android.control.afMode (controls)
294 * [OFF means infinity focus]
295 * android.control.afRegions (controls)
296 * android.control.awbLock (controls)
297 * android.control.awbMode (controls)
298 * [OFF not supported]
299 * android.control.awbRegions (controls)
300 * android.control.captureIntent (controls)
301 * android.control.effectMode (controls)
302 * android.control.mode (controls)
303 * [OFF not supported]
304 * android.control.sceneMode (controls)
305 * android.control.videoStabilizationMode (controls)
306 * android.control.aeAvailableAntibandingModes (static)
307 * android.control.aeAvailableModes (static)
308 * android.control.aeAvailableTargetFpsRanges (static)
309 * android.control.aeCompensationRange (static)
310 * android.control.aeCompensationStep (static)
311 * android.control.afAvailableModes (static)
312 * android.control.availableEffects (static)
313 * android.control.availableSceneModes (static)
314 * android.control.availableVideoStabilizationModes (static)
315 * android.control.awbAvailableModes (static)
316 * android.control.maxRegions (static)
317 * android.control.sceneModeOverrides (static)
318 * android.control.aeRegions (dynamic)
319 * android.control.aeState (dynamic)
320 * android.control.afMode (dynamic)
321 * android.control.afRegions (dynamic)
322 * android.control.afState (dynamic)
323 * android.control.awbMode (dynamic)
324 * android.control.awbRegions (dynamic)
325 * android.control.awbState (dynamic)
326 * android.control.mode (dynamic)
327 *
328 * android.flash.info.available (static)
329 *
330 * android.info.supportedHardwareLevel (static)
331 *
332 * android.jpeg.gpsCoordinates (controls)
333 * android.jpeg.gpsProcessingMethod (controls)
334 * android.jpeg.gpsTimestamp (controls)
335 * android.jpeg.orientation (controls)
336 * android.jpeg.quality (controls)
337 * android.jpeg.thumbnailQuality (controls)
338 * android.jpeg.thumbnailSize (controls)
339 * android.jpeg.availableThumbnailSizes (static)
340 * android.jpeg.maxSize (static)
341 * android.jpeg.gpsCoordinates (dynamic)
342 * android.jpeg.gpsProcessingMethod (dynamic)
343 * android.jpeg.gpsTimestamp (dynamic)
344 * android.jpeg.orientation (dynamic)
345 * android.jpeg.quality (dynamic)
346 * android.jpeg.size (dynamic)
347 * android.jpeg.thumbnailQuality (dynamic)
348 * android.jpeg.thumbnailSize (dynamic)
349 *
350 * android.lens.info.minimumFocusDistance (static)
351 *
352 * android.request.id (controls)
353 * android.request.id (dynamic)
354 *
355 * android.scaler.cropRegion (controls)
356 * [ignores (x,y), assumes center-zoom]
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -0800357 * android.scaler.availableStreamConfigurations (static)
358 * android.scaler.availableMinFrameDurations (static)
359 * android.scaler.availableStallDurations (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800360 * android.scaler.availableMaxDigitalZoom (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800361 * [full resolution not supported]
362 * android.scaler.maxDigitalZoom (static)
363 * android.scaler.cropRegion (dynamic)
364 *
365 * android.sensor.orientation (static)
366 * android.sensor.timestamp (dynamic)
367 *
368 * android.statistics.faceDetectMode (controls)
369 * android.statistics.info.availableFaceDetectModes (static)
370 * android.statistics.faceDetectMode (dynamic)
371 * android.statistics.faceIds (dynamic)
372 * android.statistics.faceLandmarks (dynamic)
373 * android.statistics.faceRectangles (dynamic)
374 * android.statistics.faceScores (dynamic)
375 *
376 * - Captures in limited mode that include high-resolution (> 1080p) output
377 * buffers may block in process_capture_request() until all the output buffers
378 * have been filled. A full-mode HAL device must process sequences of
379 * high-resolution requests at the rate indicated in the static metadata for
380 * that pixel format. The HAL must still call process_capture_result() to
381 * provide the output; the framework must simply be prepared for
382 * process_capture_request() to block until after process_capture_result() for
383 * that request completes for high-resolution captures for limited-mode
384 * devices.
385 *
386 */
387
388/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700389 * S4. 3A modes and state machines:
390 *
391 * While the actual 3A algorithms are up to the HAL implementation, a high-level
392 * state machine description is defined by the HAL interface, to allow the HAL
393 * device and the framework to communicate about the current state of 3A, and to
394 * trigger 3A events.
395 *
396 * When the device is opened, all the individual 3A states must be
397 * STATE_INACTIVE. Stream configuration does not reset 3A. For example, locked
398 * focus must be maintained across the configure() call.
399 *
400 * Triggering a 3A action involves simply setting the relevant trigger entry in
401 * the settings for the next request to indicate start of trigger. For example,
402 * the trigger for starting an autofocus scan is setting the entry
403 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTROL_AF_TRIGGER_START for one
404 * request, and cancelling an autofocus scan is triggered by setting
405 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTRL_AF_TRIGGER_CANCEL. Otherwise,
406 * the entry will not exist, or be set to ANDROID_CONTROL_AF_TRIGGER_IDLE. Each
407 * request with a trigger entry set to a non-IDLE value will be treated as an
408 * independent triggering event.
409 *
410 * At the top level, 3A is controlled by the ANDROID_CONTROL_MODE setting, which
411 * selects between no 3A (ANDROID_CONTROL_MODE_OFF), normal AUTO mode
412 * (ANDROID_CONTROL_MODE_AUTO), and using the scene mode setting
413 * (ANDROID_CONTROL_USE_SCENE_MODE).
414 *
415 * - In OFF mode, each of the individual AE/AF/AWB modes are effectively OFF,
416 * and none of the capture controls may be overridden by the 3A routines.
417 *
418 * - In AUTO mode, Auto-focus, auto-exposure, and auto-whitebalance all run
419 * their own independent algorithms, and have their own mode, state, and
420 * trigger metadata entries, as listed in the next section.
421 *
422 * - In USE_SCENE_MODE, the value of the ANDROID_CONTROL_SCENE_MODE entry must
423 * be used to determine the behavior of 3A routines. In SCENE_MODEs other than
424 * FACE_PRIORITY, the HAL must override the values of
425 * ANDROId_CONTROL_AE/AWB/AF_MODE to be the mode it prefers for the selected
426 * SCENE_MODE. For example, the HAL may prefer SCENE_MODE_NIGHT to use
427 * CONTINUOUS_FOCUS AF mode. Any user selection of AE/AWB/AF_MODE when scene
428 * must be ignored for these scene modes.
429 *
430 * - For SCENE_MODE_FACE_PRIORITY, the AE/AWB/AF_MODE controls work as in
431 * ANDROID_CONTROL_MODE_AUTO, but the 3A routines must bias toward metering
432 * and focusing on any detected faces in the scene.
433 *
434 * S4.1. Auto-focus settings and result entries:
435 *
436 * Main metadata entries:
437 *
438 * ANDROID_CONTROL_AF_MODE: Control for selecting the current autofocus
439 * mode. Set by the framework in the request settings.
440 *
441 * AF_MODE_OFF: AF is disabled; the framework/app directly controls lens
442 * position.
443 *
444 * AF_MODE_AUTO: Single-sweep autofocus. No lens movement unless AF is
445 * triggered.
446 *
447 * AF_MODE_MACRO: Single-sweep up-close autofocus. No lens movement unless
448 * AF is triggered.
449 *
450 * AF_MODE_CONTINUOUS_VIDEO: Smooth continuous focusing, for recording
451 * video. Triggering immediately locks focus in current
452 * position. Canceling resumes cotinuous focusing.
453 *
454 * AF_MODE_CONTINUOUS_PICTURE: Fast continuous focusing, for
455 * zero-shutter-lag still capture. Triggering locks focus once currently
456 * active sweep concludes. Canceling resumes continuous focusing.
457 *
458 * AF_MODE_EDOF: Advanced extended depth of field focusing. There is no
459 * autofocus scan, so triggering one or canceling one has no effect.
460 * Images are focused automatically by the HAL.
461 *
462 * ANDROID_CONTROL_AF_STATE: Dynamic metadata describing the current AF
463 * algorithm state, reported by the HAL in the result metadata.
464 *
465 * AF_STATE_INACTIVE: No focusing has been done, or algorithm was
466 * reset. Lens is not moving. Always the state for MODE_OFF or MODE_EDOF.
467 * When the device is opened, it must start in this state.
468 *
469 * AF_STATE_PASSIVE_SCAN: A continuous focus algorithm is currently scanning
470 * for good focus. The lens is moving.
471 *
472 * AF_STATE_PASSIVE_FOCUSED: A continuous focus algorithm believes it is
473 * well focused. The lens is not moving. The HAL may spontaneously leave
474 * this state.
475 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700476 * AF_STATE_PASSIVE_UNFOCUSED: A continuous focus algorithm believes it is
477 * not well focused. The lens is not moving. The HAL may spontaneously
478 * leave this state.
479 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700480 * AF_STATE_ACTIVE_SCAN: A scan triggered by the user is underway.
481 *
482 * AF_STATE_FOCUSED_LOCKED: The AF algorithm believes it is focused. The
483 * lens is not moving.
484 *
485 * AF_STATE_NOT_FOCUSED_LOCKED: The AF algorithm has been unable to
486 * focus. The lens is not moving.
487 *
488 * ANDROID_CONTROL_AF_TRIGGER: Control for starting an autofocus scan, the
489 * meaning of which is mode- and state- dependent. Set by the framework in
490 * the request settings.
491 *
492 * AF_TRIGGER_IDLE: No current trigger.
493 *
494 * AF_TRIGGER_START: Trigger start of AF scan. Effect is mode and state
495 * dependent.
496 *
497 * AF_TRIGGER_CANCEL: Cancel current AF scan if any, and reset algorithm to
498 * default.
499 *
500 * Additional metadata entries:
501 *
502 * ANDROID_CONTROL_AF_REGIONS: Control for selecting the regions of the FOV
503 * that should be used to determine good focus. This applies to all AF
504 * modes that scan for focus. Set by the framework in the request
505 * settings.
506 *
507 * S4.2. Auto-exposure settings and result entries:
508 *
509 * Main metadata entries:
510 *
511 * ANDROID_CONTROL_AE_MODE: Control for selecting the current auto-exposure
512 * mode. Set by the framework in the request settings.
513 *
514 * AE_MODE_OFF: Autoexposure is disabled; the user controls exposure, gain,
515 * frame duration, and flash.
516 *
517 * AE_MODE_ON: Standard autoexposure, with flash control disabled. User may
518 * set flash to fire or to torch mode.
519 *
520 * AE_MODE_ON_AUTO_FLASH: Standard autoexposure, with flash on at HAL's
521 * discretion for precapture and still capture. User control of flash
522 * disabled.
523 *
524 * AE_MODE_ON_ALWAYS_FLASH: Standard autoexposure, with flash always fired
525 * for capture, and at HAL's discretion for precapture.. User control of
526 * flash disabled.
527 *
528 * AE_MODE_ON_AUTO_FLASH_REDEYE: Standard autoexposure, with flash on at
529 * HAL's discretion for precapture and still capture. Use a flash burst
530 * at end of precapture sequence to reduce redeye in the final
531 * picture. User control of flash disabled.
532 *
533 * ANDROID_CONTROL_AE_STATE: Dynamic metadata describing the current AE
534 * algorithm state, reported by the HAL in the result metadata.
535 *
536 * AE_STATE_INACTIVE: Initial AE state after mode switch. When the device is
537 * opened, it must start in this state.
538 *
539 * AE_STATE_SEARCHING: AE is not converged to a good value, and is adjusting
540 * exposure parameters.
541 *
542 * AE_STATE_CONVERGED: AE has found good exposure values for the current
543 * scene, and the exposure parameters are not changing. HAL may
544 * spontaneously leave this state to search for better solution.
545 *
546 * AE_STATE_LOCKED: AE has been locked with the AE_LOCK control. Exposure
547 * values are not changing.
548 *
549 * AE_STATE_FLASH_REQUIRED: The HAL has converged exposure, but believes
550 * flash is required for a sufficiently bright picture. Used for
551 * determining if a zero-shutter-lag frame can be used.
552 *
553 * AE_STATE_PRECAPTURE: The HAL is in the middle of a precapture
554 * sequence. Depending on AE mode, this mode may involve firing the
555 * flash for metering, or a burst of flash pulses for redeye reduction.
556 *
557 * ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER: Control for starting a metering
558 * sequence before capturing a high-quality image. Set by the framework in
559 * the request settings.
560 *
561 * PRECAPTURE_TRIGGER_IDLE: No current trigger.
562 *
563 * PRECAPTURE_TRIGGER_START: Start a precapture sequence. The HAL should
564 * use the subsequent requests to measure good exposure/white balance
565 * for an upcoming high-resolution capture.
566 *
567 * Additional metadata entries:
568 *
569 * ANDROID_CONTROL_AE_LOCK: Control for locking AE controls to their current
570 * values
571 *
572 * ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION: Control for adjusting AE
573 * algorithm target brightness point.
574 *
575 * ANDROID_CONTROL_AE_TARGET_FPS_RANGE: Control for selecting the target frame
576 * rate range for the AE algorithm. The AE routine cannot change the frame
577 * rate to be outside these bounds.
578 *
579 * ANDROID_CONTROL_AE_REGIONS: Control for selecting the regions of the FOV
580 * that should be used to determine good exposure levels. This applies to
581 * all AE modes besides OFF.
582 *
583 * S4.3. Auto-whitebalance settings and result entries:
584 *
585 * Main metadata entries:
586 *
587 * ANDROID_CONTROL_AWB_MODE: Control for selecting the current white-balance
588 * mode.
589 *
590 * AWB_MODE_OFF: Auto-whitebalance is disabled. User controls color matrix.
591 *
592 * AWB_MODE_AUTO: Automatic white balance is enabled; 3A controls color
593 * transform, possibly using more complex transforms than a simple
594 * matrix.
595 *
596 * AWB_MODE_INCANDESCENT: Fixed white balance settings good for indoor
597 * incandescent (tungsten) lighting, roughly 2700K.
598 *
599 * AWB_MODE_FLUORESCENT: Fixed white balance settings good for fluorescent
600 * lighting, roughly 5000K.
601 *
602 * AWB_MODE_WARM_FLUORESCENT: Fixed white balance settings good for
603 * fluorescent lighting, roughly 3000K.
604 *
605 * AWB_MODE_DAYLIGHT: Fixed white balance settings good for daylight,
606 * roughly 5500K.
607 *
608 * AWB_MODE_CLOUDY_DAYLIGHT: Fixed white balance settings good for clouded
609 * daylight, roughly 6500K.
610 *
611 * AWB_MODE_TWILIGHT: Fixed white balance settings good for
612 * near-sunset/sunrise, roughly 15000K.
613 *
614 * AWB_MODE_SHADE: Fixed white balance settings good for areas indirectly
615 * lit by the sun, roughly 7500K.
616 *
617 * ANDROID_CONTROL_AWB_STATE: Dynamic metadata describing the current AWB
618 * algorithm state, reported by the HAL in the result metadata.
619 *
620 * AWB_STATE_INACTIVE: Initial AWB state after mode switch. When the device
621 * is opened, it must start in this state.
622 *
623 * AWB_STATE_SEARCHING: AWB is not converged to a good value, and is
624 * changing color adjustment parameters.
625 *
626 * AWB_STATE_CONVERGED: AWB has found good color adjustment values for the
627 * current scene, and the parameters are not changing. HAL may
628 * spontaneously leave this state to search for better solution.
629 *
630 * AWB_STATE_LOCKED: AWB has been locked with the AWB_LOCK control. Color
631 * adjustment values are not changing.
632 *
633 * Additional metadata entries:
634 *
635 * ANDROID_CONTROL_AWB_LOCK: Control for locking AWB color adjustments to
636 * their current values.
637 *
638 * ANDROID_CONTROL_AWB_REGIONS: Control for selecting the regions of the FOV
639 * that should be used to determine good color balance. This applies only
640 * to auto-WB mode.
641 *
642 * S4.4. General state machine transition notes
643 *
644 * Switching between AF, AE, or AWB modes always resets the algorithm's state
645 * to INACTIVE. Similarly, switching between CONTROL_MODE or
646 * CONTROL_SCENE_MODE if CONTROL_MODE == USE_SCENE_MODE resets all the
647 * algorithm states to INACTIVE.
648 *
649 * The tables below are per-mode.
650 *
651 * S4.5. AF state machines
652 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700653 * when enabling AF or changing AF mode
654 *| state | trans. cause | new state | notes |
655 *+--------------------+---------------+--------------------+------------------+
656 *| Any | AF mode change| INACTIVE | |
657 *+--------------------+---------------+--------------------+------------------+
658 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700659 * mode = AF_MODE_OFF or AF_MODE_EDOF
660 *| state | trans. cause | new state | notes |
661 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700662 *| INACTIVE | | INACTIVE | Never changes |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700663 *+--------------------+---------------+--------------------+------------------+
664 *
665 * mode = AF_MODE_AUTO or AF_MODE_MACRO
666 *| state | trans. cause | new state | notes |
667 *+--------------------+---------------+--------------------+------------------+
668 *| INACTIVE | AF_TRIGGER | ACTIVE_SCAN | Start AF sweep |
669 *| | | | Lens now moving |
670 *+--------------------+---------------+--------------------+------------------+
671 *| ACTIVE_SCAN | AF sweep done | FOCUSED_LOCKED | If AF successful |
672 *| | | | Lens now locked |
673 *+--------------------+---------------+--------------------+------------------+
674 *| ACTIVE_SCAN | AF sweep done | NOT_FOCUSED_LOCKED | If AF successful |
675 *| | | | Lens now locked |
676 *+--------------------+---------------+--------------------+------------------+
677 *| ACTIVE_SCAN | AF_CANCEL | INACTIVE | Cancel/reset AF |
678 *| | | | Lens now locked |
679 *+--------------------+---------------+--------------------+------------------+
680 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
681 *+--------------------+---------------+--------------------+------------------+
682 *| FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
683 *| | | | Lens now moving |
684 *+--------------------+---------------+--------------------+------------------+
685 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
686 *+--------------------+---------------+--------------------+------------------+
687 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
688 *| | | | Lens now moving |
689 *+--------------------+---------------+--------------------+------------------+
690 *| All states | mode change | INACTIVE | |
691 *+--------------------+---------------+--------------------+------------------+
692 *
693 * mode = AF_MODE_CONTINUOUS_VIDEO
694 *| state | trans. cause | new state | notes |
695 *+--------------------+---------------+--------------------+------------------+
696 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
697 *| | new scan | | Lens now moving |
698 *+--------------------+---------------+--------------------+------------------+
699 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
700 *| | | | Lens now locked |
701 *+--------------------+---------------+--------------------+------------------+
702 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
703 *| | current scan | | Lens now locked |
704 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700705 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
706 *| | current scan | | Lens now locked |
707 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700708 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
709 *| | | | if focus is good |
710 *| | | | Lens now locked |
711 *+--------------------+---------------+--------------------+------------------+
712 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
713 *| | | | if focus is bad |
714 *| | | | Lens now locked |
715 *+--------------------+---------------+--------------------+------------------+
716 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
717 *| | | | position |
718 *| | | | Lens now locked |
719 *+--------------------+---------------+--------------------+------------------+
720 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
721 *| | new scan | | Lens now moving |
722 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700723 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
724 *| | new scan | | Lens now moving |
725 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700726 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700727 *| | | | Lens now locked |
728 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700729 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700730 *| | | | Lens now locked |
731 *+--------------------+---------------+--------------------+------------------+
732 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
733 *+--------------------+---------------+--------------------+------------------+
734 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
735 *+--------------------+---------------+--------------------+------------------+
736 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
737 *+--------------------+---------------+--------------------+------------------+
738 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
739 *+--------------------+---------------+--------------------+------------------+
740 *
741 * mode = AF_MODE_CONTINUOUS_PICTURE
742 *| state | trans. cause | new state | notes |
743 *+--------------------+---------------+--------------------+------------------+
744 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
745 *| | new scan | | Lens now moving |
746 *+--------------------+---------------+--------------------+------------------+
747 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
748 *| | | | Lens now locked |
749 *+--------------------+---------------+--------------------+------------------+
750 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
751 *| | current scan | | Lens now locked |
752 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700753 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
754 *| | current scan | | Lens now locked |
755 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700756 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Eventual trans. |
757 *| | | | once focus good |
758 *| | | | Lens now locked |
759 *+--------------------+---------------+--------------------+------------------+
760 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Eventual trans. |
761 *| | | | if cannot focus |
762 *| | | | Lens now locked |
763 *+--------------------+---------------+--------------------+------------------+
764 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
765 *| | | | position |
766 *| | | | Lens now locked |
767 *+--------------------+---------------+--------------------+------------------+
768 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
769 *| | new scan | | Lens now moving |
770 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700771 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
772 *| | new scan | | Lens now moving |
773 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700774 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700775 *| | | | Lens now locked |
776 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700777 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700778 *| | | | Lens now locked |
779 *+--------------------+---------------+--------------------+------------------+
780 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
781 *+--------------------+---------------+--------------------+------------------+
782 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
783 *+--------------------+---------------+--------------------+------------------+
784 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
785 *+--------------------+---------------+--------------------+------------------+
786 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
787 *+--------------------+---------------+--------------------+------------------+
788 *
789 * S4.6. AE and AWB state machines
790 *
791 * The AE and AWB state machines are mostly identical. AE has additional
792 * FLASH_REQUIRED and PRECAPTURE states. So rows below that refer to those two
793 * states should be ignored for the AWB state machine.
794 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700795 * when enabling AE/AWB or changing AE/AWB mode
796 *| state | trans. cause | new state | notes |
797 *+--------------------+---------------+--------------------+------------------+
798 *| Any | mode change | INACTIVE | |
799 *+--------------------+---------------+--------------------+------------------+
800 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700801 * mode = AE_MODE_OFF / AWB mode not AUTO
802 *| state | trans. cause | new state | notes |
803 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700804 *| INACTIVE | | INACTIVE | AE/AWB disabled |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700805 *+--------------------+---------------+--------------------+------------------+
806 *
807 * mode = AE_MODE_ON_* / AWB_MODE_AUTO
808 *| state | trans. cause | new state | notes |
809 *+--------------------+---------------+--------------------+------------------+
810 *| INACTIVE | HAL initiates | SEARCHING | |
811 *| | AE/AWB scan | | |
812 *+--------------------+---------------+--------------------+------------------+
813 *| INACTIVE | AE/AWB_LOCK | LOCKED | values locked |
814 *| | on | | |
815 *+--------------------+---------------+--------------------+------------------+
816 *| SEARCHING | HAL finishes | CONVERGED | good values, not |
817 *| | AE/AWB scan | | changing |
818 *+--------------------+---------------+--------------------+------------------+
819 *| SEARCHING | HAL finishes | FLASH_REQUIRED | converged but too|
820 *| | AE scan | | dark w/o flash |
821 *+--------------------+---------------+--------------------+------------------+
822 *| SEARCHING | AE/AWB_LOCK | LOCKED | values locked |
823 *| | on | | |
824 *+--------------------+---------------+--------------------+------------------+
825 *| CONVERGED | HAL initiates | SEARCHING | values locked |
826 *| | AE/AWB scan | | |
827 *+--------------------+---------------+--------------------+------------------+
828 *| CONVERGED | AE/AWB_LOCK | LOCKED | values locked |
829 *| | on | | |
830 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala73dba5e2013-05-21 16:29:14 -0700831 *| FLASH_REQUIRED | HAL initiates | SEARCHING | values locked |
832 *| | AE/AWB scan | | |
833 *+--------------------+---------------+--------------------+------------------+
834 *| FLASH_REQUIRED | AE/AWB_LOCK | LOCKED | values locked |
835 *| | on | | |
836 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700837 *| LOCKED | AE/AWB_LOCK | SEARCHING | values not good |
838 *| | off | | after unlock |
839 *+--------------------+---------------+--------------------+------------------+
840 *| LOCKED | AE/AWB_LOCK | CONVERGED | values good |
841 *| | off | | after unlock |
842 *+--------------------+---------------+--------------------+------------------+
843 *| LOCKED | AE_LOCK | FLASH_REQUIRED | exposure good, |
844 *| | off | | but too dark |
845 *+--------------------+---------------+--------------------+------------------+
846 *| All AE states | PRECAPTURE_ | PRECAPTURE | Start precapture |
847 *| | START | | sequence |
848 *+--------------------+---------------+--------------------+------------------+
849 *| PRECAPTURE | Sequence done.| CONVERGED | Ready for high- |
850 *| | AE_LOCK off | | quality capture |
851 *+--------------------+---------------+--------------------+------------------+
852 *| PRECAPTURE | Sequence done.| LOCKED | Ready for high- |
853 *| | AE_LOCK on | | quality capture |
854 *+--------------------+---------------+--------------------+------------------+
855 *
856 */
857
858/**
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700859 * S5. Cropping:
860 *
861 * Cropping of the full pixel array (for digital zoom and other use cases where
862 * a smaller FOV is desirable) is communicated through the
863 * ANDROID_SCALER_CROP_REGION setting. This is a per-request setting, and can
864 * change on a per-request basis, which is critical for implementing smooth
865 * digital zoom.
866 *
867 * The region is defined as a rectangle (x, y, width, height), with (x, y)
868 * describing the top-left corner of the rectangle. The rectangle is defined on
869 * the coordinate system of the sensor active pixel array, with (0,0) being the
870 * top-left pixel of the active pixel array. Therefore, the width and height
871 * cannot be larger than the dimensions reported in the
872 * ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY static info field. The minimum allowed
873 * width and height are reported by the HAL through the
874 * ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes the
875 * maximum supported zoom factor. Therefore, the minimum crop region width and
876 * height are:
877 *
878 * {width, height} =
879 * { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
880 * ANDROID_SCALER_MAX_DIGITAL_ZOOM),
881 * floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
882 * ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
883 *
884 * If the crop region needs to fulfill specific requirements (for example, it
885 * needs to start on even coordinates, and its width/height needs to be even),
886 * the HAL must do the necessary rounding and write out the final crop region
887 * used in the output result metadata. Similarly, if the HAL implements video
888 * stabilization, it must adjust the result crop region to describe the region
889 * actually included in the output after video stabilization is applied. In
890 * general, a camera-using application must be able to determine the field of
891 * view it is receiving based on the crop region, the dimensions of the image
892 * sensor, and the lens focal length.
893 *
Zhijun Hef1ee67e2014-05-21 11:18:51 -0700894 * It is assumed that the cropping is applied after raw to other color space
895 * conversion. Raw streams (RAW16 and RAW_OPAQUE) don't have this conversion stage,
896 * and are not croppable. Therefore, the crop region must be ignored by the HAL
897 * for raw streams.
898 *
899 * Since the crop region applies to all non-raw streams, which may have different aspect
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700900 * ratios than the crop region, the exact sensor region used for each stream may
901 * be smaller than the crop region. Specifically, each stream should maintain
902 * square pixels and its aspect ratio by minimally further cropping the defined
903 * crop region. If the stream's aspect ratio is wider than the crop region, the
904 * stream should be further cropped vertically, and if the stream's aspect ratio
905 * is narrower than the crop region, the stream should be further cropped
906 * horizontally.
907 *
908 * In all cases, the stream crop must be centered within the full crop region,
909 * and each stream is only either cropped horizontally or vertical relative to
910 * the full crop region, never both.
911 *
912 * For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
913 * 1280x720 stream (16:9 aspect), below demonstrates the expected output regions
914 * for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
915 * 1500 pixel array) sensor.
916 *
917 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
918 *
919 * 640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)
920 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
921 *
922 * 0 1000 2000
923 * +---------+---------+---------+----------+
924 * | Active pixel array |
925 * | |
926 * | |
927 * + +-------------------+ + 375
928 * | | | |
929 * | O===================O |
930 * | I 1280x720 stream I |
931 * + I I + 750
932 * | I I |
933 * | O===================O |
934 * | | | |
935 * + +-------------------+ + 1125
936 * | Crop region, 640x480 stream |
937 * | |
938 * | |
939 * +---------+---------+---------+----------+ 1500
940 *
941 * Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)
942 *
943 * 640x480 stream crop: (666, 375, 1000, 750) (marked with =)
944 * 1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
945 *
946 * 0 1000 2000
947 * +---------+---------+---------+----------+
948 * | Active pixel array |
949 * | |
950 * | |
951 * + +---O==================O---+ + 375
952 * | | I 640x480 stream I | |
953 * | | I I | |
954 * | | I I | |
955 * + | I I | + 750
956 * | | I I | |
957 * | | I I | |
958 * | | I I | |
959 * + +---O==================O---+ + 1125
960 * | Crop region, 1280x720 stream |
961 * | |
962 * | |
963 * +---------+---------+---------+----------+ 1500
964 *
965 * Crop region: (500, 375, 750, 750) (1:1 aspect ratio)
966 *
967 * 640x480 stream crop: (500, 469, 750, 562) (marked with =)
968 * 1280x720 stream crop: (500, 543, 750, 414) (marged with #)
969 *
970 * 0 1000 2000
971 * +---------+---------+---------+----------+
972 * | Active pixel array |
973 * | |
974 * | |
975 * + +--------------+ + 375
976 * | O==============O |
977 * | ################ |
978 * | # # |
979 * + # # + 750
980 * | # # |
981 * | ################ 1280x720 |
982 * | O==============O 640x480 |
983 * + +--------------+ + 1125
984 * | Crop region |
985 * | |
986 * | |
987 * +---------+---------+---------+----------+ 1500
988 *
989 * And a final example, a 1024x1024 square aspect ratio stream instead of the
990 * 480p stream:
991 *
992 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
993 *
994 * 1024x1024 stream crop: (625, 375, 750, 750) (marked with #)
995 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
996 *
997 * 0 1000 2000
998 * +---------+---------+---------+----------+
999 * | Active pixel array |
1000 * | |
1001 * | 1024x1024 stream |
1002 * + +--###############--+ + 375
1003 * | | # # | |
1004 * | O===================O |
1005 * | I 1280x720 stream I |
1006 * + I I + 750
1007 * | I I |
1008 * | O===================O |
1009 * | | # # | |
1010 * + +--###############--+ + 1125
1011 * | Crop region |
1012 * | |
1013 * | |
1014 * +---------+---------+---------+----------+ 1500
1015 *
1016 */
1017
1018/**
1019 * S6. Error management:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001020 *
1021 * Camera HAL device ops functions that have a return value will all return
1022 * -ENODEV / NULL in case of a serious error. This means the device cannot
1023 * continue operation, and must be closed by the framework. Once this error is
Alex Rayd5ddbc92013-02-15 13:47:24 -08001024 * returned by some method, or if notify() is called with ERROR_DEVICE, only
1025 * the close() method can be called successfully. All other methods will return
1026 * -ENODEV / NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001027 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001028 * If a device op is called in the wrong sequence, for example if the framework
1029 * calls configure_streams() is called before initialize(), the device must
1030 * return -ENOSYS from the call, and do nothing.
1031 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001032 * Transient errors in image capture must be reported through notify() as follows:
1033 *
1034 * - The failure of an entire capture to occur must be reported by the HAL by
1035 * calling notify() with ERROR_REQUEST. Individual errors for the result
1036 * metadata or the output buffers must not be reported in this case.
1037 *
1038 * - If the metadata for a capture cannot be produced, but some image buffers
1039 * were filled, the HAL must call notify() with ERROR_RESULT.
1040 *
1041 * - If an output image buffer could not be filled, but either the metadata was
1042 * produced or some other buffers were filled, the HAL must call notify() with
1043 * ERROR_BUFFER for each failed buffer.
1044 *
1045 * In each of these transient failure cases, the HAL must still call
Zhijun Heceac9e32014-02-05 20:49:45 -08001046 * process_capture_result, with valid output and input (if an input buffer was
1047 * submitted) buffer_handle_t. If the result metadata could not be produced, it
1048 * should be NULL. If some buffers could not be filled, they must be returned with
1049 * process_capture_result in the error state, their release fences must be set to
1050 * the acquire fences passed by the framework, or -1 if they have been waited on by
1051 * the HAL already.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001052 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001053 * Invalid input arguments result in -EINVAL from the appropriate methods. In
1054 * that case, the framework must act as if that call had never been made.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001055 *
1056 */
1057
Zhijun He2dde4682014-01-09 09:11:49 -08001058/**
Zhijun He709e5872014-01-17 15:25:21 -08001059 * S7. Key Performance Indicator (KPI) glossary:
Zhijun He2dde4682014-01-09 09:11:49 -08001060 *
Zhijun He709e5872014-01-17 15:25:21 -08001061 * This includes some critical definitions that are used by KPI metrics.
Zhijun He2dde4682014-01-09 09:11:49 -08001062 *
1063 * Pipeline Latency:
1064 * For a given capture request, the duration from the framework calling
1065 * process_capture_request to the HAL sending capture result and all buffers
1066 * back by process_capture_result call. To make the Pipeline Latency measure
1067 * independent of frame rate, it is measured by frame count.
1068 *
1069 * For example, when frame rate is 30 (fps), the frame duration (time interval
1070 * between adjacent frame capture time) is 33 (ms).
1071 * If it takes 5 frames for framework to get the result and buffers back for
1072 * a given request, then the Pipeline Latency is 5 (frames), instead of
1073 * 5 x 33 = 165 (ms).
1074 *
1075 * The Pipeline Latency is determined by android.request.pipelineDepth and
1076 * android.request.pipelineMaxDepth, see their definitions for more details.
1077 *
1078 */
1079
Zhijun Hebc358682014-01-23 14:42:54 -08001080/**
1081 * S8. Sample Use Cases:
1082 *
1083 * This includes some typical use case examples the camera HAL may support.
1084 *
1085 * S8.1 Zero Shutter Lag (ZSL) with CAMERA3_STREAM_INPUT stream.
1086 *
1087 * When Zero Shutter Lag (ZSL) is supported by the camera device, the INPUT stream
1088 * can be used for application/framework implemented ZSL use case. This kind of stream
1089 * will be used by the framework as follows:
1090 *
1091 * 1. Framework configures an opaque raw format output stream that is used to
1092 * produce the ZSL output buffers. The stream pixel format will be
1093 * HAL_PIXEL_FORMAT_RAW_OPAQUE.
1094 *
1095 * 2. Framework configures an opaque raw format input stream that is used to
1096 * send the reprocess ZSL buffers to the HAL. The stream pixel format will
1097 * also be HAL_PIXEL_FORMAT_RAW_OPAQUE.
1098 *
1099 * 3. Framework configures a YUV/JPEG output stream that is used to receive the
1100 * reprocessed data. The stream pixel format will be YCbCr_420/HAL_PIXEL_FORMAT_BLOB.
1101 *
1102 * 4. Framework picks a ZSL buffer from the output stream when a ZSL capture is
1103 * issued by the application, and sends the data back as an input buffer in a
1104 * reprocessing request, then sends to the HAL for reprocessing.
1105 *
1106 * 5. The HAL sends back the output JPEG result to framework.
1107 *
1108 * The HAL can select the actual raw buffer format and configure the ISP pipeline
1109 * appropriately based on the HAL_PIXEL_FORMAT_RAW_OPAQUE format. See this format
1110 * definition for more details.
1111 *
1112 * S8.2 Zero Shutter Lag (ZSL) with CAMERA3_STREAM_BIDIRECTIONAL stream.
1113 *
1114 * For this use case, the bidirectional stream will be used by the framework as follows:
1115 *
1116 * 1. The framework includes a buffer from this stream as output buffer in a
1117 * request as normal.
1118 *
1119 * 2. Once the HAL device returns a filled output buffer to the framework,
1120 * the framework may do one of two things with the filled buffer:
1121 *
1122 * 2. a. The framework uses the filled data, and returns the now-used buffer
1123 * to the stream queue for reuse. This behavior exactly matches the
1124 * OUTPUT type of stream.
1125 *
1126 * 2. b. The framework wants to reprocess the filled data, and uses the
1127 * buffer as an input buffer for a request. Once the HAL device has
1128 * used the reprocessing buffer, it then returns it to the
1129 * framework. The framework then returns the now-used buffer to the
1130 * stream queue for reuse.
1131 *
1132 * 3. The HAL device will be given the buffer again as an output buffer for
1133 * a request at some future point.
1134 *
1135 * For ZSL use case, the pixel format for bidirectional stream will be
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001136 * HAL_PIXEL_FORMAT_RAW_OPAQUE if it is listed in
1137 * android.scaler.availableInputOutputFormatsMap. A configuration stream list
1138 * that has BIDIRECTIONAL stream used as input, will usually also have a
1139 * distinct OUTPUT stream to get the reprocessing data. For example, for the
Zhijun Hebc358682014-01-23 14:42:54 -08001140 * ZSL use case, the stream list might be configured with the following:
1141 *
1142 * - A HAL_PIXEL_FORMAT_RAW_OPAQUE bidirectional stream is used
1143 * as input.
1144 * - And a HAL_PIXEL_FORMAT_BLOB (JPEG) output stream.
1145 *
1146 */
1147
Ruben Brunk2d96c742014-03-18 13:39:17 -07001148/**
1149 * S9. Notes on Controls and Metadata
1150 *
1151 * This section contains notes about the interpretation and usage of various metadata tags.
1152 *
1153 * S9.1 HIGH_QUALITY and FAST modes.
1154 *
1155 * Many camera post-processing blocks may be listed as having HIGH_QUALITY,
1156 * FAST, and OFF operating modes. These blocks will typically also have an
1157 * 'available modes' tag representing which of these operating modes are
1158 * available on a given device. The general policy regarding implementing
1159 * these modes is as follows:
1160 *
1161 * 1. Operating mode controls of hardware blocks that cannot be disabled
1162 * must not list OFF in their corresponding 'available modes' tags.
1163 *
1164 * 2. OFF will always be included in their corresponding 'available modes'
1165 * tag if it is possible to disable that hardware block.
1166 *
1167 * 3. FAST must always be included in the 'available modes' tags for all
1168 * post-processing blocks supported on the device. If a post-processing
1169 * block also has a slower and higher quality operating mode that does
1170 * not meet the framerate requirements for FAST mode, HIGH_QUALITY should
1171 * be included in the 'available modes' tag to represent this operating
1172 * mode.
1173 */
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001174__BEGIN_DECLS
1175
1176struct camera3_device;
1177
1178/**********************************************************************
1179 *
1180 * Camera3 stream and stream buffer definitions.
1181 *
1182 * These structs and enums define the handles and contents of the input and
1183 * output streams connecting the HAL to various framework and application buffer
1184 * consumers. Each stream is backed by a gralloc buffer queue.
1185 *
1186 */
1187
1188/**
1189 * camera3_stream_type_t:
1190 *
1191 * The type of the camera stream, which defines whether the camera HAL device is
1192 * the producer or the consumer for that stream, and how the buffers of the
1193 * stream relate to the other streams.
1194 */
1195typedef enum camera3_stream_type {
1196 /**
1197 * This stream is an output stream; the camera HAL device will be
1198 * responsible for filling buffers from this stream with newly captured or
1199 * reprocessed image data.
1200 */
1201 CAMERA3_STREAM_OUTPUT = 0,
1202
1203 /**
1204 * This stream is an input stream; the camera HAL device will be responsible
1205 * for reading buffers from this stream and sending them through the camera
1206 * processing pipeline, as if the buffer was a newly captured image from the
1207 * imager.
Zhijun Hebc358682014-01-23 14:42:54 -08001208 *
1209 * The pixel format for input stream can be any format reported by
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001210 * android.scaler.availableInputOutputFormatsMap. The pixel format of the
1211 * output stream that is used to produce the reprocessing data may be any
1212 * format reported by android.scaler.availableStreamConfigurations. The
1213 * supported input/output stream combinations depends the camera device
1214 * capabilities, see android.scaler.availableInputOutputFormatsMap for
1215 * stream map details.
Zhijun Hebc358682014-01-23 14:42:54 -08001216 *
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001217 * This kind of stream is generally used to reprocess data into higher
1218 * quality images (that otherwise would cause a frame rate performance
1219 * loss), or to do off-line reprocessing.
Zhijun Hebc358682014-01-23 14:42:54 -08001220 *
1221 * A typical use case is Zero Shutter Lag (ZSL), see S8.1 for more details.
1222 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001223 */
1224 CAMERA3_STREAM_INPUT = 1,
1225
1226 /**
1227 * This stream can be used for input and output. Typically, the stream is
1228 * used as an output stream, but occasionally one already-filled buffer may
1229 * be sent back to the HAL device for reprocessing.
1230 *
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001231 * This kind of stream is meant generally for Zero Shutter Lag (ZSL)
1232 * features, where copying the captured image from the output buffer to the
Zhijun Hebc358682014-01-23 14:42:54 -08001233 * reprocessing input buffer would be expensive. See S8.2 for more details.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001234 *
1235 * Note that the HAL will always be reprocessing data it produced.
1236 *
1237 */
1238 CAMERA3_STREAM_BIDIRECTIONAL = 2,
1239
1240 /**
1241 * Total number of framework-defined stream types
1242 */
1243 CAMERA3_NUM_STREAM_TYPES
1244
1245} camera3_stream_type_t;
1246
1247/**
1248 * camera3_stream_t:
1249 *
1250 * A handle to a single camera input or output stream. A stream is defined by
1251 * the framework by its buffer resolution and format, and additionally by the
1252 * HAL with the gralloc usage flags and the maximum in-flight buffer count.
1253 *
1254 * The stream structures are owned by the framework, but pointers to a
1255 * camera3_stream passed into the HAL by configure_streams() are valid until the
1256 * end of the first subsequent configure_streams() call that _does not_ include
1257 * that camera3_stream as an argument, or until the end of the close() call.
1258 *
1259 * All camera3_stream framework-controlled members are immutable once the
1260 * camera3_stream is passed into configure_streams(). The HAL may only change
1261 * the HAL-controlled parameters during a configure_streams() call, except for
1262 * the contents of the private pointer.
1263 *
1264 * If a configure_streams() call returns a non-fatal error, all active streams
1265 * remain valid as if configure_streams() had not been called.
1266 *
1267 * The endpoint of the stream is not visible to the camera HAL device.
Alex Ray2ce219a2013-06-14 15:09:30 -07001268 * In DEVICE_API_VERSION_3_1, this was changed to share consumer usage flags
1269 * on streams where the camera is a producer (OUTPUT and BIDIRECTIONAL stream
1270 * types) see the usage field below.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001271 */
1272typedef struct camera3_stream {
1273
1274 /*****
1275 * Set by framework before configure_streams()
1276 */
1277
1278 /**
1279 * The type of the stream, one of the camera3_stream_type_t values.
1280 */
1281 int stream_type;
1282
1283 /**
1284 * The width in pixels of the buffers in this stream
1285 */
1286 uint32_t width;
1287
1288 /**
1289 * The height in pixels of the buffers in this stream
1290 */
1291 uint32_t height;
1292
1293 /**
1294 * The pixel format for the buffers in this stream. Format is a value from
1295 * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
1296 * from device-specific headers.
1297 *
1298 * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
1299 * gralloc module will select a format based on the usage flags provided by
1300 * the camera device and the other endpoint of the stream.
1301 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001302 * <= CAMERA_DEVICE_API_VERSION_3_1:
1303 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001304 * The camera HAL device must inspect the buffers handed to it in the
1305 * subsequent register_stream_buffers() call to obtain the
1306 * implementation-specific format details, if necessary.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001307 *
1308 * >= CAMERA_DEVICE_API_VERSION_3_2:
1309 *
1310 * register_stream_buffers() won't be called by the framework, so the HAL
1311 * should configure the ISP and sensor pipeline based purely on the sizes,
1312 * usage flags, and formats for the configured streams.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001313 */
1314 int format;
1315
1316 /*****
1317 * Set by HAL during configure_streams().
1318 */
1319
1320 /**
1321 * The gralloc usage flags for this stream, as needed by the HAL. The usage
1322 * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
1323 * headers.
1324 *
1325 * For output streams, these are the HAL's producer usage flags. For input
1326 * streams, these are the HAL's consumer usage flags. The usage flags from
1327 * the producer and the consumer will be combined together and then passed
1328 * to the platform gralloc HAL module for allocating the gralloc buffers for
1329 * each stream.
Alex Ray2ce219a2013-06-14 15:09:30 -07001330 *
1331 * Version information:
1332 *
1333 * == CAMERA_DEVICE_API_VERSION_3_0:
1334 *
1335 * No initial value guaranteed when passed via configure_streams().
1336 * HAL may not use this field as input, and must write over this field
1337 * with its usage flags.
1338 *
1339 * >= CAMERA_DEVICE_API_VERSION_3_1:
1340 *
1341 * For stream_type OUTPUT and BIDIRECTIONAL, when passed via
1342 * configure_streams(), the initial value of this is the consumer's
1343 * usage flags. The HAL may use these consumer flags to decide stream
1344 * configuration.
1345 * For stream_type INPUT, when passed via configure_streams(), the initial
1346 * value of this is 0.
1347 * For all streams passed via configure_streams(), the HAL must write
1348 * over this field with its usage flags.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001349 */
1350 uint32_t usage;
1351
1352 /**
1353 * The maximum number of buffers the HAL device may need to have dequeued at
1354 * the same time. The HAL device may not have more buffers in-flight from
1355 * this stream than this value.
1356 */
1357 uint32_t max_buffers;
1358
1359 /**
1360 * A handle to HAL-private information for the stream. Will not be inspected
1361 * by the framework code.
1362 */
1363 void *priv;
1364
1365} camera3_stream_t;
1366
1367/**
1368 * camera3_stream_configuration_t:
1369 *
1370 * A structure of stream definitions, used by configure_streams(). This
1371 * structure defines all the output streams and the reprocessing input
1372 * stream for the current camera use case.
1373 */
1374typedef struct camera3_stream_configuration {
1375 /**
1376 * The total number of streams requested by the framework. This includes
1377 * both input and output streams. The number of streams will be at least 1,
1378 * and there will be at least one output-capable stream.
1379 */
1380 uint32_t num_streams;
1381
1382 /**
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001383 * An array of camera stream pointers, defining the input/output
1384 * configuration for the camera HAL device.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001385 *
1386 * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
1387 * in a single configuration.
1388 *
1389 * At least one output-capable stream must be defined (OUTPUT or
1390 * BIDIRECTIONAL).
1391 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001392 camera3_stream_t **streams;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001393
1394} camera3_stream_configuration_t;
1395
1396/**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001397 * camera3_buffer_status_t:
1398 *
1399 * The current status of a single stream buffer.
1400 */
1401typedef enum camera3_buffer_status {
1402 /**
1403 * The buffer is in a normal state, and can be used after waiting on its
1404 * sync fence.
1405 */
1406 CAMERA3_BUFFER_STATUS_OK = 0,
1407
1408 /**
1409 * The buffer does not contain valid data, and the data in it should not be
1410 * used. The sync fence must still be waited on before reusing the buffer.
1411 */
1412 CAMERA3_BUFFER_STATUS_ERROR = 1
1413
1414} camera3_buffer_status_t;
1415
1416/**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001417 * camera3_stream_buffer_t:
1418 *
1419 * A single buffer from a camera3 stream. It includes a handle to its parent
1420 * stream, the handle to the gralloc buffer itself, and sync fences
1421 *
1422 * The buffer does not specify whether it is to be used for input or output;
1423 * that is determined by its parent stream type and how the buffer is passed to
1424 * the HAL device.
1425 */
1426typedef struct camera3_stream_buffer {
1427 /**
1428 * The handle of the stream this buffer is associated with
1429 */
1430 camera3_stream_t *stream;
1431
1432 /**
1433 * The native handle to the buffer
1434 */
1435 buffer_handle_t *buffer;
1436
1437 /**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001438 * Current state of the buffer, one of the camera3_buffer_status_t
1439 * values. The framework will not pass buffers to the HAL that are in an
1440 * error state. In case a buffer could not be filled by the HAL, it must
1441 * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
1442 * framework with process_capture_result().
1443 */
1444 int status;
1445
1446 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001447 * The acquire sync fence for this buffer. The HAL must wait on this fence
1448 * fd before attempting to read from or write to this buffer.
1449 *
1450 * The framework may be set to -1 to indicate that no waiting is necessary
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001451 * for this buffer.
1452 *
1453 * When the HAL returns an output buffer to the framework with
1454 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
1455 * never waits on the acquire_fence due to an error in filling a buffer,
1456 * when calling process_capture_result() the HAL must set the release_fence
1457 * of the buffer to be the acquire_fence passed to it by the framework. This
1458 * will allow the framework to wait on the fence before reusing the buffer.
1459 *
1460 * For input buffers, the HAL must not change the acquire_fence field during
1461 * the process_capture_request() call.
Zhijun Heceac9e32014-02-05 20:49:45 -08001462 *
1463 * >= CAMERA_DEVICE_API_VERSION_3_2:
1464 *
1465 * When the HAL returns an input buffer to the framework with
1466 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001467 * never waits on input buffer acquire fence due to an error, the sync
1468 * fences should be handled similarly to the way they are handled for output
1469 * buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001470 */
1471 int acquire_fence;
1472
1473 /**
1474 * The release sync fence for this buffer. The HAL must set this fence when
1475 * returning buffers to the framework, or write -1 to indicate that no
1476 * waiting is required for this buffer.
1477 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001478 * For the output buffers, the fences must be set in the output_buffers
1479 * array passed to process_capture_result().
1480 *
1481 * <= CAMERA_DEVICE_API_VERSION_3_1:
1482 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001483 * For the input buffer, the release fence must be set by the
Zhijun Heceac9e32014-02-05 20:49:45 -08001484 * process_capture_request() call.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001485 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001486 * >= CAMERA_DEVICE_API_VERSION_3_2:
1487 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001488 * For the input buffer, the fences must be set in the input_buffer
1489 * passed to process_capture_result().
1490 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001491 * After signaling the release_fence for this buffer, the HAL
1492 * should not make any further attempts to access this buffer as the
1493 * ownership has been fully transferred back to the framework.
1494 *
1495 * If a fence of -1 was specified then the ownership of this buffer
1496 * is transferred back immediately upon the call of process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001497 */
1498 int release_fence;
1499
1500} camera3_stream_buffer_t;
1501
1502/**
1503 * camera3_stream_buffer_set_t:
1504 *
1505 * The complete set of gralloc buffers for a stream. This structure is given to
1506 * register_stream_buffers() to allow the camera HAL device to register/map/etc
1507 * newly allocated stream buffers.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001508 *
1509 * >= CAMERA_DEVICE_API_VERSION_3_2:
1510 *
1511 * Deprecated (and not used). In particular,
1512 * register_stream_buffers is also deprecated and will never be invoked.
1513 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001514 */
1515typedef struct camera3_stream_buffer_set {
1516 /**
1517 * The stream handle for the stream these buffers belong to
1518 */
1519 camera3_stream_t *stream;
1520
1521 /**
1522 * The number of buffers in this stream. It is guaranteed to be at least
1523 * stream->max_buffers.
1524 */
1525 uint32_t num_buffers;
1526
1527 /**
1528 * The array of gralloc buffer handles for this stream. If the stream format
1529 * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
1530 * should inspect the passed-in buffers to determine any platform-private
1531 * pixel format information.
1532 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001533 buffer_handle_t **buffers;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001534
1535} camera3_stream_buffer_set_t;
1536
1537/**
1538 * camera3_jpeg_blob:
1539 *
1540 * Transport header for compressed JPEG buffers in output streams.
1541 *
1542 * To capture JPEG images, a stream is created using the pixel format
Zhijun He44a89152014-04-24 14:34:53 -07001543 * HAL_PIXEL_FORMAT_BLOB. The buffer size for the stream is calculated by the
1544 * framework, based on the static metadata field android.jpeg.maxSize. Since
1545 * compressed JPEG images are of variable size, the HAL needs to include the
1546 * final size of the compressed image using this structure inside the output
1547 * stream buffer. The JPEG blob ID field must be set to CAMERA3_JPEG_BLOB_ID.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001548 *
Zhijun He44a89152014-04-24 14:34:53 -07001549 * Transport header should be at the end of the JPEG output stream buffer. That
1550 * means the jpeg_blob_id must start at byte[buffer_size -
1551 * sizeof(camera3_jpeg_blob)], where the buffer_size is the size of gralloc buffer.
1552 * Any HAL using this transport header must account for it in android.jpeg.maxSize
1553 * The JPEG data itself starts at the beginning of the buffer and should be
1554 * jpeg_size bytes long.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001555 */
1556typedef struct camera3_jpeg_blob {
1557 uint16_t jpeg_blob_id;
1558 uint32_t jpeg_size;
1559} camera3_jpeg_blob_t;
1560
1561enum {
1562 CAMERA3_JPEG_BLOB_ID = 0x00FF
1563};
1564
1565/**********************************************************************
1566 *
1567 * Message definitions for the HAL notify() callback.
1568 *
1569 * These definitions are used for the HAL notify callback, to signal
1570 * asynchronous events from the HAL device to the Android framework.
1571 *
1572 */
1573
1574/**
1575 * camera3_msg_type:
1576 *
1577 * Indicates the type of message sent, which specifies which member of the
1578 * message union is valid.
1579 *
1580 */
1581typedef enum camera3_msg_type {
1582 /**
1583 * An error has occurred. camera3_notify_msg.message.error contains the
1584 * error information.
1585 */
1586 CAMERA3_MSG_ERROR = 1,
1587
1588 /**
1589 * The exposure of a given request has
1590 * begun. camera3_notify_msg.message.shutter contains the information
1591 * the capture.
1592 */
1593 CAMERA3_MSG_SHUTTER = 2,
1594
1595 /**
1596 * Number of framework message types
1597 */
1598 CAMERA3_NUM_MESSAGES
1599
1600} camera3_msg_type_t;
1601
1602/**
1603 * Defined error codes for CAMERA_MSG_ERROR
1604 */
1605typedef enum camera3_error_msg_code {
1606 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001607 * A serious failure occured. No further frames or buffer streams will
1608 * be produced by the device. Device should be treated as closed. The
1609 * client must reopen the device to use it again. The frame_number field
1610 * is unused.
1611 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001612 CAMERA3_MSG_ERROR_DEVICE = 1,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001613
1614 /**
1615 * An error has occurred in processing a request. No output (metadata or
1616 * buffers) will be produced for this request. The frame_number field
1617 * specifies which request has been dropped. Subsequent requests are
1618 * unaffected, and the device remains operational.
1619 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001620 CAMERA3_MSG_ERROR_REQUEST = 2,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001621
1622 /**
1623 * An error has occurred in producing an output result metadata buffer
1624 * for a request, but output stream buffers for it will still be
1625 * available. Subsequent requests are unaffected, and the device remains
1626 * operational. The frame_number field specifies the request for which
1627 * result metadata won't be available.
1628 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001629 CAMERA3_MSG_ERROR_RESULT = 3,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001630
1631 /**
1632 * An error has occurred in placing an output buffer into a stream for a
1633 * request. The frame metadata and other buffers may still be
1634 * available. Subsequent requests are unaffected, and the device remains
1635 * operational. The frame_number field specifies the request for which the
1636 * buffer was dropped, and error_stream contains a pointer to the stream
1637 * that dropped the frame.u
1638 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001639 CAMERA3_MSG_ERROR_BUFFER = 4,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001640
1641 /**
1642 * Number of error types
1643 */
1644 CAMERA3_MSG_NUM_ERRORS
1645
1646} camera3_error_msg_code_t;
1647
1648/**
1649 * camera3_error_msg_t:
1650 *
1651 * Message contents for CAMERA3_MSG_ERROR
1652 */
1653typedef struct camera3_error_msg {
1654 /**
1655 * Frame number of the request the error applies to. 0 if the frame number
1656 * isn't applicable to the error.
1657 */
1658 uint32_t frame_number;
1659
1660 /**
1661 * Pointer to the stream that had a failure. NULL if the stream isn't
1662 * applicable to the error.
1663 */
1664 camera3_stream_t *error_stream;
1665
1666 /**
1667 * The code for this error; one of the CAMERA_MSG_ERROR enum values.
1668 */
1669 int error_code;
1670
1671} camera3_error_msg_t;
1672
1673/**
1674 * camera3_shutter_msg_t:
1675 *
1676 * Message contents for CAMERA3_MSG_SHUTTER
1677 */
1678typedef struct camera3_shutter_msg {
1679 /**
1680 * Frame number of the request that has begun exposure
1681 */
1682 uint32_t frame_number;
1683
1684 /**
1685 * Timestamp for the start of capture. This must match the capture result
1686 * metadata's sensor exposure start timestamp.
1687 */
1688 uint64_t timestamp;
1689
1690} camera3_shutter_msg_t;
1691
1692/**
1693 * camera3_notify_msg_t:
1694 *
1695 * The message structure sent to camera3_callback_ops_t.notify()
1696 */
1697typedef struct camera3_notify_msg {
1698
1699 /**
1700 * The message type. One of camera3_notify_msg_type, or a private extension.
1701 */
1702 int type;
1703
1704 union {
1705 /**
1706 * Error message contents. Valid if type is CAMERA3_MSG_ERROR
1707 */
1708 camera3_error_msg_t error;
1709
1710 /**
1711 * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
1712 */
1713 camera3_shutter_msg_t shutter;
1714
1715 /**
1716 * Generic message contents. Used to ensure a minimum size for custom
1717 * message types.
1718 */
1719 uint8_t generic[32];
1720 } message;
1721
1722} camera3_notify_msg_t;
1723
1724/**********************************************************************
1725 *
1726 * Capture request/result definitions for the HAL process_capture_request()
1727 * method, and the process_capture_result() callback.
1728 *
1729 */
1730
1731/**
1732 * camera3_request_template_t:
1733 *
1734 * Available template types for
1735 * camera3_device_ops.construct_default_request_settings()
1736 */
1737typedef enum camera3_request_template {
1738 /**
1739 * Standard camera preview operation with 3A on auto.
1740 */
1741 CAMERA3_TEMPLATE_PREVIEW = 1,
1742
1743 /**
1744 * Standard camera high-quality still capture with 3A and flash on auto.
1745 */
1746 CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
1747
1748 /**
1749 * Standard video recording plus preview with 3A on auto, torch off.
1750 */
1751 CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
1752
1753 /**
1754 * High-quality still capture while recording video. Application will
1755 * include preview, video record, and full-resolution YUV or JPEG streams in
1756 * request. Must not cause stuttering on video stream. 3A on auto.
1757 */
1758 CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
1759
1760 /**
1761 * Zero-shutter-lag mode. Application will request preview and
1762 * full-resolution data for each frame, and reprocess it to JPEG when a
1763 * still image is requested by user. Settings should provide highest-quality
1764 * full-resolution images without compromising preview frame rate. 3A on
1765 * auto.
1766 */
1767 CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
1768
Zhijun Heb0c939f2013-12-13 15:56:33 -08001769 /**
1770 * A basic template for direct application control of capture
1771 * parameters. All automatic control is disabled (auto-exposure, auto-white
1772 * balance, auto-focus), and post-processing parameters are set to preview
1773 * quality. The manual capture parameters (exposure, sensitivity, etc.)
1774 * are set to reasonable defaults, but should be overridden by the
1775 * application depending on the intended use case.
1776 */
1777 CAMERA3_TEMPLATE_MANUAL = 6,
1778
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001779 /* Total number of templates */
1780 CAMERA3_TEMPLATE_COUNT,
1781
1782 /**
1783 * First value for vendor-defined request templates
1784 */
1785 CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
1786
1787} camera3_request_template_t;
1788
1789/**
1790 * camera3_capture_request_t:
1791 *
1792 * A single request for image capture/buffer reprocessing, sent to the Camera
1793 * HAL device by the framework in process_capture_request().
1794 *
1795 * The request contains the settings to be used for this capture, and the set of
1796 * output buffers to write the resulting image data in. It may optionally
1797 * contain an input buffer, in which case the request is for reprocessing that
1798 * input buffer instead of capturing a new image with the camera sensor. The
1799 * capture is identified by the frame_number.
1800 *
1801 * In response, the camera HAL device must send a camera3_capture_result
1802 * structure asynchronously to the framework, using the process_capture_result()
1803 * callback.
1804 */
1805typedef struct camera3_capture_request {
1806 /**
1807 * The frame number is an incrementing integer set by the framework to
1808 * uniquely identify this capture. It needs to be returned in the result
1809 * call, and is also used to identify the request in asynchronous
1810 * notifications sent to camera3_callback_ops_t.notify().
1811 */
1812 uint32_t frame_number;
1813
1814 /**
1815 * The settings buffer contains the capture and processing parameters for
1816 * the request. As a special case, a NULL settings buffer indicates that the
1817 * settings are identical to the most-recently submitted capture request. A
1818 * NULL buffer cannot be used as the first submitted request after a
1819 * configure_streams() call.
1820 */
1821 const camera_metadata_t *settings;
1822
1823 /**
1824 * The input stream buffer to use for this request, if any.
1825 *
1826 * If input_buffer is NULL, then the request is for a new capture from the
1827 * imager. If input_buffer is valid, the request is for reprocessing the
1828 * image contained in input_buffer.
1829 *
1830 * In the latter case, the HAL must set the release_fence of the
1831 * input_buffer to a valid sync fence, or to -1 if the HAL does not support
1832 * sync, before process_capture_request() returns.
1833 *
1834 * The HAL is required to wait on the acquire sync fence of the input buffer
1835 * before accessing it.
1836 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001837 * <= CAMERA_DEVICE_API_VERSION_3_1:
1838 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001839 * Any input buffer included here will have been registered with the HAL
1840 * through register_stream_buffers() before its inclusion in a request.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001841 *
1842 * >= CAMERA_DEVICE_API_VERSION_3_2:
1843 *
1844 * The buffers will not have been pre-registered with the HAL.
1845 * Subsequent requests may reuse buffers, or provide entirely new buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001846 */
1847 camera3_stream_buffer_t *input_buffer;
1848
1849 /**
1850 * The number of output buffers for this capture request. Must be at least
1851 * 1.
1852 */
1853 uint32_t num_output_buffers;
1854
1855 /**
1856 * An array of num_output_buffers stream buffers, to be filled with image
1857 * data from this capture/reprocess. The HAL must wait on the acquire fences
Igor Murashkin78aa1262014-01-09 16:23:43 -08001858 * of each stream buffer before writing to them.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001859 *
1860 * The HAL takes ownership of the actual buffer_handle_t entries in
1861 * output_buffers; the framework does not access them until they are
1862 * returned in a camera3_capture_result_t.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001863 *
1864 * <= CAMERA_DEVICE_API_VERSION_3_1:
1865 *
1866 * All the buffers included here will have been registered with the HAL
1867 * through register_stream_buffers() before their inclusion in a request.
1868 *
1869 * >= CAMERA_DEVICE_API_VERSION_3_2:
1870 *
1871 * Any or all of the buffers included here may be brand new in this
1872 * request (having never before seen by the HAL).
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001873 */
1874 const camera3_stream_buffer_t *output_buffers;
1875
1876} camera3_capture_request_t;
1877
1878/**
1879 * camera3_capture_result_t:
1880 *
1881 * The result of a single capture/reprocess by the camera HAL device. This is
1882 * sent to the framework asynchronously with process_capture_result(), in
1883 * response to a single capture request sent to the HAL with
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001884 * process_capture_request(). Multiple process_capture_result() calls may be
Igor Murashkin5df2f622014-01-10 14:18:45 -08001885 * performed by the HAL for each request.
1886 *
1887 * Each call, all with the same frame
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001888 * number, may contain some subset of the output buffers, and/or the result
1889 * metadata. The metadata may only be provided once for a given frame number;
1890 * all other calls must set the result metadata to NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001891 *
1892 * The result structure contains the output metadata from this capture, and the
1893 * set of output buffers that have been/will be filled for this capture. Each
1894 * output buffer may come with a release sync fence that the framework will wait
1895 * on before reading, in case the buffer has not yet been filled by the HAL.
1896 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08001897 * >= CAMERA_DEVICE_API_VERSION_3_2:
1898 *
1899 * The metadata may be provided multiple times for a single frame number. The
1900 * framework will accumulate together the final result set by combining each
1901 * partial result together into the total result set.
1902 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001903 * If an input buffer is given in a request, the HAL must return it in one of
1904 * the process_capture_result calls, and the call may be to just return the input
1905 * buffer, without metadata and output buffers; the sync fences must be handled
1906 * the same way they are done for output buffers.
1907 *
1908 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08001909 * Performance considerations:
1910 *
1911 * Applications will also receive these partial results immediately, so sending
1912 * partial results is a highly recommended performance optimization to avoid
1913 * the total pipeline latency before sending the results for what is known very
1914 * early on in the pipeline.
1915 *
1916 * A typical use case might be calculating the AF state halfway through the
1917 * pipeline; by sending the state back to the framework immediately, we get a
1918 * 50% performance increase and perceived responsiveness of the auto-focus.
1919 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001920 */
1921typedef struct camera3_capture_result {
1922 /**
1923 * The frame number is an incrementing integer set by the framework in the
1924 * submitted request to uniquely identify this capture. It is also used to
1925 * identify the request in asynchronous notifications sent to
1926 * camera3_callback_ops_t.notify().
1927 */
1928 uint32_t frame_number;
1929
1930 /**
1931 * The result metadata for this capture. This contains information about the
1932 * final capture parameters, the state of the capture and post-processing
1933 * hardware, the state of the 3A algorithms, if enabled, and the output of
1934 * any enabled statistics units.
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001935 *
1936 * Only one call to process_capture_result() with a given frame_number may
1937 * include the result metadata. All other calls for the same frame_number
1938 * must set this to NULL.
1939 *
1940 * If there was an error producing the result metadata, result must be an
1941 * empty metadata buffer, and notify() must be called with ERROR_RESULT.
Igor Murashkin5df2f622014-01-10 14:18:45 -08001942 *
1943 * >= CAMERA_DEVICE_API_VERSION_3_2:
1944 *
1945 * Multiple calls to process_capture_result() with a given frame_number
1946 * may include the result metadata.
1947 *
1948 * Partial metadata submitted should not include any metadata key returned
1949 * in a previous partial result for a given frame. Each new partial result
1950 * for that frame must also set a distinct partial_result value.
1951 *
1952 * If notify has been called with ERROR_RESULT, all further partial
1953 * results for that frame are ignored by the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001954 */
1955 const camera_metadata_t *result;
1956
1957 /**
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001958 * The number of output buffers returned in this result structure. Must be
1959 * less than or equal to the matching capture request's count. If this is
1960 * less than the buffer count in the capture request, at least one more call
1961 * to process_capture_result with the same frame_number must be made, to
1962 * return the remaining output buffers to the framework. This may only be
1963 * zero if the structure includes valid result metadata.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001964 */
1965 uint32_t num_output_buffers;
1966
1967 /**
1968 * The handles for the output stream buffers for this capture. They may not
1969 * yet be filled at the time the HAL calls process_capture_result(); the
1970 * framework will wait on the release sync fences provided by the HAL before
1971 * reading the buffers.
1972 *
1973 * The HAL must set the stream buffer's release sync fence to a valid sync
1974 * fd, or to -1 if the buffer has already been filled.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001975 *
1976 * If the HAL encounters an error while processing the buffer, and the
1977 * buffer is not filled, the buffer's status field must be set to
1978 * CAMERA3_BUFFER_STATUS_ERROR. If the HAL did not wait on the acquire fence
1979 * before encountering the error, the acquire fence should be copied into
1980 * the release fence, to allow the framework to wait on the fence before
1981 * reusing the buffer.
1982 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001983 * The acquire fence must be set to -1 for all output buffers. If
1984 * num_output_buffers is zero, this may be NULL. In that case, at least one
1985 * more process_capture_result call must be made by the HAL to provide the
1986 * output buffers.
Igor Murashkin5df2f622014-01-10 14:18:45 -08001987 *
1988 * When process_capture_result is called with a new buffer for a frame,
1989 * all previous frames' buffers for that corresponding stream must have been
1990 * already delivered (the fences need not have yet been signaled).
1991 *
1992 * >= CAMERA_DEVICE_API_VERSION_3_2:
1993 *
1994 * Gralloc buffers for a frame may be sent to framework before the
1995 * corresponding SHUTTER-notify.
1996 *
1997 * Performance considerations:
1998 *
1999 * Buffers delivered to the framework will not be dispatched to the
2000 * application layer until a start of exposure timestamp has been received
2001 * via a SHUTTER notify() call. It is highly recommended to
2002 * dispatch that call as early as possible.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002003 */
2004 const camera3_stream_buffer_t *output_buffers;
2005
Igor Murashkin5df2f622014-01-10 14:18:45 -08002006 /**
2007 * >= CAMERA_DEVICE_API_VERSION_3_2:
2008 *
Zhijun Heceac9e32014-02-05 20:49:45 -08002009 * The handle for the input stream buffer for this capture. It may not
2010 * yet be consumed at the time the HAL calls process_capture_result(); the
2011 * framework will wait on the release sync fences provided by the HAL before
2012 * reusing the buffer.
2013 *
2014 * The HAL should handle the sync fences the same way they are done for
2015 * output_buffers.
2016 *
2017 * Only one input buffer is allowed to be sent per request. Similarly to
2018 * output buffers, the ordering of returned input buffers must be
2019 * maintained by the HAL.
2020 *
2021 * Performance considerations:
2022 *
2023 * The input buffer should be returned as early as possible. If the HAL
2024 * supports sync fences, it can call process_capture_result to hand it back
2025 * with sync fences being set appropriately. If the sync fences are not
2026 * supported, the buffer can only be returned when it is consumed, which
2027 * may take long time; the HAL may choose to copy this input buffer to make
2028 * the buffer return sooner.
2029 */
2030 const camera3_stream_buffer_t *input_buffer;
2031
2032 /**
2033 * >= CAMERA_DEVICE_API_VERSION_3_2:
2034 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002035 * In order to take advantage of partial results, the HAL must set the
2036 * static metadata android.request.partialResultCount to the number of
2037 * partial results it will send for each frame.
2038 *
2039 * Each new capture result with a partial result must set
2040 * this field (partial_result) to a distinct inclusive value between
2041 * 1 and android.request.partialResultCount.
2042 *
2043 * HALs not wishing to take advantage of this feature must not
2044 * set an android.request.partialResultCount or partial_result to a value
2045 * other than 1.
2046 *
2047 * This value must be set to 0 when a capture result contains buffers only
2048 * and no metadata.
2049 */
2050 uint32_t partial_result;
2051
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002052} camera3_capture_result_t;
2053
2054/**********************************************************************
2055 *
2056 * Callback methods for the HAL to call into the framework.
2057 *
2058 * These methods are used to return metadata and image buffers for a completed
2059 * or failed captures, and to notify the framework of asynchronous events such
2060 * as errors.
2061 *
2062 * The framework will not call back into the HAL from within these callbacks,
2063 * and these calls will not block for extended periods.
2064 *
2065 */
2066typedef struct camera3_callback_ops {
2067
2068 /**
2069 * process_capture_result:
2070 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002071 * Send results from a completed capture to the framework.
2072 * process_capture_result() may be invoked multiple times by the HAL in
2073 * response to a single capture request. This allows, for example, the
2074 * metadata and low-resolution buffers to be returned in one call, and
2075 * post-processed JPEG buffers in a later call, once it is available. Each
2076 * call must include the frame number of the request it is returning
2077 * metadata or buffers for.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002078 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002079 * A component (buffer or metadata) of the complete result may only be
2080 * included in one process_capture_result call. A buffer for each stream,
2081 * and the result metadata, must be returned by the HAL for each request in
2082 * one of the process_capture_result calls, even in case of errors producing
2083 * some of the output. A call to process_capture_result() with neither
2084 * output buffers or result metadata is not allowed.
2085 *
2086 * The order of returning metadata and buffers for a single result does not
2087 * matter, but buffers for a given stream must be returned in FIFO order. So
2088 * the buffer for request 5 for stream A must always be returned before the
2089 * buffer for request 6 for stream A. This also applies to the result
2090 * metadata; the metadata for request 5 must be returned before the metadata
2091 * for request 6.
2092 *
2093 * However, different streams are independent of each other, so it is
2094 * acceptable and expected that the buffer for request 5 for stream A may be
2095 * returned after the buffer for request 6 for stream B is. And it is
2096 * acceptable that the result metadata for request 6 for stream B is
2097 * returned before the buffer for request 5 for stream A is.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002098 *
2099 * The HAL retains ownership of result structure, which only needs to be
2100 * valid to access during this call. The framework will copy whatever it
2101 * needs before this call returns.
2102 *
2103 * The output buffers do not need to be filled yet; the framework will wait
2104 * on the stream buffer release sync fence before reading the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002105 * data. Therefore, this method should be called by the HAL as soon as
2106 * possible, even if some or all of the output buffers are still in
2107 * being filled. The HAL must include valid release sync fences into each
2108 * output_buffers stream buffer entry, or -1 if that stream buffer is
2109 * already filled.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002110 *
2111 * If the result buffer cannot be constructed for a request, the HAL should
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002112 * return an empty metadata buffer, but still provide the output buffers and
2113 * their sync fences. In addition, notify() must be called with an
2114 * ERROR_RESULT message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002115 *
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08002116 * If an output buffer cannot be filled, its status field must be set to
2117 * STATUS_ERROR. In addition, notify() must be called with a ERROR_BUFFER
2118 * message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002119 *
2120 * If the entire capture has failed, then this method still needs to be
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08002121 * called to return the output buffers to the framework. All the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002122 * statuses should be STATUS_ERROR, and the result metadata should be an
2123 * empty buffer. In addition, notify() must be called with a ERROR_REQUEST
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002124 * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
2125 * should not be sent.
2126 *
Zhijun He2dde4682014-01-09 09:11:49 -08002127 * Performance requirements:
2128 *
2129 * This is a non-blocking call. The framework will return this call in 5ms.
2130 *
2131 * The pipeline latency (see S7 for definition) should be less than or equal to
2132 * 4 frame intervals, and must be less than or equal to 8 frame intervals.
2133 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002134 */
2135 void (*process_capture_result)(const struct camera3_callback_ops *,
2136 const camera3_capture_result_t *result);
2137
2138 /**
2139 * notify:
2140 *
2141 * Asynchronous notification callback from the HAL, fired for various
2142 * reasons. Only for information independent of frame capture, or that
2143 * require specific timing. The ownership of the message structure remains
2144 * with the HAL, and the msg only needs to be valid for the duration of this
2145 * call.
2146 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002147 * Multiple threads may call notify() simultaneously.
2148 *
2149 * <= CAMERA_DEVICE_API_VERSION_3_1:
2150 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002151 * The notification for the start of exposure for a given request must be
2152 * sent by the HAL before the first call to process_capture_result() for
2153 * that request is made.
2154 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002155 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002156 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002157 * Buffers delivered to the framework will not be dispatched to the
2158 * application layer until a start of exposure timestamp has been received
2159 * via a SHUTTER notify() call. It is highly recommended to
2160 * dispatch this call as early as possible.
2161 *
2162 * ------------------------------------------------------------------------
Zhijun He2dde4682014-01-09 09:11:49 -08002163 * Performance requirements:
2164 *
2165 * This is a non-blocking call. The framework will return this call in 5ms.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002166 */
2167 void (*notify)(const struct camera3_callback_ops *,
2168 const camera3_notify_msg_t *msg);
2169
2170} camera3_callback_ops_t;
2171
2172/**********************************************************************
2173 *
2174 * Camera device operations
2175 *
2176 */
2177typedef struct camera3_device_ops {
2178
2179 /**
2180 * initialize:
2181 *
2182 * One-time initialization to pass framework callback function pointers to
2183 * the HAL. Will be called once after a successful open() call, before any
2184 * other functions are called on the camera3_device_ops structure.
2185 *
Zhijun He2dde4682014-01-09 09:11:49 -08002186 * Performance requirements:
2187 *
2188 * This should be a non-blocking call. The HAL should return from this call
2189 * in 5ms, and must return from this call in 10ms.
2190 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002191 * Return values:
2192 *
2193 * 0: On successful initialization
2194 *
2195 * -ENODEV: If initialization fails. Only close() can be called successfully
2196 * by the framework after this.
2197 */
2198 int (*initialize)(const struct camera3_device *,
2199 const camera3_callback_ops_t *callback_ops);
2200
2201 /**********************************************************************
2202 * Stream management
2203 */
2204
2205 /**
2206 * configure_streams:
2207 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002208 * CAMERA_DEVICE_API_VERSION_3_0 only:
2209 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002210 * Reset the HAL camera device processing pipeline and set up new input and
2211 * output streams. This call replaces any existing stream configuration with
2212 * the streams defined in the stream_list. This method will be called at
2213 * least once after initialize() before a request is submitted with
2214 * process_capture_request().
2215 *
2216 * The stream_list must contain at least one output-capable stream, and may
2217 * not contain more than one input-capable stream.
2218 *
2219 * The stream_list may contain streams that are also in the currently-active
2220 * set of streams (from the previous call to configure_stream()). These
2221 * streams will already have valid values for usage, max_buffers, and the
Igor Murashkin78aa1262014-01-09 16:23:43 -08002222 * private pointer.
2223 *
2224 * If such a stream has already had its buffers registered,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002225 * register_stream_buffers() will not be called again for the stream, and
2226 * buffers from the stream can be immediately included in input requests.
2227 *
2228 * If the HAL needs to change the stream configuration for an existing
2229 * stream due to the new configuration, it may rewrite the values of usage
Igor Murashkin78aa1262014-01-09 16:23:43 -08002230 * and/or max_buffers during the configure call.
2231 *
2232 * The framework will detect such a change, and will then reallocate the
2233 * stream buffers, and call register_stream_buffers() again before using
2234 * buffers from that stream in a request.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002235 *
2236 * If a currently-active stream is not included in stream_list, the HAL may
2237 * safely remove any references to that stream. It will not be reused in a
2238 * later configure() call by the framework, and all the gralloc buffers for
2239 * it will be freed after the configure_streams() call returns.
2240 *
2241 * The stream_list structure is owned by the framework, and may not be
2242 * accessed once this call completes. The address of an individual
2243 * camera3_stream_t structure will remain valid for access by the HAL until
2244 * the end of the first configure_stream() call which no longer includes
2245 * that camera3_stream_t in the stream_list argument. The HAL may not change
2246 * values in the stream structure outside of the private pointer, except for
2247 * the usage and max_buffers members during the configure_streams() call
2248 * itself.
2249 *
2250 * If the stream is new, the usage, max_buffer, and private pointer fields
2251 * of the stream structure will all be set to 0. The HAL device must set
2252 * these fields before the configure_streams() call returns. These fields
2253 * are then used by the framework and the platform gralloc module to
2254 * allocate the gralloc buffers for each stream.
2255 *
2256 * Before such a new stream can have its buffers included in a capture
2257 * request, the framework will call register_stream_buffers() with that
2258 * stream. However, the framework is not required to register buffers for
2259 * _all_ streams before submitting a request. This allows for quick startup
2260 * of (for example) a preview stream, with allocation for other streams
2261 * happening later or concurrently.
2262 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002263 * ------------------------------------------------------------------------
2264 * CAMERA_DEVICE_API_VERSION_3_1 only:
2265 *
2266 * Reset the HAL camera device processing pipeline and set up new input and
2267 * output streams. This call replaces any existing stream configuration with
2268 * the streams defined in the stream_list. This method will be called at
2269 * least once after initialize() before a request is submitted with
2270 * process_capture_request().
2271 *
2272 * The stream_list must contain at least one output-capable stream, and may
2273 * not contain more than one input-capable stream.
2274 *
2275 * The stream_list may contain streams that are also in the currently-active
2276 * set of streams (from the previous call to configure_stream()). These
2277 * streams will already have valid values for usage, max_buffers, and the
2278 * private pointer.
2279 *
2280 * If such a stream has already had its buffers registered,
2281 * register_stream_buffers() will not be called again for the stream, and
2282 * buffers from the stream can be immediately included in input requests.
2283 *
2284 * If the HAL needs to change the stream configuration for an existing
2285 * stream due to the new configuration, it may rewrite the values of usage
2286 * and/or max_buffers during the configure call.
2287 *
2288 * The framework will detect such a change, and will then reallocate the
2289 * stream buffers, and call register_stream_buffers() again before using
2290 * buffers from that stream in a request.
2291 *
2292 * If a currently-active stream is not included in stream_list, the HAL may
2293 * safely remove any references to that stream. It will not be reused in a
2294 * later configure() call by the framework, and all the gralloc buffers for
2295 * it will be freed after the configure_streams() call returns.
2296 *
2297 * The stream_list structure is owned by the framework, and may not be
2298 * accessed once this call completes. The address of an individual
2299 * camera3_stream_t structure will remain valid for access by the HAL until
2300 * the end of the first configure_stream() call which no longer includes
2301 * that camera3_stream_t in the stream_list argument. The HAL may not change
2302 * values in the stream structure outside of the private pointer, except for
2303 * the usage and max_buffers members during the configure_streams() call
2304 * itself.
2305 *
2306 * If the stream is new, max_buffer, and private pointer fields of the
2307 * stream structure will all be set to 0. The usage will be set to the
2308 * consumer usage flags. The HAL device must set these fields before the
2309 * configure_streams() call returns. These fields are then used by the
2310 * framework and the platform gralloc module to allocate the gralloc
2311 * buffers for each stream.
2312 *
2313 * Before such a new stream can have its buffers included in a capture
2314 * request, the framework will call register_stream_buffers() with that
2315 * stream. However, the framework is not required to register buffers for
2316 * _all_ streams before submitting a request. This allows for quick startup
2317 * of (for example) a preview stream, with allocation for other streams
2318 * happening later or concurrently.
2319 *
2320 * ------------------------------------------------------------------------
2321 * >= CAMERA_DEVICE_API_VERSION_3_2:
2322 *
2323 * Reset the HAL camera device processing pipeline and set up new input and
2324 * output streams. This call replaces any existing stream configuration with
2325 * the streams defined in the stream_list. This method will be called at
2326 * least once after initialize() before a request is submitted with
2327 * process_capture_request().
2328 *
2329 * The stream_list must contain at least one output-capable stream, and may
2330 * not contain more than one input-capable stream.
2331 *
2332 * The stream_list may contain streams that are also in the currently-active
2333 * set of streams (from the previous call to configure_stream()). These
2334 * streams will already have valid values for usage, max_buffers, and the
2335 * private pointer.
2336 *
2337 * If the HAL needs to change the stream configuration for an existing
2338 * stream due to the new configuration, it may rewrite the values of usage
2339 * and/or max_buffers during the configure call.
2340 *
2341 * The framework will detect such a change, and may then reallocate the
2342 * stream buffers before using buffers from that stream in a request.
2343 *
2344 * If a currently-active stream is not included in stream_list, the HAL may
2345 * safely remove any references to that stream. It will not be reused in a
2346 * later configure() call by the framework, and all the gralloc buffers for
2347 * it will be freed after the configure_streams() call returns.
2348 *
2349 * The stream_list structure is owned by the framework, and may not be
2350 * accessed once this call completes. The address of an individual
2351 * camera3_stream_t structure will remain valid for access by the HAL until
2352 * the end of the first configure_stream() call which no longer includes
2353 * that camera3_stream_t in the stream_list argument. The HAL may not change
2354 * values in the stream structure outside of the private pointer, except for
2355 * the usage and max_buffers members during the configure_streams() call
2356 * itself.
2357 *
2358 * If the stream is new, max_buffer, and private pointer fields of the
2359 * stream structure will all be set to 0. The usage will be set to the
2360 * consumer usage flags. The HAL device must set these fields before the
2361 * configure_streams() call returns. These fields are then used by the
2362 * framework and the platform gralloc module to allocate the gralloc
2363 * buffers for each stream.
2364 *
2365 * Newly allocated buffers may be included in a capture request at any time
2366 * by the framework. Once a gralloc buffer is returned to the framework
2367 * with process_capture_result (and its respective release_fence has been
2368 * signaled) the framework may free or reuse it at any time.
2369 *
2370 * ------------------------------------------------------------------------
2371 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002372 * Preconditions:
2373 *
2374 * The framework will only call this method when no captures are being
2375 * processed. That is, all results have been returned to the framework, and
2376 * all in-flight input and output buffers have been returned and their
2377 * release sync fences have been signaled by the HAL. The framework will not
2378 * submit new requests for capture while the configure_streams() call is
2379 * underway.
2380 *
2381 * Postconditions:
2382 *
2383 * The HAL device must configure itself to provide maximum possible output
2384 * frame rate given the sizes and formats of the output streams, as
2385 * documented in the camera device's static metadata.
2386 *
Zhijun He2dde4682014-01-09 09:11:49 -08002387 * Performance requirements:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002388 *
2389 * This call is expected to be heavyweight and possibly take several hundred
2390 * milliseconds to complete, since it may require resetting and
2391 * reconfiguring the image sensor and the camera processing pipeline.
2392 * Nevertheless, the HAL device should attempt to minimize the
2393 * reconfiguration delay to minimize the user-visible pauses during
2394 * application operational mode changes (such as switching from still
2395 * capture to video recording).
2396 *
Zhijun He2dde4682014-01-09 09:11:49 -08002397 * The HAL should return from this call in 500ms, and must return from this
2398 * call in 1000ms.
2399 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002400 * Return values:
2401 *
2402 * 0: On successful stream configuration
2403 *
2404 * -EINVAL: If the requested stream configuration is invalid. Some examples
2405 * of invalid stream configurations include:
2406 *
2407 * - Including more than 1 input-capable stream (INPUT or
2408 * BIDIRECTIONAL)
2409 *
2410 * - Not including any output-capable streams (OUTPUT or
2411 * BIDIRECTIONAL)
2412 *
2413 * - Including streams with unsupported formats, or an unsupported
2414 * size for that format.
2415 *
2416 * - Including too many output streams of a certain format.
2417 *
Eino-Ville Talvala7effe0c2013-02-15 12:09:48 -08002418 * Note that the framework submitting an invalid stream
2419 * configuration is not normal operation, since stream
2420 * configurations are checked before configure. An invalid
2421 * configuration means that a bug exists in the framework code, or
2422 * there is a mismatch between the HAL's static metadata and the
2423 * requirements on streams.
2424 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002425 * -ENODEV: If there has been a fatal error and the device is no longer
2426 * operational. Only close() can be called successfully by the
2427 * framework after this error is returned.
2428 */
2429 int (*configure_streams)(const struct camera3_device *,
2430 camera3_stream_configuration_t *stream_list);
2431
2432 /**
2433 * register_stream_buffers:
2434 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002435 * >= CAMERA_DEVICE_API_VERSION_3_2:
2436 *
2437 * DEPRECATED. This will not be called and must be set to NULL.
2438 *
2439 * <= CAMERA_DEVICE_API_VERSION_3_1:
2440 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002441 * Register buffers for a given stream with the HAL device. This method is
2442 * called by the framework after a new stream is defined by
2443 * configure_streams, and before buffers from that stream are included in a
2444 * capture request. If the same stream is listed in a subsequent
2445 * configure_streams() call, register_stream_buffers will _not_ be called
2446 * again for that stream.
2447 *
2448 * The framework does not need to register buffers for all configured
2449 * streams before it submits the first capture request. This allows quick
2450 * startup for preview (or similar use cases) while other streams are still
2451 * being allocated.
2452 *
2453 * This method is intended to allow the HAL device to map or otherwise
2454 * prepare the buffers for later use. The buffers passed in will already be
2455 * locked for use. At the end of the call, all the buffers must be ready to
2456 * be returned to the stream. The buffer_set argument is only valid for the
2457 * duration of this call.
2458 *
2459 * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
2460 * the camera HAL should inspect the passed-in buffers here to determine any
2461 * platform-private pixel format information.
2462 *
Zhijun He2dde4682014-01-09 09:11:49 -08002463 * Performance requirements:
2464 *
2465 * This should be a non-blocking call. The HAL should return from this call
2466 * in 1ms, and must return from this call in 5ms.
2467 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002468 * Return values:
2469 *
2470 * 0: On successful registration of the new stream buffers
2471 *
2472 * -EINVAL: If the stream_buffer_set does not refer to a valid active
2473 * stream, or if the buffers array is invalid.
2474 *
2475 * -ENOMEM: If there was a failure in registering the buffers. The framework
2476 * must consider all the stream buffers to be unregistered, and can
2477 * try to register again later.
2478 *
2479 * -ENODEV: If there is a fatal error, and the device is no longer
2480 * operational. Only close() can be called successfully by the
2481 * framework after this error is returned.
2482 */
2483 int (*register_stream_buffers)(const struct camera3_device *,
2484 const camera3_stream_buffer_set_t *buffer_set);
2485
2486 /**********************************************************************
2487 * Request creation and submission
2488 */
2489
2490 /**
2491 * construct_default_request_settings:
2492 *
2493 * Create capture settings for standard camera use cases.
2494 *
2495 * The device must return a settings buffer that is configured to meet the
2496 * requested use case, which must be one of the CAMERA3_TEMPLATE_*
2497 * enums. All request control fields must be included.
2498 *
2499 * The HAL retains ownership of this structure, but the pointer to the
2500 * structure must be valid until the device is closed. The framework and the
2501 * HAL may not modify the buffer once it is returned by this call. The same
2502 * buffer may be returned for subsequent calls for the same template, or for
2503 * other templates.
2504 *
Zhijun He2dde4682014-01-09 09:11:49 -08002505 * Performance requirements:
2506 *
2507 * This should be a non-blocking call. The HAL should return from this call
2508 * in 1ms, and must return from this call in 5ms.
2509 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002510 * Return values:
2511 *
2512 * Valid metadata: On successful creation of a default settings
2513 * buffer.
2514 *
2515 * NULL: In case of a fatal error. After this is returned, only
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002516 * the close() method can be called successfully by the
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002517 * framework.
2518 */
2519 const camera_metadata_t* (*construct_default_request_settings)(
2520 const struct camera3_device *,
2521 int type);
2522
2523 /**
2524 * process_capture_request:
2525 *
2526 * Send a new capture request to the HAL. The HAL should not return from
2527 * this call until it is ready to accept the next request to process. Only
2528 * one call to process_capture_request() will be made at a time by the
2529 * framework, and the calls will all be from the same thread. The next call
2530 * to process_capture_request() will be made as soon as a new request and
2531 * its associated buffers are available. In a normal preview scenario, this
2532 * means the function will be called again by the framework almost
2533 * instantly.
2534 *
2535 * The actual request processing is asynchronous, with the results of
2536 * capture being returned by the HAL through the process_capture_result()
2537 * call. This call requires the result metadata to be available, but output
2538 * buffers may simply provide sync fences to wait on. Multiple requests are
2539 * expected to be in flight at once, to maintain full output frame rate.
2540 *
2541 * The framework retains ownership of the request structure. It is only
2542 * guaranteed to be valid during this call. The HAL device must make copies
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002543 * of the information it needs to retain for the capture processing. The HAL
2544 * is responsible for waiting on and closing the buffers' fences and
2545 * returning the buffer handles to the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002546 *
2547 * The HAL must write the file descriptor for the input buffer's release
2548 * sync fence into input_buffer->release_fence, if input_buffer is not
2549 * NULL. If the HAL returns -1 for the input buffer release sync fence, the
2550 * framework is free to immediately reuse the input buffer. Otherwise, the
2551 * framework will wait on the sync fence before refilling and reusing the
2552 * input buffer.
2553 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002554 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002555 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002556 * The input/output buffers provided by the framework in each request
2557 * may be brand new (having never before seen by the HAL).
2558 *
2559 * ------------------------------------------------------------------------
2560 * Performance considerations:
2561 *
2562 * Handling a new buffer should be extremely lightweight and there should be
2563 * no frame rate degradation or frame jitter introduced.
2564 *
2565 * This call must return fast enough to ensure that the requested frame
2566 * rate can be sustained, especially for streaming cases (post-processing
2567 * quality settings set to FAST). The HAL should return this call in 1
2568 * frame interval, and must return from this call in 4 frame intervals.
Zhijun He2dde4682014-01-09 09:11:49 -08002569 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002570 * Return values:
2571 *
2572 * 0: On a successful start to processing the capture request
2573 *
2574 * -EINVAL: If the input is malformed (the settings are NULL when not
2575 * allowed, there are 0 output buffers, etc) and capture processing
2576 * cannot start. Failures during request processing should be
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002577 * handled by calling camera3_callback_ops_t.notify(). In case of
2578 * this error, the framework will retain responsibility for the
2579 * stream buffers' fences and the buffer handles; the HAL should
2580 * not close the fences or return these buffers with
2581 * process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002582 *
2583 * -ENODEV: If the camera device has encountered a serious error. After this
2584 * error is returned, only the close() method can be successfully
2585 * called by the framework.
2586 *
2587 */
2588 int (*process_capture_request)(const struct camera3_device *,
2589 camera3_capture_request_t *request);
2590
2591 /**********************************************************************
2592 * Miscellaneous methods
2593 */
2594
2595 /**
2596 * get_metadata_vendor_tag_ops:
2597 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002598 * Get methods to query for vendor extension metadata tag information. The
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002599 * HAL should fill in all the vendor tag operation methods, or leave ops
2600 * unchanged if no vendor tags are defined.
2601 *
2602 * The definition of vendor_tag_query_ops_t can be found in
2603 * system/media/camera/include/system/camera_metadata.h.
2604 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -08002605 * >= CAMERA_DEVICE_API_VERSION_3_2:
2606 * DEPRECATED. This function has been deprecated and should be set to
2607 * NULL by the HAL. Please implement get_vendor_tag_ops in camera_common.h
2608 * instead.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002609 */
2610 void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
2611 vendor_tag_query_ops_t* ops);
2612
2613 /**
2614 * dump:
2615 *
2616 * Print out debugging state for the camera device. This will be called by
2617 * the framework when the camera service is asked for a debug dump, which
2618 * happens when using the dumpsys tool, or when capturing a bugreport.
2619 *
2620 * The passed-in file descriptor can be used to write debugging text using
2621 * dprintf() or write(). The text should be in ASCII encoding only.
Zhijun He2dde4682014-01-09 09:11:49 -08002622 *
2623 * Performance requirements:
2624 *
2625 * This must be a non-blocking call. The HAL should return from this call
2626 * in 1ms, must return from this call in 10ms. This call must avoid
2627 * deadlocks, as it may be called at any point during camera operation.
2628 * Any synchronization primitives used (such as mutex locks or semaphores)
2629 * should be acquired with a timeout.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002630 */
2631 void (*dump)(const struct camera3_device *, int fd);
2632
Alex Ray5f2fd852013-06-24 11:28:05 -07002633 /**
2634 * flush:
2635 *
2636 * Flush all currently in-process captures and all buffers in the pipeline
2637 * on the given device. The framework will use this to dump all state as
2638 * quickly as possible in order to prepare for a configure_streams() call.
2639 *
2640 * No buffers are required to be successfully returned, so every buffer
Zhijun He5a5fbf42014-01-27 14:49:44 -08002641 * held at the time of flush() (whether successfully filled or not) may be
Alex Ray5f2fd852013-06-24 11:28:05 -07002642 * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed
Zhijun He5a5fbf42014-01-27 14:49:44 -08002643 * to return valid (CAMERA3_BUFFER_STATUS_OK) buffers during this call,
2644 * provided they are successfully filled.
Alex Ray5f2fd852013-06-24 11:28:05 -07002645 *
2646 * All requests currently in the HAL are expected to be returned as soon as
2647 * possible. Not-in-process requests should return errors immediately. Any
2648 * interruptible hardware blocks should be stopped, and any uninterruptible
2649 * blocks should be waited on.
2650 *
Zhijun He5a5fbf42014-01-27 14:49:44 -08002651 * More specifically, the HAL must follow below requirements for various cases:
2652 *
2653 * 1. For captures that are too late for the HAL to cancel/stop, and will be
2654 * completed normally by the HAL; i.e. the HAL can send shutter/notify and
2655 * process_capture_result and buffers as normal.
2656 *
2657 * 2. For pending requests that have not done any processing, the HAL must call notify
2658 * CAMERA3_MSG_ERROR_REQUEST, and return all the output buffers with
2659 * process_capture_result in the error state (CAMERA3_BUFFER_STATUS_ERROR).
2660 * The HAL must not place the release fence into an error state, instead,
2661 * the release fences must be set to the acquire fences passed by the framework,
2662 * or -1 if they have been waited on by the HAL already. This is also the path
2663 * to follow for any captures for which the HAL already called notify() with
2664 * CAMERA3_MSG_SHUTTER but won't be producing any metadata/valid buffers for.
2665 * After CAMERA3_MSG_ERROR_REQUEST, for a given frame, only process_capture_results with
2666 * buffers in CAMERA3_BUFFER_STATUS_ERROR are allowed. No further notifys or
2667 * process_capture_result with non-null metadata is allowed.
2668 *
2669 * 3. For partially completed pending requests that will not have all the output
2670 * buffers or perhaps missing metadata, the HAL should follow below:
2671 *
2672 * 3.1. Call notify with CAMERA3_MSG_ERROR_RESULT if some of the expected result
2673 * metadata (i.e. one or more partial metadata) won't be available for the capture.
2674 *
2675 * 3.2. Call notify with CAMERA3_MSG_ERROR_BUFFER for every buffer that won't
2676 * be produced for the capture.
2677 *
2678 * 3.3 Call notify with CAMERA3_MSG_SHUTTER with the capture timestamp before
2679 * any buffers/metadata are returned with process_capture_result.
2680 *
2681 * 3.4 For captures that will produce some results, the HAL must not call
2682 * CAMERA3_MSG_ERROR_REQUEST, since that indicates complete failure.
2683 *
2684 * 3.5. Valid buffers/metadata should be passed to the framework as normal.
2685 *
2686 * 3.6. Failed buffers should be returned to the framework as described for case 2.
2687 * But failed buffers do not have to follow the strict ordering valid buffers do,
2688 * and may be out-of-order with respect to valid buffers. For example, if buffers
2689 * A, B, C, D, E are sent, D and E are failed, then A, E, B, D, C is an acceptable
2690 * return order.
2691 *
2692 * 3.7. For fully-missing metadata, calling CAMERA3_MSG_ERROR_RESULT is sufficient, no
2693 * need to call process_capture_result with NULL metadata or equivalent.
2694 *
Alex Ray5f2fd852013-06-24 11:28:05 -07002695 * flush() should only return when there are no more outstanding buffers or
Zhijun He5a5fbf42014-01-27 14:49:44 -08002696 * requests left in the HAL. The framework may call configure_streams (as
Alex Ray5f2fd852013-06-24 11:28:05 -07002697 * the HAL state is now quiesced) or may issue new requests.
2698 *
Zhijun He5a5fbf42014-01-27 14:49:44 -08002699 * Note that it's sufficient to only support fully-succeeded and fully-failed result cases.
2700 * However, it is highly desirable to support the partial failure cases as well, as it
2701 * could help improve the flush call overall performance.
2702 *
Zhijun He2dde4682014-01-09 09:11:49 -08002703 * Performance requirements:
2704 *
2705 * The HAL should return from this call in 100ms, and must return from this
2706 * call in 1000ms. And this call must not be blocked longer than pipeline
2707 * latency (see S7 for definition).
Alex Ray5f2fd852013-06-24 11:28:05 -07002708 *
2709 * Version information:
2710 *
2711 * only available if device version >= CAMERA_DEVICE_API_VERSION_3_1.
2712 *
2713 * Return values:
2714 *
2715 * 0: On a successful flush of the camera HAL.
2716 *
2717 * -EINVAL: If the input is malformed (the device is not valid).
2718 *
2719 * -ENODEV: If the camera device has encountered a serious error. After this
2720 * error is returned, only the close() method can be successfully
2721 * called by the framework.
2722 */
2723 int (*flush)(const struct camera3_device *);
2724
2725 /* reserved for future use */
2726 void *reserved[8];
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002727} camera3_device_ops_t;
2728
2729/**********************************************************************
2730 *
2731 * Camera device definition
2732 *
2733 */
2734typedef struct camera3_device {
2735 /**
2736 * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
2737 * device as implementing version 3.0 of the camera device HAL.
Zhijun He2dde4682014-01-09 09:11:49 -08002738 *
2739 * Performance requirements:
2740 *
Zhijun He06da1b32014-02-10 16:04:23 -08002741 * Camera open (common.module->common.methods->open) should return in 200ms, and must return
2742 * in 500ms.
Zhijun He2020ee22014-01-31 11:35:45 -08002743 * Camera close (common.close) should return in 200ms, and must return in 500ms.
2744 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002745 */
2746 hw_device_t common;
2747 camera3_device_ops_t *ops;
2748 void *priv;
2749} camera3_device_t;
2750
2751__END_DECLS
2752
2753#endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */