本讲是android camera native framework专题的第17讲,我们介绍cameraserver进程启动之初始化vendortags, flashlight和perfclass。
更多资源:
资源 | 描述 |
---|---|
在线课程 | |
知识星球 | 星球名称:深入浅出android camera 星球id: 17296815 |
极客笔记圈 |
创建vendortagdescriptorcache
vendortagdescriptorcache是一个manager,管理不同provider里面的vendor tag descriptor,vendortagdescriptor维护管理所有vendor tags的section、name、type,id之间的关系:
android 13 代码逻辑:cameraprovidermanager::setupvendortags()
status_t cameraprovidermanager::setupvendortags() {
sp tagcache = new vendortagdescriptorcache();
for (auto& provider : mproviders) {
tagcache->addvendordescriptor(provider->mprovidertagid, provider->mvendortagdescriptor);
}
vendortagdescriptorcache::setasglobalvendortagcache(tagcache);
return ok;
}
flashlight初始化
cameraserver通过cameraflashlight来管理各cameradevice的flashlight,类图如下:
通过cameraflashlight::findflashunits完成flashlight的初始化,流程如下:
android 13代码,cameraflashlight::findflashunits:
status_t cameraflashlight::findflashunits() {
mutex::autolock l(mlock);
status_t res;
std::vector cameraids;
std::vector ids = mprovidermanager->getcameradeviceids();
int numberofcameras = static_cast(ids.size());
cameraids.resize(numberofcameras);
// no module, must be provider
for (size_t i = 0; i < cameraids.size(); i ) {
cameraids[i] = string8(ids[i].c_str());
}
mflashcontrol.clear();
for (auto &id : cameraids) {
ssize_t index = mhasflashlightmap.indexofkey(id);
if (0 <= index) {
continue;
}
bool hasflash = false;
res = createflashlightcontrol(id);
if (res) {
aloge("%s: failed to create flash control for %s", __function__,
id.string());
} else {
res = mflashcontrol->hasflashunit(id, &hasflash);
if (res == -eusers || res == -ebusy) {
aloge("%s: failed to check if camera %s has a flash unit. some "
"camera devices may be opened", __function__,
id.string());
return res;
} else if (res) {
aloge("%s: failed to check if camera %s has a flash unit. %s"
" (%d)", __function__, id.string(), strerror(-res),
res);
}
mflashcontrol.clear();
}
mhasflashlightmap.add(id, hasflash);
}
mflashlightmapinitialized = true;
return ok;
}
为sperfclass过滤characteristics
执行条件:
- ro.odm.build.media_performance_class >= 31
执行动作:
- 针对主后置和主前置,过滤掉<1080p的jpeg尺寸
cts(sperfclasstest.java):
- testsperfclassjpegsizesbycamera
流程:
android 13代码:
void cameraservice::filtersperfclasscharacteristicslocked() {
// to claim to be s performance primary cameras, the cameras must be
// backward compatible. so performance class primary camera ids must be api1
// compatible.
bool firstrearcameraseen = false, firstfrontcameraseen = false;
for (const auto& cameraid : mnormaldeviceidswithoutsystemcamera) {
int facing = -1;
int orientation = 0;
string8 cameraid8(cameraid.c_str());
getdeviceversion(cameraid8, /*out*/&facing, /*out*/&orientation);
if (facing == -1) {
aloge("%s: unable to get camera device \"%s\" facing", __function__, cameraid.c_str());
return;
}
if ((facing == hardware::camera_facing_back && !firstrearcameraseen) ||
(facing == hardware::camera_facing_front && !firstfrontcameraseen)) {
status_t res = mcameraprovidermanager->filtersmalljpegsizes(cameraid);
if (res == ok) {
mperfclassprimarycameraids.insert(cameraid);
} else {
aloge("%s: failed to filter small jpeg sizes for performance class primary "
"camera %s: %s(%d)", __function__, cameraid.c_str(), strerror(-res), res);
break;
}
if (facing == hardware::camera_facing_back) {
firstrearcameraseen = true;
}
if (facing == hardware::camera_facing_front) {
firstfrontcameraseen = true;
}
}
if (firstrearcameraseen && firstfrontcameraseen) {
break;
}
}
}