From 35055e51911f70718f529c6ce6c83768ff97dabe Mon Sep 17 00:00:00 2001 From: seveno0 Date: Mon, 21 Jul 2025 22:44:18 +0800 Subject: [PATCH] hiplay: bugfix of volume, idl, concurrency, speed Signed-off-by: seveno0 --- .../include/audio_policy_ipc_interface_code.h | 2 + .../domain/pipe/src/audio_pipe_selector.cpp | 39 ++++++++++++++++++- .../volume/include/audio_adapter_manager.h | 3 +- .../volume/src/audio_adapter_manager.cpp | 10 +++-- .../client/src/renderer_in_client_public.cpp | 3 +- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/services/audio_policy/common/include/audio_policy_ipc_interface_code.h b/services/audio_policy/common/include/audio_policy_ipc_interface_code.h index 0306707535..59b5ca1442 100644 --- a/services/audio_policy/common/include/audio_policy_ipc_interface_code.h +++ b/services/audio_policy/common/include/audio_policy_ipc_interface_code.h @@ -63,6 +63,8 @@ enum class AudioPolicyInterfaceCode { DEACTIVATE_INTERRUPT, SET_INTERRUPT_CALLBACK, UNSET_INTERRUPT_CALLBACK, + SET_AUDIO_ROUTE_CALLBACK, + UNSET_AUDIO_ROUTE_CALLBACK, REQUEST_AUDIO_FOCUS, ABANDON_AUDIO_FOCUS, GET_STREAM_IN_FOCUS, diff --git a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp index 300a70e5fc..43e82d5032 100644 --- a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp +++ b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp @@ -47,6 +47,43 @@ static bool IsRemoteOffloadNeedRecreate(std::shared_ptr newPipe, (newPipe->moduleInfo_.bufferSize != oldPipe->moduleInfo_.bufferSize); } +static bool IsSameAdapter(std::shared_ptr streamDescA, + std::shared_ptr streamDescB) +{ + CHECK_AND_RETURN_RET(streamDescA != nullptr && streamDescB != nullptr, true); + + auto findFunc = [](const std::shared_ptr &info, std::shared_ptr streamDesc, + std::string &adapterName) -> bool { + CHECK_AND_RETURN_RET(info != nullptr && streamDesc != nullptr, false); + for (auto item : info->streamDescriptors_) { + CHECK_AND_CONTINUE(item && item->sessionId_ == streamDesc->sessionId_); + adapterName = info->adapterName_; + return true; + } + return false; + }; + + std::string adapterNameA = ""; + std::string adapterNameB = ""; + auto pipeManager = AudioPipeManager::GetPipeManager(); + CHECK_AND_RETURN_RET_LOG(pipeManager != nullptr, true, "pipeManager is nullptr"); + std::vector> pipeInfoList = pipeManager->GetPipeList(); + auto item = std::find_if(pipeInfoList.begin(), pipeInfoList.end(), [findFunc, streamDescA, &adapterNameA] + (const auto &info) { + return findFunc(info, streamDescA, adapterNameA); + }); + CHECK_AND_RETURN_RET(item != pipeInfoList.end(), true); + item = std::find_if(pipeInfoList.begin(), pipeInfoList.end(), [findFunc, streamDescB, &adapterNameB] + (const auto &info) { + return findFunc(info, streamDescB, adapterNameB); + }); + CHECK_AND_RETURN_RET(item != pipeInfoList.end(), true); + // just check remote + CHECK_AND_RETURN_RET(adapterNameA == "remote" || adapterNameB == "remote", true); + AUDIO_INFO_LOG("adapterNameA: %{public}s, adapterNameB: %{public}s", adapterNameA.c_str(), adapterNameB.c_str()); + return adapterNameA == adapterNameB; +} + AudioPipeSelector::AudioPipeSelector() : configManager_(AudioPolicyConfigManager::GetInstance()) { } @@ -311,7 +348,7 @@ bool AudioPipeSelector::ProcessConcurrency(std::shared_ptrrouteFlag_, stream->audioMode_), GetPipeType(cmpStream->routeFlag_, cmpStream->audioMode_))]; - + action = IsSameAdapter(stream, cmpStream) ? action : PLAY_BOTH; AUDIO_INFO_LOG("Action: %{public}u %{public}u -- %{public}u", action, stream->sessionId_, cmpStream->sessionId_); uint32_t newFlag; switch (action) { diff --git a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h index bd8433db56..2ebc58a01e 100644 --- a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h +++ b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h @@ -358,7 +358,8 @@ private: void SetAudioVolume(std::shared_ptr &device, AudioStreamType streamType, float volumeDb); void SetAppAudioVolume(int32_t appUid, float volumeDb); void SetAppAudioVolume(std::shared_ptr &device, int32_t appUid, float volumeDb); - void SetOffloadVolume(AudioStreamType streamType, float volumeDb, const std::string &deviceClass); + void SetOffloadVolume(AudioStreamType streamType, float volumeDb, const std::string &deviceClass, + const std::string &networkId = LOCAL_NETWORK_ID); int32_t SetStreamMute(std::shared_ptr &device, AudioStreamType streamType, bool mute, StreamUsage streamUsage = STREAM_USAGE_UNKNOWN, const DeviceType &deviceType = DEVICE_TYPE_NONE); diff --git a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp index f695c783fd..5672495486 100644 --- a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp +++ b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp @@ -696,7 +696,7 @@ void AudioAdapterManager::SetAudioVolume(AudioStreamType streamType, float volum if (currentActiveDevice_.IsDistributedSpeaker()) { SystemVolume systemVolume(volumeType, REMOTE_CLASS, volumeDb, volumeLevel, isMuted); audioVolume->SetSystemVolume(systemVolume); - SetOffloadVolume(volumeType, volumeDb, REMOTE_CLASS); + SetOffloadVolume(volumeType, volumeDb, REMOTE_CLASS, currentActiveDevice_.networkId_); return; } if (GetActiveDevice() == DEVICE_TYPE_NEARLINK) { @@ -736,6 +736,7 @@ void AudioAdapterManager::SetAudioVolume(std::shared_ptr if (device->IsDistributedSpeaker()) { SystemVolume systemVolume(volumeType, REMOTE_CLASS, volumeDb, volumeLevel, isMuted); audioVolume->SetSystemVolume(systemVolume); + SetOffloadVolume(volumeType, volumeDb, REMOTE_CLASS, device->networkId_); return; } auto it = DEVICE_CLASS_MAP.find(device->deviceType_); @@ -751,7 +752,8 @@ void AudioAdapterManager::SetAudioVolume(std::shared_ptr } } -void AudioAdapterManager::SetOffloadVolume(AudioStreamType streamType, float volumeDb, const std::string &deviceClass) +void AudioAdapterManager::SetOffloadVolume(AudioStreamType streamType, float volumeDb, const std::string &deviceClass, + const std::string &networkId) { float volume = volumeDb; // maybe only system volume if (!(streamType == STREAM_MUSIC || streamType == STREAM_SPEECH)) { @@ -763,7 +765,9 @@ void AudioAdapterManager::SetOffloadVolume(AudioStreamType streamType, float vol struct VolumeValues volumes = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; volume = AudioVolume::GetInstance()->GetVolume(offloadSessionID_.value(), streamType, deviceClass, &volumes); std::string routeDeviceClass = deviceClass == REMOTE_CLASS ? "remote_offload" : "offload"; - audioServerProxy_->OffloadSetVolume(volume, routeDeviceClass, currentActiveDevice_.networkId_); + AUDIO_INFO_LOG("routeDeviceClass:%{public}s, networkId:%{public}s, volume:%{public}f", routeDeviceClass.c_str(), + networkId.c_str(), volume); + audioServerProxy_->OffloadSetVolume(volume, routeDeviceClass, networkId); } IPCSkeleton::SetCallingIdentity(identity); } diff --git a/services/audio_service/client/src/renderer_in_client_public.cpp b/services/audio_service/client/src/renderer_in_client_public.cpp index df4cad5f64..734934b701 100644 --- a/services/audio_service/client/src/renderer_in_client_public.cpp +++ b/services/audio_service/client/src/renderer_in_client_public.cpp @@ -615,6 +615,7 @@ bool RendererInClientInner::DoHdiSetSpeed(float speed) CHECK_AND_RETURN_RET(isHdiSpeed_.load(), false); AUDIO_INFO_LOG("set speed to hdi, sessionId: %{public}d, speed: %{public}f", sessionId_, speed); CHECK_AND_RETURN_RET_LOG(ipcStream_ != nullptr, true, "ipcStream is not inited!"); + CHECK_AND_RETURN_RET(!isEqual(speed, speed_), true); ipcStream_->SetSpeed(speed); speed_ = speed; return true; @@ -633,12 +634,12 @@ void RendererInClientInner::NotifyRouteUpdate(uint32_t routeFlag, const std::str int32_t RendererInClientInner::SetSpeed(float speed) { std::lock_guard lock(speedMutex_); + CHECK_AND_RETURN_RET(!DoHdiSetSpeed(speed), SUCCESS); // set the speed to 1.0 and the speed has never been turned on, no actual sonic stream is created. if (isEqual(speed, SPEED_NORMAL) && !speedEnable_) { speed_ = speed; return SUCCESS; } - CHECK_AND_RETURN_RET(!DoHdiSetSpeed(speed), SUCCESS); if (audioSpeed_ == nullptr) { audioSpeed_ = std::make_unique(curStreamParams_.samplingRate, curStreamParams_.format, -- Gitee