第16讲 AIDL CameraProvider和CameraDevice初始化 - Android Camera Native Framework

本讲是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教程

计算机教程

大数据教程

开发工具教程

Android Camera Native Framework