第16讲 aidl cameraprovider和cameradevice初始化 -凯发k8手机登录

本讲是android camera native framework专题的第16讲,我们介绍cameraserver进程启动之aidl cameraprovider和cameradevice初始化。

更多资源:

资源 描述
在线课程
知识星球 星球名称:深入浅出android camera 星球id: 17296815
wechat 极客笔记圈

aidl camera provider初始化

aidl camera provider初始化

trytoaddaidlproviderslocked相关代码(来自android 13)

status_t cameraprovidermanager::trytoaddaidlproviderslocked() {
    const char * aidlhalservicedescriptor =
            aidl::android::hardware::camera::provider::icameraprovider::descriptor;
    auto sm = defaultservicemanager();
    auto aidlproviders = sm->getdeclaredinstances(
            string16(aidlhalservicedescriptor));
    for (const auto &aidlinstance : aidlproviders) {
        std::string aidlservicename =
                getfullaidlprovidername(std::string(string8(aidlinstance).c_str()));
        auto res = sm->registerfornotifications(string16(aidlservicename.c_str()), this);
        if (res != ok) {
            aloge("%s unable to register for notifications with aidl service manager",
                    __function__);
            return res;
        }
        addaidlproviderlocked(aidlservicename);
    }
    return ok;
}

trytoaddaidlproviderslocked相关代码(来自android 13)

status_t aidlproviderinfo::initializeaidlprovider(
        std::shared_ptr& interface, int64_t currentdevicestate) {
    status_t res = parseprovidername(mprovidername, &mtype, &mid);
    if (res != ok) {
        aloge("%s: invalid provider name, ignoring", __function__);
        return bad_value;
    }
    alogi("connecting to new camera provider: %s, isremote? %d",
            mprovidername.c_str(), interface->isremote());
    // cameradevicestatuschange callbacks may be called (and causing new devices added)
    // before setcallback returns
    mcallbacks =
            ndk::sharedrefbase::make(this);
    ndk::scopedastatus status =
            interface->setcallback(mcallbacks);
    if (!status.isok()) {
        aloge("%s: transaction error setting up callbacks with camera provider '%s': %s",
                __function__, mprovidername.c_str(), status.getmessage());
        return maptostatust(status);
    }
    mdeathrecipient = ndk::scopedaibinder_deathrecipient(aibinder_deathrecipient_new(binderdied));
    auto link = aibinder_linktodeath(interface->asbinder().get(), mdeathrecipient.get(), this);
    if (link != status_ok) {
        alogw("%s: unable to link to provider '%s' death notifications",
                __function__, mprovidername.c_str());
        return dead_object;
    }
    if (!kenablelazyhal) {
        // save hal reference indefinitely
        msavedinterface = interface;
    } else {
        mactiveinterface = interface;
    }
    alogv("%s: setting device state for %s: 0x%" prix64,
            __function__, mprovidername.c_str(), mdevicestate);
    notifydevicestatechange(currentdevicestate);
    res = setupvendortags();
    if (res != ok) {
        aloge("%s: unable to set up vendor tags from provider '%s'",
                __function__, mprovidername.c_str());
        return res;
     }
    // get initial list of camera devices, if any
    std::vector devices;
    std::vector retdevices;
    status = interface->getcameraidlist(&retdevices);
    if (!status.isok()) {
        aloge("%s: transaction error in getting camera id list from provider '%s': %s",
                __function__, mprovidername.c_str(), status.getmessage());
        return maptostatust(status);
    }
    for (auto& name : retdevices) {
        uint16_t major, minor;
        std::string type, id;
        status_t res = parsedevicename(name, &major, &minor, &type, &id);
        if (res != ok) {
            aloge("%s: error parsing devicename: %s: %d", __function__, name.c_str(), res);
            return res;
        } else {
            devices.push_back(name);
            mproviderpubliccameraids.push_back(id);
        }
    }
    // get list of concurrent streaming camera device combinations
    res = getconcurrentcameraidsinternallocked(interface);
    if (res != ok) {
        return res;
    }
    msettorchmodesupported = true;
    misremote = interface->isremote();
    initializeproviderinfocommon(devices);
    return ok;
}

aidl cameradevice初始化

与hidl cameradevice初始化逻辑一样,请参考第10-14讲的内容。

aidlproviderinfo::initializedeviceinfo完成3件事情

步骤 描述 aidlproviderinfo::initializedeviceinfo
第1步 获取到icameradevice的实例 调用icameraprovider的getcameradeviceinterface获取到icameradevice的实例
第2步 getresourcecost 调用icameradevice的getresourcecost获取到resource cost
第3步 创建aidldeviceinfo3 处理静态信息,比如获取systemcamerakind和修复/更新 mcameracharacteristics

创建aidldeviceinfo3完成5件事情

步骤 描述 aidldeviceinfo3::aidldeviceinfo3
第1步 获取cameracharacteristics 调用getcameracharacteristics对mcameracharacteristics赋值
第2步 获取devicestateorientationmap 获取android_info_device_state_orientations的值,保存在mdevicestateorientationmap
第3步 获取到msystemcamerakind 调用getsystemcamerakind获取到msystemcamerakind – 如果capability是android_request_available_capabilities_secure_image_data,则返回systemcamerakind::hidden_secure_camera – 如果capability有android_request_available_capabilities_system_camera,则返回systemcamerakind::system_only_camera – 其他情况返回systemcamerakind::public
第4步 修复/更新 mcameracharacteristics fixupmonochrometags、adddynamicdepthtags、deriveheictags、addrotatecroptags、addprecorrectionactivearraysize、overridezoomratiotags、fixuptorchstrengthtags、queryphysicalcameraids
第5步 修复/更新 未public 出去的physicalcamera characteristics overridezoomratiotags

camera课程

python教程

java教程

web教程

数据库教程

图形图像教程

办公软件教程

linux教程

计算机教程

大数据教程

开发工具教程

网站地图