From 74ed0799f1bfeb8411a479be9564a558b2d3ba2d Mon Sep 17 00:00:00 2001 From: byndyx Date: Fri, 10 May 2024 16:48:28 +0800 Subject: [PATCH] v-d2 Signed-off-by: byndyx --- .../managersource/include/daudio_source_dev.h | 8 ++++++++ .../managersource/src/daudio_source_dev.cpp | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/services/audiomanager/managersource/include/daudio_source_dev.h b/services/audiomanager/managersource/include/daudio_source_dev.h index 87e56b74..7e821c15 100644 --- a/services/audiomanager/managersource/include/daudio_source_dev.h +++ b/services/audiomanager/managersource/include/daudio_source_dev.h @@ -37,6 +37,12 @@ namespace OHOS { namespace DistributedHardware { +enum DaudioBusinessState : int32_t { + UNKNOWN, + IDLE, + RUNNING, + PAUSING +}; class DAudioSourceDev : public IAudioEventCallback, public std::enable_shared_from_this { public: DAudioSourceDev(const std::string &devId, const std::shared_ptr &callback); @@ -76,6 +82,8 @@ private: int32_t TaskSpkMmapStop(const std::string &args); int32_t TaskMicMmapStart(const std::string &args); int32_t TaskMicMmapStop(const std::string &args); + void NotifyFwkRunning(const std::string &devId, const std::string &dhId); + void NotifyFwkIdle(const std::string &devId, const std::string &dhId); void OnDisableTaskResult(int32_t resultCode, const std::string &result, const std::string &funcName); void OnEnableTaskResult(int32_t resultCode, const std::string &result, const std::string &funcName); diff --git a/services/audiomanager/managersource/src/daudio_source_dev.cpp b/services/audiomanager/managersource/src/daudio_source_dev.cpp index a0125af5..8c0a9da3 100644 --- a/services/audiomanager/managersource/src/daudio_source_dev.cpp +++ b/services/audiomanager/managersource/src/daudio_source_dev.cpp @@ -714,6 +714,16 @@ void DAudioSourceDev::OnDisableTaskResult(int32_t resultCode, const std::string cJSON_Delete(jParam); } +void DAudioSourceDev::NotifyFwkRunning(const std::string &devId, const std::string &dhId) +{ + DAudioSourceManager::GetInstance().OnHardwareStateChanged(devId, dhId, DaudioBusinessState::RUNNING); +} + +void DAudioSourceDev::NotifyFwkIdle(const std::string &devId, const std::string &dhId) +{ + DAudioSourceManager::GetInstance().OnHardwareStateChanged(devId, dhId, DaudioBusinessState::IDLE); +} + int32_t DAudioSourceDev::TaskOpenDSpeaker(const std::string &args) { DAudioHitrace trace("DAudioSourceDev::TaskOpenDSpeaker"); @@ -757,6 +767,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))); cJSON_Delete(jAudioParam); return DH_SUCCESS; } @@ -863,6 +874,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))); return DH_SUCCESS; } @@ -892,7 +904,6 @@ int32_t DAudioSourceDev::TaskOpenDMic(const std::string &args) NotifyHDF(NOTIFY_OPEN_MIC_RESULT, HDF_EVENT_TRANS_SETUP_FAILED, dhId); return ret; } - cJSON *jAudioParam = cJSON_CreateObject(); CHECK_NULL_RETURN(jAudioParam, ERR_DH_AUDIO_NULLPTR); to_json(jAudioParam, mic->GetAudioParam()); @@ -904,7 +915,6 @@ int32_t DAudioSourceDev::TaskOpenDMic(const std::string &args) cJSON_Delete(jAudioParam); return ret; } - ret = mic->Start(); if (ret != DH_SUCCESS) { DHLOGE("Mic start failed, error code %{public}d.", ret); @@ -915,6 +925,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))); cJSON_Delete(jAudioParam); return DH_SUCCESS; } @@ -961,6 +972,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))); return DH_SUCCESS; } -- Gitee