博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Camera
阅读量:6949 次
发布时间:2019-06-27

本文共 5750 字,大约阅读时间需要 19 分钟。

Camera

Android's camera Hardware Abstraction Layer (HAL) connects the higher level camera framework APIs in to your underlying camera driver and hardware. The camera subsystem includes implementations for camera pipeline components while the camera HAL provides interfaces for use in implementing your version of these components.

Architecture


The following figure and list describe the HAL components:

Figure 1. Camera architecture

Application framework
At the application framework level is the app's code, which utilizes the 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 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 object at the framework level.
Native framework
The native framework defined in
frameworks/av/camera/Camera.cpp provides a native equivalent to the 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 and NV21 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 and hardware/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 . This header file declares a camera_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 in hardware/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.
    LOCAL_MODULE_RELATIVE_PATH := 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 the frameworks/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 in device/<company_name>/<device_name>/media_profiles.xml and device/<company_name>/<device_name>/media_codecs.xml XML files. For more information, see 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 += \ /
    /
    /media_profiles.xml:system/etc/media_profiles.xml # media codec config xml file PRODUCT_COPY_FILES += \
    /
    /
    /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 the PRODUCT_PACKAGES variable in your device's device/<company_name>/<device_name>/device.mk Makefile:

    PRODUCT_PACKAGES := \ Gallery2 \ ...

转载地址:http://irkil.baihongyu.com/

你可能感兴趣的文章
第一章代码重构
查看>>
【益智题】十块钱去哪了?
查看>>
静态密码已经"OUT" 探索身份验证新方式
查看>>
轻松搞定RabbitMQ(四)——发布/订阅
查看>>
projecteuler_problem12
查看>>
VN2VN——中小企业的网络融合之道
查看>>
数百亿的新疆安防市场,集成巨头告诉你如何才能从中分杯羹
查看>>
[译] REST API 已死,GraphQL 长存
查看>>
学点PYTHON基础的东东--数据结构,算法,设计模式---访问者模式
查看>>
独家 | 陆化普:大数据、AI解决交通管理难题的新思路
查看>>
你需要的不是大数据 而是正确的数据~
查看>>
我只能说,Spring Data REST真的很燥辣
查看>>
使用短生命周期容器(Ephemeral Containers)构建微服务化的工作流
查看>>
R语言领跑 大数据岗位霸占IT薪酬榜单
查看>>
靠播放业务吃不饱?音乐流媒体纷纷“加电商”卖周边
查看>>
SSL之父称SSL不会因被攻击而失去生命力
查看>>
解读对象存储九大关键特征
查看>>
重构计算力 浪潮M5新一代服务器闪耀登场
查看>>
品高云产品经理邱洋:做国内云计算第一品牌
查看>>
大数据挑战:敢不敢不要加入人的判断?
查看>>