• CameraProvider进程-Android12


    CameraProvider进程-Android12

    android12-release
    CameraService启动-Android12 看到CameraProviderManager与CameraProvider进程建立联系。这里我们查看一下CameraProvider进程
    在这里插入图片描述


    1. rc文件android.hardware.camera.provider@2.4-service_64.rc

    CameraProvider进程名:vendor.camera-provider-2-4
    bin文件:/vendor/bin/hw/android.hardware.camera.provider@2.4-service_64
    对应启动入口:hardware/interfaces/camera/provider/2.4/default/service.cpp

    hardware/interfaces/camera/provider/2.4/default/android.hardware.camera.provider@2.4-service_64.rc
    在这里插入图片描述 在这里插入图片描述

    2. service.cpp#main()启动

    • android::ProcessState::initWithDriver("/dev/vndbinder"); kernel底层/dev/vndbinder驱动
    • defaultPassthroughServiceImplementation("legacy/0", 6) 直通式Passthrough注册服务给hwservicemanager。(其中使用了#include 类,ICameraProvider类是由HIDL接口定义文件 ICameraProvider.hal 经过hidl-gen编译工具编译生成
    int main()
    {
        ALOGI("CameraProvider@2.4 legacy service is starting.");
        // The camera HAL may communicate to other vendor components via
        // /dev/vndbinder
        android::ProcessState::initWithDriver("/dev/vndbinder");
    
        // b/166675194
        if (property_get_bool("ro.vendor.camera.provider24.disable_mem_init", false)) {
            if (mallopt(M_BIONIC_ZERO_INIT, 0) == 0) {
                // Note - heap initialization is only present on devices with Scudo.
                // Devices with jemalloc don't have heap-init, and thus the mallopt
                // will fail. On these devices, you probably just want to remove the
                // property.
                ALOGE("Disabling heap initialization failed.");
            }
        }
    
        status_t status;
        if (kLazyService) {
            status = defaultLazyPassthroughServiceImplementation<ICameraProvider>("legacy/0",
                                                                                  /*maxThreads*/ 6);
        } else {
            status = defaultPassthroughServiceImplementation<ICameraProvider>("legacy/0",
                                                                              /*maxThreads*/ 6);
        }
        return status;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    2.1 ICameraProvider.hal生成CameraProvider.h

    可以查看 HIDL实战笔记,相关文件查看上面rc目录等相关文件。HIDL机制本身是跨进程通信,所以Camera Service本身通过HIDL接口获取的对象都会有Bn端和Bp端,分别代表了Binder两端。
    hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.h
    hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.cpp

    ICameraProvider.hal文件中定义了ICameraProvider接口类,由CameraProvider继承并实现,主要接口如下:

    • getCameraDeviceInterface_V3_x: 该方法主要用于Camera Service获取ICameraDevice,通过该对象可以控制Camera 设备的诸如配置数据流、下发request等具体行为。
    • setCallback:将Camera Service 实现的ICameraProviderCallback传入Camera Provider,一旦Provider有事件产生时便可以通过该对象通知Camera Service。

    ICameraProviderCallback.hal文件中定义了ICameraProviderCallback回调接口类,该接口由Camera Service 中的CameraProviderManager::ProviderInfo继承并实现,在Camera Service 启动的时候被实例化,通过调用ICameraProvider::setCallback接口注册到Camera Provider中,其主要接口如下:

    • cameraDeviceStatusChange:将Camera 设备状态上传至Camera Service,状态由CameraDeviceStatus定义

    hardware/interfaces/camera/provider/2.4/ICameraProvider.hal

    package android.hardware.camera.provider@2.4;
    
    import ICameraProviderCallback;
    import android.hardware.camera.common@1.0::types;
    import android.hardware.camera.device@1.0::ICameraDevice;
    import android.hardware.camera.device@3.2::ICameraDevice;
    
    interface ICameraProvider {
    
        setCallback(ICameraProviderCallback callback) generates (Status status);
    
        getVendorTags() generates (Status status, vec<VendorTagSection> sections);
    
        getCameraIdList()
                generates (Status status, vec<string> cameraDeviceNames);
    
        isSetTorchModeSupported() generates (Status status, bool support);
    
        getCameraDeviceInterface_V1_x(string cameraDeviceName) generates
                (Status status,
                 android.hardware.camera.device@1.0::ICameraDevice device);
        getCameraDeviceInterface_V3_x(string cameraDeviceName) generates
                (Status status,
                 android.hardware.camera.device@3.2::ICameraDevice device);
    
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    hardware/interfaces/camera/provider/2.4/ICameraProviderCallback.hal

    package android.hardware.camera.provider@2.4;
    
    import android.hardware.camera.common@1.0::types;
    
    /**
     * Callback functions for a camera provider HAL to use to inform the camera
     * service of changes to the camera subsystem.
     */
    interface ICameraProviderCallback {
    
        cameraDeviceStatusChange(string cameraDeviceName,
                CameraDeviceStatus newStatus);
    
        torchModeStatusChange(string cameraDeviceName,
                TorchModeStatus newStatus);
    
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    2.2 HIDL直通式

    ServiceManagement.cpp中openLibs() 调用到CameraProvider_2_4.cppHIDL_FETCH_ICameraProvider(const char* name)方法
    HAL 接口定义语言 (AIDL/HIDL) 在 Android 10 中,HIDL 功能已整合到 AIDL 中。此后,HIDL 就被废弃了,并且仅供尚未转换为 AIDL 的子系统使用。

    system/libhidl/transport/include/hidl/LegacySupport.h
    system/libhidl/transport/LegacySupport.cpp
    system/libhidl/transport/ServiceManagement.cpp
    hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.cpp

    fqName为android.hardware.camera.provider@2.4::ICameraProvider
    在这里插入图片描述
    在这里插入图片描述 在这里插入图片描述

    2.3 CameraProvider初始化模板

    template其中IMPL相关文件hardware/interfaces/camera/provider/2.4/default/LegacyCameraProviderImpl_2_4.cpp、hardware/interfaces/camera/provider/2.4/default/ExternalCameraProviderImpl_2_4.cpp

    hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.h

    template<typename IMPL>
    struct CameraProvider : public ICameraProvider {
        CameraProvider() : impl() {}
        ~CameraProvider() {}
    
        // Caller must use this method to check if CameraProvider ctor failed
        bool isInitFailed() { return impl.isInitFailed(); }
    
        // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
        Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override {
            return impl.setCallback(callback);
        }
    
        Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override {
            return impl.getVendorTags(_hidl_cb);
        }
    
        Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override {
            return impl.getCameraIdList(_hidl_cb);
        }
    
        Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override {
            return impl.isSetTorchModeSupported(_hidl_cb);
        }
    
        Return<void> getCameraDeviceInterface_V1_x(
                const hidl_string& cameraDeviceName,
                getCameraDeviceInterface_V1_x_cb _hidl_cb) override {
            return impl.getCameraDeviceInterface_V1_x(cameraDeviceName, _hidl_cb);
        }
    
        Return<void> getCameraDeviceInterface_V3_x(
                const hidl_string& cameraDeviceName,
                getCameraDeviceInterface_V3_x_cb _hidl_cb) override {
            return impl.getCameraDeviceInterface_V3_x(cameraDeviceName, _hidl_cb);
        }
    
    private:
        IMPL impl;
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.cpp

    template<typename IMPL>
    CameraProvider<IMPL>* getProviderImpl() {
        CameraProvider<IMPL> *provider = new CameraProvider<IMPL>();
        if (provider == nullptr) {
            ALOGE("%s: cannot allocate camera provider!", __FUNCTION__);
            return nullptr;
        }
        if (provider->isInitFailed()) {
            ALOGE("%s: camera provider init failed!", __FUNCTION__);
            delete provider;
            return nullptr;
        }
        return provider;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    3. 简要时序图

    在这里插入图片描述

    4. HAL硬件框架

    深入理解高通 Camx CHI 架构 - segmentfault
    高通CamX关键流程 - 腾讯云
    CamX关键流程 - 简书

  • 相关阅读:
    C语言自学笔记3-----C语言运算符及优先级
    前端全局工具函数utils.js/正则(持续更新)
    windows设置右键打开 vscode的方法(简易版)
    深度学习之基于Pytorch服装图像分类识别系统
    android 车载widget小部件部分详细源码实战开发-千里马车载车机framework开发实战课程
    EasyOCR 常用方法参数说明
    vb加了me
    Codeforces Round #796 (Div. 2) A. Cirno‘s Perfect Bitmasks Classroom
    单源最短路的简单应用
    QT将数据写入文件,日志记录
  • 原文地址:https://blog.csdn.net/qq_23452385/article/details/126120705