blob: af918562ffe7cde2b42d8f35c1ec5820405273b7 [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/**
24 * Camera device HAL 3.0 [ CAMERA_DEVICE_API_VERSION_3_0 ]
25 *
26 * EXPERIMENTAL.
27 *
28 * Supports the android.hardware.Camera API.
29 *
30 * Camera devices that support this version of the HAL must return
31 * CAMERA_DEVICE_API_VERSION_3_0 in camera_device_t.common.version and in
32 * camera_info_t.device_version (from camera_module_t.get_camera_info).
33 *
34 * Camera modules that may contain version 3.0 devices must implement at least
35 * version 2.0 of the camera module interface (as defined by
36 * camera_module_t.common.module_api_version).
37 *
38 * See camera_common.h for more versioning details.
39 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070040 * Documentation index:
41 * S1. Version history
42 * S2. Startup and operation sequencing
43 * S3. Operational modes
44 * S4. 3A modes and state machines
Eino-Ville Talvalab6059442013-04-29 15:26:16 -070045 * S5. Cropping
46 * S6. Error management
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070047 */
48
49/**
50 * S1. Version history:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080051 *
52 * 1.0: Initial Android camera HAL (Android 4.0) [camera.h]:
53 *
54 * - Converted from C++ CameraHardwareInterface abstraction layer.
55 *
56 * - Supports android.hardware.Camera API.
57 *
58 * 2.0: Initial release of expanded-capability HAL (Android 4.2) [camera2.h]:
59 *
60 * - Sufficient for implementing existing android.hardware.Camera API.
61 *
62 * - Allows for ZSL queue in camera service layer
63 *
64 * - Not tested for any new features such manual capture control, Bayer RAW
65 * capture, reprocessing of RAW data.
66 *
67 * 3.0: First revision of expanded-capability HAL:
68 *
69 * - Major version change since the ABI is completely different. No change to
70 * the required hardware capabilities or operational model from 2.0.
71 *
72 * - Reworked input request and stream queue interfaces: Framework calls into
73 * HAL with next request and stream buffers already dequeued. Sync framework
74 * support is included, necessary for efficient implementations.
75 *
76 * - Moved triggers into requests, most notifications into results.
77 *
78 * - Consolidated all callbacks into framework into one structure, and all
79 * setup methods into a single initialize() call.
80 *
81 * - Made stream configuration into a single call to simplify stream
82 * management. Bidirectional streams replace STREAM_FROM_STREAM construct.
83 *
84 * - Limited mode semantics for older/limited hardware devices.
85 */
86
87/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -070088 * S2. Startup and general expected operation sequence:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080089 *
90 * 1. Framework calls camera_module_t->common.open(), which returns a
91 * hardware_device_t structure.
92 *
93 * 2. Framework inspects the hardware_device_t->version field, and instantiates
94 * the appropriate handler for that version of the camera hardware device. In
95 * case the version is CAMERA_DEVICE_API_VERSION_3_0, the device is cast to
96 * a camera3_device_t.
97 *
98 * 3. Framework calls camera3_device_t->ops->initialize() with the framework
99 * callback function pointers. This will only be called this one time after
100 * open(), before any other functions in the ops structure are called.
101 *
102 * 4. The framework calls camera3_device_t->ops->configure_streams() with a list
103 * of input/output streams to the HAL device.
104 *
105 * 5. The framework allocates gralloc buffers and calls
106 * camera3_device_t->ops->register_stream_buffers() for at least one of the
107 * output streams listed in configure_streams. The same stream is registered
108 * only once.
109 *
110 * 5. The framework requests default settings for some number of use cases with
111 * calls to camera3_device_t->ops->construct_default_request_settings(). This
112 * may occur any time after step 3.
113 *
114 * 7. The framework constructs and sends the first capture request to the HAL,
115 * with settings based on one of the sets of default settings, and with at
116 * least one output stream, which has been registered earlier by the
117 * framework. This is sent to the HAL with
118 * camera3_device_t->ops->process_capture_request(). The HAL must block the
119 * return of this call until it is ready for the next request to be sent.
120 *
121 * 8. The framework continues to submit requests, and possibly call
122 * register_stream_buffers() for not-yet-registered streams, and call
123 * construct_default_request_settings to get default settings buffers for
124 * other use cases.
125 *
126 * 9. When the capture of a request begins (sensor starts exposing for the
127 * capture), the HAL calls camera3_callback_ops_t->notify() with the SHUTTER
128 * event, including the frame number and the timestamp for start of exposure.
Eino-Ville Talvala71af1022013-04-22 14:19:21 -0700129 * This notify call must be made before the first call to
130 * process_capture_result() for that frame number.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800131 *
132 * 10. After some pipeline delay, the HAL begins to return completed captures to
133 * the framework with camera3_callback_ops_t->process_capture_result(). These
134 * are returned in the same order as the requests were submitted. Multiple
135 * requests can be in flight at once, depending on the pipeline depth of the
136 * camera HAL device.
137 *
138 * 11. After some time, the framework may stop submitting new requests, wait for
139 * the existing captures to complete (all buffers filled, all results
140 * returned), and then call configure_streams() again. This resets the camera
141 * hardware and pipeline for a new set of input/output streams. Some streams
142 * may be reused from the previous configuration; if these streams' buffers
143 * had already been registered with the HAL, they will not be registered
144 * again. The framework then continues from step 7, if at least one
145 * registered output stream remains (otherwise, step 5 is required first).
146 *
147 * 12. Alternatively, the framework may call camera3_device_t->common->close()
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -0800148 * to end the camera session. This may be called at any time when no other
149 * calls from the framework are active, although the call may block until all
150 * in-flight captures have completed (all results returned, all buffers
151 * filled). After the close call returns, no more calls to the
152 * camera3_callback_ops_t functions are allowed from the HAL. Once the
153 * close() call is underway, the framework may not call any other HAL device
154 * functions.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800155 *
156 * 13. In case of an error or other asynchronous event, the HAL must call
157 * camera3_callback_ops_t->notify() with the appropriate error/event
158 * message. After returning from a fatal device-wide error notification, the
159 * HAL should act as if close() had been called on it. However, the HAL must
160 * either cancel or complete all outstanding captures before calling
161 * notify(), so that once notify() is called with a fatal error, the
162 * framework will not receive further callbacks from the device. Methods
163 * besides close() should return -ENODEV or NULL after the notify() method
164 * returns from a fatal error message.
165 */
166
167/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700168 * S3. Operational modes:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800169 *
170 * The camera 3 HAL device can implement one of two possible operational modes;
171 * limited and full. Full support is expected from new higher-end
172 * devices. Limited mode has hardware requirements roughly in line with those
173 * for a camera HAL device v1 implementation, and is expected from older or
174 * inexpensive devices. Full is a strict superset of limited, and they share the
175 * same essential operational flow, as documented above.
176 *
177 * The HAL must indicate its level of support with the
178 * android.info.supportedHardwareLevel static metadata entry, with 0 indicating
179 * limited mode, and 1 indicating full mode support.
180 *
181 * Roughly speaking, limited-mode devices do not allow for application control
182 * of capture settings (3A control only), high-rate capture of high-resolution
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700183 * images, raw sensor readout, or support for YUV output streams above maximum
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800184 * recording resolution (JPEG only for large images).
185 *
186 * ** Details of limited mode behavior:
187 *
188 * - Limited-mode devices do not need to implement accurate synchronization
189 * between capture request settings and the actual image data
190 * captured. Instead, changes to settings may take effect some time in the
191 * future, and possibly not for the same output frame for each settings
192 * entry. Rapid changes in settings may result in some settings never being
193 * used for a capture. However, captures that include high-resolution output
194 * buffers ( > 1080p ) have to use the settings as specified (but see below
195 * for processing rate).
196 *
197 * - Limited-mode devices do not need to support most of the
198 * settings/result/static info metadata. Full-mode devices must support all
199 * metadata fields listed in TODO. Specifically, only the following settings
200 * are expected to be consumed or produced by a limited-mode HAL device:
201 *
202 * android.control.aeAntibandingMode (controls)
203 * android.control.aeExposureCompensation (controls)
204 * android.control.aeLock (controls)
205 * android.control.aeMode (controls)
206 * [OFF means ON_FLASH_TORCH - TODO]
207 * android.control.aeRegions (controls)
208 * android.control.aeTargetFpsRange (controls)
209 * android.control.afMode (controls)
210 * [OFF means infinity focus]
211 * android.control.afRegions (controls)
212 * android.control.awbLock (controls)
213 * android.control.awbMode (controls)
214 * [OFF not supported]
215 * android.control.awbRegions (controls)
216 * android.control.captureIntent (controls)
217 * android.control.effectMode (controls)
218 * android.control.mode (controls)
219 * [OFF not supported]
220 * android.control.sceneMode (controls)
221 * android.control.videoStabilizationMode (controls)
222 * android.control.aeAvailableAntibandingModes (static)
223 * android.control.aeAvailableModes (static)
224 * android.control.aeAvailableTargetFpsRanges (static)
225 * android.control.aeCompensationRange (static)
226 * android.control.aeCompensationStep (static)
227 * android.control.afAvailableModes (static)
228 * android.control.availableEffects (static)
229 * android.control.availableSceneModes (static)
230 * android.control.availableVideoStabilizationModes (static)
231 * android.control.awbAvailableModes (static)
232 * android.control.maxRegions (static)
233 * android.control.sceneModeOverrides (static)
234 * android.control.aeRegions (dynamic)
235 * android.control.aeState (dynamic)
236 * android.control.afMode (dynamic)
237 * android.control.afRegions (dynamic)
238 * android.control.afState (dynamic)
239 * android.control.awbMode (dynamic)
240 * android.control.awbRegions (dynamic)
241 * android.control.awbState (dynamic)
242 * android.control.mode (dynamic)
243 *
244 * android.flash.info.available (static)
245 *
246 * android.info.supportedHardwareLevel (static)
247 *
248 * android.jpeg.gpsCoordinates (controls)
249 * android.jpeg.gpsProcessingMethod (controls)
250 * android.jpeg.gpsTimestamp (controls)
251 * android.jpeg.orientation (controls)
252 * android.jpeg.quality (controls)
253 * android.jpeg.thumbnailQuality (controls)
254 * android.jpeg.thumbnailSize (controls)
255 * android.jpeg.availableThumbnailSizes (static)
256 * android.jpeg.maxSize (static)
257 * android.jpeg.gpsCoordinates (dynamic)
258 * android.jpeg.gpsProcessingMethod (dynamic)
259 * android.jpeg.gpsTimestamp (dynamic)
260 * android.jpeg.orientation (dynamic)
261 * android.jpeg.quality (dynamic)
262 * android.jpeg.size (dynamic)
263 * android.jpeg.thumbnailQuality (dynamic)
264 * android.jpeg.thumbnailSize (dynamic)
265 *
266 * android.lens.info.minimumFocusDistance (static)
267 *
268 * android.request.id (controls)
269 * android.request.id (dynamic)
270 *
271 * android.scaler.cropRegion (controls)
272 * [ignores (x,y), assumes center-zoom]
273 * android.scaler.availableFormats (static)
274 * [RAW not supported]
275 * android.scaler.availableJpegMinDurations (static)
276 * android.scaler.availableJpegSizes (static)
277 * android.scaler.availableMaxDigitalZoom (static)
278 * android.scaler.availableProcessedMinDurations (static)
279 * android.scaler.availableProcessedSizes (static)
280 * [full resolution not supported]
281 * android.scaler.maxDigitalZoom (static)
282 * android.scaler.cropRegion (dynamic)
283 *
284 * android.sensor.orientation (static)
285 * android.sensor.timestamp (dynamic)
286 *
287 * android.statistics.faceDetectMode (controls)
288 * android.statistics.info.availableFaceDetectModes (static)
289 * android.statistics.faceDetectMode (dynamic)
290 * android.statistics.faceIds (dynamic)
291 * android.statistics.faceLandmarks (dynamic)
292 * android.statistics.faceRectangles (dynamic)
293 * android.statistics.faceScores (dynamic)
294 *
295 * - Captures in limited mode that include high-resolution (> 1080p) output
296 * buffers may block in process_capture_request() until all the output buffers
297 * have been filled. A full-mode HAL device must process sequences of
298 * high-resolution requests at the rate indicated in the static metadata for
299 * that pixel format. The HAL must still call process_capture_result() to
300 * provide the output; the framework must simply be prepared for
301 * process_capture_request() to block until after process_capture_result() for
302 * that request completes for high-resolution captures for limited-mode
303 * devices.
304 *
305 */
306
307/**
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700308 * S4. 3A modes and state machines:
309 *
310 * While the actual 3A algorithms are up to the HAL implementation, a high-level
311 * state machine description is defined by the HAL interface, to allow the HAL
312 * device and the framework to communicate about the current state of 3A, and to
313 * trigger 3A events.
314 *
315 * When the device is opened, all the individual 3A states must be
316 * STATE_INACTIVE. Stream configuration does not reset 3A. For example, locked
317 * focus must be maintained across the configure() call.
318 *
319 * Triggering a 3A action involves simply setting the relevant trigger entry in
320 * the settings for the next request to indicate start of trigger. For example,
321 * the trigger for starting an autofocus scan is setting the entry
322 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTROL_AF_TRIGGER_START for one
323 * request, and cancelling an autofocus scan is triggered by setting
324 * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTRL_AF_TRIGGER_CANCEL. Otherwise,
325 * the entry will not exist, or be set to ANDROID_CONTROL_AF_TRIGGER_IDLE. Each
326 * request with a trigger entry set to a non-IDLE value will be treated as an
327 * independent triggering event.
328 *
329 * At the top level, 3A is controlled by the ANDROID_CONTROL_MODE setting, which
330 * selects between no 3A (ANDROID_CONTROL_MODE_OFF), normal AUTO mode
331 * (ANDROID_CONTROL_MODE_AUTO), and using the scene mode setting
332 * (ANDROID_CONTROL_USE_SCENE_MODE).
333 *
334 * - In OFF mode, each of the individual AE/AF/AWB modes are effectively OFF,
335 * and none of the capture controls may be overridden by the 3A routines.
336 *
337 * - In AUTO mode, Auto-focus, auto-exposure, and auto-whitebalance all run
338 * their own independent algorithms, and have their own mode, state, and
339 * trigger metadata entries, as listed in the next section.
340 *
341 * - In USE_SCENE_MODE, the value of the ANDROID_CONTROL_SCENE_MODE entry must
342 * be used to determine the behavior of 3A routines. In SCENE_MODEs other than
343 * FACE_PRIORITY, the HAL must override the values of
344 * ANDROId_CONTROL_AE/AWB/AF_MODE to be the mode it prefers for the selected
345 * SCENE_MODE. For example, the HAL may prefer SCENE_MODE_NIGHT to use
346 * CONTINUOUS_FOCUS AF mode. Any user selection of AE/AWB/AF_MODE when scene
347 * must be ignored for these scene modes.
348 *
349 * - For SCENE_MODE_FACE_PRIORITY, the AE/AWB/AF_MODE controls work as in
350 * ANDROID_CONTROL_MODE_AUTO, but the 3A routines must bias toward metering
351 * and focusing on any detected faces in the scene.
352 *
353 * S4.1. Auto-focus settings and result entries:
354 *
355 * Main metadata entries:
356 *
357 * ANDROID_CONTROL_AF_MODE: Control for selecting the current autofocus
358 * mode. Set by the framework in the request settings.
359 *
360 * AF_MODE_OFF: AF is disabled; the framework/app directly controls lens
361 * position.
362 *
363 * AF_MODE_AUTO: Single-sweep autofocus. No lens movement unless AF is
364 * triggered.
365 *
366 * AF_MODE_MACRO: Single-sweep up-close autofocus. No lens movement unless
367 * AF is triggered.
368 *
369 * AF_MODE_CONTINUOUS_VIDEO: Smooth continuous focusing, for recording
370 * video. Triggering immediately locks focus in current
371 * position. Canceling resumes cotinuous focusing.
372 *
373 * AF_MODE_CONTINUOUS_PICTURE: Fast continuous focusing, for
374 * zero-shutter-lag still capture. Triggering locks focus once currently
375 * active sweep concludes. Canceling resumes continuous focusing.
376 *
377 * AF_MODE_EDOF: Advanced extended depth of field focusing. There is no
378 * autofocus scan, so triggering one or canceling one has no effect.
379 * Images are focused automatically by the HAL.
380 *
381 * ANDROID_CONTROL_AF_STATE: Dynamic metadata describing the current AF
382 * algorithm state, reported by the HAL in the result metadata.
383 *
384 * AF_STATE_INACTIVE: No focusing has been done, or algorithm was
385 * reset. Lens is not moving. Always the state for MODE_OFF or MODE_EDOF.
386 * When the device is opened, it must start in this state.
387 *
388 * AF_STATE_PASSIVE_SCAN: A continuous focus algorithm is currently scanning
389 * for good focus. The lens is moving.
390 *
391 * AF_STATE_PASSIVE_FOCUSED: A continuous focus algorithm believes it is
392 * well focused. The lens is not moving. The HAL may spontaneously leave
393 * this state.
394 *
395 * AF_STATE_ACTIVE_SCAN: A scan triggered by the user is underway.
396 *
397 * AF_STATE_FOCUSED_LOCKED: The AF algorithm believes it is focused. The
398 * lens is not moving.
399 *
400 * AF_STATE_NOT_FOCUSED_LOCKED: The AF algorithm has been unable to
401 * focus. The lens is not moving.
402 *
403 * ANDROID_CONTROL_AF_TRIGGER: Control for starting an autofocus scan, the
404 * meaning of which is mode- and state- dependent. Set by the framework in
405 * the request settings.
406 *
407 * AF_TRIGGER_IDLE: No current trigger.
408 *
409 * AF_TRIGGER_START: Trigger start of AF scan. Effect is mode and state
410 * dependent.
411 *
412 * AF_TRIGGER_CANCEL: Cancel current AF scan if any, and reset algorithm to
413 * default.
414 *
415 * Additional metadata entries:
416 *
417 * ANDROID_CONTROL_AF_REGIONS: Control for selecting the regions of the FOV
418 * that should be used to determine good focus. This applies to all AF
419 * modes that scan for focus. Set by the framework in the request
420 * settings.
421 *
422 * S4.2. Auto-exposure settings and result entries:
423 *
424 * Main metadata entries:
425 *
426 * ANDROID_CONTROL_AE_MODE: Control for selecting the current auto-exposure
427 * mode. Set by the framework in the request settings.
428 *
429 * AE_MODE_OFF: Autoexposure is disabled; the user controls exposure, gain,
430 * frame duration, and flash.
431 *
432 * AE_MODE_ON: Standard autoexposure, with flash control disabled. User may
433 * set flash to fire or to torch mode.
434 *
435 * AE_MODE_ON_AUTO_FLASH: Standard autoexposure, with flash on at HAL's
436 * discretion for precapture and still capture. User control of flash
437 * disabled.
438 *
439 * AE_MODE_ON_ALWAYS_FLASH: Standard autoexposure, with flash always fired
440 * for capture, and at HAL's discretion for precapture.. User control of
441 * flash disabled.
442 *
443 * AE_MODE_ON_AUTO_FLASH_REDEYE: Standard autoexposure, with flash on at
444 * HAL's discretion for precapture and still capture. Use a flash burst
445 * at end of precapture sequence to reduce redeye in the final
446 * picture. User control of flash disabled.
447 *
448 * ANDROID_CONTROL_AE_STATE: Dynamic metadata describing the current AE
449 * algorithm state, reported by the HAL in the result metadata.
450 *
451 * AE_STATE_INACTIVE: Initial AE state after mode switch. When the device is
452 * opened, it must start in this state.
453 *
454 * AE_STATE_SEARCHING: AE is not converged to a good value, and is adjusting
455 * exposure parameters.
456 *
457 * AE_STATE_CONVERGED: AE has found good exposure values for the current
458 * scene, and the exposure parameters are not changing. HAL may
459 * spontaneously leave this state to search for better solution.
460 *
461 * AE_STATE_LOCKED: AE has been locked with the AE_LOCK control. Exposure
462 * values are not changing.
463 *
464 * AE_STATE_FLASH_REQUIRED: The HAL has converged exposure, but believes
465 * flash is required for a sufficiently bright picture. Used for
466 * determining if a zero-shutter-lag frame can be used.
467 *
468 * AE_STATE_PRECAPTURE: The HAL is in the middle of a precapture
469 * sequence. Depending on AE mode, this mode may involve firing the
470 * flash for metering, or a burst of flash pulses for redeye reduction.
471 *
472 * ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER: Control for starting a metering
473 * sequence before capturing a high-quality image. Set by the framework in
474 * the request settings.
475 *
476 * PRECAPTURE_TRIGGER_IDLE: No current trigger.
477 *
478 * PRECAPTURE_TRIGGER_START: Start a precapture sequence. The HAL should
479 * use the subsequent requests to measure good exposure/white balance
480 * for an upcoming high-resolution capture.
481 *
482 * Additional metadata entries:
483 *
484 * ANDROID_CONTROL_AE_LOCK: Control for locking AE controls to their current
485 * values
486 *
487 * ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION: Control for adjusting AE
488 * algorithm target brightness point.
489 *
490 * ANDROID_CONTROL_AE_TARGET_FPS_RANGE: Control for selecting the target frame
491 * rate range for the AE algorithm. The AE routine cannot change the frame
492 * rate to be outside these bounds.
493 *
494 * ANDROID_CONTROL_AE_REGIONS: Control for selecting the regions of the FOV
495 * that should be used to determine good exposure levels. This applies to
496 * all AE modes besides OFF.
497 *
498 * S4.3. Auto-whitebalance settings and result entries:
499 *
500 * Main metadata entries:
501 *
502 * ANDROID_CONTROL_AWB_MODE: Control for selecting the current white-balance
503 * mode.
504 *
505 * AWB_MODE_OFF: Auto-whitebalance is disabled. User controls color matrix.
506 *
507 * AWB_MODE_AUTO: Automatic white balance is enabled; 3A controls color
508 * transform, possibly using more complex transforms than a simple
509 * matrix.
510 *
511 * AWB_MODE_INCANDESCENT: Fixed white balance settings good for indoor
512 * incandescent (tungsten) lighting, roughly 2700K.
513 *
514 * AWB_MODE_FLUORESCENT: Fixed white balance settings good for fluorescent
515 * lighting, roughly 5000K.
516 *
517 * AWB_MODE_WARM_FLUORESCENT: Fixed white balance settings good for
518 * fluorescent lighting, roughly 3000K.
519 *
520 * AWB_MODE_DAYLIGHT: Fixed white balance settings good for daylight,
521 * roughly 5500K.
522 *
523 * AWB_MODE_CLOUDY_DAYLIGHT: Fixed white balance settings good for clouded
524 * daylight, roughly 6500K.
525 *
526 * AWB_MODE_TWILIGHT: Fixed white balance settings good for
527 * near-sunset/sunrise, roughly 15000K.
528 *
529 * AWB_MODE_SHADE: Fixed white balance settings good for areas indirectly
530 * lit by the sun, roughly 7500K.
531 *
532 * ANDROID_CONTROL_AWB_STATE: Dynamic metadata describing the current AWB
533 * algorithm state, reported by the HAL in the result metadata.
534 *
535 * AWB_STATE_INACTIVE: Initial AWB state after mode switch. When the device
536 * is opened, it must start in this state.
537 *
538 * AWB_STATE_SEARCHING: AWB is not converged to a good value, and is
539 * changing color adjustment parameters.
540 *
541 * AWB_STATE_CONVERGED: AWB has found good color adjustment values for the
542 * current scene, and the parameters are not changing. HAL may
543 * spontaneously leave this state to search for better solution.
544 *
545 * AWB_STATE_LOCKED: AWB has been locked with the AWB_LOCK control. Color
546 * adjustment values are not changing.
547 *
548 * Additional metadata entries:
549 *
550 * ANDROID_CONTROL_AWB_LOCK: Control for locking AWB color adjustments to
551 * their current values.
552 *
553 * ANDROID_CONTROL_AWB_REGIONS: Control for selecting the regions of the FOV
554 * that should be used to determine good color balance. This applies only
555 * to auto-WB mode.
556 *
557 * S4.4. General state machine transition notes
558 *
559 * Switching between AF, AE, or AWB modes always resets the algorithm's state
560 * to INACTIVE. Similarly, switching between CONTROL_MODE or
561 * CONTROL_SCENE_MODE if CONTROL_MODE == USE_SCENE_MODE resets all the
562 * algorithm states to INACTIVE.
563 *
564 * The tables below are per-mode.
565 *
566 * S4.5. AF state machines
567 *
568 * mode = AF_MODE_OFF or AF_MODE_EDOF
569 *| state | trans. cause | new state | notes |
570 *+--------------------+---------------+--------------------+------------------+
571 *| INACTIVE | | | AF is disabled |
572 *+--------------------+---------------+--------------------+------------------+
573 *
574 * mode = AF_MODE_AUTO or AF_MODE_MACRO
575 *| state | trans. cause | new state | notes |
576 *+--------------------+---------------+--------------------+------------------+
577 *| INACTIVE | AF_TRIGGER | ACTIVE_SCAN | Start AF sweep |
578 *| | | | Lens now moving |
579 *+--------------------+---------------+--------------------+------------------+
580 *| ACTIVE_SCAN | AF sweep done | FOCUSED_LOCKED | If AF successful |
581 *| | | | Lens now locked |
582 *+--------------------+---------------+--------------------+------------------+
583 *| ACTIVE_SCAN | AF sweep done | NOT_FOCUSED_LOCKED | If AF successful |
584 *| | | | Lens now locked |
585 *+--------------------+---------------+--------------------+------------------+
586 *| ACTIVE_SCAN | AF_CANCEL | INACTIVE | Cancel/reset AF |
587 *| | | | Lens now locked |
588 *+--------------------+---------------+--------------------+------------------+
589 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
590 *+--------------------+---------------+--------------------+------------------+
591 *| FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
592 *| | | | Lens now moving |
593 *+--------------------+---------------+--------------------+------------------+
594 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
595 *+--------------------+---------------+--------------------+------------------+
596 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
597 *| | | | Lens now moving |
598 *+--------------------+---------------+--------------------+------------------+
599 *| All states | mode change | INACTIVE | |
600 *+--------------------+---------------+--------------------+------------------+
601 *
602 * mode = AF_MODE_CONTINUOUS_VIDEO
603 *| state | trans. cause | new state | notes |
604 *+--------------------+---------------+--------------------+------------------+
605 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
606 *| | new scan | | Lens now moving |
607 *+--------------------+---------------+--------------------+------------------+
608 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
609 *| | | | Lens now locked |
610 *+--------------------+---------------+--------------------+------------------+
611 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
612 *| | current scan | | Lens now locked |
613 *+--------------------+---------------+--------------------+------------------+
614 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
615 *| | | | if focus is good |
616 *| | | | Lens now locked |
617 *+--------------------+---------------+--------------------+------------------+
618 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
619 *| | | | if focus is bad |
620 *| | | | Lens now locked |
621 *+--------------------+---------------+--------------------+------------------+
622 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
623 *| | | | position |
624 *| | | | Lens now locked |
625 *+--------------------+---------------+--------------------+------------------+
626 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
627 *| | new scan | | Lens now moving |
628 *+--------------------+---------------+--------------------+------------------+
629 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
630 *| | | | if focus is good |
631 *| | | | Lens now locked |
632 *+--------------------+---------------+--------------------+------------------+
633 *| PASSIVE_FOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
634 *| | | | if focus is bad |
635 *| | | | Lens now locked |
636 *+--------------------+---------------+--------------------+------------------+
637 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
638 *+--------------------+---------------+--------------------+------------------+
639 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
640 *+--------------------+---------------+--------------------+------------------+
641 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
642 *+--------------------+---------------+--------------------+------------------+
643 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
644 *+--------------------+---------------+--------------------+------------------+
645 *
646 * mode = AF_MODE_CONTINUOUS_PICTURE
647 *| state | trans. cause | new state | notes |
648 *+--------------------+---------------+--------------------+------------------+
649 *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
650 *| | new scan | | Lens now moving |
651 *+--------------------+---------------+--------------------+------------------+
652 *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
653 *| | | | Lens now locked |
654 *+--------------------+---------------+--------------------+------------------+
655 *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
656 *| | current scan | | Lens now locked |
657 *+--------------------+---------------+--------------------+------------------+
658 *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Eventual trans. |
659 *| | | | once focus good |
660 *| | | | Lens now locked |
661 *+--------------------+---------------+--------------------+------------------+
662 *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Eventual trans. |
663 *| | | | if cannot focus |
664 *| | | | Lens now locked |
665 *+--------------------+---------------+--------------------+------------------+
666 *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
667 *| | | | position |
668 *| | | | Lens now locked |
669 *+--------------------+---------------+--------------------+------------------+
670 *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
671 *| | new scan | | Lens now moving |
672 *+--------------------+---------------+--------------------+------------------+
673 *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
674 *| | | | if focus is good |
675 *| | | | Lens now locked |
676 *+--------------------+---------------+--------------------+------------------+
677 *| PASSIVE_FOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
678 *| | | | if focus is bad |
679 *| | | | Lens now locked |
680 *+--------------------+---------------+--------------------+------------------+
681 *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
682 *+--------------------+---------------+--------------------+------------------+
683 *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
684 *+--------------------+---------------+--------------------+------------------+
685 *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
686 *+--------------------+---------------+--------------------+------------------+
687 *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
688 *+--------------------+---------------+--------------------+------------------+
689 *
690 * S4.6. AE and AWB state machines
691 *
692 * The AE and AWB state machines are mostly identical. AE has additional
693 * FLASH_REQUIRED and PRECAPTURE states. So rows below that refer to those two
694 * states should be ignored for the AWB state machine.
695 *
696 * mode = AE_MODE_OFF / AWB mode not AUTO
697 *| state | trans. cause | new state | notes |
698 *+--------------------+---------------+--------------------+------------------+
699 *| INACTIVE | | | AE/AWB disabled |
700 *+--------------------+---------------+--------------------+------------------+
701 *
702 * mode = AE_MODE_ON_* / AWB_MODE_AUTO
703 *| state | trans. cause | new state | notes |
704 *+--------------------+---------------+--------------------+------------------+
705 *| INACTIVE | HAL initiates | SEARCHING | |
706 *| | AE/AWB scan | | |
707 *+--------------------+---------------+--------------------+------------------+
708 *| INACTIVE | AE/AWB_LOCK | LOCKED | values locked |
709 *| | on | | |
710 *+--------------------+---------------+--------------------+------------------+
711 *| SEARCHING | HAL finishes | CONVERGED | good values, not |
712 *| | AE/AWB scan | | changing |
713 *+--------------------+---------------+--------------------+------------------+
714 *| SEARCHING | HAL finishes | FLASH_REQUIRED | converged but too|
715 *| | AE scan | | dark w/o flash |
716 *+--------------------+---------------+--------------------+------------------+
717 *| SEARCHING | AE/AWB_LOCK | LOCKED | values locked |
718 *| | on | | |
719 *+--------------------+---------------+--------------------+------------------+
720 *| CONVERGED | HAL initiates | SEARCHING | values locked |
721 *| | AE/AWB scan | | |
722 *+--------------------+---------------+--------------------+------------------+
723 *| CONVERGED | AE/AWB_LOCK | LOCKED | values locked |
724 *| | on | | |
725 *+--------------------+---------------+--------------------+------------------+
726 *| LOCKED | AE/AWB_LOCK | SEARCHING | values not good |
727 *| | off | | after unlock |
728 *+--------------------+---------------+--------------------+------------------+
729 *| LOCKED | AE/AWB_LOCK | CONVERGED | values good |
730 *| | off | | after unlock |
731 *+--------------------+---------------+--------------------+------------------+
732 *| LOCKED | AE_LOCK | FLASH_REQUIRED | exposure good, |
733 *| | off | | but too dark |
734 *+--------------------+---------------+--------------------+------------------+
735 *| All AE states | PRECAPTURE_ | PRECAPTURE | Start precapture |
736 *| | START | | sequence |
737 *+--------------------+---------------+--------------------+------------------+
738 *| PRECAPTURE | Sequence done.| CONVERGED | Ready for high- |
739 *| | AE_LOCK off | | quality capture |
740 *+--------------------+---------------+--------------------+------------------+
741 *| PRECAPTURE | Sequence done.| LOCKED | Ready for high- |
742 *| | AE_LOCK on | | quality capture |
743 *+--------------------+---------------+--------------------+------------------+
744 *
745 */
746
747/**
Eino-Ville Talvalab6059442013-04-29 15:26:16 -0700748 * S5. Cropping:
749 *
750 * Cropping of the full pixel array (for digital zoom and other use cases where
751 * a smaller FOV is desirable) is communicated through the
752 * ANDROID_SCALER_CROP_REGION setting. This is a per-request setting, and can
753 * change on a per-request basis, which is critical for implementing smooth
754 * digital zoom.
755 *
756 * The region is defined as a rectangle (x, y, width, height), with (x, y)
757 * describing the top-left corner of the rectangle. The rectangle is defined on
758 * the coordinate system of the sensor active pixel array, with (0,0) being the
759 * top-left pixel of the active pixel array. Therefore, the width and height
760 * cannot be larger than the dimensions reported in the
761 * ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY static info field. The minimum allowed
762 * width and height are reported by the HAL through the
763 * ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes the
764 * maximum supported zoom factor. Therefore, the minimum crop region width and
765 * height are:
766 *
767 * {width, height} =
768 * { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
769 * ANDROID_SCALER_MAX_DIGITAL_ZOOM),
770 * floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
771 * ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
772 *
773 * If the crop region needs to fulfill specific requirements (for example, it
774 * needs to start on even coordinates, and its width/height needs to be even),
775 * the HAL must do the necessary rounding and write out the final crop region
776 * used in the output result metadata. Similarly, if the HAL implements video
777 * stabilization, it must adjust the result crop region to describe the region
778 * actually included in the output after video stabilization is applied. In
779 * general, a camera-using application must be able to determine the field of
780 * view it is receiving based on the crop region, the dimensions of the image
781 * sensor, and the lens focal length.
782 *
783 * Since the crop region applies to all streams, which may have different aspect
784 * ratios than the crop region, the exact sensor region used for each stream may
785 * be smaller than the crop region. Specifically, each stream should maintain
786 * square pixels and its aspect ratio by minimally further cropping the defined
787 * crop region. If the stream's aspect ratio is wider than the crop region, the
788 * stream should be further cropped vertically, and if the stream's aspect ratio
789 * is narrower than the crop region, the stream should be further cropped
790 * horizontally.
791 *
792 * In all cases, the stream crop must be centered within the full crop region,
793 * and each stream is only either cropped horizontally or vertical relative to
794 * the full crop region, never both.
795 *
796 * For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
797 * 1280x720 stream (16:9 aspect), below demonstrates the expected output regions
798 * for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
799 * 1500 pixel array) sensor.
800 *
801 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
802 *
803 * 640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)
804 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
805 *
806 * 0 1000 2000
807 * +---------+---------+---------+----------+
808 * | Active pixel array |
809 * | |
810 * | |
811 * + +-------------------+ + 375
812 * | | | |
813 * | O===================O |
814 * | I 1280x720 stream I |
815 * + I I + 750
816 * | I I |
817 * | O===================O |
818 * | | | |
819 * + +-------------------+ + 1125
820 * | Crop region, 640x480 stream |
821 * | |
822 * | |
823 * +---------+---------+---------+----------+ 1500
824 *
825 * Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)
826 *
827 * 640x480 stream crop: (666, 375, 1000, 750) (marked with =)
828 * 1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
829 *
830 * 0 1000 2000
831 * +---------+---------+---------+----------+
832 * | Active pixel array |
833 * | |
834 * | |
835 * + +---O==================O---+ + 375
836 * | | I 640x480 stream I | |
837 * | | I I | |
838 * | | I I | |
839 * + | I I | + 750
840 * | | I I | |
841 * | | I I | |
842 * | | I I | |
843 * + +---O==================O---+ + 1125
844 * | Crop region, 1280x720 stream |
845 * | |
846 * | |
847 * +---------+---------+---------+----------+ 1500
848 *
849 * Crop region: (500, 375, 750, 750) (1:1 aspect ratio)
850 *
851 * 640x480 stream crop: (500, 469, 750, 562) (marked with =)
852 * 1280x720 stream crop: (500, 543, 750, 414) (marged with #)
853 *
854 * 0 1000 2000
855 * +---------+---------+---------+----------+
856 * | Active pixel array |
857 * | |
858 * | |
859 * + +--------------+ + 375
860 * | O==============O |
861 * | ################ |
862 * | # # |
863 * + # # + 750
864 * | # # |
865 * | ################ 1280x720 |
866 * | O==============O 640x480 |
867 * + +--------------+ + 1125
868 * | Crop region |
869 * | |
870 * | |
871 * +---------+---------+---------+----------+ 1500
872 *
873 * And a final example, a 1024x1024 square aspect ratio stream instead of the
874 * 480p stream:
875 *
876 * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
877 *
878 * 1024x1024 stream crop: (625, 375, 750, 750) (marked with #)
879 * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
880 *
881 * 0 1000 2000
882 * +---------+---------+---------+----------+
883 * | Active pixel array |
884 * | |
885 * | 1024x1024 stream |
886 * + +--###############--+ + 375
887 * | | # # | |
888 * | O===================O |
889 * | I 1280x720 stream I |
890 * + I I + 750
891 * | I I |
892 * | O===================O |
893 * | | # # | |
894 * + +--###############--+ + 1125
895 * | Crop region |
896 * | |
897 * | |
898 * +---------+---------+---------+----------+ 1500
899 *
900 */
901
902/**
903 * S6. Error management:
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800904 *
905 * Camera HAL device ops functions that have a return value will all return
906 * -ENODEV / NULL in case of a serious error. This means the device cannot
907 * continue operation, and must be closed by the framework. Once this error is
Alex Rayd5ddbc92013-02-15 13:47:24 -0800908 * returned by some method, or if notify() is called with ERROR_DEVICE, only
909 * the close() method can be called successfully. All other methods will return
910 * -ENODEV / NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800911 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700912 * If a device op is called in the wrong sequence, for example if the framework
913 * calls configure_streams() is called before initialize(), the device must
914 * return -ENOSYS from the call, and do nothing.
915 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800916 * Transient errors in image capture must be reported through notify() as follows:
917 *
918 * - The failure of an entire capture to occur must be reported by the HAL by
919 * calling notify() with ERROR_REQUEST. Individual errors for the result
920 * metadata or the output buffers must not be reported in this case.
921 *
922 * - If the metadata for a capture cannot be produced, but some image buffers
923 * were filled, the HAL must call notify() with ERROR_RESULT.
924 *
925 * - If an output image buffer could not be filled, but either the metadata was
926 * produced or some other buffers were filled, the HAL must call notify() with
927 * ERROR_BUFFER for each failed buffer.
928 *
929 * In each of these transient failure cases, the HAL must still call
930 * process_capture_result, with valid output buffer_handle_t. If the result
931 * metadata could not be produced, it should be NULL. If some buffers could not
932 * be filled, their sync fences must be set to the error state.
933 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -0700934 * Invalid input arguments result in -EINVAL from the appropriate methods. In
935 * that case, the framework must act as if that call had never been made.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800936 *
937 */
938
939__BEGIN_DECLS
940
941struct camera3_device;
942
943/**********************************************************************
944 *
945 * Camera3 stream and stream buffer definitions.
946 *
947 * These structs and enums define the handles and contents of the input and
948 * output streams connecting the HAL to various framework and application buffer
949 * consumers. Each stream is backed by a gralloc buffer queue.
950 *
951 */
952
953/**
954 * camera3_stream_type_t:
955 *
956 * The type of the camera stream, which defines whether the camera HAL device is
957 * the producer or the consumer for that stream, and how the buffers of the
958 * stream relate to the other streams.
959 */
960typedef enum camera3_stream_type {
961 /**
962 * This stream is an output stream; the camera HAL device will be
963 * responsible for filling buffers from this stream with newly captured or
964 * reprocessed image data.
965 */
966 CAMERA3_STREAM_OUTPUT = 0,
967
968 /**
969 * This stream is an input stream; the camera HAL device will be responsible
970 * for reading buffers from this stream and sending them through the camera
971 * processing pipeline, as if the buffer was a newly captured image from the
972 * imager.
973 */
974 CAMERA3_STREAM_INPUT = 1,
975
976 /**
977 * This stream can be used for input and output. Typically, the stream is
978 * used as an output stream, but occasionally one already-filled buffer may
979 * be sent back to the HAL device for reprocessing.
980 *
981 * This kind of stream is meant generally for zero-shutter-lag features,
982 * where copying the captured image from the output buffer to the
983 * reprocessing input buffer would be expensive. The stream will be used by
984 * the framework as follows:
985 *
986 * 1. The framework includes a buffer from this stream as output buffer in a
987 * request as normal.
988 *
989 * 2. Once the HAL device returns a filled output buffer to the framework,
990 * the framework may do one of two things with the filled buffer:
991 *
992 * 2. a. The framework uses the filled data, and returns the now-used buffer
993 * to the stream queue for reuse. This behavior exactly matches the
994 * OUTPUT type of stream.
995 *
996 * 2. b. The framework wants to reprocess the filled data, and uses the
997 * buffer as an input buffer for a request. Once the HAL device has
998 * used the reprocessing buffer, it then returns it to the
999 * framework. The framework then returns the now-used buffer to the
1000 * stream queue for reuse.
1001 *
1002 * 3. The HAL device will be given the buffer again as an output buffer for
1003 * a request at some future point.
1004 *
1005 * Note that the HAL will always be reprocessing data it produced.
1006 *
1007 */
1008 CAMERA3_STREAM_BIDIRECTIONAL = 2,
1009
1010 /**
1011 * Total number of framework-defined stream types
1012 */
1013 CAMERA3_NUM_STREAM_TYPES
1014
1015} camera3_stream_type_t;
1016
1017/**
1018 * camera3_stream_t:
1019 *
1020 * A handle to a single camera input or output stream. A stream is defined by
1021 * the framework by its buffer resolution and format, and additionally by the
1022 * HAL with the gralloc usage flags and the maximum in-flight buffer count.
1023 *
1024 * The stream structures are owned by the framework, but pointers to a
1025 * camera3_stream passed into the HAL by configure_streams() are valid until the
1026 * end of the first subsequent configure_streams() call that _does not_ include
1027 * that camera3_stream as an argument, or until the end of the close() call.
1028 *
1029 * All camera3_stream framework-controlled members are immutable once the
1030 * camera3_stream is passed into configure_streams(). The HAL may only change
1031 * the HAL-controlled parameters during a configure_streams() call, except for
1032 * the contents of the private pointer.
1033 *
1034 * If a configure_streams() call returns a non-fatal error, all active streams
1035 * remain valid as if configure_streams() had not been called.
1036 *
1037 * The endpoint of the stream is not visible to the camera HAL device.
1038 */
1039typedef struct camera3_stream {
1040
1041 /*****
1042 * Set by framework before configure_streams()
1043 */
1044
1045 /**
1046 * The type of the stream, one of the camera3_stream_type_t values.
1047 */
1048 int stream_type;
1049
1050 /**
1051 * The width in pixels of the buffers in this stream
1052 */
1053 uint32_t width;
1054
1055 /**
1056 * The height in pixels of the buffers in this stream
1057 */
1058 uint32_t height;
1059
1060 /**
1061 * The pixel format for the buffers in this stream. Format is a value from
1062 * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
1063 * from device-specific headers.
1064 *
1065 * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
1066 * gralloc module will select a format based on the usage flags provided by
1067 * the camera device and the other endpoint of the stream.
1068 *
1069 * The camera HAL device must inspect the buffers handed to it in the
1070 * subsequent register_stream_buffers() call to obtain the
1071 * implementation-specific format details, if necessary.
1072 */
1073 int format;
1074
1075 /*****
1076 * Set by HAL during configure_streams().
1077 */
1078
1079 /**
1080 * The gralloc usage flags for this stream, as needed by the HAL. The usage
1081 * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
1082 * headers.
1083 *
1084 * For output streams, these are the HAL's producer usage flags. For input
1085 * streams, these are the HAL's consumer usage flags. The usage flags from
1086 * the producer and the consumer will be combined together and then passed
1087 * to the platform gralloc HAL module for allocating the gralloc buffers for
1088 * each stream.
1089 */
1090 uint32_t usage;
1091
1092 /**
1093 * The maximum number of buffers the HAL device may need to have dequeued at
1094 * the same time. The HAL device may not have more buffers in-flight from
1095 * this stream than this value.
1096 */
1097 uint32_t max_buffers;
1098
1099 /**
1100 * A handle to HAL-private information for the stream. Will not be inspected
1101 * by the framework code.
1102 */
1103 void *priv;
1104
1105} camera3_stream_t;
1106
1107/**
1108 * camera3_stream_configuration_t:
1109 *
1110 * A structure of stream definitions, used by configure_streams(). This
1111 * structure defines all the output streams and the reprocessing input
1112 * stream for the current camera use case.
1113 */
1114typedef struct camera3_stream_configuration {
1115 /**
1116 * The total number of streams requested by the framework. This includes
1117 * both input and output streams. The number of streams will be at least 1,
1118 * and there will be at least one output-capable stream.
1119 */
1120 uint32_t num_streams;
1121
1122 /**
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001123 * An array of camera stream pointers, defining the input/output
1124 * configuration for the camera HAL device.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001125 *
1126 * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
1127 * in a single configuration.
1128 *
1129 * At least one output-capable stream must be defined (OUTPUT or
1130 * BIDIRECTIONAL).
1131 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001132 camera3_stream_t **streams;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001133
1134} camera3_stream_configuration_t;
1135
1136/**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001137 * camera3_buffer_status_t:
1138 *
1139 * The current status of a single stream buffer.
1140 */
1141typedef enum camera3_buffer_status {
1142 /**
1143 * The buffer is in a normal state, and can be used after waiting on its
1144 * sync fence.
1145 */
1146 CAMERA3_BUFFER_STATUS_OK = 0,
1147
1148 /**
1149 * The buffer does not contain valid data, and the data in it should not be
1150 * used. The sync fence must still be waited on before reusing the buffer.
1151 */
1152 CAMERA3_BUFFER_STATUS_ERROR = 1
1153
1154} camera3_buffer_status_t;
1155
1156/**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001157 * camera3_stream_buffer_t:
1158 *
1159 * A single buffer from a camera3 stream. It includes a handle to its parent
1160 * stream, the handle to the gralloc buffer itself, and sync fences
1161 *
1162 * The buffer does not specify whether it is to be used for input or output;
1163 * that is determined by its parent stream type and how the buffer is passed to
1164 * the HAL device.
1165 */
1166typedef struct camera3_stream_buffer {
1167 /**
1168 * The handle of the stream this buffer is associated with
1169 */
1170 camera3_stream_t *stream;
1171
1172 /**
1173 * The native handle to the buffer
1174 */
1175 buffer_handle_t *buffer;
1176
1177 /**
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001178 * Current state of the buffer, one of the camera3_buffer_status_t
1179 * values. The framework will not pass buffers to the HAL that are in an
1180 * error state. In case a buffer could not be filled by the HAL, it must
1181 * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
1182 * framework with process_capture_result().
1183 */
1184 int status;
1185
1186 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001187 * The acquire sync fence for this buffer. The HAL must wait on this fence
1188 * fd before attempting to read from or write to this buffer.
1189 *
1190 * The framework may be set to -1 to indicate that no waiting is necessary
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001191 * for this buffer.
1192 *
1193 * When the HAL returns an output buffer to the framework with
1194 * process_capture_result(), the acquire_fence must be set to -1. If the HAL
1195 * never waits on the acquire_fence due to an error in filling a buffer,
1196 * when calling process_capture_result() the HAL must set the release_fence
1197 * of the buffer to be the acquire_fence passed to it by the framework. This
1198 * will allow the framework to wait on the fence before reusing the buffer.
1199 *
1200 * For input buffers, the HAL must not change the acquire_fence field during
1201 * the process_capture_request() call.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001202 */
1203 int acquire_fence;
1204
1205 /**
1206 * The release sync fence for this buffer. The HAL must set this fence when
1207 * returning buffers to the framework, or write -1 to indicate that no
1208 * waiting is required for this buffer.
1209 *
1210 * For the input buffer, the release fence must be set by the
1211 * process_capture_request() call. For the output buffers, the fences must
1212 * be set in the output_buffers array passed to process_capture_result().
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001213 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001214 */
1215 int release_fence;
1216
1217} camera3_stream_buffer_t;
1218
1219/**
1220 * camera3_stream_buffer_set_t:
1221 *
1222 * The complete set of gralloc buffers for a stream. This structure is given to
1223 * register_stream_buffers() to allow the camera HAL device to register/map/etc
1224 * newly allocated stream buffers.
1225 */
1226typedef struct camera3_stream_buffer_set {
1227 /**
1228 * The stream handle for the stream these buffers belong to
1229 */
1230 camera3_stream_t *stream;
1231
1232 /**
1233 * The number of buffers in this stream. It is guaranteed to be at least
1234 * stream->max_buffers.
1235 */
1236 uint32_t num_buffers;
1237
1238 /**
1239 * The array of gralloc buffer handles for this stream. If the stream format
1240 * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
1241 * should inspect the passed-in buffers to determine any platform-private
1242 * pixel format information.
1243 */
Eino-Ville Talvala3a6e6b42013-03-06 13:21:11 -08001244 buffer_handle_t **buffers;
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001245
1246} camera3_stream_buffer_set_t;
1247
1248/**
1249 * camera3_jpeg_blob:
1250 *
1251 * Transport header for compressed JPEG buffers in output streams.
1252 *
1253 * To capture JPEG images, a stream is created using the pixel format
1254 * HAL_PIXEL_FORMAT_BLOB, and the static metadata field android.jpeg.maxSize is
1255 * used as the buffer size. Since compressed JPEG images are of variable size,
1256 * the HAL needs to include the final size of the compressed image using this
1257 * structure inside the output stream buffer. The JPEG blob ID field must be set
1258 * to CAMERA3_JPEG_BLOB_ID.
1259 *
1260 * Transport header should be at the end of the JPEG output stream buffer. That
1261 * means the jpeg_blob_id must start at byte[android.jpeg.maxSize -
1262 * sizeof(camera3_jpeg_blob)]. Any HAL using this transport header must
1263 * account for it in android.jpeg.maxSize. The JPEG data itself starts at
1264 * the beginning of the buffer and should be jpeg_size bytes long.
1265 */
1266typedef struct camera3_jpeg_blob {
1267 uint16_t jpeg_blob_id;
1268 uint32_t jpeg_size;
1269} camera3_jpeg_blob_t;
1270
1271enum {
1272 CAMERA3_JPEG_BLOB_ID = 0x00FF
1273};
1274
1275/**********************************************************************
1276 *
1277 * Message definitions for the HAL notify() callback.
1278 *
1279 * These definitions are used for the HAL notify callback, to signal
1280 * asynchronous events from the HAL device to the Android framework.
1281 *
1282 */
1283
1284/**
1285 * camera3_msg_type:
1286 *
1287 * Indicates the type of message sent, which specifies which member of the
1288 * message union is valid.
1289 *
1290 */
1291typedef enum camera3_msg_type {
1292 /**
1293 * An error has occurred. camera3_notify_msg.message.error contains the
1294 * error information.
1295 */
1296 CAMERA3_MSG_ERROR = 1,
1297
1298 /**
1299 * The exposure of a given request has
1300 * begun. camera3_notify_msg.message.shutter contains the information
1301 * the capture.
1302 */
1303 CAMERA3_MSG_SHUTTER = 2,
1304
1305 /**
1306 * Number of framework message types
1307 */
1308 CAMERA3_NUM_MESSAGES
1309
1310} camera3_msg_type_t;
1311
1312/**
1313 * Defined error codes for CAMERA_MSG_ERROR
1314 */
1315typedef enum camera3_error_msg_code {
1316 /**
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001317 * A serious failure occured. No further frames or buffer streams will
1318 * be produced by the device. Device should be treated as closed. The
1319 * client must reopen the device to use it again. The frame_number field
1320 * is unused.
1321 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001322 CAMERA3_MSG_ERROR_DEVICE = 1,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001323
1324 /**
1325 * An error has occurred in processing a request. No output (metadata or
1326 * buffers) will be produced for this request. The frame_number field
1327 * specifies which request has been dropped. Subsequent requests are
1328 * unaffected, and the device remains operational.
1329 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001330 CAMERA3_MSG_ERROR_REQUEST = 2,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001331
1332 /**
1333 * An error has occurred in producing an output result metadata buffer
1334 * for a request, but output stream buffers for it will still be
1335 * available. Subsequent requests are unaffected, and the device remains
1336 * operational. The frame_number field specifies the request for which
1337 * result metadata won't be available.
1338 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001339 CAMERA3_MSG_ERROR_RESULT = 3,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001340
1341 /**
1342 * An error has occurred in placing an output buffer into a stream for a
1343 * request. The frame metadata and other buffers may still be
1344 * available. Subsequent requests are unaffected, and the device remains
1345 * operational. The frame_number field specifies the request for which the
1346 * buffer was dropped, and error_stream contains a pointer to the stream
1347 * that dropped the frame.u
1348 */
Alex Rayd5ddbc92013-02-15 13:47:24 -08001349 CAMERA3_MSG_ERROR_BUFFER = 4,
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001350
1351 /**
1352 * Number of error types
1353 */
1354 CAMERA3_MSG_NUM_ERRORS
1355
1356} camera3_error_msg_code_t;
1357
1358/**
1359 * camera3_error_msg_t:
1360 *
1361 * Message contents for CAMERA3_MSG_ERROR
1362 */
1363typedef struct camera3_error_msg {
1364 /**
1365 * Frame number of the request the error applies to. 0 if the frame number
1366 * isn't applicable to the error.
1367 */
1368 uint32_t frame_number;
1369
1370 /**
1371 * Pointer to the stream that had a failure. NULL if the stream isn't
1372 * applicable to the error.
1373 */
1374 camera3_stream_t *error_stream;
1375
1376 /**
1377 * The code for this error; one of the CAMERA_MSG_ERROR enum values.
1378 */
1379 int error_code;
1380
1381} camera3_error_msg_t;
1382
1383/**
1384 * camera3_shutter_msg_t:
1385 *
1386 * Message contents for CAMERA3_MSG_SHUTTER
1387 */
1388typedef struct camera3_shutter_msg {
1389 /**
1390 * Frame number of the request that has begun exposure
1391 */
1392 uint32_t frame_number;
1393
1394 /**
1395 * Timestamp for the start of capture. This must match the capture result
1396 * metadata's sensor exposure start timestamp.
1397 */
1398 uint64_t timestamp;
1399
1400} camera3_shutter_msg_t;
1401
1402/**
1403 * camera3_notify_msg_t:
1404 *
1405 * The message structure sent to camera3_callback_ops_t.notify()
1406 */
1407typedef struct camera3_notify_msg {
1408
1409 /**
1410 * The message type. One of camera3_notify_msg_type, or a private extension.
1411 */
1412 int type;
1413
1414 union {
1415 /**
1416 * Error message contents. Valid if type is CAMERA3_MSG_ERROR
1417 */
1418 camera3_error_msg_t error;
1419
1420 /**
1421 * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
1422 */
1423 camera3_shutter_msg_t shutter;
1424
1425 /**
1426 * Generic message contents. Used to ensure a minimum size for custom
1427 * message types.
1428 */
1429 uint8_t generic[32];
1430 } message;
1431
1432} camera3_notify_msg_t;
1433
1434/**********************************************************************
1435 *
1436 * Capture request/result definitions for the HAL process_capture_request()
1437 * method, and the process_capture_result() callback.
1438 *
1439 */
1440
1441/**
1442 * camera3_request_template_t:
1443 *
1444 * Available template types for
1445 * camera3_device_ops.construct_default_request_settings()
1446 */
1447typedef enum camera3_request_template {
1448 /**
1449 * Standard camera preview operation with 3A on auto.
1450 */
1451 CAMERA3_TEMPLATE_PREVIEW = 1,
1452
1453 /**
1454 * Standard camera high-quality still capture with 3A and flash on auto.
1455 */
1456 CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
1457
1458 /**
1459 * Standard video recording plus preview with 3A on auto, torch off.
1460 */
1461 CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
1462
1463 /**
1464 * High-quality still capture while recording video. Application will
1465 * include preview, video record, and full-resolution YUV or JPEG streams in
1466 * request. Must not cause stuttering on video stream. 3A on auto.
1467 */
1468 CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
1469
1470 /**
1471 * Zero-shutter-lag mode. Application will request preview and
1472 * full-resolution data for each frame, and reprocess it to JPEG when a
1473 * still image is requested by user. Settings should provide highest-quality
1474 * full-resolution images without compromising preview frame rate. 3A on
1475 * auto.
1476 */
1477 CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
1478
1479 /* Total number of templates */
1480 CAMERA3_TEMPLATE_COUNT,
1481
1482 /**
1483 * First value for vendor-defined request templates
1484 */
1485 CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
1486
1487} camera3_request_template_t;
1488
1489/**
1490 * camera3_capture_request_t:
1491 *
1492 * A single request for image capture/buffer reprocessing, sent to the Camera
1493 * HAL device by the framework in process_capture_request().
1494 *
1495 * The request contains the settings to be used for this capture, and the set of
1496 * output buffers to write the resulting image data in. It may optionally
1497 * contain an input buffer, in which case the request is for reprocessing that
1498 * input buffer instead of capturing a new image with the camera sensor. The
1499 * capture is identified by the frame_number.
1500 *
1501 * In response, the camera HAL device must send a camera3_capture_result
1502 * structure asynchronously to the framework, using the process_capture_result()
1503 * callback.
1504 */
1505typedef struct camera3_capture_request {
1506 /**
1507 * The frame number is an incrementing integer set by the framework to
1508 * uniquely identify this capture. It needs to be returned in the result
1509 * call, and is also used to identify the request in asynchronous
1510 * notifications sent to camera3_callback_ops_t.notify().
1511 */
1512 uint32_t frame_number;
1513
1514 /**
1515 * The settings buffer contains the capture and processing parameters for
1516 * the request. As a special case, a NULL settings buffer indicates that the
1517 * settings are identical to the most-recently submitted capture request. A
1518 * NULL buffer cannot be used as the first submitted request after a
1519 * configure_streams() call.
1520 */
1521 const camera_metadata_t *settings;
1522
1523 /**
1524 * The input stream buffer to use for this request, if any.
1525 *
1526 * If input_buffer is NULL, then the request is for a new capture from the
1527 * imager. If input_buffer is valid, the request is for reprocessing the
1528 * image contained in input_buffer.
1529 *
1530 * In the latter case, the HAL must set the release_fence of the
1531 * input_buffer to a valid sync fence, or to -1 if the HAL does not support
1532 * sync, before process_capture_request() returns.
1533 *
1534 * The HAL is required to wait on the acquire sync fence of the input buffer
1535 * before accessing it.
1536 *
1537 * Any input buffer included here will have been registered with the HAL
1538 * through register_stream_buffers() before its inclusion in a request.
1539 */
1540 camera3_stream_buffer_t *input_buffer;
1541
1542 /**
1543 * The number of output buffers for this capture request. Must be at least
1544 * 1.
1545 */
1546 uint32_t num_output_buffers;
1547
1548 /**
1549 * An array of num_output_buffers stream buffers, to be filled with image
1550 * data from this capture/reprocess. The HAL must wait on the acquire fences
1551 * of each stream buffer before writing to them. All the buffers included
1552 * here will have been registered with the HAL through
1553 * register_stream_buffers() before their inclusion in a request.
1554 *
1555 * The HAL takes ownership of the actual buffer_handle_t entries in
1556 * output_buffers; the framework does not access them until they are
1557 * returned in a camera3_capture_result_t.
1558 */
1559 const camera3_stream_buffer_t *output_buffers;
1560
1561} camera3_capture_request_t;
1562
1563/**
1564 * camera3_capture_result_t:
1565 *
1566 * The result of a single capture/reprocess by the camera HAL device. This is
1567 * sent to the framework asynchronously with process_capture_result(), in
1568 * response to a single capture request sent to the HAL with
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001569 * process_capture_request(). Multiple process_capture_result() calls may be
1570 * performed by the HAL for each request. Each call, all with the same frame
1571 * number, may contain some subset of the output buffers, and/or the result
1572 * metadata. The metadata may only be provided once for a given frame number;
1573 * all other calls must set the result metadata to NULL.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001574 *
1575 * The result structure contains the output metadata from this capture, and the
1576 * set of output buffers that have been/will be filled for this capture. Each
1577 * output buffer may come with a release sync fence that the framework will wait
1578 * on before reading, in case the buffer has not yet been filled by the HAL.
1579 *
1580 */
1581typedef struct camera3_capture_result {
1582 /**
1583 * The frame number is an incrementing integer set by the framework in the
1584 * submitted request to uniquely identify this capture. It is also used to
1585 * identify the request in asynchronous notifications sent to
1586 * camera3_callback_ops_t.notify().
1587 */
1588 uint32_t frame_number;
1589
1590 /**
1591 * The result metadata for this capture. This contains information about the
1592 * final capture parameters, the state of the capture and post-processing
1593 * hardware, the state of the 3A algorithms, if enabled, and the output of
1594 * any enabled statistics units.
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001595 *
1596 * Only one call to process_capture_result() with a given frame_number may
1597 * include the result metadata. All other calls for the same frame_number
1598 * must set this to NULL.
1599 *
1600 * If there was an error producing the result metadata, result must be an
1601 * empty metadata buffer, and notify() must be called with ERROR_RESULT.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001602 */
1603 const camera_metadata_t *result;
1604
1605 /**
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001606 * The number of output buffers returned in this result structure. Must be
1607 * less than or equal to the matching capture request's count. If this is
1608 * less than the buffer count in the capture request, at least one more call
1609 * to process_capture_result with the same frame_number must be made, to
1610 * return the remaining output buffers to the framework. This may only be
1611 * zero if the structure includes valid result metadata.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001612 */
1613 uint32_t num_output_buffers;
1614
1615 /**
1616 * The handles for the output stream buffers for this capture. They may not
1617 * yet be filled at the time the HAL calls process_capture_result(); the
1618 * framework will wait on the release sync fences provided by the HAL before
1619 * reading the buffers.
1620 *
1621 * The HAL must set the stream buffer's release sync fence to a valid sync
1622 * fd, or to -1 if the buffer has already been filled.
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001623 *
1624 * If the HAL encounters an error while processing the buffer, and the
1625 * buffer is not filled, the buffer's status field must be set to
1626 * CAMERA3_BUFFER_STATUS_ERROR. If the HAL did not wait on the acquire fence
1627 * before encountering the error, the acquire fence should be copied into
1628 * the release fence, to allow the framework to wait on the fence before
1629 * reusing the buffer.
1630 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001631 * The acquire fence must be set to -1 for all output buffers. If
1632 * num_output_buffers is zero, this may be NULL. In that case, at least one
1633 * more process_capture_result call must be made by the HAL to provide the
1634 * output buffers.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001635 */
1636 const camera3_stream_buffer_t *output_buffers;
1637
1638} camera3_capture_result_t;
1639
1640/**********************************************************************
1641 *
1642 * Callback methods for the HAL to call into the framework.
1643 *
1644 * These methods are used to return metadata and image buffers for a completed
1645 * or failed captures, and to notify the framework of asynchronous events such
1646 * as errors.
1647 *
1648 * The framework will not call back into the HAL from within these callbacks,
1649 * and these calls will not block for extended periods.
1650 *
1651 */
1652typedef struct camera3_callback_ops {
1653
1654 /**
1655 * process_capture_result:
1656 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001657 * Send results from a completed capture to the framework.
1658 * process_capture_result() may be invoked multiple times by the HAL in
1659 * response to a single capture request. This allows, for example, the
1660 * metadata and low-resolution buffers to be returned in one call, and
1661 * post-processed JPEG buffers in a later call, once it is available. Each
1662 * call must include the frame number of the request it is returning
1663 * metadata or buffers for.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001664 *
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001665 * A component (buffer or metadata) of the complete result may only be
1666 * included in one process_capture_result call. A buffer for each stream,
1667 * and the result metadata, must be returned by the HAL for each request in
1668 * one of the process_capture_result calls, even in case of errors producing
1669 * some of the output. A call to process_capture_result() with neither
1670 * output buffers or result metadata is not allowed.
1671 *
1672 * The order of returning metadata and buffers for a single result does not
1673 * matter, but buffers for a given stream must be returned in FIFO order. So
1674 * the buffer for request 5 for stream A must always be returned before the
1675 * buffer for request 6 for stream A. This also applies to the result
1676 * metadata; the metadata for request 5 must be returned before the metadata
1677 * for request 6.
1678 *
1679 * However, different streams are independent of each other, so it is
1680 * acceptable and expected that the buffer for request 5 for stream A may be
1681 * returned after the buffer for request 6 for stream B is. And it is
1682 * acceptable that the result metadata for request 6 for stream B is
1683 * returned before the buffer for request 5 for stream A is.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001684 *
1685 * The HAL retains ownership of result structure, which only needs to be
1686 * valid to access during this call. The framework will copy whatever it
1687 * needs before this call returns.
1688 *
1689 * The output buffers do not need to be filled yet; the framework will wait
1690 * on the stream buffer release sync fence before reading the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001691 * data. Therefore, this method should be called by the HAL as soon as
1692 * possible, even if some or all of the output buffers are still in
1693 * being filled. The HAL must include valid release sync fences into each
1694 * output_buffers stream buffer entry, or -1 if that stream buffer is
1695 * already filled.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001696 *
1697 * If the result buffer cannot be constructed for a request, the HAL should
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001698 * return an empty metadata buffer, but still provide the output buffers and
1699 * their sync fences. In addition, notify() must be called with an
1700 * ERROR_RESULT message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001701 *
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001702 * If an output buffer cannot be filled, its status field must be set to
1703 * STATUS_ERROR. In addition, notify() must be called with a ERROR_BUFFER
1704 * message.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001705 *
1706 * If the entire capture has failed, then this method still needs to be
Eino-Ville Talvala2f8cf5c2013-03-06 13:23:31 -08001707 * called to return the output buffers to the framework. All the buffer
Eino-Ville Talvala7c9416b2013-04-03 15:18:20 -07001708 * statuses should be STATUS_ERROR, and the result metadata should be an
1709 * empty buffer. In addition, notify() must be called with a ERROR_REQUEST
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001710 * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
1711 * should not be sent.
1712 *
1713 */
1714 void (*process_capture_result)(const struct camera3_callback_ops *,
1715 const camera3_capture_result_t *result);
1716
1717 /**
1718 * notify:
1719 *
1720 * Asynchronous notification callback from the HAL, fired for various
1721 * reasons. Only for information independent of frame capture, or that
1722 * require specific timing. The ownership of the message structure remains
1723 * with the HAL, and the msg only needs to be valid for the duration of this
1724 * call.
1725 *
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07001726 * The notification for the start of exposure for a given request must be
1727 * sent by the HAL before the first call to process_capture_result() for
1728 * that request is made.
1729 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001730 * Multiple threads may call notify() simultaneously.
1731 */
1732 void (*notify)(const struct camera3_callback_ops *,
1733 const camera3_notify_msg_t *msg);
1734
1735} camera3_callback_ops_t;
1736
1737/**********************************************************************
1738 *
1739 * Camera device operations
1740 *
1741 */
1742typedef struct camera3_device_ops {
1743
1744 /**
1745 * initialize:
1746 *
1747 * One-time initialization to pass framework callback function pointers to
1748 * the HAL. Will be called once after a successful open() call, before any
1749 * other functions are called on the camera3_device_ops structure.
1750 *
1751 * Return values:
1752 *
1753 * 0: On successful initialization
1754 *
1755 * -ENODEV: If initialization fails. Only close() can be called successfully
1756 * by the framework after this.
1757 */
1758 int (*initialize)(const struct camera3_device *,
1759 const camera3_callback_ops_t *callback_ops);
1760
1761 /**********************************************************************
1762 * Stream management
1763 */
1764
1765 /**
1766 * configure_streams:
1767 *
1768 * Reset the HAL camera device processing pipeline and set up new input and
1769 * output streams. This call replaces any existing stream configuration with
1770 * the streams defined in the stream_list. This method will be called at
1771 * least once after initialize() before a request is submitted with
1772 * process_capture_request().
1773 *
1774 * The stream_list must contain at least one output-capable stream, and may
1775 * not contain more than one input-capable stream.
1776 *
1777 * The stream_list may contain streams that are also in the currently-active
1778 * set of streams (from the previous call to configure_stream()). These
1779 * streams will already have valid values for usage, max_buffers, and the
1780 * private pointer. If such a stream has already had its buffers registered,
1781 * register_stream_buffers() will not be called again for the stream, and
1782 * buffers from the stream can be immediately included in input requests.
1783 *
1784 * If the HAL needs to change the stream configuration for an existing
1785 * stream due to the new configuration, it may rewrite the values of usage
1786 * and/or max_buffers during the configure call. The framework will detect
1787 * such a change, and will then reallocate the stream buffers, and call
1788 * register_stream_buffers() again before using buffers from that stream in
1789 * a request.
1790 *
1791 * If a currently-active stream is not included in stream_list, the HAL may
1792 * safely remove any references to that stream. It will not be reused in a
1793 * later configure() call by the framework, and all the gralloc buffers for
1794 * it will be freed after the configure_streams() call returns.
1795 *
1796 * The stream_list structure is owned by the framework, and may not be
1797 * accessed once this call completes. The address of an individual
1798 * camera3_stream_t structure will remain valid for access by the HAL until
1799 * the end of the first configure_stream() call which no longer includes
1800 * that camera3_stream_t in the stream_list argument. The HAL may not change
1801 * values in the stream structure outside of the private pointer, except for
1802 * the usage and max_buffers members during the configure_streams() call
1803 * itself.
1804 *
1805 * If the stream is new, the usage, max_buffer, and private pointer fields
1806 * of the stream structure will all be set to 0. The HAL device must set
1807 * these fields before the configure_streams() call returns. These fields
1808 * are then used by the framework and the platform gralloc module to
1809 * allocate the gralloc buffers for each stream.
1810 *
1811 * Before such a new stream can have its buffers included in a capture
1812 * request, the framework will call register_stream_buffers() with that
1813 * stream. However, the framework is not required to register buffers for
1814 * _all_ streams before submitting a request. This allows for quick startup
1815 * of (for example) a preview stream, with allocation for other streams
1816 * happening later or concurrently.
1817 *
1818 * Preconditions:
1819 *
1820 * The framework will only call this method when no captures are being
1821 * processed. That is, all results have been returned to the framework, and
1822 * all in-flight input and output buffers have been returned and their
1823 * release sync fences have been signaled by the HAL. The framework will not
1824 * submit new requests for capture while the configure_streams() call is
1825 * underway.
1826 *
1827 * Postconditions:
1828 *
1829 * The HAL device must configure itself to provide maximum possible output
1830 * frame rate given the sizes and formats of the output streams, as
1831 * documented in the camera device's static metadata.
1832 *
1833 * Performance expectations:
1834 *
1835 * This call is expected to be heavyweight and possibly take several hundred
1836 * milliseconds to complete, since it may require resetting and
1837 * reconfiguring the image sensor and the camera processing pipeline.
1838 * Nevertheless, the HAL device should attempt to minimize the
1839 * reconfiguration delay to minimize the user-visible pauses during
1840 * application operational mode changes (such as switching from still
1841 * capture to video recording).
1842 *
1843 * Return values:
1844 *
1845 * 0: On successful stream configuration
1846 *
1847 * -EINVAL: If the requested stream configuration is invalid. Some examples
1848 * of invalid stream configurations include:
1849 *
1850 * - Including more than 1 input-capable stream (INPUT or
1851 * BIDIRECTIONAL)
1852 *
1853 * - Not including any output-capable streams (OUTPUT or
1854 * BIDIRECTIONAL)
1855 *
1856 * - Including streams with unsupported formats, or an unsupported
1857 * size for that format.
1858 *
1859 * - Including too many output streams of a certain format.
1860 *
Eino-Ville Talvala7effe0c2013-02-15 12:09:48 -08001861 * Note that the framework submitting an invalid stream
1862 * configuration is not normal operation, since stream
1863 * configurations are checked before configure. An invalid
1864 * configuration means that a bug exists in the framework code, or
1865 * there is a mismatch between the HAL's static metadata and the
1866 * requirements on streams.
1867 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001868 * -ENODEV: If there has been a fatal error and the device is no longer
1869 * operational. Only close() can be called successfully by the
1870 * framework after this error is returned.
1871 */
1872 int (*configure_streams)(const struct camera3_device *,
1873 camera3_stream_configuration_t *stream_list);
1874
1875 /**
1876 * register_stream_buffers:
1877 *
1878 * Register buffers for a given stream with the HAL device. This method is
1879 * called by the framework after a new stream is defined by
1880 * configure_streams, and before buffers from that stream are included in a
1881 * capture request. If the same stream is listed in a subsequent
1882 * configure_streams() call, register_stream_buffers will _not_ be called
1883 * again for that stream.
1884 *
1885 * The framework does not need to register buffers for all configured
1886 * streams before it submits the first capture request. This allows quick
1887 * startup for preview (or similar use cases) while other streams are still
1888 * being allocated.
1889 *
1890 * This method is intended to allow the HAL device to map or otherwise
1891 * prepare the buffers for later use. The buffers passed in will already be
1892 * locked for use. At the end of the call, all the buffers must be ready to
1893 * be returned to the stream. The buffer_set argument is only valid for the
1894 * duration of this call.
1895 *
1896 * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
1897 * the camera HAL should inspect the passed-in buffers here to determine any
1898 * platform-private pixel format information.
1899 *
1900 * Return values:
1901 *
1902 * 0: On successful registration of the new stream buffers
1903 *
1904 * -EINVAL: If the stream_buffer_set does not refer to a valid active
1905 * stream, or if the buffers array is invalid.
1906 *
1907 * -ENOMEM: If there was a failure in registering the buffers. The framework
1908 * must consider all the stream buffers to be unregistered, and can
1909 * try to register again later.
1910 *
1911 * -ENODEV: If there is a fatal error, and the device is no longer
1912 * operational. Only close() can be called successfully by the
1913 * framework after this error is returned.
1914 */
1915 int (*register_stream_buffers)(const struct camera3_device *,
1916 const camera3_stream_buffer_set_t *buffer_set);
1917
1918 /**********************************************************************
1919 * Request creation and submission
1920 */
1921
1922 /**
1923 * construct_default_request_settings:
1924 *
1925 * Create capture settings for standard camera use cases.
1926 *
1927 * The device must return a settings buffer that is configured to meet the
1928 * requested use case, which must be one of the CAMERA3_TEMPLATE_*
1929 * enums. All request control fields must be included.
1930 *
1931 * The HAL retains ownership of this structure, but the pointer to the
1932 * structure must be valid until the device is closed. The framework and the
1933 * HAL may not modify the buffer once it is returned by this call. The same
1934 * buffer may be returned for subsequent calls for the same template, or for
1935 * other templates.
1936 *
1937 * Return values:
1938 *
1939 * Valid metadata: On successful creation of a default settings
1940 * buffer.
1941 *
1942 * NULL: In case of a fatal error. After this is returned, only
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07001943 * the close() method can be called successfully by the
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001944 * framework.
1945 */
1946 const camera_metadata_t* (*construct_default_request_settings)(
1947 const struct camera3_device *,
1948 int type);
1949
1950 /**
1951 * process_capture_request:
1952 *
1953 * Send a new capture request to the HAL. The HAL should not return from
1954 * this call until it is ready to accept the next request to process. Only
1955 * one call to process_capture_request() will be made at a time by the
1956 * framework, and the calls will all be from the same thread. The next call
1957 * to process_capture_request() will be made as soon as a new request and
1958 * its associated buffers are available. In a normal preview scenario, this
1959 * means the function will be called again by the framework almost
1960 * instantly.
1961 *
1962 * The actual request processing is asynchronous, with the results of
1963 * capture being returned by the HAL through the process_capture_result()
1964 * call. This call requires the result metadata to be available, but output
1965 * buffers may simply provide sync fences to wait on. Multiple requests are
1966 * expected to be in flight at once, to maintain full output frame rate.
1967 *
1968 * The framework retains ownership of the request structure. It is only
1969 * guaranteed to be valid during this call. The HAL device must make copies
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07001970 * of the information it needs to retain for the capture processing. The HAL
1971 * is responsible for waiting on and closing the buffers' fences and
1972 * returning the buffer handles to the framework.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001973 *
1974 * The HAL must write the file descriptor for the input buffer's release
1975 * sync fence into input_buffer->release_fence, if input_buffer is not
1976 * NULL. If the HAL returns -1 for the input buffer release sync fence, the
1977 * framework is free to immediately reuse the input buffer. Otherwise, the
1978 * framework will wait on the sync fence before refilling and reusing the
1979 * input buffer.
1980 *
1981 * Return values:
1982 *
1983 * 0: On a successful start to processing the capture request
1984 *
1985 * -EINVAL: If the input is malformed (the settings are NULL when not
1986 * allowed, there are 0 output buffers, etc) and capture processing
1987 * cannot start. Failures during request processing should be
Eino-Ville Talvala71af1022013-04-22 14:19:21 -07001988 * handled by calling camera3_callback_ops_t.notify(). In case of
1989 * this error, the framework will retain responsibility for the
1990 * stream buffers' fences and the buffer handles; the HAL should
1991 * not close the fences or return these buffers with
1992 * process_capture_result.
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001993 *
1994 * -ENODEV: If the camera device has encountered a serious error. After this
1995 * error is returned, only the close() method can be successfully
1996 * called by the framework.
1997 *
1998 */
1999 int (*process_capture_request)(const struct camera3_device *,
2000 camera3_capture_request_t *request);
2001
2002 /**********************************************************************
2003 * Miscellaneous methods
2004 */
2005
2006 /**
2007 * get_metadata_vendor_tag_ops:
2008 *
Eino-Ville Talvalaacbc4512013-03-16 16:53:28 -07002009 * Get methods to query for vendor extension metadata tag information. The
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08002010 * HAL should fill in all the vendor tag operation methods, or leave ops
2011 * unchanged if no vendor tags are defined.
2012 *
2013 * The definition of vendor_tag_query_ops_t can be found in
2014 * system/media/camera/include/system/camera_metadata.h.
2015 *
2016 */
2017 void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
2018 vendor_tag_query_ops_t* ops);
2019
2020 /**
2021 * dump:
2022 *
2023 * Print out debugging state for the camera device. This will be called by
2024 * the framework when the camera service is asked for a debug dump, which
2025 * happens when using the dumpsys tool, or when capturing a bugreport.
2026 *
2027 * The passed-in file descriptor can be used to write debugging text using
2028 * dprintf() or write(). The text should be in ASCII encoding only.
2029 */
2030 void (*dump)(const struct camera3_device *, int fd);
2031
2032} camera3_device_ops_t;
2033
2034/**********************************************************************
2035 *
2036 * Camera device definition
2037 *
2038 */
2039typedef struct camera3_device {
2040 /**
2041 * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
2042 * device as implementing version 3.0 of the camera device HAL.
2043 */
2044 hw_device_t common;
2045 camera3_device_ops_t *ops;
2046 void *priv;
2047} camera3_device_t;
2048
2049__END_DECLS
2050
2051#endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */