与 Android P 加载流程一致,在 Android Q 中 buildStaticInfo 首先通过 impBuildStaticInfo_v1 这一路进行加载。为了兼容Android P 的 metadata 加载,会再次调用 impBuildStaticInfo。然后会加载自动生成的metadata。最后调用impBuildStaticInfo_v1_overwrite,加载需要强制复写的 metadata。
//vendor/mediatek/proprietary/hardware/mtkcam/drv/src/sensor/common/v1_1/HalSensorList.cpp
MBOOL
HalSensorList::buildStaticInfo(Info const& rInfo, IMetadata& rMetadata) const {
const SensorStaticInfo *pSensorStaticInfo =
&sensorStaticInfo[rInfo.getDeviceId()];
MUINT8 u8Para = 0;
#if MTKCAM_CUSTOM_METADATA_COMMON
bool v1 = true;
if (property_get_int32("vendor.debug.camera.static_meta.version", 1) != 0) {
//(1)加载Android Q架构的metadata
if (!impBuildStaticInfo_v1(rInfo, rMetadata)) {
v1 = false;
MY_LOGW("V1: Fail to build static info for %s index:%d type:%d",
rInfo.getSensorDrvName().c_str(), rInfo.getDeviceId(),
rInfo.getSensorType());
} else {
checkSensorData(rMetadata);
updateAFData(rMetadata);
goto lbLoadDone;
}
}
#endif
//(2)兼容加载Android P架构的metadata
if (!impBuildStaticInfo(rInfo, rMetadata))
{
MY_LOGE(
"Fail to build static info for %s index:%d",
rInfo.getSensorDrvName().c_str(), rInfo.getDeviceId()
);
//return MFALSE;
}
//...
//(3)加载自动产生的metadata(Sensor manual add tag list)
{
IMetadata::IEntry entryA(MTK_MULTI_CAM_FEATURE_SENSOR_MANUAL_UPDATED);
entryA.push_back((MINT64)MTK_SENSOR_INFO_ACTIVE_ARRAY_REGION, Type2Type<MINT64>());
entryA.push_back((MINT64)MTK_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE, Type2Type<MINT64>());
entryA.push_back((MINT64)MTK_SENSOR_INFO_PIXEL_ARRAY_SIZE, Type2Type<MINT64>());
entryA.push_back((MINT64)MTK_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, Type2Type<MINT64>());
entryA.push_back((MINT64)MTK_SENSOR_INFO_ORIENTATION, Type2Type<MINT64>());
entryA.push_back((MINT64)MTK_SENSOR_INFO_WANTED_ORIENTATION, Type2Type<MINT64>());
entryA.push_back((MINT64)MTK_SENSOR_ORIENTATION, Type2Type<MINT64>());
entryA.push_back((MINT64)MTK_LENS_FACING, Type2Type<MINT64>());
entryA.push_back((MINT64)MTK_CONTROL_AF_AVAILABLE_MODES, Type2Type<MINT64>());
entryA.push_back((MINT64)MTK_CONTROL_MAX_REGIONS, Type2Type<MINT64>());
if (rMetadata.update(MTK_MULTI_CAM_FEATURE_SENSOR_MANUAL_UPDATED, entryA) < 0)
MY_LOGE("update Metadata MTK_MULTI_CAM_FEATURE_SENSOR_MANUAL_UPDATED failed");
}
#if MTKCAM_CUSTOM_METADATA_COMMON
if ( v1 )
//(4)提供强制修改metadata的接口
impBuildStaticInfo_v1_overwrite(rInfo, rMetadata);
#endif
rMetadata.sort();
return MTRUE;
}
(A)impBuildStaticInfo_v1()
impBuildStaticInfo_v1()加载 Android Q 架构的 metadata。加载的类型是[CAMERA、CONTROL_AE、
CONTROL_AF、CONTROL_AWB、TUNING、FLASHLIGHT、SENSOR、LENS]以及[LENS、MODULE]。
//vendor/mediatek/proprietary/hardware/mtkcam/drv/src/sensor/common/v1_1/HalSensorList.cpp
static
char const*const
kCommonStaticMetadataNames[] =
{
// MODULE
"CAMERA",
"CONTROL_AE",
"CONTROL_AF",
"CONTROL_AWB",
"TUNING",
"FLASHLIGHT",
"SENSOR",
"LENS",
// // PROJECT
// "AVAILABLE_KEYS",
// "FEATURE",
// "MULTICAM",
// "REQUEST",
// "SCALER",
// "VENDOR",
NULL
};
static
char const*const
kPlatformStaticMetadataNames[] =
{
"MODULE",
"LENS",
// "MOD_OVERWRITE"
// "PROJECT",
// // "PRO_OVERWRITE"
NULL
};
(B)impBuildStaticInfo()
impBuildStaticInfo()兼容 Android P 架构,加载的是 Android P 类型的 metadata[LENS、SENSOR、
TUNING_3A、FLASHLIGHT、SCALERA、FEATURE、CAMERA、REQUEST]。
//vendor/mediatek/proprietary/hardware/mtkcam/drv/src/sensor/common/v1_1/HalSensorList.cpp
static
char const*const
kStaticMetadataTypeNames[] = {
"LENS",
"SENSOR",
"TUNING_3A",
"FLASHLIGHT",
"SCALER",
"FEATURE",
"CAMERA",
"REQUEST",
NULL
};
(C)impBuildStaticInfo_v1_overwrite()
impBuildStaticInfo_v1_overwrite()提供强制修改 metadata 的接口,加载的类型是[MOD_OVERWRITE]。
//vendor/mediatek/proprietary/hardware/mtkcam/drv/src/sensor/common/v1_1/HalSensorList.cpp
static char const*const kPlatformOverwriteStaticMetadataNames[] = {
// "MODULE"
// "LENS",
"MOD_OVERWRITE",
// // "PROJECT",
// "PRO_OVERWRITE",
NULL};
在 Android Q 版本开始默认走 constructStaticMetadata_v1()这一路。
(A)MetadataProvider::onCreate()
//vendor/mediatek/proprietary/hardware/mtkcam/utils/metastore/metadataprovider/MetadataProvider.cpp
status_t
MetadataProvider::
onCreate()
{
status_t status = OK;
//prepare data for TagInfo
IMetadataTagSet mtagInfo;
setTagInfo(mtagInfo);
//create IMetadataConverter
sp<IMetadataConverter> pMetadataConverter = IMetadataConverter::createInstance(mtagInfo);
{
RWLock::AutoWLock _l(mRWLock);
status = (mVersion==0)?
constructStaticMetadata(pMetadataConverter, mpStaticCharacteristics, mpHALMetadata) :
constructStaticMetadata_v1(pMetadataConverter, mpStaticCharacteristics, mpHALMetadata);
if ( CC_UNLIKELY( status!=OK ) ) {
META_LOGE("constructStaticMetadata - status[%s(%d)]", ::strerror(-status), -status);
return status;
}
}
return status;
}
(B)constructStaticMetadata_v1()
在 constructStaticMetadata.cpp 中 constructStaticMetadata_v1()通过 impConstructStaticMetadata_v1()、impConstructStaticMetadata_v1_ext()、updateData()进行 metadata的加载,流程如下:
(C)impConstructStaticMetadata_v1()
impConstructStaticMetadata_v1()加载的是配置文件中 common 的 metadata、platform 的 metadata
以及 project 下面的 metadata。project 的优先级最高、platform 次之、common 最低。
在 impConstructStaticMetadata_v1()也保留了向前兼容 Android P 版的 metadata 配置,在
metadata 配置文件中可以直接按 Android P 的结构进行配置,而不需要任何修改。
//vendor/mediatek/proprietary/hardware/mtkcam/utils/metastore/metadataprovider/custom/info.h
static
char const*const
kCommonStaticMetadataNames[] =
{
// // MODULE
// "CAMERA",
// "CONTROL_AE",
// "CONTROL_AF",
// "CONTROL_AWB",
// "TUNING",
// "FLASHLIGHT",
// "SENSOR",
// "LENS",
// PROJECT
"AVAILABLE_KEYS",
"AVAILABLE_KEYS_VENDOR",
"AVAILABLE_KEYS_CUSTOM",
"FEATURE",
"MULTICAM",
"REQUEST",
"SCALER",
"VENDOR",
"CUSTOM",
NULL
};
static
char const*const
kPlatformStaticMetadataNames[] =
{
// "MODULE",
// "LENS",
// // "MOD_OVERWRITE"
"PROJECT",
// "PRO_OVERWRITE"
NULL
};
static
char const*const
kStaticMetadataTypeNames[] =
{
// "LENS",
// "SENSOR",
// "TUNING_3A",
// "FLASHLIGHT",
"SCALER",
"FEATURE",
"CAMERA",
"REQUEST",
NULL
};
(D)impConstructStaticMetadata_v1_ext()
impConstructStaticMetadata_v1_ext()中加载的是可选/需要复写(强制覆盖)的相关平台配置。
impConstructStaticMetadata_v1_ext(mtkMetadata, kPlatformOptionalStaticMetadataNames);
impConstructStaticMetadata_v1_ext(mtkMetadata, kPlatformOverwriteStaticMetadataNames);
//vendor/mediatek/proprietary/hardware/mtkcam/utils/metastore/metadataprovider/custom/info.h
static
char const*const
kPlatformOptionalStaticMetadataNames[] =
{
"AVAILABLE_KEYS",
"VENDOR",
"CUSTOM",
NULL
};
static
char const*const
kPlatformOverwriteStaticMetadataNames[] =
{
// // "MODULE"
// // "LENS",
// "MOD_OVERWRITE",
// "PROJECT",
"PRO_OVERWRITE",
NULL
};
(E)updateData()
updateData()与之前一样,加载的是运行时动态生成的 metadata。
void
MetadataProvider::
updateData(IMetadata &rMetadata)
{
updateStreamConfiguration(rMetadata);
updateRecommendedStreamConfiguration(rMetadata);
updateAfRegions(rMetadata);
IMetadata::IEntry availReqEntry = rMetadata.entryFor(MTK_REQUEST_AVAILABLE_REQUEST_KEYS);
availReqEntry.push_back(MTK_EIS_FEATURE_EIS_MODE, Type2Type< MINT32 >());
rMetadata.update(availReqEntry.tag(), availReqEntry);
IMetadata::IEntry availReqEntry = rMetadata.entryFor(MTK_REQUEST_AVAILABLE_REQUEST_KEYS);
availReqEntry.push_back(MTK_EIS_FEATURE_PREVIEW_EIS, Type2Type< MINT32 >());
rMetadata.update(availReqEntry.tag(), availReqEntry);
IMetadata::IEntry entry(MTK_REQUEST_AVAILABLE_SESSION_KEYS);
entry.push_back(MTK_STREAMING_FEATURE_HDR10, Type2Type< MINT32 >());
rMetadata.update(entry.tag(), entry);
//...
}
与 Android P 版加载方式差别不大,在 Android Q 上是通过 COMMON_HIERARCHY 这个宏开关来控制走 Android Q 的 Flow,只是修改了 metadata 的加载顺序。
后面的会覆盖或者追加到前面的数据。
//vendor/mediatek/proprietary/hardware/mtkcam/utils/metastore/templateRequest/TemplateRequest.cpp
status_t
TemplateRequest::
impConstructRequestMetadata(
IMetadata& metadata,
int const requestType
)
{
status_t status = OK;
FUNC_PROFILE_START(__FUNCTION__);
#ifdef COMMON_HIERARCHY
//
int32_t result = 0;
std::string libPath = "libmtkcam_metastore.so";
void* handle = ::dlopen(libPath.c_str(), RTLD_GLOBAL);
if (!handle) {
char const* err_str = ::dlerror();
META_LOGW("dlopen library=%s %s", libPath.c_str(), err_str ? err_str : "unknown");
return NAME_NOT_FOUND;
}
{
String8 const s8Symbol_Common = String8::format("%s_COMMON_%s", PREFIX_FUNCTION_REQUEST_METADATA, "COMMON");
status = impConstructRequestMetadata_by_SymbolName(s8Symbol_Common, metadata, requestType, handle);
if ( !status ) result|=COMMON_COMMON;
String8 const s8Symbol_Sensor = String8::format("%s_COMMON_%s", PREFIX_FUNCTION_REQUEST_METADATA, mInfo.getSensorDrvName());
status = impConstructRequestMetadata_by_SymbolName(s8Symbol_Sensor, metadata, requestType, handle);
if ( !status ) result|=COMMON_SENSOR;
}
//
{
String8 const s8Symbol_Common = String8::format("%s_DEVICE_%s", PREFIX_FUNCTION_REQUEST_METADATA, "DEFAULT");
status = impConstructRequestMetadata_by_SymbolName(s8Symbol_Common, metadata, requestType, handle);
if ( !status ) result|=PLATFORM_COMMON;
String8 const s8Symbol_Sensor = String8::format("%s_DEVICE_%s", PREFIX_FUNCTION_REQUEST_METADATA, mInfo.getSensorDrvName());
status = impConstructRequestMetadata_by_SymbolName(s8Symbol_Sensor, metadata, requestType, handle);
if ( !status ) result|=PLATFORM_SENSOR;
}
//
{
String8 const s8Symbol_Sensor = String8::format("%s_PROJECT_%s", PREFIX_FUNCTION_REQUEST_METADATA, mInfo.getSensorDrvName());
status = impConstructRequestMetadata_by_SymbolName(s8Symbol_Sensor, metadata, requestType, handle);
if ( !status ) result|=PROJECT_SENSOR;
}
META_LOGD("%s: load status(0x%x)", "TemplateRequest", result);
//
#else
//...
(A_1)COMMON_COMMON
目录结构如下所示。主要配置 TemplateRequest,以及所有平台通用的 3A 或者其他 metadata 配置。该文件夹会最先被加载。
其中第一个参数 COMMON 和最后一个参数 COMMON 表示位于 COMMON-COMON 目录下(后面都参考此规则),第二个参数表示类型;
STATIC_METADATA2_BEGIN(COMMON, CONTROL_AF, COMMON)
STATIC_METADATA2_BEGIN(COMMON, CONTROL_AE, COMMON)
STATIC_METADATA_BEGIN(COMMON, REQUEST, COMMON)
//...
(A_2)COMMON_SENSOR
目录结构如下所示,配置的是特定 sensor 相关的信息,所有平台都通用 camera sensor 属性。
config_static_metadata.sensor.imx499mipiraw.h:配置的类型是 SENSOR,第一个参数是 COMMON,第三个参数是SENSOR_DRVNAME_IMX499_MIPI_RAW,表示位于 COMMON-SENSOR 目录下。
(B_1)PLATFORM-COMMON
该目录下的文件结构如下所示,除了config_static_metadata_project.h 这支文件,其他文件都是 STATIC_METADATA2_BEGIN(DEVICE,TYPE,COMMON)类型,以 DEVICE 开头的都是 Android P 的Metadata加载方式,只有Android Q的加载方式没有加载到数据时才会使用。
config_static_metadata_project.h配置 PEOJECT 类型的 Metadata,位于 PLATFORM 目录下,目前存放了PLARFORM通用stream configuration。
(B_2)PLATFORM-SENSOR
文件结构如下所示,该目录配置的是 Platform 中 Camera Sensor 特有的 camera metadata 配置。
04-12 09:57:32.389 26530 26530 I camerahalserver: Camera HAL Server is starting..., ADV_CAM_SUPPORT(0)
04-12 09:57:32.630 26530 26530 I mtkcam-devicemgr: [getCameraDeviceManager] [hidldc] getCameraDeviceManager
04-12 09:57:32.632 26530 26530 I mtkcam-devicemgr: [initialize] +
04-12 09:57:32.633 26530 26530 D MtkCam/HalSensorList: [searchSensors] searchSensors
04-12 09:57:32.633 26530 26530 D SeninfDrv: [init][init]: Entry count 0
04-12 09:57:32.634 26530 26530 D ImgSensorDrv: [init][init] imgsensor_drv
04-12 09:57:32.634 26530 26530 D ImgSensorDrv: [searchSensor]searchSensor idx = 0
04-12 09:57:32.653 26530 26530 D ImgSensorDrv: [searchSensor]found <8a3/GC08A3_mipi_raw>
04-12 09:57:32.668 26530 26530 D ImgSensorDrv: [searchSensor]searchSensor idx = 1
04-12 09:57:32.688 26530 26530 D ImgSensorDrv: [searchSensor]found <8a4/GC08A4_mipi_raw>
04-12 09:57:32.704 26530 26530 D MtkCam/Util/LogicalDevice: (26530)[createDeviceMap] sensorNum : 2
04-12 09:57:32.704 26530 26530 D MtkCam/Util/LogicalDevice: (26530)[createDeviceMap] 0 : facing(0), Name(SENSOR_DRVNAME_GC08A3_MIPI_RAW), remapping(0), isHidden(0)
04-12 09:57:32.704 26530 26530 D MtkCam/Util/LogicalDevice: (26530)[createDeviceMap] i : 0, remapping: 0, Info Name : SENSOR_DRVNAME_GC08A3_MIPI_RAW
04-12 09:57:32.704 26530 26530 D MtkCam/Util/LogicalDevice: (26530)[createDeviceMap] 1 : facing(1), Name(SENSOR_DRVNAME_GC08A4_MIPI_RAW), remapping(1), isHidden(0)
04-12 09:57:32.704 26530 26530 D MtkCam/Util/LogicalDevice: (26530)[createDeviceMap] i : 1, remapping: 1, Info Name : SENSOR_DRVNAME_GC08A4_MIPI_RAW
04-12 09:57:32.705 26530 26530 I mtkcam-devicemgr: pHalDeviceList:0xb400006f9405ada0 searchDevices:2 queryNumberOfDevices:2
04-12 09:57:32.841 26530 26530 D mtkcam-devicemgr: [onEnumerateDevicesLocked] [0x00] vid: 0x00 isHidden:0 IMetadataProvider:0xb400006ff4047c10 sensor:SENSOR_DRVNAME_GC08A3_MIPI_RAW
04-12 09:57:32.976 26530 26530 D mtkcam-devicemgr: [onEnumerateDevicesLocked] [0x01] vid: 0x01 isHidden:0 IMetadataProvider:0xb400006ff404b250 sensor:SENSOR_DRVNAME_GC08A4_MIPI_RAW