From d8f1ea667301bf81edc5526cf1ef8117e433b043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A6=E5=9B=BD=E5=BA=86?= Date: Thu, 11 Jul 2024 10:56:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98=EF=BC=9A?= =?UTF-8?q?=E5=9B=9E=E9=80=80audio=E5=89=8D=E7=BC=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韦国庆 --- audiohandler/src/daudio_handler.cpp | 4 +-- common/include/daudio_util.h | 2 -- common/src/daudio_util.cpp | 29 ------------------- .../test/unittest/src/daudio_utils_test.cpp | 26 ++++------------- .../audio_sink/src/daudio_sink_handler.cpp | 4 +-- .../audio_source/src/daudio_ipc_callback.cpp | 4 +-- .../src/daudio_source_handler.cpp | 6 ++-- .../managersource/src/daudio_source_dev.cpp | 8 ++--- 8 files changed, 19 insertions(+), 64 deletions(-) diff --git a/audiohandler/src/daudio_handler.cpp b/audiohandler/src/daudio_handler.cpp index 5accbe88..b9c19d79 100644 --- a/audiohandler/src/daudio_handler.cpp +++ b/audiohandler/src/daudio_handler.cpp @@ -140,7 +140,7 @@ std::vector DAudioHandler::RealQuery(const std::string &dataType) cJSON_AddNumberToObject(infoJson, INTERRUPT_GROUP_ID, dev->interruptGroupId_); cJSON_AddNumberToObject(infoJson, VOLUME_GROUP_ID, dev->volumeGroupId_); cJSON_AddStringToObject(infoJson, KEY_DATATYPE, dataType.c_str()); - dhItem.dhId = AddDhIdPrefix(std::to_string(dhId)); + dhItem.dhId = std::to_string(dhId); char *jsonInfo = cJSON_Print(infoJson); if (jsonInfo == NULL) { DHLOGE("Failed to create JSON data."); @@ -152,7 +152,7 @@ std::vector DAudioHandler::RealQuery(const std::string &dataType) 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)); + dhItem.dhId = 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); } diff --git a/common/include/daudio_util.h b/common/include/daudio_util.h index 07a42e57..de3ecdaa 100644 --- a/common/include/daudio_util.h +++ b/common/include/daudio_util.h @@ -55,8 +55,6 @@ void SaveFile(std::string fileName, uint8_t *audioData, int32_t size); std::string GetCJsonString(const char *key, const char *value); std::string ParseStringFromArgs(std::string args, const char *key); std::string GetEventNameByType(const int32_t eventType); -std::string AddDhIdPrefix(const std::string &dhId); -std::string ReduceDhIdPrefix(const std::string &dhId); template bool GetSysPara(const char *key, T &value); diff --git a/common/src/daudio_util.cpp b/common/src/daudio_util.cpp index 38b270c0..adef28dc 100644 --- a/common/src/daudio_util.cpp +++ b/common/src/daudio_util.cpp @@ -490,35 +490,6 @@ std::string ParseStringFromArgs(std::string args, const char *key) return content; } -std::string AddDhIdPrefix(const std::string &dhId) -{ - std::string prefix = "Audio_"; - size_t pos = dhId.find(prefix); - DHLOGD("Append the prefix. The current dhId is %{public}s.", dhId.c_str()); - if (pos != std::string::npos) { - DHLOGD("No need to add prefix."); - return dhId; - } else { - prefix.append(dhId); - DHLOGD("After append the prefix. The current dhId is %{public}s.", prefix.c_str()); - return prefix; - } -} - -std::string ReduceDhIdPrefix(const std::string &dhId) -{ - std::string prefix = "Audio_"; - size_t pos = dhId.find(prefix); - DHLOGD("Delete the prefix. The current dhId is %{public}s.", dhId.c_str()); - if (pos != std::string::npos) { - DHLOGD("After delete the prefix. The current dhId is %{public}s.", dhId.substr(prefix.size()).c_str()); - return dhId.substr(prefix.size()); - } else { - DHLOGD("No need to delete prefix."); - return dhId; - } -} - template bool GetSysPara(const char *key, T &value) { diff --git a/common/test/unittest/src/daudio_utils_test.cpp b/common/test/unittest/src/daudio_utils_test.cpp index d1ac4d3b..37b60bc9 100644 --- a/common/test/unittest/src/daudio_utils_test.cpp +++ b/common/test/unittest/src/daudio_utils_test.cpp @@ -311,23 +311,9 @@ HWTEST_F(DAudioUtilsTest, DAudioUtilTest_007, TestSize.Level1) EXPECT_EQ(true, CheckDevIdIsLegal(tempDevIdStr)); } -/** - * @tc.name: DAudioLogTest_009 - * @tc.desc: Verify the AddDhIdPrefix and ReduceDhIdPrefix function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DAudioUtilsTest, DAudioUtilTest_009, TestSize.Level1) -{ - EXPECT_EQ(AddDhIdPrefix("1394302"), "Audio_1394302"); - EXPECT_EQ(AddDhIdPrefix("Audio_1394302"), "Audio_1394302"); - EXPECT_EQ(ReduceDhIdPrefix("Audio_1394302"), "1394302"); - EXPECT_EQ(ReduceDhIdPrefix("1394302"), "1394302"); -} - /** * @tc.name: DAudioLogTest_010 - * @tc.desc: Verify the AddDhIdPrefix and ReduceDhIdPrefix function. + * @tc.desc: Verify the cjson function. * @tc.type: FUNC * @tc.require: AR000H0E5U */ @@ -351,7 +337,7 @@ HWTEST_F(DAudioUtilsTest, DAudioUtilTest_010, TestSize.Level1) /** * @tc.name: DAudioLogTest_011 - * @tc.desc: Verify the AddDhIdPrefix and ReduceDhIdPrefix function. + * @tc.desc: Verify the cjson function. * @tc.type: FUNC * @tc.require: AR000H0E5U */ @@ -375,7 +361,7 @@ HWTEST_F(DAudioUtilsTest, DAudioUtilTest_011, TestSize.Level1) /** * @tc.name: DAudioLogTest_012 - * @tc.desc: Verify the AddDhIdPrefix and ReduceDhIdPrefix function. + * @tc.desc: Verify the IsAudioParam function. * @tc.type: FUNC * @tc.require: AR000H0E5U */ @@ -396,7 +382,7 @@ HWTEST_F(DAudioUtilsTest, DAudioUtilTest_012, TestSize.Level1) /** * @tc.name: DAudioLogTest_013 - * @tc.desc: Verify the AddDhIdPrefix and ReduceDhIdPrefix function. + * @tc.desc: Verify the IsParamEnabled function. * @tc.type: FUNC * @tc.require: AR000H0E5U */ @@ -409,7 +395,7 @@ HWTEST_F(DAudioUtilsTest, DAudioUtilTest_013, TestSize.Level1) /** * @tc.name: DAudioLogTest_014 - * @tc.desc: Verify the AddDhIdPrefix and ReduceDhIdPrefix function. + * @tc.desc: Verify the GetSysPara function. * @tc.type: FUNC * @tc.require: AR000H0E5U */ @@ -424,7 +410,7 @@ HWTEST_F(DAudioUtilsTest, DAudioUtilTest_014, TestSize.Level1) /** * @tc.name: DAudioLogTest_015 - * @tc.desc: Verify the AddDhIdPrefix and ReduceDhIdPrefix function. + * @tc.desc: Verify the AbsoluteSleep function. * @tc.type: FUNC * @tc.require: AR000H0E5U */ diff --git a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp index d03625ab..ba86c043 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp +++ b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp @@ -101,7 +101,7 @@ int32_t DAudioSinkHandler::SubscribeLocalHardware(const std::string &dhId, const if (dhId.length() > DAUDIO_MAX_DEVICE_ID_LEN) { return ERR_DH_AUDIO_SA_DEVID_ILLEGAL; } - std::string reduceDhId = ReduceDhIdPrefix(dhId); + std::string reduceDhId = dhId; int32_t ret = dAudioSinkProxy_->SubscribeLocalHardware(reduceDhId, param); return ret; } @@ -114,7 +114,7 @@ int32_t DAudioSinkHandler::UnsubscribeLocalHardware(const std::string &dhId) if (dhId.length() > DAUDIO_MAX_DEVICE_ID_LEN) { return ERR_DH_AUDIO_SA_DEVID_ILLEGAL; } - std::string reduceDhId = ReduceDhIdPrefix(dhId); + std::string reduceDhId = dhId; int32_t ret = dAudioSinkProxy_->UnsubscribeLocalHardware(reduceDhId); return ret; } diff --git a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback.cpp b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback.cpp index c5c86ca4..d0551cfe 100644 --- a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback.cpp +++ b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback.cpp @@ -39,7 +39,7 @@ int32_t DAudioIpcCallback::OnNotifyRegResult(const std::string &devId, const std std::lock_guard registerLck(registerMapMtx_); auto iter = registerCallbackMap_.find(reqId); if (iter != registerCallbackMap_.end()) { - std::string reduceDhId = AddDhIdPrefix(dhId); + std::string reduceDhId = dhId; iter->second->OnRegisterResult(devId, reduceDhId, status, resultData); registerCallbackMap_.erase(reqId); return DH_SUCCESS; @@ -62,7 +62,7 @@ int32_t DAudioIpcCallback::OnNotifyUnregResult(const std::string &devId, const s std::lock_guard registerLck(unregisterMapMtx_); auto iter = unregisterCallbackMap_.find(reqId); if (iter != unregisterCallbackMap_.end()) { - std::string reduceDhId = AddDhIdPrefix(dhId); + std::string reduceDhId = dhId; iter->second->OnUnregisterResult(devId, reduceDhId, status, resultData); unregisterCallbackMap_.erase(reqId); return DH_SUCCESS; diff --git a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_handler.cpp b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_handler.cpp index d43861d1..d8ce97d7 100644 --- a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_handler.cpp +++ b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_handler.cpp @@ -108,7 +108,7 @@ int32_t DAudioSourceHandler::RegisterDistributedHardware(const std::string &devI std::string reqId = GetRandomID(); dAudioIpcCallback_->PushRegisterCallback(reqId, callback); - std::string reduceDhId = ReduceDhIdPrefix(dhId); + std::string reduceDhId = dhId; return dAudioSourceProxy_->RegisterDistributedHardware(devId, reduceDhId, param, reqId); } @@ -126,7 +126,7 @@ int32_t DAudioSourceHandler::UnregisterDistributedHardware(const std::string &de std::string reqId = GetRandomID(); dAudioIpcCallback_->PushUnregisterCallback(reqId, callback); - std::string reduceDhId = ReduceDhIdPrefix(dhId); + std::string reduceDhId = dhId; return dAudioSourceProxy_->UnregisterDistributedHardware(devId, reduceDhId, reqId); } @@ -140,7 +140,7 @@ int32_t DAudioSourceHandler::ConfigDistributedHardware(const std::string &devId, if (devId.length() > DAUDIO_MAX_DEVICE_ID_LEN || dhId.length() > DAUDIO_MAX_DEVICE_ID_LEN) { return ERR_DH_AUDIO_SA_DEVID_ILLEGAL; } - std::string reduceDhId = ReduceDhIdPrefix(dhId); + std::string reduceDhId = dhId; return dAudioSourceProxy_->ConfigDistributedHardware(devId, reduceDhId, key, value); } diff --git a/services/audiomanager/managersource/src/daudio_source_dev.cpp b/services/audiomanager/managersource/src/daudio_source_dev.cpp index 300c50c9..f153a4f5 100644 --- a/services/audiomanager/managersource/src/daudio_source_dev.cpp +++ b/services/audiomanager/managersource/src/daudio_source_dev.cpp @@ -867,7 +867,7 @@ int32_t DAudioSourceDev::TaskOpenDSpeaker(const std::string &args) DHLOGE("Task Open DSpeaker Execute failed, error code %{public}d.", ret); return ret; } - NotifyFwkRunning(devId_, AddDhIdPrefix(std::to_string(dhId))); + NotifyFwkRunning(devId_, std::to_string(dhId)); cJSON_Delete(jAudioParam); return DH_SUCCESS; } @@ -973,7 +973,7 @@ int32_t DAudioSourceDev::TaskCloseDSpeaker(const std::string &args) return ret; } NotifyHDF(NOTIFY_CLOSE_SPEAKER_RESULT, HDF_EVENT_RESULT_SUCCESS, dhId); - NotifyFwkIdle(devId_, AddDhIdPrefix(std::to_string(dhId))); + NotifyFwkIdle(devId_, std::to_string(dhId)); return DH_SUCCESS; } @@ -1043,7 +1043,7 @@ int32_t DAudioSourceDev::TaskOpenDMic(const std::string &args) return ret; } NotifyHDF(NOTIFY_OPEN_MIC_RESULT, HDF_EVENT_RESULT_SUCCESS, dhId); - NotifyFwkRunning(devId_, AddDhIdPrefix(std::to_string(dhId))); + NotifyFwkRunning(devId_, std::to_string(dhId)); cJSON_Delete(jAudioParam); return DH_SUCCESS; } @@ -1090,7 +1090,7 @@ int32_t DAudioSourceDev::TaskCloseDMic(const std::string &args) return ret; } NotifyHDF(NOTIFY_CLOSE_MIC_RESULT, HDF_EVENT_RESULT_SUCCESS, dhId); - NotifyFwkIdle(devId_, AddDhIdPrefix(std::to_string(dhId))); + NotifyFwkIdle(devId_, std::to_string(dhId)); return DH_SUCCESS; } -- Gitee