1 /* 2 * Copyright (C) 2012 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 // FIXME: add well-defined names for cameras 18 19 #ifndef ANDROID_INCLUDE_CAMERA_COMMON_H 20 #define ANDROID_INCLUDE_CAMERA_COMMON_H 21 22 #include <stdint.h> 23 #include <stdbool.h> 24 #include <sys/cdefs.h> 25 #include <sys/types.h> 26 #include <cutils/native_handle.h> 27 #include <system/camera.h> 28 #include <system/camera_vendor_tags.h> 29 #include <hardware/hardware.h> 30 #include <hardware/gralloc.h> 31 32 __BEGIN_DECLS 33 34 /** 35 * The id of this module 36 */ 37 #define CAMERA_HARDWARE_MODULE_ID "camera" 38 39 /** 40 * Module versioning information for the Camera hardware module, based on 41 * camera_module_t.common.module_api_version. The two most significant hex 42 * digits represent the major version, and the two least significant represent 43 * the minor version. 44 * 45 ******************************************************************************* 46 * Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0] 47 * 48 * Camera modules that report these version numbers implement the initial 49 * camera module HAL interface. All camera devices openable through this 50 * module support only version 1 of the camera device HAL. The device_version 51 * and static_camera_characteristics fields of camera_info are not valid. Only 52 * the android.hardware.Camera API can be supported by this module and its 53 * devices. 54 * 55 ******************************************************************************* 56 * Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0] 57 * 58 * Camera modules that report this version number implement the second version 59 * of the camera module HAL interface. Camera devices openable through this 60 * module may support either version 1.0 or version 2.0 of the camera device 61 * HAL interface. The device_version field of camera_info is always valid; the 62 * static_camera_characteristics field of camera_info is valid if the 63 * device_version field is 2.0 or higher. 64 * 65 ******************************************************************************* 66 * Version: 2.1 [CAMERA_MODULE_API_VERSION_2_1] 67 * 68 * This camera module version adds support for asynchronous callbacks to the 69 * framework from the camera HAL module, which is used to notify the framework 70 * about changes to the camera module state. Modules that provide a valid 71 * set_callbacks() method must report at least this version number. 72 * 73 ******************************************************************************* 74 * Version: 2.2 [CAMERA_MODULE_API_VERSION_2_2] 75 * 76 * This camera module version adds vendor tag support from the module, and 77 * deprecates the old vendor_tag_query_ops that were previously only 78 * accessible with a device open. 79 * 80 ******************************************************************************* 81 * Version: 2.3 [CAMERA_MODULE_API_VERSION_2_3] 82 * 83 * This camera module version adds open legacy camera HAL device support. 84 * Framework can use it to open the camera device as lower device HAL version 85 * HAL device if the same device can support multiple device API versions. 86 * The standard hardware module open call (common.methods->open) continues 87 * to open the camera device with the latest supported version, which is 88 * also the version listed in camera_info_t.device_version. 89 * 90 ******************************************************************************* 91 * Version: 2.4 [CAMERA_MODULE_API_VERSION_2_4] 92 * 93 * This camera module version adds below API changes: 94 * 95 * 1. Torch mode support. The framework can use it to turn on torch mode for 96 * any camera device that has a flash unit, without opening a camera device. The 97 * camera device has a higher priority accessing the flash unit than the camera 98 * module; opening a camera device will turn off the torch if it had been enabled 99 * through the module interface. When there are any resource conflicts, such as 100 * open() is called to open a camera device, the camera HAL module must notify the 101 * framework through the torch mode status callback that the torch mode has been 102 * turned off. 103 * 104 * 2. External camera (e.g. USB hot-plug camera) support. The API updates specify that 105 * the camera static info is only available when camera is connected and ready to 106 * use for external hot-plug cameras. Calls to get static info will be invalid 107 * calls when camera status is not CAMERA_DEVICE_STATUS_PRESENT. The frameworks 108 * will only count on device status change callbacks to manage the available external 109 * camera list. 110 * 111 * 3. Camera arbitration hints. This module version adds support for explicitly 112 * indicating the number of camera devices that can be simultaneously opened and used. 113 * To specify valid combinations of devices, the resource_cost and conflicting_devices 114 * fields should always be set in the camera_info structure returned by the 115 * get_camera_info call. 116 * 117 * 4. Module initialization method. This will be called by the camera service 118 * right after the HAL module is loaded, to allow for one-time initialization 119 * of the HAL. It is called before any other module methods are invoked. 120 */ 121 122 /** 123 * Predefined macros for currently-defined version numbers 124 */ 125 126 /** 127 * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated 128 * as CAMERA_MODULE_API_VERSION_1_0 129 */ 130 #define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0) 131 #define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0) 132 #define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1) 133 #define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2) 134 #define CAMERA_MODULE_API_VERSION_2_3 HARDWARE_MODULE_API_VERSION(2, 3) 135 #define CAMERA_MODULE_API_VERSION_2_4 HARDWARE_MODULE_API_VERSION(2, 4) 136 137 #define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_4 138 139 /** 140 * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated 141 * as CAMERA_DEVICE_API_VERSION_1_0 142 */ 143 #define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) // DEPRECATED 144 #define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0) // NO LONGER SUPPORTED 145 #define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1) // NO LONGER SUPPORTED 146 #define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0) // NO LONGER SUPPORTED 147 #define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1) // NO LONGER SUPPORTED 148 #define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2) 149 #define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3) 150 #define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4) 151 #define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5) 152 153 // Device version 3.5 is current, older HAL camera device versions are not 154 // recommended for new devices. 155 #define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_5 156 157 /** 158 * Defined in /system/media/camera/include/system/camera_metadata.h 159 */ 160 typedef struct camera_metadata camera_metadata_t; 161 162 typedef struct camera_info { 163 /** 164 * The direction that the camera faces to. See system/core/include/system/camera.h 165 * for camera facing definitions. 166 * 167 * Version information (based on camera_module_t.common.module_api_version): 168 * 169 * CAMERA_MODULE_API_VERSION_2_3 or lower: 170 * 171 * It should be CAMERA_FACING_BACK or CAMERA_FACING_FRONT. 172 * 173 * CAMERA_MODULE_API_VERSION_2_4 or higher: 174 * 175 * It should be CAMERA_FACING_BACK, CAMERA_FACING_FRONT or 176 * CAMERA_FACING_EXTERNAL. 177 */ 178 int facing; 179 180 /** 181 * The orientation of the camera image. The value is the angle that the 182 * camera image needs to be rotated clockwise so it shows correctly on the 183 * display in its natural orientation. It should be 0, 90, 180, or 270. 184 * 185 * For example, suppose a device has a naturally tall screen. The 186 * back-facing camera sensor is mounted in landscape. You are looking at the 187 * screen. If the top side of the camera sensor is aligned with the right 188 * edge of the screen in natural orientation, the value should be 90. If the 189 * top side of a front-facing camera sensor is aligned with the right of the 190 * screen, the value should be 270. 191 * 192 * Version information (based on camera_module_t.common.module_api_version): 193 * 194 * CAMERA_MODULE_API_VERSION_2_3 or lower: 195 * 196 * Valid in all camera_module versions. 197 * 198 * CAMERA_MODULE_API_VERSION_2_4 or higher: 199 * 200 * Valid if camera facing is CAMERA_FACING_BACK or CAMERA_FACING_FRONT, 201 * not valid if camera facing is CAMERA_FACING_EXTERNAL. 202 */ 203 int orientation; 204 205 /** 206 * The value of camera_device_t.common.version. 207 * 208 * Version information (based on camera_module_t.common.module_api_version): 209 * 210 * CAMERA_MODULE_API_VERSION_1_0: 211 * 212 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do 213 * not read this field. 214 * 215 * CAMERA_MODULE_API_VERSION_2_0 or higher: 216 * 217 * Always valid 218 * 219 */ 220 uint32_t device_version; 221 222 /** 223 * The camera's fixed characteristics, which include all static camera metadata 224 * specified in system/media/camera/docs/docs.html. This should be a sorted metadata 225 * buffer, and may not be modified or freed by the caller. The pointer should remain 226 * valid for the lifetime of the camera module, and values in it may not 227 * change after it is returned by get_camera_info(). 228 * 229 * Version information (based on camera_module_t.common.module_api_version): 230 * 231 * CAMERA_MODULE_API_VERSION_1_0: 232 * 233 * Not valid. Extra characteristics are not available. Do not read this 234 * field. 235 * 236 * CAMERA_MODULE_API_VERSION_2_0 or higher: 237 * 238 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read 239 * otherwise. 240 * 241 */ 242 const camera_metadata_t *static_camera_characteristics; 243 244 /** 245 * The total resource "cost" of using this camera, represented as an integer 246 * value in the range [0, 100] where 100 represents total usage of the shared 247 * resource that is the limiting bottleneck of the camera subsystem. This may 248 * be a very rough estimate, and is used as a hint to the camera service to 249 * determine when to disallow multiple applications from simultaneously 250 * opening different cameras advertised by the camera service. 251 * 252 * The camera service must be able to simultaneously open and use any 253 * combination of camera devices exposed by the HAL where the sum of 254 * the resource costs of these cameras is <= 100. For determining cost, 255 * each camera device must be assumed to be configured and operating at 256 * the maximally resource-consuming framerate and stream size settings 257 * available in the configuration settings exposed for that device through 258 * the camera metadata. 259 * 260 * The camera service may still attempt to simultaneously open combinations 261 * of camera devices with a total resource cost > 100. This may succeed or 262 * fail. If this succeeds, combinations of configurations that are not 263 * supported due to resource constraints from having multiple open devices 264 * should fail during the configure calls. If the total resource cost is 265 * <= 100, open and configure should never fail for any stream configuration 266 * settings or other device capabilities that would normally succeed for a 267 * device when it is the only open camera device. 268 * 269 * This field will be used to determine whether background applications are 270 * allowed to use this camera device while other applications are using other 271 * camera devices. Note: multiple applications will never be allowed by the 272 * camera service to simultaneously open the same camera device. 273 * 274 * Example use cases: 275 * 276 * Ex. 1: Camera Device 0 = Back Camera 277 * Camera Device 1 = Front Camera 278 * - Using both camera devices causes a large framerate slowdown due to 279 * limited ISP bandwidth. 280 * 281 * Configuration: 282 * 283 * Camera Device 0 - resource_cost = 51 284 * conflicting_devices = null 285 * Camera Device 1 - resource_cost = 51 286 * conflicting_devices = null 287 * 288 * Result: 289 * 290 * Since the sum of the resource costs is > 100, if a higher-priority 291 * application has either device open, no lower-priority applications will be 292 * allowed by the camera service to open either device. If a lower-priority 293 * application is using a device that a higher-priority subsequently attempts 294 * to open, the lower-priority application will be forced to disconnect the 295 * the device. 296 * 297 * If the highest-priority application chooses, it may still attempt to open 298 * both devices (since these devices are not listed as conflicting in the 299 * conflicting_devices fields), but usage of these devices may fail in the 300 * open or configure calls. 301 * 302 * Ex. 2: Camera Device 0 = Left Back Camera 303 * Camera Device 1 = Right Back Camera 304 * Camera Device 2 = Combined stereo camera using both right and left 305 * back camera sensors used by devices 0, and 1 306 * Camera Device 3 = Front Camera 307 * - Due to do hardware constraints, up to two cameras may be open at once. The 308 * combined stereo camera may never be used at the same time as either of the 309 * two back camera devices (device 0, 1), and typically requires too much 310 * bandwidth to use at the same time as the front camera (device 3). 311 * 312 * Configuration: 313 * 314 * Camera Device 0 - resource_cost = 50 315 * conflicting_devices = { 2 } 316 * Camera Device 1 - resource_cost = 50 317 * conflicting_devices = { 2 } 318 * Camera Device 2 - resource_cost = 100 319 * conflicting_devices = { 0, 1 } 320 * Camera Device 3 - resource_cost = 50 321 * conflicting_devices = null 322 * 323 * Result: 324 * 325 * Based on the conflicting_devices fields, the camera service guarantees that 326 * the following sets of open devices will never be allowed: { 1, 2 }, { 0, 2 }. 327 * 328 * Based on the resource_cost fields, if a high-priority foreground application 329 * is using camera device 0, a background application would be allowed to open 330 * camera device 1 or 3 (but would be forced to disconnect it again if the 331 * foreground application opened another device). 332 * 333 * The highest priority application may still attempt to simultaneously open 334 * devices 0, 2, and 3, but the HAL may fail in open or configure calls for 335 * this combination. 336 * 337 * Ex. 3: Camera Device 0 = Back Camera 338 * Camera Device 1 = Front Camera 339 * Camera Device 2 = Low-power Front Camera that uses the same 340 * sensor as device 1, but only exposes image stream 341 * resolutions that can be used in low-power mode 342 * - Using both front cameras (device 1, 2) at the same time is impossible due 343 * a shared physical sensor. Using the back and "high-power" front camera 344 * (device 1) may be impossible for some stream configurations due to hardware 345 * limitations, but the "low-power" front camera option may always be used as 346 * it has special dedicated hardware. 347 * 348 * Configuration: 349 * 350 * Camera Device 0 - resource_cost = 100 351 * conflicting_devices = null 352 * Camera Device 1 - resource_cost = 100 353 * conflicting_devices = { 2 } 354 * Camera Device 2 - resource_cost = 0 355 * conflicting_devices = { 1 } 356 * Result: 357 * 358 * Based on the conflicting_devices fields, the camera service guarantees that 359 * the following sets of open devices will never be allowed: { 1, 2 }. 360 * 361 * Based on the resource_cost fields, only the highest priority application 362 * may attempt to open both device 0 and 1 at the same time. If a higher-priority 363 * application is not using device 1 or 2, a low-priority background application 364 * may open device 2 (but will be forced to disconnect it if a higher-priority 365 * application subsequently opens device 1 or 2). 366 * 367 * Version information (based on camera_module_t.common.module_api_version): 368 * 369 * CAMERA_MODULE_API_VERSION_2_3 or lower: 370 * 371 * Not valid. Can be assumed to be 100. Do not read this field. 372 * 373 * CAMERA_MODULE_API_VERSION_2_4 or higher: 374 * 375 * Always valid. 376 */ 377 int resource_cost; 378 379 /** 380 * An array of camera device IDs represented as NULL-terminated strings 381 * indicating other devices that cannot be simultaneously opened while this 382 * camera device is in use. 383 * 384 * This field is intended to be used to indicate that this camera device 385 * is a composite of several other camera devices, or otherwise has 386 * hardware dependencies that prohibit simultaneous usage. If there are no 387 * dependencies, a NULL may be returned in this field to indicate this. 388 * 389 * The camera service will never simultaneously open any of the devices 390 * in this list while this camera device is open. 391 * 392 * The strings pointed to in this field will not be cleaned up by the camera 393 * service, and must remain while this device is plugged in. 394 * 395 * Version information (based on camera_module_t.common.module_api_version): 396 * 397 * CAMERA_MODULE_API_VERSION_2_3 or lower: 398 * 399 * Not valid. Can be assumed to be NULL. Do not read this field. 400 * 401 * CAMERA_MODULE_API_VERSION_2_4 or higher: 402 * 403 * Always valid. 404 */ 405 char** conflicting_devices; 406 407 /** 408 * The length of the array given in the conflicting_devices field. 409 * 410 * Version information (based on camera_module_t.common.module_api_version): 411 * 412 * CAMERA_MODULE_API_VERSION_2_3 or lower: 413 * 414 * Not valid. Can be assumed to be 0. Do not read this field. 415 * 416 * CAMERA_MODULE_API_VERSION_2_4 or higher: 417 * 418 * Always valid. 419 */ 420 size_t conflicting_devices_length; 421 422 } camera_info_t; 423 424 /** 425 * camera_device_status_t: 426 * 427 * The current status of the camera device, as provided by the HAL through the 428 * camera_module_callbacks.camera_device_status_change() call. 429 * 430 * At module load time, the framework will assume all camera devices are in the 431 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke 432 * camera_module_callbacks::camera_device_status_change to inform the framework 433 * of any initially NOT_PRESENT devices. 434 * 435 * Allowed transitions: 436 * PRESENT -> NOT_PRESENT 437 * NOT_PRESENT -> ENUMERATING 438 * NOT_PRESENT -> PRESENT 439 * ENUMERATING -> PRESENT 440 * ENUMERATING -> NOT_PRESENT 441 */ 442 typedef enum camera_device_status { 443 /** 444 * The camera device is not currently connected, and opening it will return 445 * failure. 446 * 447 * Version information (based on camera_module_t.common.module_api_version): 448 * 449 * CAMERA_MODULE_API_VERSION_2_3 or lower: 450 * 451 * Calls to get_camera_info must still succeed, and provide the same information 452 * it would if the camera were connected. 453 * 454 * CAMERA_MODULE_API_VERSION_2_4: 455 * 456 * The camera device at this status must return -EINVAL for get_camera_info call, 457 * as the device is not connected. 458 */ 459 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0, 460 461 /** 462 * The camera device is connected, and opening it will succeed. 463 * 464 * CAMERA_MODULE_API_VERSION_2_3 or lower: 465 * 466 * The information returned by get_camera_info cannot change due to this status 467 * change. By default, the framework will assume all devices are in this state. 468 * 469 * CAMERA_MODULE_API_VERSION_2_4: 470 * 471 * The information returned by get_camera_info will become valid after a device's 472 * status changes to this. By default, the framework will assume all devices are in 473 * this state. 474 */ 475 CAMERA_DEVICE_STATUS_PRESENT = 1, 476 477 /** 478 * The camera device is connected, but it is undergoing an enumeration and 479 * so opening the device will return -EBUSY. 480 * 481 * CAMERA_MODULE_API_VERSION_2_3 or lower: 482 * 483 * Calls to get_camera_info must still succeed, as if the camera was in the 484 * PRESENT status. 485 * 486 * CAMERA_MODULE_API_VERSION_2_4: 487 * 488 * The camera device at this status must return -EINVAL for get_camera_info for call, 489 * as the device is not ready. 490 */ 491 CAMERA_DEVICE_STATUS_ENUMERATING = 2, 492 493 } camera_device_status_t; 494 495 /** 496 * torch_mode_status_t: 497 * 498 * The current status of the torch mode, as provided by the HAL through the 499 * camera_module_callbacks.torch_mode_status_change() call. 500 * 501 * The torch mode status of a camera device is applicable only when the camera 502 * device is present. The framework will not call set_torch_mode() to turn on 503 * torch mode of a camera device if the camera device is not present. At module 504 * load time, the framework will assume torch modes are in the 505 * TORCH_MODE_STATUS_AVAILABLE_OFF state if the camera device is present and 506 * android.flash.info.available is reported as true via get_camera_info() call. 507 * 508 * The behaviors of the camera HAL module that the framework expects in the 509 * following situations when a camera device's status changes: 510 * 1. A previously-disconnected camera device becomes connected. 511 * After camera_module_callbacks::camera_device_status_change() is invoked 512 * to inform the framework that the camera device is present, the framework 513 * will assume the camera device's torch mode is in 514 * TORCH_MODE_STATUS_AVAILABLE_OFF state. The camera HAL module does not need 515 * to invoke camera_module_callbacks::torch_mode_status_change() unless the 516 * flash unit is unavailable to use by set_torch_mode(). 517 * 518 * 2. A previously-connected camera becomes disconnected. 519 * After camera_module_callbacks::camera_device_status_change() is invoked 520 * to inform the framework that the camera device is not present, the 521 * framework will not call set_torch_mode() for the disconnected camera 522 * device until its flash unit becomes available again. The camera HAL 523 * module does not need to invoke 524 * camera_module_callbacks::torch_mode_status_change() separately to inform 525 * that the flash unit has become unavailable. 526 * 527 * 3. open() is called to open a camera device. 528 * The camera HAL module must invoke 529 * camera_module_callbacks::torch_mode_status_change() for all flash units 530 * that have entered TORCH_MODE_STATUS_NOT_AVAILABLE state and can not be 531 * turned on by calling set_torch_mode() anymore due to this open() call. 532 * open() must not trigger TORCH_MODE_STATUS_AVAILABLE_OFF before 533 * TORCH_MODE_STATUS_NOT_AVAILABLE for all flash units that have become 534 * unavailable. 535 * 536 * 4. close() is called to close a camera device. 537 * The camera HAL module must invoke 538 * camera_module_callbacks::torch_mode_status_change() for all flash units 539 * that have entered TORCH_MODE_STATUS_AVAILABLE_OFF state and can be turned 540 * on by calling set_torch_mode() again because of enough resources freed 541 * up by this close() call. 542 * 543 * Note that the framework calling set_torch_mode() successfully must trigger 544 * TORCH_MODE_STATUS_AVAILABLE_OFF or TORCH_MODE_STATUS_AVAILABLE_ON callback 545 * for the given camera device. Additionally it must trigger 546 * TORCH_MODE_STATUS_AVAILABLE_OFF callbacks for other previously-on torch 547 * modes if HAL cannot keep multiple torch modes on simultaneously. 548 */ 549 typedef enum torch_mode_status { 550 551 /** 552 * The flash unit is no longer available and the torch mode can not be 553 * turned on by calling set_torch_mode(). If the torch mode is on, it 554 * will be turned off by HAL before HAL calls torch_mode_status_change(). 555 */ 556 TORCH_MODE_STATUS_NOT_AVAILABLE = 0, 557 558 /** 559 * A torch mode has become off and available to be turned on via 560 * set_torch_mode(). This may happen in the following 561 * cases: 562 * 1. After the resources to turn on the torch mode have become available. 563 * 2. After set_torch_mode() is called to turn off the torch mode. 564 * 3. After the framework turned on the torch mode of some other camera 565 * device and HAL had to turn off the torch modes of any camera devices 566 * that were previously on. 567 */ 568 TORCH_MODE_STATUS_AVAILABLE_OFF = 1, 569 570 /** 571 * A torch mode has become on and available to be turned off via 572 * set_torch_mode(). This can happen only after set_torch_mode() is called 573 * to turn on the torch mode. 574 */ 575 TORCH_MODE_STATUS_AVAILABLE_ON = 2, 576 577 } torch_mode_status_t; 578 579 /** 580 * Callback functions for the camera HAL module to use to inform the framework 581 * of changes to the camera subsystem. 582 * 583 * Version information (based on camera_module_t.common.module_api_version): 584 * 585 * Each callback is called only by HAL modules implementing the indicated 586 * version or higher of the HAL module API interface. 587 * 588 * CAMERA_MODULE_API_VERSION_2_1: 589 * camera_device_status_change() 590 * 591 * CAMERA_MODULE_API_VERSION_2_4: 592 * torch_mode_status_change() 593 594 */ 595 typedef struct camera_module_callbacks { 596 597 /** 598 * camera_device_status_change: 599 * 600 * Callback to the framework to indicate that the state of a specific camera 601 * device has changed. At module load time, the framework will assume all 602 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL 603 * must call this method to inform the framework of any initially 604 * NOT_PRESENT devices. 605 * 606 * This callback is added for CAMERA_MODULE_API_VERSION_2_1. 607 * 608 * camera_module_callbacks: The instance of camera_module_callbacks_t passed 609 * to the module with set_callbacks. 610 * 611 * camera_id: The ID of the camera device that has a new status. 612 * 613 * new_status: The new status code, one of the camera_device_status_t enums, 614 * or a platform-specific status. 615 * 616 */ 617 void (*camera_device_status_change)(const struct camera_module_callbacks*, 618 int camera_id, 619 int new_status); 620 621 /** 622 * torch_mode_status_change: 623 * 624 * Callback to the framework to indicate that the state of the torch mode 625 * of the flash unit associated with a specific camera device has changed. 626 * At module load time, the framework will assume the torch modes are in 627 * the TORCH_MODE_STATUS_AVAILABLE_OFF state if android.flash.info.available 628 * is reported as true via get_camera_info() call. 629 * 630 * This callback is added for CAMERA_MODULE_API_VERSION_2_4. 631 * 632 * camera_module_callbacks: The instance of camera_module_callbacks_t 633 * passed to the module with set_callbacks. 634 * 635 * camera_id: The ID of camera device whose flash unit has a new torch mode 636 * status. 637 * 638 * new_status: The new status code, one of the torch_mode_status_t enums. 639 */ 640 void (*torch_mode_status_change)(const struct camera_module_callbacks*, 641 const char* camera_id, 642 int new_status); 643 644 645 } camera_module_callbacks_t; 646 647 typedef struct camera_module { 648 /** 649 * Common methods of the camera module. This *must* be the first member of 650 * camera_module as users of this structure will cast a hw_module_t to 651 * camera_module pointer in contexts where it's known the hw_module_t 652 * references a camera_module. 653 * 654 * The return values for common.methods->open for camera_module are: 655 * 656 * 0: On a successful open of the camera device. 657 * 658 * -ENODEV: The camera device cannot be opened due to an internal 659 * error. 660 * 661 * -EINVAL: The input arguments are invalid, i.e. the id is invalid, 662 * and/or the module is invalid. 663 * 664 * -EBUSY: The camera device was already opened for this camera id 665 * (by using this method or open_legacy), 666 * regardless of the device HAL version it was opened as. 667 * 668 * -EUSERS: The maximal number of camera devices that can be 669 * opened concurrently were opened already, either by 670 * this method or the open_legacy method. 671 * 672 * All other return values from common.methods->open will be treated as 673 * -ENODEV. 674 */ 675 hw_module_t common; 676 677 /** 678 * get_number_of_cameras: 679 * 680 * Returns the number of camera devices accessible through the camera 681 * module. The camera devices are numbered 0 through N-1, where N is the 682 * value returned by this call. The name of the camera device for open() is 683 * simply the number converted to a string. That is, "0" for camera ID 0, 684 * "1" for camera ID 1. 685 * 686 * Version information (based on camera_module_t.common.module_api_version): 687 * 688 * CAMERA_MODULE_API_VERSION_2_3 or lower: 689 * 690 * The value here must be static, and cannot change after the first call 691 * to this method. 692 * 693 * CAMERA_MODULE_API_VERSION_2_4 or higher: 694 * 695 * The value here must be static, and must count only built-in cameras, 696 * which have CAMERA_FACING_BACK or CAMERA_FACING_FRONT camera facing values 697 * (camera_info.facing). The HAL must not include the external cameras 698 * (camera_info.facing == CAMERA_FACING_EXTERNAL) into the return value 699 * of this call. Frameworks will use camera_device_status_change callback 700 * to manage number of external cameras. 701 */ 702 int (*get_number_of_cameras)(void); 703 704 /** 705 * get_camera_info: 706 * 707 * Return the static camera information for a given camera device. This 708 * information may not change for a camera device. 709 * 710 * Return values: 711 * 712 * 0: On a successful operation 713 * 714 * -ENODEV: The information cannot be provided due to an internal 715 * error. 716 * 717 * -EINVAL: The input arguments are invalid, i.e. the id is invalid, 718 * and/or the module is invalid. 719 * 720 * Version information (based on camera_module_t.common.module_api_version): 721 * 722 * CAMERA_MODULE_API_VERSION_2_4 or higher: 723 * 724 * When a camera is disconnected, its camera id becomes invalid. Calling this 725 * this method with this invalid camera id will get -EINVAL and NULL camera 726 * static metadata (camera_info.static_camera_characteristics). 727 */ 728 int (*get_camera_info)(int camera_id, struct camera_info *info); 729 730 /** 731 * set_callbacks: 732 * 733 * Provide callback function pointers to the HAL module to inform framework 734 * of asynchronous camera module events. The framework will call this 735 * function once after initial camera HAL module load, after the 736 * get_number_of_cameras() method is called for the first time, and before 737 * any other calls to the module. 738 * 739 * Version information (based on camera_module_t.common.module_api_version): 740 * 741 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0: 742 * 743 * Not provided by HAL module. Framework may not call this function. 744 * 745 * CAMERA_MODULE_API_VERSION_2_1: 746 * 747 * Valid to be called by the framework. 748 * 749 * Return values: 750 * 751 * 0: On a successful operation 752 * 753 * -ENODEV: The operation cannot be completed due to an internal 754 * error. 755 * 756 * -EINVAL: The input arguments are invalid, i.e. the callbacks are 757 * null 758 */ 759 int (*set_callbacks)(const camera_module_callbacks_t *callbacks); 760 761 /** 762 * get_vendor_tag_ops: 763 * 764 * Get methods to query for vendor extension metadata tag information. The 765 * HAL should fill in all the vendor tag operation methods, or leave ops 766 * unchanged if no vendor tags are defined. 767 * 768 * The vendor_tag_ops structure used here is defined in: 769 * system/media/camera/include/system/vendor_tags.h 770 * 771 * Version information (based on camera_module_t.common.module_api_version): 772 * 773 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1: 774 * Not provided by HAL module. Framework may not call this function. 775 * 776 * CAMERA_MODULE_API_VERSION_2_2: 777 * Valid to be called by the framework. 778 */ 779 void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops); 780 781 /** 782 * open_legacy: 783 * 784 * Open a specific legacy camera HAL device if multiple device HAL API 785 * versions are supported by this camera HAL module. For example, if the 786 * camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and 787 * CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id, 788 * framework can call this function to open the camera device as 789 * CAMERA_DEVICE_API_VERSION_1_0 device. 790 * 791 * This is an optional method. A Camera HAL module does not need to support 792 * more than one device HAL version per device, and such modules may return 793 * -ENOSYS for all calls to this method. For all older HAL device API 794 * versions that are not supported, it may return -EOPNOTSUPP. When above 795 * cases occur, The normal open() method (common.methods->open) will be 796 * used by the framework instead. 797 * 798 * Version information (based on camera_module_t.common.module_api_version): 799 * 800 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2: 801 * Not provided by HAL module. Framework will not call this function. 802 * 803 * CAMERA_MODULE_API_VERSION_2_3: 804 * Valid to be called by the framework. 805 * 806 * Return values: 807 * 808 * 0: On a successful open of the camera device. 809 * 810 * -ENOSYS This method is not supported. 811 * 812 * -EOPNOTSUPP: The requested HAL version is not supported by this method. 813 * 814 * -EINVAL: The input arguments are invalid, i.e. the id is invalid, 815 * and/or the module is invalid. 816 * 817 * -EBUSY: The camera device was already opened for this camera id 818 * (by using this method or common.methods->open method), 819 * regardless of the device HAL version it was opened as. 820 * 821 * -EUSERS: The maximal number of camera devices that can be 822 * opened concurrently were opened already, either by 823 * this method or common.methods->open method. 824 */ 825 int (*open_legacy)(const struct hw_module_t* module, const char* id, 826 uint32_t halVersion, struct hw_device_t** device); 827 828 /** 829 * set_torch_mode: 830 * 831 * Turn on or off the torch mode of the flash unit associated with a given 832 * camera ID. If the operation is successful, HAL must notify the framework 833 * torch state by invoking 834 * camera_module_callbacks.torch_mode_status_change() with the new state. 835 * 836 * The camera device has a higher priority accessing the flash unit. When 837 * there are any resource conflicts, such as open() is called to open a 838 * camera device, HAL module must notify the framework through 839 * camera_module_callbacks.torch_mode_status_change() that the 840 * torch mode has been turned off and the torch mode state has become 841 * TORCH_MODE_STATUS_NOT_AVAILABLE. When resources to turn on torch mode 842 * become available again, HAL module must notify the framework through 843 * camera_module_callbacks.torch_mode_status_change() that the torch mode 844 * state has become TORCH_MODE_STATUS_AVAILABLE_OFF for set_torch_mode() to 845 * be called. 846 * 847 * When the framework calls set_torch_mode() to turn on the torch mode of a 848 * flash unit, if HAL cannot keep multiple torch modes on simultaneously, 849 * HAL should turn off the torch mode that was turned on by 850 * a previous set_torch_mode() call and notify the framework that the torch 851 * mode state of that flash unit has become TORCH_MODE_STATUS_AVAILABLE_OFF. 852 * 853 * Version information (based on camera_module_t.common.module_api_version): 854 * 855 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3: 856 * Not provided by HAL module. Framework will not call this function. 857 * 858 * CAMERA_MODULE_API_VERSION_2_4: 859 * Valid to be called by the framework. 860 * 861 * Return values: 862 * 863 * 0: On a successful operation. 864 * 865 * -ENOSYS: The camera device does not support this operation. It is 866 * returned if and only if android.flash.info.available is 867 * false. 868 * 869 * -EBUSY: The camera device is already in use. 870 * 871 * -EUSERS: The resources needed to turn on the torch mode are not 872 * available, typically because other camera devices are 873 * holding the resources to make using the flash unit not 874 * possible. 875 * 876 * -EINVAL: camera_id is invalid. 877 * 878 */ 879 int (*set_torch_mode)(const char* camera_id, bool enabled); 880 881 /** 882 * init: 883 * 884 * This method is called by the camera service before any other methods 885 * are invoked, right after the camera HAL library has been successfully 886 * loaded. It may be left as NULL by the HAL module, if no initialization 887 * in needed. 888 * 889 * It can be used by HAL implementations to perform initialization and 890 * other one-time operations. 891 * 892 * Version information (based on camera_module_t.common.module_api_version): 893 * 894 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3: 895 * Not provided by HAL module. Framework will not call this function. 896 * 897 * CAMERA_MODULE_API_VERSION_2_4: 898 * If not NULL, will always be called by the framework once after the HAL 899 * module is loaded, before any other HAL module method is called. 900 * 901 * Return values: 902 * 903 * 0: On a successful operation. 904 * 905 * -ENODEV: Initialization cannot be completed due to an internal 906 * error. The HAL must be assumed to be in a nonfunctional 907 * state. 908 * 909 */ 910 int (*init)(); 911 912 /* reserved for future use */ 913 void* reserved[5]; 914 } camera_module_t; 915 916 __END_DECLS 917 918 #endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */ 919