Camera service-Architecture Analysis

Source: Internet
Author: User

From: http://blog.csdn.net/ljsbuct/article/details/7094670

I. Application Layer

The application layer of camera is a camera application APK package developed by directly calling SDK APIs on Android. The code is in/Android/packages/apps/camera. It mainly calls the Android. Hardware. Camera (in the Framework) class and implements the business logic and UI display of the camera application. To use this android SDK in an Android app. hardware. for the camera class, you need to declare the permissions of camera in the manifest file. In addition, you need to add some <uses-feature> elements to declare the camera features in the application, such as auto focus. The procedure is as follows:

<Uses-Permission Android: Name = "android. Permission. Camera"/>

<Uses-feature Android: Name = "android. Hardware. Camera"/>

<Uses-feature Android: Name = "android. Hardware. Camera. autofocus"/>

Ii. Framework Layer

1. Android. Hardware. Camera: Code Location/Android/frameworks/base/CORE/Java/Android/hardware/camera. Java

The target part is framework. jar. This is the Java interface that android provides to the app layer to call. This class is used to connect to or disconnect a camera service, set shooting parameters, start, stop previewing, and take photos.

2. The Android. Hardware. Camera class is the same as the class defined in JNI. Some methods call local code through JNI, and some methods are implemented by themselves.
Java Native calling part of camera (JNI):/Android/frameworks/base/CORE/JNI/android_hardware_camera.cpp. Camera. Java serves as a bridge between Java code and C ++ code. Compile and generate libandroid_runtime.so. The libandroid_runtime.so library is public. Besides camera, it has other functions.

3. Client section of the camera framework:

Code path:/Android/frameworks/base/libs/camera/the next five files.

Camera. cpp

Cameraparameters. cpp

Icamera. cpp

Icameraclient. cpp

Icameraservice. cpp

Their header files are in the/Android/frameworks/base/include/camera directory.

This part of content is compiled to generate libcamera_client.so. In each library of the camera module, libcamera_client.so is at the core position. It is used as the client part of the camera framework and libcameraservice of the other content server. so communication is performed through inter-process communication (that is, the Binder Mechanism.

4. Service Section of the camera framework:

Code path:/Android/frameworks/base/services/camera/libcameraservice.

This part of content is compiled into the library libcameraservice. So. Cameraservice is a camera service and the middle layer of the camera framework. It is used to link camerahardwareinterface and client. It calls the actual camera hardware interface to implement functions, that is, the lower-Layer HAL layer.

Iii. Hardware Abstraction Layer HAL Hardware Abstraction action Layer

This level is actually the driver code of the user space. We have previously introduced the framework layer pairs in camerahardwareinterface. H (/Android/frameworks/base/include/camera/camerahardwareinterface. h ). The header file defines the interface of the camera hardware abstraction layer. It is a class containing pure virtual functions and must be inherited by the Implementation class before it can be used. The Hal layer inherits the camerahardwareinterface interface, instantiates the underlying hardware driver according to the v4l2 specification, calls the driver using ioctl, and finally generates libcamera. So for the libcameraservice. So call of the framework.

The code for this layer is stored in the/Android/hardware/XXX/libcamera directory (it may also be in the libcamera directory corresponding to the vendor directory ). Note that XXX is the directory created by different manufacturers for different products (boards). Take the Qualcomm MSM platform as an example. Here XXX is represented by msm7k, in this way, the Hal directory under the Qualcomm MSM platform is/Android/hardware/msm7k/libcamera. It is not hard to see that if you want to run Android on a hardware platform, it is mainly modified at this layer because it is directly related to the underlying hardware driver. As mentioned above, the application framework layer defines the standard interfaces for both the upper and lower layers.
The Code on the upper layer is independent and is not affected in porting. So now we can basically make sure that if we want to change the camera hardware, the above part of the framework layer can not be changed. If we want to change it, we need to change the part from Hal to the kernel layer, this is also the main work of Android underlying development.

Iv. Driver Layer

This layer is mainly based on Linux device drivers. For camera, the camera atomic function is exposed in the form of ioctl in accordance with the v4l2 specification for the implementation of Hal layer calls.

The main function implementation code is in/Android/kernel/Drivers/Media/Video/xxx. Like the Hal directory, XXX is the directory of different platforms of different manufacturers. Taking the Qualcomm MSM platform as an example, this directory is/Android/kernel/Drivers/Media/Video/MSM. Therefore, to add hardware functions on the Android platform, first consider adding its driver to the Linux kernel of Android.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.