diff --git a/services/audiomanager/managersource/include/daudio_source_dev.h b/services/audiomanager/managersource/include/daudio_source_dev.h index 87e56b742b918cf779082b54eea88eac19a11307..7e821c15165599c7661bdc525347cbd65c08203d 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 a0125af55d8f9b5fefcceba8d10efeaafefe10bc..8c0a9da350fbc91cb0f3c2993389970267603325 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; }