blob: daf5034919bca1bc7397a1b03d4b711994219f10 [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
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070055 */
56
57/**
58 * S1. Version history:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080059 *
60 * 1.0: Initial Android camera HAL (Android 4.0) [camera.h]:
61 *
62 * - Converted from C++ CameraHardwareInterface abstraction layer.
63 *
64 * - Supports android.hardware.Camera API.
65 *
66 * 2.0: Initial release of expanded-capability HAL (Android 4.2) [camera2.h]:
67 *
68 * - Sufficient for implementing existing android.hardware.Camera API.
69 *
70 * - Allows for ZSL queue in camera service layer
71 *
72 * - Not tested for any new features such manual capture control, Bayer RAW
73 * capture, reprocessing of RAW data.
74 *
75 * 3.0: First revision of expanded-capability HAL:
76 *
77 * - Major version change since the ABI is completely different. No change to
78 * the required hardware capabilities or operational model from 2.0.
79 *
80 * - Reworked input request and stream queue interfaces: Framework calls into
81 * HAL with next request and stream buffers already dequeued. Sync framework
82 * support is included, necessary for efficient implementations.
83 *
84 * - Moved triggers into requests, most notifications into results.
85 *
86 * - Consolidated all callbacks into framework into one structure, and all
87 * setup methods into a single initialize() call.
88 *
89 * - Made stream configuration into a single call to simplify stream
90 * management. Bidirectional streams replace STREAM_FROM_STREAM construct.
91 *
92 * - Limited mode semantics for older/limited hardware devices.
Alex Ray2ce219a2013-06-14 15:09:30 -070093 *
94 * 3.1: Minor revision of expanded-capability HAL:
95 *
96 * - configure_streams passes consumer usage flags to the HAL.
Alex Ray5f2fd852013-06-24 11:28:05 -070097 *
98 * - flush call to drop all in-flight requests/buffers as fast as possible.
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080099 *
100 * 3.2: Minor revision of expanded-capability HAL:
101 *
102 * - Deprecates get_metadata_vendor_tag_ops. Please use get_vendor_tag_ops
103 * in camera_common.h instead.
Igor Murashkin78aa1262014-01-09 16:23:43 -0800104 *
105 * - register_stream_buffers deprecated. All gralloc buffers provided
106 * by framework to HAL in process_capture_request may be new at any time.
Igor Murashkin5df2f622014-01-10 14:18:45 -0800107 *
108 * - add partial result support. process_capture_result may be called
109 * multiple times with a subset of the available result before the full
110 * result is available.
Zhijun Hebc358682014-01-23 14:42:54 -0800111 *
112 * - add manual template to camera3_request_template. The applications may
113 * use this template to control the capture settings directly.
114 *
115 * - Rework the bidirectional and input stream specifications.
116 *
Zhijun Heceac9e32014-02-05 20:49:45 -0800117 * - change the input buffer return path. The buffer is returned in
118 * process_capture_result instead of process_capture_request.
119 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800120 */
121
122/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700123 * S2. Startup and general expected operation sequence:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800124 *
125 * 1. Framework calls camera_module_t->common.open(), which returns a
126 * hardware_device_t structure.
127 *
128 * 2. Framework inspects the hardware_device_t->version field, and instantiates
129 * the appropriate handler for that version of the camera hardware device. In
130 * case the version is CAMERA_DEVICE_API_VERSION_3_0, the device is cast to
131 * a camera3_device_t.
132 *
133 * 3. Framework calls camera3_device_t->ops->initialize() with the framework
134 * callback function pointers. This will only be called this one time after
135 * open(), before any other functions in the ops structure are called.
136 *
137 * 4. The framework calls camera3_device_t->ops->configure_streams() with a list
138 * of input/output streams to the HAL device.
139 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800140 * 5. <= CAMERA_DEVICE_API_VERSION_3_1:
141 *
142 * The framework allocates gralloc buffers and calls
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800143 * camera3_device_t->ops->register_stream_buffers() for at least one of the
144 * output streams listed in configure_streams. The same stream is registered
145 * only once.
146 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800147 * >= CAMERA_DEVICE_API_VERSION_3_2:
148 *
149 * camera3_device_t->ops->register_stream_buffers() is not called and must
150 * be NULL.
151 *
152 * 6. The framework requests default settings for some number of use cases with
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800153 * calls to camera3_device_t->ops->construct_default_request_settings(). This
154 * may occur any time after step 3.
155 *
156 * 7. The framework constructs and sends the first capture request to the HAL,
157 * with settings based on one of the sets of default settings, and with at
158 * least one output stream, which has been registered earlier by the
159 * framework. This is sent to the HAL with
160 * camera3_device_t->ops->process_capture_request(). The HAL must block the
161 * return of this call until it is ready for the next request to be sent.
162 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800163 * >= CAMERA_DEVICE_API_VERSION_3_2:
164 *
165 * The buffer_handle_t provided in the camera3_stream_buffer_t array
166 * in the camera3_capture_request_t may be new and never-before-seen
167 * by the HAL on any given new request.
168 *
169 * 8. The framework continues to submit requests, and call
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800170 * construct_default_request_settings to get default settings buffers for
171 * other use cases.
172 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800173 * <= CAMERA_DEVICE_API_VERSION_3_1:
174 *
175 * The framework may call register_stream_buffers() at this time for
176 * not-yet-registered streams.
177 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800178 * 9. When the capture of a request begins (sensor starts exposing for the
179 * capture), the HAL calls camera3_callback_ops_t->notify() with the SHUTTER
180 * event, including the frame number and the timestamp for start of exposure.
Igor Murashkin5df2f622014-01-10 14:18:45 -0800181 *
182 * <= CAMERA_DEVICE_API_VERSION_3_1:
183 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -0700184 * This notify call must be made before the first call to
185 * process_capture_result() for that frame number.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800186 *
Igor Murashkin5df2f622014-01-10 14:18:45 -0800187 * >= CAMERA_DEVICE_API_VERSION_3_2:
188 *
189 * The camera3_callback_ops_t->notify() call with the SHUTTER event should
190 * be made as early as possible since the framework will be unable to
191 * deliver gralloc buffers to the application layer (for that frame) until
192 * it has a valid timestamp for the start of exposure.
193 *
194 * Both partial metadata results and the gralloc buffers may be sent to the
195 * framework at any time before or after the SHUTTER event.
196 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800197 * 10. After some pipeline delay, the HAL begins to return completed captures to
198 * the framework with camera3_callback_ops_t->process_capture_result(). These
199 * are returned in the same order as the requests were submitted. Multiple
200 * requests can be in flight at once, depending on the pipeline depth of the
201 * camera HAL device.
202 *
Igor Murashkin78aa1262014-01-09 16:23:43 -0800203 * >= CAMERA_DEVICE_API_VERSION_3_2:
204 *
205 * Once a buffer is returned by process_capture_result as part of the
206 * camera3_stream_buffer_t array, and the fence specified by release_fence
207 * has been signaled (this is a no-op for -1 fences), the ownership of that
208 * buffer is considered to be transferred back to the framework. After that,
209 * the HAL must no longer retain that particular buffer, and the
210 * framework may clean up the memory for it immediately.
211 *
Igor Murashkin5df2f622014-01-10 14:18:45 -0800212 * process_capture_result may be called multiple times for a single frame,
213 * each time with a new disjoint piece of metadata and/or set of gralloc
214 * buffers. The framework will accumulate these partial metadata results
215 * into one result.
216 *
217 * In particular, it is legal for a process_capture_result to be called
218 * simultaneously for both a frame N and a frame N+1 as long as the
Zhijun Heceac9e32014-02-05 20:49:45 -0800219 * above rule holds for gralloc buffers (both input and output).
Igor Murashkin5df2f622014-01-10 14:18:45 -0800220 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800221 * 11. After some time, the framework may stop submitting new requests, wait for
222 * the existing captures to complete (all buffers filled, all results
223 * returned), and then call configure_streams() again. This resets the camera
224 * hardware and pipeline for a new set of input/output streams. Some streams
225 * may be reused from the previous configuration; if these streams' buffers
226 * had already been registered with the HAL, they will not be registered
227 * again. The framework then continues from step 7, if at least one
228 * registered output stream remains (otherwise, step 5 is required first).
229 *
230 * 12. Alternatively, the framework may call camera3_device_t->common->close()
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -0800231 * to end the camera session. This may be called at any time when no other
232 * calls from the framework are active, although the call may block until all
233 * in-flight captures have completed (all results returned, all buffers
234 * filled). After the close call returns, no more calls to the
235 * camera3_callback_ops_t functions are allowed from the HAL. Once the
236 * close() call is underway, the framework may not call any other HAL device
237 * functions.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800238 *
239 * 13. In case of an error or other asynchronous event, the HAL must call
240 * camera3_callback_ops_t->notify() with the appropriate error/event
241 * message. After returning from a fatal device-wide error notification, the
242 * HAL should act as if close() had been called on it. However, the HAL must
243 * either cancel or complete all outstanding captures before calling
244 * notify(), so that once notify() is called with a fatal error, the
245 * framework will not receive further callbacks from the device. Methods
246 * besides close() should return -ENODEV or NULL after the notify() method
247 * returns from a fatal error message.
248 */
249
250/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700251 * S3. Operational modes:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800252 *
253 * The camera 3 HAL device can implement one of two possible operational modes;
254 * limited and full. Full support is expected from new higher-end
255 * devices. Limited mode has hardware requirements roughly in line with those
256 * for a camera HAL device v1 implementation, and is expected from older or
257 * inexpensive devices. Full is a strict superset of limited, and they share the
258 * same essential operational flow, as documented above.
259 *
260 * The HAL must indicate its level of support with the
261 * android.info.supportedHardwareLevel static metadata entry, with 0 indicating
262 * limited mode, and 1 indicating full mode support.
263 *
264 * Roughly speaking, limited-mode devices do not allow for application control
265 * of capture settings (3A control only), high-rate capture of high-resolution
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700266 * images, raw sensor readout, or support for YUV output streams above maximum
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800267 * recording resolution (JPEG only for large images).
268 *
269 * ** Details of limited mode behavior:
270 *
271 * - Limited-mode devices do not need to implement accurate synchronization
272 * between capture request settings and the actual image data
273 * captured. Instead, changes to settings may take effect some time in the
274 * future, and possibly not for the same output frame for each settings
275 * entry. Rapid changes in settings may result in some settings never being
276 * used for a capture. However, captures that include high-resolution output
277 * buffers ( > 1080p ) have to use the settings as specified (but see below
278 * for processing rate).
279 *
280 * - Limited-mode devices do not need to support most of the
281 * settings/result/static info metadata. Full-mode devices must support all
282 * metadata fields listed in TODO. Specifically, only the following settings
283 * are expected to be consumed or produced by a limited-mode HAL device:
284 *
285 * android.control.aeAntibandingMode (controls)
286 * android.control.aeExposureCompensation (controls)
287 * android.control.aeLock (controls)
288 * android.control.aeMode (controls)
289 * [OFF means ON_FLASH_TORCH - TODO]
290 * android.control.aeRegions (controls)
291 * android.control.aeTargetFpsRange (controls)
292 * android.control.afMode (controls)
293 * [OFF means infinity focus]
294 * android.control.afRegions (controls)
295 * android.control.awbLock (controls)
296 * android.control.awbMode (controls)
297 * [OFF not supported]
298 * android.control.awbRegions (controls)
299 * android.control.captureIntent (controls)
300 * android.control.effectMode (controls)
301 * android.control.mode (controls)
302 * [OFF not supported]
303 * android.control.sceneMode (controls)
304 * android.control.videoStabilizationMode (controls)
305 * android.control.aeAvailableAntibandingModes (static)
306 * android.control.aeAvailableModes (static)
307 * android.control.aeAvailableTargetFpsRanges (static)
308 * android.control.aeCompensationRange (static)
309 * android.control.aeCompensationStep (static)
310 * android.control.afAvailableModes (static)
311 * android.control.availableEffects (static)
312 * android.control.availableSceneModes (static)
313 * android.control.availableVideoStabilizationModes (static)
314 * android.control.awbAvailableModes (static)
315 * android.control.maxRegions (static)
316 * android.control.sceneModeOverrides (static)
317 * android.control.aeRegions (dynamic)
318 * android.control.aeState (dynamic)
319 * android.control.afMode (dynamic)
320 * android.control.afRegions (dynamic)
321 * android.control.afState (dynamic)
322 * android.control.awbMode (dynamic)
323 * android.control.awbRegions (dynamic)
324 * android.control.awbState (dynamic)
325 * android.control.mode (dynamic)
326 *
327 * android.flash.info.available (static)
328 *
329 * android.info.supportedHardwareLevel (static)
330 *
331 * android.jpeg.gpsCoordinates (controls)
332 * android.jpeg.gpsProcessingMethod (controls)
333 * android.jpeg.gpsTimestamp (controls)
334 * android.jpeg.orientation (controls)
335 * android.jpeg.quality (controls)
336 * android.jpeg.thumbnailQuality (controls)
337 * android.jpeg.thumbnailSize (controls)
338 * android.jpeg.availableThumbnailSizes (static)
339 * android.jpeg.maxSize (static)
340 * android.jpeg.gpsCoordinates (dynamic)
341 * android.jpeg.gpsProcessingMethod (dynamic)
342 * android.jpeg.gpsTimestamp (dynamic)
343 * android.jpeg.orientation (dynamic)
344 * android.jpeg.quality (dynamic)
345 * android.jpeg.size (dynamic)
346 * android.jpeg.thumbnailQuality (dynamic)
347 * android.jpeg.thumbnailSize (dynamic)
348 *
349 * android.lens.info.minimumFocusDistance (static)
350 *
351 * android.request.id (controls)
352 * android.request.id (dynamic)
353 *
354 * android.scaler.cropRegion (controls)
355 * [ignores (x,y), assumes center-zoom]
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -0800356 * android.scaler.availableStreamConfigurations (static)
357 * android.scaler.availableMinFrameDurations (static)
358 * android.scaler.availableStallDurations (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800359 * android.scaler.availableMaxDigitalZoom (static)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800360 * [full resolution not supported]
361 * android.scaler.maxDigitalZoom (static)
362 * android.scaler.cropRegion (dynamic)
363 *
364 * android.sensor.orientation (static)
365 * android.sensor.timestamp (dynamic)
366 *
367 * android.statistics.faceDetectMode (controls)
368 * android.statistics.info.availableFaceDetectModes (static)
369 * android.statistics.faceDetectMode (dynamic)
370 * android.statistics.faceIds (dynamic)
371 * android.statistics.faceLandmarks (dynamic)
372 * android.statistics.faceRectangles (dynamic)
373 * android.statistics.faceScores (dynamic)
374 *
375 * - Captures in limited mode that include high-resolution (> 1080p) output
376 * buffers may block in process_capture_request() until all the output buffers
377 * have been filled. A full-mode HAL device must process sequences of
378 * high-resolution requests at the rate indicated in the static metadata for
379 * that pixel format. The HAL must still call process_capture_result() to
380 * provide the output; the framework must simply be prepared for
381 * process_capture_request() to block until after process_capture_result() for
382 * that request completes for high-resolution captures for limited-mode
383 * devices.
384 *
385 */
386
387/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700388 * S4. 3A modes and state machines:
389 *
390 * While the actual 3A algorithms are up to the HAL implementation, a high-level
391 * state machine description is defined by the HAL interface, to allow the HAL
392 * device and the framework to communicate about the current state of 3A, and to
393 * trigger 3A events.
394 *
395 * When the device is opened, all the individual 3A states must be
396 * STATE_INACTIVE. Stream configuration does not reset 3A. For example, locked
397 * focus must be maintained across the configure() call.
398 *
399 * Triggering a 3A action involves simply setting the relevant trigger entry in
400 * the settings for the next request to indicate start of trigger. For example,
401 * the trigger for starting an autofocus scan is setting the entry
402 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTROL_AF_TRIGGER_START for one
403 * request, and cancelling an autofocus scan is triggered by setting
404 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTRL_AF_TRIGGER_CANCEL. Otherwise,
405 * the entry will not exist, or be set to ANDROID_CONTROL_AF_TRIGGER_IDLE. Each
406 * request with a trigger entry set to a non-IDLE value will be treated as an
407 * independent triggering event.
408 *
409 * At the top level, 3A is controlled by the ANDROID_CONTROL_MODE setting, which
410 * selects between no 3A (ANDROID_CONTROL_MODE_OFF), normal AUTO mode
411 * (ANDROID_CONTROL_MODE_AUTO), and using the scene mode setting
412 * (ANDROID_CONTROL_USE_SCENE_MODE).
413 *
414 * - In OFF mode, each of the individual AE/AF/AWB modes are effectively OFF,
415 * and none of the capture controls may be overridden by the 3A routines.
416 *
417 * - In AUTO mode, Auto-focus, auto-exposure, and auto-whitebalance all run
418 * their own independent algorithms, and have their own mode, state, and
419 * trigger metadata entries, as listed in the next section.
420 *
421 * - In USE_SCENE_MODE, the value of the ANDROID_CONTROL_SCENE_MODE entry must
422 * be used to determine the behavior of 3A routines. In SCENE_MODEs other than
423 * FACE_PRIORITY, the HAL must override the values of
424 * ANDROId_CONTROL_AE/AWB/AF_MODE to be the mode it prefers for the selected
425 * SCENE_MODE. For example, the HAL may prefer SCENE_MODE_NIGHT to use
426 * CONTINUOUS_FOCUS AF mode. Any user selection of AE/AWB/AF_MODE when scene
427 * must be ignored for these scene modes.
428 *
429 * - For SCENE_MODE_FACE_PRIORITY, the AE/AWB/AF_MODE controls work as in
430 * ANDROID_CONTROL_MODE_AUTO, but the 3A routines must bias toward metering
431 * and focusing on any detected faces in the scene.
432 *
433 * S4.1. Auto-focus settings and result entries:
434 *
435 * Main metadata entries:
436 *
437 * ANDROID_CONTROL_AF_MODE: Control for selecting the current autofocus
438 * mode. Set by the framework in the request settings.
439 *
440 * AF_MODE_OFF: AF is disabled; the framework/app directly controls lens
441 * position.
442 *
443 * AF_MODE_AUTO: Single-sweep autofocus. No lens movement unless AF is
444 * triggered.
445 *
446 * AF_MODE_MACRO: Single-sweep up-close autofocus. No lens movement unless
447 * AF is triggered.
448 *
449 * AF_MODE_CONTINUOUS_VIDEO: Smooth continuous focusing, for recording
450 * video. Triggering immediately locks focus in current
451 * position. Canceling resumes cotinuous focusing.
452 *
453 * AF_MODE_CONTINUOUS_PICTURE: Fast continuous focusing, for
454 * zero-shutter-lag still capture. Triggering locks focus once currently
455 * active sweep concludes. Canceling resumes continuous focusing.
456 *
457 * AF_MODE_EDOF: Advanced extended depth of field focusing. There is no
458 * autofocus scan, so triggering one or canceling one has no effect.
459 * Images are focused automatically by the HAL.
460 *
461 * ANDROID_CONTROL_AF_STATE: Dynamic metadata describing the current AF
462 * algorithm state, reported by the HAL in the result metadata.
463 *
464 * AF_STATE_INACTIVE: No focusing has been done, or algorithm was
465 * reset. Lens is not moving. Always the state for MODE_OFF or MODE_EDOF.
466 * When the device is opened, it must start in this state.
467 *
468 * AF_STATE_PASSIVE_SCAN: A continuous focus algorithm is currently scanning
469 * for good focus. The lens is moving.
470 *
471 * AF_STATE_PASSIVE_FOCUSED: A continuous focus algorithm believes it is
472 * well focused. The lens is not moving. The HAL may spontaneously leave
473 * this state.
474 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700475 * AF_STATE_PASSIVE_UNFOCUSED: A continuous focus algorithm believes it is
476 * not well focused. The lens is not moving. The HAL may spontaneously
477 * leave this state.
478 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700479 * AF_STATE_ACTIVE_SCAN: A scan triggered by the user is underway.
480 *
481 * AF_STATE_FOCUSED_LOCKED: The AF algorithm believes it is focused. The
482 * lens is not moving.
483 *
484 * AF_STATE_NOT_FOCUSED_LOCKED: The AF algorithm has been unable to
485 * focus. The lens is not moving.
486 *
487 * ANDROID_CONTROL_AF_TRIGGER: Control for starting an autofocus scan, the
488 * meaning of which is mode- and state- dependent. Set by the framework in
489 * the request settings.
490 *
491 * AF_TRIGGER_IDLE: No current trigger.
492 *
493 * AF_TRIGGER_START: Trigger start of AF scan. Effect is mode and state
494 * dependent.
495 *
496 * AF_TRIGGER_CANCEL: Cancel current AF scan if any, and reset algorithm to
497 * default.
498 *
499 * Additional metadata entries:
500 *
501 * ANDROID_CONTROL_AF_REGIONS: Control for selecting the regions of the FOV
502 * that should be used to determine good focus. This applies to all AF
503 * modes that scan for focus. Set by the framework in the request
504 * settings.
505 *
506 * S4.2. Auto-exposure settings and result entries:
507 *
508 * Main metadata entries:
509 *
510 * ANDROID_CONTROL_AE_MODE: Control for selecting the current auto-exposure
511 * mode. Set by the framework in the request settings.
512 *
513 * AE_MODE_OFF: Autoexposure is disabled; the user controls exposure, gain,
514 * frame duration, and flash.
515 *
516 * AE_MODE_ON: Standard autoexposure, with flash control disabled. User may
517 * set flash to fire or to torch mode.
518 *
519 * AE_MODE_ON_AUTO_FLASH: Standard autoexposure, with flash on at HAL's
520 * discretion for precapture and still capture. User control of flash
521 * disabled.
522 *
523 * AE_MODE_ON_ALWAYS_FLASH: Standard autoexposure, with flash always fired
524 * for capture, and at HAL's discretion for precapture.. User control of
525 * flash disabled.
526 *
527 * AE_MODE_ON_AUTO_FLASH_REDEYE: Standard autoexposure, with flash on at
528 * HAL's discretion for precapture and still capture. Use a flash burst
529 * at end of precapture sequence to reduce redeye in the final
530 * picture. User control of flash disabled.
531 *
532 * ANDROID_CONTROL_AE_STATE: Dynamic metadata describing the current AE
533 * algorithm state, reported by the HAL in the result metadata.
534 *
535 * AE_STATE_INACTIVE: Initial AE state after mode switch. When the device is
536 * opened, it must start in this state.
537 *
538 * AE_STATE_SEARCHING: AE is not converged to a good value, and is adjusting
539 * exposure parameters.
540 *
541 * AE_STATE_CONVERGED: AE has found good exposure values for the current
542 * scene, and the exposure parameters are not changing. HAL may
543 * spontaneously leave this state to search for better solution.
544 *
545 * AE_STATE_LOCKED: AE has been locked with the AE_LOCK control. Exposure
546 * values are not changing.
547 *
548 * AE_STATE_FLASH_REQUIRED: The HAL has converged exposure, but believes
549 * flash is required for a sufficiently bright picture. Used for
550 * determining if a zero-shutter-lag frame can be used.
551 *
552 * AE_STATE_PRECAPTURE: The HAL is in the middle of a precapture
553 * sequence. Depending on AE mode, this mode may involve firing the
554 * flash for metering, or a burst of flash pulses for redeye reduction.
555 *
556 * ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER: Control for starting a metering
557 * sequence before capturing a high-quality image. Set by the framework in
558 * the request settings.
559 *
560 * PRECAPTURE_TRIGGER_IDLE: No current trigger.
561 *
562 * PRECAPTURE_TRIGGER_START: Start a precapture sequence. The HAL should
563 * use the subsequent requests to measure good exposure/white balance
564 * for an upcoming high-resolution capture.
565 *
566 * Additional metadata entries:
567 *
568 * ANDROID_CONTROL_AE_LOCK: Control for locking AE controls to their current
569 * values
570 *
571 * ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION: Control for adjusting AE
572 * algorithm target brightness point.
573 *
574 * ANDROID_CONTROL_AE_TARGET_FPS_RANGE: Control for selecting the target frame
575 * rate range for the AE algorithm. The AE routine cannot change the frame
576 * rate to be outside these bounds.
577 *
578 * ANDROID_CONTROL_AE_REGIONS: Control for selecting the regions of the FOV
579 * that should be used to determine good exposure levels. This applies to
580 * all AE modes besides OFF.
581 *
582 * S4.3. Auto-whitebalance settings and result entries:
583 *
584 * Main metadata entries:
585 *
586 * ANDROID_CONTROL_AWB_MODE: Control for selecting the current white-balance
587 * mode.
588 *
589 * AWB_MODE_OFF: Auto-whitebalance is disabled. User controls color matrix.
590 *
591 * AWB_MODE_AUTO: Automatic white balance is enabled; 3A controls color
592 * transform, possibly using more complex transforms than a simple
593 * matrix.
594 *
595 * AWB_MODE_INCANDESCENT: Fixed white balance settings good for indoor
596 * incandescent (tungsten) lighting, roughly 2700K.
597 *
598 * AWB_MODE_FLUORESCENT: Fixed white balance settings good for fluorescent
599 * lighting, roughly 5000K.
600 *
601 * AWB_MODE_WARM_FLUORESCENT: Fixed white balance settings good for
602 * fluorescent lighting, roughly 3000K.
603 *
604 * AWB_MODE_DAYLIGHT: Fixed white balance settings good for daylight,
605 * roughly 5500K.
606 *
607 * AWB_MODE_CLOUDY_DAYLIGHT: Fixed white balance settings good for clouded
608 * daylight, roughly 6500K.
609 *
610 * AWB_MODE_TWILIGHT: Fixed white balance settings good for
611 * near-sunset/sunrise, roughly 15000K.
612 *
613 * AWB_MODE_SHADE: Fixed white balance settings good for areas indirectly
614 * lit by the sun, roughly 7500K.
615 *
616 * ANDROID_CONTROL_AWB_STATE: Dynamic metadata describing the current AWB
617 * algorithm state, reported by the HAL in the result metadata.
618 *
619 * AWB_STATE_INACTIVE: Initial AWB state after mode switch. When the device
620 * is opened, it must start in this state.
621 *
622 * AWB_STATE_SEARCHING: AWB is not converged to a good value, and is
623 * changing color adjustment parameters.
624 *
625 * AWB_STATE_CONVERGED: AWB has found good color adjustment values for the
626 * current scene, and the parameters are not changing. HAL may
627 * spontaneously leave this state to search for better solution.
628 *
629 * AWB_STATE_LOCKED: AWB has been locked with the AWB_LOCK control. Color
630 * adjustment values are not changing.
631 *
632 * Additional metadata entries:
633 *
634 * ANDROID_CONTROL_AWB_LOCK: Control for locking AWB color adjustments to
635 * their current values.
636 *
637 * ANDROID_CONTROL_AWB_REGIONS: Control for selecting the regions of the FOV
638 * that should be used to determine good color balance. This applies only
639 * to auto-WB mode.
640 *
641 * S4.4. General state machine transition notes
642 *
643 * Switching between AF, AE, or AWB modes always resets the algorithm's state
644 * to INACTIVE. Similarly, switching between CONTROL_MODE or
645 * CONTROL_SCENE_MODE if CONTROL_MODE == USE_SCENE_MODE resets all the
646 * algorithm states to INACTIVE.
647 *
648 * The tables below are per-mode.
649 *
650 * S4.5. AF state machines
651 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700652 * when enabling AF or changing AF mode
653 *| state | trans. cause | new state | notes |
654 *+--------------------+---------------+--------------------+------------------+
655 *| Any | AF mode change| INACTIVE | |
656 *+--------------------+---------------+--------------------+------------------+
657 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700658 * mode = AF_MODE_OFF or AF_MODE_EDOF
659 *| state | trans. cause | new state | notes |
660 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700661 *| INACTIVE | | INACTIVE | Never changes |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700662 *+--------------------+---------------+--------------------+------------------+
663 *
664 * mode = AF_MODE_AUTO or AF_MODE_MACRO
665 *| state | trans. cause | new state | notes |
666 *+--------------------+---------------+--------------------+------------------+
667 *| INACTIVE | AF_TRIGGER | ACTIVE_SCAN | Start AF sweep |
668 *| | | | Lens now moving |
669 *+--------------------+---------------+--------------------+------------------+
670 *| ACTIVE_SCAN | AF sweep done | FOCUSED_LOCKED | If AF successful |
671 *| | | | Lens now locked |
672 *+--------------------+---------------+--------------------+------------------+
673 *| ACTIVE_SCAN | AF sweep done | NOT_FOCUSED_LOCKED | If AF successful |
674 *| | | | Lens now locked |
675 *+--------------------+---------------+--------------------+------------------+
676 *| ACTIVE_SCAN | AF_CANCEL | INACTIVE | Cancel/reset AF |
677 *| | | | Lens now locked |
678 *+--------------------+---------------+--------------------+------------------+
679 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
680 *+--------------------+---------------+--------------------+------------------+
681 *| FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
682 *| | | | Lens now moving |
683 *+--------------------+---------------+--------------------+------------------+
684 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
685 *+--------------------+---------------+--------------------+------------------+
686 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
687 *| | | | Lens now moving |
688 *+--------------------+---------------+--------------------+------------------+
689 *| All states | mode change | INACTIVE | |
690 *+--------------------+---------------+--------------------+------------------+
691 *
692 * mode = AF_MODE_CONTINUOUS_VIDEO
693 *| state | trans. cause | new state | notes |
694 *+--------------------+---------------+--------------------+------------------+
695 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
696 *| | new scan | | Lens now moving |
697 *+--------------------+---------------+--------------------+------------------+
698 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
699 *| | | | Lens now locked |
700 *+--------------------+---------------+--------------------+------------------+
701 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
702 *| | current scan | | Lens now locked |
703 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700704 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
705 *| | current scan | | Lens now locked |
706 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700707 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
708 *| | | | if focus is good |
709 *| | | | Lens now locked |
710 *+--------------------+---------------+--------------------+------------------+
711 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
712 *| | | | if focus is bad |
713 *| | | | Lens now locked |
714 *+--------------------+---------------+--------------------+------------------+
715 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
716 *| | | | position |
717 *| | | | Lens now locked |
718 *+--------------------+---------------+--------------------+------------------+
719 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
720 *| | new scan | | Lens now moving |
721 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700722 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
723 *| | new scan | | Lens now moving |
724 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700725 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700726 *| | | | Lens now locked |
727 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700728 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700729 *| | | | Lens now locked |
730 *+--------------------+---------------+--------------------+------------------+
731 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
732 *+--------------------+---------------+--------------------+------------------+
733 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
734 *+--------------------+---------------+--------------------+------------------+
735 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
736 *+--------------------+---------------+--------------------+------------------+
737 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
738 *+--------------------+---------------+--------------------+------------------+
739 *
740 * mode = AF_MODE_CONTINUOUS_PICTURE
741 *| state | trans. cause | new state | notes |
742 *+--------------------+---------------+--------------------+------------------+
743 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
744 *| | new scan | | Lens now moving |
745 *+--------------------+---------------+--------------------+------------------+
746 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
747 *| | | | Lens now locked |
748 *+--------------------+---------------+--------------------+------------------+
749 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
750 *| | current scan | | Lens now locked |
751 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700752 *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
753 *| | current scan | | Lens now locked |
754 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700755 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Eventual trans. |
756 *| | | | once focus good |
757 *| | | | Lens now locked |
758 *+--------------------+---------------+--------------------+------------------+
759 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Eventual trans. |
760 *| | | | if cannot focus |
761 *| | | | Lens now locked |
762 *+--------------------+---------------+--------------------+------------------+
763 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
764 *| | | | position |
765 *| | | | Lens now locked |
766 *+--------------------+---------------+--------------------+------------------+
767 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
768 *| | new scan | | Lens now moving |
769 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700770 *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
771 *| | new scan | | Lens now moving |
772 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700773 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700774 *| | | | Lens now locked |
775 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700776 *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700777 *| | | | Lens now locked |
778 *+--------------------+---------------+--------------------+------------------+
779 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
780 *+--------------------+---------------+--------------------+------------------+
781 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
782 *+--------------------+---------------+--------------------+------------------+
783 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
784 *+--------------------+---------------+--------------------+------------------+
785 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
786 *+--------------------+---------------+--------------------+------------------+
787 *
788 * S4.6. AE and AWB state machines
789 *
790 * The AE and AWB state machines are mostly identical. AE has additional
791 * FLASH_REQUIRED and PRECAPTURE states. So rows below that refer to those two
792 * states should be ignored for the AWB state machine.
793 *
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700794 * when enabling AE/AWB or changing AE/AWB mode
795 *| state | trans. cause | new state | notes |
796 *+--------------------+---------------+--------------------+------------------+
797 *| Any | mode change | INACTIVE | |
798 *+--------------------+---------------+--------------------+------------------+
799 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700800 * mode = AE_MODE_OFF / AWB mode not AUTO
801 *| state | trans. cause | new state | notes |
802 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala4d45d302013-09-20 17:24:50 -0700803 *| INACTIVE | | INACTIVE | AE/AWB disabled |
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700804 *+--------------------+---------------+--------------------+------------------+
805 *
806 * mode = AE_MODE_ON_* / AWB_MODE_AUTO
807 *| state | trans. cause | new state | notes |
808 *+--------------------+---------------+--------------------+------------------+
809 *| INACTIVE | HAL initiates | SEARCHING | |
810 *| | AE/AWB scan | | |
811 *+--------------------+---------------+--------------------+------------------+
812 *| INACTIVE | AE/AWB_LOCK | LOCKED | values locked |
813 *| | on | | |
814 *+--------------------+---------------+--------------------+------------------+
815 *| SEARCHING | HAL finishes | CONVERGED | good values, not |
816 *| | AE/AWB scan | | changing |
817 *+--------------------+---------------+--------------------+------------------+
818 *| SEARCHING | HAL finishes | FLASH_REQUIRED | converged but too|
819 *| | AE scan | | dark w/o flash |
820 *+--------------------+---------------+--------------------+------------------+
821 *| SEARCHING | AE/AWB_LOCK | LOCKED | values locked |
822 *| | on | | |
823 *+--------------------+---------------+--------------------+------------------+
824 *| CONVERGED | HAL initiates | SEARCHING | values locked |
825 *| | AE/AWB scan | | |
826 *+--------------------+---------------+--------------------+------------------+
827 *| CONVERGED | AE/AWB_LOCK | LOCKED | values locked |
828 *| | on | | |
829 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvala73dba5e2013-05-21 16:29:14 -0700830 *| FLASH_REQUIRED | HAL initiates | SEARCHING | values locked |
831 *| | AE/AWB scan | | |
832 *+--------------------+---------------+--------------------+------------------+
833 *| FLASH_REQUIRED | AE/AWB_LOCK | LOCKED | values locked |
834 *| | on | | |
835 *+--------------------+---------------+--------------------+------------------+
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700836 *| LOCKED | AE/AWB_LOCK | SEARCHING | values not good |
837 *| | off | | after unlock |
838 *+--------------------+---------------+--------------------+------------------+
839 *| LOCKED | AE/AWB_LOCK | CONVERGED | values good |
840 *| | off | | after unlock |
841 *+--------------------+---------------+--------------------+------------------+
842 *| LOCKED | AE_LOCK | FLASH_REQUIRED | exposure good, |
843 *| | off | | but too dark |
844 *+--------------------+---------------+--------------------+------------------+
845 *| All AE states | PRECAPTURE_ | PRECAPTURE | Start precapture |
846 *| | START | | sequence |
847 *+--------------------+---------------+--------------------+------------------+
848 *| PRECAPTURE | Sequence done.| CONVERGED | Ready for high- |
849 *| | AE_LOCK off | | quality capture |
850 *+--------------------+---------------+--------------------+------------------+
851 *| PRECAPTURE | Sequence done.| LOCKED | Ready for high- |
852 *| | AE_LOCK on | | quality capture |
853 *+--------------------+---------------+--------------------+------------------+
854 *
855 */
856
857/**
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700858 * S5. Cropping:
859 *
860 * Cropping of the full pixel array (for digital zoom and other use cases where
861 * a smaller FOV is desirable) is communicated through the
862 * ANDROID_SCALER_CROP_REGION setting. This is a per-request setting, and can
863 * change on a per-request basis, which is critical for implementing smooth
864 * digital zoom.
865 *
866 * The region is defined as a rectangle (x, y, width, height), with (x, y)
867 * describing the top-left corner of the rectangle. The rectangle is defined on
868 * the coordinate system of the sensor active pixel array, with (0,0) being the
869 * top-left pixel of the active pixel array. Therefore, the width and height
870 * cannot be larger than the dimensions reported in the
871 * ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY static info field. The minimum allowed
872 * width and height are reported by the HAL through the
873 * ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes the
874 * maximum supported zoom factor. Therefore, the minimum crop region width and
875 * height are:
876 *
877 * {width, height} =
878 * { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
879 * ANDROID_SCALER_MAX_DIGITAL_ZOOM),
880 * floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
881 * ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
882 *
883 * If the crop region needs to fulfill specific requirements (for example, it
884 * needs to start on even coordinates, and its width/height needs to be even),
885 * the HAL must do the necessary rounding and write out the final crop region
886 * used in the output result metadata. Similarly, if the HAL implements video
887 * stabilization, it must adjust the result crop region to describe the region
888 * actually included in the output after video stabilization is applied. In
889 * general, a camera-using application must be able to determine the field of
890 * view it is receiving based on the crop region, the dimensions of the image
891 * sensor, and the lens focal length.
892 *
893 * Since the crop region applies to all streams, which may have different aspect
894 * ratios than the crop region, the exact sensor region used for each stream may
895 * be smaller than the crop region. Specifically, each stream should maintain
896 * square pixels and its aspect ratio by minimally further cropping the defined
897 * crop region. If the stream's aspect ratio is wider than the crop region, the
898 * stream should be further cropped vertically, and if the stream's aspect ratio
899 * is narrower than the crop region, the stream should be further cropped
900 * horizontally.
901 *
902 * In all cases, the stream crop must be centered within the full crop region,
903 * and each stream is only either cropped horizontally or vertical relative to
904 * the full crop region, never both.
905 *
906 * For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
907 * 1280x720 stream (16:9 aspect), below demonstrates the expected output regions
908 * for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
909 * 1500 pixel array) sensor.
910 *
911 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
912 *
913 * 640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)
914 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
915 *
916 * 0 1000 2000
917 * +---------+---------+---------+----------+
918 * | Active pixel array |
919 * | |
920 * | |
921 * + +-------------------+ + 375
922 * | | | |
923 * | O===================O |
924 * | I 1280x720 stream I |
925 * + I I + 750
926 * | I I |
927 * | O===================O |
928 * | | | |
929 * + +-------------------+ + 1125
930 * | Crop region, 640x480 stream |
931 * | |
932 * | |
933 * +---------+---------+---------+----------+ 1500
934 *
935 * Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)
936 *
937 * 640x480 stream crop: (666, 375, 1000, 750) (marked with =)
938 * 1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
939 *
940 * 0 1000 2000
941 * +---------+---------+---------+----------+
942 * | Active pixel array |
943 * | |
944 * | |
945 * + +---O==================O---+ + 375
946 * | | I 640x480 stream I | |
947 * | | I I | |
948 * | | I I | |
949 * + | I I | + 750
950 * | | I I | |
951 * | | I I | |
952 * | | I I | |
953 * + +---O==================O---+ + 1125
954 * | Crop region, 1280x720 stream |
955 * | |
956 * | |
957 * +---------+---------+---------+----------+ 1500
958 *
959 * Crop region: (500, 375, 750, 750) (1:1 aspect ratio)
960 *
961 * 640x480 stream crop: (500, 469, 750, 562) (marked with =)
962 * 1280x720 stream crop: (500, 543, 750, 414) (marged with #)
963 *
964 * 0 1000 2000
965 * +---------+---------+---------+----------+
966 * | Active pixel array |
967 * | |
968 * | |
969 * + +--------------+ + 375
970 * | O==============O |
971 * | ################ |
972 * | # # |
973 * + # # + 750
974 * | # # |
975 * | ################ 1280x720 |
976 * | O==============O 640x480 |
977 * + +--------------+ + 1125
978 * | Crop region |
979 * | |
980 * | |
981 * +---------+---------+---------+----------+ 1500
982 *
983 * And a final example, a 1024x1024 square aspect ratio stream instead of the
984 * 480p stream:
985 *
986 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
987 *
988 * 1024x1024 stream crop: (625, 375, 750, 750) (marked with #)
989 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
990 *
991 * 0 1000 2000
992 * +---------+---------+---------+----------+
993 * | Active pixel array |
994 * | |
995 * | 1024x1024 stream |
996 * + +--###############--+ + 375
997 * | | # # | |
998 * | O===================O |
999 * | I 1280x720 stream I |
1000 * + I I + 750
1001 * | I I |
1002 * | O===================O |
1003 * | | # # | |
1004 * + +--###############--+ + 1125
1005 * | Crop region |
1006 * | |
1007 * | |
1008 * +---------+---------+---------+----------+ 1500
1009 *
1010 */
1011
1012/**
1013 * S6. Error management:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001014 *
1015 * Camera HAL device ops functions that have a return value will all return
1016 * -ENODEV / NULL in case of a serious error. This means the device cannot
1017 * continue operation, and must be closed by the framework. Once this error is
Alex Rayd5ddbc92013-02-15 13:47:24 -08001018 * returned by some method, or if notify() is called with ERROR_DEVICE, only
1019 * the close() method can be called successfully. All other methods will return
1020 * -ENODEV / NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001021 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001022 * If a device op is called in the wrong sequence, for example if the framework
1023 * calls configure_streams() is called before initialize(), the device must
1024 * return -ENOSYS from the call, and do nothing.
1025 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001026 * Transient errors in image capture must be reported through notify() as follows:
1027 *
1028 * - The failure of an entire capture to occur must be reported by the HAL by
1029 * calling notify() with ERROR_REQUEST. Individual errors for the result
1030 * metadata or the output buffers must not be reported in this case.
1031 *
1032 * - If the metadata for a capture cannot be produced, but some image buffers
1033 * were filled, the HAL must call notify() with ERROR_RESULT.
1034 *
1035 * - If an output image buffer could not be filled, but either the metadata was
1036 * produced or some other buffers were filled, the HAL must call notify() with
1037 * ERROR_BUFFER for each failed buffer.
1038 *
1039 * In each of these transient failure cases, the HAL must still call
Zhijun Heceac9e32014-02-05 20:49:45 -08001040 * process_capture_result, with valid output and input (if an input buffer was
1041 * submitted) buffer_handle_t. If the result metadata could not be produced, it
1042 * should be NULL. If some buffers could not be filled, they must be returned with
1043 * process_capture_result in the error state, their release fences must be set to
1044 * the acquire fences passed by the framework, or -1 if they have been waited on by
1045 * the HAL already.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001046 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001047 * Invalid input arguments result in -EINVAL from the appropriate methods. In
1048 * that case, the framework must act as if that call had never been made.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001049 *
1050 */
1051
Zhijun He2dde4682014-01-09 09:11:49 -08001052/**
Zhijun He709e5872014-01-17 15:25:21 -08001053 * S7. Key Performance Indicator (KPI) glossary:
Zhijun He2dde4682014-01-09 09:11:49 -08001054 *
Zhijun He709e5872014-01-17 15:25:21 -08001055 * This includes some critical definitions that are used by KPI metrics.
Zhijun He2dde4682014-01-09 09:11:49 -08001056 *
1057 * Pipeline Latency:
1058 * For a given capture request, the duration from the framework calling
1059 * process_capture_request to the HAL sending capture result and all buffers
1060 * back by process_capture_result call. To make the Pipeline Latency measure
1061 * independent of frame rate, it is measured by frame count.
1062 *
1063 * For example, when frame rate is 30 (fps), the frame duration (time interval
1064 * between adjacent frame capture time) is 33 (ms).
1065 * If it takes 5 frames for framework to get the result and buffers back for
1066 * a given request, then the Pipeline Latency is 5 (frames), instead of
1067 * 5 x 33 = 165 (ms).
1068 *
1069 * The Pipeline Latency is determined by android.request.pipelineDepth and
1070 * android.request.pipelineMaxDepth, see their definitions for more details.
1071 *
1072 */
1073
Zhijun Hebc358682014-01-23 14:42:54 -08001074/**
1075 * S8. Sample Use Cases:
1076 *
1077 * This includes some typical use case examples the camera HAL may support.
1078 *
1079 * S8.1 Zero Shutter Lag (ZSL) with CAMERA3_STREAM_INPUT stream.
1080 *
1081 * When Zero Shutter Lag (ZSL) is supported by the camera device, the INPUT stream
1082 * can be used for application/framework implemented ZSL use case. This kind of stream
1083 * will be used by the framework as follows:
1084 *
1085 * 1. Framework configures an opaque raw format output stream that is used to
1086 * produce the ZSL output buffers. The stream pixel format will be
1087 * HAL_PIXEL_FORMAT_RAW_OPAQUE.
1088 *
1089 * 2. Framework configures an opaque raw format input stream that is used to
1090 * send the reprocess ZSL buffers to the HAL. The stream pixel format will
1091 * also be HAL_PIXEL_FORMAT_RAW_OPAQUE.
1092 *
1093 * 3. Framework configures a YUV/JPEG output stream that is used to receive the
1094 * reprocessed data. The stream pixel format will be YCbCr_420/HAL_PIXEL_FORMAT_BLOB.
1095 *
1096 * 4. Framework picks a ZSL buffer from the output stream when a ZSL capture is
1097 * issued by the application, and sends the data back as an input buffer in a
1098 * reprocessing request, then sends to the HAL for reprocessing.
1099 *
1100 * 5. The HAL sends back the output JPEG result to framework.
1101 *
1102 * The HAL can select the actual raw buffer format and configure the ISP pipeline
1103 * appropriately based on the HAL_PIXEL_FORMAT_RAW_OPAQUE format. See this format
1104 * definition for more details.
1105 *
1106 * S8.2 Zero Shutter Lag (ZSL) with CAMERA3_STREAM_BIDIRECTIONAL stream.
1107 *
1108 * For this use case, the bidirectional stream will be used by the framework as follows:
1109 *
1110 * 1. The framework includes a buffer from this stream as output buffer in a
1111 * request as normal.
1112 *
1113 * 2. Once the HAL device returns a filled output buffer to the framework,
1114 * the framework may do one of two things with the filled buffer:
1115 *
1116 * 2. a. The framework uses the filled data, and returns the now-used buffer
1117 * to the stream queue for reuse. This behavior exactly matches the
1118 * OUTPUT type of stream.
1119 *
1120 * 2. b. The framework wants to reprocess the filled data, and uses the
1121 * buffer as an input buffer for a request. Once the HAL device has
1122 * used the reprocessing buffer, it then returns it to the
1123 * framework. The framework then returns the now-used buffer to the
1124 * stream queue for reuse.
1125 *
1126 * 3. The HAL device will be given the buffer again as an output buffer for
1127 * a request at some future point.
1128 *
1129 * For ZSL use case, the pixel format for bidirectional stream will be
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001130 * HAL_PIXEL_FORMAT_RAW_OPAQUE if it is listed in
1131 * android.scaler.availableInputOutputFormatsMap. A configuration stream list
1132 * that has BIDIRECTIONAL stream used as input, will usually also have a
1133 * distinct OUTPUT stream to get the reprocessing data. For example, for the
Zhijun Hebc358682014-01-23 14:42:54 -08001134 * ZSL use case, the stream list might be configured with the following:
1135 *
1136 * - A HAL_PIXEL_FORMAT_RAW_OPAQUE bidirectional stream is used
1137 * as input.
1138 * - And a HAL_PIXEL_FORMAT_BLOB (JPEG) output stream.
1139 *
1140 */
1141
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001142__BEGIN_DECLS
1143
1144struct camera3_device;
1145
1146/**********************************************************************
1147 *
1148 * Camera3 stream and stream buffer definitions.
1149 *
1150 * These structs and enums define the handles and contents of the input and
1151 * output streams connecting the HAL to various framework and application buffer
1152 * consumers. Each stream is backed by a gralloc buffer queue.
1153 *
1154 */
1155
1156/**
1157 * camera3_stream_type_t:
1158 *
1159 * The type of the camera stream, which defines whether the camera HAL device is
1160 * the producer or the consumer for that stream, and how the buffers of the
1161 * stream relate to the other streams.
1162 */
1163typedef enum camera3_stream_type {
1164 /**
1165 * This stream is an output stream; the camera HAL device will be
1166 * responsible for filling buffers from this stream with newly captured or
1167 * reprocessed image data.
1168 */
1169 CAMERA3_STREAM_OUTPUT = 0,
1170
1171 /**
1172 * This stream is an input stream; the camera HAL device will be responsible
1173 * for reading buffers from this stream and sending them through the camera
1174 * processing pipeline, as if the buffer was a newly captured image from the
1175 * imager.
Zhijun Hebc358682014-01-23 14:42:54 -08001176 *
1177 * The pixel format for input stream can be any format reported by
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001178 * android.scaler.availableInputOutputFormatsMap. The pixel format of the
1179 * output stream that is used to produce the reprocessing data may be any
1180 * format reported by android.scaler.availableStreamConfigurations. The
1181 * supported input/output stream combinations depends the camera device
1182 * capabilities, see android.scaler.availableInputOutputFormatsMap for
1183 * stream map details.
Zhijun Hebc358682014-01-23 14:42:54 -08001184 *
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001185 * This kind of stream is generally used to reprocess data into higher
1186 * quality images (that otherwise would cause a frame rate performance
1187 * loss), or to do off-line reprocessing.
Zhijun Hebc358682014-01-23 14:42:54 -08001188 *
1189 * A typical use case is Zero Shutter Lag (ZSL), see S8.1 for more details.
1190 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001191 */
1192 CAMERA3_STREAM_INPUT = 1,
1193
1194 /**
1195 * This stream can be used for input and output. Typically, the stream is
1196 * used as an output stream, but occasionally one already-filled buffer may
1197 * be sent back to the HAL device for reprocessing.
1198 *
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001199 * This kind of stream is meant generally for Zero Shutter Lag (ZSL)
1200 * features, where copying the captured image from the output buffer to the
Zhijun Hebc358682014-01-23 14:42:54 -08001201 * reprocessing input buffer would be expensive. See S8.2 for more details.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001202 *
1203 * Note that the HAL will always be reprocessing data it produced.
1204 *
1205 */
1206 CAMERA3_STREAM_BIDIRECTIONAL = 2,
1207
1208 /**
1209 * Total number of framework-defined stream types
1210 */
1211 CAMERA3_NUM_STREAM_TYPES
1212
1213} camera3_stream_type_t;
1214
1215/**
1216 * camera3_stream_t:
1217 *
1218 * A handle to a single camera input or output stream. A stream is defined by
1219 * the framework by its buffer resolution and format, and additionally by the
1220 * HAL with the gralloc usage flags and the maximum in-flight buffer count.
1221 *
1222 * The stream structures are owned by the framework, but pointers to a
1223 * camera3_stream passed into the HAL by configure_streams() are valid until the
1224 * end of the first subsequent configure_streams() call that _does not_ include
1225 * that camera3_stream as an argument, or until the end of the close() call.
1226 *
1227 * All camera3_stream framework-controlled members are immutable once the
1228 * camera3_stream is passed into configure_streams(). The HAL may only change
1229 * the HAL-controlled parameters during a configure_streams() call, except for
1230 * the contents of the private pointer.
1231 *
1232 * If a configure_streams() call returns a non-fatal error, all active streams
1233 * remain valid as if configure_streams() had not been called.
1234 *
1235 * The endpoint of the stream is not visible to the camera HAL device.
Alex Ray2ce219a2013-06-14 15:09:30 -07001236 * In DEVICE_API_VERSION_3_1, this was changed to share consumer usage flags
1237 * on streams where the camera is a producer (OUTPUT and BIDIRECTIONAL stream
1238 * types) see the usage field below.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001239 */
1240typedef struct camera3_stream {
1241
1242 /*****
1243 * Set by framework before configure_streams()
1244 */
1245
1246 /**
1247 * The type of the stream, one of the camera3_stream_type_t values.
1248 */
1249 int stream_type;
1250
1251 /**
1252 * The width in pixels of the buffers in this stream
1253 */
1254 uint32_t width;
1255
1256 /**
1257 * The height in pixels of the buffers in this stream
1258 */
1259 uint32_t height;
1260
1261 /**
1262 * The pixel format for the buffers in this stream. Format is a value from
1263 * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
1264 * from device-specific headers.
1265 *
1266 * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
1267 * gralloc module will select a format based on the usage flags provided by
1268 * the camera device and the other endpoint of the stream.
1269 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001270 * <= CAMERA_DEVICE_API_VERSION_3_1:
1271 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001272 * The camera HAL device must inspect the buffers handed to it in the
1273 * subsequent register_stream_buffers() call to obtain the
1274 * implementation-specific format details, if necessary.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001275 *
1276 * >= CAMERA_DEVICE_API_VERSION_3_2:
1277 *
1278 * register_stream_buffers() won't be called by the framework, so the HAL
1279 * should configure the ISP and sensor pipeline based purely on the sizes,
1280 * usage flags, and formats for the configured streams.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001281 */
1282 int format;
1283
1284 /*****
1285 * Set by HAL during configure_streams().
1286 */
1287
1288 /**
1289 * The gralloc usage flags for this stream, as needed by the HAL. The usage
1290 * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
1291 * headers.
1292 *
1293 * For output streams, these are the HAL's producer usage flags. For input
1294 * streams, these are the HAL's consumer usage flags. The usage flags from
1295 * the producer and the consumer will be combined together and then passed
1296 * to the platform gralloc HAL module for allocating the gralloc buffers for
1297 * each stream.
Alex Ray2ce219a2013-06-14 15:09:30 -07001298 *
1299 * Version information:
1300 *
1301 * == CAMERA_DEVICE_API_VERSION_3_0:
1302 *
1303 * No initial value guaranteed when passed via configure_streams().
1304 * HAL may not use this field as input, and must write over this field
1305 * with its usage flags.
1306 *
1307 * >= CAMERA_DEVICE_API_VERSION_3_1:
1308 *
1309 * For stream_type OUTPUT and BIDIRECTIONAL, when passed via
1310 * configure_streams(), the initial value of this is the consumer's
1311 * usage flags. The HAL may use these consumer flags to decide stream
1312 * configuration.
1313 * For stream_type INPUT, when passed via configure_streams(), the initial
1314 * value of this is 0.
1315 * For all streams passed via configure_streams(), the HAL must write
1316 * over this field with its usage flags.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001317 */
1318 uint32_t usage;
1319
1320 /**
1321 * The maximum number of buffers the HAL device may need to have dequeued at
1322 * the same time. The HAL device may not have more buffers in-flight from
1323 * this stream than this value.
1324 */
1325 uint32_t max_buffers;
1326
1327 /**
1328 * A handle to HAL-private information for the stream. Will not be inspected
1329 * by the framework code.
1330 */
1331 void *priv;
1332
1333} camera3_stream_t;
1334
1335/**
1336 * camera3_stream_configuration_t:
1337 *
1338 * A structure of stream definitions, used by configure_streams(). This
1339 * structure defines all the output streams and the reprocessing input
1340 * stream for the current camera use case.
1341 */
1342typedef struct camera3_stream_configuration {
1343 /**
1344 * The total number of streams requested by the framework. This includes
1345 * both input and output streams. The number of streams will be at least 1,
1346 * and there will be at least one output-capable stream.
1347 */
1348 uint32_t num_streams;
1349
1350 /**
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001351 * An array of camera stream pointers, defining the input/output
1352 * configuration for the camera HAL device.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001353 *
1354 * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
1355 * in a single configuration.
1356 *
1357 * At least one output-capable stream must be defined (OUTPUT or
1358 * BIDIRECTIONAL).
1359 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001360 camera3_stream_t **streams;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001361
1362} camera3_stream_configuration_t;
1363
1364/**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001365 * camera3_buffer_status_t:
1366 *
1367 * The current status of a single stream buffer.
1368 */
1369typedef enum camera3_buffer_status {
1370 /**
1371 * The buffer is in a normal state, and can be used after waiting on its
1372 * sync fence.
1373 */
1374 CAMERA3_BUFFER_STATUS_OK = 0,
1375
1376 /**
1377 * The buffer does not contain valid data, and the data in it should not be
1378 * used. The sync fence must still be waited on before reusing the buffer.
1379 */
1380 CAMERA3_BUFFER_STATUS_ERROR = 1
1381
1382} camera3_buffer_status_t;
1383
1384/**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001385 * camera3_stream_buffer_t:
1386 *
1387 * A single buffer from a camera3 stream. It includes a handle to its parent
1388 * stream, the handle to the gralloc buffer itself, and sync fences
1389 *
1390 * The buffer does not specify whether it is to be used for input or output;
1391 * that is determined by its parent stream type and how the buffer is passed to
1392 * the HAL device.
1393 */
1394typedef struct camera3_stream_buffer {
1395 /**
1396 * The handle of the stream this buffer is associated with
1397 */
1398 camera3_stream_t *stream;
1399
1400 /**
1401 * The native handle to the buffer
1402 */
1403 buffer_handle_t *buffer;
1404
1405 /**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001406 * Current state of the buffer, one of the camera3_buffer_status_t
1407 * values. The framework will not pass buffers to the HAL that are in an
1408 * error state. In case a buffer could not be filled by the HAL, it must
1409 * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
1410 * framework with process_capture_result().
1411 */
1412 int status;
1413
1414 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001415 * The acquire sync fence for this buffer. The HAL must wait on this fence
1416 * fd before attempting to read from or write to this buffer.
1417 *
1418 * The framework may be set to -1 to indicate that no waiting is necessary
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001419 * for this buffer.
1420 *
1421 * When the HAL returns an output buffer to the framework with
1422 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
1423 * never waits on the acquire_fence due to an error in filling a buffer,
1424 * when calling process_capture_result() the HAL must set the release_fence
1425 * of the buffer to be the acquire_fence passed to it by the framework. This
1426 * will allow the framework to wait on the fence before reusing the buffer.
1427 *
1428 * For input buffers, the HAL must not change the acquire_fence field during
1429 * the process_capture_request() call.
Zhijun Heceac9e32014-02-05 20:49:45 -08001430 *
1431 * >= CAMERA_DEVICE_API_VERSION_3_2:
1432 *
1433 * When the HAL returns an input buffer to the framework with
1434 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
Eino-Ville Talvalac5bff0d2014-02-10 16:43:26 -08001435 * never waits on input buffer acquire fence due to an error, the sync
1436 * fences should be handled similarly to the way they are handled for output
1437 * buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001438 */
1439 int acquire_fence;
1440
1441 /**
1442 * The release sync fence for this buffer. The HAL must set this fence when
1443 * returning buffers to the framework, or write -1 to indicate that no
1444 * waiting is required for this buffer.
1445 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001446 * For the output buffers, the fences must be set in the output_buffers
1447 * array passed to process_capture_result().
1448 *
1449 * <= CAMERA_DEVICE_API_VERSION_3_1:
1450 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001451 * For the input buffer, the release fence must be set by the
Zhijun Heceac9e32014-02-05 20:49:45 -08001452 * process_capture_request() call.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001453 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001454 * >= CAMERA_DEVICE_API_VERSION_3_2:
1455 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001456 * For the input buffer, the fences must be set in the input_buffer
1457 * passed to process_capture_result().
1458 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001459 * After signaling the release_fence for this buffer, the HAL
1460 * should not make any further attempts to access this buffer as the
1461 * ownership has been fully transferred back to the framework.
1462 *
1463 * If a fence of -1 was specified then the ownership of this buffer
1464 * is transferred back immediately upon the call of process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001465 */
1466 int release_fence;
1467
1468} camera3_stream_buffer_t;
1469
1470/**
1471 * camera3_stream_buffer_set_t:
1472 *
1473 * The complete set of gralloc buffers for a stream. This structure is given to
1474 * register_stream_buffers() to allow the camera HAL device to register/map/etc
1475 * newly allocated stream buffers.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001476 *
1477 * >= CAMERA_DEVICE_API_VERSION_3_2:
1478 *
1479 * Deprecated (and not used). In particular,
1480 * register_stream_buffers is also deprecated and will never be invoked.
1481 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001482 */
1483typedef struct camera3_stream_buffer_set {
1484 /**
1485 * The stream handle for the stream these buffers belong to
1486 */
1487 camera3_stream_t *stream;
1488
1489 /**
1490 * The number of buffers in this stream. It is guaranteed to be at least
1491 * stream->max_buffers.
1492 */
1493 uint32_t num_buffers;
1494
1495 /**
1496 * The array of gralloc buffer handles for this stream. If the stream format
1497 * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
1498 * should inspect the passed-in buffers to determine any platform-private
1499 * pixel format information.
1500 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001501 buffer_handle_t **buffers;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001502
1503} camera3_stream_buffer_set_t;
1504
1505/**
1506 * camera3_jpeg_blob:
1507 *
1508 * Transport header for compressed JPEG buffers in output streams.
1509 *
1510 * To capture JPEG images, a stream is created using the pixel format
1511 * HAL_PIXEL_FORMAT_BLOB, and the static metadata field android.jpeg.maxSize is
1512 * used as the buffer size. Since compressed JPEG images are of variable size,
1513 * the HAL needs to include the final size of the compressed image using this
1514 * structure inside the output stream buffer. The JPEG blob ID field must be set
1515 * to CAMERA3_JPEG_BLOB_ID.
1516 *
1517 * Transport header should be at the end of the JPEG output stream buffer. That
1518 * means the jpeg_blob_id must start at byte[android.jpeg.maxSize -
1519 * sizeof(camera3_jpeg_blob)]. Any HAL using this transport header must
1520 * account for it in android.jpeg.maxSize. The JPEG data itself starts at
1521 * the beginning of the buffer and should be jpeg_size bytes long.
1522 */
1523typedef struct camera3_jpeg_blob {
1524 uint16_t jpeg_blob_id;
1525 uint32_t jpeg_size;
1526} camera3_jpeg_blob_t;
1527
1528enum {
1529 CAMERA3_JPEG_BLOB_ID = 0x00FF
1530};
1531
1532/**********************************************************************
1533 *
1534 * Message definitions for the HAL notify() callback.
1535 *
1536 * These definitions are used for the HAL notify callback, to signal
1537 * asynchronous events from the HAL device to the Android framework.
1538 *
1539 */
1540
1541/**
1542 * camera3_msg_type:
1543 *
1544 * Indicates the type of message sent, which specifies which member of the
1545 * message union is valid.
1546 *
1547 */
1548typedef enum camera3_msg_type {
1549 /**
1550 * An error has occurred. camera3_notify_msg.message.error contains the
1551 * error information.
1552 */
1553 CAMERA3_MSG_ERROR = 1,
1554
1555 /**
1556 * The exposure of a given request has
1557 * begun. camera3_notify_msg.message.shutter contains the information
1558 * the capture.
1559 */
1560 CAMERA3_MSG_SHUTTER = 2,
1561
1562 /**
1563 * Number of framework message types
1564 */
1565 CAMERA3_NUM_MESSAGES
1566
1567} camera3_msg_type_t;
1568
1569/**
1570 * Defined error codes for CAMERA_MSG_ERROR
1571 */
1572typedef enum camera3_error_msg_code {
1573 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001574 * A serious failure occured. No further frames or buffer streams will
1575 * be produced by the device. Device should be treated as closed. The
1576 * client must reopen the device to use it again. The frame_number field
1577 * is unused.
1578 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001579 CAMERA3_MSG_ERROR_DEVICE = 1,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001580
1581 /**
1582 * An error has occurred in processing a request. No output (metadata or
1583 * buffers) will be produced for this request. The frame_number field
1584 * specifies which request has been dropped. Subsequent requests are
1585 * unaffected, and the device remains operational.
1586 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001587 CAMERA3_MSG_ERROR_REQUEST = 2,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001588
1589 /**
1590 * An error has occurred in producing an output result metadata buffer
1591 * for a request, but output stream buffers for it will still be
1592 * available. Subsequent requests are unaffected, and the device remains
1593 * operational. The frame_number field specifies the request for which
1594 * result metadata won't be available.
1595 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001596 CAMERA3_MSG_ERROR_RESULT = 3,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001597
1598 /**
1599 * An error has occurred in placing an output buffer into a stream for a
1600 * request. The frame metadata and other buffers may still be
1601 * available. Subsequent requests are unaffected, and the device remains
1602 * operational. The frame_number field specifies the request for which the
1603 * buffer was dropped, and error_stream contains a pointer to the stream
1604 * that dropped the frame.u
1605 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001606 CAMERA3_MSG_ERROR_BUFFER = 4,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001607
1608 /**
1609 * Number of error types
1610 */
1611 CAMERA3_MSG_NUM_ERRORS
1612
1613} camera3_error_msg_code_t;
1614
1615/**
1616 * camera3_error_msg_t:
1617 *
1618 * Message contents for CAMERA3_MSG_ERROR
1619 */
1620typedef struct camera3_error_msg {
1621 /**
1622 * Frame number of the request the error applies to. 0 if the frame number
1623 * isn't applicable to the error.
1624 */
1625 uint32_t frame_number;
1626
1627 /**
1628 * Pointer to the stream that had a failure. NULL if the stream isn't
1629 * applicable to the error.
1630 */
1631 camera3_stream_t *error_stream;
1632
1633 /**
1634 * The code for this error; one of the CAMERA_MSG_ERROR enum values.
1635 */
1636 int error_code;
1637
1638} camera3_error_msg_t;
1639
1640/**
1641 * camera3_shutter_msg_t:
1642 *
1643 * Message contents for CAMERA3_MSG_SHUTTER
1644 */
1645typedef struct camera3_shutter_msg {
1646 /**
1647 * Frame number of the request that has begun exposure
1648 */
1649 uint32_t frame_number;
1650
1651 /**
1652 * Timestamp for the start of capture. This must match the capture result
1653 * metadata's sensor exposure start timestamp.
1654 */
1655 uint64_t timestamp;
1656
1657} camera3_shutter_msg_t;
1658
1659/**
1660 * camera3_notify_msg_t:
1661 *
1662 * The message structure sent to camera3_callback_ops_t.notify()
1663 */
1664typedef struct camera3_notify_msg {
1665
1666 /**
1667 * The message type. One of camera3_notify_msg_type, or a private extension.
1668 */
1669 int type;
1670
1671 union {
1672 /**
1673 * Error message contents. Valid if type is CAMERA3_MSG_ERROR
1674 */
1675 camera3_error_msg_t error;
1676
1677 /**
1678 * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
1679 */
1680 camera3_shutter_msg_t shutter;
1681
1682 /**
1683 * Generic message contents. Used to ensure a minimum size for custom
1684 * message types.
1685 */
1686 uint8_t generic[32];
1687 } message;
1688
1689} camera3_notify_msg_t;
1690
1691/**********************************************************************
1692 *
1693 * Capture request/result definitions for the HAL process_capture_request()
1694 * method, and the process_capture_result() callback.
1695 *
1696 */
1697
1698/**
1699 * camera3_request_template_t:
1700 *
1701 * Available template types for
1702 * camera3_device_ops.construct_default_request_settings()
1703 */
1704typedef enum camera3_request_template {
1705 /**
1706 * Standard camera preview operation with 3A on auto.
1707 */
1708 CAMERA3_TEMPLATE_PREVIEW = 1,
1709
1710 /**
1711 * Standard camera high-quality still capture with 3A and flash on auto.
1712 */
1713 CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
1714
1715 /**
1716 * Standard video recording plus preview with 3A on auto, torch off.
1717 */
1718 CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
1719
1720 /**
1721 * High-quality still capture while recording video. Application will
1722 * include preview, video record, and full-resolution YUV or JPEG streams in
1723 * request. Must not cause stuttering on video stream. 3A on auto.
1724 */
1725 CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
1726
1727 /**
1728 * Zero-shutter-lag mode. Application will request preview and
1729 * full-resolution data for each frame, and reprocess it to JPEG when a
1730 * still image is requested by user. Settings should provide highest-quality
1731 * full-resolution images without compromising preview frame rate. 3A on
1732 * auto.
1733 */
1734 CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
1735
Zhijun Heb0c939f2013-12-13 15:56:33 -08001736 /**
1737 * A basic template for direct application control of capture
1738 * parameters. All automatic control is disabled (auto-exposure, auto-white
1739 * balance, auto-focus), and post-processing parameters are set to preview
1740 * quality. The manual capture parameters (exposure, sensitivity, etc.)
1741 * are set to reasonable defaults, but should be overridden by the
1742 * application depending on the intended use case.
1743 */
1744 CAMERA3_TEMPLATE_MANUAL = 6,
1745
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001746 /* Total number of templates */
1747 CAMERA3_TEMPLATE_COUNT,
1748
1749 /**
1750 * First value for vendor-defined request templates
1751 */
1752 CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
1753
1754} camera3_request_template_t;
1755
1756/**
1757 * camera3_capture_request_t:
1758 *
1759 * A single request for image capture/buffer reprocessing, sent to the Camera
1760 * HAL device by the framework in process_capture_request().
1761 *
1762 * The request contains the settings to be used for this capture, and the set of
1763 * output buffers to write the resulting image data in. It may optionally
1764 * contain an input buffer, in which case the request is for reprocessing that
1765 * input buffer instead of capturing a new image with the camera sensor. The
1766 * capture is identified by the frame_number.
1767 *
1768 * In response, the camera HAL device must send a camera3_capture_result
1769 * structure asynchronously to the framework, using the process_capture_result()
1770 * callback.
1771 */
1772typedef struct camera3_capture_request {
1773 /**
1774 * The frame number is an incrementing integer set by the framework to
1775 * uniquely identify this capture. It needs to be returned in the result
1776 * call, and is also used to identify the request in asynchronous
1777 * notifications sent to camera3_callback_ops_t.notify().
1778 */
1779 uint32_t frame_number;
1780
1781 /**
1782 * The settings buffer contains the capture and processing parameters for
1783 * the request. As a special case, a NULL settings buffer indicates that the
1784 * settings are identical to the most-recently submitted capture request. A
1785 * NULL buffer cannot be used as the first submitted request after a
1786 * configure_streams() call.
1787 */
1788 const camera_metadata_t *settings;
1789
1790 /**
1791 * The input stream buffer to use for this request, if any.
1792 *
1793 * If input_buffer is NULL, then the request is for a new capture from the
1794 * imager. If input_buffer is valid, the request is for reprocessing the
1795 * image contained in input_buffer.
1796 *
1797 * In the latter case, the HAL must set the release_fence of the
1798 * input_buffer to a valid sync fence, or to -1 if the HAL does not support
1799 * sync, before process_capture_request() returns.
1800 *
1801 * The HAL is required to wait on the acquire sync fence of the input buffer
1802 * before accessing it.
1803 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08001804 * <= CAMERA_DEVICE_API_VERSION_3_1:
1805 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001806 * Any input buffer included here will have been registered with the HAL
1807 * through register_stream_buffers() before its inclusion in a request.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001808 *
1809 * >= CAMERA_DEVICE_API_VERSION_3_2:
1810 *
1811 * The buffers will not have been pre-registered with the HAL.
1812 * Subsequent requests may reuse buffers, or provide entirely new buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001813 */
1814 camera3_stream_buffer_t *input_buffer;
1815
1816 /**
1817 * The number of output buffers for this capture request. Must be at least
1818 * 1.
1819 */
1820 uint32_t num_output_buffers;
1821
1822 /**
1823 * An array of num_output_buffers stream buffers, to be filled with image
1824 * data from this capture/reprocess. The HAL must wait on the acquire fences
Igor Murashkin78aa1262014-01-09 16:23:43 -08001825 * of each stream buffer before writing to them.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001826 *
1827 * The HAL takes ownership of the actual buffer_handle_t entries in
1828 * output_buffers; the framework does not access them until they are
1829 * returned in a camera3_capture_result_t.
Igor Murashkin78aa1262014-01-09 16:23:43 -08001830 *
1831 * <= CAMERA_DEVICE_API_VERSION_3_1:
1832 *
1833 * All the buffers included here will have been registered with the HAL
1834 * through register_stream_buffers() before their inclusion in a request.
1835 *
1836 * >= CAMERA_DEVICE_API_VERSION_3_2:
1837 *
1838 * Any or all of the buffers included here may be brand new in this
1839 * request (having never before seen by the HAL).
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001840 */
1841 const camera3_stream_buffer_t *output_buffers;
1842
1843} camera3_capture_request_t;
1844
1845/**
1846 * camera3_capture_result_t:
1847 *
1848 * The result of a single capture/reprocess by the camera HAL device. This is
1849 * sent to the framework asynchronously with process_capture_result(), in
1850 * response to a single capture request sent to the HAL with
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001851 * process_capture_request(). Multiple process_capture_result() calls may be
Igor Murashkin5df2f622014-01-10 14:18:45 -08001852 * performed by the HAL for each request.
1853 *
1854 * Each call, all with the same frame
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001855 * number, may contain some subset of the output buffers, and/or the result
1856 * metadata. The metadata may only be provided once for a given frame number;
1857 * all other calls must set the result metadata to NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001858 *
1859 * The result structure contains the output metadata from this capture, and the
1860 * set of output buffers that have been/will be filled for this capture. Each
1861 * output buffer may come with a release sync fence that the framework will wait
1862 * on before reading, in case the buffer has not yet been filled by the HAL.
1863 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08001864 * >= CAMERA_DEVICE_API_VERSION_3_2:
1865 *
1866 * The metadata may be provided multiple times for a single frame number. The
1867 * framework will accumulate together the final result set by combining each
1868 * partial result together into the total result set.
1869 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001870 * If an input buffer is given in a request, the HAL must return it in one of
1871 * the process_capture_result calls, and the call may be to just return the input
1872 * buffer, without metadata and output buffers; the sync fences must be handled
1873 * the same way they are done for output buffers.
1874 *
1875 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08001876 * Performance considerations:
1877 *
1878 * Applications will also receive these partial results immediately, so sending
1879 * partial results is a highly recommended performance optimization to avoid
1880 * the total pipeline latency before sending the results for what is known very
1881 * early on in the pipeline.
1882 *
1883 * A typical use case might be calculating the AF state halfway through the
1884 * pipeline; by sending the state back to the framework immediately, we get a
1885 * 50% performance increase and perceived responsiveness of the auto-focus.
1886 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001887 */
1888typedef struct camera3_capture_result {
1889 /**
1890 * The frame number is an incrementing integer set by the framework in the
1891 * submitted request to uniquely identify this capture. It is also used to
1892 * identify the request in asynchronous notifications sent to
1893 * camera3_callback_ops_t.notify().
1894 */
1895 uint32_t frame_number;
1896
1897 /**
1898 * The result metadata for this capture. This contains information about the
1899 * final capture parameters, the state of the capture and post-processing
1900 * hardware, the state of the 3A algorithms, if enabled, and the output of
1901 * any enabled statistics units.
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001902 *
1903 * Only one call to process_capture_result() with a given frame_number may
1904 * include the result metadata. All other calls for the same frame_number
1905 * must set this to NULL.
1906 *
1907 * If there was an error producing the result metadata, result must be an
1908 * empty metadata buffer, and notify() must be called with ERROR_RESULT.
Igor Murashkin5df2f622014-01-10 14:18:45 -08001909 *
1910 * >= CAMERA_DEVICE_API_VERSION_3_2:
1911 *
1912 * Multiple calls to process_capture_result() with a given frame_number
1913 * may include the result metadata.
1914 *
1915 * Partial metadata submitted should not include any metadata key returned
1916 * in a previous partial result for a given frame. Each new partial result
1917 * for that frame must also set a distinct partial_result value.
1918 *
1919 * If notify has been called with ERROR_RESULT, all further partial
1920 * results for that frame are ignored by the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001921 */
1922 const camera_metadata_t *result;
1923
1924 /**
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001925 * The number of output buffers returned in this result structure. Must be
1926 * less than or equal to the matching capture request's count. If this is
1927 * less than the buffer count in the capture request, at least one more call
1928 * to process_capture_result with the same frame_number must be made, to
1929 * return the remaining output buffers to the framework. This may only be
1930 * zero if the structure includes valid result metadata.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001931 */
1932 uint32_t num_output_buffers;
1933
1934 /**
1935 * The handles for the output stream buffers for this capture. They may not
1936 * yet be filled at the time the HAL calls process_capture_result(); the
1937 * framework will wait on the release sync fences provided by the HAL before
1938 * reading the buffers.
1939 *
1940 * The HAL must set the stream buffer's release sync fence to a valid sync
1941 * fd, or to -1 if the buffer has already been filled.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001942 *
1943 * If the HAL encounters an error while processing the buffer, and the
1944 * buffer is not filled, the buffer's status field must be set to
1945 * CAMERA3_BUFFER_STATUS_ERROR. If the HAL did not wait on the acquire fence
1946 * before encountering the error, the acquire fence should be copied into
1947 * the release fence, to allow the framework to wait on the fence before
1948 * reusing the buffer.
1949 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001950 * The acquire fence must be set to -1 for all output buffers. If
1951 * num_output_buffers is zero, this may be NULL. In that case, at least one
1952 * more process_capture_result call must be made by the HAL to provide the
1953 * output buffers.
Igor Murashkin5df2f622014-01-10 14:18:45 -08001954 *
1955 * When process_capture_result is called with a new buffer for a frame,
1956 * all previous frames' buffers for that corresponding stream must have been
1957 * already delivered (the fences need not have yet been signaled).
1958 *
1959 * >= CAMERA_DEVICE_API_VERSION_3_2:
1960 *
1961 * Gralloc buffers for a frame may be sent to framework before the
1962 * corresponding SHUTTER-notify.
1963 *
1964 * Performance considerations:
1965 *
1966 * Buffers delivered to the framework will not be dispatched to the
1967 * application layer until a start of exposure timestamp has been received
1968 * via a SHUTTER notify() call. It is highly recommended to
1969 * dispatch that call as early as possible.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001970 */
1971 const camera3_stream_buffer_t *output_buffers;
1972
Igor Murashkin5df2f622014-01-10 14:18:45 -08001973 /**
1974 * >= CAMERA_DEVICE_API_VERSION_3_2:
1975 *
Zhijun Heceac9e32014-02-05 20:49:45 -08001976 * The handle for the input stream buffer for this capture. It may not
1977 * yet be consumed at the time the HAL calls process_capture_result(); the
1978 * framework will wait on the release sync fences provided by the HAL before
1979 * reusing the buffer.
1980 *
1981 * The HAL should handle the sync fences the same way they are done for
1982 * output_buffers.
1983 *
1984 * Only one input buffer is allowed to be sent per request. Similarly to
1985 * output buffers, the ordering of returned input buffers must be
1986 * maintained by the HAL.
1987 *
1988 * Performance considerations:
1989 *
1990 * The input buffer should be returned as early as possible. If the HAL
1991 * supports sync fences, it can call process_capture_result to hand it back
1992 * with sync fences being set appropriately. If the sync fences are not
1993 * supported, the buffer can only be returned when it is consumed, which
1994 * may take long time; the HAL may choose to copy this input buffer to make
1995 * the buffer return sooner.
1996 */
1997 const camera3_stream_buffer_t *input_buffer;
1998
1999 /**
2000 * >= CAMERA_DEVICE_API_VERSION_3_2:
2001 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002002 * In order to take advantage of partial results, the HAL must set the
2003 * static metadata android.request.partialResultCount to the number of
2004 * partial results it will send for each frame.
2005 *
2006 * Each new capture result with a partial result must set
2007 * this field (partial_result) to a distinct inclusive value between
2008 * 1 and android.request.partialResultCount.
2009 *
2010 * HALs not wishing to take advantage of this feature must not
2011 * set an android.request.partialResultCount or partial_result to a value
2012 * other than 1.
2013 *
2014 * This value must be set to 0 when a capture result contains buffers only
2015 * and no metadata.
2016 */
2017 uint32_t partial_result;
2018
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002019} camera3_capture_result_t;
2020
2021/**********************************************************************
2022 *
2023 * Callback methods for the HAL to call into the framework.
2024 *
2025 * These methods are used to return metadata and image buffers for a completed
2026 * or failed captures, and to notify the framework of asynchronous events such
2027 * as errors.
2028 *
2029 * The framework will not call back into the HAL from within these callbacks,
2030 * and these calls will not block for extended periods.
2031 *
2032 */
2033typedef struct camera3_callback_ops {
2034
2035 /**
2036 * process_capture_result:
2037 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002038 * Send results from a completed capture to the framework.
2039 * process_capture_result() may be invoked multiple times by the HAL in
2040 * response to a single capture request. This allows, for example, the
2041 * metadata and low-resolution buffers to be returned in one call, and
2042 * post-processed JPEG buffers in a later call, once it is available. Each
2043 * call must include the frame number of the request it is returning
2044 * metadata or buffers for.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002045 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002046 * A component (buffer or metadata) of the complete result may only be
2047 * included in one process_capture_result call. A buffer for each stream,
2048 * and the result metadata, must be returned by the HAL for each request in
2049 * one of the process_capture_result calls, even in case of errors producing
2050 * some of the output. A call to process_capture_result() with neither
2051 * output buffers or result metadata is not allowed.
2052 *
2053 * The order of returning metadata and buffers for a single result does not
2054 * matter, but buffers for a given stream must be returned in FIFO order. So
2055 * the buffer for request 5 for stream A must always be returned before the
2056 * buffer for request 6 for stream A. This also applies to the result
2057 * metadata; the metadata for request 5 must be returned before the metadata
2058 * for request 6.
2059 *
2060 * However, different streams are independent of each other, so it is
2061 * acceptable and expected that the buffer for request 5 for stream A may be
2062 * returned after the buffer for request 6 for stream B is. And it is
2063 * acceptable that the result metadata for request 6 for stream B is
2064 * returned before the buffer for request 5 for stream A is.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002065 *
2066 * The HAL retains ownership of result structure, which only needs to be
2067 * valid to access during this call. The framework will copy whatever it
2068 * needs before this call returns.
2069 *
2070 * The output buffers do not need to be filled yet; the framework will wait
2071 * on the stream buffer release sync fence before reading the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002072 * data. Therefore, this method should be called by the HAL as soon as
2073 * possible, even if some or all of the output buffers are still in
2074 * being filled. The HAL must include valid release sync fences into each
2075 * output_buffers stream buffer entry, or -1 if that stream buffer is
2076 * already filled.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002077 *
2078 * If the result buffer cannot be constructed for a request, the HAL should
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002079 * return an empty metadata buffer, but still provide the output buffers and
2080 * their sync fences. In addition, notify() must be called with an
2081 * ERROR_RESULT message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002082 *
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08002083 * If an output buffer cannot be filled, its status field must be set to
2084 * STATUS_ERROR. In addition, notify() must be called with a ERROR_BUFFER
2085 * message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002086 *
2087 * If the entire capture has failed, then this method still needs to be
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08002088 * called to return the output buffers to the framework. All the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07002089 * statuses should be STATUS_ERROR, and the result metadata should be an
2090 * empty buffer. In addition, notify() must be called with a ERROR_REQUEST
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002091 * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
2092 * should not be sent.
2093 *
Zhijun He2dde4682014-01-09 09:11:49 -08002094 * Performance requirements:
2095 *
2096 * This is a non-blocking call. The framework will return this call in 5ms.
2097 *
2098 * The pipeline latency (see S7 for definition) should be less than or equal to
2099 * 4 frame intervals, and must be less than or equal to 8 frame intervals.
2100 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002101 */
2102 void (*process_capture_result)(const struct camera3_callback_ops *,
2103 const camera3_capture_result_t *result);
2104
2105 /**
2106 * notify:
2107 *
2108 * Asynchronous notification callback from the HAL, fired for various
2109 * reasons. Only for information independent of frame capture, or that
2110 * require specific timing. The ownership of the message structure remains
2111 * with the HAL, and the msg only needs to be valid for the duration of this
2112 * call.
2113 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002114 * Multiple threads may call notify() simultaneously.
2115 *
2116 * <= CAMERA_DEVICE_API_VERSION_3_1:
2117 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002118 * The notification for the start of exposure for a given request must be
2119 * sent by the HAL before the first call to process_capture_result() for
2120 * that request is made.
2121 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002122 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002123 *
Igor Murashkin5df2f622014-01-10 14:18:45 -08002124 * Buffers delivered to the framework will not be dispatched to the
2125 * application layer until a start of exposure timestamp has been received
2126 * via a SHUTTER notify() call. It is highly recommended to
2127 * dispatch this call as early as possible.
2128 *
2129 * ------------------------------------------------------------------------
Zhijun He2dde4682014-01-09 09:11:49 -08002130 * Performance requirements:
2131 *
2132 * This is a non-blocking call. The framework will return this call in 5ms.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002133 */
2134 void (*notify)(const struct camera3_callback_ops *,
2135 const camera3_notify_msg_t *msg);
2136
2137} camera3_callback_ops_t;
2138
2139/**********************************************************************
2140 *
2141 * Camera device operations
2142 *
2143 */
2144typedef struct camera3_device_ops {
2145
2146 /**
2147 * initialize:
2148 *
2149 * One-time initialization to pass framework callback function pointers to
2150 * the HAL. Will be called once after a successful open() call, before any
2151 * other functions are called on the camera3_device_ops structure.
2152 *
Zhijun He2dde4682014-01-09 09:11:49 -08002153 * Performance requirements:
2154 *
2155 * This should be a non-blocking call. The HAL should return from this call
2156 * in 5ms, and must return from this call in 10ms.
2157 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002158 * Return values:
2159 *
2160 * 0: On successful initialization
2161 *
2162 * -ENODEV: If initialization fails. Only close() can be called successfully
2163 * by the framework after this.
2164 */
2165 int (*initialize)(const struct camera3_device *,
2166 const camera3_callback_ops_t *callback_ops);
2167
2168 /**********************************************************************
2169 * Stream management
2170 */
2171
2172 /**
2173 * configure_streams:
2174 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002175 * CAMERA_DEVICE_API_VERSION_3_0 only:
2176 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002177 * Reset the HAL camera device processing pipeline and set up new input and
2178 * output streams. This call replaces any existing stream configuration with
2179 * the streams defined in the stream_list. This method will be called at
2180 * least once after initialize() before a request is submitted with
2181 * process_capture_request().
2182 *
2183 * The stream_list must contain at least one output-capable stream, and may
2184 * not contain more than one input-capable stream.
2185 *
2186 * The stream_list may contain streams that are also in the currently-active
2187 * set of streams (from the previous call to configure_stream()). These
2188 * streams will already have valid values for usage, max_buffers, and the
Igor Murashkin78aa1262014-01-09 16:23:43 -08002189 * private pointer.
2190 *
2191 * If such a stream has already had its buffers registered,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002192 * register_stream_buffers() will not be called again for the stream, and
2193 * buffers from the stream can be immediately included in input requests.
2194 *
2195 * If the HAL needs to change the stream configuration for an existing
2196 * stream due to the new configuration, it may rewrite the values of usage
Igor Murashkin78aa1262014-01-09 16:23:43 -08002197 * and/or max_buffers during the configure call.
2198 *
2199 * The framework will detect such a change, and will then reallocate the
2200 * stream buffers, and call register_stream_buffers() again before using
2201 * buffers from that stream in a request.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002202 *
2203 * If a currently-active stream is not included in stream_list, the HAL may
2204 * safely remove any references to that stream. It will not be reused in a
2205 * later configure() call by the framework, and all the gralloc buffers for
2206 * it will be freed after the configure_streams() call returns.
2207 *
2208 * The stream_list structure is owned by the framework, and may not be
2209 * accessed once this call completes. The address of an individual
2210 * camera3_stream_t structure will remain valid for access by the HAL until
2211 * the end of the first configure_stream() call which no longer includes
2212 * that camera3_stream_t in the stream_list argument. The HAL may not change
2213 * values in the stream structure outside of the private pointer, except for
2214 * the usage and max_buffers members during the configure_streams() call
2215 * itself.
2216 *
2217 * If the stream is new, the usage, max_buffer, and private pointer fields
2218 * of the stream structure will all be set to 0. The HAL device must set
2219 * these fields before the configure_streams() call returns. These fields
2220 * are then used by the framework and the platform gralloc module to
2221 * allocate the gralloc buffers for each stream.
2222 *
2223 * Before such a new stream can have its buffers included in a capture
2224 * request, the framework will call register_stream_buffers() with that
2225 * stream. However, the framework is not required to register buffers for
2226 * _all_ streams before submitting a request. This allows for quick startup
2227 * of (for example) a preview stream, with allocation for other streams
2228 * happening later or concurrently.
2229 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002230 * ------------------------------------------------------------------------
2231 * CAMERA_DEVICE_API_VERSION_3_1 only:
2232 *
2233 * Reset the HAL camera device processing pipeline and set up new input and
2234 * output streams. This call replaces any existing stream configuration with
2235 * the streams defined in the stream_list. This method will be called at
2236 * least once after initialize() before a request is submitted with
2237 * process_capture_request().
2238 *
2239 * The stream_list must contain at least one output-capable stream, and may
2240 * not contain more than one input-capable stream.
2241 *
2242 * The stream_list may contain streams that are also in the currently-active
2243 * set of streams (from the previous call to configure_stream()). These
2244 * streams will already have valid values for usage, max_buffers, and the
2245 * private pointer.
2246 *
2247 * If such a stream has already had its buffers registered,
2248 * register_stream_buffers() will not be called again for the stream, and
2249 * buffers from the stream can be immediately included in input requests.
2250 *
2251 * If the HAL needs to change the stream configuration for an existing
2252 * stream due to the new configuration, it may rewrite the values of usage
2253 * and/or max_buffers during the configure call.
2254 *
2255 * The framework will detect such a change, and will then reallocate the
2256 * stream buffers, and call register_stream_buffers() again before using
2257 * buffers from that stream in a request.
2258 *
2259 * If a currently-active stream is not included in stream_list, the HAL may
2260 * safely remove any references to that stream. It will not be reused in a
2261 * later configure() call by the framework, and all the gralloc buffers for
2262 * it will be freed after the configure_streams() call returns.
2263 *
2264 * The stream_list structure is owned by the framework, and may not be
2265 * accessed once this call completes. The address of an individual
2266 * camera3_stream_t structure will remain valid for access by the HAL until
2267 * the end of the first configure_stream() call which no longer includes
2268 * that camera3_stream_t in the stream_list argument. The HAL may not change
2269 * values in the stream structure outside of the private pointer, except for
2270 * the usage and max_buffers members during the configure_streams() call
2271 * itself.
2272 *
2273 * If the stream is new, max_buffer, and private pointer fields of the
2274 * stream structure will all be set to 0. The usage will be set to the
2275 * consumer usage flags. The HAL device must set these fields before the
2276 * configure_streams() call returns. These fields are then used by the
2277 * framework and the platform gralloc module to allocate the gralloc
2278 * buffers for each stream.
2279 *
2280 * Before such a new stream can have its buffers included in a capture
2281 * request, the framework will call register_stream_buffers() with that
2282 * stream. However, the framework is not required to register buffers for
2283 * _all_ streams before submitting a request. This allows for quick startup
2284 * of (for example) a preview stream, with allocation for other streams
2285 * happening later or concurrently.
2286 *
2287 * ------------------------------------------------------------------------
2288 * >= CAMERA_DEVICE_API_VERSION_3_2:
2289 *
2290 * Reset the HAL camera device processing pipeline and set up new input and
2291 * output streams. This call replaces any existing stream configuration with
2292 * the streams defined in the stream_list. This method will be called at
2293 * least once after initialize() before a request is submitted with
2294 * process_capture_request().
2295 *
2296 * The stream_list must contain at least one output-capable stream, and may
2297 * not contain more than one input-capable stream.
2298 *
2299 * The stream_list may contain streams that are also in the currently-active
2300 * set of streams (from the previous call to configure_stream()). These
2301 * streams will already have valid values for usage, max_buffers, and the
2302 * private pointer.
2303 *
2304 * If the HAL needs to change the stream configuration for an existing
2305 * stream due to the new configuration, it may rewrite the values of usage
2306 * and/or max_buffers during the configure call.
2307 *
2308 * The framework will detect such a change, and may then reallocate the
2309 * stream buffers before using buffers from that stream in a request.
2310 *
2311 * If a currently-active stream is not included in stream_list, the HAL may
2312 * safely remove any references to that stream. It will not be reused in a
2313 * later configure() call by the framework, and all the gralloc buffers for
2314 * it will be freed after the configure_streams() call returns.
2315 *
2316 * The stream_list structure is owned by the framework, and may not be
2317 * accessed once this call completes. The address of an individual
2318 * camera3_stream_t structure will remain valid for access by the HAL until
2319 * the end of the first configure_stream() call which no longer includes
2320 * that camera3_stream_t in the stream_list argument. The HAL may not change
2321 * values in the stream structure outside of the private pointer, except for
2322 * the usage and max_buffers members during the configure_streams() call
2323 * itself.
2324 *
2325 * If the stream is new, max_buffer, and private pointer fields of the
2326 * stream structure will all be set to 0. The usage will be set to the
2327 * consumer usage flags. The HAL device must set these fields before the
2328 * configure_streams() call returns. These fields are then used by the
2329 * framework and the platform gralloc module to allocate the gralloc
2330 * buffers for each stream.
2331 *
2332 * Newly allocated buffers may be included in a capture request at any time
2333 * by the framework. Once a gralloc buffer is returned to the framework
2334 * with process_capture_result (and its respective release_fence has been
2335 * signaled) the framework may free or reuse it at any time.
2336 *
2337 * ------------------------------------------------------------------------
2338 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002339 * Preconditions:
2340 *
2341 * The framework will only call this method when no captures are being
2342 * processed. That is, all results have been returned to the framework, and
2343 * all in-flight input and output buffers have been returned and their
2344 * release sync fences have been signaled by the HAL. The framework will not
2345 * submit new requests for capture while the configure_streams() call is
2346 * underway.
2347 *
2348 * Postconditions:
2349 *
2350 * The HAL device must configure itself to provide maximum possible output
2351 * frame rate given the sizes and formats of the output streams, as
2352 * documented in the camera device's static metadata.
2353 *
Zhijun He2dde4682014-01-09 09:11:49 -08002354 * Performance requirements:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002355 *
2356 * This call is expected to be heavyweight and possibly take several hundred
2357 * milliseconds to complete, since it may require resetting and
2358 * reconfiguring the image sensor and the camera processing pipeline.
2359 * Nevertheless, the HAL device should attempt to minimize the
2360 * reconfiguration delay to minimize the user-visible pauses during
2361 * application operational mode changes (such as switching from still
2362 * capture to video recording).
2363 *
Zhijun He2dde4682014-01-09 09:11:49 -08002364 * The HAL should return from this call in 500ms, and must return from this
2365 * call in 1000ms.
2366 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002367 * Return values:
2368 *
2369 * 0: On successful stream configuration
2370 *
2371 * -EINVAL: If the requested stream configuration is invalid. Some examples
2372 * of invalid stream configurations include:
2373 *
2374 * - Including more than 1 input-capable stream (INPUT or
2375 * BIDIRECTIONAL)
2376 *
2377 * - Not including any output-capable streams (OUTPUT or
2378 * BIDIRECTIONAL)
2379 *
2380 * - Including streams with unsupported formats, or an unsupported
2381 * size for that format.
2382 *
2383 * - Including too many output streams of a certain format.
2384 *
Eino-Ville Talvala7effe0c2013-02-15 12:09:48 -08002385 * Note that the framework submitting an invalid stream
2386 * configuration is not normal operation, since stream
2387 * configurations are checked before configure. An invalid
2388 * configuration means that a bug exists in the framework code, or
2389 * there is a mismatch between the HAL's static metadata and the
2390 * requirements on streams.
2391 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002392 * -ENODEV: If there has been a fatal error and the device is no longer
2393 * operational. Only close() can be called successfully by the
2394 * framework after this error is returned.
2395 */
2396 int (*configure_streams)(const struct camera3_device *,
2397 camera3_stream_configuration_t *stream_list);
2398
2399 /**
2400 * register_stream_buffers:
2401 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002402 * >= CAMERA_DEVICE_API_VERSION_3_2:
2403 *
2404 * DEPRECATED. This will not be called and must be set to NULL.
2405 *
2406 * <= CAMERA_DEVICE_API_VERSION_3_1:
2407 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002408 * Register buffers for a given stream with the HAL device. This method is
2409 * called by the framework after a new stream is defined by
2410 * configure_streams, and before buffers from that stream are included in a
2411 * capture request. If the same stream is listed in a subsequent
2412 * configure_streams() call, register_stream_buffers will _not_ be called
2413 * again for that stream.
2414 *
2415 * The framework does not need to register buffers for all configured
2416 * streams before it submits the first capture request. This allows quick
2417 * startup for preview (or similar use cases) while other streams are still
2418 * being allocated.
2419 *
2420 * This method is intended to allow the HAL device to map or otherwise
2421 * prepare the buffers for later use. The buffers passed in will already be
2422 * locked for use. At the end of the call, all the buffers must be ready to
2423 * be returned to the stream. The buffer_set argument is only valid for the
2424 * duration of this call.
2425 *
2426 * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
2427 * the camera HAL should inspect the passed-in buffers here to determine any
2428 * platform-private pixel format information.
2429 *
Zhijun He2dde4682014-01-09 09:11:49 -08002430 * Performance requirements:
2431 *
2432 * This should be a non-blocking call. The HAL should return from this call
2433 * in 1ms, and must return from this call in 5ms.
2434 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002435 * Return values:
2436 *
2437 * 0: On successful registration of the new stream buffers
2438 *
2439 * -EINVAL: If the stream_buffer_set does not refer to a valid active
2440 * stream, or if the buffers array is invalid.
2441 *
2442 * -ENOMEM: If there was a failure in registering the buffers. The framework
2443 * must consider all the stream buffers to be unregistered, and can
2444 * try to register again later.
2445 *
2446 * -ENODEV: If there is a fatal error, and the device is no longer
2447 * operational. Only close() can be called successfully by the
2448 * framework after this error is returned.
2449 */
2450 int (*register_stream_buffers)(const struct camera3_device *,
2451 const camera3_stream_buffer_set_t *buffer_set);
2452
2453 /**********************************************************************
2454 * Request creation and submission
2455 */
2456
2457 /**
2458 * construct_default_request_settings:
2459 *
2460 * Create capture settings for standard camera use cases.
2461 *
2462 * The device must return a settings buffer that is configured to meet the
2463 * requested use case, which must be one of the CAMERA3_TEMPLATE_*
2464 * enums. All request control fields must be included.
2465 *
2466 * The HAL retains ownership of this structure, but the pointer to the
2467 * structure must be valid until the device is closed. The framework and the
2468 * HAL may not modify the buffer once it is returned by this call. The same
2469 * buffer may be returned for subsequent calls for the same template, or for
2470 * other templates.
2471 *
Zhijun He2dde4682014-01-09 09:11:49 -08002472 * Performance requirements:
2473 *
2474 * This should be a non-blocking call. The HAL should return from this call
2475 * in 1ms, and must return from this call in 5ms.
2476 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002477 * Return values:
2478 *
2479 * Valid metadata: On successful creation of a default settings
2480 * buffer.
2481 *
2482 * NULL: In case of a fatal error. After this is returned, only
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002483 * the close() method can be called successfully by the
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002484 * framework.
2485 */
2486 const camera_metadata_t* (*construct_default_request_settings)(
2487 const struct camera3_device *,
2488 int type);
2489
2490 /**
2491 * process_capture_request:
2492 *
2493 * Send a new capture request to the HAL. The HAL should not return from
2494 * this call until it is ready to accept the next request to process. Only
2495 * one call to process_capture_request() will be made at a time by the
2496 * framework, and the calls will all be from the same thread. The next call
2497 * to process_capture_request() will be made as soon as a new request and
2498 * its associated buffers are available. In a normal preview scenario, this
2499 * means the function will be called again by the framework almost
2500 * instantly.
2501 *
2502 * The actual request processing is asynchronous, with the results of
2503 * capture being returned by the HAL through the process_capture_result()
2504 * call. This call requires the result metadata to be available, but output
2505 * buffers may simply provide sync fences to wait on. Multiple requests are
2506 * expected to be in flight at once, to maintain full output frame rate.
2507 *
2508 * The framework retains ownership of the request structure. It is only
2509 * guaranteed to be valid during this call. The HAL device must make copies
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002510 * of the information it needs to retain for the capture processing. The HAL
2511 * is responsible for waiting on and closing the buffers' fences and
2512 * returning the buffer handles to the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002513 *
2514 * The HAL must write the file descriptor for the input buffer's release
2515 * sync fence into input_buffer->release_fence, if input_buffer is not
2516 * NULL. If the HAL returns -1 for the input buffer release sync fence, the
2517 * framework is free to immediately reuse the input buffer. Otherwise, the
2518 * framework will wait on the sync fence before refilling and reusing the
2519 * input buffer.
2520 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002521 * >= CAMERA_DEVICE_API_VERSION_3_2:
Zhijun He2dde4682014-01-09 09:11:49 -08002522 *
Igor Murashkin78aa1262014-01-09 16:23:43 -08002523 * The input/output buffers provided by the framework in each request
2524 * may be brand new (having never before seen by the HAL).
2525 *
2526 * ------------------------------------------------------------------------
2527 * Performance considerations:
2528 *
2529 * Handling a new buffer should be extremely lightweight and there should be
2530 * no frame rate degradation or frame jitter introduced.
2531 *
2532 * This call must return fast enough to ensure that the requested frame
2533 * rate can be sustained, especially for streaming cases (post-processing
2534 * quality settings set to FAST). The HAL should return this call in 1
2535 * frame interval, and must return from this call in 4 frame intervals.
Zhijun He2dde4682014-01-09 09:11:49 -08002536 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002537 * Return values:
2538 *
2539 * 0: On a successful start to processing the capture request
2540 *
2541 * -EINVAL: If the input is malformed (the settings are NULL when not
2542 * allowed, there are 0 output buffers, etc) and capture processing
2543 * cannot start. Failures during request processing should be
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07002544 * handled by calling camera3_callback_ops_t.notify(). In case of
2545 * this error, the framework will retain responsibility for the
2546 * stream buffers' fences and the buffer handles; the HAL should
2547 * not close the fences or return these buffers with
2548 * process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002549 *
2550 * -ENODEV: If the camera device has encountered a serious error. After this
2551 * error is returned, only the close() method can be successfully
2552 * called by the framework.
2553 *
2554 */
2555 int (*process_capture_request)(const struct camera3_device *,
2556 camera3_capture_request_t *request);
2557
2558 /**********************************************************************
2559 * Miscellaneous methods
2560 */
2561
2562 /**
2563 * get_metadata_vendor_tag_ops:
2564 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002565 * Get methods to query for vendor extension metadata tag information. The
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002566 * HAL should fill in all the vendor tag operation methods, or leave ops
2567 * unchanged if no vendor tags are defined.
2568 *
2569 * The definition of vendor_tag_query_ops_t can be found in
2570 * system/media/camera/include/system/camera_metadata.h.
2571 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -08002572 * >= CAMERA_DEVICE_API_VERSION_3_2:
2573 * DEPRECATED. This function has been deprecated and should be set to
2574 * NULL by the HAL. Please implement get_vendor_tag_ops in camera_common.h
2575 * instead.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002576 */
2577 void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
2578 vendor_tag_query_ops_t* ops);
2579
2580 /**
2581 * dump:
2582 *
2583 * Print out debugging state for the camera device. This will be called by
2584 * the framework when the camera service is asked for a debug dump, which
2585 * happens when using the dumpsys tool, or when capturing a bugreport.
2586 *
2587 * The passed-in file descriptor can be used to write debugging text using
2588 * dprintf() or write(). The text should be in ASCII encoding only.
Zhijun He2dde4682014-01-09 09:11:49 -08002589 *
2590 * Performance requirements:
2591 *
2592 * This must be a non-blocking call. The HAL should return from this call
2593 * in 1ms, must return from this call in 10ms. This call must avoid
2594 * deadlocks, as it may be called at any point during camera operation.
2595 * Any synchronization primitives used (such as mutex locks or semaphores)
2596 * should be acquired with a timeout.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002597 */
2598 void (*dump)(const struct camera3_device *, int fd);
2599
Alex Ray5f2fd852013-06-24 11:28:05 -07002600 /**
2601 * flush:
2602 *
2603 * Flush all currently in-process captures and all buffers in the pipeline
2604 * on the given device. The framework will use this to dump all state as
2605 * quickly as possible in order to prepare for a configure_streams() call.
2606 *
2607 * No buffers are required to be successfully returned, so every buffer
Zhijun He5a5fbf42014-01-27 14:49:44 -08002608 * held at the time of flush() (whether successfully filled or not) may be
Alex Ray5f2fd852013-06-24 11:28:05 -07002609 * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed
Zhijun He5a5fbf42014-01-27 14:49:44 -08002610 * to return valid (CAMERA3_BUFFER_STATUS_OK) buffers during this call,
2611 * provided they are successfully filled.
Alex Ray5f2fd852013-06-24 11:28:05 -07002612 *
2613 * All requests currently in the HAL are expected to be returned as soon as
2614 * possible. Not-in-process requests should return errors immediately. Any
2615 * interruptible hardware blocks should be stopped, and any uninterruptible
2616 * blocks should be waited on.
2617 *
Zhijun He5a5fbf42014-01-27 14:49:44 -08002618 * More specifically, the HAL must follow below requirements for various cases:
2619 *
2620 * 1. For captures that are too late for the HAL to cancel/stop, and will be
2621 * completed normally by the HAL; i.e. the HAL can send shutter/notify and
2622 * process_capture_result and buffers as normal.
2623 *
2624 * 2. For pending requests that have not done any processing, the HAL must call notify
2625 * CAMERA3_MSG_ERROR_REQUEST, and return all the output buffers with
2626 * process_capture_result in the error state (CAMERA3_BUFFER_STATUS_ERROR).
2627 * The HAL must not place the release fence into an error state, instead,
2628 * the release fences must be set to the acquire fences passed by the framework,
2629 * or -1 if they have been waited on by the HAL already. This is also the path
2630 * to follow for any captures for which the HAL already called notify() with
2631 * CAMERA3_MSG_SHUTTER but won't be producing any metadata/valid buffers for.
2632 * After CAMERA3_MSG_ERROR_REQUEST, for a given frame, only process_capture_results with
2633 * buffers in CAMERA3_BUFFER_STATUS_ERROR are allowed. No further notifys or
2634 * process_capture_result with non-null metadata is allowed.
2635 *
2636 * 3. For partially completed pending requests that will not have all the output
2637 * buffers or perhaps missing metadata, the HAL should follow below:
2638 *
2639 * 3.1. Call notify with CAMERA3_MSG_ERROR_RESULT if some of the expected result
2640 * metadata (i.e. one or more partial metadata) won't be available for the capture.
2641 *
2642 * 3.2. Call notify with CAMERA3_MSG_ERROR_BUFFER for every buffer that won't
2643 * be produced for the capture.
2644 *
2645 * 3.3 Call notify with CAMERA3_MSG_SHUTTER with the capture timestamp before
2646 * any buffers/metadata are returned with process_capture_result.
2647 *
2648 * 3.4 For captures that will produce some results, the HAL must not call
2649 * CAMERA3_MSG_ERROR_REQUEST, since that indicates complete failure.
2650 *
2651 * 3.5. Valid buffers/metadata should be passed to the framework as normal.
2652 *
2653 * 3.6. Failed buffers should be returned to the framework as described for case 2.
2654 * But failed buffers do not have to follow the strict ordering valid buffers do,
2655 * and may be out-of-order with respect to valid buffers. For example, if buffers
2656 * A, B, C, D, E are sent, D and E are failed, then A, E, B, D, C is an acceptable
2657 * return order.
2658 *
2659 * 3.7. For fully-missing metadata, calling CAMERA3_MSG_ERROR_RESULT is sufficient, no
2660 * need to call process_capture_result with NULL metadata or equivalent.
2661 *
Alex Ray5f2fd852013-06-24 11:28:05 -07002662 * flush() should only return when there are no more outstanding buffers or
Zhijun He5a5fbf42014-01-27 14:49:44 -08002663 * requests left in the HAL. The framework may call configure_streams (as
Alex Ray5f2fd852013-06-24 11:28:05 -07002664 * the HAL state is now quiesced) or may issue new requests.
2665 *
Zhijun He5a5fbf42014-01-27 14:49:44 -08002666 * Note that it's sufficient to only support fully-succeeded and fully-failed result cases.
2667 * However, it is highly desirable to support the partial failure cases as well, as it
2668 * could help improve the flush call overall performance.
2669 *
Zhijun He2dde4682014-01-09 09:11:49 -08002670 * Performance requirements:
2671 *
2672 * The HAL should return from this call in 100ms, and must return from this
2673 * call in 1000ms. And this call must not be blocked longer than pipeline
2674 * latency (see S7 for definition).
Alex Ray5f2fd852013-06-24 11:28:05 -07002675 *
2676 * Version information:
2677 *
2678 * only available if device version >= CAMERA_DEVICE_API_VERSION_3_1.
2679 *
2680 * Return values:
2681 *
2682 * 0: On a successful flush of the camera HAL.
2683 *
2684 * -EINVAL: If the input is malformed (the device is not valid).
2685 *
2686 * -ENODEV: If the camera device has encountered a serious error. After this
2687 * error is returned, only the close() method can be successfully
2688 * called by the framework.
2689 */
2690 int (*flush)(const struct camera3_device *);
2691
2692 /* reserved for future use */
2693 void *reserved[8];
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002694} camera3_device_ops_t;
2695
2696/**********************************************************************
2697 *
2698 * Camera device definition
2699 *
2700 */
2701typedef struct camera3_device {
2702 /**
2703 * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
2704 * device as implementing version 3.0 of the camera device HAL.
Zhijun He2dde4682014-01-09 09:11:49 -08002705 *
2706 * Performance requirements:
2707 *
Zhijun He2020ee22014-01-31 11:35:45 -08002708 * Camera open (common.methods->open) should return in 200ms, and must return in 500ms.
2709 * Camera close (common.close) should return in 200ms, and must return in 500ms.
2710 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002711 */
2712 hw_device_t common;
2713 camera3_device_ops_t *ops;
2714 void *priv;
2715} camera3_device_t;
2716
2717__END_DECLS
2718
2719#endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */