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