From 59be2c27e2a89d5b03862f899c303e54faa83254 Mon Sep 17 00:00:00 2001 From: darkshadow Date: Sat, 30 Aug 2025 18:04:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=95=9C=E5=83=8F=E6=8A=95?= =?UTF-8?q?=E5=B1=8F=E5=92=8C=E5=BA=94=E7=94=A8=E6=8A=95=E5=B1=8F=E9=9F=B3?= =?UTF-8?q?=E9=87=8F=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: darkshadow --- .../volume/include/volume_data_maintainer.h | 2 ++ .../volume/src/audio_adapter_manager.cpp | 24 +++++++++++++++---- .../volume/src/volume_data_maintainer.cpp | 13 ++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h b/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h index ba8364bc85..717a3439fd 100644 --- a/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h +++ b/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h @@ -100,6 +100,8 @@ public: int32_t GetDeviceVolume(DeviceType deviceType, AudioStreamType streamType); int32_t GetAppVolume(int32_t appUid); bool IsSetAppVolume(int32_t appUid); + void CopyVolumeLevelAndMuteStatusMap; + void CopyVolumeLevelAndMuteStatusMap other>; std::unordered_map GetVolumeMap(); bool GetMuteStatusWithDatabaseVolumeName(const std::string &databaseVolumeName, AudioStreamType streamType); 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 a2fc2581c7..9a5220db19 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 @@ -484,7 +484,10 @@ int32_t AudioAdapterManager::SetAdjustVolumeForZone(int32_t zoneId) "zone device error"); if (volumeDataExtMaintainer_.find(devices[0]->GetKey()) == volumeDataExtMaintainer_.end()) { volumeDataExtMaintainer_[devices[0]->GetKey()] = std::make_shared(); - if (devices[0]->IsDistributedSpeaker()) { + if (devices[0]->deviceType_ == currentActiveDevice_.deviceType_ && + devices[0]->networkId_ == currentActiveDevice_.networkId_) { + volumeDataExtMaintainer_[devices[0]->GetKey()]->CopyVolumeLevelAndMuteStatusMap(volumeDataMaintainer_); + } else if (devices[0]->IsDistributedSpeaker()) { for (auto streamType : DISTRIBUTED_VOLUME_TYPE_LIST) { int32_t maxVolumeLevel = GetMaxVolumeLevel(streamType); volumeDataExtMaintainer_[devices[0]->GetKey()]->SetStreamVolume(streamType, maxVolumeLevel); @@ -494,12 +497,17 @@ int32_t AudioAdapterManager::SetAdjustVolumeForZone(int32_t zoneId) LoadMuteStatusMap(devices[0]); LoadVolumeMap(devices[0]); } - auto iter = defaultVolumeTypeList_.begin(); - while (iter != defaultVolumeTypeList_.end()) { - SetVolumeDb(devices[0], *iter); - iter++; + } else { + if (devices[0]->deviceType_ == currentActiveDevice_.deviceType_ && + devices[0]->networkId_ == currentActiveDevice_.networkId_) { + volumeDataExtMaintainer_[devices[0]->GetKey()]->CopyVolumeLevelAndMuteStatusMap(volumeDataMaintainer_); } } + auto iter = defaultVolumeTypeList_.begin(); + while (iter != defaultVolumeTypeList_.end()) { + SetVolumeDb(devices[0], *iter); + iter++; + } return SUCCESS; } @@ -611,6 +619,9 @@ int32_t AudioAdapterManager::SetSystemVolumeLevel(AudioStreamType streamType, in // Save the volume to volumeLevelMap_. volumeDataMaintainer_.SetStreamVolume(streamType, volumeLevel); + if (volumeDataExtMaintainer_.find(currentActiveDevice_.GetKey()) != volumeDataExtMaintainer.end()) { + volumeDataExtMaintainer_[currentActiveDevice_.GetKey()]->SetStreamVolume(streamType, volumeLevel); + } // Save the volume to settingsdata. if (currentActiveDevice_.volumeBehavior_.databaseVolumeName != "" && IsDistributedVolumeType(streamType)) { volumeDataMaintainer_.SaveVolumeWithDatabaseVolumeName( @@ -1312,6 +1323,9 @@ void AudioAdapterManager::SetVolumeForSwitchDevice(AudioDeviceDescriptor deviceD return; } } + if (volumeDataExtMaintainer_.find(currentActiveDevice_.GetKey()) != volumeDataExtMaintainer.end()) { + volumeDataMaintainer_.CopyVolumeLevelAndMuteStatusMap(volumeDataExtMaintainer_[currentActiveDevice_.GetKey()]); + } // The same device does not set the volume bool isSameVolumeGroup = ((GetVolumeGroupForDevice(currentActiveDevice_.deviceType_) == GetVolumeGroupForDevice(deviceDescriptor.deviceType_)) && diff --git a/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp b/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp index 5fdfb68aa6..5c52996604 100644 --- a/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp +++ b/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp @@ -468,6 +468,19 @@ int32_t VolumeDataMaintainer::GetAppVolume(int32_t appUid) return appVolumeLevelMap_[appUid]; } +void VolumeDataMaintainer::CopyVolumeLevelAndMuteStatusMap +{ + std::lock_guard lock(volumeMutex_); + volumeLevelMap_ = other.volumeLevelMap_; + muteStatusMap_ = other.muteStatusMap_; +} + +void VolumeDataMaintainer::CopyVolumeLevelAndMuteStatusMap other> +{ + std::lock_guard lock(volumeMutex_); + volumeLevelMap_ = other->volumeLevelMap_; + muteStatusMap_ = other->muteStatusMap_; +} int32_t VolumeDataMaintainer::GetStreamVolumeInternal(AudioStreamType streamType) { -- Gitee