MTK camera打开流程介绍

和你一起终身学习,这里是程序员 Android

经典好文推荐,通过阅读本文,您将收获以下知识点:

一、整体介绍
1、MiddleWare(MW)层介绍
2、Pipeline介绍
二、Camera Open流程

一、整体介绍

首先看下mtkcam的整体框架图如下包含了很多的内容,其中camera的打开流程也贯穿在其中,从Camera APK 一层层的系统调用到driver再到Hardware层,这篇文章主要从Pipeline开始介绍打开camera的流程,JAVA/Cameraservice/MiddleWare层后续再进行介绍:

1、MiddleWare(MW)层介绍

ICameraProvider: 向上暴露的接口调用,实现是在CameraProverideer中;
[email protected] 用于Camera Service去操作各个Camera device的操作,实现在CameraDevice3中;
[email protected] Camera会话的接口;
ICameraDeviceCallBack: 底层对上层的CallBack接口;
CameraDeviceManager: 用于管理CameraDevice,包括查找,打开,关闭等。

2、Pipeline介绍

PipelineModelHAL3核心架构,对上需要开放对Pipeline创建 & 操作的API,对下需要建立Pipeline & 管理Pipeline的生命周期。PipelineModel会针对不同的场景创建不同的PipelineHWNodeHWNode向下传输APP层的命令,向上传递图形数据:
P1Node: pipelineroot nodeinput app命令,output raw data to P2CaptureNode and P2StreamNode
P2CaptureNode: 转换raw data to yuvsSupport scale/crop
P2StreamingNode:P2CaptureNode功能类似;
JPEGNode: Convert YUV to Jpeg
FDNode: Generate the FD information

二、Camera Open流程

1、在APP层调用openCam后会调用的CameraDevice层,最后调用到driver中,整体的调用流程如下:

文件位置:
./vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/device/CameraDevice3SessionImpl.cpp

auto ThisNamespace::open(
    const ::android::sp& 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& 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;
}

这里主要看PipelineModelOpen函数如下:
文件位置:
vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/model/PipelineModelImpl.cpp

auto PipelineModelImpl::open(
    std::string const& userName,
    android::wp const& callback) -> int
{
    {
        std::lock_guard _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 const    mHalDeviceAdapter;
                        && CC_LIKELY( mHalDeviceAdapter->powerOn() );
                }
            )
        ); 
    }
    return OK;
}

再调用mHalDeviceAdapterOpen用于初始化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 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) setSensorMclksetSensorMclkDrivingCurrent

(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);
}

原文链接
https://blog.csdn.net/karaskass/article/details/106270105?spm=1001.2014.3001.5502

至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!

你可能感兴趣的:(MTK camera打开流程介绍)