Android 的相機硬體抽象層 (HAL) 會將 android.hardware.camera2 中較高層級的相機架構 API 連結至基礎相機驅動程式和硬體。從 Android 13 開始,相機 HAL 介面開發作業會使用 AIDL。Android 8.0 推出了 Treble,將相機 HAL API 切換至由 HAL 介面描述語言 (HIDL) 定義的穩定介面。如果您先前為 Android 7.0 以下版本開發相機 HAL 模組和驅動程式,請注意相機管道中的重大變更。
重新設計 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"]],["上次更新時間:2025-06-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)."]]