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