1. 首先是調用framework層的Camera.java(frameworks\base\core\java\Android\hardware)的takePicture方法
2. 接著會調用到JNI層的android_hardware_Camera.cpp(frameworks\base\core\jni)的android_hardware_Camera_takePicture方法,其中會通過get_native_camera獲取一個Camera對象。
3. 上述Camera對象的定義在Camera.h(frameworks\av\include\camera),camera.h同時定義了CameraInfo。Camera對象繼承自publicBnCameraClient,DeathRecipient。Camera對象的真正實現是在Camera.cpp(frameworks\av\camera) 。BnCameraClient是作為CameraService回調而存在的。Camera對象內含有一個mCameraService變量用於保存CameraService引用。
class Camera : public BnCameraClient,public IBinder::DeathRecipient
constsp<ICameraService>& Camera::getCameraService()
{
Mutex::Autolock _l(mLock);
if (mCameraService.get() == 0) {
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder;
do {
binder =sm->getService(String16("media.camera"));
if (binder != 0)
break;
ALOGW("CameraService notpublished, waiting...");
usleep(500000); // 0.5 s
} while(true);
if (mDeathNotifier == NULL) {
mDeathNotifier = newDeathNotifier();
}
binder->linkToDeath(mDeathNotifier);
mCameraService =interface_cast<ICameraService>(binder);
}
4. 在ICameraClient.h和ICameraService.h文件中,ICameraClient和ICameraService都繼承自IInterface,也就是Binder通信的基礎,此外ICamera.h也繼承自IInterface
class ICameraClient:public IInterface
class ICameraService :public IInterface
class ICamera: publicIInterface
然後發現BnCameraClient繼承自BnInterface<ICameraClient>,作為ICameraClient的服務器端存在:
class BnCameraClient: publicBnInterface<ICameraClient>
BnCameraService繼承自BnInterface<ICameraService>,作為ICameraService的服務器端存在:
class BnCameraService: publicBnInterface<ICameraService>
BnCamera繼承自BnInterface<ICamera>,作為ICamera的服務器端存在:
class BnCamera: public BnInterface<ICamera>
對應的上述三個分別存在一個作為Binder客戶端的類存在,為Bp***:
class BpCameraClient:public BpInterface<ICameraClient>
class BpCameraService:public BpInterface<ICameraService>
class BpCamera: publicBpInterface<ICamera>
上述三個的實現分別在ICameraClient.cpp、ICameraService.cpp、ICamera.cpp,在這三支文件中分別實現了三組Binder的Server端和Client端,Camera常用的方法都在ICamera中實現。