mtk android8.1上,camera主摄的调用流程

        mtk的摄像头hal模块,跟android原生的有很大的出入,基本上是自己重写了一套,不熟悉的话,查看起来相当的复杂。特别是在8.0以后,mtk的hal,既使用了hidl接口,又没有完全按照hidl的标准来,底层仍是他们自己的一套流程。如果按google的流程来看,是别想弄明白的。

        前段时间,我调了下mtk的camera,大致弄清了它们的流程。随手记了点笔记,写得比较散乱,懒得整理了,大家能看明白就行。

mtk的camera hal层代码都在这个目录vendor\mediatek\proprietary\hardware\mtkcam\legacy。下面先以预览为例,理清一下预览的流程:

预览::
status_t CameraClient.cpp::startPreview() {
    LOG1("startPreview (pid %d)", getCallingPid());
    return startCameraMode(CAMERA_PREVIEW_MODE);
}

status_t CameraClient.cpp::startCameraMode(camera_mode mode) {
    Mutex::Autolock lock(mLock);
    status_t result = checkPidAndHardware();
    if (result != NO_ERROR) return result;

    switch(mode) {
        case CAMERA_PREVIEW_MODE:
            return startPreviewMode();
        case CAMERA_RECORDING_MODE:
            if (mSurface == 0 && mPreviewWindow == 0) {
                ALOGE("mSurface or mPreviewWindow must be set before startRecordingMode.");
                return INVALID_OPERATION;
            }
            return startRecordingMode();
        default:
            return UNKNOWN_ERROR;
    }
}

status_t CameraClient.cpp::startPreviewMode() {
    status_t result = NO_ERROR;

    if (mHardware->previewEnabled()) {
        return NO_ERROR;
    }
    if (mPreviewWindow != 0) {
        mHardware->setPreviewScalingMode(
            NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
        mHardware->setPreviewTransform(mOrientation);
    }
    mHardware->setPreviewWindow(mPreviewWindow);
    result = mHardware->startPreview();
    if (result == NO_ERROR) {
        sCameraService->updateProxyDeviceState(
            hardware::ICameraServiceProxy::CAMERA_STATE_ACTIVE,
            mCameraIdStr, mCameraFacing, mClientPackageName);
    }
    return result;
}

CameraHardwareInterface.cpp::startPreview()
{
    ALOGV("%s(%s)", __FUNCTION__, mName.string());
    if (CC_LIKELY(mHidlDevice != nullptr)) {
        return CameraProviderManager::mapToStatusT(
                mHidlDevice->startPreview());
    }
    return INVALID_OPERATION;
}

....
中间通过CameraProviderManager,经过了hidl接口,调到了vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\CameraDevice.cpp下的startPreview
....

CameraDevice.cpp::startPreview()
{
....
    return mpDevice->startPreview();
....
}

CameraDevice1Base.cpp::startPreview()
{
....
        ( OK != (status = enableDisplayClient()) )
        {
            goto lbExit;
        }
....
}

CameraDevice1Base.cpp::enableDisplayClient()
{
......
    if  ( ! queryPreviewSize(previewSize.width, previewSize.height) )
    {
        status = DEAD_OBJECT;
        goto lbExit;
    }
    if(mpParamsMgr->getIfFirstPreviewFrameAsBlack())
    {
        mpDisplayClient->setFirstFrameBlack();
        mpParamsMgr->set(MtkCameraParameters::KEY_FIRST_PREVIEW_FRAME_BLACK, 0);
    }
    if  ( ! mpDisplayClient->enableDisplay(previewSize.width, previewSize.height, queryDisplayBufCount(), mpCamAdapter) )
    {
        status = INVALID_OPERATION;
        goto lbExit;
    }
......
}

DisplayClient.cpp::enableDisplay()
{
....
    mpDisplayThread->postCommand(Command(Command::eID_WAKEUP));
....
}

DisplayThread.cpp::postCommand
{
....
    //rCmd为eID_WAKEUP
    mCmdQue.push_back(rCmd);
    mCmdQueCond.broadcast();
....
}

DisplayThread.cpp::threadLoop()
{
    Command cmd;
    if  ( getCommand(cmd) )
    {
        switch  (cmd.eId)
        {
        case Command::eID_EXIT:
            MY_LOGD("Command::%s", cmd.name());
            break;
        //
        case Command::eID_WAKEUP:
        default:
            if  ( mpThreadHandler != 0 )
            {
                mpThreadHandler->onThreadLoop(cmd);
            }
            break;
        }
    }
    return  true;
}

DisplayThread.cpp::getCommand(Command& rCmd)
{
....
    rCmd = *mCmdQue.begin();
....
}

DisplayClient.BufOps.cpp::onThreadLoop(Command const& /*rCmd*/)
{
....
    while   ( 1 )
    {
        ....
        waitAndHandleReturnBuffers(pImgBufQueue);
        ....
    }
....
}

DisplayClient.BufOps.cpp::waitAndHandleReturnBuffers(sp<IImgBufQueue>const& rpBufQueue)
{
....
    ret = handleReturnBuffers(vQueNode);
....
}

DisplayClient.BufOps.cpp::handleReturnBuffers(Vector<ImgBufQueNode>const& rvQueNode)
{
....
    //这个pStreamImgBuf,就是最终显示在屏幕上的数据。我们要加时间水印等,就可以在这条
    //语句的前面加
    enquePrvOps(pStreamImgBuf);
....
}

***********************************************************************************************************
打开摄像头的流程::
1.) vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\devicemgr\depend\instance.cpp
HIDL_FETCH_ICameraProvider(const char* name)
{
    ......
    return createICameraProvider_V2_4(name, getCameraDeviceManager());
}

2.) vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\devicemgr\provider\2.4\CameraProviderImpl.cpp
createICameraProvider_V2_4(const char* providerName, NSCam::ICameraDeviceManager* manager)
{
    ......
    auto provider = new CameraProviderImpl(providerName, manager);
    if ( ! provider ) {
        MY_LOGE("cannot allocate camera provider %s", providerName);
        return nullptr;
    }
    //
    if ( ! provider->initialize() ) {
        MY_LOGE("camera provider %s initialize failed", providerName);
        delete provider;
        provider = nullptr;
    }
    ......    
}



**********************************************************************************************************************
1.0)\frameworks\av\services\camera\libcameraservice\CameraService.cpp
status_t CameraService::enumerateProviders() {
    ......
    mCameraProviderManager = new CameraProviderManager();
    res = mCameraProviderManager->initialize(this);
    ......
}    

1.0.1)\frameworks\av\services\camera\libcameraservice\CameraService.cpp
template<class CALLBACK, class CLIENT>
Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
        int halVersion, const String16& clientPackageName, int clientUid, int clientPid,
        apiLevel effectiveApiLevel, bool legacyMode, bool shimUpdateOnly,
        /*out*/sp<CLIENT>& device) {
    ......
         sp<BasicClient> tmp = nullptr;
        if(!(ret = makeClient(this, cameraCb, clientPackageName, cameraId, facing, clientPid,
                clientUid, getpid(), legacyMode, halVersion, deviceVersion, effectiveApiLevel,
                /*out*/&tmp)).isOk()) {
            return ret;
        }
        client = static_cast<CLIENT*>(tmp.get());
        //这里将刚刚在1.0步初始化好的mCameraProviderManager,传到了CameraClient里面
        err = client->initialize(mCameraProviderManager);           
    ......
}
 1.0.2)frameworks\av\services\camera\libcameraservice\api1\CameraClient.cpp
 status_t CameraClient::initialize(sp<CameraProviderManager> manager) {
     ......
     //这里又一步步的将CameraService里传进来的CameraProviderManager,传给了CameraHardwareInterface
     mHardware = new CameraHardwareInterface(camera_device_name);
     res = mHardware->initialize(manager);
     ......
 }
        
1.0.3)\frameworks\av\services\camera\libcameraservice\device1\CameraHardwareInterface.cpp
status_t CameraHardwareInterface::initialize(sp<CameraProviderManager> manager) {
    //这里的mHidlDevice,是sp<hardware::camera::device::V1_0::ICameraDevice>这个类型。这里一步步的绕,
    //最终将在第6步,将vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\CameraDevice.cpp
    //这个里的接口,都给绑到了mHidlDevice上。然后在CameraHardwareInterface.cpp里,就可以通过mHidlDevice来直接操作
    //mtkcam\legacy\main\hal\device\1.x\device\CameraDevice.cpp这个里面的值了。
    status_t ret = manager->openSession(mName.string(), this, &mHidlDevice);
    return ret;
}


1.0.4)frameworks\av\services\camera\libcameraservice\common\CameraProviderManager.cpp
status_t CameraProviderManager::openSession(const std::string &id,
        const sp<hardware::camera::device::V1_0::ICameraDeviceCallback>& callback,
        /*out*/
        sp<hardware::camera::device::V1_0::ICameraDevice> *session) {
    ALOGD("CameraProviderManager::openSession 2 start, id is %s", id.c_str());
    std::lock_guard<std::mutex> lock(mInterfaceMutex);

    auto deviceInfo = findDeviceInfoLocked(id,
    if (deviceInfo == nullptr) return NAME_NOT_FOUND;

    auto *deviceInfo1 = static_cast<ProviderInfo::DeviceInfo1*>(deviceInfo);

    hardware::Return<Status> status = deviceInfo1->mInterface->open(callback);

    if (status == Status::OK) {
        *session = deviceInfo1->mInterface;
    }
    return mapToStatusT(status);
}
        
1.1)frameworks\av\services\camera\libcameraservice\common\CameraProviderManager.cpp
status_t CameraProviderManager::initialize(wp<CameraProviderManager::StatusListener> listener,
        ServiceInteractionProxy* proxy) {
    ......
    addProviderLocked(kLegacyProviderName, /*expected*/ false);
    ......
}

1.2)frameworks\av\services\camera\libcameraservice\common\CameraProviderManager.cpp
status_t CameraProviderManager::addProviderLocked(const std::string& newProvider, bool expected) {
    ......
    sp<ProviderInfo> providerInfo =
            new ProviderInfo(newProvider, interface, this);
    status_t res = providerInfo->initialize();    
    ......
}


1.3)frameworks\av\services\camera\libcameraservice\common\CameraProviderManager.cpp
status_t CameraProviderManager::ProviderInfo::initialize() {
    ......
    sp<StatusListener> listener = mManager->getStatusListener();
    for (auto& device : devices) {
        std::string id;
        status_t res = addDevice(device,
                hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT, &id);
    }    
    ......
}

1.4)frameworks\av\services\camera\libcameraservice\common\CameraProviderManager.cpp
status_t CameraProviderManager::ProviderInfo::addDevice(const std::string& name,
        CameraDeviceStatus initialStatus, /*out*/ std::string* parsedId) {
    ......
         case 1:
            deviceInfo = initializeDeviceInfo<DeviceInfo1>(name, mProviderTagid,
                    id, minor);
            break;
        case 3:
            deviceInfo = initializeDeviceInfo<DeviceInfo3>(name, mProviderTagid,
                    id, minor);
            break;
    }   
    ......
}

1.5)
frameworks\av\services\camera\libcameraservice\common\CameraProviderManager.cpp
template<class DeviceInfoT>
std::unique_ptr<CameraProviderManager::ProviderInfo::DeviceInfo>
    CameraProviderManager::ProviderInfo::initializeDeviceInfo(
        const std::string &name, const metadata_vendor_id_t tagId,
        const std::string &id, uint16_t minorVersion) const {
    ......
    auto cameraInterface =
            getDeviceInterface<typename DeviceInfoT::InterfaceT>(name);
    ......         
    return std::unique_ptr<DeviceInfo>(
        new DeviceInfoT(name, tagId, id, minorVersion, resourceCost,
                cameraInterface));
    ......
}


2.1)
frameworks\av\services\camera\libcameraservice\common\CameraProviderManager.cpp
template<>
sp<device::V1_0::ICameraDevice>
CameraProviderManager::ProviderInfo::getDeviceInterface
        <device::V1_0::ICameraDevice>(const std::string &name) const {
    Status status;
    sp<device::V1_0::ICameraDevice> cameraInterface;
    hardware::Return<void> ret;
    ret = mInterface->getCameraDeviceInterface_V1_x(name, [&status, &cameraInterface](
        Status s, sp<device::V1_0::ICameraDevice> interface) {
                status = s;
                cameraInterface = interface;
            });
    ......
    return cameraInterface;
}



3.) vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\devicemgr\provider\2.4\CameraProviderImpl.cpp
 ******************************************************************************/
Return<void>
CameraProviderImpl::
getCameraDeviceInterface_V1_x(
    const hidl_string& cameraDeviceName,
    getCameraDeviceInterface_V1_x_cb _hidl_cb)
{
    MY_LOGD("getCameraDeviceInterface_V1_x start");
    getCameraDeviceInterface<::android::hardware::camera::device::V1_0::ICameraDevice>(cameraDeviceName, _hidl_cb);
    return Void();
}

4.) vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\devicemgr\provider\2.4\CameraProviderImpl.cpp
getCameraDeviceInterface(
    const hidl_string& cameraDeviceName,
    InterfaceCallbackT _hidl_cb
)
{
    ......
    auto status = mManager->getDeviceInterface(cameraDeviceName, pBaseDevice);
    ......
}

5.)vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\devicemgr\CameraDeviceManagerBase.cpp
auto
CameraDeviceManagerBase::
getDeviceInterface(
    const std::string& deviceName,
    ::android::sp<IBase_t>& rpDevice
) -> ::android::status_t
{
    ......
    status_t status = pDevice->getDeviceInterfaceBase(rpDevice);
    ......
}

6.)vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\CameraDevice.cpp
auto
CameraDevice::
getDeviceInterfaceBase(
    sp<IBase>& rpDevice
) const -> ::android::status_t
{
    rpDevice = const_cast<IBase*>(
        static_cast<const IBase*>(this));
    return android::OK;
}
上面这里将CameraDevice这个类作为了一个interface,传给了rpDevice。也就是上面从frameworks\av\services\camera\libcameraservice\common\CameraProviderManager.cpp::getDeviceInterface里取到的接口,就是这个vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\CameraDevice.cpp类里的所有接口。


综上所叙,CameraDevice是最关键的一个类,它是用hal层和驱动层的代码。它的open函数,应该就能一步步的调到打开camera驱动的地方。


vendor/mediatek/proprietary/hardware/mtkcam/legacy/main/hal/device/1.x/device/CameraDevice.cpp

CameraDevice.cpp::open(const sp<ICameraDeviceCallback>& callback)
{
    mpDevice = CameraDevice1Base::createCameraDevice(mDeviceManager,
                                  mStaticDeviceInfo->mInstanceName,
                                  mInstanceId);

    if( !mpDevice.get() ){
        MY_LOGE("Create CameraDevice1Base failed!");
        return Status::INTERNAL_ERROR;
    }
    return mpDevice->open(callback);
}

上面这个CameraDevice.cpp::open,可以分两部份来讲,一部份是CameraDevice1Base::createCameraDevice, 一部份是mpDevice->open.咱们先讲下createCameraDevice.
##########################################################################################################################################################

1.1)vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\CameraDevice1Factory.cpp
CameraDevice1Base*
CameraDevice1Base::
createCameraDevice(
    ICameraDeviceManager* deviceManager,
    std::string           instanceName,
    int32_t               instanceId
)
{
    ......
     pDevice = createSpecificCameraDevice1(mClientAppMode,
                                          deviceManager,
                                          instanceName,
                                          instanceId);   
    ......
}

1.2)vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\CameraDevice1Factory.cpp
static
CameraDevice1Base*
createSpecificCameraDevice1(
    String8 const                   s8ClientAppMode,
    ICameraDeviceManager*           deviceManager,
    std::string                     instanceName,
    int32_t                         instanceId
)
{

CameraDevice1Base* pdev = NULL;
    String8 s8CamDeviceInstFactory;
    MY_LOGD("createSpecificCameraDevice1 instanceName is %s", instanceName.c_str());
    //[TODO] check the library name
    String8 const s8LibPath = String8::format("libmtkcam_device1.so");
    void *handle = ::dlopen(s8LibPath.string(), RTLD_GLOBAL);
    ......
    void* pCreateInstance = ::dlsym(handle, s8CamDeviceInstFactory.string());
    ......    
}

1.3)vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\depend\DefaultCameraDevice1.cpp
NSCam::CameraDevice1Base*
createCameraDevice1_Default(
    ICameraDeviceManager* deviceManager,
    std::string           instanceName,
    int32_t               instanceId,
    android::String8 const& rDevName
)
{
    return new DefaultCameraDevice1(deviceManager
                                  , instanceName
                                  , instanceId
                                  , rDevName);

}
1.4)vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\depend\DefaultCameraDevice1.cpp
status_t
DefaultCameraDevice1::
onOpenLocked()
{
    ......
        if  ( OK != CameraDevice1Base::onOpenLocked())
        {
            MY_LOGE("CameraDevice1Base onOpenLocked failed");
            setThreadPriority(policy,priority);
            profile.print("");
            return NO_INIT;
        }    
    ......
}

再讲下加载camera的地方:
1.)vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\depend\DefaultCameraDevice1.cpp
void*
DefaultCameraDevice1::
doThreadSensorOn(void* arg)
{
    ::prctl(PR_SET_NAME,"initCamdevice", 0, 0, 0);
    DefaultCameraDevice1* pSelf = reinterpret_cast<DefaultCameraDevice1*>(arg);
    pSelf->mRet = pSelf->powerOnSensor();
    pthread_exit(NULL);
    return NULL;
}

2.)
vendor\mediatek\proprietary\hardware\mtkcam\legacy\main\hal\device\1.x\device\depend\DefaultCameraDevice1.cpp
bool
DefaultCameraDevice1::
powerOnSensor()
{
    ......
    if( !mpHalSensor->powerOn(USER_NAME, 1, &sensorIdx) )
    {
        MY_LOGE("Sensor power on failed: %d", sensorIdx);
        AEE_ASSERT("\nCRDISPATCH_KEY:MtkCam/Cam1Device:Sensor power on failed");
        return false;
    }    
    ......
}

3.)vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6580\hal\sensor\HalSensor.cpp
MBOOL
HalSensor::
onCreate(
    SortedVector<MUINT>const& vSensorIndex
)
{
    ......
    mpSeninfDrv = SeninfDrv::createInstance();
    ......
}

4.)真正打开camera的地方是在vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6580\hal\sensor\seninf_drv.cpp::int SeninfDrvImp::init() 
{
/*
#define SENSOR_DEV_NAME     "/dev/kd_camera_hw"
#define ISP_DEV_NAME         "/dev/camera-isp"
*/
    ......
    // Open isp driver
    mfd = open(ISP_DEV_NAME, O_RDWR);
    if (mfd < 0) {
        LOG_ERR("error open kernel driver, %d, %s\n", errno, strerror(errno));
        return -1;
    }
    //Open sensor driver
    m_fdSensor = open(SENSOR_DEV_NAME, O_RDWR);
    if (m_fdSensor < 0) {
        LOG_ERR("[init]: error opening  %s \n",  strerror(errno));
        return -13;
    }
    ......
}



######################################################################################################################
CameraDevice1Base.cpp::open(const sp<ICameraDeviceCallback>& callback)
{
......
    status = mDeviceManager->startOpenDevice(instanceName);
......
}

CameraDeviceManagerBase.cpp::startOpenDevice(
    const std::string& deviceName
) -> ::android::status_t
{
....
    status = enumerateDevicesLocked();
....
}

CameraDeviceManagerBase_camera.cpp::enumerateDevicesLocked() -> ::android::status_t
{
    status_t status = OK;
    {
        Utils::CamProfile _profile(__FUNCTION__, "CameraDeviceManagerBase");
        status = onEnumerateDevicesLocked();
        _profile.print("");
    }
    logLocked();
    return status;
}

CameraDeviceManagerImpl.cpp::onEnumerateDevicesLocked() -> ::android::status_t
{
....
#if '1'==MTKCAM_HAVE_METADATAPROVIDER
        //真正的Camera是在IMetadataProvider这里创建的.
        pMetadataProvider = IMetadataProvider::create(instanceId);
        NSMetadataProviderManager::add(instanceId, pMetadataProvider.get());
        MY_LOGD("[0x%02zx] IMetadataProvider:%p sensor:%s", instanceId, pMetadataProvider.get(), pHalSensorList->queryDriverName(instanceId));
#endif
        //
        pPhysDevice->mMetadataProvider   = pMetadataProvider;
        pPhysDevice->mSensorName         = pHalSensorList->queryDriverName(instanceId);
        pPhysDevice->mInstanceId         = instanceId;
        pPhysDevice->mFacing             = pMetadataProvider->getDeviceFacing();
        pPhysDevice->mWantedOrientation  = pMetadataProvider->getDeviceWantedOrientation();
        pPhysDevice->mSetupOrientation   = pMetadataProvider->getDeviceSetupOrientation();
        pPhysDevice->mHasFlashUnit       = pMetadataProvider->getDeviceHasFlashLight();
        //
        addVirtualDevicesLocked(pPhysDevice.get());
....
}

metadataprovider定义在vendor\mediatek\proprietary\hardware\mtkcam\legacy\platform\mt6580\metadata\metadataprovider\MetadataProvider.cpp这个文件里
IMetadataProvider*IMetadataProvider::create(
    int32_t const   i4OpenId
)
{
    MetadataProvider* p = new MetadataProvider(i4OpenId);
    if  ( ! p )
    {
        MY_LOGE("No Memory");
        return  NULL;
    }
    //
    if  ( OK != p->onCreate() )
    {
        MY_LOGE("onCreate");
        delete  p;
        return  NULL;
    }
    //
    return  p;
}

MetadataProvider::MetadataProvider(int32_t const   i4OpenId)
    : mpStaticCharacteristics(NULL)
    , mpHALMetadata()
{
    int32_t sensorType = IHalSensorList::get()->queryType(i4OpenId);

    const char* sensorDrvName = IHalSensorList::get()->queryDriverName(i4OpenId);
    //
    mInfo = Info(i4OpenId, sensorType, sensorDrvName);
    //
    showCustInfo();
}
上面将camera打开后,下面用这个打开的物理camera里取出来的参数,构建一个虚拟的cameraDevice,
后续的操作都是对这个虚拟的cameraDevice操作的

CameraDeviceManagerBase_camera.cpp::addVirtualDevicesLocked(PhysEnumDevice* pPhyDevice) -> void
{
....
        uint32_t const deviceVersion = pMetadataProvider->getDeviceVersion();
        uint32_t const majorDeviceVersion = queryMajorDeviceVersion(deviceVersion);
        switch (majorDeviceVersion)
        {
        case 1:{//Enumerating device 1.x + 3.x(latest)
            create_and_add_virtual_device(1);
            if  ( mSupportLatestDevice ) {
                create_and_add_virtual_device(3);
            }
            }break;

        case 3:{//Enumerating device 3.x + 1.x(legacy)
            create_and_add_virtual_device(3);
            if  ( mSupportLegacyDevice ) {
                create_and_add_virtual_device(1);
            }
            }break;

        default:{
            MY_LOGW(
                "unsupported device instance id:%d deviceVersion:0x%x majorDeviceVersion:%d",
                instanceId, deviceVersion, majorDeviceVersion);
            }break;
        }
....
}

CameraDeviceManagerBase_camera.cpp::addVirtualDevicesLocked(PhysEnumDevice* pPhyDevice) -> void
{
....
    auto create_and_add_virtual_device = [&](uint32_t majorVersion){
            auto create_device = mVirtEnumDeviceFactoryMap[majorVersion].mCreateVirtualCameraDevice;
            if ( create_device == nullptr ) {
                CAM_LOGE("The symbole createVirtualCameraDevice for device version %d does not exist!!!", majorVersion);
                return;
            }
            CreateVirtualCameraDeviceParams param = {
                .instanceId = static_cast<int32_t>(instanceId),
                .deviceType = mType.c_str(),
                .pMetadataProvider = pMetadataProvider.get(),
                .pDeviceManager = this,
            };
            auto new_device = create_device(&param);
            add_virtual_device(new_device);
        };
....
}

CameraDevice.cpp::createVirtualCameraDevice(CreateVirtualCameraDeviceParams* params)
{
    CameraDevice* pDevice = new CameraDevice(
                                     params->pDeviceManager,
                                     params->pMetadataProvider,
                                     params->deviceType,
                                     params->instanceId);
    return pDevice;
}

CameraDevice.cpp::CameraDevice(
    ICameraDeviceManager* deviceManager,
    IMetadataProvider* metadataProvider,
    char const* deviceType,
    int32_t instanceId
)
    : mDeviceManager(deviceManager)
    , mStaticDeviceInfo(nullptr)
    , mMetadataProvider(metadataProvider)
    , mDeviceType(deviceType)
    , mInstanceId(instanceId)
{
    MY_LOGD("ENTRY: CameraDevice contruction");
    mStaticDeviceInfo = std::make_shared<Info>();
    if (mStaticDeviceInfo != nullptr) {
        mStaticDeviceInfo->mInstanceName    = String8::format("device@%u.%u/%s/%d", kMajorDeviceVersion, kMinorDeviceVersion, deviceType, instanceId).string();
        mStaticDeviceInfo->mInstanceId      = instanceId;
        mStaticDeviceInfo->mMajorVersion    = kMajorDeviceVersion;
        mStaticDeviceInfo->mMinorVersion    = kMinorDeviceVersion;
        mStaticDeviceInfo->mHasFlashUnit    = metadataProvider->getDeviceHasFlashLight();
    }
}

      本人建了个android camera系统 微信群,不过现在群成员超200了,不能通过二维码扫码加入,有兴趣的,可以加我微信号:xuhui_7810,到时拉你们入群。

 

参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

xuhui_7810

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值