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