[Android] Android Camera Architecture and the System Workflow

In the Android System, the camera device is as a service for the Android framework. We can uses the Camera APIs to program a camera application runs on Android. These APIs are easier to use for application programmer than the V4L or V4L2 APIs in Linux.

What’s the different between Android’s Camera APIs and V4L(2)? The Android’s Camera APIs is provided by Google in the Android Framework. The V4L(2) is popularly used on Linux System for video applications. In general, the low-level implementation of the Camera APIs is V4L(2), but in some platforms that are not. Google Android provides the high-level Camera APIs, a highly abstraction for V4L(2), helps programmer do not need to focus on the complicated interfaces (V4L or V4L2).
Actually, Google also uses design pattern to separate between the framework and kernel driver. This will reduce the HW-dependency. In this post, I will show the Android camera architecture and explain the implemented detail of camera architecture.

– A Diagram of Camera Architecture 

This diagram shows the basic architecture of camera on Android. Especially the HAL may be provided by the hardware vendor. Beside the diagram, the strings are the path of source code are placed.

– Android Camera Architecture

This diagram is the simple class diagram for camera. The Binder is as IPC used for Camera and CameraService. Here, Google uses the singleton and proxy pattern to establish the relationship between Camera and CameraService.

– From the Source Code

a. Singleton Pattern

  – frameworks/base/libs/camera/Camera.cpp

The Camera obtains the CameraService instance by getService(). This establishes the connection between the camera and camera service by the binder.

b. Proxy Pattern
  – frameworks/base/libs/camera/ICamera.cpp

– Sender –

– Receiver –

The BpCamera class is as a proxy role in the architecture; The Client is as a receiver that binds with proxy. The Proxy Pattern is applied to when we want to exploit a remote system. This pattern will prevent the client operates the server’s methods immediately. By the Proxy, the dependency between client and server can be reduced. Following this pattern, the client doesn’t need to face the network issues, too.

c. A Workflow of Starting the Camera Preview

This diagram shows the workflow of the application for camera-preview. Between the client and server, the binder is used to bind them to establish the IPC mechanism. By this diagram, you can see the system flow when you apply the Camera APIs and you can also know how the procedures are called in the source code.

You can also see my presentation in my Slideshare.
http://www.slideshare.net/pickerweng/android-camera-architecture-8098156

One comment

  1. HI nice post, can you plz explain why the singleton pattern is used here?and whose singleton instance is used here/is it on the client side.

發佈留言