From c0fac6985924f2b0312b134720c47a349394d4f6 Mon Sep 17 00:00:00 2001 From: byndyx Date: Tue, 23 Apr 2024 19:30:15 +0800 Subject: [PATCH] v-d Signed-off-by: byndyx --- audiohandler/include/daudio_handler.h | 1 + audiohandler/src/daudio_handler.cpp | 53 ++++++++++++++++++- .../managersource/src/daudio_source_dev.cpp | 8 ++- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/audiohandler/include/daudio_handler.h b/audiohandler/include/daudio_handler.h index 33bd82c6..d86a71e8 100644 --- a/audiohandler/include/daudio_handler.h +++ b/audiohandler/include/daudio_handler.h @@ -40,6 +40,7 @@ DECLARE_SINGLE_INSTANCE_BASE(DAudioHandler); public: int32_t Initialize() override; std::vector Query() override; + std::vector QueryMeta() override; std::map QueryExtraInfo() override; bool IsSupportPlugin() override; void RegisterPluginListener(std::shared_ptr listener) override; diff --git a/audiohandler/src/daudio_handler.cpp b/audiohandler/src/daudio_handler.cpp index 1f0c4d9f..9b6d6a6f 100644 --- a/audiohandler/src/daudio_handler.cpp +++ b/audiohandler/src/daudio_handler.cpp @@ -102,7 +102,7 @@ bool DAudioHandler::AddItemsToObject(DHItem &dhItem, cJSON* infoJson, const int3 std::vector DAudioHandler::Query() { - DHLOGI("Query distributed hardware information."); + DHLOGI("Query full distributed hardware information."); auto audioSrv = AudioStandard::AudioSystemManager::GetInstance(); std::vector dhItemVec; if (audioSrv == nullptr) { @@ -126,6 +126,57 @@ std::vector DAudioHandler::Query() } cJSON_AddNumberToObject(infoJson, "INTERRUPT_GROUP_ID", dev->interruptGroupId_); cJSON_AddNumberToObject(infoJson, "VOLUME_GROUP_ID", dev->volumeGroupId_); + cJSON_AddNumberToObject(infoJson, "DataType", "full"); + dhItem.dhId = AddDhIdPrefix(std::to_string(dhId)); + char *jsonInfo = cJSON_Print(infoJson); + if (jsonInfo == NULL) { + DHLOGE("Failed to create JSON data."); + cJSON_Delete(infoJson); + return dhItemVec; + } + dhItem.attrs = jsonInfo; + dhItemVec.push_back(dhItem); + DHLOGD("Query result: dhId: %{public}d, subtype: %{public}s, attrs: %{public}s.", + dhId, dhItem.subtype.c_str(), jsonInfo); + if (dhId == DEFAULT_RENDER_ID) { + dhItem.dhId = AddDhIdPrefix(std::to_string(LOW_LATENCY_RENDER_ID)); + dhItemVec.push_back(dhItem); + DHLOGD("Query result: dhId: %{public}d, attrs: %{public}s.", LOW_LATENCY_RENDER_ID, jsonInfo); + } + cJSON_Delete(infoJson); + cJSON_free(jsonInfo); + } + ablityForDumpVec_ = dhItemVec; + return dhItemVec; +} + +std::vector DAudioHandler::QueryMeta() +{ + DHLOGI("Query meta distributed hardware information."); + auto audioSrv = AudioStandard::AudioSystemManager::GetInstance(); + std::vector dhItemVec; + if (audioSrv == nullptr) { + DHLOGE("Unable to get audio system manager."); + return dhItemVec; + } + + auto audioDevices = audioSrv->GetDevices(AudioStandard::DeviceFlag::ALL_DEVICES_FLAG); + for (auto dev : audioDevices) { + auto dhId = audioSrv->GetPinValueFromType(dev->deviceType_, dev->deviceRole_); + + cJSON* infoJson = cJSON_CreateObject(); + if (infoJson == nullptr) { + DHLOGE("Failed to create cJSON object."); + return dhItemVec; + } + DHItem dhItem; + if (!AddItemsToObject(dhItem, infoJson, dhId)) { + cJSON_Delete(infoJson); + return dhItemVec; + } + cJSON_AddNumberToObject(infoJson, "INTERRUPT_GROUP_ID", dev->interruptGroupId_); + cJSON_AddNumberToObject(infoJson, "VOLUME_GROUP_ID", dev->volumeGroupId_); + cJSON_AddNumberToObject(infoJson, "DataType", "meta"); dhItem.dhId = AddDhIdPrefix(std::to_string(dhId)); char *jsonInfo = cJSON_Print(infoJson); if (jsonInfo == NULL) { diff --git a/services/audiomanager/managersource/src/daudio_source_dev.cpp b/services/audiomanager/managersource/src/daudio_source_dev.cpp index e6abf306..15be183f 100644 --- a/services/audiomanager/managersource/src/daudio_source_dev.cpp +++ b/services/audiomanager/managersource/src/daudio_source_dev.cpp @@ -611,12 +611,16 @@ int32_t DAudioSourceDev::EnableDSpeaker(const int32_t dhId, const std::string &a { std::lock_guard devLck(ioDevMtx_); if (deviceMap_.find(dhId) != deviceMap_.end()) { - DHLOGI("The speaker device is already enabled."); + DHLOGI("The speaker device is enabled, enable it with full data this time."); + if (deviceMap_[dhId]->EnableDevice(dhId, attrs) != DH_SUCCESS) { + DHLOGI("Failed to enable speaker device with full data."); + return ERR_DH_AUDIO_FAILED; + } return DH_SUCCESS; } auto speaker = std::make_shared(devId_, shared_from_this()); if (speaker->EnableDevice(dhId, attrs) != DH_SUCCESS) { - DHLOGI("Failed to enable speaker device."); + DHLOGI("Failed to enable speaker device first time."); return ERR_DH_AUDIO_FAILED; } deviceMap_[dhId] = speaker; -- Gitee