From c656134fb47bd3bb044de45f1e186e232efbfacc Mon Sep 17 00:00:00 2001 From: bao92 Date: Mon, 27 May 2024 22:40:15 +0800 Subject: [PATCH] modify the lazy load Signed-off-by: bao92 --- .../server/src/drm_host_manager.cpp | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/services/drm_service/server/src/drm_host_manager.cpp b/services/drm_service/server/src/drm_host_manager.cpp index 818178ff..dcb70d6f 100644 --- a/services/drm_service/server/src/drm_host_manager.cpp +++ b/services/drm_service/server/src/drm_host_manager.cpp @@ -315,30 +315,32 @@ int32_t DrmHostManager::GetSevices(std::string &name, bool *isSurpported) DRM_DEBUG_LOG("DrmHostManager::GetSevices, the plugin service has been pulled up."); return DRM_OK; } - /* - * If the plugin is configured with lazy loading, read the service name from the configuration file. - * If lazy loading is not configured, traverse the service bound by the interface descriptor, and obtain - * the plugin service instance through the uuid and issuport interfaces - */ - loadPluginInfo(PLUGIN_LAZYLOAD_CONFIG_PATH); + auto servmgr = IServiceManager::Get(); + ret = servmgr->ListServiceByInterfaceDesc(serviceName, "ohos.hdi.drm.v1_0.IMediaKeySystemFactory"); + if (ret != DRM_OK) { + DRM_ERR_LOG("ListServiceByInterfaceDesc faild, return Code:%{public}d", ret); + return ret; + } if (lazyLoadPluginInfoMap.count(name) > 0) { - sptr deviceMgr = IDeviceManager::Get(); - if (deviceMgr == nullptr) { - DRM_ERR_LOG("DrmHostManager:GetSevices deviceMgr == nullptr"); - return DRM_SERVICE_ERROR; - } - ret = deviceMgr->LoadDevice(lazyLoadPluginInfoMap[name]); - if (ret != DRM_OK) { - DRM_ERR_LOG("DrmHostManager LoadDevice return Code:%{public}d", ret); - return DRM_HOST_ERROR; - } - serviceName.push_back(lazyLoadPluginInfoMap[name]); - } else { - auto servmgr = IServiceManager::Get(); - ret = servmgr->ListServiceByInterfaceDesc(serviceName, "ohos.hdi.drm.v1_0.IMediaKeySystemFactory"); - if (ret != DRM_OK) { - DRM_ERR_LOG("ListServiceByInterfaceDesc faild, return Code:%{public}d", ret); - return ret; + auto it = std::find(serviceName.begin(), serviceName.end(), lazyLoadPluginInfoMap[name]); + if (it == serviceName.end()) { + /* + * If the plugin is configured with lazy loading, read the service name from the configuration file. + * If lazy loading is not configured, traverse the service bound by the interface descriptor, and obtain + * the plugin service instance through the uuid and issuport interfaces + */ + loadPluginInfo(PLUGIN_LAZYLOAD_CONFIG_PATH); + sptr deviceMgr = IDeviceManager::Get(); + if (deviceMgr == nullptr) { + DRM_ERR_LOG("DrmHostManager:GetSevices deviceMgr == nullptr"); + return DRM_SERVICE_ERROR; + } + ret = deviceMgr->LoadDevice(lazyLoadPluginInfoMap[name]); + if (ret != DRM_OK) { + DRM_ERR_LOG("DrmHostManager LoadDevice return Code:%{public}d", ret); + return DRM_HOST_ERROR; + } + serviceName.push_back(lazyLoadPluginInfoMap[name]); } } for (auto hdiServiceName : serviceName) { @@ -522,6 +524,12 @@ int32_t DrmHostManager::GetMediaKeySystems(std::map &m std::vector lazyLoadServiceNames; std::vector pluginServiceNames; std::unique_lock lock(lazyLoadPluginInfoMapMtx); + auto servmgr = IServiceManager::Get(); + ret = servmgr->ListServiceByInterfaceDesc(pluginServiceNames, "ohos.hdi.drm.v1_0.IMediaKeySystemFactory"); + if (ret != DRM_OK) { + DRM_ERR_LOG("ListServiceByInterfaceDesc faild, return Code:%{public}d", ret); + return ret; + } /* * If the plugin is configured with lazy loading, read the service name from the configuration file. * If lazy loading is not configured, traverse the service bound by the interface descriptor, and obtain @@ -531,14 +539,13 @@ int32_t DrmHostManager::GetMediaKeySystems(std::map &m sptr deviceMgr = IDeviceManager::Get(); if (deviceMgr == nullptr) { DRM_ERR_LOG("DrmHostManager:GetSevices deviceMgr == nullptr"); - return DRM_SERVICE_ERROR; } for (auto pluginInfoIt = lazyLoadPluginInfoMap.begin(); pluginInfoIt != lazyLoadPluginInfoMap.end(); pluginInfoIt++) { ret = deviceMgr->LoadDevice(pluginInfoIt->second); if (ret != DRM_OK) { DRM_ERR_LOG("DrmHostManager LoadDevice return Code:%{public}d", ret); - return DRM_HOST_ERROR; + continue; } lazyLoadServiceNames.push_back(pluginInfoIt->second); if (pluginCountMap.empty()) { @@ -547,12 +554,6 @@ int32_t DrmHostManager::GetMediaKeySystems(std::map &m pluginCountMap[pluginInfoIt->first]++; } } - auto servmgr = IServiceManager::Get(); - ret = servmgr->ListServiceByInterfaceDesc(pluginServiceNames, "ohos.hdi.drm.v1_0.IMediaKeySystemFactory"); - if (ret != DRM_OK) { - DRM_ERR_LOG("ListServiceByInterfaceDesc faild, return Code:%{public}d", ret); - return ret; - } for (uint32_t i = 0; i < lazyLoadServiceNames.size(); i++) { bool found = false; for (uint32_t j = 0; i < pluginServiceNames.size(); j++) {