MTK Camera Open 流程
共 5667字,需浏览 12分钟
·
2021-03-27 16:40
和你一起终身学习,这里是程序员Android
经典好文推荐,通过阅读本文,您将收获以下知识点:
一、整体介绍
首先看下mtkcam
的整体框架图如下包含了很多的内容,其中camera
的打开流程也贯穿在其中,从Camera APK
一层层的系统调用到driver
再到Hardware
层,这篇文章主要从Pipeline
开始介绍打开camera
的流程,JAVA/Cameraservice/MiddleWare
层后续再进行介绍:
1、MiddleWare(MW)层介绍
ICameraProvider: 向上暴露的接口调用,实现是在CameraProverideer
中;
Device@3.2ICameraDevice: 用于Camera Service
去操作各个Camera device
的操作,实现在CameraDevice3
中;
Device@3.2ICameraDeviceSession: Camera
会话的接口;
ICameraDeviceCallBack: 底层对上层的CallBack
接口;
CameraDeviceManager: 用于管理CameraDevice
,包括查找,打开,关闭等。
2、Pipeline介绍
PipelineModel
是HAL3
核心架构,对上需要开放对Pipeline
创建 & 操作的API
,对下需要建立Pipeline
& 管理Pipeline
的生命周期。PipelineModel
会针对不同的场景创建不同的Pipeline
和HWNode
,HWNode
向下传输APP
层的命令,向上传递图形数据:
P1Node: pipeline
的root node
,input app
命令,output raw data to P2CaptureNode and P2StreamNode
;
P2CaptureNode: 转换raw data to yuvs
,Support scale/crop
;
P2StreamingNode: 和P2CaptureNode
功能类似;
*JPEGNode: Convert YUV to Jpeg
;
FDNode: Generate the FD information
;
二、Camera Open流程
1、在APP
层调用openCam
后会调用的CameraDevice
层,最后调用到driver
中,整体的调用流程如下:
程序员Android 转于网络
文件位置:./vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/device/CameraDevice3SessionImpl.cpp
auto ThisNamespace::open(
const ::android::sp<V3_4::ICameraDeviceCallback>& callback) -> ::android::status_t
{
auto pDeviceManager = mStaticInfo.mDeviceManager;
auto const& instanceName = mStaticInfo.mStaticDeviceInfo->mInstanceName;
status = pDeviceManager->startOpenDevice(instanceName);
err = onOpenLocked(callback);
pDeviceManager->updatePowerOnDone();
status = pDeviceManager->finishOpenDevice(instanceName, false/*cancel*/);
}
auto ThisNamespace::onOpenLocked(
const ::android::sp<V3_4::ICameraDeviceCallback>& callback
) -> ::android::status_t
{
//--------------------------------------------------------------------------
{
Mutex::Autolock _l(mPipelineModelLock);
auto pPipelineModelMgr = IPipelineModelManager::get();
auto pPipelineModel = pPipelineModelMgr->getPipelineModel( getInstanceId() );
::android::status_t err = OK;
err = pPipelineModel->open(getInstanceName().c_str(), this);
mPipelineModel = pPipelineModel;
}
//--------------------------------------------------------------------------
return OK;
}
这里主要看PipelineModel
的Open
函数如下:
文件位置:vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/model/PipelineModelImpl.cpp
auto PipelineModelImpl::open(
std::string const& userName,
android::wp<IPipelineModelCallback> const& callback) -> int
{
{
std::lock_guard<std::timed_mutex> _l(mLock);
mUserName = userName;
mCallback = callback;
mvOpenFutures.push_back(
std::async(std::launch::async,
[this]() {
return CC_LIKELY( mHalDeviceAdapter!=nullptr )
&& CC_LIKELY( mHalDeviceAdapter->open() )
//android::sp<IHalDeviceAdapter> const mHalDeviceAdapter;
&& CC_LIKELY( mHalDeviceAdapter->powerOn() );
}
)
);
}
return OK;
}
再调用mHalDeviceAdapter
的Open
用于初始化DeviceAdapter
,这里重点看powerOn
接口,这里的powerOn
有另起一个线程去操作sensor
,等待sensor
上电完成后对3A
进行powerOn
操作:
文件位置:vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/model/adapter/HalDeviceAdapter.cpp
virtual auto powerOn() -> bool override
{
//1.调用HalSensor的powerOn
std::future<bool> future_initSensor =
std::async(std::launch::async,
[ this ]() {
if (CC_UNLIKELY( !mvHalSensor[i]->powerOn(mName.c_str(), 1, &sensorIndex) ))
}
//2.init 3A and poweron 3A
bool success_sensorPowerOn = false;
bool success_init3A = true;
for (size_t i = 0; i < mvPhySensorId.size(); i++)
{
mvHal3A.push_back(IHal3AAdapter::create(mvPhySensorId[i], mName.c_str()));
mvHalIsp.push_back(MAKE_HalISP(mvPhySensorId[i], mName.c_str()));
}
//3.Wait for Sensor PowerOn
{
success_sensorPowerOn = future_initSensor.get();
if ( ! success_sensorPowerOn ) {
return false;
}
}
//4.Notify 3A of Power On
for (size_t i = 0; i < mvHal3A.size(); i++){
if (mvHal3A[i] != nullptr){
mvHal3A[i]->notifyPowerOn();
}
}
}
这里继续跟踪mvHalSensor[i]->powerOn
,会调用到HalSensor.cpp
中,这里到了和Driver
交互的部分:
(1) 初始化SeninfDrv
;
(2) 初始化SensorDrv
;
(3) setSensorMclk
和setSensorMclkDrivingCurrent
;
(4) 最后通过mpSensorDrv->open
;
MBOOL HalSensor:: powerOn(){
mpSeninfDrv->init();
mpSensorDrv->init();
for (MUINT i = 0; i < uCountOfIndex; i++)
{
setSensorMclk(sensorIdx, 1)
setSensorMclkDrivingCurrent(sensorIdx)
// Open sensor, try to open 3 time
for (int i =0; i < 3; i++) {
if ((ret = mpSensorDrv->open(sensorIdx)) != SENSOR_NO_ERROR) {
MY_LOGE("pSensorDrv->open fail, retry = %d ", i);
}
}
}
}
mpSensorDrv->open
会调用如下,到此featureControl
调用到驱动的SENSOR_FEATURE_OPEN
:
文件位置:vendor/mediatek/proprietary/hardware/mtkcam/drv/src/sensor/mt6765/../common/v1/imgsensor_drv.cpp
MINT32 ImgSensorDrv::open(IMGSENSOR_SENSOR_IDX sensorIdx){
MUINT32 featureParaLen = sizeof(MUINT32);
MUINT32 featurePara;
return featureControl(sensorIdx, SENSOR_FEATURE_OPEN, (MUINT8 *)&featurePara, &featureParaLen);
}
友情推荐:
至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!
点个在看,方便您使用时快速查找!