zoukankan      html  css  js  c++  java
  • audio DevicesFactory

    audio DevicesFactory

    xref: /hardware/interfaces/audio/common/all-versions/default/service/service.cpp

    int main(int /* argc */, char* /* argv */ []) {
        android::ProcessState::initWithDriver("/dev/vndbinder");
        // start a threadpool for vndbinder interactions
        android::ProcessState::self()->startThreadPool();
        configureRpcThreadpool(16, true /*callerWillJoin*/);
    
        bool fail = registerPassthroughServiceImplementation<audio::V4_0::IDevicesFactory>() != OK &&
                    registerPassthroughServiceImplementation<audio::V2_0::IDevicesFactory>() != OK;
        LOG_ALWAYS_FATAL_IF(fail, "Could not register audio core API 2.0 nor 4.0");
    
        fail = registerPassthroughServiceImplementation<audio::effect::V4_0::IEffectsFactory>() != OK &&
               registerPassthroughServiceImplementation<audio::effect::V2_0::IEffectsFactory>() != OK,
        LOG_ALWAYS_FATAL_IF(fail, "Could not register audio effect API 2.0 nor 4.0");
    
        fail = registerPassthroughServiceImplementation<soundtrigger::V2_1::ISoundTriggerHw>() != OK &&
               registerPassthroughServiceImplementation<soundtrigger::V2_0::ISoundTriggerHw>() != OK,
        ALOGW_IF(fail, "Could not register soundtrigger API 2.0 nor 2.1");
    
        fail =
            registerPassthroughServiceImplementation<bluetooth::a2dp::V1_0::IBluetoothAudioOffload>() !=
            OK;
        ALOGW_IF(fail, "Could not register Bluetooth audio offload 1.0");
    
        joinRpcThreadpool();
    }
    registerPassthroughServiceImplementation()

    xref: /system/libhidl/transport/include/hidl/LegacySupport.h

    template<class Interface>
    __attribute__((warn_unused_result))
    status_t registerPassthroughServiceImplementation(
            std::string name = "default") {
        sp<Interface> service = Interface::getService(name, true /* getStub */);
    
        if (service == nullptr) {
            ALOGE("Could not get passthrough implementation for %s/%s.",
                Interface::descriptor, name.c_str());
            return EXIT_FAILURE;
        }
    
        LOG_FATAL_IF(service->isRemote(), "Implementation of %s/%s is remote!",
                Interface::descriptor, name.c_str());
    
        status_t status = service->registerAsService(name);
    
        if (status == OK) {
            ALOGI("Registration complete for %s/%s.",
                Interface::descriptor, name.c_str());
        } else {
            ALOGE("Could not register service %s/%s (%d).",
                Interface::descriptor, name.c_str(), status);
        }
    
        return status;
    }

    上面Interface::getService()中的getStub参数为true,所以在ServiceManagement.cpp中的getRawServiceInternal()中,会直接走下面的pm = getPassthroughServiceManager(); pm->get()
    所以会执行PassthroughServiceManager::get(),这个函数也在ServiceManagement.cpp里。这个函数会去open so库,以IDevicesFactory为例,会去open android.hardware.audio@4.0-impl.so。open后会call这个so里的HIDL_FETCH_IDevicesFactory(),而这个函数会new一个DevicesFactory对象,如下:
    hardwareinterfacesaudiocoreall-versionsdefaultincludecoreall-versionsdefaultDevicesFactory.impl.h
    IDevicesFactory* HIDL_FETCH_IDevicesFactory(const char* /* name */) {
    
    return new DevicesFactory();
    
    }

     DevicesFactory继承了IDevicesFactory(这个类在soong/.intermediates下)

    继续PassthroughServiceManager::get(),这个函数接下来会call RegisterReference(actualFqName, name),这个actualFqName就是在DevicesFactoryAll.cpp里的IDevicesFactory::descriptor,它的值为android.hardware.audio@4.0::IDevicesFactory

    所以getRawServiceInternal() return了一个DevicesFactory对象,回到getServiceInternal(),因为DevicesFactory是继承IDevicesFactory,而IDevicesFactory::isRemote()会返回false,所以会执行下面的IType::castFrom(base),这个函数是直接return parent,即是return base参数,也就是DevicesFactory对象。

    然后返回到registerPassthroughServiceImplementation(),然后执行service->registerAsService(),即为执行IDevicesFactory::registerAsService()

    上面会去open android.hardware.audio@4.0-impl.so,这个so的查找路径在:

    xref: /system/libhidl/base/include/hidl/HidlInternal.h

    #define HAL_LIBRARY_PATH_SYSTEM_64BIT "/system/lib64/hw/"
    #define HAL_LIBRARY_PATH_VNDK_SP_64BIT_FOR_VERSION "/system/lib64/vndk-sp%s/hw/"
    #define HAL_LIBRARY_PATH_VENDOR_64BIT "/vendor/lib64/hw/"
    #define HAL_LIBRARY_PATH_ODM_64BIT    "/odm/lib64/hw/"
    #define HAL_LIBRARY_PATH_SYSTEM_32BIT "/system/lib/hw/"
    #define HAL_LIBRARY_PATH_VNDK_SP_32BIT_FOR_VERSION "/system/lib/vndk-sp%s/hw/"
    #define HAL_LIBRARY_PATH_VENDOR_32BIT "/vendor/lib/hw/"
    #define HAL_LIBRARY_PATH_ODM_32BIT    "/odm/lib/hw/"
    
    #if defined(__LP64__)
    #define HAL_LIBRARY_PATH_SYSTEM HAL_LIBRARY_PATH_SYSTEM_64BIT
    #define HAL_LIBRARY_PATH_VNDK_SP_FOR_VERSION HAL_LIBRARY_PATH_VNDK_SP_64BIT_FOR_VERSION
    #define HAL_LIBRARY_PATH_VENDOR HAL_LIBRARY_PATH_VENDOR_64BIT
    #define HAL_LIBRARY_PATH_ODM    HAL_LIBRARY_PATH_ODM_64BIT
    #else
    #define HAL_LIBRARY_PATH_SYSTEM HAL_LIBRARY_PATH_SYSTEM_32BIT
    #define HAL_LIBRARY_PATH_VNDK_SP_FOR_VERSION HAL_LIBRARY_PATH_VNDK_SP_32BIT_FOR_VERSION
    #define HAL_LIBRARY_PATH_VENDOR HAL_LIBRARY_PATH_VENDOR_32BIT
    #define HAL_LIBRARY_PATH_ODM    HAL_LIBRARY_PATH_ODM_32BIT
    #endif

    那这个android.hardware.audio@4.0-impl.so是哪个makefile去build它的呢?如下:

    cc_library_shared {
        name: "android.hardware.audio@4.0-impl",
        relative_install_path: "hw",
        proprietary: true,
        vendor: true,
        srcs: [
            "Conversions.cpp",
            "Device.cpp",
            "DevicesFactory.cpp",
            "ParametersUtil.cpp",
            "PrimaryDevice.cpp",
            "Stream.cpp",
            "StreamIn.cpp",
            "StreamOut.cpp",
        ],
    
        cflags: [
            "-DAUDIO_HAL_VERSION_4_0",
        ],
    
        defaults: ["hidl_defaults"],
    
        export_include_dirs: ["include"],
    
        shared_libs: [
            "libbase",
            "libcutils",
            "libfmq",
            "libhardware",
            "libhidlbase",
            "libhidltransport",
            "liblog",
            "libutils",
            "android.hardware.audio@4.0",
            "android.hardware.audio.common@4.0",
            "android.hardware.audio.common@4.0-util",
            "android.hardware.audio.common-util",
        ],
    
        header_libs: [
            "android.hardware.audio.common.util@all-versions",
            "android.hardware.audio.core@all-versions-impl",
            "libaudioclient_headers",
            "libaudio_system_headers",
            "libhardware_headers",
            "libmedia_headers",
        ],
    
        whole_static_libs: [
            "libmedia_helper",
        ],
    
    }
  • 相关阅读:
    CSS媒体查询
    搜索关键词标注红色
    揭秘 | 小白如何0基础0元建站
    细说浏览器输入URL后发生了什么
    js问题总结
    vue elementui如何修改el-table头部样式
    h5开发微信公众号重定向到关注页面没有关注按钮 (微信你个坑)
    下拉展开动画
    html中常用的转义字符总结
    9个设计师常用的高清图库 不敢配图? 这9个免版权图库牢记心中!
  • 原文地址:https://www.cnblogs.com/aspirs/p/11605154.html
Copyright © 2011-2022 走看看