diff --git a/audiohandler/include/daudio_handler.h b/audiohandler/include/daudio_handler.h index 33bd82c6d3dfbfade4da6a849dc9490b9cf0b78a..d86a71e8ce95dd7808438753d2b894a6734a48b3 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 1f0c4d9f00816307cb903be92f0f4c7561ddb205..9b6d6a6f995970cbb94d3a14b702a36a80e4a5dc 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 e6abf306e14526122dab8c44196dceee69acbdd8..15be183fd16362175b248ec6526b368f4ffc87d7 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;