基于Mtk平台的android camera hal3学习

 框架
基于Mtk平台的android camera hal3学习_第1张图片

Android Camera硬件抽象层(HAL,Hardware Abstraction Layer)主要用于把底层camera driver的实现接口进行封装,再经过算法处理,提供接口给framework连接起来。
在安卓上实现camera的功能会有这么几个流程实现,open、config、request、result、close

  1. Hal层封装了kernel的器件实现,向Camera service封装了各种算法接口,供其调用。在hal3中有这么几个接口,ICameraProvider, ICameraDevice, ICameraDeviceSession, ICameraDeviceCallback。
  2. ICameraProvider主要是向上层提供能力值查询,比如属性类的metadata,并且通过它可以获取CameraDevice3lmpl(例如open camera)和cameradevice3sessionimpl实例。
  3. AppStreamMgr主要是向framework层提供process result、转化framework request格式为hal3 request和pipeline request、更新厂商定义的帧缓冲区使用方法。
  4. 在pipeline中p1node主要输出raw图。JPEJ nod e主要是将yuv转化为jpeg,metadata转化为app metadata。P1node就是root node是所有节点的根node,输出raw data到p2c或者p2s
     AppStreamMgr
    基于Mtk平台的android camera hal3学习_第2张图片

负责AppStreamMgr的回调
alps/vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/app/AppStreamMgr.CallbackHandler.cpp
负责AppStreamMgr的Frame处理
alps/vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/app/AppStreamMgr.FrameHandler.cpp
负责AppStreamMgr的Batch处理
alps/vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/app/AppStreamMgr.BatchHandler.cpp
负责AppStreamMgr的处理请求
alps/vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/app/AppStreamMgr.RequestHandler.cpp
负责AppStreamMgr的结果返回
alps/vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/app/AppStreamMgr.ResultHandler.cpp
负责AppStreamMgr的Config处理
alps/vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/app/AppStreamMgr.ConfigHandler.cpp

 Open
基于Mtk平台的android camera hal3学习_第3张图片
基于Mtk平台的android camera hal3学习_第4张图片

  1. mHalDeviceAdapter的Open用于初始化DeviceAdapter, 调用powerOn接口,这里的powerOn有另起一个线程去操作sensor,等待sensor上电完成后对3A进行powerOn操作。
  2. 在halSensor中主要是跟driver交互的地方,主要是初始化sensor drv、设置sensor mclk、继续调用ImgSensorDrv::open。再会调用featureControl调用到驱动的SENSOR_FEATURE_OPEN。Close流程跟open大致相同。
  3. 在freamwork跨进程调用camera3devicelmpl::open时,会创建CameraDevice3SessionImpl对象。
  4. CameraDevice3Impl::open(const ::android::sp& callback, open_cb _hidl_cb){
    //打开mSession,CameraDevice3Impl初始化时会创建mSession
    ::android::status_t status = mSession->open(V3_4::ICameraDeviceCallback::castFrom(callback));
    //返回CameraDevice3SessionImpl对象
    _hidl_cb(mapToHidlCameraStatus(status), mSession);
    return Void();
    }
  5. 在CameraDevice3SessionImpl中会构造AppStreamMgr和获取pipelineModuleManager进而创建pipelineModule。
  6. 创建IAppStreamManager
    mAppStreamManager = IAppStreamManager::create(
    IAppStreamManager::CreationInfo{
    .mInstanceId = getInstanceId(),
    .mCameraDeviceCallback = callback,
    .mMetadataProvider = mStaticInfo.mMetadataProvider,读取底层相机信息,初始化时会赋值
    .mMetadataConverter = mStaticInfo.mMetadataConverter,读取底层相机信息,初始化时会赋值
    mErrorPrinter= std::static_pointer_castandroid::Printer(mAppStreamManagerErrorState),
    mWarningPrinter=std::static_pointer_castandroid::Printer(mAppStreamManagerWarningState),
    mDebugPrinter=std::static_pointer_castandroid::Printer(mAppStreamManagerDebugState),
    }
    //获得PipelineModelManager
    auto pPipelineModelMgr = IPipelineModelManager::get();
    //创建 PipelineModel
    auto pPipelineModel = pPipelineModelMgr->getPipelineModel( getInstanceId() );
    //初始化pPipelineModel,并通知底层初始化和powerOn
    ii. pPipelineModel->open(getInstanceName().c_str(), this);
    //保存PipelineModel
    mPipelineModel = pPipelineModel;
    6 appStreamMgr初始化的时候创建 对象,不同对象处理不同类型的事件,这样可以最大程度减小阻塞。

7、pipelineModulelmpl调用创建线程来进行open和powerOn。

配流
基于Mtk平台的android camera hal3学习_第5张图片

在给配流过程中有两次配流
IPipelineModelSessionFactory::
createPipelineModelSession(
CreationParams const& params __unused
){
// (1) convert to UserConfiguration
auto pUserConfiguration = convertToUserConfiguration(
*params.pPipelineStaticInfo,
*params.pUserConfigurationParams
);
// (2) pipeline policy
auto pSettingPolicy = IPipelineSettingPolicyFactory::createPipelineSettingPolicy(
IPipelineSettingPolicyFactory::CreationParams{
.pPipelineStaticInfo = params.pPipelineStaticInfo,
.pPipelineUserConfiguration = pUserConfiguration,
});
// (3) pipeline session
auto pSession = decidePipelineModelSession(params, pUserConfiguration, pSettingPolicy);
}
Config stream 1st (pipelingsettingPolicy)
sessionCfgParams.pPipelineStaticInfo = mPipelineStaticInfo;
sessionCfgParams.pUserConfigurationParams = params;
sessionCfgParams.pPipelineModelCallback = mCallback.promote();

Config stream 2nd
mPolicyTable->fConfigPipelineNodesNeed
mPolicyTable->fConfigPipelineTopology
mPolicyTable->fConfigSensorSetting
mPolicyTable->fConfigP1HwSetting
mPolicyTable->fConfigP1DmaNeed
mPolicyTable->fConfigStreamInfo_P1
mPolicyTable->fConfigStreamInfo_NonP1
第二次配流主要配置pipelineModuleSession和构建pipelineContext,构建pipelineContext需要配streaming、node、pipeline。
构建pipelineContext:
Config streaming:网上代码乱码。。
Config node:configContextLocked_Nodes(…)
{
for(size_t i = 0; i < pPipelineNodesNeed->needP1Node.size(); i++) {
if (pPipelineNodesNeed->needP1Node[i]) {
configContextLocked_P1Node(pContext,
pOldPipelineContext,
pStreamingFeatureSetting,
pPipelineNodesNeed,
&(*pParsedStreamInfo_P1)[i],
pParsedStreamInfo_NonP1,
&(*pSensorSetting)[i],
&(*pvP1HwSetting)[i],
i,
batchSize,
useP1NodeCount > 1,
bMultiCam_CamSvPath,
pCommon,
isReConfig);
}
}
if( pPipelineNodesNeed->needP2StreamNode ) {
bool hasMonoSensor = false;
for(auto const v : pPipelineStaticInfo->sensorRawType) {
if(SENSOR_RAW_MONO == v) {
hasMonoSensor = true;
break;
}
}
configContextLocked_P2SNode(pContext,
pStreamingFeatureSetting,
pParsedStreamInfo_P1,
pParsedStreamInfo_NonP1,
batchSize,
useP1NodeCount,
hasMonoSensor,
pCommon);
}
if( pPipelineNodesNeed->needP2CaptureNode ) {
configContextLocked_P2CNode(pContext,
pCaptureFeatureSetting,
pParsedStreamInfo_P1,
pParsedStreamInfo_NonP1,
useP1NodeCount,
pCommon);
}
if( pPipelineNodesNeed->needFDNode ) {
configContextLocked_FdNode(pContext,
pParsedStreamInfo_P1,
pParsedStreamInfo_NonP1,
useP1NodeCount,
pCommon);
}
if( pPipelineNodesNeed->needJpegNode ) {
configContextLocked_JpegNode(pContext,
pParsedStreamInfo_NonP1,
useP1NodeCount,
pCommon);
}
if( pPipelineNodesNeed->needRaw16Node ) {
configContextLocked_Raw16Node(pContext,
pParsedStreamInfo_P1,
pParsedStreamInfo_NonP1,
useP1NodeCount,
pCommon);
}
if( pPipelineNodesNeed->needPDENode ) {
configContextLocked_PDENode(pContext,
pParsedStreamInfo_P1,
pParsedStreamInfo_NonP1,
useP1NodeCount,
pCommon);
}
}
配置pipeline
mpPipelineConfig->setRootNode(rootNodes);
mpPipelineConfig->setNodeEdges(edges);
 Request阶段
基于Mtk平台的android camera hal3学习_第6张图片

Camera3deviceSession通过submitRequest将request发给appStreamMgr进行校验和格式转化为hal request和pipeline request,然后camera3deviceSession把转化结果送给pipelineModule处理。

1、Camera3deviceSession接到request,将request通过submitRequest先提交给appstreamMgr再提交给pipelineModule。
pAppStreamManager->submitRequest(requests, appRequests);
pPipelineModel->submitRequest(vPipelineRequests, numRequestProcessed);
2、PipelineModelSessionBase里面解析request并通过submitOneRequest(reqs[i])提交处理。
PipelineModelSessionBase::
submitRequest(
std::vectorconst& requests,
uint32_t& numRequestProcessed
){
解析
for (size_t i = 0; i < requests.size(); i++) {
auto r = std::make_shared();
parseAppRequest(r.get(), requests[i].get() );//构造AppRequest对象
reqs.emplace_back®;
}

逐个提交
for (size_t i = 0; i < reqs.size(); i++, numRequestProcessed++) {
    submitOneRequest(reqs[i]);
}

}
3、进行处理流程

在处理前会构建freamqueue,建立这个request的I/O buffer、Topological、sub frame、dummy frame、feature set等信息;
android::sp pPipelineFrame;
buildPipelineFrame(pPipelineFrame,params);
PipelineContext流程
基于Mtk平台的android camera hal3学习_第7张图片
基于Mtk平台的android camera hal3学习_第8张图片

基于Mtk平台的android camera hal3学习_第9张图片

你可能感兴趣的:(android)