本讲是android camera native framework专题的第8讲,我们介绍cameraserver进程启动之enumerateproviders概述
更多资源:
资源 | 描述 |
---|---|
在线课程 | |
知识星球 | 星球名称:深入浅出android camera 星球id: 17296815 |
极客笔记圈 |
android camera hal接口简介
android camera hal接口分成hidl和aidl两种,核心接口如下:
注:接口代码路径:/hardware/interfaces/camera/
解释:
- icameraprovider管理多个icameradevice
- icameradevice管理和维护某一颗cameradevice
- 通过icameraprovider获取到icameradevice
- 通过icameradevice获取到icameradevicesession
- 初始化时,icameraprovider和icameradevice的实例就会被创建起来, icameradevicesession要open camera时才创建,close camera时销毁
cameraservice与cameraprovidermanager的关系
cameraprovidermanager
- 负责管理camera hal providers
cameraservice
- icameraservice的实现,cameraservice与hal provider的交互要通过cameraprovidermanager
cameraprovidermanager中的providerinfo
cameraprovidermanager抽象出providerinfo来屏蔽hidl和aidl provider的差异,将差异部分交给hidlproviderinfo和aidlproviderinfo去处理。
enumerateproviders总体流程介绍
有哪些情况会调用到enumerateproviders
- cameraserver进程启动时(onfirstref)
- cameraserver进程启动后,有新的provider注册到servicemanager时(onnewproviderregistered)
总体流程代码介绍
- 创建cameraprovidermanager,并调用initialize完成初始化
- 初始化 vendortags
- 初始化flashlight并完成枚举动作
-
针对主前/后摄,为sperfclass过滤cameracharacteristics
- 参考cdd:2.2.7. handheld media performance class
代码基于android 13:
status_t cameraservice::enumerateproviders() {
status_t res;
std::vector deviceids;
{
mutex::autolock l(mservicelock);
if (nullptr == mcameraprovidermanager.get()) {
mcameraprovidermanager = new cameraprovidermanager();
res = mcameraprovidermanager->initialize(this);
if (res != ok) {
aloge("%s: unable to initialize camera provider manager: %s (%d)",
__function__, strerror(-res), res);
logserviceerror(string8::format("unable to initialize camera provider manager"),
error_disconnected);
return res;
}
}
// setup vendor tags before we call get_camera_info the first time
// because hal might need to setup static vendor keys in get_camera_info
// todo: maybe put this into cameraprovidermanager::initialize()?
mcameraprovidermanager->setupvendortags();
if (nullptr == mflashlight.get()) {
mflashlight = new cameraflashlight(mcameraprovidermanager, this);
}
res = mflashlight->findflashunits();
if (res != ok) {
aloge("failed to enumerate flash units: %s (%d)", strerror(-res), res);
}
deviceids = mcameraprovidermanager->getcameradeviceids();
}
for (auto& cameraid : deviceids) {
string8 id8 = string8(cameraid.c_str());
if (getcamerastate(id8) == nullptr) {
ondevicestatuschanged(id8, cameradevicestatus::present);
}
}
// derive primary rear/front cameras, and filter their charactierstics.
// this needs to be done after all cameras are enumerated and camera ids are sorted.
if (sessionconfigurationutils::is_perf_class) {
// assume internal cameras are advertised from the same
// provider. if multiple providers are registered at different time,
// and each provider contains multiple internal color cameras, the current
// logic may filter the characteristics of more than one front/rear color
// cameras.
mutex::autolock l(mservicelock);
filtersperfclasscharacteristicslocked();
}
return ok;
}