Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include <aidl/Gtest.h> |
| 17 | #include <aidl/Vintf.h> |
| 18 | #include <aidl/android/hardware/bluetooth/audio/BnBluetoothAudioPort.h> |
| 19 | #include <aidl/android/hardware/bluetooth/audio/IBluetoothAudioPort.h> |
| 20 | #include <aidl/android/hardware/bluetooth/audio/IBluetoothAudioProviderFactory.h> |
| 21 | #include <android/binder_auto_utils.h> |
| 22 | #include <android/binder_manager.h> |
| 23 | #include <android/binder_process.h> |
| 24 | #include <binder/IServiceManager.h> |
| 25 | #include <binder/ProcessState.h> |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 26 | #include <cutils/properties.h> |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 27 | #include <fmq/AidlMessageQueue.h> |
| 28 | |
| 29 | #include <cstdint> |
| 30 | #include <future> |
| 31 | #include <unordered_set> |
| 32 | #include <vector> |
| 33 | |
| 34 | using aidl::android::hardware::audio::common::SinkMetadata; |
| 35 | using aidl::android::hardware::audio::common::SourceMetadata; |
Antoine SOULIER | 33c4e5a | 2023-09-28 21:59:19 +0000 | [diff] [blame] | 36 | using aidl::android::hardware::bluetooth::audio::A2dpConfiguration; |
| 37 | using aidl::android::hardware::bluetooth::audio::A2dpConfigurationHint; |
| 38 | using aidl::android::hardware::bluetooth::audio::A2dpRemoteCapabilities; |
| 39 | using aidl::android::hardware::bluetooth::audio::A2dpStatus; |
| 40 | using aidl::android::hardware::bluetooth::audio::A2dpStreamConfiguration; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 41 | using aidl::android::hardware::bluetooth::audio::AacCapabilities; |
| 42 | using aidl::android::hardware::bluetooth::audio::AacConfiguration; |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 43 | using aidl::android::hardware::bluetooth::audio::AptxAdaptiveLeCapabilities; |
| 44 | using aidl::android::hardware::bluetooth::audio::AptxAdaptiveLeConfiguration; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 45 | using aidl::android::hardware::bluetooth::audio::AptxCapabilities; |
| 46 | using aidl::android::hardware::bluetooth::audio::AptxConfiguration; |
| 47 | using aidl::android::hardware::bluetooth::audio::AudioCapabilities; |
| 48 | using aidl::android::hardware::bluetooth::audio::AudioConfiguration; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 49 | using aidl::android::hardware::bluetooth::audio::AudioContext; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 50 | using aidl::android::hardware::bluetooth::audio::BnBluetoothAudioPort; |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 51 | using aidl::android::hardware::bluetooth::audio::BroadcastCapability; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 52 | using aidl::android::hardware::bluetooth::audio::ChannelMode; |
| 53 | using aidl::android::hardware::bluetooth::audio::CodecCapabilities; |
| 54 | using aidl::android::hardware::bluetooth::audio::CodecConfiguration; |
Antoine SOULIER | 8c90f1f | 2023-09-26 18:55:17 +0000 | [diff] [blame] | 55 | using aidl::android::hardware::bluetooth::audio::CodecId; |
| 56 | using aidl::android::hardware::bluetooth::audio::CodecInfo; |
Antoine SOULIER | 33c4e5a | 2023-09-28 21:59:19 +0000 | [diff] [blame] | 57 | using aidl::android::hardware::bluetooth::audio::CodecParameters; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 58 | using aidl::android::hardware::bluetooth::audio::CodecSpecificCapabilitiesLtv; |
| 59 | using aidl::android::hardware::bluetooth::audio::CodecSpecificConfigurationLtv; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 60 | using aidl::android::hardware::bluetooth::audio::CodecType; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 61 | using aidl::android::hardware::bluetooth::audio::ConfigurationFlags; |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 62 | using aidl::android::hardware::bluetooth::audio::HfpConfiguration; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 63 | using aidl::android::hardware::bluetooth::audio::IBluetoothAudioPort; |
| 64 | using aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider; |
| 65 | using aidl::android::hardware::bluetooth::audio::IBluetoothAudioProviderFactory; |
| 66 | using aidl::android::hardware::bluetooth::audio::LatencyMode; |
| 67 | using aidl::android::hardware::bluetooth::audio::Lc3Capabilities; |
| 68 | using aidl::android::hardware::bluetooth::audio::Lc3Configuration; |
| 69 | using aidl::android::hardware::bluetooth::audio::LdacCapabilities; |
| 70 | using aidl::android::hardware::bluetooth::audio::LdacConfiguration; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 71 | using aidl::android::hardware::bluetooth::audio::LeAudioAseConfiguration; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 72 | using aidl::android::hardware::bluetooth::audio::LeAudioBisConfiguration; |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 73 | using aidl::android::hardware::bluetooth::audio::LeAudioBroadcastConfiguration; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 74 | using aidl::android::hardware::bluetooth::audio:: |
| 75 | LeAudioCodecCapabilitiesSetting; |
| 76 | using aidl::android::hardware::bluetooth::audio::LeAudioCodecConfiguration; |
| 77 | using aidl::android::hardware::bluetooth::audio::LeAudioConfiguration; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 78 | using aidl::android::hardware::bluetooth::audio::MetadataLtv; |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 79 | using aidl::android::hardware::bluetooth::audio::OpusCapabilities; |
| 80 | using aidl::android::hardware::bluetooth::audio::OpusConfiguration; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 81 | using aidl::android::hardware::bluetooth::audio::PcmConfiguration; |
| 82 | using aidl::android::hardware::bluetooth::audio::PresentationPosition; |
| 83 | using aidl::android::hardware::bluetooth::audio::SbcAllocMethod; |
| 84 | using aidl::android::hardware::bluetooth::audio::SbcCapabilities; |
| 85 | using aidl::android::hardware::bluetooth::audio::SbcChannelMode; |
| 86 | using aidl::android::hardware::bluetooth::audio::SbcConfiguration; |
| 87 | using aidl::android::hardware::bluetooth::audio::SessionType; |
| 88 | using aidl::android::hardware::bluetooth::audio::UnicastCapability; |
| 89 | using aidl::android::hardware::common::fmq::MQDescriptor; |
| 90 | using aidl::android::hardware::common::fmq::SynchronizedReadWrite; |
| 91 | using android::AidlMessageQueue; |
| 92 | using android::ProcessState; |
| 93 | using android::String16; |
| 94 | using ndk::ScopedAStatus; |
| 95 | using ndk::SpAIBinder; |
| 96 | |
| 97 | using MqDataType = int8_t; |
| 98 | using MqDataMode = SynchronizedReadWrite; |
| 99 | using DataMQ = AidlMessageQueue<MqDataType, MqDataMode>; |
| 100 | using DataMQDesc = MQDescriptor<MqDataType, MqDataMode>; |
| 101 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 102 | using LeAudioAseConfigurationSetting = |
| 103 | IBluetoothAudioProvider::LeAudioAseConfigurationSetting; |
| 104 | using AseDirectionRequirement = IBluetoothAudioProvider:: |
| 105 | LeAudioConfigurationRequirement::AseDirectionRequirement; |
| 106 | using AseDirectionConfiguration = IBluetoothAudioProvider:: |
| 107 | LeAudioAseConfigurationSetting::AseDirectionConfiguration; |
| 108 | using AseQosDirectionRequirement = IBluetoothAudioProvider:: |
| 109 | LeAudioAseQosConfigurationRequirement::AseQosDirectionRequirement; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 110 | using LeAudioAseQosConfigurationRequirement = |
| 111 | IBluetoothAudioProvider::LeAudioAseQosConfigurationRequirement; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 112 | using LeAudioAseQosConfiguration = |
| 113 | IBluetoothAudioProvider::LeAudioAseQosConfiguration; |
| 114 | using LeAudioDeviceCapabilities = |
| 115 | IBluetoothAudioProvider::LeAudioDeviceCapabilities; |
| 116 | using LeAudioConfigurationRequirement = |
| 117 | IBluetoothAudioProvider::LeAudioConfigurationRequirement; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 118 | using LeAudioBroadcastConfigurationRequirement = |
| 119 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement; |
| 120 | using LeAudioBroadcastSubgroupConfiguration = |
| 121 | IBluetoothAudioProvider::LeAudioBroadcastSubgroupConfiguration; |
| 122 | using LeAudioBroadcastSubgroupConfigurationRequirement = |
| 123 | IBluetoothAudioProvider::LeAudioBroadcastSubgroupConfigurationRequirement; |
| 124 | using LeAudioBroadcastConfigurationSetting = |
| 125 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationSetting; |
| 126 | using LeAudioSubgroupBisConfiguration = |
| 127 | IBluetoothAudioProvider::LeAudioSubgroupBisConfiguration; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 128 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 129 | // Constants |
| 130 | |
| 131 | static constexpr int32_t a2dp_sample_rates[] = {0, 44100, 48000, 88200, 96000}; |
| 132 | static constexpr int8_t a2dp_bits_per_samples[] = {0, 16, 24, 32}; |
| 133 | static constexpr ChannelMode a2dp_channel_modes[] = { |
| 134 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 135 | static std::vector<LatencyMode> latency_modes = {LatencyMode::FREE}; |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 136 | |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 137 | enum class BluetoothAudioHalVersion : int32_t { |
| 138 | VERSION_UNAVAILABLE = 0, |
| 139 | VERSION_2_0, |
| 140 | VERSION_2_1, |
| 141 | VERSION_AIDL_V1, |
| 142 | VERSION_AIDL_V2, |
| 143 | VERSION_AIDL_V3, |
| 144 | VERSION_AIDL_V4, |
| 145 | }; |
| 146 | |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 147 | // Some valid configs for HFP PCM configuration (software sessions) |
| 148 | static constexpr int32_t hfp_sample_rates_[] = {8000, 16000, 32000}; |
| 149 | static constexpr int8_t hfp_bits_per_samples_[] = {16}; |
| 150 | static constexpr ChannelMode hfp_channel_modes_[] = {ChannelMode::MONO}; |
| 151 | static constexpr int32_t hfp_data_interval_us_[] = {7500}; |
| 152 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 153 | // Helpers |
| 154 | |
| 155 | template <typename T> |
| 156 | struct identity { |
| 157 | typedef T type; |
| 158 | }; |
| 159 | |
| 160 | template <class T> |
| 161 | bool contained_in_vector(const std::vector<T>& vector, |
| 162 | const typename identity<T>::type& target) { |
| 163 | return std::find(vector.begin(), vector.end(), target) != vector.end(); |
| 164 | } |
| 165 | |
| 166 | void copy_codec_specific(CodecConfiguration::CodecSpecific& dst, |
| 167 | const CodecConfiguration::CodecSpecific& src) { |
| 168 | switch (src.getTag()) { |
| 169 | case CodecConfiguration::CodecSpecific::sbcConfig: |
| 170 | dst.set<CodecConfiguration::CodecSpecific::sbcConfig>( |
| 171 | src.get<CodecConfiguration::CodecSpecific::sbcConfig>()); |
| 172 | break; |
| 173 | case CodecConfiguration::CodecSpecific::aacConfig: |
| 174 | dst.set<CodecConfiguration::CodecSpecific::aacConfig>( |
| 175 | src.get<CodecConfiguration::CodecSpecific::aacConfig>()); |
| 176 | break; |
| 177 | case CodecConfiguration::CodecSpecific::ldacConfig: |
| 178 | dst.set<CodecConfiguration::CodecSpecific::ldacConfig>( |
| 179 | src.get<CodecConfiguration::CodecSpecific::ldacConfig>()); |
| 180 | break; |
| 181 | case CodecConfiguration::CodecSpecific::aptxConfig: |
| 182 | dst.set<CodecConfiguration::CodecSpecific::aptxConfig>( |
| 183 | src.get<CodecConfiguration::CodecSpecific::aptxConfig>()); |
| 184 | break; |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 185 | case CodecConfiguration::CodecSpecific::opusConfig: |
| 186 | dst.set<CodecConfiguration::CodecSpecific::opusConfig>( |
| 187 | src.get<CodecConfiguration::CodecSpecific::opusConfig>()); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 188 | break; |
| 189 | case CodecConfiguration::CodecSpecific::aptxAdaptiveConfig: |
| 190 | dst.set<CodecConfiguration::CodecSpecific::aptxAdaptiveConfig>( |
| 191 | src.get<CodecConfiguration::CodecSpecific::aptxAdaptiveConfig>()); |
| 192 | break; |
| 193 | default: |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | class BluetoothAudioPort : public BnBluetoothAudioPort { |
| 199 | public: |
| 200 | BluetoothAudioPort() {} |
| 201 | |
Chen Chen | 0a68a92 | 2022-02-15 18:43:26 -0800 | [diff] [blame] | 202 | ndk::ScopedAStatus startStream(bool) { return ScopedAStatus::ok(); } |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 203 | |
| 204 | ndk::ScopedAStatus suspendStream() { return ScopedAStatus::ok(); } |
| 205 | |
| 206 | ndk::ScopedAStatus stopStream() { return ScopedAStatus::ok(); } |
| 207 | |
| 208 | ndk::ScopedAStatus getPresentationPosition(PresentationPosition*) { |
| 209 | return ScopedAStatus::ok(); |
| 210 | } |
| 211 | |
| 212 | ndk::ScopedAStatus updateSourceMetadata(const SourceMetadata&) { |
| 213 | return ScopedAStatus::ok(); |
| 214 | } |
| 215 | |
| 216 | ndk::ScopedAStatus updateSinkMetadata(const SinkMetadata&) { |
| 217 | return ScopedAStatus::ok(); |
| 218 | } |
| 219 | |
| 220 | ndk::ScopedAStatus setLatencyMode(const LatencyMode) { |
| 221 | return ScopedAStatus::ok(); |
| 222 | } |
| 223 | |
| 224 | ndk::ScopedAStatus setCodecType(const CodecType) { |
| 225 | return ScopedAStatus::ok(); |
| 226 | } |
| 227 | |
| 228 | protected: |
| 229 | virtual ~BluetoothAudioPort() = default; |
| 230 | }; |
| 231 | |
| 232 | class BluetoothAudioProviderFactoryAidl |
| 233 | : public testing::TestWithParam<std::string> { |
| 234 | public: |
| 235 | virtual void SetUp() override { |
| 236 | provider_factory_ = IBluetoothAudioProviderFactory::fromBinder( |
| 237 | SpAIBinder(AServiceManager_getService(GetParam().c_str()))); |
| 238 | audio_provider_ = nullptr; |
| 239 | ASSERT_NE(provider_factory_, nullptr); |
| 240 | } |
| 241 | |
| 242 | virtual void TearDown() override { provider_factory_ = nullptr; } |
| 243 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 244 | void GetProviderInfoHelper(const SessionType& session_type) { |
| 245 | temp_provider_info_ = std::nullopt; |
| 246 | auto aidl_reval = |
| 247 | provider_factory_->getProviderInfo(session_type, &temp_provider_info_); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 250 | void GetProviderCapabilitiesHelper(const SessionType& session_type) { |
| 251 | temp_provider_capabilities_.clear(); |
| 252 | auto aidl_retval = provider_factory_->getProviderCapabilities( |
| 253 | session_type, &temp_provider_capabilities_); |
| 254 | // AIDL calls should not be failed and callback has to be executed |
| 255 | ASSERT_TRUE(aidl_retval.isOk()); |
| 256 | switch (session_type) { |
| 257 | case SessionType::UNKNOWN: { |
| 258 | ASSERT_TRUE(temp_provider_capabilities_.empty()); |
| 259 | } break; |
| 260 | case SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH: |
| 261 | case SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH: |
| 262 | case SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH: |
| 263 | case SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH: |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 264 | case SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH: |
| 265 | case SessionType::HFP_SOFTWARE_ENCODING_DATAPATH: { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 266 | // All software paths are mandatory and must have exact 1 |
| 267 | // "PcmParameters" |
| 268 | ASSERT_EQ(temp_provider_capabilities_.size(), 1); |
| 269 | ASSERT_EQ(temp_provider_capabilities_[0].getTag(), |
| 270 | AudioCapabilities::pcmCapabilities); |
| 271 | } break; |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 272 | case SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH: |
| 273 | case SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH: { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 274 | std::unordered_set<CodecType> codec_types; |
| 275 | // empty capability means offload is unsupported |
| 276 | for (auto& audio_capability : temp_provider_capabilities_) { |
| 277 | ASSERT_EQ(audio_capability.getTag(), |
| 278 | AudioCapabilities::a2dpCapabilities); |
| 279 | const auto& codec_capabilities = |
| 280 | audio_capability.get<AudioCapabilities::a2dpCapabilities>(); |
| 281 | // Every codec can present once at most |
| 282 | ASSERT_EQ(codec_types.count(codec_capabilities.codecType), 0); |
| 283 | switch (codec_capabilities.codecType) { |
| 284 | case CodecType::SBC: |
| 285 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 286 | CodecCapabilities::Capabilities::sbcCapabilities); |
| 287 | break; |
| 288 | case CodecType::AAC: |
| 289 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 290 | CodecCapabilities::Capabilities::aacCapabilities); |
| 291 | break; |
| 292 | case CodecType::APTX: |
| 293 | case CodecType::APTX_HD: |
| 294 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 295 | CodecCapabilities::Capabilities::aptxCapabilities); |
| 296 | break; |
| 297 | case CodecType::LDAC: |
| 298 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 299 | CodecCapabilities::Capabilities::ldacCapabilities); |
| 300 | break; |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 301 | case CodecType::OPUS: |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 302 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 303 | CodecCapabilities::Capabilities::opusCapabilities); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 304 | break; |
| 305 | case CodecType::APTX_ADAPTIVE: |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 306 | case CodecType::APTX_ADAPTIVE_LE: |
| 307 | case CodecType::APTX_ADAPTIVE_LEX: |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 308 | case CodecType::LC3: |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 309 | case CodecType::VENDOR: |
| 310 | case CodecType::UNKNOWN: |
| 311 | break; |
| 312 | } |
| 313 | codec_types.insert(codec_capabilities.codecType); |
| 314 | } |
| 315 | } break; |
| 316 | case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH: |
| 317 | case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH: |
| 318 | case SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH: { |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 319 | // empty capability means offload is unsupported since capabilities are |
| 320 | // not hardcoded |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 321 | for (auto audio_capability : temp_provider_capabilities_) { |
| 322 | ASSERT_EQ(audio_capability.getTag(), |
| 323 | AudioCapabilities::leAudioCapabilities); |
| 324 | } |
| 325 | } break; |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 326 | case SessionType::A2DP_SOFTWARE_DECODING_DATAPATH: |
| 327 | case SessionType::HFP_SOFTWARE_DECODING_DATAPATH: { |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 328 | if (!temp_provider_capabilities_.empty()) { |
| 329 | ASSERT_EQ(temp_provider_capabilities_.size(), 1); |
| 330 | ASSERT_EQ(temp_provider_capabilities_[0].getTag(), |
| 331 | AudioCapabilities::pcmCapabilities); |
| 332 | } |
| 333 | } break; |
| 334 | default: { |
| 335 | ASSERT_TRUE(temp_provider_capabilities_.empty()); |
| 336 | } |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
| 340 | /*** |
| 341 | * This helps to open the specified provider and check the openProvider() |
| 342 | * has corruct return values. BUT, to keep it simple, it does not consider |
| 343 | * the capability, and please do so at the SetUp of each session's test. |
| 344 | ***/ |
| 345 | void OpenProviderHelper(const SessionType& session_type) { |
| 346 | auto aidl_retval = |
| 347 | provider_factory_->openProvider(session_type, &audio_provider_); |
| 348 | if (aidl_retval.isOk()) { |
| 349 | ASSERT_NE(session_type, SessionType::UNKNOWN); |
| 350 | ASSERT_NE(audio_provider_, nullptr); |
| 351 | audio_port_ = ndk::SharedRefBase::make<BluetoothAudioPort>(); |
| 352 | } else { |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 353 | // optional session type |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 354 | ASSERT_TRUE( |
| 355 | session_type == SessionType::UNKNOWN || |
| 356 | session_type == |
| 357 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH || |
| 358 | session_type == |
| 359 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH || |
| 360 | session_type == |
| 361 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH || |
| 362 | session_type == |
| 363 | SessionType:: |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 364 | LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH || |
| 365 | session_type == |
| 366 | SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH || |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 367 | session_type == SessionType::A2DP_SOFTWARE_DECODING_DATAPATH || |
| 368 | session_type == SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH || |
| 369 | session_type == SessionType::HFP_SOFTWARE_DECODING_DATAPATH || |
| 370 | session_type == SessionType::HFP_SOFTWARE_ENCODING_DATAPATH); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 371 | ASSERT_EQ(audio_provider_, nullptr); |
| 372 | } |
| 373 | } |
| 374 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 375 | void GetA2dpOffloadCapabilityHelper(const CodecType& codec_type) { |
| 376 | temp_codec_capabilities_ = nullptr; |
Josh Wu | 4d2938f | 2022-02-15 09:21:10 -0800 | [diff] [blame] | 377 | for (auto& codec_capability : temp_provider_capabilities_) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 378 | auto& a2dp_capabilities = |
| 379 | codec_capability.get<AudioCapabilities::a2dpCapabilities>(); |
| 380 | if (a2dp_capabilities.codecType != codec_type) { |
| 381 | continue; |
| 382 | } |
| 383 | temp_codec_capabilities_ = &a2dp_capabilities; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | std::vector<CodecConfiguration::CodecSpecific> |
| 388 | GetSbcCodecSpecificSupportedList(bool supported) { |
| 389 | std::vector<CodecConfiguration::CodecSpecific> sbc_codec_specifics; |
| 390 | if (!supported) { |
| 391 | SbcConfiguration sbc_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 392 | sbc_codec_specifics.push_back( |
| 393 | CodecConfiguration::CodecSpecific(sbc_config)); |
| 394 | return sbc_codec_specifics; |
| 395 | } |
| 396 | GetA2dpOffloadCapabilityHelper(CodecType::SBC); |
| 397 | if (temp_codec_capabilities_ == nullptr || |
| 398 | temp_codec_capabilities_->codecType != CodecType::SBC) { |
| 399 | return sbc_codec_specifics; |
| 400 | } |
| 401 | // parse the capability |
| 402 | auto& sbc_capability = |
| 403 | temp_codec_capabilities_->capabilities |
| 404 | .get<CodecCapabilities::Capabilities::sbcCapabilities>(); |
| 405 | if (sbc_capability.minBitpool > sbc_capability.maxBitpool) { |
| 406 | return sbc_codec_specifics; |
| 407 | } |
| 408 | |
| 409 | // combine those parameters into one list of |
| 410 | // CodecConfiguration::CodecSpecific |
| 411 | for (int32_t sample_rate : sbc_capability.sampleRateHz) { |
| 412 | for (int8_t block_length : sbc_capability.blockLength) { |
| 413 | for (int8_t num_subbands : sbc_capability.numSubbands) { |
| 414 | for (int8_t bits_per_sample : sbc_capability.bitsPerSample) { |
| 415 | for (auto channel_mode : sbc_capability.channelMode) { |
| 416 | for (auto alloc_method : sbc_capability.allocMethod) { |
| 417 | SbcConfiguration sbc_data = { |
| 418 | .sampleRateHz = sample_rate, |
| 419 | .channelMode = channel_mode, |
| 420 | .blockLength = block_length, |
| 421 | .numSubbands = num_subbands, |
| 422 | .allocMethod = alloc_method, |
| 423 | .bitsPerSample = bits_per_sample, |
| 424 | .minBitpool = sbc_capability.minBitpool, |
| 425 | .maxBitpool = sbc_capability.maxBitpool}; |
| 426 | sbc_codec_specifics.push_back( |
| 427 | CodecConfiguration::CodecSpecific(sbc_data)); |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | return sbc_codec_specifics; |
| 435 | } |
| 436 | |
| 437 | std::vector<CodecConfiguration::CodecSpecific> |
| 438 | GetAacCodecSpecificSupportedList(bool supported) { |
| 439 | std::vector<CodecConfiguration::CodecSpecific> aac_codec_specifics; |
| 440 | if (!supported) { |
| 441 | AacConfiguration aac_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 442 | aac_codec_specifics.push_back( |
| 443 | CodecConfiguration::CodecSpecific(aac_config)); |
| 444 | return aac_codec_specifics; |
| 445 | } |
| 446 | GetA2dpOffloadCapabilityHelper(CodecType::AAC); |
| 447 | if (temp_codec_capabilities_ == nullptr || |
| 448 | temp_codec_capabilities_->codecType != CodecType::AAC) { |
| 449 | return aac_codec_specifics; |
| 450 | } |
| 451 | // parse the capability |
| 452 | auto& aac_capability = |
| 453 | temp_codec_capabilities_->capabilities |
| 454 | .get<CodecCapabilities::Capabilities::aacCapabilities>(); |
| 455 | |
| 456 | std::vector<bool> variable_bit_rate_enableds = {false}; |
| 457 | if (aac_capability.variableBitRateSupported) { |
| 458 | variable_bit_rate_enableds.push_back(true); |
| 459 | } |
| 460 | |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 461 | std::vector<bool> adaptive_bit_rate_supporteds = {false}; |
| 462 | if (aac_capability.adaptiveBitRateSupported) { |
| 463 | adaptive_bit_rate_supporteds.push_back(true); |
| 464 | } |
| 465 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 466 | // combine those parameters into one list of |
| 467 | // CodecConfiguration::CodecSpecific |
| 468 | for (auto object_type : aac_capability.objectType) { |
| 469 | for (int32_t sample_rate : aac_capability.sampleRateHz) { |
| 470 | for (auto channel_mode : aac_capability.channelMode) { |
| 471 | for (int8_t bits_per_sample : aac_capability.bitsPerSample) { |
| 472 | for (auto variable_bit_rate_enabled : variable_bit_rate_enableds) { |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 473 | for (auto adaptive_bit_rate_supported : |
| 474 | adaptive_bit_rate_supporteds) { |
| 475 | AacConfiguration aac_data{ |
| 476 | .objectType = object_type, |
| 477 | .sampleRateHz = sample_rate, |
| 478 | .channelMode = channel_mode, |
| 479 | .variableBitRateEnabled = variable_bit_rate_enabled, |
| 480 | .bitsPerSample = bits_per_sample, |
| 481 | .adaptiveBitRateSupported = adaptive_bit_rate_supported}; |
| 482 | aac_codec_specifics.push_back( |
| 483 | CodecConfiguration::CodecSpecific(aac_data)); |
| 484 | } |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | return aac_codec_specifics; |
| 491 | } |
| 492 | |
| 493 | std::vector<CodecConfiguration::CodecSpecific> |
| 494 | GetLdacCodecSpecificSupportedList(bool supported) { |
| 495 | std::vector<CodecConfiguration::CodecSpecific> ldac_codec_specifics; |
| 496 | if (!supported) { |
| 497 | LdacConfiguration ldac_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 498 | ldac_codec_specifics.push_back( |
| 499 | CodecConfiguration::CodecSpecific(ldac_config)); |
| 500 | return ldac_codec_specifics; |
| 501 | } |
| 502 | GetA2dpOffloadCapabilityHelper(CodecType::LDAC); |
| 503 | if (temp_codec_capabilities_ == nullptr || |
| 504 | temp_codec_capabilities_->codecType != CodecType::LDAC) { |
| 505 | return ldac_codec_specifics; |
| 506 | } |
| 507 | // parse the capability |
| 508 | auto& ldac_capability = |
| 509 | temp_codec_capabilities_->capabilities |
| 510 | .get<CodecCapabilities::Capabilities::ldacCapabilities>(); |
| 511 | |
| 512 | // combine those parameters into one list of |
| 513 | // CodecConfiguration::CodecSpecific |
| 514 | for (int32_t sample_rate : ldac_capability.sampleRateHz) { |
| 515 | for (int8_t bits_per_sample : ldac_capability.bitsPerSample) { |
| 516 | for (auto channel_mode : ldac_capability.channelMode) { |
| 517 | for (auto quality_index : ldac_capability.qualityIndex) { |
| 518 | LdacConfiguration ldac_data{.sampleRateHz = sample_rate, |
| 519 | .channelMode = channel_mode, |
| 520 | .qualityIndex = quality_index, |
| 521 | .bitsPerSample = bits_per_sample}; |
| 522 | ldac_codec_specifics.push_back( |
| 523 | CodecConfiguration::CodecSpecific(ldac_data)); |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | return ldac_codec_specifics; |
| 529 | } |
| 530 | |
| 531 | std::vector<CodecConfiguration::CodecSpecific> |
| 532 | GetAptxCodecSpecificSupportedList(bool is_hd, bool supported) { |
| 533 | std::vector<CodecConfiguration::CodecSpecific> aptx_codec_specifics; |
| 534 | if (!supported) { |
| 535 | AptxConfiguration aptx_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 536 | aptx_codec_specifics.push_back( |
| 537 | CodecConfiguration::CodecSpecific(aptx_config)); |
| 538 | return aptx_codec_specifics; |
| 539 | } |
| 540 | GetA2dpOffloadCapabilityHelper( |
| 541 | (is_hd ? CodecType::APTX_HD : CodecType::APTX)); |
| 542 | if (temp_codec_capabilities_ == nullptr) { |
| 543 | return aptx_codec_specifics; |
| 544 | } |
| 545 | if ((is_hd && temp_codec_capabilities_->codecType != CodecType::APTX_HD) || |
| 546 | (!is_hd && temp_codec_capabilities_->codecType != CodecType::APTX)) { |
| 547 | return aptx_codec_specifics; |
| 548 | } |
| 549 | |
| 550 | // parse the capability |
| 551 | auto& aptx_capability = |
| 552 | temp_codec_capabilities_->capabilities |
| 553 | .get<CodecCapabilities::Capabilities::aptxCapabilities>(); |
| 554 | |
| 555 | // combine those parameters into one list of |
| 556 | // CodecConfiguration::CodecSpecific |
| 557 | for (int8_t bits_per_sample : aptx_capability.bitsPerSample) { |
| 558 | for (int32_t sample_rate : aptx_capability.sampleRateHz) { |
| 559 | for (auto channel_mode : aptx_capability.channelMode) { |
| 560 | AptxConfiguration aptx_data{.sampleRateHz = sample_rate, |
| 561 | .channelMode = channel_mode, |
| 562 | .bitsPerSample = bits_per_sample}; |
| 563 | aptx_codec_specifics.push_back( |
| 564 | CodecConfiguration::CodecSpecific(aptx_data)); |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | return aptx_codec_specifics; |
| 569 | } |
| 570 | |
| 571 | std::vector<CodecConfiguration::CodecSpecific> |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 572 | GetOpusCodecSpecificSupportedList(bool supported) { |
| 573 | std::vector<CodecConfiguration::CodecSpecific> opus_codec_specifics; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 574 | if (!supported) { |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 575 | OpusConfiguration opus_config{.samplingFrequencyHz = 0, |
| 576 | .frameDurationUs = 0}; |
| 577 | opus_codec_specifics.push_back( |
| 578 | CodecConfiguration::CodecSpecific(opus_config)); |
| 579 | return opus_codec_specifics; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 580 | } |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 581 | GetA2dpOffloadCapabilityHelper(CodecType::OPUS); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 582 | if (temp_codec_capabilities_ == nullptr || |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 583 | temp_codec_capabilities_->codecType != CodecType::OPUS) { |
| 584 | return opus_codec_specifics; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 585 | } |
| 586 | // parse the capability |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 587 | auto& opus_capability = |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 588 | temp_codec_capabilities_->capabilities |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 589 | .get<CodecCapabilities::Capabilities::opusCapabilities>(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 590 | |
| 591 | // combine those parameters into one list of |
| 592 | // CodecConfiguration::CodecSpecific |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 593 | for (int32_t samplingFrequencyHz : opus_capability->samplingFrequencyHz) { |
| 594 | for (int32_t frameDurationUs : opus_capability->frameDurationUs) { |
| 595 | for (auto channel_mode : opus_capability->channelMode) { |
| 596 | OpusConfiguration opus_data{ |
| 597 | .samplingFrequencyHz = samplingFrequencyHz, |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 598 | .frameDurationUs = frameDurationUs, |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 599 | .channelMode = channel_mode, |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 600 | }; |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 601 | opus_codec_specifics.push_back( |
| 602 | CodecConfiguration::CodecSpecific(opus_data)); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | } |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 606 | return opus_codec_specifics; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 607 | } |
| 608 | |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 609 | bool IsPcmConfigSupported(const PcmConfiguration& pcm_config) { |
| 610 | if (temp_provider_capabilities_.size() != 1 || |
| 611 | temp_provider_capabilities_[0].getTag() != |
| 612 | AudioCapabilities::pcmCapabilities) { |
| 613 | return false; |
| 614 | } |
| 615 | auto pcm_capability = temp_provider_capabilities_[0] |
| 616 | .get<AudioCapabilities::pcmCapabilities>(); |
| 617 | return (contained_in_vector(pcm_capability.channelMode, |
| 618 | pcm_config.channelMode) && |
| 619 | contained_in_vector(pcm_capability.sampleRateHz, |
| 620 | pcm_config.sampleRateHz) && |
| 621 | contained_in_vector(pcm_capability.bitsPerSample, |
| 622 | pcm_config.bitsPerSample)); |
| 623 | } |
| 624 | |
| 625 | std::shared_ptr<IBluetoothAudioProviderFactory> provider_factory_; |
| 626 | std::shared_ptr<IBluetoothAudioProvider> audio_provider_; |
| 627 | std::shared_ptr<IBluetoothAudioPort> audio_port_; |
| 628 | std::vector<AudioCapabilities> temp_provider_capabilities_; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 629 | std::optional<IBluetoothAudioProviderFactory::ProviderInfo> |
| 630 | temp_provider_info_; |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 631 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 632 | // temp storage saves the specified codec capability by |
| 633 | // GetOffloadCodecCapabilityHelper() |
| 634 | CodecCapabilities* temp_codec_capabilities_; |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 635 | |
| 636 | static constexpr SessionType kSessionTypes[] = { |
| 637 | SessionType::UNKNOWN, |
| 638 | SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH, |
| 639 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 640 | SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH, |
| 641 | SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH, |
| 642 | SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH, |
| 643 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 644 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 645 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH, |
| 646 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 647 | SessionType::A2DP_SOFTWARE_DECODING_DATAPATH, |
| 648 | SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 649 | }; |
| 650 | |
| 651 | static constexpr SessionType kAndroidVSessionType[] = { |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 652 | SessionType::HFP_SOFTWARE_ENCODING_DATAPATH, |
| 653 | SessionType::HFP_SOFTWARE_DECODING_DATAPATH, |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 654 | }; |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 655 | |
| 656 | BluetoothAudioHalVersion GetProviderFactoryInterfaceVersion() { |
| 657 | int32_t aidl_version = 0; |
| 658 | if (provider_factory_ == nullptr) { |
| 659 | return BluetoothAudioHalVersion::VERSION_UNAVAILABLE; |
| 660 | } |
| 661 | |
| 662 | auto aidl_retval = provider_factory_->getInterfaceVersion(&aidl_version); |
| 663 | if (!aidl_retval.isOk()) { |
| 664 | return BluetoothAudioHalVersion::VERSION_UNAVAILABLE; |
| 665 | } |
| 666 | switch (aidl_version) { |
| 667 | case 1: |
| 668 | return BluetoothAudioHalVersion::VERSION_AIDL_V1; |
| 669 | case 2: |
| 670 | return BluetoothAudioHalVersion::VERSION_AIDL_V2; |
| 671 | case 3: |
| 672 | return BluetoothAudioHalVersion::VERSION_AIDL_V3; |
| 673 | case 4: |
| 674 | return BluetoothAudioHalVersion::VERSION_AIDL_V4; |
| 675 | default: |
| 676 | return BluetoothAudioHalVersion::VERSION_UNAVAILABLE; |
| 677 | } |
| 678 | |
| 679 | return BluetoothAudioHalVersion::VERSION_UNAVAILABLE; |
| 680 | } |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 681 | }; |
| 682 | |
| 683 | /** |
| 684 | * Test whether we can get the FactoryService from HIDL |
| 685 | */ |
| 686 | TEST_P(BluetoothAudioProviderFactoryAidl, GetProviderFactoryService) {} |
| 687 | |
| 688 | /** |
| 689 | * Test whether we can open a provider for each provider returned by |
| 690 | * getProviderCapabilities() with non-empty capabalities |
| 691 | */ |
| 692 | TEST_P(BluetoothAudioProviderFactoryAidl, |
| 693 | OpenProviderAndCheckCapabilitiesBySession) { |
| 694 | for (auto session_type : kSessionTypes) { |
| 695 | GetProviderCapabilitiesHelper(session_type); |
| 696 | OpenProviderHelper(session_type); |
| 697 | // We must be able to open a provider if its getProviderCapabilities() |
| 698 | // returns non-empty list. |
| 699 | EXPECT_TRUE(temp_provider_capabilities_.empty() || |
| 700 | audio_provider_ != nullptr); |
| 701 | } |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 702 | if (GetProviderFactoryInterfaceVersion() >= |
| 703 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 704 | for (auto session_type : kAndroidVSessionType) { |
| 705 | GetProviderCapabilitiesHelper(session_type); |
| 706 | OpenProviderHelper(session_type); |
| 707 | EXPECT_TRUE(temp_provider_capabilities_.empty() || |
| 708 | audio_provider_ != nullptr); |
| 709 | } |
| 710 | } |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /** |
Antoine SOULIER | 8c90f1f | 2023-09-26 18:55:17 +0000 | [diff] [blame] | 714 | * Test that getProviderInfo, when implemented, |
| 715 | * returns empty information for session types for |
| 716 | * software data paths. |
| 717 | */ |
| 718 | TEST_P(BluetoothAudioProviderFactoryAidl, getProviderInfo_invalidSessionTypes) { |
| 719 | static constexpr SessionType kInvalidSessionTypes[]{ |
| 720 | SessionType::UNKNOWN, |
| 721 | SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH, |
| 722 | SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH, |
| 723 | SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH, |
| 724 | SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH, |
| 725 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH, |
| 726 | SessionType::A2DP_SOFTWARE_DECODING_DATAPATH, |
| 727 | }; |
| 728 | |
| 729 | for (auto session_type : kInvalidSessionTypes) { |
| 730 | std::optional<IBluetoothAudioProviderFactory::ProviderInfo> provider_info = |
| 731 | std::nullopt; |
| 732 | auto aidl_retval = |
| 733 | provider_factory_->getProviderInfo(session_type, &provider_info); |
| 734 | if (!aidl_retval.isOk()) { |
| 735 | continue; |
| 736 | } |
| 737 | |
| 738 | // If getProviderInfo is supported, the provider info |
| 739 | // must be empty for software session types. |
| 740 | ASSERT_FALSE(provider_info.has_value()); |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | /** |
| 745 | * Test that getProviderInfo, when implemented, |
| 746 | * returns valid information for session types for |
| 747 | * a2dp hardware data paths. |
| 748 | */ |
| 749 | TEST_P(BluetoothAudioProviderFactoryAidl, getProviderInfo_a2dpSessionTypes) { |
| 750 | static constexpr SessionType kA2dpSessionTypes[]{ |
| 751 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 752 | SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 753 | }; |
| 754 | |
| 755 | for (auto session_type : kA2dpSessionTypes) { |
| 756 | std::optional<IBluetoothAudioProviderFactory::ProviderInfo> provider_info = |
| 757 | std::nullopt; |
| 758 | auto aidl_retval = |
| 759 | provider_factory_->getProviderInfo(session_type, &provider_info); |
| 760 | if (!aidl_retval.isOk() || !provider_info.has_value()) { |
| 761 | continue; |
| 762 | } |
| 763 | |
| 764 | for (auto const& codec_info : provider_info->codecInfos) { |
| 765 | // The codec id must not be core. |
| 766 | ASSERT_NE(codec_info.id.getTag(), CodecId::core); |
| 767 | // The codec info must contain the information |
| 768 | // for a2dp transport. |
| 769 | ASSERT_EQ(codec_info.transport.getTag(), CodecInfo::Transport::a2dp); |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * Test that getProviderInfo, when implemented, |
| 776 | * returns valid information for session types for |
| 777 | * le audio hardware data paths. |
| 778 | */ |
| 779 | TEST_P(BluetoothAudioProviderFactoryAidl, getProviderInfo_leAudioSessionTypes) { |
| 780 | static constexpr SessionType kLeAudioSessionTypes[]{ |
| 781 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 782 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 783 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 784 | }; |
| 785 | |
| 786 | for (auto session_type : kLeAudioSessionTypes) { |
| 787 | std::optional<IBluetoothAudioProviderFactory::ProviderInfo> provider_info = |
| 788 | std::nullopt; |
| 789 | auto aidl_retval = |
| 790 | provider_factory_->getProviderInfo(session_type, &provider_info); |
| 791 | if (!aidl_retval.isOk() || !provider_info.has_value()) { |
| 792 | continue; |
| 793 | } |
| 794 | |
| 795 | for (auto const& codec_info : provider_info->codecInfos) { |
| 796 | // The codec id must not be a2dp. |
| 797 | ASSERT_NE(codec_info.id.getTag(), CodecId::a2dp); |
| 798 | // The codec info must contain the information |
| 799 | // for le audio transport. |
Jakub Tyszkowski | 06781c0 | 2024-01-08 13:16:42 +0000 | [diff] [blame] | 800 | ASSERT_EQ(codec_info.transport.getTag(), CodecInfo::Transport::leAudio); |
Antoine SOULIER | 8c90f1f | 2023-09-26 18:55:17 +0000 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
Antoine SOULIER | 33c4e5a | 2023-09-28 21:59:19 +0000 | [diff] [blame] | 805 | class BluetoothAudioProviderAidl : public BluetoothAudioProviderFactoryAidl { |
| 806 | protected: |
| 807 | std::optional<IBluetoothAudioProviderFactory::ProviderInfo> |
| 808 | a2dp_encoding_provider_info_{}; |
| 809 | std::optional<IBluetoothAudioProviderFactory::ProviderInfo> |
| 810 | a2dp_decoding_provider_info_{}; |
| 811 | std::shared_ptr<IBluetoothAudioProvider> a2dp_encoding_provider_{nullptr}; |
| 812 | std::shared_ptr<IBluetoothAudioProvider> a2dp_decoding_provider_{nullptr}; |
| 813 | |
| 814 | public: |
| 815 | void SetUp() override { |
| 816 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 817 | audio_port_ = ndk::SharedRefBase::make<BluetoothAudioPort>(); |
| 818 | |
| 819 | (void)provider_factory_->getProviderInfo( |
| 820 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 821 | &a2dp_encoding_provider_info_); |
| 822 | |
| 823 | (void)provider_factory_->getProviderInfo( |
| 824 | SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 825 | &a2dp_decoding_provider_info_); |
| 826 | |
| 827 | (void)provider_factory_->openProvider( |
| 828 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 829 | &a2dp_encoding_provider_); |
| 830 | |
| 831 | (void)provider_factory_->openProvider( |
| 832 | SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 833 | &a2dp_decoding_provider_); |
| 834 | } |
| 835 | }; |
| 836 | |
| 837 | /** |
| 838 | * Calling parseA2dpConfiguration on a session of a different type than |
| 839 | * A2DP_HARDWARE_OFFLOAD_(ENCODING|DECODING)_DATAPATH must fail. |
| 840 | */ |
| 841 | TEST_P(BluetoothAudioProviderAidl, parseA2dpConfiguration_invalidSessionType) { |
| 842 | static constexpr SessionType kInvalidSessionTypes[] = { |
| 843 | SessionType::UNKNOWN, |
| 844 | SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH, |
| 845 | SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH, |
| 846 | SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH, |
| 847 | SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH, |
| 848 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 849 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 850 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH, |
| 851 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 852 | SessionType::A2DP_SOFTWARE_DECODING_DATAPATH, |
| 853 | }; |
| 854 | |
| 855 | for (auto session_type : kInvalidSessionTypes) { |
| 856 | // Open a BluetoothAudioProvider instance of the selected session type. |
| 857 | // Skip validation if the provider cannot be opened. |
| 858 | std::shared_ptr<IBluetoothAudioProvider> provider{nullptr}; |
| 859 | (void)provider_factory_->openProvider(session_type, &provider); |
| 860 | if (provider == nullptr) { |
| 861 | continue; |
| 862 | } |
| 863 | |
| 864 | // parseA2dpConfiguration must fail without returning an A2dpStatus. |
| 865 | CodecId codec_id(CodecId::A2dp::SBC); |
| 866 | CodecParameters codec_parameters; |
| 867 | A2dpStatus a2dp_status = A2dpStatus::OK; |
| 868 | auto aidl_retval = provider->parseA2dpConfiguration( |
| 869 | codec_id, std::vector<uint8_t>{}, &codec_parameters, &a2dp_status); |
| 870 | EXPECT_FALSE(aidl_retval.isOk()); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Calling parseA2dpConfiguration with an unknown codec must fail |
| 876 | * with the A2dpStatus code INVALID_CODEC_TYPE or NOT_SUPPORTED_CODEC_TYPE. |
| 877 | */ |
| 878 | TEST_P(BluetoothAudioProviderAidl, |
| 879 | parseA2dpConfiguration_unsupportedCodecType) { |
| 880 | CodecId unsupported_core_id(CodecId::Core::CVSD); |
| 881 | CodecId unsupported_vendor_id( |
| 882 | CodecId::Vendor(0xFCB1, 0x42)); // Google Codec #42 |
| 883 | |
| 884 | for (auto& provider : {a2dp_encoding_provider_, a2dp_decoding_provider_}) { |
| 885 | if (provider == nullptr) { |
| 886 | continue; |
| 887 | } |
| 888 | |
| 889 | CodecParameters codec_parameters; |
| 890 | A2dpStatus a2dp_status = A2dpStatus::OK; |
| 891 | ::ndk::ScopedAStatus aidl_retval; |
| 892 | |
| 893 | // Test with two invalid codec identifiers: vendor or core. |
| 894 | aidl_retval = provider->parseA2dpConfiguration( |
| 895 | unsupported_core_id, std::vector<uint8_t>{}, &codec_parameters, |
| 896 | &a2dp_status); |
| 897 | EXPECT_TRUE(!aidl_retval.isOk() || |
| 898 | a2dp_status == A2dpStatus::NOT_SUPPORTED_CODEC_TYPE); |
| 899 | |
| 900 | aidl_retval = provider->parseA2dpConfiguration( |
| 901 | unsupported_vendor_id, std::vector<uint8_t>{}, &codec_parameters, |
| 902 | &a2dp_status); |
| 903 | EXPECT_TRUE(!aidl_retval.isOk() || |
| 904 | a2dp_status == A2dpStatus::NOT_SUPPORTED_CODEC_TYPE); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * Calling parseA2dpConfiguration with a known codec and invalid configuration |
| 910 | * must fail with an A2dpStatus code different from INVALID_CODEC_TYPE or |
| 911 | * NOT_SUPPORTED_CODEC_TYPE. |
| 912 | */ |
| 913 | TEST_P(BluetoothAudioProviderAidl, |
| 914 | parseA2dpConfiguration_invalidConfiguration) { |
| 915 | for (auto& [provider, provider_info] : |
| 916 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 917 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 918 | if (provider == nullptr || !provider_info.has_value() || |
| 919 | provider_info->codecInfos.empty()) { |
| 920 | continue; |
| 921 | } |
| 922 | |
| 923 | CodecParameters codec_parameters; |
| 924 | A2dpStatus a2dp_status = A2dpStatus::OK; |
| 925 | ::ndk::ScopedAStatus aidl_retval; |
| 926 | |
| 927 | // Test with the first available codec in the provider info for testing. |
| 928 | // The test runs with an empty parameters array, anything more specific |
| 929 | // would need understanding the codec. |
| 930 | aidl_retval = provider->parseA2dpConfiguration( |
| 931 | provider_info->codecInfos[0].id, std::vector<uint8_t>{}, |
| 932 | &codec_parameters, &a2dp_status); |
| 933 | ASSERT_TRUE(aidl_retval.isOk()); |
| 934 | EXPECT_TRUE(a2dp_status != A2dpStatus::OK && |
| 935 | a2dp_status != A2dpStatus::NOT_SUPPORTED_CODEC_TYPE && |
| 936 | a2dp_status != A2dpStatus::INVALID_CODEC_TYPE); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * Calling parseA2dpConfiguration with a known codec and valid parameters |
| 942 | * must return with A2dpStatus OK. |
| 943 | */ |
| 944 | TEST_P(BluetoothAudioProviderAidl, parseA2dpConfiguration_valid) { |
| 945 | for (auto& [provider, provider_info] : |
| 946 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 947 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 948 | if (provider == nullptr || !provider_info.has_value() || |
| 949 | provider_info->codecInfos.empty()) { |
| 950 | continue; |
| 951 | } |
| 952 | |
| 953 | CodecParameters codec_parameters; |
| 954 | A2dpStatus a2dp_status = A2dpStatus::OK; |
| 955 | ::ndk::ScopedAStatus aidl_retval; |
| 956 | |
| 957 | // Test with the first available codec in the provider info for testing. |
| 958 | // To get a valid configuration (the capabilities array in the provider |
| 959 | // info is not a selection), getA2dpConfiguration is used with the |
| 960 | // selected codec parameters as input. |
| 961 | auto const& codec_info = provider_info->codecInfos[0]; |
| 962 | auto transport = codec_info.transport.get<CodecInfo::Transport::a2dp>(); |
| 963 | A2dpRemoteCapabilities remote_capabilities(/*seid*/ 0, codec_info.id, |
| 964 | transport.capabilities); |
| 965 | std::optional<A2dpConfiguration> configuration; |
| 966 | aidl_retval = provider->getA2dpConfiguration( |
| 967 | std::vector<A2dpRemoteCapabilities>{remote_capabilities}, |
| 968 | A2dpConfigurationHint(), &configuration); |
| 969 | ASSERT_TRUE(aidl_retval.isOk()); |
| 970 | ASSERT_TRUE(configuration.has_value()); |
| 971 | |
| 972 | aidl_retval = provider->parseA2dpConfiguration( |
| 973 | configuration->id, configuration->configuration, &codec_parameters, |
| 974 | &a2dp_status); |
| 975 | ASSERT_TRUE(aidl_retval.isOk()); |
| 976 | EXPECT_TRUE(a2dp_status == A2dpStatus::OK); |
| 977 | EXPECT_EQ(codec_parameters, configuration->parameters); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * Calling getA2dpConfiguration on a session of a different type than |
| 983 | * A2DP_HARDWARE_OFFLOAD_(ENCODING|DECODING)_DATAPATH must fail. |
| 984 | */ |
| 985 | TEST_P(BluetoothAudioProviderAidl, getA2dpConfiguration_invalidSessionType) { |
| 986 | static constexpr SessionType kInvalidSessionTypes[] = { |
| 987 | SessionType::UNKNOWN, |
| 988 | SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH, |
| 989 | SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH, |
| 990 | SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH, |
| 991 | SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH, |
| 992 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 993 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 994 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH, |
| 995 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 996 | SessionType::A2DP_SOFTWARE_DECODING_DATAPATH, |
| 997 | }; |
| 998 | |
| 999 | for (auto session_type : kInvalidSessionTypes) { |
| 1000 | // Open a BluetoothAudioProvider instance of the selected session type. |
| 1001 | // Skip validation if the provider cannot be opened. |
| 1002 | std::shared_ptr<IBluetoothAudioProvider> provider{nullptr}; |
| 1003 | auto aidl_retval = provider_factory_->openProvider(session_type, &provider); |
| 1004 | if (provider == nullptr) { |
| 1005 | continue; |
| 1006 | } |
| 1007 | |
| 1008 | // getA2dpConfiguration must fail without returning a configuration. |
| 1009 | std::optional<A2dpConfiguration> configuration; |
| 1010 | aidl_retval = |
| 1011 | provider->getA2dpConfiguration(std::vector<A2dpRemoteCapabilities>{}, |
| 1012 | A2dpConfigurationHint(), &configuration); |
| 1013 | EXPECT_FALSE(aidl_retval.isOk()); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * Calling getA2dpConfiguration with empty or unknown remote capabilities |
| 1019 | * must return an empty configuration. |
| 1020 | */ |
| 1021 | TEST_P(BluetoothAudioProviderAidl, |
| 1022 | getA2dpConfiguration_unknownRemoteCapabilities) { |
| 1023 | for (auto& [provider, provider_info] : |
| 1024 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1025 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1026 | if (provider == nullptr || !provider_info.has_value() || |
| 1027 | provider_info->codecInfos.empty()) { |
| 1028 | continue; |
| 1029 | } |
| 1030 | |
| 1031 | std::optional<A2dpConfiguration> configuration; |
| 1032 | ::ndk::ScopedAStatus aidl_retval; |
| 1033 | |
| 1034 | // Test with empty remote capabilities. |
| 1035 | aidl_retval = |
| 1036 | provider->getA2dpConfiguration(std::vector<A2dpRemoteCapabilities>{}, |
| 1037 | A2dpConfigurationHint(), &configuration); |
| 1038 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1039 | EXPECT_FALSE(configuration.has_value()); |
| 1040 | |
| 1041 | // Test with unknown remote capabilities. |
| 1042 | A2dpRemoteCapabilities unknown_core_remote_capabilities( |
| 1043 | /*seid*/ 0, CodecId::Core::CVSD, std::vector<uint8_t>{1, 2, 3}); |
| 1044 | A2dpRemoteCapabilities unknown_vendor_remote_capabilities( |
| 1045 | /*seid*/ 1, |
| 1046 | /* Google Codec #42 */ CodecId::Vendor(0xFCB1, 0x42), |
| 1047 | std::vector<uint8_t>{1, 2, 3}); |
| 1048 | aidl_retval = provider->getA2dpConfiguration( |
| 1049 | std::vector<A2dpRemoteCapabilities>{ |
| 1050 | unknown_core_remote_capabilities, |
| 1051 | unknown_vendor_remote_capabilities, |
| 1052 | }, |
| 1053 | A2dpConfigurationHint(), &configuration); |
| 1054 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1055 | EXPECT_FALSE(configuration.has_value()); |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | /** |
| 1060 | * Calling getA2dpConfiguration with invalid remote capabilities |
| 1061 | * must return an empty configuration. |
| 1062 | */ |
| 1063 | TEST_P(BluetoothAudioProviderAidl, |
| 1064 | getA2dpConfiguration_invalidRemoteCapabilities) { |
| 1065 | for (auto& [provider, provider_info] : |
| 1066 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1067 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1068 | if (provider == nullptr || !provider_info.has_value() || |
| 1069 | provider_info->codecInfos.empty()) { |
| 1070 | continue; |
| 1071 | } |
| 1072 | |
| 1073 | std::optional<A2dpConfiguration> configuration; |
| 1074 | ::ndk::ScopedAStatus aidl_retval; |
| 1075 | |
| 1076 | // Use the first available codec in the provider info for testing. |
| 1077 | // The capabilities are modified to make them invalid. |
| 1078 | auto const& codec_info = provider_info->codecInfos[0]; |
| 1079 | auto transport = codec_info.transport.get<CodecInfo::Transport::a2dp>(); |
| 1080 | std::vector<uint8_t> invalid_capabilities = transport.capabilities; |
| 1081 | invalid_capabilities.push_back(0x42); // adding bytes should be invalid. |
| 1082 | aidl_retval = provider->getA2dpConfiguration( |
| 1083 | std::vector<A2dpRemoteCapabilities>{ |
| 1084 | A2dpRemoteCapabilities(/*seid*/ 0, codec_info.id, |
| 1085 | std::vector<uint8_t>()), |
| 1086 | A2dpRemoteCapabilities(/*seid*/ 1, codec_info.id, |
| 1087 | invalid_capabilities), |
| 1088 | }, |
| 1089 | A2dpConfigurationHint(), &configuration); |
| 1090 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1091 | EXPECT_FALSE(configuration.has_value()); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | /** |
| 1096 | * Calling getA2dpConfiguration with valid remote capabilities |
| 1097 | * must return a valid configuration. The selected parameters must |
| 1098 | * be contained in the original capabilities. The returned configuration |
| 1099 | * must match the returned parameters. The returned SEID must match the |
| 1100 | * input SEID. |
| 1101 | */ |
| 1102 | TEST_P(BluetoothAudioProviderAidl, |
| 1103 | getA2dpConfiguration_validRemoteCapabilities) { |
| 1104 | for (auto& [provider, provider_info] : |
| 1105 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1106 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1107 | if (provider == nullptr || !provider_info.has_value() || |
| 1108 | provider_info->codecInfos.empty()) { |
| 1109 | continue; |
| 1110 | } |
| 1111 | |
| 1112 | // Test with all available codecs in the provider info. |
| 1113 | for (auto const& codec_info : provider_info->codecInfos) { |
| 1114 | auto a2dp_info = codec_info.transport.get<CodecInfo::Transport::a2dp>(); |
| 1115 | std::optional<A2dpConfiguration> configuration{}; |
| 1116 | ::ndk::ScopedAStatus aidl_retval; |
| 1117 | |
| 1118 | aidl_retval = provider->getA2dpConfiguration( |
| 1119 | std::vector<A2dpRemoteCapabilities>{ |
| 1120 | A2dpRemoteCapabilities(/*seid*/ 42, codec_info.id, |
| 1121 | a2dp_info.capabilities), |
| 1122 | }, |
| 1123 | A2dpConfigurationHint(), &configuration); |
| 1124 | |
| 1125 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1126 | ASSERT_TRUE(configuration.has_value()); |
| 1127 | |
| 1128 | // Returned configuration must have the same codec id |
| 1129 | // as the remote capability. |
| 1130 | EXPECT_EQ(configuration->id, codec_info.id); |
| 1131 | |
| 1132 | // Returned configuration must have the same SEID |
| 1133 | // as the remote capability. |
| 1134 | EXPECT_EQ(configuration->remoteSeid, 42); |
| 1135 | |
| 1136 | // Returned codec parameters must be in the range of input |
| 1137 | // parameters. |
| 1138 | EXPECT_NE( |
| 1139 | std::find(a2dp_info.channelMode.begin(), a2dp_info.channelMode.end(), |
| 1140 | configuration->parameters.channelMode), |
| 1141 | a2dp_info.channelMode.end()); |
| 1142 | EXPECT_NE(std::find(a2dp_info.samplingFrequencyHz.begin(), |
| 1143 | a2dp_info.samplingFrequencyHz.end(), |
| 1144 | configuration->parameters.samplingFrequencyHz), |
| 1145 | a2dp_info.samplingFrequencyHz.end()); |
| 1146 | EXPECT_NE(std::find(a2dp_info.bitdepth.begin(), a2dp_info.bitdepth.end(), |
| 1147 | configuration->parameters.bitdepth), |
| 1148 | a2dp_info.bitdepth.end()); |
| 1149 | EXPECT_EQ(a2dp_info.lossless, configuration->parameters.lossless); |
| 1150 | EXPECT_TRUE(configuration->parameters.minBitrate <= |
| 1151 | configuration->parameters.maxBitrate); |
| 1152 | |
| 1153 | // Returned configuration must be parsable by parseA2dpParameters |
| 1154 | // and match the codec parameters. |
| 1155 | CodecParameters codec_parameters; |
| 1156 | A2dpStatus a2dp_status = A2dpStatus::OK; |
| 1157 | aidl_retval = provider->parseA2dpConfiguration( |
| 1158 | configuration->id, configuration->configuration, &codec_parameters, |
| 1159 | &a2dp_status); |
| 1160 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1161 | EXPECT_TRUE(a2dp_status == A2dpStatus::OK); |
| 1162 | EXPECT_EQ(codec_parameters, configuration->parameters); |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * Calling getA2dpConfiguration with valid remote capabilities |
| 1169 | * with various hinted codec ids. |
| 1170 | */ |
| 1171 | TEST_P(BluetoothAudioProviderAidl, getA2dpConfiguration_hintCodecId) { |
| 1172 | for (auto& [provider, provider_info] : |
| 1173 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1174 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1175 | if (provider == nullptr || !provider_info.has_value() || |
| 1176 | provider_info->codecInfos.empty()) { |
| 1177 | continue; |
| 1178 | } |
| 1179 | |
| 1180 | // Build the remote capabilities with all supported codecs. |
| 1181 | std::vector<A2dpRemoteCapabilities> remote_capabilities; |
| 1182 | for (size_t n = 0; n < provider_info->codecInfos.size(); n++) { |
| 1183 | auto const& codec_info = provider_info->codecInfos[n]; |
| 1184 | auto a2dp_info = codec_info.transport.get<CodecInfo::Transport::a2dp>(); |
| 1185 | remote_capabilities.push_back(A2dpRemoteCapabilities( |
| 1186 | /*seid*/ n, codec_info.id, a2dp_info.capabilities)); |
| 1187 | } |
| 1188 | |
| 1189 | // Test with all supported codec identifiers, |
| 1190 | for (auto const& codec_info : provider_info->codecInfos) { |
| 1191 | std::optional<A2dpConfiguration> configuration{}; |
| 1192 | ::ndk::ScopedAStatus aidl_retval; |
| 1193 | |
| 1194 | A2dpConfigurationHint hint; |
| 1195 | hint.codecId = codec_info.id; |
| 1196 | |
| 1197 | aidl_retval = provider->getA2dpConfiguration(remote_capabilities, hint, |
| 1198 | &configuration); |
| 1199 | |
| 1200 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1201 | ASSERT_TRUE(configuration.has_value()); |
| 1202 | EXPECT_EQ(configuration->id, codec_info.id); |
| 1203 | } |
| 1204 | |
| 1205 | // Test with unknown codec identifiers: either core or vendor. |
| 1206 | for (auto& codec_id : |
| 1207 | {CodecId(CodecId::Core::CVSD), |
| 1208 | CodecId(CodecId::Vendor(0xFCB1, 0x42)) /*Google Codec #42*/}) { |
| 1209 | std::optional<A2dpConfiguration> configuration{}; |
| 1210 | ::ndk::ScopedAStatus aidl_retval; |
| 1211 | |
| 1212 | A2dpConfigurationHint hint; |
| 1213 | hint.codecId = codec_id; |
| 1214 | |
| 1215 | aidl_retval = provider->getA2dpConfiguration(remote_capabilities, hint, |
| 1216 | &configuration); |
| 1217 | |
| 1218 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1219 | ASSERT_TRUE(configuration.has_value()); |
| 1220 | EXPECT_NE(configuration->id, codec_id); |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * Calling getA2dpConfiguration with valid remote capabilities |
| 1227 | * with various hinted channel modes. |
| 1228 | */ |
| 1229 | TEST_P(BluetoothAudioProviderAidl, getA2dpConfiguration_hintChannelMode) { |
| 1230 | for (auto& [provider, provider_info] : |
| 1231 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1232 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1233 | if (provider == nullptr || !provider_info.has_value() || |
| 1234 | provider_info->codecInfos.empty()) { |
| 1235 | continue; |
| 1236 | } |
| 1237 | |
| 1238 | // Test with all available codecs in the provider info. |
| 1239 | for (auto const& codec_info : provider_info->codecInfos) { |
| 1240 | auto a2dp_info = codec_info.transport.get<CodecInfo::Transport::a2dp>(); |
| 1241 | std::optional<A2dpConfiguration> configuration{}; |
| 1242 | ::ndk::ScopedAStatus aidl_retval; |
| 1243 | |
| 1244 | for (auto& channel_mode : |
| 1245 | {ChannelMode::STEREO, ChannelMode::MONO, ChannelMode::DUALMONO}) { |
| 1246 | // Add the hint for the channel mode. |
| 1247 | A2dpConfigurationHint hint; |
| 1248 | auto& codec_parameters = hint.codecParameters.emplace(); |
| 1249 | codec_parameters.channelMode = channel_mode; |
| 1250 | |
| 1251 | aidl_retval = provider->getA2dpConfiguration( |
| 1252 | std::vector<A2dpRemoteCapabilities>{ |
| 1253 | A2dpRemoteCapabilities(/*seid*/ 42, codec_info.id, |
| 1254 | a2dp_info.capabilities), |
| 1255 | }, |
| 1256 | hint, &configuration); |
| 1257 | |
| 1258 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1259 | ASSERT_TRUE(configuration.has_value()); |
| 1260 | |
| 1261 | // The hint must be ignored if the channel mode is not supported |
| 1262 | // by the codec, and applied otherwise. |
| 1263 | ASSERT_EQ(configuration->parameters.channelMode == channel_mode, |
| 1264 | std::find(a2dp_info.channelMode.begin(), |
| 1265 | a2dp_info.channelMode.end(), |
| 1266 | channel_mode) != a2dp_info.channelMode.end()); |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | /** |
| 1273 | * Calling getA2dpConfiguration with valid remote capabilities |
| 1274 | * with various hinted sampling frequencies. |
| 1275 | */ |
| 1276 | TEST_P(BluetoothAudioProviderAidl, |
| 1277 | getA2dpConfiguration_hintSamplingFrequencyHz) { |
| 1278 | for (auto& [provider, provider_info] : |
| 1279 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1280 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1281 | if (provider == nullptr || !provider_info.has_value() || |
| 1282 | provider_info->codecInfos.empty()) { |
| 1283 | continue; |
| 1284 | } |
| 1285 | |
| 1286 | // Test with all available codecs in the provider info. |
| 1287 | for (auto const& codec_info : provider_info->codecInfos) { |
| 1288 | auto a2dp_info = codec_info.transport.get<CodecInfo::Transport::a2dp>(); |
| 1289 | std::optional<A2dpConfiguration> configuration{}; |
| 1290 | ::ndk::ScopedAStatus aidl_retval; |
| 1291 | |
| 1292 | for (auto& sampling_frequency_hz : { |
| 1293 | 0, |
| 1294 | 1, |
| 1295 | 8000, |
| 1296 | 16000, |
| 1297 | 24000, |
| 1298 | 32000, |
| 1299 | 44100, |
| 1300 | 48000, |
| 1301 | 88200, |
| 1302 | 96000, |
| 1303 | 176400, |
| 1304 | 192000, |
| 1305 | }) { |
| 1306 | // Add the hint for the sampling frequency. |
| 1307 | A2dpConfigurationHint hint; |
| 1308 | auto& codec_parameters = hint.codecParameters.emplace(); |
| 1309 | codec_parameters.samplingFrequencyHz = sampling_frequency_hz; |
| 1310 | |
| 1311 | aidl_retval = provider->getA2dpConfiguration( |
| 1312 | std::vector<A2dpRemoteCapabilities>{ |
| 1313 | A2dpRemoteCapabilities(/*seid*/ 42, codec_info.id, |
| 1314 | a2dp_info.capabilities), |
| 1315 | }, |
| 1316 | hint, &configuration); |
| 1317 | |
| 1318 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1319 | ASSERT_TRUE(configuration.has_value()); |
| 1320 | |
| 1321 | // The hint must be ignored if the sampling frequency is not supported |
| 1322 | // by the codec, and applied otherwise. |
| 1323 | ASSERT_EQ(configuration->parameters.samplingFrequencyHz == |
| 1324 | sampling_frequency_hz, |
| 1325 | std::find(a2dp_info.samplingFrequencyHz.begin(), |
| 1326 | a2dp_info.samplingFrequencyHz.end(), |
| 1327 | sampling_frequency_hz) != |
| 1328 | a2dp_info.samplingFrequencyHz.end()); |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | /** |
| 1335 | * Calling getA2dpConfiguration with valid remote capabilities |
| 1336 | * with various hinted sampling bit-depths. |
| 1337 | */ |
| 1338 | TEST_P(BluetoothAudioProviderAidl, getA2dpConfiguration_hintBitdepth) { |
| 1339 | for (auto& [provider, provider_info] : |
| 1340 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1341 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1342 | if (provider == nullptr || !provider_info.has_value() || |
| 1343 | provider_info->codecInfos.empty()) { |
| 1344 | continue; |
| 1345 | } |
| 1346 | |
| 1347 | // Test with all available codecs in the provider info. |
| 1348 | for (auto const& codec_info : provider_info->codecInfos) { |
| 1349 | auto a2dp_info = codec_info.transport.get<CodecInfo::Transport::a2dp>(); |
| 1350 | std::optional<A2dpConfiguration> configuration{}; |
| 1351 | ::ndk::ScopedAStatus aidl_retval; |
| 1352 | |
| 1353 | for (auto& bitdepth : {0, 1, 16, 24, 32}) { |
| 1354 | // Add the hint for the bit depth. |
| 1355 | A2dpConfigurationHint hint; |
| 1356 | auto& codec_parameters = hint.codecParameters.emplace(); |
| 1357 | codec_parameters.bitdepth = bitdepth; |
| 1358 | |
| 1359 | aidl_retval = provider->getA2dpConfiguration( |
| 1360 | std::vector<A2dpRemoteCapabilities>{ |
| 1361 | A2dpRemoteCapabilities(/*seid*/ 42, codec_info.id, |
| 1362 | a2dp_info.capabilities), |
| 1363 | }, |
| 1364 | hint, &configuration); |
| 1365 | |
| 1366 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1367 | ASSERT_TRUE(configuration.has_value()); |
| 1368 | |
| 1369 | // The hint must be ignored if the bitdepth is not supported |
| 1370 | // by the codec, and applied otherwise. |
| 1371 | ASSERT_EQ( |
| 1372 | configuration->parameters.bitdepth == bitdepth, |
| 1373 | std::find(a2dp_info.bitdepth.begin(), a2dp_info.bitdepth.end(), |
| 1374 | bitdepth) != a2dp_info.bitdepth.end()); |
| 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | /** |
| 1381 | * Calling startSession with an unknown codec id must fail. |
| 1382 | */ |
| 1383 | TEST_P(BluetoothAudioProviderAidl, startSession_unknownCodecId) { |
| 1384 | for (auto& [provider, provider_info] : |
| 1385 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1386 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1387 | if (provider == nullptr || !provider_info.has_value() || |
| 1388 | provider_info->codecInfos.empty()) { |
| 1389 | continue; |
| 1390 | } |
| 1391 | |
| 1392 | for (auto& codec_id : |
| 1393 | {CodecId(CodecId::Core::CVSD), |
| 1394 | CodecId(CodecId::Vendor(0xFCB1, 0x42) /*Google Codec #42*/)}) { |
| 1395 | A2dpStreamConfiguration a2dp_config; |
| 1396 | DataMQDesc data_mq_desc; |
| 1397 | |
| 1398 | a2dp_config.codecId = codec_id; |
| 1399 | a2dp_config.configuration = std::vector<uint8_t>{1, 2, 3}; |
| 1400 | |
| 1401 | auto aidl_retval = |
| 1402 | provider->startSession(audio_port_, AudioConfiguration(a2dp_config), |
| 1403 | std::vector<LatencyMode>{}, &data_mq_desc); |
| 1404 | |
| 1405 | EXPECT_FALSE(aidl_retval.isOk()); |
| 1406 | } |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | /** |
| 1411 | * Calling startSession with a known codec and a valid configuration |
| 1412 | * must succeed. |
| 1413 | */ |
| 1414 | TEST_P(BluetoothAudioProviderAidl, startSession_valid) { |
| 1415 | for (auto& [provider, provider_info] : |
| 1416 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1417 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1418 | if (provider == nullptr || !provider_info.has_value() || |
| 1419 | provider_info->codecInfos.empty()) { |
| 1420 | continue; |
| 1421 | } |
| 1422 | |
| 1423 | // Use the first available codec in the provider info for testing. |
| 1424 | // To get a valid configuration (the capabilities array in the provider |
| 1425 | // info is not a selection), getA2dpConfiguration is used with the |
| 1426 | // selected codec parameters as input. |
| 1427 | auto const& codec_info = provider_info->codecInfos[0]; |
| 1428 | auto a2dp_info = codec_info.transport.get<CodecInfo::Transport::a2dp>(); |
| 1429 | ::ndk::ScopedAStatus aidl_retval; |
| 1430 | A2dpRemoteCapabilities remote_capabilities(/*seid*/ 0, codec_info.id, |
| 1431 | a2dp_info.capabilities); |
| 1432 | std::optional<A2dpConfiguration> configuration; |
| 1433 | aidl_retval = provider->getA2dpConfiguration( |
| 1434 | std::vector<A2dpRemoteCapabilities>{remote_capabilities}, |
| 1435 | A2dpConfigurationHint(), &configuration); |
| 1436 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1437 | ASSERT_TRUE(configuration.has_value()); |
| 1438 | |
| 1439 | // Build the stream configuration. |
| 1440 | A2dpStreamConfiguration a2dp_config; |
| 1441 | DataMQDesc data_mq_desc; |
| 1442 | |
| 1443 | a2dp_config.codecId = codec_info.id; |
| 1444 | a2dp_config.configuration = configuration->configuration; |
| 1445 | |
| 1446 | aidl_retval = |
| 1447 | provider->startSession(audio_port_, AudioConfiguration(a2dp_config), |
| 1448 | std::vector<LatencyMode>{}, &data_mq_desc); |
| 1449 | |
| 1450 | EXPECT_TRUE(aidl_retval.isOk()); |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | /** |
| 1455 | * Calling startSession with a known codec but an invalid configuration |
| 1456 | * must fail. |
| 1457 | */ |
| 1458 | TEST_P(BluetoothAudioProviderAidl, startSession_invalidConfiguration) { |
| 1459 | for (auto& [provider, provider_info] : |
| 1460 | {std::pair(a2dp_encoding_provider_, a2dp_encoding_provider_info_), |
| 1461 | std::pair(a2dp_decoding_provider_, a2dp_decoding_provider_info_)}) { |
| 1462 | if (provider == nullptr || !provider_info.has_value() || |
| 1463 | provider_info->codecInfos.empty()) { |
| 1464 | continue; |
| 1465 | } |
| 1466 | |
| 1467 | // Use the first available codec in the provider info for testing. |
| 1468 | // To get a valid configuration (the capabilities array in the provider |
| 1469 | // info is not a selection), getA2dpConfiguration is used with the |
| 1470 | // selected codec parameters as input. |
| 1471 | ::ndk::ScopedAStatus aidl_retval; |
| 1472 | auto const& codec_info = provider_info->codecInfos[0]; |
| 1473 | auto a2dp_info = codec_info.transport.get<CodecInfo::Transport::a2dp>(); |
| 1474 | A2dpRemoteCapabilities remote_capabilities(/*seid*/ 0, codec_info.id, |
| 1475 | a2dp_info.capabilities); |
| 1476 | std::optional<A2dpConfiguration> configuration; |
| 1477 | aidl_retval = provider->getA2dpConfiguration( |
| 1478 | std::vector<A2dpRemoteCapabilities>{remote_capabilities}, |
| 1479 | A2dpConfigurationHint(), &configuration); |
| 1480 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1481 | ASSERT_TRUE(configuration.has_value()); |
| 1482 | |
| 1483 | // Build the stream configuration but edit the configuration bytes |
| 1484 | // to make it invalid. |
| 1485 | A2dpStreamConfiguration a2dp_config; |
| 1486 | DataMQDesc data_mq_desc; |
| 1487 | |
| 1488 | a2dp_config.codecId = codec_info.id; |
| 1489 | a2dp_config.configuration = configuration->configuration; |
| 1490 | a2dp_config.configuration.push_back(42); |
| 1491 | |
| 1492 | aidl_retval = |
| 1493 | provider->startSession(audio_port_, AudioConfiguration(a2dp_config), |
| 1494 | std::vector<LatencyMode>{}, &data_mq_desc); |
| 1495 | |
| 1496 | EXPECT_FALSE(aidl_retval.isOk()); |
| 1497 | } |
| 1498 | } |
| 1499 | |
Antoine SOULIER | 8c90f1f | 2023-09-26 18:55:17 +0000 | [diff] [blame] | 1500 | /** |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1501 | * openProvider A2DP_SOFTWARE_ENCODING_DATAPATH |
| 1502 | */ |
| 1503 | class BluetoothAudioProviderA2dpEncodingSoftwareAidl |
| 1504 | : public BluetoothAudioProviderFactoryAidl { |
| 1505 | public: |
| 1506 | virtual void SetUp() override { |
| 1507 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1508 | GetProviderCapabilitiesHelper(SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH); |
| 1509 | OpenProviderHelper(SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH); |
| 1510 | ASSERT_NE(audio_provider_, nullptr); |
| 1511 | } |
| 1512 | |
| 1513 | virtual void TearDown() override { |
| 1514 | audio_port_ = nullptr; |
| 1515 | audio_provider_ = nullptr; |
| 1516 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1517 | } |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1518 | }; |
| 1519 | |
| 1520 | /** |
| 1521 | * Test whether we can open a provider of type |
| 1522 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1523 | TEST_P(BluetoothAudioProviderA2dpEncodingSoftwareAidl, |
| 1524 | OpenA2dpEncodingSoftwareProvider) {} |
| 1525 | |
| 1526 | /** |
| 1527 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1528 | * SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH can be started and stopped |
| 1529 | * with different PCM config |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1530 | */ |
| 1531 | TEST_P(BluetoothAudioProviderA2dpEncodingSoftwareAidl, |
| 1532 | StartAndEndA2dpEncodingSoftwareSessionWithPossiblePcmConfig) { |
| 1533 | for (auto sample_rate : a2dp_sample_rates) { |
| 1534 | for (auto bits_per_sample : a2dp_bits_per_samples) { |
| 1535 | for (auto channel_mode : a2dp_channel_modes) { |
| 1536 | PcmConfiguration pcm_config{ |
| 1537 | .sampleRateHz = sample_rate, |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1538 | .channelMode = channel_mode, |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 1539 | .bitsPerSample = bits_per_sample, |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1540 | }; |
| 1541 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 1542 | DataMQDesc mq_desc; |
| 1543 | auto aidl_retval = audio_provider_->startSession( |
| 1544 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 1545 | &mq_desc); |
| 1546 | DataMQ data_mq(mq_desc); |
| 1547 | |
| 1548 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 1549 | if (is_codec_config_valid) { |
| 1550 | EXPECT_TRUE(data_mq.isValid()); |
| 1551 | } |
| 1552 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1553 | } |
| 1554 | } |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | /** |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1559 | * openProvider HFP_SOFTWARE_ENCODING_DATAPATH |
| 1560 | */ |
| 1561 | class BluetoothAudioProviderHfpSoftwareEncodingAidl |
| 1562 | : public BluetoothAudioProviderFactoryAidl { |
| 1563 | public: |
| 1564 | virtual void SetUp() override { |
| 1565 | BluetoothAudioProviderFactoryAidl::SetUp(); |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1566 | if (GetProviderFactoryInterfaceVersion() < |
| 1567 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 1568 | GTEST_SKIP(); |
| 1569 | } |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1570 | GetProviderCapabilitiesHelper(SessionType::HFP_SOFTWARE_ENCODING_DATAPATH); |
| 1571 | OpenProviderHelper(SessionType::HFP_SOFTWARE_ENCODING_DATAPATH); |
| 1572 | ASSERT_NE(audio_provider_, nullptr); |
| 1573 | } |
| 1574 | |
| 1575 | virtual void TearDown() override { |
| 1576 | audio_port_ = nullptr; |
| 1577 | audio_provider_ = nullptr; |
| 1578 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1579 | } |
| 1580 | |
| 1581 | bool OpenSession(int32_t sample_rate, int8_t bits_per_sample, |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 1582 | ChannelMode channel_mode, int32_t data_interval_us) { |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1583 | PcmConfiguration pcm_config{ |
| 1584 | .sampleRateHz = sample_rate, |
| 1585 | .channelMode = channel_mode, |
| 1586 | .bitsPerSample = bits_per_sample, |
| 1587 | .dataIntervalUs = data_interval_us, |
| 1588 | }; |
| 1589 | // Checking against provider capability from getProviderCapabilities |
| 1590 | // For HFP software, it's |
| 1591 | // BluetoothAudioCodecs::GetSoftwarePcmCapabilities(); |
| 1592 | DataMQDesc mq_desc; |
| 1593 | auto aidl_retval = audio_provider_->startSession( |
| 1594 | audio_port_, AudioConfiguration(pcm_config), latency_modes, &mq_desc); |
| 1595 | DataMQ data_mq(mq_desc); |
| 1596 | |
| 1597 | if (!aidl_retval.isOk()) return false; |
| 1598 | if (!data_mq.isValid()) return false; |
| 1599 | return true; |
| 1600 | } |
| 1601 | }; |
| 1602 | |
| 1603 | /** |
| 1604 | * Test whether we can open a provider of type |
| 1605 | */ |
| 1606 | TEST_P(BluetoothAudioProviderHfpSoftwareEncodingAidl, |
| 1607 | OpenHfpSoftwareEncodingProvider) {} |
| 1608 | |
| 1609 | /** |
| 1610 | * Test whether each provider of type |
| 1611 | * SessionType::HFP_SOFTWARE_ENCODING_DATAPATH can be started and stopped with |
| 1612 | * different PCM config |
| 1613 | */ |
| 1614 | TEST_P(BluetoothAudioProviderHfpSoftwareEncodingAidl, |
| 1615 | StartAndEndHfpEncodingSoftwareSessionWithPossiblePcmConfig) { |
| 1616 | for (auto sample_rate : hfp_sample_rates_) { |
| 1617 | for (auto bits_per_sample : hfp_bits_per_samples_) { |
| 1618 | for (auto channel_mode : hfp_channel_modes_) { |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 1619 | for (auto data_interval_us : hfp_data_interval_us_) { |
| 1620 | EXPECT_TRUE(OpenSession(sample_rate, bits_per_sample, channel_mode, |
| 1621 | data_interval_us)); |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1622 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1623 | } |
| 1624 | } |
| 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | /** |
| 1630 | * openProvider HFP_SOFTWARE_DECODING_DATAPATH |
| 1631 | */ |
| 1632 | class BluetoothAudioProviderHfpSoftwareDecodingAidl |
| 1633 | : public BluetoothAudioProviderFactoryAidl { |
| 1634 | public: |
| 1635 | virtual void SetUp() override { |
| 1636 | BluetoothAudioProviderFactoryAidl::SetUp(); |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1637 | if (GetProviderFactoryInterfaceVersion() < |
| 1638 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 1639 | GTEST_SKIP(); |
| 1640 | } |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1641 | GetProviderCapabilitiesHelper(SessionType::HFP_SOFTWARE_DECODING_DATAPATH); |
| 1642 | OpenProviderHelper(SessionType::HFP_SOFTWARE_DECODING_DATAPATH); |
| 1643 | ASSERT_NE(audio_provider_, nullptr); |
| 1644 | } |
| 1645 | |
| 1646 | virtual void TearDown() override { |
| 1647 | audio_port_ = nullptr; |
| 1648 | audio_provider_ = nullptr; |
| 1649 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1650 | } |
| 1651 | |
| 1652 | bool OpenSession(int32_t sample_rate, int8_t bits_per_sample, |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 1653 | ChannelMode channel_mode, int32_t data_interval_us) { |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1654 | PcmConfiguration pcm_config{ |
| 1655 | .sampleRateHz = sample_rate, |
| 1656 | .channelMode = channel_mode, |
| 1657 | .bitsPerSample = bits_per_sample, |
| 1658 | .dataIntervalUs = data_interval_us, |
| 1659 | }; |
| 1660 | DataMQDesc mq_desc; |
| 1661 | auto aidl_retval = audio_provider_->startSession( |
| 1662 | audio_port_, AudioConfiguration(pcm_config), latency_modes, &mq_desc); |
| 1663 | DataMQ data_mq(mq_desc); |
| 1664 | |
| 1665 | if (!aidl_retval.isOk()) return false; |
| 1666 | if (!data_mq.isValid()) return false; |
| 1667 | return true; |
| 1668 | } |
| 1669 | }; |
| 1670 | |
| 1671 | /** |
| 1672 | * Test whether we can open a provider of type |
| 1673 | */ |
| 1674 | TEST_P(BluetoothAudioProviderHfpSoftwareDecodingAidl, |
| 1675 | OpenHfpSoftwareDecodingProvider) {} |
| 1676 | |
| 1677 | /** |
| 1678 | * Test whether each provider of type |
| 1679 | * SessionType::HFP_SOFTWARE_DECODING_DATAPATH can be started and stopped with |
| 1680 | * different PCM config |
| 1681 | */ |
| 1682 | TEST_P(BluetoothAudioProviderHfpSoftwareDecodingAidl, |
| 1683 | StartAndEndHfpDecodingSoftwareSessionWithPossiblePcmConfig) { |
| 1684 | for (auto sample_rate : hfp_sample_rates_) { |
| 1685 | for (auto bits_per_sample : hfp_bits_per_samples_) { |
| 1686 | for (auto channel_mode : hfp_channel_modes_) { |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 1687 | for (auto data_interval_us : hfp_data_interval_us_) { |
| 1688 | EXPECT_TRUE(OpenSession(sample_rate, bits_per_sample, channel_mode, |
| 1689 | data_interval_us)); |
| 1690 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | } |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | /** |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1698 | * openProvider A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH |
| 1699 | */ |
| 1700 | class BluetoothAudioProviderA2dpEncodingHardwareAidl |
| 1701 | : public BluetoothAudioProviderFactoryAidl { |
| 1702 | public: |
| 1703 | virtual void SetUp() override { |
| 1704 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1705 | GetProviderCapabilitiesHelper( |
| 1706 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1707 | OpenProviderHelper(SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1708 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1709 | audio_provider_ != nullptr); |
| 1710 | } |
| 1711 | |
| 1712 | virtual void TearDown() override { |
| 1713 | audio_port_ = nullptr; |
| 1714 | audio_provider_ = nullptr; |
| 1715 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1716 | } |
| 1717 | |
| 1718 | bool IsOffloadSupported() { return (temp_provider_capabilities_.size() > 0); } |
| 1719 | }; |
| 1720 | |
| 1721 | /** |
| 1722 | * Test whether we can open a provider of type |
| 1723 | */ |
| 1724 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 1725 | OpenA2dpEncodingHardwareProvider) {} |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1726 | |
| 1727 | /** |
| 1728 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1729 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped |
| 1730 | * with SBC hardware encoding config |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1731 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1732 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 1733 | StartAndEndA2dpSbcEncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1734 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 1735 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | CodecConfiguration codec_config = { |
| 1739 | .codecType = CodecType::SBC, |
| 1740 | .encodedAudioBitrate = 328000, |
| 1741 | .peerMtu = 1005, |
| 1742 | .isScmstEnabled = false, |
| 1743 | }; |
| 1744 | auto sbc_codec_specifics = GetSbcCodecSpecificSupportedList(true); |
| 1745 | |
| 1746 | for (auto& codec_specific : sbc_codec_specifics) { |
| 1747 | copy_codec_specific(codec_config.config, codec_specific); |
| 1748 | DataMQDesc mq_desc; |
| 1749 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1750 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1751 | |
| 1752 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1753 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | /** |
| 1758 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1759 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped |
| 1760 | * with AAC hardware encoding config |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1761 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1762 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 1763 | StartAndEndA2dpAacEncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1764 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 1765 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | CodecConfiguration codec_config = { |
| 1769 | .codecType = CodecType::AAC, |
| 1770 | .encodedAudioBitrate = 320000, |
| 1771 | .peerMtu = 1005, |
| 1772 | .isScmstEnabled = false, |
| 1773 | }; |
| 1774 | auto aac_codec_specifics = GetAacCodecSpecificSupportedList(true); |
| 1775 | |
| 1776 | for (auto& codec_specific : aac_codec_specifics) { |
| 1777 | copy_codec_specific(codec_config.config, codec_specific); |
| 1778 | DataMQDesc mq_desc; |
| 1779 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1780 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1781 | |
| 1782 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1783 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1789 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped |
| 1790 | * with LDAC hardware encoding config |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1791 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1792 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 1793 | StartAndEndA2dpLdacEncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1794 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 1795 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | CodecConfiguration codec_config = { |
| 1799 | .codecType = CodecType::LDAC, |
| 1800 | .encodedAudioBitrate = 990000, |
| 1801 | .peerMtu = 1005, |
| 1802 | .isScmstEnabled = false, |
| 1803 | }; |
| 1804 | auto ldac_codec_specifics = GetLdacCodecSpecificSupportedList(true); |
| 1805 | |
| 1806 | for (auto& codec_specific : ldac_codec_specifics) { |
| 1807 | copy_codec_specific(codec_config.config, codec_specific); |
| 1808 | DataMQDesc mq_desc; |
| 1809 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1810 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1811 | |
| 1812 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1813 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | /** |
| 1818 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1819 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped |
| 1820 | * with Opus hardware encoding config |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1821 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1822 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 1823 | StartAndEndA2dpOpusEncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1824 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 1825 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | CodecConfiguration codec_config = { |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 1829 | .codecType = CodecType::OPUS, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1830 | .encodedAudioBitrate = 990000, |
| 1831 | .peerMtu = 1005, |
| 1832 | .isScmstEnabled = false, |
| 1833 | }; |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 1834 | auto opus_codec_specifics = GetOpusCodecSpecificSupportedList(true); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1835 | |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 1836 | for (auto& codec_specific : opus_codec_specifics) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1837 | copy_codec_specific(codec_config.config, codec_specific); |
| 1838 | DataMQDesc mq_desc; |
| 1839 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1840 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1841 | |
| 1842 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1843 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | /** |
| 1848 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1849 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped |
| 1850 | * with AptX hardware encoding config |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1851 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1852 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 1853 | StartAndEndA2dpAptxEncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1854 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 1855 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | for (auto codec_type : {CodecType::APTX, CodecType::APTX_HD}) { |
| 1859 | CodecConfiguration codec_config = { |
| 1860 | .codecType = codec_type, |
| 1861 | .encodedAudioBitrate = |
| 1862 | (codec_type == CodecType::APTX ? 352000 : 576000), |
| 1863 | .peerMtu = 1005, |
| 1864 | .isScmstEnabled = false, |
| 1865 | }; |
| 1866 | |
| 1867 | auto aptx_codec_specifics = GetAptxCodecSpecificSupportedList( |
| 1868 | (codec_type == CodecType::APTX_HD ? true : false), true); |
| 1869 | |
| 1870 | for (auto& codec_specific : aptx_codec_specifics) { |
| 1871 | copy_codec_specific(codec_config.config, codec_specific); |
| 1872 | DataMQDesc mq_desc; |
| 1873 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1874 | audio_port_, AudioConfiguration(codec_config), latency_modes, |
| 1875 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1876 | |
| 1877 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1878 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1879 | } |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | /** |
| 1884 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1885 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped |
| 1886 | * with an invalid codec config |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1887 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 1888 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 1889 | StartAndEndA2dpEncodingHardwareSessionInvalidCodecConfig) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1890 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 1891 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1892 | } |
| 1893 | ASSERT_NE(audio_provider_, nullptr); |
| 1894 | |
| 1895 | std::vector<CodecConfiguration::CodecSpecific> codec_specifics; |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 1896 | for (auto codec_type : ndk::enum_range<CodecType>()) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1897 | switch (codec_type) { |
| 1898 | case CodecType::SBC: |
| 1899 | codec_specifics = GetSbcCodecSpecificSupportedList(false); |
| 1900 | break; |
| 1901 | case CodecType::AAC: |
| 1902 | codec_specifics = GetAacCodecSpecificSupportedList(false); |
| 1903 | break; |
| 1904 | case CodecType::LDAC: |
| 1905 | codec_specifics = GetLdacCodecSpecificSupportedList(false); |
| 1906 | break; |
| 1907 | case CodecType::APTX: |
| 1908 | codec_specifics = GetAptxCodecSpecificSupportedList(false, false); |
| 1909 | break; |
| 1910 | case CodecType::APTX_HD: |
| 1911 | codec_specifics = GetAptxCodecSpecificSupportedList(true, false); |
| 1912 | break; |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 1913 | case CodecType::OPUS: |
| 1914 | codec_specifics = GetOpusCodecSpecificSupportedList(false); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1915 | continue; |
| 1916 | case CodecType::APTX_ADAPTIVE: |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 1917 | case CodecType::APTX_ADAPTIVE_LE: |
| 1918 | case CodecType::APTX_ADAPTIVE_LEX: |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 1919 | case CodecType::LC3: |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1920 | case CodecType::VENDOR: |
| 1921 | case CodecType::UNKNOWN: |
| 1922 | codec_specifics.clear(); |
| 1923 | break; |
| 1924 | } |
| 1925 | if (codec_specifics.empty()) { |
| 1926 | continue; |
| 1927 | } |
| 1928 | |
| 1929 | CodecConfiguration codec_config = { |
| 1930 | .codecType = codec_type, |
| 1931 | .encodedAudioBitrate = 328000, |
| 1932 | .peerMtu = 1005, |
| 1933 | .isScmstEnabled = false, |
| 1934 | }; |
| 1935 | for (auto codec_specific : codec_specifics) { |
| 1936 | copy_codec_specific(codec_config.config, codec_specific); |
| 1937 | DataMQDesc mq_desc; |
| 1938 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1939 | audio_port_, AudioConfiguration(codec_config), latency_modes, |
| 1940 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1941 | |
| 1942 | // AIDL call should fail on invalid codec |
| 1943 | ASSERT_FALSE(aidl_retval.isOk()); |
| 1944 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1945 | } |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | /** |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1950 | * openProvider HFP_HARDWARE_OFFLOAD_DATAPATH |
| 1951 | */ |
| 1952 | class BluetoothAudioProviderHfpHardwareAidl |
| 1953 | : public BluetoothAudioProviderFactoryAidl { |
| 1954 | public: |
| 1955 | virtual void SetUp() override { |
| 1956 | BluetoothAudioProviderFactoryAidl::SetUp(); |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 1957 | if (GetProviderFactoryInterfaceVersion() < |
| 1958 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 1959 | GTEST_SKIP(); |
| 1960 | } |
Bao Do | 2fa1ab4 | 2024-01-29 17:50:34 +0800 | [diff] [blame] | 1961 | GetProviderInfoHelper(SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH); |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1962 | OpenProviderHelper(SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH); |
| 1963 | // Can open or empty capability |
| 1964 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1965 | audio_provider_ != nullptr); |
| 1966 | } |
| 1967 | |
| 1968 | virtual void TearDown() override { |
| 1969 | audio_port_ = nullptr; |
| 1970 | audio_provider_ = nullptr; |
| 1971 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1972 | } |
| 1973 | |
| 1974 | bool OpenSession(CodecId codec_id, int connection_handle, bool nrec, |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 1975 | bool controller_codec) { |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 1976 | // Check if can open session with a Hfp configuration |
| 1977 | HfpConfiguration hfp_configuration{ |
| 1978 | .codecId = codec_id, |
| 1979 | .connectionHandle = connection_handle, |
| 1980 | .nrec = nrec, |
| 1981 | .controllerCodec = controller_codec, |
| 1982 | }; |
| 1983 | DataMQDesc mq_desc; |
| 1984 | auto aidl_retval = audio_provider_->startSession( |
| 1985 | audio_port_, AudioConfiguration(hfp_configuration), latency_modes, |
| 1986 | &mq_desc); |
| 1987 | |
| 1988 | // Only check if aidl is ok to start session. |
| 1989 | return aidl_retval.isOk(); |
| 1990 | } |
| 1991 | }; |
| 1992 | |
| 1993 | /** |
| 1994 | * Test whether we can open a provider of type |
| 1995 | */ |
| 1996 | TEST_P(BluetoothAudioProviderHfpHardwareAidl, OpenHfpHardwareProvider) {} |
| 1997 | |
| 1998 | /** |
| 1999 | * Test whether each provider of type |
| 2000 | * SessionType::HFP_SOFTWARE_DECODING_DATAPATH can be started and stopped with |
| 2001 | * different HFP config |
| 2002 | */ |
| 2003 | TEST_P(BluetoothAudioProviderHfpHardwareAidl, |
| 2004 | StartAndEndHfpHardwareSessionWithPossiblePcmConfig) { |
| 2005 | // Try to open with a sample configuration |
| 2006 | EXPECT_TRUE(OpenSession(CodecId::Core::CVSD, 6, false, true)); |
| 2007 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 2008 | } |
| 2009 | |
| 2010 | /** |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2011 | * openProvider HEARING_AID_SOFTWARE_ENCODING_DATAPATH |
| 2012 | */ |
| 2013 | class BluetoothAudioProviderHearingAidSoftwareAidl |
| 2014 | : public BluetoothAudioProviderFactoryAidl { |
| 2015 | public: |
| 2016 | virtual void SetUp() override { |
| 2017 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 2018 | GetProviderCapabilitiesHelper( |
| 2019 | SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH); |
| 2020 | OpenProviderHelper(SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH); |
| 2021 | ASSERT_NE(audio_provider_, nullptr); |
| 2022 | } |
| 2023 | |
| 2024 | virtual void TearDown() override { |
| 2025 | audio_port_ = nullptr; |
| 2026 | audio_provider_ = nullptr; |
| 2027 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 2028 | } |
| 2029 | |
| 2030 | static constexpr int32_t hearing_aid_sample_rates_[] = {0, 16000, 24000}; |
| 2031 | static constexpr int8_t hearing_aid_bits_per_samples_[] = {0, 16, 24}; |
| 2032 | static constexpr ChannelMode hearing_aid_channel_modes_[] = { |
| 2033 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 2034 | }; |
| 2035 | |
| 2036 | /** |
| 2037 | * Test whether we can open a provider of type |
| 2038 | */ |
| 2039 | TEST_P(BluetoothAudioProviderHearingAidSoftwareAidl, |
| 2040 | OpenHearingAidSoftwareProvider) {} |
| 2041 | |
| 2042 | /** |
| 2043 | * Test whether each provider of type |
| 2044 | * SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH can be started and |
| 2045 | * stopped with different PCM config |
| 2046 | */ |
| 2047 | TEST_P(BluetoothAudioProviderHearingAidSoftwareAidl, |
| 2048 | StartAndEndHearingAidSessionWithPossiblePcmConfig) { |
| 2049 | for (int32_t sample_rate : hearing_aid_sample_rates_) { |
| 2050 | for (int8_t bits_per_sample : hearing_aid_bits_per_samples_) { |
| 2051 | for (auto channel_mode : hearing_aid_channel_modes_) { |
| 2052 | PcmConfiguration pcm_config{ |
| 2053 | .sampleRateHz = sample_rate, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2054 | .channelMode = channel_mode, |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 2055 | .bitsPerSample = bits_per_sample, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2056 | }; |
| 2057 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 2058 | DataMQDesc mq_desc; |
| 2059 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 2060 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 2061 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2062 | DataMQ data_mq(mq_desc); |
| 2063 | |
| 2064 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 2065 | if (is_codec_config_valid) { |
| 2066 | EXPECT_TRUE(data_mq.isValid()); |
| 2067 | } |
| 2068 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 2069 | } |
| 2070 | } |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | /** |
| 2075 | * openProvider LE_AUDIO_SOFTWARE_ENCODING_DATAPATH |
| 2076 | */ |
| 2077 | class BluetoothAudioProviderLeAudioOutputSoftwareAidl |
| 2078 | : public BluetoothAudioProviderFactoryAidl { |
| 2079 | public: |
| 2080 | virtual void SetUp() override { |
| 2081 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 2082 | GetProviderCapabilitiesHelper( |
| 2083 | SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH); |
| 2084 | OpenProviderHelper(SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH); |
| 2085 | ASSERT_NE(audio_provider_, nullptr); |
| 2086 | } |
| 2087 | |
| 2088 | virtual void TearDown() override { |
| 2089 | audio_port_ = nullptr; |
| 2090 | audio_provider_ = nullptr; |
| 2091 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 2092 | } |
| 2093 | |
| 2094 | static constexpr int32_t le_audio_output_sample_rates_[] = { |
| 2095 | 0, 8000, 16000, 24000, 32000, 44100, 48000, |
| 2096 | }; |
| 2097 | static constexpr int8_t le_audio_output_bits_per_samples_[] = {0, 16, 24}; |
| 2098 | static constexpr ChannelMode le_audio_output_channel_modes_[] = { |
| 2099 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 2100 | static constexpr int32_t le_audio_output_data_interval_us_[] = { |
| 2101 | 0 /* Invalid */, 10000 /* Valid 10ms */}; |
| 2102 | }; |
| 2103 | |
| 2104 | /** |
| 2105 | * Test whether each provider of type |
| 2106 | * SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH can be started and |
| 2107 | * stopped |
| 2108 | */ |
| 2109 | TEST_P(BluetoothAudioProviderLeAudioOutputSoftwareAidl, |
| 2110 | OpenLeAudioOutputSoftwareProvider) {} |
| 2111 | |
| 2112 | /** |
| 2113 | * Test whether each provider of type |
| 2114 | * SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH can be started and |
| 2115 | * stopped with different PCM config |
| 2116 | */ |
| 2117 | TEST_P(BluetoothAudioProviderLeAudioOutputSoftwareAidl, |
| 2118 | StartAndEndLeAudioOutputSessionWithPossiblePcmConfig) { |
| 2119 | for (auto sample_rate : le_audio_output_sample_rates_) { |
| 2120 | for (auto bits_per_sample : le_audio_output_bits_per_samples_) { |
| 2121 | for (auto channel_mode : le_audio_output_channel_modes_) { |
| 2122 | for (auto data_interval_us : le_audio_output_data_interval_us_) { |
| 2123 | PcmConfiguration pcm_config{ |
| 2124 | .sampleRateHz = sample_rate, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2125 | .channelMode = channel_mode, |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 2126 | .bitsPerSample = bits_per_sample, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2127 | .dataIntervalUs = data_interval_us, |
| 2128 | }; |
Josh Wu | 8a1be76 | 2022-02-15 09:37:29 -0800 | [diff] [blame] | 2129 | bool is_codec_config_valid = |
| 2130 | IsPcmConfigSupported(pcm_config) && pcm_config.dataIntervalUs > 0; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2131 | DataMQDesc mq_desc; |
| 2132 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 2133 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 2134 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2135 | DataMQ data_mq(mq_desc); |
| 2136 | |
| 2137 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 2138 | if (is_codec_config_valid) { |
| 2139 | EXPECT_TRUE(data_mq.isValid()); |
| 2140 | } |
| 2141 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 2142 | } |
| 2143 | } |
| 2144 | } |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | /** |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame] | 2149 | * openProvider LE_AUDIO_SOFTWARE_DECODING_DATAPATH |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2150 | */ |
| 2151 | class BluetoothAudioProviderLeAudioInputSoftwareAidl |
| 2152 | : public BluetoothAudioProviderFactoryAidl { |
| 2153 | public: |
| 2154 | virtual void SetUp() override { |
| 2155 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 2156 | GetProviderCapabilitiesHelper( |
| 2157 | SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH); |
| 2158 | OpenProviderHelper(SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH); |
| 2159 | ASSERT_NE(audio_provider_, nullptr); |
| 2160 | } |
| 2161 | |
| 2162 | virtual void TearDown() override { |
| 2163 | audio_port_ = nullptr; |
| 2164 | audio_provider_ = nullptr; |
| 2165 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 2166 | } |
| 2167 | |
| 2168 | static constexpr int32_t le_audio_input_sample_rates_[] = { |
| 2169 | 0, 8000, 16000, 24000, 32000, 44100, 48000}; |
| 2170 | static constexpr int8_t le_audio_input_bits_per_samples_[] = {0, 16, 24}; |
| 2171 | static constexpr ChannelMode le_audio_input_channel_modes_[] = { |
| 2172 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 2173 | static constexpr int32_t le_audio_input_data_interval_us_[] = { |
| 2174 | 0 /* Invalid */, 10000 /* Valid 10ms */}; |
| 2175 | }; |
| 2176 | |
| 2177 | /** |
| 2178 | * Test whether each provider of type |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame] | 2179 | * SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2180 | * stopped |
| 2181 | */ |
| 2182 | TEST_P(BluetoothAudioProviderLeAudioInputSoftwareAidl, |
| 2183 | OpenLeAudioInputSoftwareProvider) {} |
| 2184 | |
| 2185 | /** |
| 2186 | * Test whether each provider of type |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame] | 2187 | * SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2188 | * stopped with different PCM config |
| 2189 | */ |
| 2190 | TEST_P(BluetoothAudioProviderLeAudioInputSoftwareAidl, |
| 2191 | StartAndEndLeAudioInputSessionWithPossiblePcmConfig) { |
| 2192 | for (auto sample_rate : le_audio_input_sample_rates_) { |
| 2193 | for (auto bits_per_sample : le_audio_input_bits_per_samples_) { |
| 2194 | for (auto channel_mode : le_audio_input_channel_modes_) { |
| 2195 | for (auto data_interval_us : le_audio_input_data_interval_us_) { |
| 2196 | PcmConfiguration pcm_config{ |
| 2197 | .sampleRateHz = sample_rate, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2198 | .channelMode = channel_mode, |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 2199 | .bitsPerSample = bits_per_sample, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2200 | .dataIntervalUs = data_interval_us, |
| 2201 | }; |
Josh Wu | 8a1be76 | 2022-02-15 09:37:29 -0800 | [diff] [blame] | 2202 | bool is_codec_config_valid = |
| 2203 | IsPcmConfigSupported(pcm_config) && pcm_config.dataIntervalUs > 0; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2204 | DataMQDesc mq_desc; |
| 2205 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 2206 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 2207 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2208 | DataMQ data_mq(mq_desc); |
| 2209 | |
| 2210 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 2211 | if (is_codec_config_valid) { |
| 2212 | EXPECT_TRUE(data_mq.isValid()); |
| 2213 | } |
| 2214 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 2215 | } |
| 2216 | } |
| 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | /** |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame] | 2222 | * openProvider LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2223 | */ |
| 2224 | class BluetoothAudioProviderLeAudioOutputHardwareAidl |
| 2225 | : public BluetoothAudioProviderFactoryAidl { |
| 2226 | public: |
| 2227 | virtual void SetUp() override { |
| 2228 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 2229 | GetProviderCapabilitiesHelper( |
| 2230 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2231 | GetProviderInfoHelper( |
| 2232 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2233 | OpenProviderHelper( |
| 2234 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 2235 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 2236 | audio_provider_ != nullptr); |
| 2237 | } |
| 2238 | |
| 2239 | virtual void TearDown() override { |
| 2240 | audio_port_ = nullptr; |
| 2241 | audio_provider_ = nullptr; |
| 2242 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 2243 | } |
| 2244 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2245 | bool IsMultidirectionalCapabilitiesEnabled() { |
| 2246 | if (!temp_provider_info_.has_value()) return false; |
| 2247 | |
| 2248 | return temp_provider_info_.value().supportsMultidirectionalCapabilities; |
| 2249 | } |
| 2250 | |
| 2251 | bool IsAsymmetricConfigurationAllowed() { |
| 2252 | if (!temp_provider_info_.has_value()) return false; |
| 2253 | if (temp_provider_info_.value().codecInfos.empty()) return false; |
| 2254 | |
| 2255 | for (auto& codec_info : temp_provider_info_.value().codecInfos) { |
| 2256 | if (codec_info.transport.getTag() != CodecInfo::Transport::leAudio) { |
| 2257 | return false; |
| 2258 | } |
| 2259 | |
| 2260 | auto flags = |
| 2261 | codec_info.transport.get<CodecInfo::Transport::leAudio>().flags; |
| 2262 | |
| 2263 | if (!flags) { |
| 2264 | continue; |
| 2265 | } |
| 2266 | |
| 2267 | if (flags->bitmask & |
| 2268 | ConfigurationFlags::ALLOW_ASYMMETRIC_CONFIGURATIONS) { |
| 2269 | return true; |
| 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | return false; |
| 2274 | } |
| 2275 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2276 | bool IsOffloadOutputSupported() { |
| 2277 | for (auto& capability : temp_provider_capabilities_) { |
| 2278 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 2279 | continue; |
| 2280 | } |
| 2281 | auto& le_audio_capability = |
| 2282 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 2283 | if (le_audio_capability.unicastEncodeCapability.codecType != |
| 2284 | CodecType::UNKNOWN) |
| 2285 | return true; |
| 2286 | } |
| 2287 | return false; |
| 2288 | } |
| 2289 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2290 | bool IsOffloadOutputProviderInfoSupported() { |
| 2291 | if (!temp_provider_info_.has_value()) return false; |
| 2292 | if (temp_provider_info_.value().codecInfos.empty()) return false; |
| 2293 | // Check if all codec info is of LeAudio type |
| 2294 | for (auto& codec_info : temp_provider_info_.value().codecInfos) { |
| 2295 | if (codec_info.transport.getTag() != CodecInfo::Transport::leAudio) |
| 2296 | return false; |
| 2297 | } |
| 2298 | return true; |
| 2299 | } |
| 2300 | |
| 2301 | std::vector<Lc3Configuration> GetUnicastLc3SupportedListFromProviderInfo() { |
| 2302 | std::vector<Lc3Configuration> le_audio_codec_configs; |
| 2303 | for (auto& codec_info : temp_provider_info_.value().codecInfos) { |
| 2304 | // Only gets LC3 codec information |
| 2305 | if (codec_info.id != CodecId::Core::LC3) continue; |
| 2306 | // Combine those parameters into one list of Lc3Configuration |
| 2307 | auto& transport = |
| 2308 | codec_info.transport.get<CodecInfo::Transport::Tag::leAudio>(); |
| 2309 | for (int32_t samplingFrequencyHz : transport.samplingFrequencyHz) { |
| 2310 | for (int32_t frameDurationUs : transport.frameDurationUs) { |
| 2311 | for (int32_t octetsPerFrame : transport.bitdepth) { |
| 2312 | Lc3Configuration lc3_config = { |
| 2313 | .samplingFrequencyHz = samplingFrequencyHz, |
| 2314 | .frameDurationUs = frameDurationUs, |
| 2315 | .octetsPerFrame = octetsPerFrame, |
| 2316 | }; |
| 2317 | le_audio_codec_configs.push_back(lc3_config); |
| 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | return le_audio_codec_configs; |
| 2324 | } |
| 2325 | |
| 2326 | AudioContext GetAudioContext(int32_t bitmask) { |
| 2327 | AudioContext media_audio_context; |
| 2328 | media_audio_context.bitmask = bitmask; |
| 2329 | return media_audio_context; |
| 2330 | } |
| 2331 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2332 | LeAudioDeviceCapabilities GetDefaultRemoteSinkCapability() { |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2333 | // Create a capability |
| 2334 | LeAudioDeviceCapabilities capability; |
| 2335 | |
| 2336 | capability.codecId = CodecId::Core::LC3; |
| 2337 | |
| 2338 | auto pref_context_metadata = MetadataLtv::PreferredAudioContexts(); |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2339 | pref_context_metadata.values = |
| 2340 | GetAudioContext(AudioContext::MEDIA | AudioContext::CONVERSATIONAL | |
| 2341 | AudioContext::GAME); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2342 | capability.metadata = {pref_context_metadata}; |
| 2343 | |
| 2344 | auto sampling_rate = |
| 2345 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies(); |
| 2346 | sampling_rate.bitmask = |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2347 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies::HZ16000 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2348 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies::HZ8000; |
| 2349 | auto frame_duration = |
| 2350 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations(); |
| 2351 | frame_duration.bitmask = |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2352 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations::US7500 | |
| 2353 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations::US10000; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2354 | auto octets = CodecSpecificCapabilitiesLtv::SupportedOctetsPerCodecFrame(); |
Jakub Tyszkowski | 1d21422 | 2024-01-16 09:44:48 +0000 | [diff] [blame] | 2355 | octets.min = 0; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2356 | octets.max = 120; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2357 | auto frames = CodecSpecificCapabilitiesLtv::SupportedMaxCodecFramesPerSDU(); |
| 2358 | frames.value = 2; |
| 2359 | capability.codecSpecificCapabilities = {sampling_rate, frame_duration, |
| 2360 | octets, frames}; |
| 2361 | return capability; |
| 2362 | } |
| 2363 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2364 | LeAudioDeviceCapabilities GetDefaultRemoteSourceCapability() { |
| 2365 | // Create a capability |
| 2366 | LeAudioDeviceCapabilities capability; |
| 2367 | |
| 2368 | capability.codecId = CodecId::Core::LC3; |
| 2369 | |
| 2370 | auto pref_context_metadata = MetadataLtv::PreferredAudioContexts(); |
| 2371 | pref_context_metadata.values = |
| 2372 | GetAudioContext(AudioContext::LIVE_AUDIO | |
| 2373 | AudioContext::CONVERSATIONAL | AudioContext::GAME); |
| 2374 | capability.metadata = {pref_context_metadata}; |
| 2375 | |
| 2376 | auto sampling_rate = |
| 2377 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies(); |
| 2378 | sampling_rate.bitmask = |
| 2379 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies::HZ16000 | |
| 2380 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies::HZ8000; |
| 2381 | auto frame_duration = |
| 2382 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations(); |
| 2383 | frame_duration.bitmask = |
| 2384 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations::US7500 | |
| 2385 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations::US10000; |
| 2386 | auto octets = CodecSpecificCapabilitiesLtv::SupportedOctetsPerCodecFrame(); |
| 2387 | octets.min = 0; |
| 2388 | octets.max = 120; |
| 2389 | auto frames = CodecSpecificCapabilitiesLtv::SupportedMaxCodecFramesPerSDU(); |
| 2390 | frames.value = 2; |
| 2391 | capability.codecSpecificCapabilities = {sampling_rate, frame_duration, |
| 2392 | octets, frames}; |
| 2393 | return capability; |
| 2394 | } |
| 2395 | |
| 2396 | std::optional<CodecSpecificConfigurationLtv> GetConfigurationLtv( |
| 2397 | const std::vector<CodecSpecificConfigurationLtv>& configurationLtvs, |
| 2398 | CodecSpecificConfigurationLtv::Tag tag) { |
| 2399 | for (const auto ltv : configurationLtvs) { |
| 2400 | if (ltv.getTag() == tag) { |
| 2401 | return ltv; |
| 2402 | } |
| 2403 | } |
| 2404 | return std::nullopt; |
| 2405 | } |
| 2406 | |
| 2407 | bool IsAseRequirementSatisfiedWithUnknownChannelCount( |
| 2408 | const std::vector<std::optional<AseDirectionRequirement>>& |
| 2409 | ase_requirements, |
| 2410 | const std::vector<std::optional<AseDirectionConfiguration>>& |
| 2411 | ase_configurations) { |
| 2412 | /* This is mandatory to match sample freq, allocation however, when in the |
| 2413 | * device group there is only one device which supports left and right |
| 2414 | * allocation, and channel count is hidden from the BT stack, the BT stack |
| 2415 | * will send single requirement but it can receive two configurations if the |
| 2416 | * channel count is 1. |
| 2417 | */ |
| 2418 | |
| 2419 | int num_of_ase_requirements = 0; |
| 2420 | for (const auto& ase_req : ase_requirements) { |
| 2421 | auto required_allocation_ltv = GetConfigurationLtv( |
| 2422 | ase_req->aseConfiguration.codecConfiguration, |
| 2423 | CodecSpecificConfigurationLtv::Tag::audioChannelAllocation); |
| 2424 | if (required_allocation_ltv == std::nullopt) { |
| 2425 | continue; |
| 2426 | } |
| 2427 | int required_allocation = |
| 2428 | required_allocation_ltv |
| 2429 | ->get< |
| 2430 | CodecSpecificConfigurationLtv::Tag::audioChannelAllocation>() |
| 2431 | .bitmask; |
| 2432 | num_of_ase_requirements += std::bitset<32>(required_allocation).count(); |
| 2433 | } |
| 2434 | |
| 2435 | int num_of_satisfied_ase_requirements = 0; |
| 2436 | for (const auto& ase_req : ase_requirements) { |
| 2437 | if (!ase_req) { |
| 2438 | continue; |
| 2439 | } |
| 2440 | auto required_sample_freq_ltv = GetConfigurationLtv( |
| 2441 | ase_req->aseConfiguration.codecConfiguration, |
| 2442 | CodecSpecificConfigurationLtv::Tag::samplingFrequency); |
| 2443 | auto required_allocation_ltv = GetConfigurationLtv( |
| 2444 | ase_req->aseConfiguration.codecConfiguration, |
| 2445 | CodecSpecificConfigurationLtv::Tag::audioChannelAllocation); |
| 2446 | |
| 2447 | /* Allocation and sample freq shall be always in the requirement */ |
| 2448 | if (!required_sample_freq_ltv || !required_allocation_ltv) { |
| 2449 | return false; |
| 2450 | } |
| 2451 | |
| 2452 | int required_allocation = |
| 2453 | required_allocation_ltv |
| 2454 | ->get< |
| 2455 | CodecSpecificConfigurationLtv::Tag::audioChannelAllocation>() |
| 2456 | .bitmask; |
| 2457 | |
| 2458 | for (const auto& ase_conf : ase_configurations) { |
| 2459 | if (!ase_conf) { |
| 2460 | continue; |
| 2461 | } |
| 2462 | auto config_sample_freq_ltv = GetConfigurationLtv( |
| 2463 | ase_conf->aseConfiguration.codecConfiguration, |
| 2464 | CodecSpecificConfigurationLtv::Tag::samplingFrequency); |
| 2465 | auto config_allocation_ltv = GetConfigurationLtv( |
| 2466 | ase_conf->aseConfiguration.codecConfiguration, |
| 2467 | CodecSpecificConfigurationLtv::Tag::audioChannelAllocation); |
| 2468 | if (config_sample_freq_ltv == std::nullopt || |
| 2469 | config_allocation_ltv == std::nullopt) { |
| 2470 | return false; |
| 2471 | } |
| 2472 | |
| 2473 | int configured_allocation = config_allocation_ltv |
| 2474 | ->get<CodecSpecificConfigurationLtv:: |
| 2475 | Tag::audioChannelAllocation>() |
| 2476 | .bitmask; |
| 2477 | |
| 2478 | if (config_sample_freq_ltv == required_sample_freq_ltv && |
| 2479 | (required_allocation & configured_allocation)) { |
| 2480 | num_of_satisfied_ase_requirements += |
| 2481 | std::bitset<32>(configured_allocation).count(); |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | return (num_of_satisfied_ase_requirements == num_of_ase_requirements); |
| 2487 | } |
| 2488 | |
| 2489 | bool IsAseRequirementSatisfied( |
| 2490 | const std::vector<std::optional<AseDirectionRequirement>>& |
| 2491 | ase_requirements, |
| 2492 | const std::vector<std::optional<AseDirectionConfiguration>>& |
| 2493 | ase_configurations) { |
| 2494 | // This is mandatory to match sample freq, allocation |
| 2495 | int num_of_satisfied_ase_requirements = 0; |
| 2496 | |
| 2497 | int required_allocations = 0; |
| 2498 | for (const auto& ase_req : ase_requirements) { |
| 2499 | auto required_allocation_ltv = GetConfigurationLtv( |
| 2500 | ase_req->aseConfiguration.codecConfiguration, |
| 2501 | CodecSpecificConfigurationLtv::Tag::audioChannelAllocation); |
| 2502 | if (required_allocation_ltv == std::nullopt) { |
| 2503 | continue; |
| 2504 | } |
| 2505 | |
| 2506 | int allocations = |
| 2507 | required_allocation_ltv |
| 2508 | ->get< |
| 2509 | CodecSpecificConfigurationLtv::Tag::audioChannelAllocation>() |
| 2510 | .bitmask; |
| 2511 | required_allocations += std::bitset<32>(allocations).count(); |
| 2512 | } |
| 2513 | |
| 2514 | if (ase_requirements.size() != required_allocations) { |
| 2515 | /* If more than one allication is requested in the requirement, then use |
| 2516 | * different verifier */ |
| 2517 | return IsAseRequirementSatisfiedWithUnknownChannelCount( |
| 2518 | ase_requirements, ase_configurations); |
| 2519 | } |
| 2520 | |
| 2521 | for (const auto& ase_req : ase_requirements) { |
| 2522 | if (!ase_req) { |
| 2523 | continue; |
| 2524 | } |
| 2525 | auto required_sample_freq_ltv = GetConfigurationLtv( |
| 2526 | ase_req->aseConfiguration.codecConfiguration, |
| 2527 | CodecSpecificConfigurationLtv::Tag::samplingFrequency); |
| 2528 | auto required_allocation_ltv = GetConfigurationLtv( |
| 2529 | ase_req->aseConfiguration.codecConfiguration, |
| 2530 | CodecSpecificConfigurationLtv::Tag::audioChannelAllocation); |
| 2531 | |
| 2532 | /* Allocation and sample freq shall be always in the requirement */ |
| 2533 | if (!required_sample_freq_ltv || !required_allocation_ltv) { |
| 2534 | return false; |
| 2535 | } |
| 2536 | |
| 2537 | for (const auto& ase_conf : ase_configurations) { |
| 2538 | if (!ase_conf) { |
| 2539 | continue; |
| 2540 | } |
| 2541 | auto config_sample_freq_ltv = GetConfigurationLtv( |
| 2542 | ase_conf->aseConfiguration.codecConfiguration, |
| 2543 | CodecSpecificConfigurationLtv::Tag::samplingFrequency); |
| 2544 | auto config_allocation_ltv = GetConfigurationLtv( |
| 2545 | ase_conf->aseConfiguration.codecConfiguration, |
| 2546 | CodecSpecificConfigurationLtv::Tag::audioChannelAllocation); |
| 2547 | if (config_sample_freq_ltv == std::nullopt || |
| 2548 | config_allocation_ltv == std::nullopt) { |
| 2549 | return false; |
| 2550 | } |
| 2551 | |
| 2552 | if (config_sample_freq_ltv == required_sample_freq_ltv && |
| 2553 | config_allocation_ltv == required_allocation_ltv) { |
| 2554 | num_of_satisfied_ase_requirements++; |
| 2555 | break; |
| 2556 | } |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | return (num_of_satisfied_ase_requirements == ase_requirements.size()); |
| 2561 | } |
| 2562 | |
| 2563 | void VerifyIfRequirementsSatisfied( |
| 2564 | const std::vector<LeAudioConfigurationRequirement>& requirements, |
| 2565 | const std::vector<LeAudioAseConfigurationSetting>& configurations) { |
| 2566 | if (requirements.empty() && configurations.empty()) { |
| 2567 | return; |
| 2568 | } |
| 2569 | |
| 2570 | /* It might happen that vendor lib will provide same configuration for |
| 2571 | * multiple contexts and it should be accepted |
| 2572 | */ |
| 2573 | |
| 2574 | int num_of_requirements = 0; |
| 2575 | for (const auto& req : requirements) { |
| 2576 | num_of_requirements += std::bitset<32>(req.audioContext.bitmask).count(); |
| 2577 | } |
| 2578 | |
| 2579 | int num_of_configurations = 0; |
| 2580 | for (const auto& conf : configurations) { |
| 2581 | num_of_configurations += |
| 2582 | std::bitset<32>(conf.audioContext.bitmask).count(); |
| 2583 | } |
| 2584 | |
| 2585 | ASSERT_EQ(num_of_requirements, num_of_configurations); |
| 2586 | |
| 2587 | int num_of_satisfied_requirements = 0; |
| 2588 | for (const auto& req : requirements) { |
| 2589 | for (const auto& conf : configurations) { |
| 2590 | if ((req.audioContext.bitmask & conf.audioContext.bitmask) != |
| 2591 | req.audioContext.bitmask) { |
| 2592 | continue; |
| 2593 | } |
| 2594 | |
| 2595 | if (req.sinkAseRequirement && req.sourceAseRequirement) { |
| 2596 | if (!conf.sinkAseConfiguration || !conf.sourceAseConfiguration) { |
| 2597 | continue; |
| 2598 | } |
| 2599 | |
| 2600 | if (!IsAseRequirementSatisfied(*req.sinkAseRequirement, |
| 2601 | *conf.sinkAseConfiguration) || |
| 2602 | !IsAseRequirementSatisfied(*req.sourceAseRequirement, |
| 2603 | *conf.sourceAseConfiguration)) { |
| 2604 | continue; |
| 2605 | } |
| 2606 | num_of_satisfied_requirements += |
| 2607 | std::bitset<32>(req.audioContext.bitmask).count(); |
| 2608 | |
| 2609 | break; |
| 2610 | } else if (req.sinkAseRequirement) { |
| 2611 | if (!IsAseRequirementSatisfied(*req.sinkAseRequirement, |
| 2612 | *conf.sinkAseConfiguration)) { |
| 2613 | continue; |
| 2614 | } |
| 2615 | num_of_satisfied_requirements += |
| 2616 | std::bitset<32>(req.audioContext.bitmask).count(); |
| 2617 | break; |
| 2618 | } else if (req.sourceAseRequirement) { |
| 2619 | if (!IsAseRequirementSatisfied(*req.sourceAseRequirement, |
| 2620 | *conf.sourceAseConfiguration)) { |
| 2621 | continue; |
| 2622 | } |
| 2623 | num_of_satisfied_requirements += |
| 2624 | std::bitset<32>(req.audioContext.bitmask).count(); |
| 2625 | break; |
| 2626 | } |
| 2627 | } |
| 2628 | } |
| 2629 | ASSERT_EQ(num_of_satisfied_requirements, num_of_requirements); |
| 2630 | } |
| 2631 | |
| 2632 | LeAudioConfigurationRequirement GetUnicastDefaultRequirement( |
| 2633 | int32_t context_bits, bool is_sink_requirement, |
| 2634 | bool is_source_requriement, |
| 2635 | CodecSpecificConfigurationLtv::SamplingFrequency freq = |
| 2636 | CodecSpecificConfigurationLtv::SamplingFrequency::HZ16000) { |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2637 | // Create a requirements |
| 2638 | LeAudioConfigurationRequirement requirement; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2639 | requirement.audioContext = GetAudioContext(context_bits); |
| 2640 | |
| 2641 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 2642 | allocation.bitmask = |
| 2643 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 2644 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2645 | |
| 2646 | auto direction_ase_requriement = AseDirectionRequirement(); |
| 2647 | direction_ase_requriement.aseConfiguration.codecId = CodecId::Core::LC3; |
| 2648 | direction_ase_requriement.aseConfiguration.targetLatency = |
| 2649 | LeAudioAseConfiguration::TargetLatency::BALANCED_LATENCY_RELIABILITY; |
| 2650 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2651 | direction_ase_requriement.aseConfiguration.codecConfiguration = { |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2652 | freq, CodecSpecificConfigurationLtv::FrameDuration::US10000, allocation |
| 2653 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2654 | }; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2655 | if (is_sink_requirement) |
| 2656 | requirement.sinkAseRequirement = {direction_ase_requriement}; |
| 2657 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2658 | if (is_source_requriement) |
| 2659 | requirement.sourceAseRequirement = {direction_ase_requriement}; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2660 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2661 | return requirement; |
| 2662 | } |
| 2663 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2664 | LeAudioConfigurationRequirement GetUnicastGameRequirement(bool asymmetric) { |
| 2665 | // Create a requirements |
| 2666 | LeAudioConfigurationRequirement requirement; |
| 2667 | requirement.audioContext = GetAudioContext(AudioContext::GAME); |
| 2668 | |
| 2669 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 2670 | allocation.bitmask = |
| 2671 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 2672 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
| 2673 | |
| 2674 | auto sink_ase_requriement = AseDirectionRequirement(); |
| 2675 | sink_ase_requriement.aseConfiguration.codecId = CodecId::Core::LC3; |
| 2676 | sink_ase_requriement.aseConfiguration.targetLatency = |
| 2677 | LeAudioAseConfiguration::TargetLatency::BALANCED_LATENCY_RELIABILITY; |
| 2678 | |
| 2679 | sink_ase_requriement.aseConfiguration.codecConfiguration = { |
| 2680 | CodecSpecificConfigurationLtv::SamplingFrequency::HZ16000, |
| 2681 | CodecSpecificConfigurationLtv::FrameDuration::US10000, allocation}; |
| 2682 | |
| 2683 | auto source_ase_requriement = AseDirectionRequirement(); |
| 2684 | source_ase_requriement.aseConfiguration.codecId = CodecId::Core::LC3; |
| 2685 | source_ase_requriement.aseConfiguration.targetLatency = |
| 2686 | LeAudioAseConfiguration::TargetLatency::BALANCED_LATENCY_RELIABILITY; |
| 2687 | |
| 2688 | if (asymmetric) { |
| 2689 | source_ase_requriement.aseConfiguration.codecConfiguration = { |
| 2690 | CodecSpecificConfigurationLtv::SamplingFrequency::HZ8000, |
| 2691 | CodecSpecificConfigurationLtv::FrameDuration::US10000, allocation}; |
| 2692 | } else { |
| 2693 | source_ase_requriement.aseConfiguration.codecConfiguration = { |
| 2694 | CodecSpecificConfigurationLtv::SamplingFrequency::HZ16000, |
| 2695 | CodecSpecificConfigurationLtv::FrameDuration::US10000, allocation}; |
| 2696 | } |
| 2697 | |
| 2698 | requirement.sinkAseRequirement = {sink_ase_requriement}; |
| 2699 | requirement.sourceAseRequirement = {source_ase_requriement}; |
| 2700 | |
| 2701 | return requirement; |
| 2702 | } |
| 2703 | |
| 2704 | LeAudioAseQosConfigurationRequirement GetQosRequirements( |
| 2705 | bool is_sink_requirement, bool is_source_requriement, bool valid = true) { |
| 2706 | LeAudioAseQosConfigurationRequirement qosRequirement; |
| 2707 | |
| 2708 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 2709 | allocation.bitmask = |
| 2710 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 2711 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
| 2712 | |
| 2713 | AseQosDirectionRequirement directionalRequirement = { |
| 2714 | .framing = IBluetoothAudioProvider::Framing::UNFRAMED, |
| 2715 | .preferredRetransmissionNum = 2, |
| 2716 | .maxTransportLatencyMs = 10, |
| 2717 | .presentationDelayMinUs = 40000, |
| 2718 | .presentationDelayMaxUs = 40000, |
| 2719 | .aseConfiguration = |
| 2720 | { |
| 2721 | .targetLatency = LeAudioAseConfiguration::TargetLatency:: |
| 2722 | BALANCED_LATENCY_RELIABILITY, |
| 2723 | .codecId = CodecId::Core::LC3, |
| 2724 | .codecConfiguration = |
| 2725 | {CodecSpecificConfigurationLtv::SamplingFrequency::HZ16000, |
| 2726 | CodecSpecificConfigurationLtv::FrameDuration::US10000, |
| 2727 | allocation}, |
| 2728 | }, |
| 2729 | }; |
| 2730 | |
| 2731 | if (!valid) { |
| 2732 | // clear some required values; |
| 2733 | directionalRequirement.maxTransportLatencyMs = 0; |
| 2734 | directionalRequirement.presentationDelayMaxUs = 0; |
| 2735 | } |
| 2736 | |
| 2737 | qosRequirement.sinkAseQosRequirement = directionalRequirement; |
| 2738 | if (is_source_requriement && is_sink_requirement) { |
| 2739 | qosRequirement.sourceAseQosRequirement = directionalRequirement; |
| 2740 | qosRequirement.sinkAseQosRequirement = directionalRequirement; |
| 2741 | } else if (is_source_requriement) { |
| 2742 | qosRequirement.sourceAseQosRequirement = directionalRequirement; |
| 2743 | qosRequirement.sinkAseQosRequirement = std::nullopt; |
| 2744 | } else if (is_sink_requirement) { |
| 2745 | qosRequirement.sourceAseQosRequirement = std::nullopt; |
| 2746 | qosRequirement.sinkAseQosRequirement = directionalRequirement; |
| 2747 | } |
| 2748 | |
| 2749 | return qosRequirement; |
| 2750 | } |
| 2751 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2752 | std::vector<Lc3Configuration> GetUnicastLc3SupportedList(bool decoding, |
| 2753 | bool supported) { |
| 2754 | std::vector<Lc3Configuration> le_audio_codec_configs; |
| 2755 | if (!supported) { |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 2756 | Lc3Configuration lc3_config{.pcmBitDepth = 0, .samplingFrequencyHz = 0}; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2757 | le_audio_codec_configs.push_back(lc3_config); |
| 2758 | return le_audio_codec_configs; |
| 2759 | } |
| 2760 | |
| 2761 | // There might be more than one LeAudioCodecCapabilitiesSetting |
| 2762 | std::vector<Lc3Capabilities> lc3_capabilities; |
| 2763 | for (auto& capability : temp_provider_capabilities_) { |
| 2764 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 2765 | continue; |
| 2766 | } |
| 2767 | auto& le_audio_capability = |
| 2768 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 2769 | auto& unicast_capability = |
| 2770 | decoding ? le_audio_capability.unicastDecodeCapability |
| 2771 | : le_audio_capability.unicastEncodeCapability; |
| 2772 | if (unicast_capability.codecType != CodecType::LC3) { |
| 2773 | continue; |
| 2774 | } |
| 2775 | auto& lc3_capability = unicast_capability.leAudioCodecCapabilities.get< |
| 2776 | UnicastCapability::LeAudioCodecCapabilities::lc3Capabilities>(); |
| 2777 | lc3_capabilities.push_back(lc3_capability); |
| 2778 | } |
| 2779 | |
| 2780 | // Combine those parameters into one list of LeAudioCodecConfiguration |
| 2781 | // This seems horrible, but usually each Lc3Capability only contains a |
| 2782 | // single Lc3Configuration, which means every array has a length of 1. |
| 2783 | for (auto& lc3_capability : lc3_capabilities) { |
| 2784 | for (int32_t samplingFrequencyHz : lc3_capability.samplingFrequencyHz) { |
| 2785 | for (int32_t frameDurationUs : lc3_capability.frameDurationUs) { |
| 2786 | for (int32_t octetsPerFrame : lc3_capability.octetsPerFrame) { |
| 2787 | Lc3Configuration lc3_config = { |
| 2788 | .samplingFrequencyHz = samplingFrequencyHz, |
| 2789 | .frameDurationUs = frameDurationUs, |
| 2790 | .octetsPerFrame = octetsPerFrame, |
| 2791 | }; |
| 2792 | le_audio_codec_configs.push_back(lc3_config); |
| 2793 | } |
| 2794 | } |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | return le_audio_codec_configs; |
| 2799 | } |
| 2800 | |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 2801 | static constexpr int32_t apx_adaptive_le_config_codec_modes[] = {0, 1, 2, 3}; |
| 2802 | |
| 2803 | std::vector<AptxAdaptiveLeConfiguration> |
| 2804 | GetUnicastAptxAdaptiveLeSupportedList(bool decoding, bool supported, |
| 2805 | bool is_le_extended) { |
| 2806 | std::vector<AptxAdaptiveLeConfiguration> le_audio_codec_configs; |
| 2807 | if (!supported) { |
| 2808 | AptxAdaptiveLeConfiguration aptx_adaptive_le_config{ |
| 2809 | .pcmBitDepth = 0, .samplingFrequencyHz = 0}; |
| 2810 | le_audio_codec_configs.push_back(aptx_adaptive_le_config); |
| 2811 | return le_audio_codec_configs; |
| 2812 | } |
| 2813 | |
| 2814 | // There might be more than one LeAudioCodecCapabilitiesSetting |
| 2815 | std::vector<AptxAdaptiveLeCapabilities> aptx_adaptive_le_capabilities; |
| 2816 | for (auto& capability : temp_provider_capabilities_) { |
| 2817 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 2818 | continue; |
| 2819 | } |
| 2820 | auto& le_audio_capability = |
| 2821 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 2822 | auto& unicast_capability = |
| 2823 | decoding ? le_audio_capability.unicastDecodeCapability |
| 2824 | : le_audio_capability.unicastEncodeCapability; |
| 2825 | if ((!is_le_extended && |
| 2826 | unicast_capability.codecType != CodecType::APTX_ADAPTIVE_LE) || |
| 2827 | (is_le_extended && |
| 2828 | unicast_capability.codecType != CodecType::APTX_ADAPTIVE_LEX)) { |
| 2829 | continue; |
| 2830 | } |
| 2831 | |
| 2832 | auto& aptx_adaptive_le_capability = |
| 2833 | unicast_capability.leAudioCodecCapabilities |
| 2834 | .get<UnicastCapability::LeAudioCodecCapabilities:: |
| 2835 | aptxAdaptiveLeCapabilities>(); |
| 2836 | |
| 2837 | aptx_adaptive_le_capabilities.push_back(aptx_adaptive_le_capability); |
| 2838 | } |
| 2839 | |
| 2840 | for (auto& aptx_adaptive_le_capability : aptx_adaptive_le_capabilities) { |
| 2841 | for (int32_t samplingFrequencyHz : |
| 2842 | aptx_adaptive_le_capability.samplingFrequencyHz) { |
| 2843 | for (int32_t frameDurationUs : |
| 2844 | aptx_adaptive_le_capability.frameDurationUs) { |
| 2845 | for (int32_t octetsPerFrame : |
| 2846 | aptx_adaptive_le_capability.octetsPerFrame) { |
| 2847 | for (int8_t blocksPerSdu : |
| 2848 | aptx_adaptive_le_capability.blocksPerSdu) { |
| 2849 | for (int32_t codecMode : apx_adaptive_le_config_codec_modes) { |
| 2850 | AptxAdaptiveLeConfiguration aptx_adaptive_le_config = { |
| 2851 | .samplingFrequencyHz = samplingFrequencyHz, |
| 2852 | .frameDurationUs = frameDurationUs, |
| 2853 | .octetsPerFrame = octetsPerFrame, |
| 2854 | .blocksPerSdu = blocksPerSdu, |
| 2855 | .codecMode = codecMode, |
| 2856 | }; |
| 2857 | le_audio_codec_configs.push_back(aptx_adaptive_le_config); |
| 2858 | } |
| 2859 | } |
| 2860 | } |
| 2861 | } |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | return le_audio_codec_configs; |
| 2866 | } |
| 2867 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2868 | LeAudioCodecCapabilitiesSetting temp_le_audio_capabilities_; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2869 | std::vector<int32_t> all_context_bitmasks = { |
| 2870 | AudioContext::UNSPECIFIED, AudioContext::CONVERSATIONAL, |
| 2871 | AudioContext::MEDIA, AudioContext::GAME, |
| 2872 | AudioContext::INSTRUCTIONAL, AudioContext::VOICE_ASSISTANTS, |
| 2873 | AudioContext::LIVE_AUDIO, AudioContext::SOUND_EFFECTS, |
| 2874 | AudioContext::NOTIFICATIONS, AudioContext::RINGTONE_ALERTS, |
| 2875 | AudioContext::ALERTS, AudioContext::EMERGENCY_ALARM, |
| 2876 | }; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2877 | |
| 2878 | AudioContext bidirectional_contexts = { |
| 2879 | .bitmask = AudioContext::CONVERSATIONAL | AudioContext::GAME | |
| 2880 | AudioContext::VOICE_ASSISTANTS | AudioContext::LIVE_AUDIO, |
| 2881 | }; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2882 | }; |
| 2883 | |
| 2884 | /** |
| 2885 | * Test whether each provider of type |
| 2886 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 2887 | * stopped |
| 2888 | */ |
| 2889 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 2890 | OpenLeAudioOutputHardwareProvider) {} |
| 2891 | |
| 2892 | /** |
| 2893 | * Test whether each provider of type |
| 2894 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2895 | * stopped with Unicast hardware encoding config taken from provider info |
| 2896 | */ |
| 2897 | TEST_P( |
| 2898 | BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 2899 | StartAndEndLeAudioOutputSessionWithPossibleUnicastConfigFromProviderInfo) { |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 2900 | if (GetProviderFactoryInterfaceVersion() < |
| 2901 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 2902 | GTEST_SKIP(); |
| 2903 | } |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2904 | if (!IsOffloadOutputProviderInfoSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 2905 | GTEST_SKIP(); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | auto lc3_codec_configs = GetUnicastLc3SupportedListFromProviderInfo(); |
| 2909 | LeAudioConfiguration le_audio_config = { |
| 2910 | .codecType = CodecType::LC3, |
| 2911 | .peerDelayUs = 0, |
| 2912 | }; |
| 2913 | |
| 2914 | for (auto& lc3_config : lc3_codec_configs) { |
| 2915 | le_audio_config.leAudioCodecConfig |
| 2916 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 2917 | DataMQDesc mq_desc; |
| 2918 | auto aidl_retval = audio_provider_->startSession( |
| 2919 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 2920 | &mq_desc); |
| 2921 | |
| 2922 | ASSERT_TRUE(aidl_retval.isOk()); |
| 2923 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 2928 | GetEmptyAseConfigurationEmptyCapability) { |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 2929 | if (GetProviderFactoryInterfaceVersion() < |
| 2930 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 2931 | GTEST_SKIP(); |
| 2932 | } |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2933 | |
| 2934 | if (IsMultidirectionalCapabilitiesEnabled()) { |
| 2935 | GTEST_SKIP(); |
| 2936 | } |
| 2937 | |
| 2938 | std::vector<std::optional<LeAudioDeviceCapabilities>> empty_capability; |
| 2939 | std::vector<LeAudioConfigurationRequirement> empty_requirement; |
| 2940 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 2941 | |
| 2942 | // Check empty capability for source direction |
| 2943 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 2944 | std::nullopt, empty_capability, empty_requirement, &configurations); |
| 2945 | |
| 2946 | ASSERT_FALSE(aidl_retval.isOk()); |
| 2947 | |
| 2948 | // Check empty capability for sink direction |
| 2949 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 2950 | empty_capability, std::nullopt, empty_requirement, &configurations); |
| 2951 | |
| 2952 | ASSERT_TRUE(aidl_retval.isOk()); |
| 2953 | ASSERT_TRUE(configurations.empty()); |
| 2954 | } |
| 2955 | |
| 2956 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 2957 | GetEmptyAseConfigurationEmptyCapability_Multidirectiona) { |
| 2958 | if (GetProviderFactoryInterfaceVersion() < |
| 2959 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 2960 | GTEST_SKIP(); |
| 2961 | } |
| 2962 | |
| 2963 | if (!IsMultidirectionalCapabilitiesEnabled()) { |
| 2964 | GTEST_SKIP(); |
| 2965 | } |
| 2966 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2967 | std::vector<std::optional<LeAudioDeviceCapabilities>> empty_capability; |
| 2968 | std::vector<LeAudioConfigurationRequirement> empty_requirement; |
| 2969 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 2970 | |
| 2971 | // Check empty capability for source direction |
| 2972 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 2973 | std::nullopt, empty_capability, empty_requirement, &configurations); |
| 2974 | |
| 2975 | ASSERT_TRUE(aidl_retval.isOk()); |
| 2976 | ASSERT_TRUE(configurations.empty()); |
| 2977 | |
| 2978 | // Check empty capability for sink direction |
| 2979 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 2980 | empty_capability, std::nullopt, empty_requirement, &configurations); |
| 2981 | |
| 2982 | ASSERT_TRUE(aidl_retval.isOk()); |
| 2983 | ASSERT_TRUE(configurations.empty()); |
| 2984 | } |
| 2985 | |
| 2986 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 2987 | GetEmptyAseConfigurationMismatchedRequirement) { |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 2988 | if (GetProviderFactoryInterfaceVersion() < |
| 2989 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 2990 | GTEST_SKIP(); |
| 2991 | } |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 2992 | std::vector<std::optional<LeAudioDeviceCapabilities>> sink_capabilities = { |
| 2993 | GetDefaultRemoteSinkCapability()}; |
| 2994 | std::vector<std::optional<LeAudioDeviceCapabilities>> source_capabilities = { |
| 2995 | GetDefaultRemoteSourceCapability()}; |
| 2996 | |
| 2997 | auto not_supported_sampling_rate_by_remote = |
| 2998 | CodecSpecificConfigurationLtv::SamplingFrequency::HZ11025; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 2999 | |
| 3000 | // Check empty capability for source direction |
| 3001 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 3002 | std::vector<LeAudioConfigurationRequirement> source_requirements = { |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3003 | GetUnicastDefaultRequirement(AudioContext::LIVE_AUDIO, false /*sink */, |
| 3004 | true /* source */, |
| 3005 | not_supported_sampling_rate_by_remote)}; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3006 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3007 | std::nullopt, source_capabilities, source_requirements, &configurations); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3008 | |
| 3009 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3010 | ASSERT_TRUE(configurations.empty()); |
| 3011 | |
| 3012 | // Check empty capability for sink direction |
| 3013 | std::vector<LeAudioConfigurationRequirement> sink_requirements = { |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3014 | GetUnicastDefaultRequirement(AudioContext::MEDIA, true /*sink */, |
| 3015 | false /* source */, |
| 3016 | not_supported_sampling_rate_by_remote)}; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3017 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3018 | sink_capabilities, std::nullopt, sink_requirements, &configurations); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3019 | |
| 3020 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3021 | ASSERT_TRUE(configurations.empty()); |
| 3022 | } |
| 3023 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3024 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, GetAseConfiguration) { |
| 3025 | if (GetProviderFactoryInterfaceVersion() < |
| 3026 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3027 | GTEST_SKIP(); |
| 3028 | } |
| 3029 | |
| 3030 | if (IsMultidirectionalCapabilitiesEnabled()) { |
| 3031 | GTEST_SKIP(); |
| 3032 | } |
| 3033 | |
| 3034 | std::vector<std::optional<LeAudioDeviceCapabilities>> sink_capabilities = { |
| 3035 | GetDefaultRemoteSinkCapability()}; |
| 3036 | std::vector<std::optional<LeAudioDeviceCapabilities>> source_capabilities = { |
| 3037 | GetDefaultRemoteSourceCapability()}; |
| 3038 | |
| 3039 | // Should not ask for Source on ENCODING session if Multidiretional not |
| 3040 | // supported |
| 3041 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 3042 | std::vector<LeAudioConfigurationRequirement> source_requirements = { |
| 3043 | GetUnicastDefaultRequirement(AudioContext::LIVE_AUDIO, false /* sink */, |
| 3044 | true /* source */)}; |
| 3045 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3046 | std::nullopt, source_capabilities, source_requirements, &configurations); |
| 3047 | |
| 3048 | ASSERT_FALSE(aidl_retval.isOk()); |
| 3049 | ASSERT_TRUE(configurations.empty()); |
| 3050 | |
| 3051 | // Check capability for remote sink direction |
| 3052 | std::vector<LeAudioConfigurationRequirement> sink_requirements = { |
| 3053 | GetUnicastDefaultRequirement(AudioContext::MEDIA, true /* sink */, |
| 3054 | false /* source */)}; |
| 3055 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3056 | sink_capabilities, std::nullopt, sink_requirements, &configurations); |
| 3057 | |
| 3058 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3059 | ASSERT_FALSE(configurations.empty()); |
| 3060 | VerifyIfRequirementsSatisfied(sink_requirements, configurations); |
| 3061 | |
| 3062 | // Check multiple capability for remote sink direction |
| 3063 | std::vector<LeAudioConfigurationRequirement> multi_sink_requirements = { |
| 3064 | GetUnicastDefaultRequirement(AudioContext::MEDIA, true /* sink */, |
| 3065 | false /* source */), |
| 3066 | GetUnicastDefaultRequirement(AudioContext::CONVERSATIONAL, |
| 3067 | true /* sink */, false /* source */)}; |
| 3068 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3069 | sink_capabilities, std::nullopt, multi_sink_requirements, |
| 3070 | &configurations); |
| 3071 | |
| 3072 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3073 | ASSERT_FALSE(configurations.empty()); |
| 3074 | VerifyIfRequirementsSatisfied(multi_sink_requirements, configurations); |
| 3075 | |
| 3076 | // Check multiple context types in a single requirement. |
| 3077 | std::vector<LeAudioConfigurationRequirement> multi_context_sink_requirements = |
| 3078 | {GetUnicastDefaultRequirement( |
| 3079 | AudioContext::MEDIA | AudioContext::SOUND_EFFECTS, true /* sink */, |
| 3080 | false /* source */)}; |
| 3081 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3082 | sink_capabilities, std::nullopt, multi_context_sink_requirements, |
| 3083 | &configurations); |
| 3084 | |
| 3085 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3086 | ASSERT_FALSE(configurations.empty()); |
| 3087 | VerifyIfRequirementsSatisfied(multi_sink_requirements, configurations); |
| 3088 | } |
| 3089 | |
| 3090 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 3091 | GetAseConfiguration_Multidirectional) { |
| 3092 | if (GetProviderFactoryInterfaceVersion() < |
| 3093 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3094 | GTEST_SKIP(); |
| 3095 | } |
| 3096 | |
| 3097 | if (!IsMultidirectionalCapabilitiesEnabled()) { |
| 3098 | GTEST_SKIP(); |
| 3099 | } |
| 3100 | |
| 3101 | std::vector<std::optional<LeAudioDeviceCapabilities>> sink_capabilities = { |
| 3102 | GetDefaultRemoteSinkCapability()}; |
| 3103 | std::vector<std::optional<LeAudioDeviceCapabilities>> source_capabilities = { |
| 3104 | GetDefaultRemoteSourceCapability()}; |
| 3105 | |
| 3106 | // Verify source configuration is received |
| 3107 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 3108 | std::vector<LeAudioConfigurationRequirement> source_requirements = { |
| 3109 | GetUnicastDefaultRequirement(AudioContext::LIVE_AUDIO, false /* sink */, |
| 3110 | true /* source */)}; |
| 3111 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3112 | std::nullopt, source_capabilities, source_requirements, &configurations); |
| 3113 | |
| 3114 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3115 | ASSERT_FALSE(configurations.empty()); |
| 3116 | VerifyIfRequirementsSatisfied(source_requirements, configurations); |
| 3117 | |
| 3118 | // Verify sink configuration is received |
| 3119 | std::vector<LeAudioConfigurationRequirement> sink_requirements = { |
| 3120 | GetUnicastDefaultRequirement(AudioContext::MEDIA, true /* sink */, |
| 3121 | false /* source */)}; |
| 3122 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3123 | sink_capabilities, std::nullopt, sink_requirements, &configurations); |
| 3124 | |
| 3125 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3126 | ASSERT_FALSE(configurations.empty()); |
| 3127 | VerifyIfRequirementsSatisfied(sink_requirements, configurations); |
| 3128 | |
| 3129 | std::vector<LeAudioConfigurationRequirement> combined_requirements = { |
| 3130 | GetUnicastDefaultRequirement(AudioContext::LIVE_AUDIO, false /* sink */, |
| 3131 | true /* source */), |
| 3132 | GetUnicastDefaultRequirement(AudioContext::CONVERSATIONAL, |
| 3133 | true /* sink */, true /* source */), |
| 3134 | GetUnicastDefaultRequirement(AudioContext::MEDIA, true /* sink */, |
| 3135 | false /* source */)}; |
| 3136 | |
| 3137 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3138 | sink_capabilities, source_capabilities, combined_requirements, |
| 3139 | &configurations); |
| 3140 | |
| 3141 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3142 | ASSERT_FALSE(configurations.empty()); |
| 3143 | VerifyIfRequirementsSatisfied(combined_requirements, configurations); |
| 3144 | } |
| 3145 | |
| 3146 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 3147 | GetAsymmetricAseConfiguration_Multidirectional) { |
| 3148 | if (GetProviderFactoryInterfaceVersion() < |
| 3149 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3150 | GTEST_SKIP(); |
| 3151 | } |
| 3152 | |
| 3153 | if (!IsMultidirectionalCapabilitiesEnabled()) { |
| 3154 | GTEST_SKIP(); |
| 3155 | } |
| 3156 | |
| 3157 | if (!IsAsymmetricConfigurationAllowed()) { |
| 3158 | GTEST_SKIP(); |
| 3159 | } |
| 3160 | |
| 3161 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 3162 | std::vector<std::optional<LeAudioDeviceCapabilities>> sink_capabilities = { |
| 3163 | GetDefaultRemoteSinkCapability()}; |
| 3164 | std::vector<std::optional<LeAudioDeviceCapabilities>> source_capabilities = { |
| 3165 | GetDefaultRemoteSourceCapability()}; |
| 3166 | |
| 3167 | std::vector<LeAudioConfigurationRequirement> asymmetric_requirements = { |
| 3168 | GetUnicastGameRequirement(true /* Asymmetric */)}; |
| 3169 | |
| 3170 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3171 | sink_capabilities, source_capabilities, asymmetric_requirements, |
| 3172 | &configurations); |
| 3173 | |
| 3174 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3175 | ASSERT_FALSE(configurations.empty()); |
| 3176 | VerifyIfRequirementsSatisfied(asymmetric_requirements, configurations); |
| 3177 | } |
| 3178 | |
| 3179 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 3180 | GetQoSConfiguration_Multidirectional) { |
| 3181 | if (GetProviderFactoryInterfaceVersion() < |
| 3182 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3183 | GTEST_SKIP(); |
| 3184 | } |
| 3185 | |
| 3186 | if (!IsMultidirectionalCapabilitiesEnabled()) { |
| 3187 | GTEST_SKIP(); |
| 3188 | } |
| 3189 | |
| 3190 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 3191 | allocation.bitmask = |
| 3192 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 3193 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
| 3194 | |
| 3195 | LeAudioAseQosConfigurationRequirement requirement = |
| 3196 | GetQosRequirements(true, true); |
| 3197 | |
| 3198 | std::vector<IBluetoothAudioProvider::LeAudioAseQosConfiguration> |
| 3199 | QoSConfigurations; |
| 3200 | bool is_supported = false; |
| 3201 | for (auto bitmask : all_context_bitmasks) { |
| 3202 | requirement.audioContext = GetAudioContext(bitmask); |
| 3203 | bool is_bidirectional = bidirectional_contexts.bitmask & bitmask; |
| 3204 | |
| 3205 | if (is_bidirectional) { |
| 3206 | requirement.sourceAseQosRequirement = requirement.sinkAseQosRequirement; |
| 3207 | } else { |
| 3208 | requirement.sourceAseQosRequirement = std::nullopt; |
| 3209 | } |
| 3210 | |
| 3211 | IBluetoothAudioProvider::LeAudioAseQosConfigurationPair result; |
| 3212 | auto aidl_retval = |
| 3213 | audio_provider_->getLeAudioAseQosConfiguration(requirement, &result); |
| 3214 | if (!aidl_retval.isOk()) { |
| 3215 | // If not OK, then it could be not supported, as it is an optional |
| 3216 | // feature |
| 3217 | ASSERT_EQ(aidl_retval.getExceptionCode(), EX_UNSUPPORTED_OPERATION); |
| 3218 | } |
| 3219 | |
| 3220 | is_supported = true; |
| 3221 | if (result.sinkQosConfiguration.has_value()) { |
| 3222 | if (is_bidirectional) { |
| 3223 | ASSERT_TRUE(result.sourceQosConfiguration.has_value()); |
| 3224 | } else { |
| 3225 | ASSERT_FALSE(result.sourceQosConfiguration.has_value()); |
| 3226 | } |
| 3227 | QoSConfigurations.push_back(result.sinkQosConfiguration.value()); |
| 3228 | } |
| 3229 | } |
| 3230 | if (is_supported) { |
| 3231 | // QoS Configurations should not be empty, as we searched for all contexts |
| 3232 | ASSERT_FALSE(QoSConfigurations.empty()); |
| 3233 | } |
| 3234 | } |
| 3235 | |
| 3236 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 3237 | GetQoSConfiguration_InvalidRequirements) { |
| 3238 | if (GetProviderFactoryInterfaceVersion() < |
| 3239 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3240 | GTEST_SKIP(); |
| 3241 | } |
| 3242 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 3243 | allocation.bitmask = |
| 3244 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 3245 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
| 3246 | |
| 3247 | LeAudioAseQosConfigurationRequirement invalid_requirement = |
| 3248 | GetQosRequirements(true /* sink */, false /* source */, |
| 3249 | false /* valid */); |
| 3250 | |
| 3251 | std::vector<IBluetoothAudioProvider::LeAudioAseQosConfiguration> |
| 3252 | QoSConfigurations; |
| 3253 | for (auto bitmask : all_context_bitmasks) { |
| 3254 | invalid_requirement.audioContext = GetAudioContext(bitmask); |
| 3255 | IBluetoothAudioProvider::LeAudioAseQosConfigurationPair result; |
| 3256 | auto aidl_retval = audio_provider_->getLeAudioAseQosConfiguration( |
| 3257 | invalid_requirement, &result); |
| 3258 | ASSERT_FALSE(aidl_retval.isOk()); |
| 3259 | } |
| 3260 | } |
| 3261 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3262 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, GetQoSConfiguration) { |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 3263 | if (GetProviderFactoryInterfaceVersion() < |
| 3264 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3265 | GTEST_SKIP(); |
| 3266 | } |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3267 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 3268 | allocation.bitmask = |
| 3269 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 3270 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
| 3271 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3272 | IBluetoothAudioProvider::LeAudioAseQosConfigurationRequirement requirement; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3273 | requirement = GetQosRequirements(true /* sink */, false /* source */); |
| 3274 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3275 | std::vector<IBluetoothAudioProvider::LeAudioAseQosConfiguration> |
| 3276 | QoSConfigurations; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3277 | bool is_supported = false; |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3278 | for (auto bitmask : all_context_bitmasks) { |
Jakub Tyszkowski | 1d21422 | 2024-01-16 09:44:48 +0000 | [diff] [blame] | 3279 | requirement.audioContext = GetAudioContext(bitmask); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3280 | IBluetoothAudioProvider::LeAudioAseQosConfigurationPair result; |
| 3281 | auto aidl_retval = |
| 3282 | audio_provider_->getLeAudioAseQosConfiguration(requirement, &result); |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3283 | if (!aidl_retval.isOk()) { |
| 3284 | // If not OK, then it could be not supported, as it is an optional |
| 3285 | // feature |
| 3286 | ASSERT_EQ(aidl_retval.getExceptionCode(), EX_UNSUPPORTED_OPERATION); |
| 3287 | } else { |
| 3288 | is_supported = true; |
| 3289 | if (result.sinkQosConfiguration.has_value()) { |
| 3290 | QoSConfigurations.push_back(result.sinkQosConfiguration.value()); |
| 3291 | } |
| 3292 | } |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3293 | } |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3294 | |
| 3295 | if (is_supported) { |
| 3296 | // QoS Configurations should not be empty, as we searched for all contexts |
| 3297 | ASSERT_FALSE(QoSConfigurations.empty()); |
| 3298 | } |
| 3299 | } |
| 3300 | |
| 3301 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 3302 | GetDataPathConfiguration_Multidirectional) { |
| 3303 | IBluetoothAudioProvider::StreamConfig sink_requirement; |
| 3304 | IBluetoothAudioProvider::StreamConfig source_requirement; |
| 3305 | std::vector<IBluetoothAudioProvider::LeAudioDataPathConfiguration> |
| 3306 | DataPathConfigurations; |
| 3307 | |
| 3308 | if (!IsMultidirectionalCapabilitiesEnabled()) { |
| 3309 | GTEST_SKIP(); |
| 3310 | } |
| 3311 | |
| 3312 | bool is_supported = false; |
| 3313 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 3314 | allocation.bitmask = |
| 3315 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 3316 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
| 3317 | |
| 3318 | auto streamMap = LeAudioConfiguration::StreamMap(); |
| 3319 | |
| 3320 | // Use some mandatory configuration |
| 3321 | streamMap.streamHandle = 0x0001; |
| 3322 | streamMap.audioChannelAllocation = 0x03; |
| 3323 | streamMap.aseConfiguration = { |
| 3324 | .targetLatency = |
| 3325 | LeAudioAseConfiguration::TargetLatency::BALANCED_LATENCY_RELIABILITY, |
| 3326 | .codecId = CodecId::Core::LC3, |
| 3327 | .codecConfiguration = |
| 3328 | {CodecSpecificConfigurationLtv::SamplingFrequency::HZ16000, |
| 3329 | CodecSpecificConfigurationLtv::FrameDuration::US10000, allocation}, |
| 3330 | }; |
| 3331 | |
| 3332 | // Bidirectional |
| 3333 | sink_requirement.streamMap = {streamMap}; |
| 3334 | source_requirement.streamMap = {streamMap}; |
| 3335 | |
| 3336 | for (auto bitmask : all_context_bitmasks) { |
| 3337 | sink_requirement.audioContext = GetAudioContext(bitmask); |
| 3338 | source_requirement.audioContext = sink_requirement.audioContext; |
| 3339 | |
| 3340 | IBluetoothAudioProvider::LeAudioDataPathConfigurationPair result; |
| 3341 | ::ndk::ScopedAStatus aidl_retval; |
| 3342 | |
| 3343 | bool is_bidirectional = bidirectional_contexts.bitmask & bitmask; |
| 3344 | if (is_bidirectional) { |
| 3345 | aidl_retval = audio_provider_->getLeAudioAseDatapathConfiguration( |
| 3346 | sink_requirement, source_requirement, &result); |
| 3347 | } else { |
| 3348 | aidl_retval = audio_provider_->getLeAudioAseDatapathConfiguration( |
| 3349 | sink_requirement, std::nullopt, &result); |
| 3350 | } |
| 3351 | |
| 3352 | if (!aidl_retval.isOk()) { |
| 3353 | // If not OK, then it could be not supported, as it is an optional |
| 3354 | // feature |
| 3355 | ASSERT_EQ(aidl_retval.getExceptionCode(), EX_UNSUPPORTED_OPERATION); |
| 3356 | } else { |
| 3357 | is_supported = true; |
| 3358 | if (result.outputConfig.has_value()) { |
| 3359 | if (is_bidirectional) { |
| 3360 | ASSERT_TRUE(result.inputConfig.has_value()); |
| 3361 | } else { |
| 3362 | ASSERT_TRUE(!result.inputConfig.has_value()); |
| 3363 | } |
| 3364 | DataPathConfigurations.push_back(result.outputConfig.value()); |
| 3365 | } |
| 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | if (is_supported) { |
| 3370 | // Datapath Configurations should not be empty, as we searched for all |
| 3371 | // contexts |
| 3372 | ASSERT_FALSE(DataPathConfigurations.empty()); |
| 3373 | } |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3374 | } |
Jakub Tyszkowski | c8a6224 | 2024-01-05 15:25:49 +0000 | [diff] [blame] | 3375 | |
| 3376 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 3377 | GetDataPathConfiguration) { |
Jakub Tyszkowski | e77f872 | 2024-01-29 13:21:21 +0000 | [diff] [blame] | 3378 | if (GetProviderFactoryInterfaceVersion() < |
| 3379 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3380 | GTEST_SKIP(); |
| 3381 | } |
Jakub Tyszkowski | c8a6224 | 2024-01-05 15:25:49 +0000 | [diff] [blame] | 3382 | IBluetoothAudioProvider::StreamConfig sink_requirement; |
Jakub Tyszkowski | c8a6224 | 2024-01-05 15:25:49 +0000 | [diff] [blame] | 3383 | std::vector<IBluetoothAudioProvider::LeAudioDataPathConfiguration> |
| 3384 | DataPathConfigurations; |
| 3385 | bool is_supported = false; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3386 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 3387 | allocation.bitmask = |
| 3388 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 3389 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
| 3390 | |
| 3391 | auto streamMap = LeAudioConfiguration::StreamMap(); |
| 3392 | |
| 3393 | // Use some mandatory configuration |
| 3394 | streamMap.streamHandle = 0x0001; |
| 3395 | streamMap.audioChannelAllocation = 0x03; |
| 3396 | streamMap.aseConfiguration = { |
| 3397 | .targetLatency = |
| 3398 | LeAudioAseConfiguration::TargetLatency::BALANCED_LATENCY_RELIABILITY, |
| 3399 | .codecId = CodecId::Core::LC3, |
| 3400 | .codecConfiguration = |
| 3401 | {CodecSpecificConfigurationLtv::SamplingFrequency::HZ16000, |
| 3402 | CodecSpecificConfigurationLtv::FrameDuration::US10000, allocation}, |
| 3403 | }; |
| 3404 | |
| 3405 | sink_requirement.streamMap = {streamMap}; |
Jakub Tyszkowski | c8a6224 | 2024-01-05 15:25:49 +0000 | [diff] [blame] | 3406 | |
| 3407 | for (auto bitmask : all_context_bitmasks) { |
Jakub Tyszkowski | 1d21422 | 2024-01-16 09:44:48 +0000 | [diff] [blame] | 3408 | sink_requirement.audioContext = GetAudioContext(bitmask); |
Jakub Tyszkowski | c8a6224 | 2024-01-05 15:25:49 +0000 | [diff] [blame] | 3409 | IBluetoothAudioProvider::LeAudioDataPathConfigurationPair result; |
| 3410 | auto aidl_retval = audio_provider_->getLeAudioAseDatapathConfiguration( |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3411 | sink_requirement, std::nullopt, &result); |
| 3412 | |
Jakub Tyszkowski | c8a6224 | 2024-01-05 15:25:49 +0000 | [diff] [blame] | 3413 | if (!aidl_retval.isOk()) { |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3414 | // If not OK, then it could be not supported, as it is an optional |
| 3415 | // feature |
Jakub Tyszkowski | c8a6224 | 2024-01-05 15:25:49 +0000 | [diff] [blame] | 3416 | ASSERT_EQ(aidl_retval.getExceptionCode(), EX_UNSUPPORTED_OPERATION); |
| 3417 | } else { |
| 3418 | is_supported = true; |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3419 | if (result.outputConfig.has_value()) { |
| 3420 | DataPathConfigurations.push_back(result.outputConfig.value()); |
| 3421 | } |
Jakub Tyszkowski | c8a6224 | 2024-01-05 15:25:49 +0000 | [diff] [blame] | 3422 | } |
| 3423 | } |
| 3424 | |
| 3425 | if (is_supported) { |
| 3426 | // Datapath Configurations should not be empty, as we searched for all |
| 3427 | // contexts |
| 3428 | ASSERT_FALSE(DataPathConfigurations.empty()); |
| 3429 | } |
| 3430 | } |
| 3431 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3432 | /** |
| 3433 | * Test whether each provider of type |
| 3434 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3435 | * stopped with Unicast hardware encoding config |
| 3436 | */ |
| 3437 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 3438 | StartAndEndLeAudioOutputSessionWithPossibleUnicastConfig) { |
| 3439 | if (!IsOffloadOutputSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 3440 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | auto lc3_codec_configs = |
| 3444 | GetUnicastLc3SupportedList(false /* decoding */, true /* supported */); |
| 3445 | LeAudioConfiguration le_audio_config = { |
| 3446 | .codecType = CodecType::LC3, |
| 3447 | .peerDelayUs = 0, |
| 3448 | }; |
| 3449 | |
| 3450 | for (auto& lc3_config : lc3_codec_configs) { |
| 3451 | le_audio_config.leAudioCodecConfig |
| 3452 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 3453 | DataMQDesc mq_desc; |
| 3454 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 3455 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 3456 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3457 | |
| 3458 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3459 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | /** |
| 3464 | * Test whether each provider of type |
| 3465 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 3466 | * stopped with Unicast hardware encoding config |
| 3467 | * |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3468 | */ |
| 3469 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3470 | StartAndEndLeAudioOutputSessionWithInvalidAudioConfiguration) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3471 | if (!IsOffloadOutputSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 3472 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | auto lc3_codec_configs = |
| 3476 | GetUnicastLc3SupportedList(false /* decoding */, false /* supported */); |
| 3477 | LeAudioConfiguration le_audio_config = { |
| 3478 | .codecType = CodecType::LC3, |
| 3479 | .peerDelayUs = 0, |
| 3480 | }; |
| 3481 | |
| 3482 | for (auto& lc3_config : lc3_codec_configs) { |
| 3483 | le_audio_config.leAudioCodecConfig |
| 3484 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 3485 | DataMQDesc mq_desc; |
| 3486 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 3487 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 3488 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3489 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3490 | // It is OK to start session with invalid configuration |
| 3491 | ASSERT_TRUE(aidl_retval.isOk()); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3492 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 3493 | } |
| 3494 | } |
| 3495 | |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 3496 | static std::vector<uint8_t> vendorMetadata = {0x0B, // Length |
| 3497 | 0xFF, // Type: Vendor-specific |
| 3498 | 0x0A, 0x00, // Company_ID |
| 3499 | 0x01, 0x02, 0x03, 0x04, // Data |
| 3500 | 0x05, 0x06, 0x07, 0x08}; |
| 3501 | |
| 3502 | /** |
| 3503 | * Test whether each provider of type |
| 3504 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 3505 | * stopped with Unicast hardware encoding config |
| 3506 | */ |
| 3507 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 3508 | StartAndEndLeAudioOutputSessionWithAptxAdaptiveLeUnicastConfig) { |
| 3509 | if (!IsOffloadOutputSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 3510 | GTEST_SKIP(); |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 3511 | } |
| 3512 | for (auto codec_type : |
| 3513 | {CodecType::APTX_ADAPTIVE_LE, CodecType::APTX_ADAPTIVE_LEX}) { |
| 3514 | bool is_le_extended = (codec_type == CodecType::APTX_ADAPTIVE_LEX); |
| 3515 | auto aptx_adaptive_le_codec_configs = |
| 3516 | GetUnicastAptxAdaptiveLeSupportedList(false, true, is_le_extended); |
| 3517 | LeAudioConfiguration le_audio_config = { |
| 3518 | .codecType = codec_type, |
| 3519 | .peerDelayUs = 0, |
| 3520 | .vendorSpecificMetadata = vendorMetadata, |
| 3521 | }; |
| 3522 | |
| 3523 | for (auto& aptx_adaptive_le_config : aptx_adaptive_le_codec_configs) { |
| 3524 | le_audio_config.leAudioCodecConfig |
| 3525 | .set<LeAudioCodecConfiguration::aptxAdaptiveLeConfig>( |
| 3526 | aptx_adaptive_le_config); |
| 3527 | DataMQDesc mq_desc; |
| 3528 | auto aidl_retval = audio_provider_->startSession( |
| 3529 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 3530 | &mq_desc); |
| 3531 | |
| 3532 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3533 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 3534 | } |
| 3535 | } |
| 3536 | } |
| 3537 | |
| 3538 | /** |
| 3539 | * Test whether each provider of type |
| 3540 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 3541 | * stopped with Unicast hardware encoding config |
| 3542 | */ |
| 3543 | TEST_P( |
| 3544 | BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 3545 | BluetoothAudioProviderLeAudioOutputHardwareAidl_StartAndEndLeAudioOutputSessionWithInvalidAptxAdaptiveLeAudioConfiguration) { |
| 3546 | if (!IsOffloadOutputSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 3547 | GTEST_SKIP(); |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | for (auto codec_type : |
| 3551 | {CodecType::APTX_ADAPTIVE_LE, CodecType::APTX_ADAPTIVE_LEX}) { |
| 3552 | bool is_le_extended = (codec_type == CodecType::APTX_ADAPTIVE_LEX); |
| 3553 | auto aptx_adaptive_le_codec_configs = |
| 3554 | GetUnicastAptxAdaptiveLeSupportedList(false, true, is_le_extended); |
| 3555 | LeAudioConfiguration le_audio_config = { |
| 3556 | .codecType = codec_type, |
| 3557 | .peerDelayUs = 0, |
| 3558 | .vendorSpecificMetadata = vendorMetadata, |
| 3559 | }; |
| 3560 | |
| 3561 | for (auto& aptx_adaptive_le_config : aptx_adaptive_le_codec_configs) { |
| 3562 | le_audio_config.leAudioCodecConfig |
| 3563 | .set<LeAudioCodecConfiguration::aptxAdaptiveLeConfig>( |
| 3564 | aptx_adaptive_le_config); |
| 3565 | DataMQDesc mq_desc; |
| 3566 | auto aidl_retval = audio_provider_->startSession( |
| 3567 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 3568 | &mq_desc); |
| 3569 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3570 | // It is OK to start session with invalid configuration |
| 3571 | ASSERT_TRUE(aidl_retval.isOk()); |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 3572 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 3573 | } |
| 3574 | } |
| 3575 | } |
| 3576 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3577 | /** |
| 3578 | * openProvider LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH |
| 3579 | */ |
| 3580 | class BluetoothAudioProviderLeAudioInputHardwareAidl |
| 3581 | : public BluetoothAudioProviderLeAudioOutputHardwareAidl { |
| 3582 | public: |
| 3583 | virtual void SetUp() override { |
| 3584 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 3585 | GetProviderCapabilitiesHelper( |
| 3586 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3587 | GetProviderInfoHelper( |
| 3588 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3589 | OpenProviderHelper( |
| 3590 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
| 3591 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 3592 | audio_provider_ != nullptr); |
| 3593 | } |
| 3594 | |
| 3595 | bool IsOffloadInputSupported() { |
| 3596 | for (auto& capability : temp_provider_capabilities_) { |
| 3597 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 3598 | continue; |
| 3599 | } |
| 3600 | auto& le_audio_capability = |
| 3601 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 3602 | if (le_audio_capability.unicastDecodeCapability.codecType != |
| 3603 | CodecType::UNKNOWN) |
| 3604 | return true; |
| 3605 | } |
| 3606 | return false; |
| 3607 | } |
| 3608 | |
| 3609 | virtual void TearDown() override { |
| 3610 | audio_port_ = nullptr; |
| 3611 | audio_provider_ = nullptr; |
| 3612 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 3613 | } |
| 3614 | }; |
| 3615 | |
| 3616 | /** |
| 3617 | * Test whether each provider of type |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3618 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3619 | * stopped |
| 3620 | */ |
| 3621 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 3622 | OpenLeAudioInputHardwareProvider) {} |
| 3623 | |
| 3624 | /** |
| 3625 | * Test whether each provider of type |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3626 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH can be started and |
| 3627 | * stopped with Unicast hardware encoding config taken from provider info |
| 3628 | */ |
| 3629 | TEST_P( |
| 3630 | BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 3631 | StartAndEndLeAudioInputSessionWithPossibleUnicastConfigFromProviderInfo) { |
| 3632 | if (!IsOffloadOutputProviderInfoSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 3633 | GTEST_SKIP(); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
| 3636 | auto lc3_codec_configs = GetUnicastLc3SupportedListFromProviderInfo(); |
| 3637 | LeAudioConfiguration le_audio_config = { |
| 3638 | .codecType = CodecType::LC3, |
| 3639 | .peerDelayUs = 0, |
| 3640 | }; |
| 3641 | |
| 3642 | for (auto& lc3_config : lc3_codec_configs) { |
| 3643 | le_audio_config.leAudioCodecConfig |
| 3644 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 3645 | DataMQDesc mq_desc; |
| 3646 | auto aidl_retval = audio_provider_->startSession( |
| 3647 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 3648 | &mq_desc); |
| 3649 | |
| 3650 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3651 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | /** |
| 3656 | * Test whether each provider of type |
| 3657 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3658 | * stopped with Unicast hardware encoding config |
| 3659 | */ |
| 3660 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 3661 | StartAndEndLeAudioInputSessionWithPossibleUnicastConfig) { |
| 3662 | if (!IsOffloadInputSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 3663 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | auto lc3_codec_configs = |
| 3667 | GetUnicastLc3SupportedList(true /* decoding */, true /* supported */); |
| 3668 | LeAudioConfiguration le_audio_config = { |
| 3669 | .codecType = CodecType::LC3, |
| 3670 | .peerDelayUs = 0, |
| 3671 | }; |
| 3672 | |
| 3673 | for (auto& lc3_config : lc3_codec_configs) { |
| 3674 | le_audio_config.leAudioCodecConfig |
| 3675 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 3676 | DataMQDesc mq_desc; |
| 3677 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 3678 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 3679 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3680 | |
| 3681 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3682 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | /** |
| 3687 | * Test whether each provider of type |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 3688 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3689 | * stopped with Unicast hardware encoding config |
| 3690 | * |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3691 | */ |
| 3692 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3693 | StartAndEndLeAudioInputSessionWithInvalidAudioConfiguration) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3694 | if (!IsOffloadInputSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 3695 | GTEST_SKIP(); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | auto lc3_codec_configs = |
| 3699 | GetUnicastLc3SupportedList(true /* decoding */, false /* supported */); |
| 3700 | LeAudioConfiguration le_audio_config = { |
| 3701 | .codecType = CodecType::LC3, |
| 3702 | .peerDelayUs = 0, |
| 3703 | }; |
| 3704 | |
| 3705 | for (auto& lc3_config : lc3_codec_configs) { |
| 3706 | le_audio_config.leAudioCodecConfig |
| 3707 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 3708 | |
| 3709 | DataMQDesc mq_desc; |
| 3710 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 3711 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 3712 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3713 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3714 | // It is OK to start with invalid configuration as it might be unknown on |
| 3715 | // start |
| 3716 | ASSERT_TRUE(aidl_retval.isOk()); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3717 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 3718 | } |
| 3719 | } |
| 3720 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 3721 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 3722 | GetEmptyAseConfigurationEmptyCapability) { |
| 3723 | if (GetProviderFactoryInterfaceVersion() < |
| 3724 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3725 | GTEST_SKIP(); |
| 3726 | } |
| 3727 | |
| 3728 | if (IsMultidirectionalCapabilitiesEnabled()) { |
| 3729 | GTEST_SKIP(); |
| 3730 | } |
| 3731 | |
| 3732 | std::vector<std::optional<LeAudioDeviceCapabilities>> empty_capability; |
| 3733 | std::vector<LeAudioConfigurationRequirement> empty_requirement; |
| 3734 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 3735 | |
| 3736 | // Check success for source direction (Input == DecodingSession == remote |
| 3737 | // source) |
| 3738 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3739 | std::nullopt, empty_capability, empty_requirement, &configurations); |
| 3740 | |
| 3741 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3742 | ASSERT_TRUE(configurations.empty()); |
| 3743 | |
| 3744 | // Check failure for sink direction |
| 3745 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3746 | empty_capability, std::nullopt, empty_requirement, &configurations); |
| 3747 | |
| 3748 | ASSERT_FALSE(aidl_retval.isOk()); |
| 3749 | } |
| 3750 | |
| 3751 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 3752 | GetEmptyAseConfigurationEmptyCapability_Multidirectional) { |
| 3753 | if (GetProviderFactoryInterfaceVersion() < |
| 3754 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3755 | GTEST_SKIP(); |
| 3756 | } |
| 3757 | |
| 3758 | if (!IsMultidirectionalCapabilitiesEnabled()) { |
| 3759 | GTEST_SKIP(); |
| 3760 | } |
| 3761 | |
| 3762 | std::vector<std::optional<LeAudioDeviceCapabilities>> empty_capability; |
| 3763 | std::vector<LeAudioConfigurationRequirement> empty_requirement; |
| 3764 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 3765 | |
| 3766 | // Check empty capability for source direction |
| 3767 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3768 | std::nullopt, empty_capability, empty_requirement, &configurations); |
| 3769 | |
| 3770 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3771 | ASSERT_TRUE(configurations.empty()); |
| 3772 | |
| 3773 | // Check empty capability for sink direction |
| 3774 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3775 | empty_capability, std::nullopt, empty_requirement, &configurations); |
| 3776 | |
| 3777 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3778 | ASSERT_TRUE(configurations.empty()); |
| 3779 | } |
| 3780 | |
| 3781 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, GetAseConfiguration) { |
| 3782 | if (GetProviderFactoryInterfaceVersion() < |
| 3783 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3784 | GTEST_SKIP(); |
| 3785 | } |
| 3786 | |
| 3787 | if (IsMultidirectionalCapabilitiesEnabled()) { |
| 3788 | GTEST_SKIP(); |
| 3789 | } |
| 3790 | |
| 3791 | std::vector<std::optional<LeAudioDeviceCapabilities>> sink_capabilities = { |
| 3792 | GetDefaultRemoteSinkCapability()}; |
| 3793 | std::vector<std::optional<LeAudioDeviceCapabilities>> source_capabilities = { |
| 3794 | GetDefaultRemoteSourceCapability()}; |
| 3795 | |
| 3796 | // Check source configuration is received |
| 3797 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 3798 | std::vector<LeAudioConfigurationRequirement> source_requirements = { |
| 3799 | GetUnicastDefaultRequirement(AudioContext::LIVE_AUDIO, false /* sink */, |
| 3800 | true /* source */)}; |
| 3801 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3802 | std::nullopt, source_capabilities, source_requirements, &configurations); |
| 3803 | |
| 3804 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3805 | ASSERT_FALSE(configurations.empty()); |
| 3806 | |
| 3807 | // Check error result when requesting sink on DECODING session |
| 3808 | std::vector<LeAudioConfigurationRequirement> sink_requirements = { |
| 3809 | GetUnicastDefaultRequirement(AudioContext::MEDIA, true /* sink */, |
| 3810 | false /* source */)}; |
| 3811 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3812 | sink_capabilities, std::nullopt, sink_requirements, &configurations); |
| 3813 | |
| 3814 | ASSERT_FALSE(aidl_retval.isOk()); |
| 3815 | } |
| 3816 | |
| 3817 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 3818 | GetAseConfiguration_Multidirectional) { |
| 3819 | if (GetProviderFactoryInterfaceVersion() < |
| 3820 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3821 | GTEST_SKIP(); |
| 3822 | } |
| 3823 | |
| 3824 | if (!IsMultidirectionalCapabilitiesEnabled()) { |
| 3825 | GTEST_SKIP(); |
| 3826 | } |
| 3827 | |
| 3828 | std::vector<std::optional<LeAudioDeviceCapabilities>> sink_capabilities = { |
| 3829 | GetDefaultRemoteSinkCapability()}; |
| 3830 | std::vector<std::optional<LeAudioDeviceCapabilities>> source_capabilities = { |
| 3831 | GetDefaultRemoteSourceCapability()}; |
| 3832 | |
| 3833 | // Check source configuration is received |
| 3834 | std::vector<LeAudioAseConfigurationSetting> configurations; |
| 3835 | std::vector<LeAudioConfigurationRequirement> source_requirements = { |
| 3836 | GetUnicastDefaultRequirement(AudioContext::LIVE_AUDIO, false /* sink */, |
| 3837 | true /* source */)}; |
| 3838 | auto aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3839 | std::nullopt, source_capabilities, source_requirements, &configurations); |
| 3840 | |
| 3841 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3842 | ASSERT_FALSE(configurations.empty()); |
| 3843 | VerifyIfRequirementsSatisfied(source_requirements, configurations); |
| 3844 | |
| 3845 | // Check empty capability for sink direction |
| 3846 | std::vector<LeAudioConfigurationRequirement> sink_requirements = { |
| 3847 | GetUnicastDefaultRequirement(AudioContext::MEDIA, true /* sink */, |
| 3848 | false /* source */)}; |
| 3849 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3850 | sink_capabilities, std::nullopt, sink_requirements, &configurations); |
| 3851 | |
| 3852 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3853 | ASSERT_FALSE(configurations.empty()); |
| 3854 | VerifyIfRequirementsSatisfied(sink_requirements, configurations); |
| 3855 | |
| 3856 | std::vector<LeAudioConfigurationRequirement> combined_requirements = { |
| 3857 | GetUnicastDefaultRequirement(AudioContext::LIVE_AUDIO, false /* sink */, |
| 3858 | true /* source */), |
| 3859 | GetUnicastDefaultRequirement(AudioContext::CONVERSATIONAL, |
| 3860 | true /* sink */, true /* source */), |
| 3861 | GetUnicastDefaultRequirement(AudioContext::MEDIA, true /* sink */, |
| 3862 | false /* source */)}; |
| 3863 | |
| 3864 | aidl_retval = audio_provider_->getLeAudioAseConfiguration( |
| 3865 | sink_capabilities, source_capabilities, combined_requirements, |
| 3866 | &configurations); |
| 3867 | |
| 3868 | ASSERT_TRUE(aidl_retval.isOk()); |
| 3869 | ASSERT_FALSE(configurations.empty()); |
| 3870 | VerifyIfRequirementsSatisfied(combined_requirements, configurations); |
| 3871 | } |
| 3872 | |
| 3873 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 3874 | GetQoSConfiguration_InvalidRequirements) { |
| 3875 | if (GetProviderFactoryInterfaceVersion() < |
| 3876 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3877 | GTEST_SKIP(); |
| 3878 | } |
| 3879 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 3880 | allocation.bitmask = |
| 3881 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 3882 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
| 3883 | |
| 3884 | LeAudioAseQosConfigurationRequirement invalid_requirement = |
| 3885 | GetQosRequirements(false /* sink */, true /* source */, |
| 3886 | false /* valid */); |
| 3887 | |
| 3888 | std::vector<IBluetoothAudioProvider::LeAudioAseQosConfiguration> |
| 3889 | QoSConfigurations; |
| 3890 | for (auto bitmask : all_context_bitmasks) { |
| 3891 | invalid_requirement.audioContext = GetAudioContext(bitmask); |
| 3892 | IBluetoothAudioProvider::LeAudioAseQosConfigurationPair result; |
| 3893 | auto aidl_retval = audio_provider_->getLeAudioAseQosConfiguration( |
| 3894 | invalid_requirement, &result); |
| 3895 | ASSERT_FALSE(aidl_retval.isOk()); |
| 3896 | } |
| 3897 | } |
| 3898 | |
| 3899 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, GetQoSConfiguration) { |
| 3900 | if (GetProviderFactoryInterfaceVersion() < |
| 3901 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 3902 | GTEST_SKIP(); |
| 3903 | } |
| 3904 | auto allocation = CodecSpecificConfigurationLtv::AudioChannelAllocation(); |
| 3905 | allocation.bitmask = |
| 3906 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_LEFT | |
| 3907 | CodecSpecificConfigurationLtv::AudioChannelAllocation::FRONT_RIGHT; |
| 3908 | |
| 3909 | IBluetoothAudioProvider::LeAudioAseQosConfigurationRequirement requirement; |
| 3910 | requirement = GetQosRequirements(false /* sink */, true /* source */); |
| 3911 | |
| 3912 | std::vector<IBluetoothAudioProvider::LeAudioAseQosConfiguration> |
| 3913 | QoSConfigurations; |
| 3914 | bool is_supported = false; |
| 3915 | for (auto bitmask : all_context_bitmasks) { |
| 3916 | requirement.audioContext = GetAudioContext(bitmask); |
| 3917 | IBluetoothAudioProvider::LeAudioAseQosConfigurationPair result; |
| 3918 | auto aidl_retval = |
| 3919 | audio_provider_->getLeAudioAseQosConfiguration(requirement, &result); |
| 3920 | if (!aidl_retval.isOk()) { |
| 3921 | // If not OK, then it could be not supported, as it is an optional |
| 3922 | // feature |
| 3923 | ASSERT_EQ(aidl_retval.getExceptionCode(), EX_UNSUPPORTED_OPERATION); |
| 3924 | } else { |
| 3925 | is_supported = true; |
| 3926 | if (result.sourceQosConfiguration.has_value()) { |
| 3927 | QoSConfigurations.push_back(result.sourceQosConfiguration.value()); |
| 3928 | } |
| 3929 | } |
| 3930 | } |
| 3931 | |
| 3932 | if (is_supported) { |
| 3933 | // QoS Configurations should not be empty, as we searched for all contexts |
| 3934 | ASSERT_FALSE(QoSConfigurations.empty()); |
| 3935 | } |
| 3936 | } |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3937 | /** |
| 3938 | * openProvider LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH |
| 3939 | */ |
| 3940 | class BluetoothAudioProviderLeAudioBroadcastSoftwareAidl |
| 3941 | : public BluetoothAudioProviderFactoryAidl { |
| 3942 | public: |
| 3943 | virtual void SetUp() override { |
| 3944 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 3945 | GetProviderCapabilitiesHelper( |
| 3946 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH); |
| 3947 | OpenProviderHelper( |
| 3948 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH); |
| 3949 | ASSERT_NE(audio_provider_, nullptr); |
| 3950 | } |
| 3951 | |
| 3952 | virtual void TearDown() override { |
| 3953 | audio_port_ = nullptr; |
| 3954 | audio_provider_ = nullptr; |
| 3955 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 3956 | } |
| 3957 | |
| 3958 | static constexpr int32_t le_audio_output_sample_rates_[] = { |
| 3959 | 0, 8000, 16000, 24000, 32000, 44100, 48000, |
| 3960 | }; |
| 3961 | static constexpr int8_t le_audio_output_bits_per_samples_[] = {0, 16, 24}; |
| 3962 | static constexpr ChannelMode le_audio_output_channel_modes_[] = { |
| 3963 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 3964 | static constexpr int32_t le_audio_output_data_interval_us_[] = { |
| 3965 | 0 /* Invalid */, 10000 /* Valid 10ms */}; |
| 3966 | }; |
| 3967 | |
| 3968 | /** |
| 3969 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 3970 | * SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH can be started |
| 3971 | * and stopped |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3972 | */ |
| 3973 | TEST_P(BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, |
Josh Wu | 3202eab | 2022-02-17 18:09:05 -0800 | [diff] [blame] | 3974 | OpenLeAudioOutputSoftwareProvider) {} |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3975 | |
| 3976 | /** |
| 3977 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 3978 | * SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH can be started |
| 3979 | * and stopped with different PCM config |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3980 | */ |
| 3981 | TEST_P(BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, |
Josh Wu | 3202eab | 2022-02-17 18:09:05 -0800 | [diff] [blame] | 3982 | StartAndEndLeAudioOutputSessionWithPossiblePcmConfig) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3983 | for (auto sample_rate : le_audio_output_sample_rates_) { |
| 3984 | for (auto bits_per_sample : le_audio_output_bits_per_samples_) { |
| 3985 | for (auto channel_mode : le_audio_output_channel_modes_) { |
| 3986 | for (auto data_interval_us : le_audio_output_data_interval_us_) { |
| 3987 | PcmConfiguration pcm_config{ |
| 3988 | .sampleRateHz = sample_rate, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3989 | .channelMode = channel_mode, |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 3990 | .bitsPerSample = bits_per_sample, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3991 | .dataIntervalUs = data_interval_us, |
| 3992 | }; |
Josh Wu | 8a1be76 | 2022-02-15 09:37:29 -0800 | [diff] [blame] | 3993 | bool is_codec_config_valid = |
| 3994 | IsPcmConfigSupported(pcm_config) && pcm_config.dataIntervalUs > 0; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3995 | DataMQDesc mq_desc; |
| 3996 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 3997 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 3998 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 3999 | DataMQ data_mq(mq_desc); |
| 4000 | |
| 4001 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 4002 | if (is_codec_config_valid) { |
| 4003 | EXPECT_TRUE(data_mq.isValid()); |
| 4004 | } |
| 4005 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4006 | } |
| 4007 | } |
| 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4012 | /** |
| 4013 | * openProvider LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH |
| 4014 | */ |
| 4015 | class BluetoothAudioProviderLeAudioBroadcastHardwareAidl |
| 4016 | : public BluetoothAudioProviderFactoryAidl { |
| 4017 | public: |
| 4018 | virtual void SetUp() override { |
| 4019 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 4020 | GetProviderCapabilitiesHelper( |
| 4021 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 4022 | GetProviderInfoHelper( |
| 4023 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4024 | OpenProviderHelper( |
| 4025 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 4026 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 4027 | audio_provider_ != nullptr); |
| 4028 | } |
| 4029 | |
| 4030 | virtual void TearDown() override { |
| 4031 | audio_port_ = nullptr; |
| 4032 | audio_provider_ = nullptr; |
| 4033 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 4034 | } |
| 4035 | |
| 4036 | bool IsBroadcastOffloadSupported() { |
| 4037 | for (auto& capability : temp_provider_capabilities_) { |
| 4038 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 4039 | continue; |
| 4040 | } |
| 4041 | auto& le_audio_capability = |
| 4042 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 4043 | if (le_audio_capability.broadcastCapability.codecType != |
| 4044 | CodecType::UNKNOWN) |
| 4045 | return true; |
| 4046 | } |
| 4047 | return false; |
| 4048 | } |
| 4049 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 4050 | bool IsBroadcastOffloadProviderInfoSupported() { |
| 4051 | if (!temp_provider_info_.has_value()) return false; |
| 4052 | if (temp_provider_info_.value().codecInfos.empty()) return false; |
| 4053 | // Check if all codec info is of LeAudio type |
| 4054 | for (auto& codec_info : temp_provider_info_.value().codecInfos) { |
| 4055 | if (codec_info.transport.getTag() != CodecInfo::Transport::leAudio) |
| 4056 | return false; |
| 4057 | } |
| 4058 | return true; |
| 4059 | } |
| 4060 | |
| 4061 | std::vector<Lc3Configuration> GetBroadcastLc3SupportedListFromProviderInfo() { |
| 4062 | std::vector<Lc3Configuration> le_audio_codec_configs; |
| 4063 | for (auto& codec_info : temp_provider_info_.value().codecInfos) { |
| 4064 | // Only gets LC3 codec information |
| 4065 | if (codec_info.id != CodecId::Core::LC3) continue; |
| 4066 | // Combine those parameters into one list of Lc3Configuration |
| 4067 | auto& transport = |
| 4068 | codec_info.transport.get<CodecInfo::Transport::Tag::leAudio>(); |
| 4069 | for (int32_t samplingFrequencyHz : transport.samplingFrequencyHz) { |
| 4070 | for (int32_t frameDurationUs : transport.frameDurationUs) { |
| 4071 | for (int32_t octetsPerFrame : transport.bitdepth) { |
| 4072 | Lc3Configuration lc3_config = { |
| 4073 | .samplingFrequencyHz = samplingFrequencyHz, |
| 4074 | .frameDurationUs = frameDurationUs, |
| 4075 | .octetsPerFrame = octetsPerFrame, |
| 4076 | }; |
| 4077 | le_audio_codec_configs.push_back(lc3_config); |
| 4078 | } |
| 4079 | } |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | return le_audio_codec_configs; |
| 4084 | } |
| 4085 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 4086 | AudioContext GetAudioContext(int32_t bitmask) { |
| 4087 | AudioContext media_audio_context; |
| 4088 | media_audio_context.bitmask = bitmask; |
| 4089 | return media_audio_context; |
| 4090 | } |
| 4091 | |
| 4092 | std::optional<CodecSpecificConfigurationLtv> GetConfigurationLtv( |
| 4093 | const std::vector<CodecSpecificConfigurationLtv>& configurationLtvs, |
| 4094 | CodecSpecificConfigurationLtv::Tag tag) { |
| 4095 | for (const auto ltv : configurationLtvs) { |
| 4096 | if (ltv.getTag() == tag) { |
| 4097 | return ltv; |
| 4098 | } |
| 4099 | } |
| 4100 | return std::nullopt; |
| 4101 | } |
| 4102 | |
| 4103 | std::optional<CodecSpecificConfigurationLtv::SamplingFrequency> |
| 4104 | GetBisSampleFreq(const LeAudioBisConfiguration& bis_conf) { |
| 4105 | auto sample_freq_ltv = GetConfigurationLtv( |
| 4106 | bis_conf.codecConfiguration, |
| 4107 | CodecSpecificConfigurationLtv::Tag::samplingFrequency); |
| 4108 | if (!sample_freq_ltv) { |
| 4109 | return std::nullopt; |
| 4110 | } |
| 4111 | return (*sample_freq_ltv) |
| 4112 | .get<CodecSpecificConfigurationLtv::samplingFrequency>(); |
| 4113 | } |
| 4114 | |
| 4115 | std::vector<CodecSpecificConfigurationLtv::SamplingFrequency> |
| 4116 | GetSubgroupSampleFreqs( |
| 4117 | const LeAudioBroadcastSubgroupConfiguration& subgroup_conf) { |
| 4118 | std::vector<CodecSpecificConfigurationLtv::SamplingFrequency> result = {}; |
| 4119 | |
| 4120 | for (const auto& bis_conf : subgroup_conf.bisConfigurations) { |
| 4121 | auto sample_freq = GetBisSampleFreq(bis_conf.bisConfiguration); |
| 4122 | if (sample_freq) { |
| 4123 | result.push_back(*sample_freq); |
| 4124 | } |
| 4125 | } |
| 4126 | return result; |
| 4127 | } |
| 4128 | |
| 4129 | void VerifyBroadcastConfiguration( |
| 4130 | const LeAudioBroadcastConfigurationRequirement& requirements, |
| 4131 | const LeAudioBroadcastConfigurationSetting& configuration, |
| 4132 | std::vector<CodecSpecificConfigurationLtv::SamplingFrequency> |
| 4133 | expectedSampleFreqs = {}) { |
| 4134 | std::vector<CodecSpecificConfigurationLtv::SamplingFrequency> sampleFreqs = |
| 4135 | {}; |
| 4136 | |
| 4137 | int number_of_requested_bises = 0; |
| 4138 | for (const auto& subgroup_req : |
| 4139 | requirements.subgroupConfigurationRequirements) { |
| 4140 | number_of_requested_bises += subgroup_req.bisNumPerSubgroup; |
| 4141 | } |
| 4142 | |
| 4143 | if (!expectedSampleFreqs.empty()) { |
| 4144 | for (const auto& subgroup_conf : configuration.subgroupsConfigurations) { |
| 4145 | auto result = GetSubgroupSampleFreqs(subgroup_conf); |
| 4146 | sampleFreqs.insert(sampleFreqs.end(), result.begin(), result.end()); |
| 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | ASSERT_EQ(number_of_requested_bises, configuration.numBis); |
| 4151 | ASSERT_EQ(requirements.subgroupConfigurationRequirements.size(), |
| 4152 | configuration.subgroupsConfigurations.size()); |
| 4153 | |
| 4154 | if (expectedSampleFreqs.empty()) { |
| 4155 | return; |
| 4156 | } |
| 4157 | |
| 4158 | std::sort(sampleFreqs.begin(), sampleFreqs.end()); |
| 4159 | std::sort(expectedSampleFreqs.begin(), expectedSampleFreqs.end()); |
| 4160 | |
| 4161 | ASSERT_EQ(sampleFreqs, expectedSampleFreqs); |
| 4162 | } |
| 4163 | |
| 4164 | LeAudioDeviceCapabilities GetDefaultBroadcastSinkCapability() { |
| 4165 | // Create a capability |
| 4166 | LeAudioDeviceCapabilities capability; |
| 4167 | |
| 4168 | capability.codecId = CodecId::Core::LC3; |
| 4169 | |
| 4170 | auto pref_context_metadata = MetadataLtv::PreferredAudioContexts(); |
| 4171 | pref_context_metadata.values = |
| 4172 | GetAudioContext(AudioContext::MEDIA | AudioContext::CONVERSATIONAL | |
| 4173 | AudioContext::GAME); |
| 4174 | capability.metadata = {pref_context_metadata}; |
| 4175 | |
| 4176 | auto sampling_rate = |
| 4177 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies(); |
| 4178 | sampling_rate.bitmask = |
| 4179 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies::HZ48000 | |
| 4180 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies::HZ16000; |
| 4181 | auto frame_duration = |
| 4182 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations(); |
| 4183 | frame_duration.bitmask = |
| 4184 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations::US7500 | |
| 4185 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations::US10000; |
| 4186 | auto octets = CodecSpecificCapabilitiesLtv::SupportedOctetsPerCodecFrame(); |
| 4187 | octets.min = 0; |
| 4188 | octets.max = 120; |
| 4189 | auto frames = CodecSpecificCapabilitiesLtv::SupportedMaxCodecFramesPerSDU(); |
| 4190 | frames.value = 2; |
| 4191 | capability.codecSpecificCapabilities = {sampling_rate, frame_duration, |
| 4192 | octets, frames}; |
| 4193 | return capability; |
| 4194 | } |
| 4195 | |
| 4196 | LeAudioBroadcastConfigurationRequirement GetBroadcastRequirement( |
| 4197 | bool standard_quality, bool high_quality) { |
| 4198 | LeAudioBroadcastConfigurationRequirement requirement; |
| 4199 | |
| 4200 | AudioContext media_audio_context; |
| 4201 | media_audio_context.bitmask = AudioContext::MEDIA; |
| 4202 | |
| 4203 | LeAudioBroadcastSubgroupConfigurationRequirement |
| 4204 | standard_quality_requirement = { |
| 4205 | .audioContext = media_audio_context, |
| 4206 | .quality = IBluetoothAudioProvider::BroadcastQuality::STANDARD, |
| 4207 | .bisNumPerSubgroup = 2}; |
| 4208 | |
| 4209 | LeAudioBroadcastSubgroupConfigurationRequirement high_quality_requirement = |
| 4210 | {.audioContext = media_audio_context, |
| 4211 | .quality = IBluetoothAudioProvider::BroadcastQuality::HIGH, |
| 4212 | .bisNumPerSubgroup = 2}; |
| 4213 | |
| 4214 | if (standard_quality) { |
| 4215 | requirement.subgroupConfigurationRequirements.push_back( |
| 4216 | standard_quality_requirement); |
| 4217 | } |
| 4218 | |
| 4219 | if (high_quality) { |
| 4220 | requirement.subgroupConfigurationRequirements.push_back( |
| 4221 | high_quality_requirement); |
| 4222 | } |
| 4223 | return requirement; |
| 4224 | } |
| 4225 | |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4226 | std::vector<Lc3Configuration> GetBroadcastLc3SupportedList(bool supported) { |
| 4227 | std::vector<Lc3Configuration> le_audio_codec_configs; |
| 4228 | if (!supported) { |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 4229 | Lc3Configuration lc3_config{.pcmBitDepth = 0, .samplingFrequencyHz = 0}; |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4230 | le_audio_codec_configs.push_back(lc3_config); |
| 4231 | return le_audio_codec_configs; |
| 4232 | } |
| 4233 | |
| 4234 | // There might be more than one LeAudioCodecCapabilitiesSetting |
| 4235 | std::vector<Lc3Capabilities> lc3_capabilities; |
| 4236 | for (auto& capability : temp_provider_capabilities_) { |
| 4237 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 4238 | continue; |
| 4239 | } |
| 4240 | auto& le_audio_capability = |
| 4241 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 4242 | auto& broadcast_capability = le_audio_capability.broadcastCapability; |
| 4243 | if (broadcast_capability.codecType != CodecType::LC3) { |
| 4244 | continue; |
| 4245 | } |
| 4246 | auto& lc3_capability = broadcast_capability.leAudioCodecCapabilities.get< |
| 4247 | BroadcastCapability::LeAudioCodecCapabilities::lc3Capabilities>(); |
| 4248 | for (int idx = 0; idx < lc3_capability->size(); idx++) |
| 4249 | lc3_capabilities.push_back(*lc3_capability->at(idx)); |
| 4250 | } |
| 4251 | |
| 4252 | // Combine those parameters into one list of LeAudioCodecConfiguration |
| 4253 | // This seems horrible, but usually each Lc3Capability only contains a |
| 4254 | // single Lc3Configuration, which means every array has a length of 1. |
| 4255 | for (auto& lc3_capability : lc3_capabilities) { |
| 4256 | for (int32_t samplingFrequencyHz : lc3_capability.samplingFrequencyHz) { |
| 4257 | for (int32_t frameDurationUs : lc3_capability.frameDurationUs) { |
| 4258 | for (int32_t octetsPerFrame : lc3_capability.octetsPerFrame) { |
| 4259 | Lc3Configuration lc3_config = { |
| 4260 | .samplingFrequencyHz = samplingFrequencyHz, |
| 4261 | .frameDurationUs = frameDurationUs, |
| 4262 | .octetsPerFrame = octetsPerFrame, |
| 4263 | }; |
| 4264 | le_audio_codec_configs.push_back(lc3_config); |
| 4265 | } |
| 4266 | } |
| 4267 | } |
| 4268 | } |
| 4269 | |
| 4270 | return le_audio_codec_configs; |
| 4271 | } |
| 4272 | |
| 4273 | LeAudioCodecCapabilitiesSetting temp_le_audio_capabilities_; |
| 4274 | }; |
| 4275 | |
| 4276 | /** |
| 4277 | * Test whether each provider of type |
| 4278 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
| 4279 | * started and stopped |
| 4280 | */ |
| 4281 | TEST_P(BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 4282 | OpenLeAudioOutputHardwareProvider) {} |
| 4283 | |
| 4284 | /** |
| 4285 | * Test whether each provider of type |
| 4286 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 4287 | * started and stopped with broadcast hardware encoding config taken from |
| 4288 | * provider info |
| 4289 | */ |
| 4290 | TEST_P( |
| 4291 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 4292 | StartAndEndLeAudioBroadcastSessionWithPossibleUnicastConfigFromProviderInfo) { |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 4293 | if (GetProviderFactoryInterfaceVersion() < |
| 4294 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 4295 | GTEST_SKIP(); |
| 4296 | } |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 4297 | if (!IsBroadcastOffloadProviderInfoSupported()) { |
| 4298 | return; |
| 4299 | } |
| 4300 | |
| 4301 | auto lc3_codec_configs = GetBroadcastLc3SupportedListFromProviderInfo(); |
| 4302 | LeAudioBroadcastConfiguration le_audio_broadcast_config = { |
| 4303 | .codecType = CodecType::LC3, |
| 4304 | .streamMap = {}, |
| 4305 | }; |
| 4306 | |
| 4307 | for (auto& lc3_config : lc3_codec_configs) { |
| 4308 | le_audio_broadcast_config.streamMap.resize(1); |
| 4309 | le_audio_broadcast_config.streamMap[0] |
| 4310 | .leAudioCodecConfig.set<LeAudioCodecConfiguration::lc3Config>( |
| 4311 | lc3_config); |
| 4312 | le_audio_broadcast_config.streamMap[0].streamHandle = 0x0; |
| 4313 | le_audio_broadcast_config.streamMap[0].pcmStreamId = 0x0; |
| 4314 | le_audio_broadcast_config.streamMap[0].audioChannelAllocation = 0x1 << 0; |
| 4315 | |
| 4316 | DataMQDesc mq_desc; |
| 4317 | auto aidl_retval = audio_provider_->startSession( |
| 4318 | audio_port_, AudioConfiguration(le_audio_broadcast_config), |
| 4319 | latency_modes, &mq_desc); |
| 4320 | |
| 4321 | ASSERT_TRUE(aidl_retval.isOk()); |
| 4322 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4323 | } |
| 4324 | } |
| 4325 | |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 4326 | TEST_P(BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 4327 | GetEmptyBroadcastConfigurationEmptyCapability) { |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 4328 | if (GetProviderFactoryInterfaceVersion() < |
| 4329 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 4330 | GTEST_SKIP(); |
| 4331 | } |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 4332 | |
| 4333 | if (!IsBroadcastOffloadSupported()) { |
| 4334 | GTEST_SKIP(); |
| 4335 | } |
| 4336 | |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 4337 | std::vector<std::optional<LeAudioDeviceCapabilities>> empty_capability; |
| 4338 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement |
| 4339 | empty_requirement; |
| 4340 | |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 4341 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationSetting configuration; |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 4342 | |
| 4343 | // Check empty capability for source direction |
| 4344 | auto aidl_retval = audio_provider_->getLeAudioBroadcastConfiguration( |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 4345 | empty_capability, empty_requirement, &configuration); |
| 4346 | |
| 4347 | ASSERT_FALSE(aidl_retval.isOk()); |
| 4348 | } |
| 4349 | |
| 4350 | TEST_P(BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 4351 | GetBroadcastConfigurationEmptyCapability) { |
| 4352 | if (GetProviderFactoryInterfaceVersion() < |
| 4353 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 4354 | GTEST_SKIP(); |
| 4355 | } |
| 4356 | |
| 4357 | if (!IsBroadcastOffloadSupported()) { |
| 4358 | GTEST_SKIP(); |
| 4359 | } |
| 4360 | |
| 4361 | std::vector<std::optional<LeAudioDeviceCapabilities>> empty_capability; |
| 4362 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationSetting configuration; |
| 4363 | |
| 4364 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement |
| 4365 | one_subgroup_requirement = |
| 4366 | GetBroadcastRequirement(true /* standard*/, false /* high */); |
| 4367 | |
| 4368 | // Check empty capability for source direction |
| 4369 | auto aidl_retval = audio_provider_->getLeAudioBroadcastConfiguration( |
| 4370 | empty_capability, one_subgroup_requirement, &configuration); |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 4371 | |
| 4372 | ASSERT_TRUE(aidl_retval.isOk()); |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 4373 | ASSERT_NE(configuration.numBis, 0); |
| 4374 | ASSERT_FALSE(configuration.subgroupsConfigurations.empty()); |
| 4375 | VerifyBroadcastConfiguration(one_subgroup_requirement, configuration); |
| 4376 | |
| 4377 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement |
| 4378 | two_subgroup_requirement = |
| 4379 | GetBroadcastRequirement(true /* standard*/, true /* high */); |
| 4380 | |
| 4381 | // Check empty capability for source direction |
| 4382 | aidl_retval = audio_provider_->getLeAudioBroadcastConfiguration( |
| 4383 | empty_capability, two_subgroup_requirement, &configuration); |
| 4384 | |
| 4385 | ASSERT_TRUE(aidl_retval.isOk()); |
| 4386 | ASSERT_NE(configuration.numBis, 0); |
| 4387 | ASSERT_FALSE(configuration.subgroupsConfigurations.empty()); |
| 4388 | VerifyBroadcastConfiguration(two_subgroup_requirement, configuration); |
| 4389 | } |
| 4390 | |
| 4391 | TEST_P(BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 4392 | GetBroadcastConfigurationNonEmptyCapability) { |
| 4393 | if (GetProviderFactoryInterfaceVersion() < |
| 4394 | BluetoothAudioHalVersion::VERSION_AIDL_V4) { |
| 4395 | GTEST_SKIP(); |
| 4396 | } |
| 4397 | |
| 4398 | if (!IsBroadcastOffloadSupported()) { |
| 4399 | GTEST_SKIP(); |
| 4400 | } |
| 4401 | |
| 4402 | std::vector<std::optional<LeAudioDeviceCapabilities>> capability = { |
| 4403 | GetDefaultBroadcastSinkCapability()}; |
| 4404 | |
| 4405 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement |
| 4406 | requirement = |
| 4407 | GetBroadcastRequirement(true /* standard*/, true /* high */); |
| 4408 | |
| 4409 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationSetting configuration; |
| 4410 | |
| 4411 | // Check empty capability for source direction |
| 4412 | auto aidl_retval = audio_provider_->getLeAudioBroadcastConfiguration( |
| 4413 | capability, requirement, &configuration); |
| 4414 | |
| 4415 | ASSERT_TRUE(aidl_retval.isOk()); |
| 4416 | ASSERT_NE(configuration.numBis, 0); |
| 4417 | ASSERT_FALSE(configuration.subgroupsConfigurations.empty()); |
| 4418 | VerifyBroadcastConfiguration(requirement, configuration); |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
Bao Do | c36897d | 2023-12-06 01:27:54 +0000 | [diff] [blame] | 4421 | /** |
| 4422 | * Test whether each provider of type |
| 4423 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4424 | * started and stopped with broadcast hardware encoding config |
| 4425 | */ |
| 4426 | TEST_P(BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 4427 | StartAndEndLeAudioBroadcastSessionWithPossibleBroadcastConfig) { |
| 4428 | if (!IsBroadcastOffloadSupported()) { |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 4429 | GTEST_SKIP(); |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | auto lc3_codec_configs = GetBroadcastLc3SupportedList(true /* supported */); |
| 4433 | LeAudioBroadcastConfiguration le_audio_broadcast_config = { |
| 4434 | .codecType = CodecType::LC3, |
| 4435 | .streamMap = {}, |
| 4436 | }; |
| 4437 | |
| 4438 | for (auto& lc3_config : lc3_codec_configs) { |
Patty Huang | ac077ef | 2022-11-23 14:45:15 +0800 | [diff] [blame] | 4439 | le_audio_broadcast_config.streamMap.resize(1); |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4440 | le_audio_broadcast_config.streamMap[0] |
| 4441 | .leAudioCodecConfig.set<LeAudioCodecConfiguration::lc3Config>( |
| 4442 | lc3_config); |
Rongxuan Liu | c1aea32 | 2023-01-26 17:14:54 +0000 | [diff] [blame] | 4443 | le_audio_broadcast_config.streamMap[0].streamHandle = 0x0; |
| 4444 | le_audio_broadcast_config.streamMap[0].pcmStreamId = 0x0; |
| 4445 | le_audio_broadcast_config.streamMap[0].audioChannelAllocation = 0x1 << 0; |
| 4446 | |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4447 | DataMQDesc mq_desc; |
| 4448 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | 60d52e4 | 2022-02-16 12:19:12 -0800 | [diff] [blame] | 4449 | audio_port_, AudioConfiguration(le_audio_broadcast_config), |
| 4450 | latency_modes, &mq_desc); |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4451 | |
| 4452 | ASSERT_TRUE(aidl_retval.isOk()); |
| 4453 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | /** |
| 4458 | * Test whether each provider of type |
| 4459 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
| 4460 | * started and stopped with Broadcast hardware encoding config |
| 4461 | * |
| 4462 | * Disabled since offload codec checking is not ready |
| 4463 | */ |
| 4464 | TEST_P( |
| 4465 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 4466 | DISABLED_StartAndEndLeAudioBroadcastSessionWithInvalidAudioConfiguration) { |
| 4467 | if (!IsBroadcastOffloadSupported()) { |
Łukasz Rymanowski | 5a43cb9 | 2024-01-17 21:35:44 +0000 | [diff] [blame^] | 4468 | GTEST_SKIP(); |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | auto lc3_codec_configs = GetBroadcastLc3SupportedList(false /* supported */); |
| 4472 | LeAudioBroadcastConfiguration le_audio_broadcast_config = { |
| 4473 | .codecType = CodecType::LC3, |
| 4474 | .streamMap = {}, |
| 4475 | }; |
| 4476 | |
| 4477 | for (auto& lc3_config : lc3_codec_configs) { |
| 4478 | le_audio_broadcast_config.streamMap[0] |
| 4479 | .leAudioCodecConfig.set<LeAudioCodecConfiguration::lc3Config>( |
| 4480 | lc3_config); |
| 4481 | DataMQDesc mq_desc; |
| 4482 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | 60d52e4 | 2022-02-16 12:19:12 -0800 | [diff] [blame] | 4483 | audio_port_, AudioConfiguration(le_audio_broadcast_config), |
| 4484 | latency_modes, &mq_desc); |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4485 | |
| 4486 | // AIDL call should fail on invalid codec |
| 4487 | ASSERT_FALSE(aidl_retval.isOk()); |
| 4488 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4489 | } |
| 4490 | } |
| 4491 | |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4492 | /** |
| 4493 | * openProvider A2DP_SOFTWARE_DECODING_DATAPATH |
| 4494 | */ |
| 4495 | class BluetoothAudioProviderA2dpDecodingSoftwareAidl |
| 4496 | : public BluetoothAudioProviderFactoryAidl { |
| 4497 | public: |
| 4498 | virtual void SetUp() override { |
| 4499 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 4500 | GetProviderCapabilitiesHelper(SessionType::A2DP_SOFTWARE_DECODING_DATAPATH); |
| 4501 | OpenProviderHelper(SessionType::A2DP_SOFTWARE_DECODING_DATAPATH); |
| 4502 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 4503 | audio_provider_ != nullptr); |
| 4504 | } |
| 4505 | |
| 4506 | virtual void TearDown() override { |
| 4507 | audio_port_ = nullptr; |
| 4508 | audio_provider_ = nullptr; |
| 4509 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 4510 | } |
| 4511 | }; |
| 4512 | |
| 4513 | /** |
| 4514 | * Test whether we can open a provider of type |
| 4515 | */ |
| 4516 | TEST_P(BluetoothAudioProviderA2dpDecodingSoftwareAidl, |
| 4517 | OpenA2dpDecodingSoftwareProvider) {} |
| 4518 | |
| 4519 | /** |
| 4520 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 4521 | * SessionType::A2DP_SOFTWARE_DECODING_DATAPATH can be started and stopped |
| 4522 | * with different PCM config |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4523 | */ |
| 4524 | TEST_P(BluetoothAudioProviderA2dpDecodingSoftwareAidl, |
| 4525 | StartAndEndA2dpDecodingSoftwareSessionWithPossiblePcmConfig) { |
| 4526 | for (auto sample_rate : a2dp_sample_rates) { |
| 4527 | for (auto bits_per_sample : a2dp_bits_per_samples) { |
| 4528 | for (auto channel_mode : a2dp_channel_modes) { |
| 4529 | PcmConfiguration pcm_config{ |
| 4530 | .sampleRateHz = sample_rate, |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4531 | .channelMode = channel_mode, |
shihchienc | 3ab9f5e | 2022-09-23 08:18:05 +0000 | [diff] [blame] | 4532 | .bitsPerSample = bits_per_sample, |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4533 | }; |
| 4534 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 4535 | DataMQDesc mq_desc; |
| 4536 | auto aidl_retval = audio_provider_->startSession( |
| 4537 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 4538 | &mq_desc); |
| 4539 | DataMQ data_mq(mq_desc); |
| 4540 | |
| 4541 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 4542 | if (is_codec_config_valid) { |
| 4543 | EXPECT_TRUE(data_mq.isValid()); |
| 4544 | } |
| 4545 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4546 | } |
| 4547 | } |
| 4548 | } |
| 4549 | } |
| 4550 | |
| 4551 | /** |
| 4552 | * openProvider A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH |
| 4553 | */ |
| 4554 | class BluetoothAudioProviderA2dpDecodingHardwareAidl |
| 4555 | : public BluetoothAudioProviderFactoryAidl { |
| 4556 | public: |
| 4557 | virtual void SetUp() override { |
| 4558 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 4559 | GetProviderCapabilitiesHelper( |
| 4560 | SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
| 4561 | OpenProviderHelper(SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
| 4562 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 4563 | audio_provider_ != nullptr); |
| 4564 | } |
| 4565 | |
| 4566 | virtual void TearDown() override { |
| 4567 | audio_port_ = nullptr; |
| 4568 | audio_provider_ = nullptr; |
| 4569 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 4570 | } |
| 4571 | |
| 4572 | bool IsOffloadSupported() { return (temp_provider_capabilities_.size() > 0); } |
| 4573 | }; |
| 4574 | |
| 4575 | /** |
| 4576 | * Test whether we can open a provider of type |
| 4577 | */ |
| 4578 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 4579 | OpenA2dpDecodingHardwareProvider) {} |
| 4580 | |
| 4581 | /** |
| 4582 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 4583 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped |
| 4584 | * with SBC hardware encoding config |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4585 | */ |
| 4586 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 4587 | StartAndEndA2dpSbcDecodingHardwareSession) { |
| 4588 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 4589 | GTEST_SKIP(); |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | CodecConfiguration codec_config = { |
| 4593 | .codecType = CodecType::SBC, |
| 4594 | .encodedAudioBitrate = 328000, |
| 4595 | .peerMtu = 1005, |
| 4596 | .isScmstEnabled = false, |
| 4597 | }; |
| 4598 | auto sbc_codec_specifics = GetSbcCodecSpecificSupportedList(true); |
| 4599 | |
| 4600 | for (auto& codec_specific : sbc_codec_specifics) { |
| 4601 | copy_codec_specific(codec_config.config, codec_specific); |
| 4602 | DataMQDesc mq_desc; |
| 4603 | auto aidl_retval = audio_provider_->startSession( |
| 4604 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
| 4605 | |
| 4606 | ASSERT_TRUE(aidl_retval.isOk()); |
| 4607 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4608 | } |
| 4609 | } |
| 4610 | |
| 4611 | /** |
| 4612 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 4613 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped |
| 4614 | * with AAC hardware encoding config |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4615 | */ |
| 4616 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 4617 | StartAndEndA2dpAacDecodingHardwareSession) { |
| 4618 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 4619 | GTEST_SKIP(); |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | CodecConfiguration codec_config = { |
| 4623 | .codecType = CodecType::AAC, |
| 4624 | .encodedAudioBitrate = 320000, |
| 4625 | .peerMtu = 1005, |
| 4626 | .isScmstEnabled = false, |
| 4627 | }; |
| 4628 | auto aac_codec_specifics = GetAacCodecSpecificSupportedList(true); |
| 4629 | |
| 4630 | for (auto& codec_specific : aac_codec_specifics) { |
| 4631 | copy_codec_specific(codec_config.config, codec_specific); |
| 4632 | DataMQDesc mq_desc; |
| 4633 | auto aidl_retval = audio_provider_->startSession( |
| 4634 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
| 4635 | |
| 4636 | ASSERT_TRUE(aidl_retval.isOk()); |
| 4637 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4638 | } |
| 4639 | } |
| 4640 | |
| 4641 | /** |
| 4642 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 4643 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped |
| 4644 | * with LDAC hardware encoding config |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4645 | */ |
| 4646 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 4647 | StartAndEndA2dpLdacDecodingHardwareSession) { |
| 4648 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 4649 | GTEST_SKIP(); |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | CodecConfiguration codec_config = { |
| 4653 | .codecType = CodecType::LDAC, |
| 4654 | .encodedAudioBitrate = 990000, |
| 4655 | .peerMtu = 1005, |
| 4656 | .isScmstEnabled = false, |
| 4657 | }; |
| 4658 | auto ldac_codec_specifics = GetLdacCodecSpecificSupportedList(true); |
| 4659 | |
| 4660 | for (auto& codec_specific : ldac_codec_specifics) { |
| 4661 | copy_codec_specific(codec_config.config, codec_specific); |
| 4662 | DataMQDesc mq_desc; |
| 4663 | auto aidl_retval = audio_provider_->startSession( |
| 4664 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
| 4665 | |
| 4666 | ASSERT_TRUE(aidl_retval.isOk()); |
| 4667 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4668 | } |
| 4669 | } |
| 4670 | |
| 4671 | /** |
| 4672 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 4673 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped |
| 4674 | * with Opus hardware encoding config |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4675 | */ |
| 4676 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 4677 | StartAndEndA2dpOpusDecodingHardwareSession) { |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4678 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 4679 | GTEST_SKIP(); |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4680 | } |
| 4681 | |
| 4682 | CodecConfiguration codec_config = { |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 4683 | .codecType = CodecType::OPUS, |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4684 | .encodedAudioBitrate = 990000, |
| 4685 | .peerMtu = 1005, |
| 4686 | .isScmstEnabled = false, |
| 4687 | }; |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 4688 | auto opus_codec_specifics = GetOpusCodecSpecificSupportedList(true); |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4689 | |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 4690 | for (auto& codec_specific : opus_codec_specifics) { |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4691 | copy_codec_specific(codec_config.config, codec_specific); |
| 4692 | DataMQDesc mq_desc; |
| 4693 | auto aidl_retval = audio_provider_->startSession( |
| 4694 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
| 4695 | |
| 4696 | ASSERT_TRUE(aidl_retval.isOk()); |
| 4697 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4698 | } |
| 4699 | } |
| 4700 | |
| 4701 | /** |
| 4702 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 4703 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped |
| 4704 | * with AptX hardware encoding config |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4705 | */ |
| 4706 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 4707 | StartAndEndA2dpAptxDecodingHardwareSession) { |
| 4708 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 4709 | GTEST_SKIP(); |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | for (auto codec_type : {CodecType::APTX, CodecType::APTX_HD}) { |
| 4713 | CodecConfiguration codec_config = { |
| 4714 | .codecType = codec_type, |
| 4715 | .encodedAudioBitrate = |
| 4716 | (codec_type == CodecType::APTX ? 352000 : 576000), |
| 4717 | .peerMtu = 1005, |
| 4718 | .isScmstEnabled = false, |
| 4719 | }; |
| 4720 | |
| 4721 | auto aptx_codec_specifics = GetAptxCodecSpecificSupportedList( |
| 4722 | (codec_type == CodecType::APTX_HD ? true : false), true); |
| 4723 | |
| 4724 | for (auto& codec_specific : aptx_codec_specifics) { |
| 4725 | copy_codec_specific(codec_config.config, codec_specific); |
| 4726 | DataMQDesc mq_desc; |
| 4727 | auto aidl_retval = audio_provider_->startSession( |
| 4728 | audio_port_, AudioConfiguration(codec_config), latency_modes, |
| 4729 | &mq_desc); |
| 4730 | |
| 4731 | ASSERT_TRUE(aidl_retval.isOk()); |
| 4732 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4733 | } |
| 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | /** |
| 4738 | * Test whether each provider of type |
Bao Do | b487a85 | 2023-12-25 10:12:09 +0800 | [diff] [blame] | 4739 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped |
| 4740 | * with an invalid codec config |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4741 | */ |
| 4742 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 4743 | StartAndEndA2dpDecodingHardwareSessionInvalidCodecConfig) { |
| 4744 | if (!IsOffloadSupported()) { |
Jakub Tyszkowski | 334bf18 | 2024-01-08 13:43:27 +0000 | [diff] [blame] | 4745 | GTEST_SKIP(); |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4746 | } |
| 4747 | ASSERT_NE(audio_provider_, nullptr); |
| 4748 | |
| 4749 | std::vector<CodecConfiguration::CodecSpecific> codec_specifics; |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 4750 | for (auto codec_type : ndk::enum_range<CodecType>()) { |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4751 | switch (codec_type) { |
| 4752 | case CodecType::SBC: |
| 4753 | codec_specifics = GetSbcCodecSpecificSupportedList(false); |
| 4754 | break; |
| 4755 | case CodecType::AAC: |
| 4756 | codec_specifics = GetAacCodecSpecificSupportedList(false); |
| 4757 | break; |
| 4758 | case CodecType::LDAC: |
| 4759 | codec_specifics = GetLdacCodecSpecificSupportedList(false); |
| 4760 | break; |
| 4761 | case CodecType::APTX: |
| 4762 | codec_specifics = GetAptxCodecSpecificSupportedList(false, false); |
| 4763 | break; |
| 4764 | case CodecType::APTX_HD: |
| 4765 | codec_specifics = GetAptxCodecSpecificSupportedList(true, false); |
| 4766 | break; |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 4767 | case CodecType::OPUS: |
| 4768 | codec_specifics = GetOpusCodecSpecificSupportedList(false); |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4769 | continue; |
| 4770 | case CodecType::APTX_ADAPTIVE: |
Sagar Verma | 62df910 | 2022-12-07 17:56:04 +0530 | [diff] [blame] | 4771 | case CodecType::APTX_ADAPTIVE_LE: |
| 4772 | case CodecType::APTX_ADAPTIVE_LEX: |
Omer Osman | a2587da | 2022-05-01 03:54:11 +0000 | [diff] [blame] | 4773 | case CodecType::LC3: |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4774 | case CodecType::VENDOR: |
| 4775 | case CodecType::UNKNOWN: |
| 4776 | codec_specifics.clear(); |
| 4777 | break; |
| 4778 | } |
| 4779 | if (codec_specifics.empty()) { |
| 4780 | continue; |
| 4781 | } |
| 4782 | |
| 4783 | CodecConfiguration codec_config = { |
| 4784 | .codecType = codec_type, |
| 4785 | .encodedAudioBitrate = 328000, |
| 4786 | .peerMtu = 1005, |
| 4787 | .isScmstEnabled = false, |
| 4788 | }; |
| 4789 | for (auto codec_specific : codec_specifics) { |
| 4790 | copy_codec_specific(codec_config.config, codec_specific); |
| 4791 | DataMQDesc mq_desc; |
| 4792 | auto aidl_retval = audio_provider_->startSession( |
| 4793 | audio_port_, AudioConfiguration(codec_config), latency_modes, |
| 4794 | &mq_desc); |
| 4795 | |
| 4796 | // AIDL call should fail on invalid codec |
| 4797 | ASSERT_FALSE(aidl_retval.isOk()); |
| 4798 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 4799 | } |
| 4800 | } |
| 4801 | } |
| 4802 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 4803 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4804 | BluetoothAudioProviderFactoryAidl); |
| 4805 | INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAudioProviderFactoryAidl, |
| 4806 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4807 | IBluetoothAudioProviderFactory::descriptor)), |
| 4808 | android::PrintInstanceNameToString); |
| 4809 | |
Antoine SOULIER | 33c4e5a | 2023-09-28 21:59:19 +0000 | [diff] [blame] | 4810 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BluetoothAudioProviderAidl); |
| 4811 | INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAudioProviderAidl, |
| 4812 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4813 | IBluetoothAudioProviderFactory::descriptor)), |
| 4814 | android::PrintInstanceNameToString); |
| 4815 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 4816 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4817 | BluetoothAudioProviderA2dpEncodingSoftwareAidl); |
| 4818 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4819 | BluetoothAudioProviderA2dpEncodingSoftwareAidl, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 4820 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4821 | IBluetoothAudioProviderFactory::descriptor)), |
| 4822 | android::PrintInstanceNameToString); |
| 4823 | |
| 4824 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4825 | BluetoothAudioProviderA2dpEncodingHardwareAidl); |
| 4826 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4827 | BluetoothAudioProviderA2dpEncodingHardwareAidl, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 4828 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4829 | IBluetoothAudioProviderFactory::descriptor)), |
| 4830 | android::PrintInstanceNameToString); |
| 4831 | |
| 4832 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4833 | BluetoothAudioProviderHearingAidSoftwareAidl); |
| 4834 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4835 | BluetoothAudioProviderHearingAidSoftwareAidl, |
| 4836 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4837 | IBluetoothAudioProviderFactory::descriptor)), |
| 4838 | android::PrintInstanceNameToString); |
| 4839 | |
| 4840 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4841 | BluetoothAudioProviderLeAudioOutputSoftwareAidl); |
| 4842 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4843 | BluetoothAudioProviderLeAudioOutputSoftwareAidl, |
| 4844 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4845 | IBluetoothAudioProviderFactory::descriptor)), |
| 4846 | android::PrintInstanceNameToString); |
| 4847 | |
| 4848 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4849 | BluetoothAudioProviderLeAudioInputSoftwareAidl); |
| 4850 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4851 | BluetoothAudioProviderLeAudioInputSoftwareAidl, |
| 4852 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4853 | IBluetoothAudioProviderFactory::descriptor)), |
| 4854 | android::PrintInstanceNameToString); |
| 4855 | |
| 4856 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4857 | BluetoothAudioProviderLeAudioOutputHardwareAidl); |
| 4858 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4859 | BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 4860 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4861 | IBluetoothAudioProviderFactory::descriptor)), |
| 4862 | android::PrintInstanceNameToString); |
| 4863 | |
| 4864 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4865 | BluetoothAudioProviderLeAudioInputHardwareAidl); |
| 4866 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4867 | BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 4868 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4869 | IBluetoothAudioProviderFactory::descriptor)), |
| 4870 | android::PrintInstanceNameToString); |
| 4871 | |
| 4872 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4873 | BluetoothAudioProviderLeAudioBroadcastSoftwareAidl); |
| 4874 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4875 | BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, |
| 4876 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4877 | IBluetoothAudioProviderFactory::descriptor)), |
| 4878 | android::PrintInstanceNameToString); |
| 4879 | |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 4880 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4881 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl); |
| 4882 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4883 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 4884 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4885 | IBluetoothAudioProviderFactory::descriptor)), |
| 4886 | android::PrintInstanceNameToString); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 4887 | |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 4888 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4889 | BluetoothAudioProviderA2dpDecodingSoftwareAidl); |
| 4890 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4891 | BluetoothAudioProviderA2dpDecodingSoftwareAidl, |
| 4892 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4893 | IBluetoothAudioProviderFactory::descriptor)), |
| 4894 | android::PrintInstanceNameToString); |
| 4895 | |
| 4896 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4897 | BluetoothAudioProviderA2dpDecodingHardwareAidl); |
| 4898 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4899 | BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 4900 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4901 | IBluetoothAudioProviderFactory::descriptor)), |
| 4902 | android::PrintInstanceNameToString); |
| 4903 | |
Bao Do | 7239943 | 2023-11-09 08:13:05 +0000 | [diff] [blame] | 4904 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4905 | BluetoothAudioProviderHfpHardwareAidl); |
| 4906 | INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAudioProviderHfpHardwareAidl, |
| 4907 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4908 | IBluetoothAudioProviderFactory::descriptor)), |
| 4909 | android::PrintInstanceNameToString); |
| 4910 | |
| 4911 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4912 | BluetoothAudioProviderHfpSoftwareDecodingAidl); |
| 4913 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4914 | BluetoothAudioProviderHfpSoftwareDecodingAidl, |
| 4915 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4916 | IBluetoothAudioProviderFactory::descriptor)), |
| 4917 | android::PrintInstanceNameToString); |
| 4918 | |
| 4919 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 4920 | BluetoothAudioProviderHfpSoftwareEncodingAidl); |
| 4921 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 4922 | BluetoothAudioProviderHfpSoftwareEncodingAidl, |
| 4923 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 4924 | IBluetoothAudioProviderFactory::descriptor)), |
| 4925 | android::PrintInstanceNameToString); |
| 4926 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 4927 | int main(int argc, char** argv) { |
| 4928 | ::testing::InitGoogleTest(&argc, argv); |
| 4929 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 4930 | ABinderProcess_startThreadPool(); |
| 4931 | return RUN_ALL_TESTS(); |
| 4932 | } |