From c25326dd3d27ee6cc37470691ae38902aaad5259 Mon Sep 17 00:00:00 2001 From: ruiyangsun Date: Thu, 11 Sep 2025 16:35:18 +0800 Subject: [PATCH] fix a2dp offload format bug Signed-off-by: ruiyangsun --- .../native/audiocommon/include/audio_device_descriptor.h | 2 ++ .../server/domain/device/include/audio_active_device.h | 1 + .../server/domain/device/src/audio_active_device.cpp | 5 +++++ .../server/domain/device/src/audio_device_descriptor.cpp | 5 +++++ .../server/service/service_main/src/audio_policy_service.cpp | 3 ++- 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/interfaces/inner_api/native/audiocommon/include/audio_device_descriptor.h b/interfaces/inner_api/native/audiocommon/include/audio_device_descriptor.h index ea9856ebd1..724834d68e 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_device_descriptor.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_device_descriptor.h @@ -110,6 +110,8 @@ public: bool IsRemote() const; + bool IsA2dpOffload() const; + DeviceType MapInternalToExternalDeviceType(int32_t apiVersion, bool isSupportedNearlink = true) const; DeviceStreamInfo GetDeviceStreamInfo(void) const; diff --git a/services/audio_policy/server/domain/device/include/audio_active_device.h b/services/audio_policy/server/domain/device/include/audio_active_device.h index 39e190580f..e3a2cc115c 100644 --- a/services/audio_policy/server/domain/device/include/audio_active_device.h +++ b/services/audio_policy/server/domain/device/include/audio_active_device.h @@ -56,6 +56,7 @@ public: bool UpdateDevice(std::shared_ptr &desc, const AudioStreamDeviceChangeReasonExt reason, const std::shared_ptr &rendererChangeInfo); bool IsDeviceActive(DeviceType deviceType); + bool IsA2dpOffload() const; float GetMaxAmplitude(const int32_t deviceId, const AudioInterrupt audioInterrupt); std::string GetActiveBtDeviceMac(); void SetActiveBtDeviceMac(const std::string macAddress); diff --git a/services/audio_policy/server/domain/device/src/audio_active_device.cpp b/services/audio_policy/server/domain/device/src/audio_active_device.cpp index fb3641033e..1ff409081d 100644 --- a/services/audio_policy/server/domain/device/src/audio_active_device.cpp +++ b/services/audio_policy/server/domain/device/src/audio_active_device.cpp @@ -315,6 +315,11 @@ bool AudioActiveDevice::IsDeviceActive(DeviceType deviceType) return GetCurrentOutputDeviceType() == deviceType; } +bool AudioActiveDevice::IsA2dpOffload() +{ + return currentActiveDevice_.IsA2dpOffload(); +} + int32_t AudioActiveDevice::SetDeviceActive(DeviceType deviceType, bool active, const int32_t uid) { CHECK_AND_RETURN_RET_LOG(deviceType != DEVICE_TYPE_NONE, ERR_DEVICE_NOT_SUPPORTED, "Invalid device"); diff --git a/services/audio_policy/server/domain/device/src/audio_device_descriptor.cpp b/services/audio_policy/server/domain/device/src/audio_device_descriptor.cpp index eb70f338c0..a9666e3356 100644 --- a/services/audio_policy/server/domain/device/src/audio_device_descriptor.cpp +++ b/services/audio_policy/server/domain/device/src/audio_device_descriptor.cpp @@ -530,6 +530,11 @@ bool AudioDeviceDescriptor::IsRemote() const return networkId_ != "LocalDevice"; } +bool AudioDeviceDescriptor::IsA2dpOffload() const +{ + return a2dpOffloadFlag_ == A2DP_OFFLOAD; +} + void AudioDeviceDescriptor::Dump(std::string &dumpString) { AppendFormat(dumpString, " - device %d: role %s type %d (%s) name: %s\n", diff --git a/services/audio_policy/server/service/service_main/src/audio_policy_service.cpp b/services/audio_policy/server/service/service_main/src/audio_policy_service.cpp index 881a1aa0b2..afceac580b 100644 --- a/services/audio_policy/server/service/service_main/src/audio_policy_service.cpp +++ b/services/audio_policy/server/service/service_main/src/audio_policy_service.cpp @@ -278,7 +278,8 @@ AudioStreamInfo AudioPolicyService::GetFastStreamInfo() // change to SAMPLE_S16LE for bluetooth if (streamInfo.format == SAMPLE_S32LE) { DeviceType deviceType = audioActiveDevice_.GetCurrentOutputDeviceType(); - streamInfo.format = deviceType == DEVICE_TYPE_BLUETOOTH_A2DP ? SAMPLE_S16LE : SAMPLE_S32LE; + bool flag = audioActiveDevice_.IsA2dpOffload(); + streamInfo.format = (deviceType == DEVICE_TYPE_BLUETOOTH_A2DP && !flag) ? SAMPLE_S16LE : SAMPLE_S32LE; } AUDIO_INFO_LOG("Fast format is %{public}d", streamInfo.format); return streamInfo; -- Gitee