Camera HAL overview

Android Camera HAL 是连接相机框架与底层驱动的接口,实现HAL需定义接口供上层应用操作相机硬件。主要组件包括:实现HAL接口的代码,配置共享库。HAL接口在`<hardware/interfaces/camera`>头文件中定义,`camera.h`包含`camera_info`结构体,用于获取相机基本信息。`camera_device`结构体包含指向实现HAL接口的函数指针。配置共享库时,创建Android Makefile来构建库并将其复制到正确位置,同时更新设备Makefile声明相机特性、媒体编解码能力,并包含Camera应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Copy From :http://source.android.com/devices/camera/camera.html


Android's camera HAL connects the higher level camera framework APIs in android.hardware to your underlying camera driver and hardware. The following figure and list describe the components involved and where to find the source for each:


Application framework
At the application framework level is the app's code, which utilizes the  android.hardware.Camera API to interact with the camera hardware. Internally, this code calls a corresponding JNI glue class to access the native code that interacts with the camera.
JNI
The JNI code associated with  android.hardware.Camera is located in frameworks/base/core/jni/android_hardware_Camera.cpp. This code calls the lower level native code to obtain access to the physical camera and returns data that is used to create the  android.hardware.Cameraobject at the framework level.
Native framework
The native framework defined in  frameworks/av/camera/Camera.cpp provides a native equivalent to the android.hardware.Camera class. This class calls the IPC binder proxies to obtain access to the camera service.
Binder IPC proxies
The IPC binder proxies facilitate communication over process boundaries. There are three camera binder classes that are located in the  frameworks/av/camera directory that calls into camera service. ICameraService is the interface to the camera service, ICamera is the interface to a specific opened camera device, and ICameraClient is the device's interface back to the application framework.
Camera service
The camera service, located in  frameworks/av/services/camera/libcameraservice/CameraService.cpp, is the actual code that interacts with the HAL.

HAL
The hardware abstraction layer defines the standard interface that the camera service calls into and that you must implement to have your camera hardware function correctly.
Kernel driver
The camera's driver interacts with the actual camera hardware and your implementation of the HAL. The camera and driver must support YV12[yuv420sp] and NV21[yuv420p] image formats to provide support for previewing the camera image on the display and video recording.

Implementing the HAL


The HAL sits between the camera driver and the higher level Android framework and defines an interface that you must implement so that apps can correctly operate the camera hardware. The HAL interface is defined in the hardware/libhardware/include/hardware/camera.h andhardware/libhardware/include/hardware/camera_common.h header files.

camera_common.h defines an important struct, camera_module, which defines a standard structure to obtain general information about the camera, such as its ID and properties that are common to all cameras such as whether or not it is a front or back-facing camera.

camera.h contains the code that corresponds mainly with android.hardware.Camera. This header file declares acamera_device struct that contains a camera_device_ops struct with function pointers that point to functions that implement the HAL interface. For documentation on the different types of camera parameters that a developer can set, see the frameworks/av/include/camera/CameraParameters.h file. These parameters are set with the function pointed to by int (*set_parameters)(struct camera_device *, const char *parms) in the HAL.

For an example of a HAL implementation, see the implementation for the Galaxy Nexus HAL inhardware/ti/omap4xxx/camera.

Configuring the Shared Library


You need to set up the Android build system to correctly package the HAL implementation into a shared library and copy it to the appropriate location by creating an Android.mk file:

  1. Create a device/<company_name>/<device_name>/camera directory to contain your library's source files.
  2. Create an Android.mk file to build the shared library. Ensure that the Makefile contains the following lines:
    LOCAL_MODULE := camera.<device_name>
    LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw

    Notice that your library must be named camera.<device_name> (.so is appended automatically), so that Android can correctly load the library. For an example, see the Makefile for the Galaxy Nexus camera located in hardware/ti/omap4xxx/Android.mk.

  3. Specify that your device has camera features by copying the necessary feature XML files in theframeworks/native/data/etc directory with your device's Makefile. For example, to specify that your device has a camera flash and can autofocus, add the following lines in your device's<device>/<company_name>/<device_name>/device.mk Makefile:
    PRODUCT_COPY_FILES := \ ...
    
    PRODUCT_COPY_FILES += \
    frameworks/native/data/etc/android.hardware.camera.flash-autofocus.xml:system/etc/permissions/android.hardware.camera.flash-autofocus.xml \    
    

    For an example of a device Makefile, see device/samsung/tuna/device.mk.

  4. Declare your camera’s media codec, format, and resolution capabilities indevice/<company_name>/<device_name>/media_profiles.xml anddevice/<company_name>/<device_name>/media_codecs.xml XML files. For more information, see Exposing Codecs and Profiles to the Framework for information on how to do this.

  5. Add the following lines in your device's device/<company_name>/<device_name>/device.mk Makefile to copy the media_profiles.xml and media_codecs.xml files to the appropriate location:
    # media config xml file
    PRODUCT_COPY_FILES += \
        <device>/<company_name>/<device_name>/media_profiles.xml:system/etc/media_profiles.xml
    
    # media codec config xml file
    PRODUCT_COPY_FILES += \
        <device>/<company_name>/<device_name>/media_codecs.xml:system/etc/media_codecs.xml
  6. Declare that you want to include the Camera app in your device's system image by specifying it in thePRODUCT_PACKAGES variable in your device's device/<company_name>/<device_name>/device.mk Makefile:

    PRODUCT_PACKAGES := \
    Gallery2 \
    ...


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值