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中实现。
Android Camera AP到Camera Hal调用流程
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/31236584679861db5c1263c69b9be18d.html