From 19583a96b8efeab96a32d323baf7697de557880f Mon Sep 17 00:00:00 2001 From: t00605578 Date: Fri, 1 Dec 2023 17:34:20 +0800 Subject: [PATCH] fix mic closed and close mic concurrent calls Signed-off-by: t00605578 --- .../managersource/include/daudio_source_dev.h | 2 + .../managersource/src/daudio_source_dev.cpp | 64 ++++++++++++++++--- .../include/daudio_volume_internal.h | 1 + .../src/daudio_param_callback_internal.cpp | 1 + 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/services/audiomanager/managersource/include/daudio_source_dev.h b/services/audiomanager/managersource/include/daudio_source_dev.h index 05e70d5c..79e24d1b 100644 --- a/services/audiomanager/managersource/include/daudio_source_dev.h +++ b/services/audiomanager/managersource/include/daudio_source_dev.h @@ -67,6 +67,7 @@ private: int32_t TaskCloseDSpeaker(const std::string &args); int32_t TaskOpenDMic(const std::string &args); int32_t TaskCloseDMic(const std::string &args); + int32_t TaskDMicClosed(const std::string &args); int32_t TaskSetVolume(const std::string &args); int32_t TaskChangeVolume(const std::string &args); int32_t TaskChangeFocus(const std::string &args); @@ -153,6 +154,7 @@ private: void CloseDSpeakerCallback(const AppExecFwk::InnerEvent::Pointer &event); void OpenDMicCallback(const AppExecFwk::InnerEvent::Pointer &event); void CloseDMicCallback(const AppExecFwk::InnerEvent::Pointer &event); + void DMicClosedCallback(const AppExecFwk::InnerEvent::Pointer &event); void SetVolumeCallback(const AppExecFwk::InnerEvent::Pointer &event); void ChangeVolumeCallback(const AppExecFwk::InnerEvent::Pointer &event); void ChangeFocusCallback(const AppExecFwk::InnerEvent::Pointer &event); diff --git a/services/audiomanager/managersource/src/daudio_source_dev.cpp b/services/audiomanager/managersource/src/daudio_source_dev.cpp index da48b3ed..da289694 100644 --- a/services/audiomanager/managersource/src/daudio_source_dev.cpp +++ b/services/audiomanager/managersource/src/daudio_source_dev.cpp @@ -36,6 +36,7 @@ constexpr uint32_t EVENT_OPEN_SPEAKER = 11; constexpr uint32_t EVENT_CLOSE_SPEAKER = 12; constexpr uint32_t EVENT_OPEN_MIC = 21; constexpr uint32_t EVENT_CLOSE_MIC = 22; +constexpr uint32_t EVENT_DMIC_CLOSED = 24; constexpr uint32_t EVENT_VOLUME_SET = 31; constexpr uint32_t EVENT_VOLUME_CHANGE = 33; constexpr uint32_t EVENT_AUDIO_FOCUS_CHANGE = 41; @@ -329,18 +330,20 @@ int32_t DAudioSourceDev::HandleDMicOpened(const AudioEvent &event) int32_t DAudioSourceDev::HandleDMicClosed(const AudioEvent &event) { - DHLOGI("Mic device closed, event.content = %s.", event.content.c_str()); - int32_t dhId = ParseDhidFromEvent(event.content); - if (dhId < 0) { - DHLOGE("Failed to parse dhardware id."); - return ERR_DH_AUDIO_FAILED; + DHLOGI("Dmic device closed, event.content = %s.", event.content.c_str()); + if (handler_ == nullptr) { + DHLOGE("Event handler is null."); + return ERR_DH_AUDIO_NULLPTR; } - auto mic = FindIoDevImpl(event.content); - if (mic == nullptr) { - DHLOGE("Mic already closed."); - return DH_SUCCESS; + + auto eventParam = std::make_shared(event); + auto msgEvent = AppExecFwk::InnerEvent::Get(EVENT_DMIC_CLOSED, eventParam, 0); + if (!handler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { + DHLOGE("Send event failed."); + return ERR_DH_AUDIO_FAILED; } - return mic->NotifyHdfAudioEvent(event, dhId); + DHLOGD("Dmic closed event is sent successfully."); + return DH_SUCCESS; } int32_t DAudioSourceDev::HandleCtrlTransClosed(const AudioEvent &event) @@ -1002,6 +1005,27 @@ int32_t DAudioSourceDev::TaskCloseDMic(const std::string &args) return DH_SUCCESS; } +int32_t DAudioSourceDev::TaskDMicClosed(const std::string &args) +{ + DHLOGI("Task dmic closed, args: %s.", args.c_str()); + if (args.length() > DAUDIO_MAX_JSON_LEN || args.empty()) { + DHLOGE("Args length err. 0 or max."); + return ERR_DH_AUDIO_SA_PARAM_INVALID; + } + int32_t dhId = ParseDhidFromEvent(args); + if (dhId < 0) { + DHLOGE("Failed to parse dhardware id."); + return ERR_DH_AUDIO_FAILED; + } + auto mic = FindIoDevImpl(args); + if (mic == nullptr) { + DHLOGE("Mic already clear."); + return DH_SUCCESS; + } + AudioEvent event(MIC_CLOSED, args); + return mic->NotifyHdfAudioEvent(event, dhId); +} + int32_t DAudioSourceDev::TaskSetVolume(const std::string &args) { DHLOGD("Task set volume, args: %s.", args.c_str()); @@ -1286,6 +1310,7 @@ DAudioSourceDev::SourceEventHandler::SourceEventHandler(const std::shared_ptrTaskDMicClosed(eventParam) != DH_SUCCESS) { + DHLOGE("Deal dmic closed failed."); + return; + } + DHLOGI("Deal dmic closed successfully."); +} + void DAudioSourceDev::SourceEventHandler::SetVolumeCallback(const AppExecFwk::InnerEvent::Pointer &event) { std::string eventParam; diff --git a/services/hdfaudioclient/include/daudio_volume_internal.h b/services/hdfaudioclient/include/daudio_volume_internal.h index ca6a8b06..b48f4a42 100644 --- a/services/hdfaudioclient/include/daudio_volume_internal.h +++ b/services/hdfaudioclient/include/daudio_volume_internal.h @@ -36,6 +36,7 @@ public: static int32_t SetGain(AudioHandle handle, float gain); static int32_t GetGain(AudioHandle handle, float *gain); }; + template int32_t AudioVolumeInternal::SetMute(AudioHandle handle, bool mute) { diff --git a/services/hdfaudioclient/src/daudio_param_callback_internal.cpp b/services/hdfaudioclient/src/daudio_param_callback_internal.cpp index cb89b82c..18cea822 100644 --- a/services/hdfaudioclient/src/daudio_param_callback_internal.cpp +++ b/services/hdfaudioclient/src/daudio_param_callback_internal.cpp @@ -41,6 +41,7 @@ private: ::ParamCallback callback_ = nullptr; void *cookie_ = nullptr; }; + AudioParamCallbackContext::AudioParamCallbackContext(::ParamCallback callback, void *cookie) { callbackStub_ = new AudioParamCallbackImpl(callback, cookie); -- Gitee