2024年11月01日 第8讲 cameraserver进程启动之enumerateProviders概述 极客笔记
本讲是Android Camera Native Framework专题的第8讲,我们介绍cameraserver进程启动之enumerateProviders概述
更多资源:
资源 | 描述 |
---|---|
在线课程 | 极客笔记在线课程 |
知识星球 | 星球名称:深入浅出Android Camera 星球ID: 17296815 |
极客笔记圈 |
Android Camera HAL接口分成HIDL和AIDL两种,核心接口如下:
注:接口代码路径:/hardware/interfaces/camera/
解释:
CameraProviderManager
CameraService
CameraProviderManager抽象出ProviderInfo来屏蔽HIDL和AIDL Provider的差异,将差异部分交给HidlProviderInfo和AidlProviderInfo去处理。
有哪些情况会调用到enumerateProviders
总体流程代码介绍
代码基于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;
}
本文链接:http://so.lmcjl.com/news/16752/