一、服务端CameraService初始化
//-------------------1------------------------------//
Main_mediaserver.cpp::main()
1、其他准备
2、CameraService::instantiate();
3、其他
//-------------------2------------------------------//
BinderService::instantiate()
//-------------------3------------------------------//
BinderService::publish(bool allowIsolated=false)
1、获取servicemanager
sp<IServiceManager> sm(defaultServiceManager());
2、构建CameraService对象
3、加入servicemanager管理
其中,2和3是在一条语句里完成的:
return sm->addService(String16(CameraService::getServiceName()),new CameraService(),allowIsolated);
//-------------------4------------------------------//
CameraService::onFirstRef()
1、BnCameraService::onFirstRef()
2、bettery相关重置
3、加载hal module,加载相关硬件的so库
hw_get_module(CAMERA_HARDWARE_MODULE_ID,(const hw_module_t **)&rawModule);
//@hardware/libhardware/include/hardware/camera.h
//#define CAMERA_HARDWARE_MODULE_ID “camera”
//实现文件在libhardware/hardware.c
4、创建mModule对象,这个是CameraModule指针变量
mModule=new CameraModule(rawModule);
5、mModule初始化
mModule->init();
6、获取一些属性
7、设置回调
mModule->setCallback(this);
8、注册
CameraDeviceFactory::registerService(this);
9、ping proxy端
CameraService::pingCameraServiceProxy();
这个onFirstRef方法是继承自RefBase的方法,当第一次用这个sp<CameraService>包装的时候,会调用到。
二、服务端的响应
//---------------------------1---------------------------//
CameraService::onTransact(uint32_t code,const Parcel& data,Parcel* reply,uint32_t flags)
1、相关权限检查
2、调用BnCameraService::onTransact(code,data,reply,flags);
BnCameraService的实现定义文件在:
Framework/av/camera/ICameraService.cpp
会分别又调用回CameraService的connect等方法。
//-------------------2------------------------------//
CameraService::connect(const sp<ICameraClient>& cameraClient,int cameraId,const String16& clientPackageName,int clientUid,/*out*/sp<Icamera>& device)
1、调用connectHelper得到一个client
sp<Client> client=nullptr;
connectHelper<ICameraClient,Client>(cameraClient,id,CAMERA_HAL_API_VERSION_UNSPECIFIED,clientPackageName,clientUid,API_1,false,false,/*out*/client);
2、device=client;
//-------------------3------------------------------//
Template<class CALLBACK,class CLIENT>
Status_t CameraService::connectHelper(...)
1、调用makeClient
sp<CLIENT> client=nullptr;
sp<BasicClient> tmp nullptr;
ret=makeClient(…,&tmp);
client=static_cast<CLIENT*>(tmp.get());
2、初始化client
client->initialize(mModule);
3、返回值
device=client;
//-------------------4.1------------------------------//
CameraService::makeClient(const sp<CameraService>& cameraService,const sp<Iinterface>& cameraCb,const String16& packageName,const String8& cameraId,int facing,int clientPid,uid_t clientUid,int servicePid,bool legacyMode,int halVersion,int deviceVersion,apiLeval effectiveApiLevel,/*out*/sp<BasicClient>* client)
获取client的方法,静态方法。
1、根据不同的halVersion创建不同的client
分别用到了以下几种client:
1)CamraClient:
1.1)halVersion<0 || halVersion == deviceVersion
并且deviceVersion==CAMERA_DEVICE_API_VERSION_1_0
并且effectiveApiLevel==API_1
1.2)halVersion>=0 && halVersion<>deviceVersion
并且deviceVersion>=CAMERA_DEVICE_API_VERSION_1_0 && halVersion==CAMERA_DEVICE_API_VERSION_1_0
2)Camera2Client
3)CameraDeviceClient
问题:何处调用该方法?
在connectHelper方法里调用。
//-------------------4.2------------------------------//
CameraClient::initialize(CameraModule *module)
1、构建CameraHardwareInterface对象
mHardware=new CameraHardwareInterface(camera_device_name);
2、初始化
mHardware->initialize(module);
3、设置回调
mHardware->setCallbacks(notifyCallback,dataCallback,dataCallbackTimestamp,(void*)(uintptr_t)mCameraId);
问题:module来自何处?在初始化的时候的onFirstRef方法中得到的。
//-------------------1------------------------------//
Main_mediaserver.cpp::main()
1、其他准备
2、CameraService::instantiate();
3、其他
//-------------------2------------------------------//
BinderService::instantiate()
//-------------------3------------------------------//
BinderService::publish(bool allowIsolated=false)
1、获取servicemanager
sp<IServiceManager> sm(defaultServiceManager());
2、构建CameraService对象
3、加入servicemanager管理
其中,2和3是在一条语句里完成的:
return sm->addService(String16(CameraService::getServiceName()),new CameraService(),allowIsolated);
//-------------------4------------------------------//
CameraService::onFirstRef()
1、BnCameraService::onFirstRef()
2、bettery相关重置
3、加载hal module,加载相关硬件的so库
hw_get_module(CAMERA_HARDWARE_MODULE_ID,(const hw_module_t **)&rawModule);
//@hardware/libhardware/include/hardware/camera.h
//#define CAMERA_HARDWARE_MODULE_ID “camera”
//实现文件在libhardware/hardware.c
4、创建mModule对象,这个是CameraModule指针变量
mModule=new CameraModule(rawModule);
5、mModule初始化
mModule->init();
6、获取一些属性
7、设置回调
mModule->setCallback(this);
8、注册
CameraDeviceFactory::registerService(this);
9、ping proxy端
CameraService::pingCameraServiceProxy();
这个onFirstRef方法是继承自RefBase的方法,当第一次用这个sp<CameraService>包装的时候,会调用到。
二、服务端的响应
//---------------------------1---------------------------//
CameraService::onTransact(uint32_t code,const Parcel& data,Parcel* reply,uint32_t flags)
1、相关权限检查
2、调用BnCameraService::onTransact(code,data,reply,flags);
BnCameraService的实现定义文件在:
Framework/av/camera/ICameraService.cpp
会分别又调用回CameraService的connect等方法。
//-------------------2------------------------------//
CameraService::connect(const sp<ICameraClient>& cameraClient,int cameraId,const String16& clientPackageName,int clientUid,/*out*/sp<Icamera>& device)
1、调用connectHelper得到一个client
sp<Client> client=nullptr;
connectHelper<ICameraClient,Client>(cameraClient,id,CAMERA_HAL_API_VERSION_UNSPECIFIED,clientPackageName,clientUid,API_1,false,false,/*out*/client);
2、device=client;
//-------------------3------------------------------//
Template<class CALLBACK,class CLIENT>
Status_t CameraService::connectHelper(...)
1、调用makeClient
sp<CLIENT> client=nullptr;
sp<BasicClient> tmp nullptr;
ret=makeClient(…,&tmp);
client=static_cast<CLIENT*>(tmp.get());
2、初始化client
client->initialize(mModule);
3、返回值
device=client;
//-------------------4.1------------------------------//
CameraService::makeClient(const sp<CameraService>& cameraService,const sp<Iinterface>& cameraCb,const String16& packageName,const String8& cameraId,int facing,int clientPid,uid_t clientUid,int servicePid,bool legacyMode,int halVersion,int deviceVersion,apiLeval effectiveApiLevel,/*out*/sp<BasicClient>* client)
获取client的方法,静态方法。
1、根据不同的halVersion创建不同的client
分别用到了以下几种client:
1)CamraClient:
1.1)halVersion<0 || halVersion == deviceVersion
并且deviceVersion==CAMERA_DEVICE_API_VERSION_1_0
并且effectiveApiLevel==API_1
1.2)halVersion>=0 && halVersion<>deviceVersion
并且deviceVersion>=CAMERA_DEVICE_API_VERSION_1_0 && halVersion==CAMERA_DEVICE_API_VERSION_1_0
2)Camera2Client
3)CameraDeviceClient
问题:何处调用该方法?
在connectHelper方法里调用。
//-------------------4.2------------------------------//
CameraClient::initialize(CameraModule *module)
1、构建CameraHardwareInterface对象
mHardware=new CameraHardwareInterface(camera_device_name);
2、初始化
mHardware->initialize(module);
3、设置回调
mHardware->setCallbacks(notifyCallback,dataCallback,dataCallbackTimestamp,(void*)(uintptr_t)mCameraId);
问题:module来自何处?在初始化的时候的onFirstRef方法中得到的。