diff --git a/frameworks/native/audioadapter/include/audio_service_adapter.h b/frameworks/native/audioadapter/include/audio_service_adapter.h index dadcb97660686b46e916ba46c6fb24b1ce6a390d..ee5c1a7ef0b4a9ce73ee381debf496c4c6390933 100644 --- a/frameworks/native/audioadapter/include/audio_service_adapter.h +++ b/frameworks/native/audioadapter/include/audio_service_adapter.h @@ -159,6 +159,14 @@ public: */ virtual int32_t SuspendAudioDevice(std::string &audioPortName, bool isSuspend) = 0; + /** + * @brief mute the device or unmute + * + * @param sinkName Name of the audio sink + * @return Returns {@link true} if mute is success; returns false otherwise. + */ + virtual bool SetSinkMute(const std::string &sinkName, bool isMute) = 0; + /** * @brief returns if given streamType is set to mute * diff --git a/frameworks/native/audioadapter/include/pulse_audio_service_adapter_impl.h b/frameworks/native/audioadapter/include/pulse_audio_service_adapter_impl.h index 458cc3401f4d2ec7ed4d7ca469ffb8073b0f1bff..3295b601e92899ce6dc7b2b9e22c4559c11fe8c2 100644 --- a/frameworks/native/audioadapter/include/pulse_audio_service_adapter_impl.h +++ b/frameworks/native/audioadapter/include/pulse_audio_service_adapter_impl.h @@ -39,6 +39,7 @@ public: int32_t SetMute(AudioStreamType streamType, bool mute) override; int32_t SetSourceOutputMute(int32_t uid, bool setMute) override; int32_t SuspendAudioDevice(std::string &audioPortName, bool isSuspend) override; + bool SetSinkMute(const std::string &sinkName, bool isMute) override; bool IsMute(AudioStreamType streamType) override; bool IsStreamActive(AudioStreamType streamType) override; std::vector GetAllSinkInputs() override; diff --git a/frameworks/native/audioadapter/src/pulse_audio_service_adapter_impl.cpp b/frameworks/native/audioadapter/src/pulse_audio_service_adapter_impl.cpp index e9efbcf8aec6cc9ad85a7221b9dade1d6c7023b1..1183b242a05088056144053a249020bdc2fa0d09 100644 --- a/frameworks/native/audioadapter/src/pulse_audio_service_adapter_impl.cpp +++ b/frameworks/native/audioadapter/src/pulse_audio_service_adapter_impl.cpp @@ -215,6 +215,25 @@ int32_t PulseAudioServiceAdapterImpl::SuspendAudioDevice(string &audioPortName, return SUCCESS; } +bool PulseAudioServiceAdapterImpl::SetSinkMute(const std::string &sinkName, bool isMute) +{ + AUDIO_INFO_LOG("MuteAudioDevice: [%{public}s] : [%{public}d]", sinkName.c_str(), isMute); + pa_threaded_mainloop_lock(mMainLoop); + + int muteFlag = isMute ? 1 : 0; + pa_operation *operation = pa_context_set_sink_mute_by_name(mContext, sinkName.c_str(), muteFlag, nullptr, nullptr); + if (operation == nullptr) { + AUDIO_ERR_LOG("[PulseAudioServiceAdapterImpl] pa_context_suspend_sink_by_name failed!"); + pa_threaded_mainloop_unlock(mMainLoop); + return false; + } + + pa_operation_unref(operation); + pa_threaded_mainloop_unlock(mMainLoop); + + return true; +} + int32_t PulseAudioServiceAdapterImpl::SetDefaultSink(string name) { pa_threaded_mainloop_lock(mMainLoop); @@ -973,8 +992,8 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoVolumeCb(pa_context *c, con pa_operation_unref(pa_context_set_sink_input_mute(c, i->index, 0, nullptr, nullptr)); } } - AUDIO_INFO_LOG("[PulseAudioServiceAdapterImpl]volume : %{public}f for stream : %{public}s, volumeInt%{public}d", - vol, i->name, volume); + AUDIO_INFO_LOG("[PulseAudioServiceAdapterImpl]volume %{public}f for stream uid %{public}d, volumeFactor %{public}f" + " volumeDbCb %{public}f ", vol, uid, volumeFactor, volumeDbCb); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::AUDIO, "VOLUME_CHANGE", HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ISOUTPUT", 1, "STREAMID", sessionID, "APP_UID", uid, "APP_PID", pid, "STREAMTYPE", streamID, "VOLUME", vol, diff --git a/frameworks/native/hdiadapter/sink/primary/audio_renderer_sink.cpp b/frameworks/native/hdiadapter/sink/primary/audio_renderer_sink.cpp index 61147e319bc324cb202ec9b2a6297221233a517d..0072e86770231a9eedfa960eff29f5aea2aa4cac 100644 --- a/frameworks/native/hdiadapter/sink/primary/audio_renderer_sink.cpp +++ b/frameworks/native/hdiadapter/sink/primary/audio_renderer_sink.cpp @@ -725,7 +725,10 @@ int32_t AudioRendererSinkInner::SetOutputRoute(DeviceType outputDevice, AudioPor AUDIO_ERR_LOG("SetOutputRoute failed, audioAdapter_ is null."); return ERR_INVALID_HANDLE; } + int64_t stamp = ClockTime::GetCurNano(); ret = audioAdapter_->UpdateAudioRoute(audioAdapter_, &route, &routeHandle_); + stamp = (ClockTime::GetCurNano() - stamp) / AUDIO_US_PER_SECOND; + AUDIO_INFO_LOG("UpdateAudioRoute cost[%{public}" PRId64 "]ms", stamp); if (ret != 0) { AUDIO_ERR_LOG("UpdateAudioRoute failed"); return ERR_OPERATION_FAILED; diff --git a/services/audio_policy/server/include/service/audio_policy_service.h b/services/audio_policy/server/include/service/audio_policy_service.h index 0f560cdfc87c74df639bbe492ee9a75d2869bd46..22a461cec1e2da1237bc9f6d5ea4abc92371c11a 100644 --- a/services/audio_policy/server/include/service/audio_policy_service.h +++ b/services/audio_policy/server/include/service/audio_policy_service.h @@ -57,7 +57,7 @@ public: void InitKVStore(); bool ConnectServiceAdapter(); - const sptr GetAudioPolicyServiceProxy(); + const sptr GetAudioServerProxy(); int32_t GetMaxVolumeLevel(AudioVolumeType volumeType) const; @@ -298,10 +298,14 @@ private: int32_t SelectNewDevice(DeviceRole deviceRole, DeviceType deviceType); + int32_t HandleA2dpDevice(DeviceType deviceType); + int32_t ActivateNewDevice(DeviceType deviceType, bool isSceneActivation); DeviceRole GetDeviceRole(AudioPin pin) const; + void KeepPortMute(int32_t muteDuration, std::string portName, DeviceType deviceType); + int32_t ActivateNewDevice(std::string networkId, DeviceType deviceType, bool isRemote); DeviceType FetchHighPriorityDevice(bool isOutputDevice); @@ -364,7 +368,7 @@ private: bool hasModulesLoaded = false; const int32_t G_UNKNOWN_PID = -1; int32_t dAudioClientUid = 3055; - int32_t switchVolumeDelay_ = 500000; // us + int32_t switchVolumeDelay_ = 200000; // us int32_t maxRendererInstances_ = 16; uint64_t audioLatencyInMsec_ = 50; uint32_t sinkLatencyInMsec_ {0}; diff --git a/services/audio_policy/server/include/service/interface/iaudio_policy_interface.h b/services/audio_policy/server/include/service/interface/iaudio_policy_interface.h index 4f78637bae1c06339dee9d6cc15a76c489e71f69..3a984773d3592a8c7061274277cfdc64ff51dae9 100644 --- a/services/audio_policy/server/include/service/interface/iaudio_policy_interface.h +++ b/services/audio_policy/server/include/service/interface/iaudio_policy_interface.h @@ -81,6 +81,10 @@ public: virtual int32_t SuspendAudioDevice(std::string &name, bool isSuspend) = 0; + virtual void SetVolumeForSwitchDevice(InternalDeviceType deviceType) = 0; + + virtual bool SetSinkMute(const std::string &sinkName, bool isMute) = 0; + virtual float CalculateVolumeDb(int32_t volumeLevel) = 0; virtual int32_t SetSystemSoundUri(const std::string &key, const std::string &uri) = 0; diff --git a/services/audio_policy/server/include/service/manager/audio_adapter_manager.h b/services/audio_policy/server/include/service/manager/audio_adapter_manager.h index e024110423079da389676d53d6d8ec306131fc36..10a7d5e0143731dd35eec96a1729759a4411a930 100644 --- a/services/audio_policy/server/include/service/manager/audio_adapter_manager.h +++ b/services/audio_policy/server/include/service/manager/audio_adapter_manager.h @@ -98,6 +98,8 @@ public: int32_t SuspendAudioDevice(std::string &name, bool isSuspend); + bool SetSinkMute(const std::string &sinkName, bool isMute); + float CalculateVolumeDb(int32_t volumeLevel); int32_t SetSystemSoundUri(const std::string &key, const std::string &uri); diff --git a/services/audio_policy/server/src/audio_capturer_state_change_listener_proxy.cpp b/services/audio_policy/server/src/audio_capturer_state_change_listener_proxy.cpp index 51f704ad832f1dc0275d941792135ef6c9b5a120..e40175d767f30ac8f2cc798fe9b09ad3044526e5 100644 --- a/services/audio_policy/server/src/audio_capturer_state_change_listener_proxy.cpp +++ b/services/audio_policy/server/src/audio_capturer_state_change_listener_proxy.cpp @@ -63,7 +63,7 @@ void AudioCapturerStateChangeListenerProxy::OnCapturerStateChange( { MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_ASYNC); AUDIO_DEBUG_LOG("AudioCapturerStateChangeListenerProxy OnCapturerStateChange entered"); diff --git a/services/audio_policy/server/src/audio_policy_manager_listener_proxy.cpp b/services/audio_policy/server/src/audio_policy_manager_listener_proxy.cpp index 5d0d3cf0e5cdc71ba605c13e42ae3f45fa844b6c..bd0568c11f070f5702f5a7a04cc7a581d6f1c125 100644 --- a/services/audio_policy/server/src/audio_policy_manager_listener_proxy.cpp +++ b/services/audio_policy/server/src/audio_policy_manager_listener_proxy.cpp @@ -62,7 +62,7 @@ void AudioPolicyManagerListenerProxy::OnDeviceChange(const DeviceChangeAction &d MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_ASYNC); if (!data.WriteInterfaceToken(GetDescriptor())) { AUDIO_ERR_LOG("AudioPolicyManagerListenerProxy: WriteInterfaceToken failed"); return; diff --git a/services/audio_policy/server/src/audio_renderer_state_change_listener_proxy.cpp b/services/audio_policy/server/src/audio_renderer_state_change_listener_proxy.cpp index 53d5d9b881e24f17caa2c7aa0a84d20d41b13324..378671f209e89ce90d3e5103e9992493ea8fbf0f 100644 --- a/services/audio_policy/server/src/audio_renderer_state_change_listener_proxy.cpp +++ b/services/audio_policy/server/src/audio_renderer_state_change_listener_proxy.cpp @@ -66,7 +66,7 @@ void AudioRendererStateChangeListenerProxy::OnRendererStateChange( { MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_ASYNC); AUDIO_DEBUG_LOG("AudioRendererStateChangeListenerProxy OnRendererStateChange entered"); diff --git a/services/audio_policy/server/src/audio_routing_manager_listener_proxy.cpp b/services/audio_policy/server/src/audio_routing_manager_listener_proxy.cpp index 40fc1373e0c360836966311f32bce60de4988cbf..60be9064017f909ac48408a3c48384514d1e1373 100644 --- a/services/audio_policy/server/src/audio_routing_manager_listener_proxy.cpp +++ b/services/audio_policy/server/src/audio_routing_manager_listener_proxy.cpp @@ -53,7 +53,7 @@ void AudioRoutingManagerListenerProxy::OnPreferOutputDeviceUpdated(const std::ve { MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_ASYNC); if (!data.WriteInterfaceToken(GetDescriptor())) { AUDIO_ERR_LOG("AudioPolicyManagerListenerProxy: WriteInterfaceToken failed"); return; diff --git a/services/audio_policy/server/src/service/audio_policy_service.cpp b/services/audio_policy/server/src/service/audio_policy_service.cpp index 641a77f94afef9e72558ad973cd2e690f6c79fb7..77d68d4b082e23f7ae2e47178ea6068ed0f44b71 100644 --- a/services/audio_policy/server/src/service/audio_policy_service.cpp +++ b/services/audio_policy/server/src/service/audio_policy_service.cpp @@ -23,6 +23,7 @@ #include "audio_errors.h" #include "audio_log.h" +#include "audio_utils.h" #include "audio_focus_parser.h" #include "audio_manager_listener_stub.h" #include "device_manager.h" @@ -97,7 +98,7 @@ bool AudioPolicyService::Init(void) return true; } -const sptr AudioPolicyService::GetAudioPolicyServiceProxy() +const sptr AudioPolicyService::GetAudioServerProxy() { AUDIO_DEBUG_LOG("[Policy Service] Start get audio policy service proxy."); lock_guard lock(g_adProxyMutex); @@ -183,7 +184,7 @@ int32_t AudioPolicyService::SetSystemVolumeLevel(AudioStreamType streamType, int if (volumeLevel == 0) { AUDIO_ERR_LOG("SetVoiceVolume: volume of voice_call cannot be set to 0"); } else { - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); if (gsp == nullptr) { AUDIO_ERR_LOG("SetVoiceVolume: gsp null"); } else { @@ -462,7 +463,7 @@ int32_t AudioPolicyService::RememberRoutingInfo(sptr audioR AUDIO_ERR_LOG("Device error: no such device:%{public}s", networkId.c_str()); return ERR_INVALID_PARAM; } - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable"); int32_t ret = gsp->CheckRemoteDeviceState(networkId, deviceRole, true); CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERR_OPERATION_FAILED, "remote device state is invalid!"); @@ -554,7 +555,7 @@ int32_t AudioPolicyService::MoveToRemoteOutputDevice(std::vector sink } } - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable"); CHECK_AND_RETURN_RET_LOG((gsp->CheckRemoteDeviceState(networkId, deviceRole, true) == SUCCESS), ERR_OPERATION_FAILED, "remote device state is invalid!"); @@ -700,7 +701,7 @@ int32_t AudioPolicyService::MoveToRemoteInputDevice(std::vector source } } - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable"); CHECK_AND_RETURN_RET_LOG((gsp->CheckRemoteDeviceState(networkId, deviceRole, true) == SUCCESS), ERR_OPERATION_FAILED, "remote device state is invalid!"); @@ -908,7 +909,7 @@ DeviceType AudioPolicyService::FetchHighPriorityDevice(bool isOutputDevice = tru int32_t AudioPolicyService::SetMicrophoneMute(bool isMute) { AUDIO_DEBUG_LOG("SetMicrophoneMute state[%{public}d]", isMute); - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable"); return gsp->SetMicrophoneMute(isMute); } @@ -916,7 +917,7 @@ int32_t AudioPolicyService::SetMicrophoneMute(bool isMute) bool AudioPolicyService::IsMicrophoneMute() { AUDIO_DEBUG_LOG("Enter IsMicrophoneMute"); - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "Service proxy unavailable"); return gsp->IsMicrophoneMute(); } @@ -1036,18 +1037,25 @@ int32_t AudioPolicyService::SelectNewDevice(DeviceRole deviceRole, DeviceType de std::string portName = GetPortName(deviceType); CHECK_AND_RETURN_RET_LOG(portName != PORT_NONE, result, "Invalid port name %{public}s", portName.c_str()); + if (deviceRole == DeviceRole::OUTPUT_DEVICE) { + int32_t muteDuration = 500000; // us + std::thread switchThread(&AudioPolicyService::KeepPortMute, this, muteDuration, portName, deviceType); + switchThread.detach(); // add another sleep before switch local can avoid pop in some case + } + result = audioPolicyManager_.SelectDevice(deviceRole, deviceType, portName); CHECK_AND_RETURN_RET_LOG(portName != PORT_NONE, result, "SetDeviceActive failed %{public}d", result); audioPolicyManager_.SuspendAudioDevice(portName, false); if (isUpdateRouteSupported_) { DeviceFlag deviceFlag = deviceRole == DeviceRole::OUTPUT_DEVICE ? OUTPUT_DEVICES_FLAG : INPUT_DEVICES_FLAG; - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable"); gsp->UpdateActiveDeviceRoute(deviceType, deviceFlag); } if (deviceRole == DeviceRole::OUTPUT_DEVICE) { + audioPolicyManager_.SetVolumeForSwitchDevice(deviceType); currentActiveDevice_ = deviceType; OnPreferOutputDeviceUpdated(currentActiveDevice_, LOCAL_NETWORK_ID); } else { @@ -1056,14 +1064,9 @@ int32_t AudioPolicyService::SelectNewDevice(DeviceRole deviceRole, DeviceType de return SUCCESS; } -int32_t AudioPolicyService::ActivateNewDevice(DeviceType deviceType, bool isSceneActivation = false) +int32_t AudioPolicyService::HandleA2dpDevice(DeviceType deviceType) { - int32_t result = SUCCESS; - - if (currentActiveDevice_ == deviceType) { - return result; - } - + Trace trace("AudioPolicyService::HandleA2dpDevice"); if (deviceType == DEVICE_TYPE_BLUETOOTH_A2DP) { auto primaryModulesPos = deviceClassInfo_.find(ClassType::TYPE_A2DP); if (primaryModulesPos != deviceClassInfo_.end()) { @@ -1097,22 +1100,60 @@ int32_t AudioPolicyService::ActivateNewDevice(DeviceType deviceType, bool isScen } else if (currentActiveDevice_ == DEVICE_TYPE_BLUETOOTH_A2DP) { std::string activePort = GetPortName(currentActiveDevice_); audioPolicyManager_.SuspendAudioDevice(activePort, true); + int32_t muteDuration = 1000000; // us + std::thread switchThread(&AudioPolicyService::KeepPortMute, this, muteDuration, PRIMARY_SPEAKER, deviceType); + switchThread.detach(); + int32_t beforSwitchDelay = 300000; + usleep(beforSwitchDelay); } AudioIOHandle ioHandle = GetAudioIOHandle(deviceType); std::string portName = GetPortName(deviceType); - CHECK_AND_RETURN_RET_LOG(portName != PORT_NONE, result, "Invalid port name %{public}s", portName.c_str()); + CHECK_AND_RETURN_RET_LOG(portName != PORT_NONE, ERR_OPERATION_FAILED, "Invalid port %{public}s", portName.c_str()); - result = audioPolicyManager_.SetDeviceActive(ioHandle, deviceType, portName, true); + int32_t result = audioPolicyManager_.SetDeviceActive(ioHandle, deviceType, portName, true); CHECK_AND_RETURN_RET_LOG(portName != PORT_NONE, result, "SetDeviceActive failed %{public}d", result); audioPolicyManager_.SuspendAudioDevice(portName, false); + UpdateInputDeviceInfo(deviceType); + + return SUCCESS; +} + +int32_t AudioPolicyService::ActivateNewDevice(DeviceType deviceType, bool isSceneActivation = false) +{ + AUDIO_INFO_LOG("Switch device: [%{public}d]-->[%{public}d]", currentActiveDevice_, deviceType); + int32_t result = SUCCESS; + + if (currentActiveDevice_ == deviceType) { + return result; + } + + if (deviceType == DEVICE_TYPE_BLUETOOTH_A2DP || currentActiveDevice_ == DEVICE_TYPE_BLUETOOTH_A2DP) { + result = HandleA2dpDevice(deviceType); + return result; + } + + std::string portName = GetPortName(deviceType); + CHECK_AND_RETURN_RET_LOG(portName != PORT_NONE, ERR_OPERATION_FAILED, "Invalid port %{public}s", portName.c_str()); + bool isVolumeSwitched = false; if (isUpdateRouteSupported_ && !isSceneActivation) { - if (deviceType == DEVICE_TYPE_SPEAKER && currentActiveDevice_ != DEVICE_TYPE_SPEAKER) { - AUDIO_INFO_LOG("Delay for device: [%{public}d]-->[%{public}d]", currentActiveDevice_, deviceType); - usleep(switchVolumeDelay_); + if (GetDeviceRole(deviceType) == OUTPUT_DEVICE) { + int32_t muteDuration = 1200000; // us + std::thread switchThread(&AudioPolicyService::KeepPortMute, this, muteDuration, portName, deviceType); + switchThread.detach(); + int32_t beforSwitchDelay = 300000; // 300 ms + usleep(beforSwitchDelay); } UpdateActiveDeviceRoute(deviceType); + if (GetDeviceRole(deviceType) == OUTPUT_DEVICE) { + audioPolicyManager_.SetVolumeForSwitchDevice(deviceType); + isVolumeSwitched = true; + } + } + + if (GetDeviceRole(deviceType) == OUTPUT_DEVICE && !isVolumeSwitched) { + audioPolicyManager_.SetVolumeForSwitchDevice(deviceType); } UpdateInputDeviceInfo(deviceType); @@ -1120,6 +1161,15 @@ int32_t AudioPolicyService::ActivateNewDevice(DeviceType deviceType, bool isScen return SUCCESS; } +void AudioPolicyService::KeepPortMute(int32_t muteDuration, std::string portName, DeviceType deviceType) +{ + Trace trace("AudioPolicyService::KeepPortMute:" + portName); + AUDIO_INFO_LOG("KeepPortMute %{public}d us for device type[%{public}d]", muteDuration, deviceType); + audioPolicyManager_.SetSinkMute(portName, true); + usleep(muteDuration); + audioPolicyManager_.SetSinkMute(portName, false); +} + int32_t AudioPolicyService::ActivateNewDevice(std::string networkId, DeviceType deviceType, bool isRemote) { if (isRemote) { @@ -1221,7 +1271,7 @@ AudioRingerMode AudioPolicyService::GetRingerMode() const int32_t AudioPolicyService::SetAudioScene(AudioScene audioScene) { AUDIO_INFO_LOG("SetAudioScene: %{public}d", audioScene); - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable"); audioScene_ = audioScene; @@ -1448,7 +1498,7 @@ void AudioPolicyService::OnPnpDeviceStatusUpdated(DeviceType devType, bool isCon } AudioStreamInfo streamInfo = {}; if (g_adProxy == nullptr) { - GetAudioPolicyServiceProxy(); + GetAudioServerProxy(); } OnDeviceStatusUpdated(devType, isConnected, "", "", streamInfo); } @@ -1490,12 +1540,12 @@ int32_t AudioPolicyService::HandleLocalDeviceDisconnected(DeviceType devType, co AUDIO_INFO_LOG("Priority device is [%{public}d]", priorityDev); if (priorityDev == DEVICE_TYPE_SPEAKER) { - result = ActivateNewDevice(DEVICE_TYPE_SPEAKER); - CHECK_AND_RETURN_RET_LOG(result == SUCCESS, result, "Failed to activate new device [%{public}d]", - DEVICE_TYPE_SPEAKER); result = ActivateNewDevice(DEVICE_TYPE_MIC); CHECK_AND_RETURN_RET_LOG(result == SUCCESS, result, "Failed to activate new device [%{public}d]", DEVICE_TYPE_MIC); + result = ActivateNewDevice(DEVICE_TYPE_SPEAKER); + CHECK_AND_RETURN_RET_LOG(result == SUCCESS, result, "Failed to activate new device [%{public}d]", + DEVICE_TYPE_SPEAKER); } else { result = ActivateNewDevice(priorityDev); CHECK_AND_RETURN_RET_LOG(result == SUCCESS, result, "Failed to activate new device [%{public}d]", @@ -1747,7 +1797,7 @@ void AudioPolicyService::OnDeviceStatusUpdated(DStatusInfo statusInfo) CHECK_AND_RETURN_LOG(ret == SUCCESS, "DEVICE online but open audio device failed."); UpdateConnectedDevicesWhenConnecting(deviceDesc, deviceChangeDescriptor); - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); if (gsp != nullptr && statusInfo.connectType == ConnectType::CONNECT_TYPE_DISTRIBUTED) { gsp->NotifyDeviceInfo(networkId, true); } @@ -1812,6 +1862,7 @@ void AudioPolicyService::OnServiceConnected(AudioServiceIndex serviceIndex) hasModulesLoaded = true; currentActiveDevice_ = DEVICE_TYPE_SPEAKER; activeInputDevice_ = DEVICE_TYPE_MIC; + audioPolicyManager_.SetVolumeForSwitchDevice(currentActiveDevice_); OnPreferOutputDeviceUpdated(currentActiveDevice_, LOCAL_NETWORK_ID); OnPnpDeviceStatusUpdated(pnpDevice_, isPnpDeviceConnected); } @@ -1830,7 +1881,7 @@ void AudioPolicyService::OnServiceDisconnected(AudioServiceIndex serviceIndex) void AudioPolicyService::OnMonoAudioConfigChanged(bool audioMono) { AUDIO_INFO_LOG("AudioPolicyService::OnMonoAudioConfigChanged: audioMono = %{public}s", audioMono? "true": "false"); - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); if (gsp == nullptr) { AUDIO_ERR_LOG("Service proxy unavailable: g_adProxy null"); return; @@ -1841,7 +1892,7 @@ void AudioPolicyService::OnMonoAudioConfigChanged(bool audioMono) void AudioPolicyService::OnAudioBalanceChanged(float audioBalance) { AUDIO_INFO_LOG("AudioPolicyService::OnAudioBalanceChanged: audioBalance = %{public}f", audioBalance); - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); if (gsp == nullptr) { AUDIO_ERR_LOG("Service proxy unavailable: g_adProxy null"); return; @@ -1852,7 +1903,7 @@ void AudioPolicyService::OnAudioBalanceChanged(float audioBalance) void AudioPolicyService::LoadEffectLibrary() { // IPC -> audioservice load library - const sptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); if (gsp == nullptr) { AUDIO_ERR_LOG("Service proxy unavailable: g_adProxy null"); return; @@ -2420,6 +2471,7 @@ std::vector> AudioPolicyService void AudioPolicyService::TriggerDeviceChangedCallback(const vector> &desc, bool isConnected) { + Trace trace("AudioPolicyService::TriggerDeviceChangedCallback"); DeviceChangeAction deviceChangeAction; deviceChangeAction.type = isConnected ? DeviceChangeType::CONNECT : DeviceChangeType::DISCONNECT; @@ -2666,7 +2718,7 @@ void AudioPolicyService::SetParameterCallback(const std::shared_ptr gsp = GetAudioPolicyServiceProxy(); + const sptr gsp = GetAudioServerProxy(); if (gsp == nullptr) { AUDIO_ERR_LOG("SetParameterCallback g_adProxy null"); return; diff --git a/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp b/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp index f6cd97cafd856bdd6feb73f70e6b1059cff63536..0d33c1a242831c0ad6bc3e77590e3f1c1b11e7c0 100644 --- a/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp +++ b/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp @@ -265,6 +265,16 @@ int32_t AudioAdapterManager::SuspendAudioDevice(std::string &portName, bool isSu return audioServiceAdapter_->SuspendAudioDevice(portName, isSuspend); } +bool AudioAdapterManager::SetSinkMute(const std::string &sinkName, bool isMute) +{ + if (!audioServiceAdapter_) { + AUDIO_ERR_LOG("SetSinkMute audio adapter null"); + return false; + } + + return audioServiceAdapter_->SetSinkMute(sinkName, isMute); +} + int32_t AudioAdapterManager::SelectDevice(DeviceRole deviceRole, InternalDeviceType deviceType, std::string name) { if (!audioServiceAdapter_) { @@ -275,7 +285,6 @@ int32_t AudioAdapterManager::SelectDevice(DeviceRole deviceRole, InternalDeviceT case DeviceRole::INPUT_DEVICE: return audioServiceAdapter_->SetDefaultSource(name); case DeviceRole::OUTPUT_DEVICE: { - SetVolumeForSwitchDevice(deviceType); AUDIO_INFO_LOG("SetDefaultSink %{public}d", deviceType); return audioServiceAdapter_->SetDefaultSink(name); } @@ -302,7 +311,6 @@ int32_t AudioAdapterManager::SetDeviceActive(AudioIOHandle ioHandle, InternalDev case InternalDeviceType::DEVICE_TYPE_USB_HEADSET: case InternalDeviceType::DEVICE_TYPE_BLUETOOTH_A2DP: case InternalDeviceType::DEVICE_TYPE_BLUETOOTH_SCO: { - SetVolumeForSwitchDevice(deviceType); AUDIO_INFO_LOG("SetDefaultSink %{public}d", deviceType); return audioServiceAdapter_->SetDefaultSink(name); } diff --git a/services/audio_service/client/src/audio_service_client.cpp b/services/audio_service/client/src/audio_service_client.cpp index 3a5dd3cecc54fe8c98b0c3052950a49cce976212..fad8f0b17d2ae3b817d64b8cd0ca1450d63abf25 100644 --- a/services/audio_service/client/src/audio_service_client.cpp +++ b/services/audio_service/client/src/audio_service_client.cpp @@ -2175,7 +2175,8 @@ void AudioServiceClient::SetPaVolume(const AudioServiceClient &client) pa_cvolume_set(&cv, client.volumeChannels, volume); pa_operation_unref(pa_context_set_sink_input_volume(client.context, client.streamIndex, &cv, nullptr, nullptr)); - AUDIO_INFO_LOG("Applied volume : %{public}f, pa volume: %{public}d", vol, volume); + AUDIO_INFO_LOG("Applied volume %{public}f, systemVolume %{public}f, volumeFactor %{public}f", vol, systemVolumeDb, + client.mVolumeFactor); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::AUDIO, "VOLUME_CHANGE", HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "ISOUTPUT", 1,