Android2.2 --- Introduction to the Camera Architecture

Source: Internet
Author: User

Currently, we need to develop a voice call and video chat function, which is mainly divided into two parts: audio and video, which will inevitably involve the Camera and AudioFlinger sections. SurfaceFlinger sections will be involved in the display section, therefore, it is necessary to learn step by step and confirm whether the design is reasonable.
 
 
This article gives a brief introduction to Camera and describes the various stages of development.
 
 
 
 
The camera system provides the following functions:
 
A. preview
 
B. recording
 
C. photographing function takePicture
 
D. parameter settings
 
 
 
 
1. The basic architecture of android is the C/S layer architecture. The client provides call interfaces and the implementation work is completed by the server, so the Camera is the same
 
This condition is met: although the Client process does not have any substantive Camera data, the service end provides it with a variety of interfaces,
 
It can easily obtain the address of the Camera data and then process the data. The two communicate through the Binder.
 

 
First, let's clear the workflow so that we can know what is going on:


 
All the way through the process is called and implemented by the client, but the real implementation of these interfaces is on the server:
 

 
By reading its interface function, we know that all interfaces provided by ICamera are control interfaces, while all interfaces defined by ICameraClient are callback functions.
 
Interface, that is, the real data stream transmission is implemented through the callback function.
 
OK. The above shows the basic camera hierarchy.
 

 
2. Focus on CamerService, which is a starting service process.
 
Code path: frameworks \ base \ camera \ libcameraservice
 
This part of content is compiled to generate the libcameraservice library. Here there is a fake camera Code, which is set by the USE_CAMERA_STUB macro.
 
 
 
 
Class CameraService: public BnCameraService
 
{
 
// ICameraService interface
 
Virtual sp <ICamera> connect (const sp <ICameraClient> & cameraClient );
 
 
Void removeClient (const sp <ICameraClient> & cameraClient );
 
 
//... Omitted part of the content
 
 
 
 
Class Client: public BnCamera
 
{
 
//... Omitted part of the content
 
}}
 
 
 
 
During the running process, the CameraService: connect obtained from a CameraService: Client code is as follows:
 
Sp <ICamera> CameraService: connect (const sp <ICameraClient> & cameraClient)
 
{
 
...
 
// Create a new Client object
 
Client = new Client (this, cameraClient, callingPid );
 
MClient = client;
 
Return client;
 
}
 
 
 
 
During use, the Camera function is mainly implemented through the interface of the mClient class.
 
 
For details, see the Implementation Layer Code:
 
Photo Taking function:
 
// * Take a picture-image is returned in callback */
 
Status_t CameraService: Client: takePicture ()
 
{
 
 
LOGV ("takePicture (pid % d)", getCallingPid ());
 
 
Mutex: Autolock lock (mLock );
Status_t result = checkPid ();
If (result! = NO_ERROR) return result;
 
 
If (mHardware = 0 ){
LOGE ("mHardware is NULL, returning .");
Return INVALID_OPERATION;
}
 
 
MHardware-> enableMsgType (CAMERA_MSG_SHUTTER |
CAMERA_MSG_POSTVIEW_FRAME |
CAMERA_MSG_RAW_IMAGE |
CAMERA_MSG_COMPRESSED_IMAGE );
 
 
Return mHardware-> takePicture ();
 
 
}
 
 
 
 
The mHardware object is used here. Calling all HAL layer interfaces is performed through this object. How is this generated?
 
 
MHardware = openCameraHardware ();
 
Note that this function openCameraHardware () is located in the libcamera. so library of the hardware abstraction layer. The function is defined as follows:
 
/* Factory function to instantiate a camera hardware object */
Extern "C" sp <CameraHardwareInterface> openCameraHardware ();
 

3. A large amount of data streams are generated during the camera process. How is this part operated?
 
The next article continues to explain
 

From andyhuabing's column

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.