Android 的相机硬件抽象层 (HAL) 可将 android.hardware.camera2 中较高级别的相机框架 API 连接到底层的相机驱动程序和硬件。从 Android 13 开始,相机 HAL 接口使用 AIDL 进行开发。Android 8.0 引入了 Treble,用于将 Camera HAL API 切换到由 HAL 接口描述语言 (HIDL) 定义的稳定接口。
如果您之前为 Android 7.0 及更低版本开发过相机 HAL 模块和驱动程序,请注意相机管道中发生的重大变化。
AIDL 相机 HAL
对于搭载 Android 13 或更高版本的设备,该相机框架包含对 AIDL 相机 HAL 的支持。该相机框架还支持 HIDL 相机 HAL,不过,在 Android 13 或更高版本中添加的相机功能只能通过 AIDL 相机 HAL 接口使用。如需在升级到 Android 13 或更高版本的设备上实现此类功能,设备制造商必须将其 HAL 进程从使用 HIDL 相机接口迁移到使用 AIDL 相机接口。
重新设计 Android Camera API 的目的在于大幅提高应用对于 Android 设备上的相机子系统的控制能力,同时重新组织 API,提高其效率和可维护性。借助额外的控制能力,您可以更轻松地在 Android 设备上构建高品质的相机应用,这些应用可在多种产品上稳定运行,同时仍会尽可能使用设备专用算法来最大限度地提升质量和性能。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Camera HAL\n\nAndroid's camera hardware abstraction layer (HAL) connects the higher level\ncamera framework APIs in\n[android.hardware.camera2](https://developer.android.com/reference/android/hardware/camera2/package-summary)\nto your underlying camera driver and hardware.\nStarting with Android 13, camera HAL interface\ndevelopment uses [AIDL](#aidl-camera-hal). Android 8.0 introduced\n[Treble](/docs/core/architecture#hidl), switching the Camera HAL API\nto a stable interface defined by the HAL interface description language (HIDL).\nIf you've previously developed a camera HAL module and driver for Android 7.0\nand lower, be aware of significant\nchanges in the camera pipeline.\n\nAIDL camera HAL\n---------------\n\n\nFor devices running Android 13 or higher, the camera\nframework includes support for AIDL camera HALs. The camera framework also\nsupports HIDL camera HALs, however camera features added in\nAndroid 13 or higher are available only through the\nAIDL camera HAL interfaces. To implement such features on devices upgrading to\nAndroid 13 or higher, device manufacturers must\nmigrate their HAL process from using HIDL camera interfaces to AIDL camera\ninterfaces.\n\n\nTo learn about the advantages of AIDL, see\n[AIDL for HALs](/docs/core/architecture/aidl/aidl-hals#motivation).\n\n### Implement AIDL camera HAL\n\n\nFor a reference implementation of an AIDL camera HAL, see\n[`hardware/google/camera/common/hal/aidl_service/`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/google/camera/common/hal/aidl_service/).\n\n\nThe AIDL camera HAL specifications are in the following locations:\n\n- Camera provider: [`hardware/interfaces/camera/provider/aidl/`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/provider/aidl/)\n- Camera device: [`hardware/interfaces/camera/device/aidl/`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/device/aidl/)\n- Camera metadata: [`hardware/interfaces/camera/metadata/aidl/`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/metadata/aidl/)\n- Common data types: [`hardware/interfaces/camera/common/aidl/`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/common/aidl/)\n\n\nFor devices migrating to AIDL, device manufacturers might need to modify the\n[Android SELinux policy (sepolicy)](https://cs.android.com/android/platform/superproject/+/android-latest-release:system/sepolicy/) and RC files depending on the code\nstructure.\n\n### Validate AIDL camera HAL\n\n\nTo test your AIDL camera HAL implementation, ensure that the device passes all\nCTS and VTS tests. Android 13 introduces the AIDL VTS\ntest,\n[`VtsAidlHalCameraProvider_TargetTest.cpp`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp).\n\nCamera HAL3 features\n--------------------\n\nThe aim of the Android Camera API redesign is to substantially increase the\nability of apps to control the camera subsystem on Android devices while\nreorganizing the API to make it more efficient and maintainable. The additional\ncontrol makes it easier to build high-quality camera apps on Android\ndevices that can operate reliably across multiple products while still using\ndevice-specific algorithms whenever possible to maximize quality and\nperformance.\n\nVersion 3 of the camera subsystem structures the operation modes into a\nsingle unified view, which can be used to implement any of the previous modes\nand several others, such as burst mode. This results in better user control for\nfocus and exposure and more post-processing, such as noise reduction, contrast\nand sharpening. Further, this simplified view makes it easier for application\ndevelopers to use the camera's various functions.\n\nThe API models the camera subsystem as a pipeline that converts incoming\nrequests for frame captures into frames, on a 1:1 basis. The requests\nencapsulate all configuration information about the capture and processing of a\nframe. This includes resolution and pixel format; manual sensor, lens and flash\ncontrol; 3A operating modes; RAW-\\\u003eYUV processing control; statistics generation;\nand so on.\n\nIn simple terms, the application framework requests a frame from the camera\nsubsystem, and the camera subsystem returns results to an output stream. In\naddition, metadata that contains information such as color spaces and lens\nshading is generated for each set of results. You can think of camera version 3\nas a pipeline to camera version 1's one-way stream. It converts each capture\nrequest into one image captured by the sensor, which is processed into:\n\n- A result object with metadata about the capture.\n- One to N buffers of image data, each into its own destination surface.\n\nThe set of possible output surfaces is preconfigured:\n\n- Each surface is a destination for a stream of image buffers of a fixed resolution.\n- Only a small number of surfaces can be configured as outputs at once (\\~3).\n\nA request contains all desired capture settings and the list of output\nsurfaces to push image buffers into for this request (out of the total\nconfigured set). A request can be one-shot (with `capture()`), or it\nmay be repeated indefinitely (with `setRepeatingRequest()`). Captures\nhave priority over repeating requests.\n\n**Figure 1.** Camera core operation model\n\nCamera HAL1 overview\n--------------------\n\n| **Note:** As Camera HAL1 has been deprecated, Camera HAL3 is recommended for devices launching on Android 9 or higher.\n\nVersion 1 of the camera subsystem was designed as a black box with high-level\ncontrols and the following three operating modes:\n\n- Preview\n- Video Record\n- Still Capture\n\nEach mode has slightly different and overlapping capabilities. This made it\nhard to implement new features such as burst mode, which falls between two of\nthe operating modes.\n\n**Figure 2.** Camera components\n\nAndroid 7.0 continues to support camera HAL1 as many devices still rely on\nit. In addition, the Android camera service supports implementing both HALs (1\nand 3), which is useful when you want to support a less-capable front-facing\ncamera with camera HAL1 and a more advanced back-facing camera with camera\nHAL3.\n\nThere is a single camera HAL *module* (with its own\n[version\nnumber](/docs/core/camera/versioning#module_version)), which lists multiple independent camera devices that each have\ntheir own version number. Camera module 2 or newer is required to support\ndevices 2 or newer, and such camera modules can have a mix of camera device\nversions (this is what we mean when we say Android supports implementing both\nHALs)."]]