Analysis of the android camera Module

Source: Internet
Author: User

Android camera module architecture and bottom layer communication mechanism
----------- Albert tchen
The Android Application Programming Language is Java, while many Linux service programs, including some libraries, are written in C or C ++, what kind of mechanism does an application use to call these system functions? Java virtual machines can use system. loadlibrary to load local libraries, or use the JNI function registernatives to register local methods associated with classes. In Android, most native functions related to some underlying platforms are called through registration Association.
Two important processes after the system is started:
1: app_main process: the process uses androidruntime to call register_jni_procs to register the native function of the module with JNI for JVM to call.
2: mediaserver proces: The process registers the following servers:
Audioflinger, mediaplayerserver; cameraservice.

Process for Android camera application to call the native function:
First, Android runtime calls register_android_hardware_camera to register navtive functions related to camera to JNI. Then call android_hardware_camera_native_setup to create a client for the application to open the device through opencamerahardware and connect to cameraserver. The process of enabling preview by application is similar to that of establishing a connection between application and cameraservice. This process is as follows:

 

 

 

 

 

 

 

 

 

 

From the above we can see that there is a very important connection layer between Java Vm and native, namely, Java Native Interface. The android1.0 platform provides native interfaces related to camera. If these interfaces are not enough, we can easily extend them through this mechanism, however, our own extended interfaces are related to our hardware platform and are not officially supported by Android. Some people on the Internet say that android1.0 does not support JNI and Android cannot execute local JNI calls. However, from the android source code, this situation does not exist. At least it supports registering local methods associated with classes.

 

 

 

 

 

 

 

 

 

Android Architecture

Communication between Java Process and native Process
Native process is considered to be a service program written in C, C ++ language (an independent process ). Java Process is generally called Android Application. Take the camera module as an example. We need to establish the communication between the camera object and the cameraservice object.
Java application calls native_setup to create a camera client in cameraservice. The client obtains the ibinder object in camerasevice through getcameraservice and establishes an interface between Java application and camerservice icameraservice, through this interface, we call bpcameraservice: connect. In fact, the previously obtained ibinder object will call the cameraservice: ontransact function in this function and then call bncamerasrvice :: ontransact has now established a message pipeline between Java application and cameraservice.

 

 

 

 

 

 


 

, Camera. jar camera. CPP, icamera, and icameraservice objects all belong to Java application process. After the communication between two objects is established, Java application sends a message to the camera client in cameraservice through the icamera interface.
At the native layer, two objects in different processes need to pass messages to inherit the ibinder interface. If an object only needs to initiate a connection, it can inherit the Extended Interface bpinterface of ibinder, to accept a connection request, you can inherit the bninterface interface, for example, in icamera. CPP has two interfaces: bpcamera and bncamera. bpcamera is used to send messages. bncamera is inherited by cameraservice. Recently, the message response uses bncamera to call cameraservice: client object to process messages.
The underlying interface Implementation Method of audiorecord, audiofinger, and mediaplayer is similar to that of camera.

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.