From 6885ff1a3ff0565a17d024f85f377013efee5393 Mon Sep 17 00:00:00 2001 From: ljh54_space Date: Thu, 14 Sep 2023 18:07:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=A0=E8=BE=93=E7=9A=84js?= =?UTF-8?q?on=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=B8=AD=E9=94=AE=E5=80=BC?= =?UTF-8?q?=E5=AF=B9=E7=9A=84=E5=80=BC=E5=A4=9A=E4=BD=99=E5=8F=8C=E5=BC=95?= =?UTF-8?q?=E5=8F=B7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ljh54_space --- .../managersink/src/daudio_sink_dev.cpp | 3 -- .../managersource/src/daudio_source_dev.cpp | 36 +++++-------------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/services/audiomanager/managersink/src/daudio_sink_dev.cpp b/services/audiomanager/managersink/src/daudio_sink_dev.cpp index 908b945f..33274a1f 100644 --- a/services/audiomanager/managersink/src/daudio_sink_dev.cpp +++ b/services/audiomanager/managersink/src/daudio_sink_dev.cpp @@ -387,7 +387,6 @@ void DAudioSinkDev::NotifySourceDev(const AudioEventType type, const std::string { std::random_device rd; const uint32_t randomTaskCode = rd(); - cJSON *jEvent = cJSON_CreateObject(); if (jEvent == nullptr) { DHLOGE("Failed to create JSON data."); @@ -397,7 +396,6 @@ void DAudioSinkDev::NotifySourceDev(const AudioEventType type, const std::string cJSON_AddNumberToObject(jEvent, KEY_RESULT, result); cJSON_AddNumberToObject(jEvent, KEY_EVENT_TYPE, static_cast(type)); cJSON_AddNumberToObject(jEvent, KEY_RANDOM_TASK_CODE, randomTaskCode); - DHLOGD("Notify source dev, new engine, random task code:%u", randomTaskCode); if (type == NOTIFY_OPEN_CTRL_RESULT || type == NOTIFY_CLOSE_CTRL_RESULT) { DHLOGE("In new engine mode, ctrl is not allowed."); @@ -411,7 +409,6 @@ void DAudioSinkDev::NotifySourceDev(const AudioEventType type, const std::string return; } std::string messageStr(message); - if (speakerClient_ != nullptr) { speakerClient_->SendMessage(static_cast(type), messageStr, devId_); } diff --git a/services/audiomanager/managersource/src/daudio_source_dev.cpp b/services/audiomanager/managersource/src/daudio_source_dev.cpp index c3a16f4d..528f5f30 100644 --- a/services/audiomanager/managersource/src/daudio_source_dev.cpp +++ b/services/audiomanager/managersource/src/daudio_source_dev.cpp @@ -654,15 +654,14 @@ int32_t DAudioSourceDev::TaskEnableDAudio(const std::string &args) return ERR_DH_AUDIO_NULLPTR; } int32_t dhId = std::atoi(jsonDhId->valuestring); - char *attrs = cJSON_PrintUnformatted(cJSON_GetObjectItem(jParam, KEY_ATTRS)); - std::string attrsStr(attrs); int32_t result = 0; switch (GetDevTypeByDHId(dhId)) { case AUDIO_DEVICE_TYPE_SPEAKER: - result = EnableDSpeaker(dhId, attrsStr); + result = EnableDSpeaker(dhId, + std::string(cJSON_GetObjectItemCaseSensitive(jParam, KEY_ATTRS)->valuestring)); break; case AUDIO_DEVICE_TYPE_MIC: - result = EnableDMic(dhId, attrsStr); + result = EnableDMic(dhId, std::string(cJSON_GetObjectItemCaseSensitive(jParam, KEY_ATTRS)->valuestring)); break; default: DHLOGE("Unknown audio device."); @@ -670,7 +669,6 @@ int32_t DAudioSourceDev::TaskEnableDAudio(const std::string &args) break; } cJSON_Delete(jParam); - cJSON_free(attrs); return result; } @@ -717,18 +715,10 @@ void DAudioSourceDev::OnEnableTaskResult(int32_t resultCode, const std::string & cJSON_Delete(jParam); return; } - char *devId = cJSON_PrintUnformatted(cJSON_GetObjectItem(jParam, KEY_DEV_ID)); - std::string devIdStr(devId); - char *dhId = cJSON_PrintUnformatted(cJSON_GetObjectItem(jParam, KEY_DH_ID)); - std::string dhIdStr(dhId); - mgrCallback_->OnEnableAudioResult(devIdStr, dhIdStr, resultCode); + mgrCallback_->OnEnableAudioResult(std::string(cJSON_GetObjectItemCaseSensitive(jParam, KEY_DEV_ID)->valuestring), + std::string(cJSON_GetObjectItemCaseSensitive(jParam, KEY_DH_ID)->valuestring), + resultCode); cJSON_Delete(jParam); - if (devId != nullptr) { - cJSON_free(devId); - } - if (dhId != nullptr) { - cJSON_free(dhId); - } } int32_t DAudioSourceDev::TaskDisableDAudio(const std::string &args) @@ -815,18 +805,10 @@ void DAudioSourceDev::OnDisableTaskResult(int32_t resultCode, const std::string cJSON_Delete(jParam); return; } - char *devId = cJSON_PrintUnformatted(cJSON_GetObjectItem(jParam, KEY_DEV_ID)); - std::string devIdStr(devId); - char *dhId = cJSON_PrintUnformatted(cJSON_GetObjectItem(jParam, KEY_DH_ID)); - std::string dhIdStr(dhId); - mgrCallback_->OnDisableAudioResult(devIdStr, dhIdStr, resultCode); + mgrCallback_->OnDisableAudioResult(std::string(cJSON_GetObjectItemCaseSensitive(jParam, KEY_DEV_ID)->valuestring), + std::string(cJSON_GetObjectItemCaseSensitive(jParam, KEY_DH_ID)->valuestring), + resultCode); cJSON_Delete(jParam); - if (devId != nullptr) { - cJSON_free(devId); - } - if (dhId != nullptr) { - cJSON_free(dhId); - } } int32_t DAudioSourceDev::TaskOpenDSpeaker(const std::string &args) -- Gitee