diff --git a/distributedaudio.gni b/distributedaudio.gni index 6320eeb7e6dc302d573582abb45a32e7d3adaaaa..d2f03bdb22d2b12ecaa9848e94a77837b406d87c 100644 --- a/distributedaudio.gni +++ b/distributedaudio.gni @@ -48,6 +48,7 @@ build_flags = [ "-Werror" ] declare_args() { distributed_audio_extension_sa = false device_security_level_control = true + distributed_audio_shared_buffer = false if (defined(global_parts_info) && !defined(global_parts_info.security_device_security_level)) { diff --git a/services/audiomanager/managersource/include/daudio_source_dev.h b/services/audiomanager/managersource/include/daudio_source_dev.h index df281ad3da65ce3863af3452860c8c69daab8c9c..22c8ebb0cdeb41b6cf295c3e22d29d91e5c80997 100644 --- a/services/audiomanager/managersource/include/daudio_source_dev.h +++ b/services/audiomanager/managersource/include/daudio_source_dev.h @@ -108,6 +108,11 @@ private: int32_t HandleSpkMmapStop(const AudioEvent &event); int32_t HandleMicMmapStart(const AudioEvent &event); int32_t HandleMicMmapStop(const AudioEvent &event); +#ifdef AUDIO_SUPPORT_SHARED_BUFFER + void HandleAudioStatus(const AudioEvent &event); + int32_t HandleAudioStart(const AudioEvent &event); + int32_t HandleAudioStop(const AudioEvent &event); +#endif int32_t NotifySinkDev(const AudioEventType type, const cJSON *Param, const std::string dhId); int32_t NotifyHDF(const AudioEventType type, const std::string result, const int32_t dhId); diff --git a/services/audiomanager/managersource/src/daudio_source_dev.cpp b/services/audiomanager/managersource/src/daudio_source_dev.cpp index 2bb79ba0677ae69e19d3d13b29ab75d5b3c0140f..ad9b04e6a9a824ec8d3d34a5994cb5eb9dacfa36 100644 --- a/services/audiomanager/managersource/src/daudio_source_dev.cpp +++ b/services/audiomanager/managersource/src/daudio_source_dev.cpp @@ -291,7 +291,6 @@ void DAudioSourceDev::NotifyEventInner(const AudioEvent &event) void DAudioSourceDev::NotifyEvent(const AudioEvent &event) { - DHLOGD("Notify event, eventType: %{public}d.", event.type); switch (event.type) { case OPEN_SPEAKER: HandleOpenDSpeaker(event); @@ -313,6 +312,12 @@ void DAudioSourceDev::NotifyEvent(const AudioEvent &event) case NOTIFY_CLOSE_CTRL_RESULT: HandleNotifyRPC(event); break; +#ifdef AUDIO_SUPPORT_SHARED_BUFFER + case AUDIO_START: + case AUDIO_STOP: + HandleAudioStatus(event); + break; +#endif case OPEN_MIC: case CLOSE_MIC: case MIC_OPENED: @@ -336,6 +341,68 @@ void DAudioSourceDev::NotifyEvent(const AudioEvent &event) } } +#ifdef AUDIO_SUPPORT_SHARED_BUFFER +void DAudioSourceDev::HandleAudioStatus(const AudioEvent &event) +{ + switch (event.type) { + case AUDIO_START: + HandleAudioStart(event); + break; + case AUDIO_STOP: + HandleAudioStop(event); + break; + default: + break; + } +} + +int32_t DAudioSourceDev::HandleAudioStart(const AudioEvent &event) +{ + DHLOGI("Audio start, content: %{public}s.", event.content.c_str()); + int32_t dhId = ParseDhidFromEvent(event.content); + if (dhId < 0) { + DHLOGE("Failed to parse dhardware id."); + return ERR_DH_AUDIO_SA_PARAM_INVALID; + } + if (dhId == PIN_IN_MIC) { + DHLOGI("MIC start"); + return DH_SUCCESS; + } + CHECK_NULL_RETURN(handler_, ERR_DH_AUDIO_NULLPTR); + auto eventParam = std::make_shared(event); + auto msgEvent = AppExecFwk::InnerEvent::Get(EVENT_MMAP_SPK_START, eventParam, 0); + if (!handler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { + DHLOGE("Send event failed."); + return ERR_DH_AUDIO_FAILED; + } + DHLOGD("Mmap Start event is sent successfully."); + return DH_SUCCESS; +} + +int32_t DAudioSourceDev::HandleAudioStop(const AudioEvent &event) +{ + DHLOGI("Audio mmap stop, content: %{public}s.", event.content.c_str()); + int32_t dhId = ParseDhidFromEvent(event.content); + if (dhId < 0) { + DHLOGE("Failed to parse dhardware id."); + return ERR_DH_AUDIO_SA_PARAM_INVALID; + } + if (dhId == PIN_IN_MIC) { + DHLOGI("MIC stop"); + return DH_SUCCESS; + } + CHECK_NULL_RETURN(handler_, ERR_DH_AUDIO_NULLPTR); + auto eventParam = std::make_shared(event); + auto msgEvent = AppExecFwk::InnerEvent::Get(EVENT_MMAP_SPK_STOP, eventParam, 0); + if (!handler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { + DHLOGE("Send event failed."); + return ERR_DH_AUDIO_FAILED; + } + DHLOGD("Speaker Mmap Stop event is sent successfully."); + return DH_SUCCESS; +} +#endif + int32_t DAudioSourceDev::HandleOpenDSpeaker(const AudioEvent &event) { DHLOGI("Open speaker device."); diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index 5fd26612452c12dbb7ded4f379cd905c28c13311..0c760deee2758e8faa6edf5315d0b1072eddc055 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -124,6 +124,9 @@ ohos_shared_library("distributed_audio_source") { if (distributed_audio_extension_sa) { cflags += [ "-DECHO_CANNEL_ENABLE" ] } + if (distributed_audio_shared_buffer) { + cflags += [ "-DAUDIO_SUPPORT_SHARED_BUFFER" ] + } cflags_cc = cflags