Camera Service--an analysis of architecture

Source: Internet
Author: User

 Camera Service--an analysis of architectureCategory: Camera analysis 2011-12-22 11:17 7685 people read reviews (3) favorite reports Android Hardware driver Framework Jnilinux kernel platform

I. Application layer

The application layer of the camera is shown on Android as a camera app APK package that directly invokes SDK API development. The code is under/android/packages/apps/camera. Calls primarily to Android.hardware.Camera (in the framework) class, and implements the business logic and UI display for the Camera app. In an Android app to use this Android.hardware.Camera class, you need to declare the permissions of the camera in the manifest file, plus some additional <uses-feature> element to declare camera features in your app, such as autofocus. This can be done as follows:

<uses-permission android:name = "Android.permission.CAMERA"/>

<uses-feature android:name = "Android.hardware.camera"/>

<uses-feature android:name = "Android.hardware.camera.autofocus"/>

Two. Framework Layer

1.android.hardware.camera: Code Location/android/frameworks/base/core/java/android/hardware/camera.java

This part of the goal is Framework.jar. This is the Java interface that Android provides to the app layer call. This class is used to connect or disconnect a camera service, set shooting parameters, start, stop previewing, take pictures, and more.

2.android.hardware.camera This class is a class that is defined in JNI, and some methods invoke local code in a JNI way, some of which are implemented by themselves.
The Java Native invocation part (JNI) of the Camera:/android/frameworks/base/core/jni/android_hardware_camera.cpp. Camera.java takes Java code to the C + + code bridge. Compile the build libandroid_runtime.so. The libandroid_runtime.so library is common, with other features in addition to the camera.

The client part of the 3.Camera framework:

Code location:/android/frameworks/av/camera/under 5 files.

Camera.cpp

CameraParameters.cpp

ICamera.cpp

ICameraClient.cpp

ICameraService.cpp

Their header files are in the/android/frameworks/av/include/camera directory.

The contents of this section are compiled to generate libcamera_client.so. In each library of the camera module, the libcamera_client.so is located at the core, acting as the client-side part of the camera framework, and libcameraservice.so through interprocess communication with another part of the content server (that is, binder Mechanisms) to communicate in a way.

Service part of the 4.Camera framework:

Code location:/frameworks/av/services/camera/libcameraservice/.

This section is compiled into a library libcameraservice.so. Cameraservice is the camera service, the middle tier of the camera framework, used to link the camerahardwareinterface and client parts, and it implements functionality by invoking the actual Camera hardware interface, the lower HAL layer.

Three. Hardware Abstraction Layer Hal Hardware Abstraction Layer

This level is actually the driver code of the user space. The previous introduction of the frame layer pair under the CameraHardwareInterface.h (/android/frameworks/av/services/camera/libcameraservice/device1/ CameraHardwareInterface.h). The interface of the Camera hardware abstraction layer is defined in the header file, which is a class containing pure virtual functions that must be inherited by the implementation class to be used. The HAL layer inherits the Camerahardwareinterface interface, instantiates the underlying hardware driver according to the V4L2 specification, invokes the driver using the IOCTL method, and eventually generates libcamera.so for the libcameraservice.so call of the framework.

This layer of code is under the/android/hardware/xxx/libcamera directory (also possible under the corresponding Libcamera in the vendor directory). Note here xxx is different manufacturers for different products (boards) and the directory, to high-pass MSM platform for example, here xxx with msm7k said, so high-pass MSM platform This HAL directory is/android/hardware/msm7k/libcamera. It is not difficult to see, if you want to run Android on a hardware platform, it is mainly in this layer to modify, because it is directly related to the underlying hardware driver. As mentioned above, the application of the framework layer to the upper and lower defined standard interface, so that the purpose is to make the upper layer of code independent, in the porting is not affected. So we can now basically determine, if you want to change the camera hardware, the frame layer above the parts can not move, to change the HAL to the core layer of the part, which is the main work of Android bottom-up development.

Four. Driver Layer

This layer is primarily Linux-based device drivers. For camera, it is generally the realization that the camera atom function is exposed as an IOCTL for the HAL layer invocation in the form of the V4L2 specification.

The implementation code of the main function is under/ANDROID/KERNEL/DRIVERS/MEDIA/VIDEO/XXX. Like the HAL layer directory, XXX is a directory of different vendors of different platforms, the high-pass MSM platform as an example, this directory is/android/kernel/drivers/media/video/msm. So to add hardware to the Android platform, first consider adding its drivers to the Android Linux kernel.

Camera Service--an analysis of architecture

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.