audio DevicesFactory

audio DevicesFactoryandroid

 

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.hui

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對象,以下:
hardware\interfaces\audio\core\all-versions\default\include\core\all-versions\default\DevicesFactory.impl.h
IDevicesFactory* HIDL_FETCH_IDevicesFactory(const char* /* name */) { return new DevicesFactory(); }

 DevicesFactory繼承了IDevicesFactory(這個類在soong/.intermediates下)spa

繼續PassthroughServiceManager::get(),這個函數接下來會call RegisterReference(actualFqName, name),這個actualFqName就是在DevicesFactoryAll.cpp裏的IDevicesFactory::descriptor,它的值爲android.hardware.audio@4.0::IDevicesFactorycode

 

因此getRawServiceInternal() return了一個DevicesFactory對象,回到getServiceInternal(),由於DevicesFactory是繼承IDevicesFactory,而IDevicesFactory::isRemote()會返回false,因此會執行下面的IType::castFrom(base),這個函數是直接return parent,便是return base參數,也就是DevicesFactory對象。對象

 

而後返回到registerPassthroughServiceImplementation(),而後執行service->registerAsService(),即爲執行IDevicesFactory::registerAsService()blog

 

上面會去open android.hardware.audio@4.0-impl.so,這個so的查找路徑在:繼承

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

#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它的呢?以下:rem

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", ], }
相關文章
相關標籤/搜索