第8讲 cameraserver进程启动之enumerateProviders概述 - Android Camera Native Framework

本讲是Android Camera Native Framework专题的第8讲,我们介绍cameraserver进程启动之enumerateProviders概述

更多资源:

资源 描述
在线课程 极客笔记在线课程
知识星球 星球名称:深入浅出Android Camera 星球ID: 17296815
Wechat 极客笔记圈

Android Camera HAL接口简介

Android Camera HAL接口分成HIDL和AIDL两种,核心接口如下:

Android Camera HAL接口简介

注:接口代码路径:/hardware/interfaces/camera/

解释:

  • ICameraProvider管理多个ICameraDevice
  • ICameraDevice管理和维护某一颗CameraDevice
  • 通过ICameraProvider获取到ICameraDevice
  • 通过ICameraDevice获取到ICameraDeviceSession
  • 初始化时,ICameraProvider和ICameraDevice的实例就会被创建起来, ICameraDeviceSession要open camera时才创建,close camera时销毁

CameraService与CameraProviderManager的关系

CameraProviderManager

  • 负责管理Camera HAL Providers

CameraService

  • ICameraService的实现,CameraService与HAL Provider的交互要通过CameraProviderManager

CameraService与CameraProviderManager的关系

CameraProviderManager中的ProviderInfo

CameraProviderManager抽象出ProviderInfo来屏蔽HIDL和AIDL Provider的差异,将差异部分交给HidlProviderInfo和AidlProviderInfo去处理。

CameraProviderManager中的ProviderInfo

enumerateProviders总体流程介绍

有哪些情况会调用到enumerateProviders

  • CameraServer进程启动时(onFirstRef)
  • CameraServer进程启动后,有新的Provider注册到ServiceManager时(onNewProviderRegistered)

总体流程代码介绍

  1. 创建CameraProviderManager,并调用initialize完成初始化
  2. 初始化 VendorTags
  3. 初始化Flashlight并完成枚举动作
  4. 针对前/后摄,为SPerfClass过滤CameraCharacteristics

    • 参考CDD:2.2.7. Handheld Media Performance Class

代码基于Android 13:

status_t CameraService::enumerateProviders() {
    status_t res;

    std::vector deviceIds;
    {
        Mutex::Autolock l(mServiceLock);

        if (nullptr == mCameraProviderManager.get()) {
            mCameraProviderManager = new CameraProviderManager();
            res = mCameraProviderManager->initialize(this);
            if (res != OK) {
                ALOGE("%s: Unable to initialize camera provider manager: %s (%d)",
                        __FUNCTION__, strerror(-res), res);
                logServiceError(String8::format("Unable to initialize camera provider manager"),
                ERROR_DISCONNECTED);
                return res;
            }
        }

        // Setup vendor tags before we call get_camera_info the first time
        // because HAL might need to setup static vendor keys in get_camera_info
        // TODO: maybe put this into CameraProviderManager::initialize()?
        mCameraProviderManager->setUpVendorTags();

        if (nullptr == mFlashlight.get()) {
            mFlashlight = new CameraFlashlight(mCameraProviderManager, this);
        }

        res = mFlashlight->findFlashUnits();
        if (res != OK) {
            ALOGE("Failed to enumerate flash units: %s (%d)", strerror(-res), res);
        }

        deviceIds = mCameraProviderManager->getCameraDeviceIds();
    }

    for (auto& cameraId : deviceIds) {
        String8 id8 = String8(cameraId.c_str());
        if (getCameraState(id8) == nullptr) {
            onDeviceStatusChanged(id8, CameraDeviceStatus::PRESENT);
        }
    }

    // Derive primary rear/front cameras, and filter their charactierstics.
    // This needs to be done after all cameras are enumerated and camera ids are sorted.
    if (SessionConfigurationUtils::IS_PERF_CLASS) {
        // Assume internal cameras are advertised from the same
        // provider. If multiple providers are registered at different time,
        // and each provider contains multiple internal color cameras, the current
        // logic may filter the characteristics of more than one front/rear color
        // cameras.
        Mutex::Autolock l(mServiceLock);
        filterSPerfClassCharacteristicsLocked();
    }

    return OK;
}

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程

Android Camera Native Framework