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> |
| 26 | #include <fmq/AidlMessageQueue.h> |
| 27 | |
| 28 | #include <cstdint> |
| 29 | #include <future> |
| 30 | #include <unordered_set> |
| 31 | #include <vector> |
| 32 | |
| 33 | using aidl::android::hardware::audio::common::SinkMetadata; |
| 34 | using aidl::android::hardware::audio::common::SourceMetadata; |
| 35 | using aidl::android::hardware::bluetooth::audio::AacCapabilities; |
| 36 | using aidl::android::hardware::bluetooth::audio::AacConfiguration; |
| 37 | using aidl::android::hardware::bluetooth::audio::AptxCapabilities; |
| 38 | using aidl::android::hardware::bluetooth::audio::AptxConfiguration; |
| 39 | using aidl::android::hardware::bluetooth::audio::AudioCapabilities; |
| 40 | using aidl::android::hardware::bluetooth::audio::AudioConfiguration; |
| 41 | using aidl::android::hardware::bluetooth::audio::BnBluetoothAudioPort; |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 42 | using aidl::android::hardware::bluetooth::audio::BroadcastCapability; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 43 | using aidl::android::hardware::bluetooth::audio::ChannelMode; |
| 44 | using aidl::android::hardware::bluetooth::audio::CodecCapabilities; |
| 45 | using aidl::android::hardware::bluetooth::audio::CodecConfiguration; |
| 46 | using aidl::android::hardware::bluetooth::audio::CodecType; |
| 47 | using aidl::android::hardware::bluetooth::audio::IBluetoothAudioPort; |
| 48 | using aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider; |
| 49 | using aidl::android::hardware::bluetooth::audio::IBluetoothAudioProviderFactory; |
| 50 | using aidl::android::hardware::bluetooth::audio::LatencyMode; |
| 51 | using aidl::android::hardware::bluetooth::audio::Lc3Capabilities; |
| 52 | using aidl::android::hardware::bluetooth::audio::Lc3Configuration; |
| 53 | using aidl::android::hardware::bluetooth::audio::LdacCapabilities; |
| 54 | using aidl::android::hardware::bluetooth::audio::LdacConfiguration; |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 55 | using aidl::android::hardware::bluetooth::audio::LeAudioBroadcastConfiguration; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 56 | using aidl::android::hardware::bluetooth::audio:: |
| 57 | LeAudioCodecCapabilitiesSetting; |
| 58 | using aidl::android::hardware::bluetooth::audio::LeAudioCodecConfiguration; |
| 59 | using aidl::android::hardware::bluetooth::audio::LeAudioConfiguration; |
| 60 | using aidl::android::hardware::bluetooth::audio::PcmConfiguration; |
| 61 | using aidl::android::hardware::bluetooth::audio::PresentationPosition; |
| 62 | using aidl::android::hardware::bluetooth::audio::SbcAllocMethod; |
| 63 | using aidl::android::hardware::bluetooth::audio::SbcCapabilities; |
| 64 | using aidl::android::hardware::bluetooth::audio::SbcChannelMode; |
| 65 | using aidl::android::hardware::bluetooth::audio::SbcConfiguration; |
| 66 | using aidl::android::hardware::bluetooth::audio::SessionType; |
| 67 | using aidl::android::hardware::bluetooth::audio::UnicastCapability; |
| 68 | using aidl::android::hardware::common::fmq::MQDescriptor; |
| 69 | using aidl::android::hardware::common::fmq::SynchronizedReadWrite; |
| 70 | using android::AidlMessageQueue; |
| 71 | using android::ProcessState; |
| 72 | using android::String16; |
| 73 | using ndk::ScopedAStatus; |
| 74 | using ndk::SpAIBinder; |
| 75 | |
| 76 | using MqDataType = int8_t; |
| 77 | using MqDataMode = SynchronizedReadWrite; |
| 78 | using DataMQ = AidlMessageQueue<MqDataType, MqDataMode>; |
| 79 | using DataMQDesc = MQDescriptor<MqDataType, MqDataMode>; |
| 80 | |
| 81 | // Constants |
| 82 | |
| 83 | static constexpr int32_t a2dp_sample_rates[] = {0, 44100, 48000, 88200, 96000}; |
| 84 | static constexpr int8_t a2dp_bits_per_samples[] = {0, 16, 24, 32}; |
| 85 | static constexpr ChannelMode a2dp_channel_modes[] = { |
| 86 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 87 | static constexpr CodecType a2dp_codec_types[] = { |
| 88 | CodecType::UNKNOWN, CodecType::SBC, CodecType::AAC, |
| 89 | CodecType::APTX, CodecType::APTX_HD, CodecType::LDAC, |
| 90 | CodecType::LC3, CodecType::APTX_ADAPTIVE}; |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 91 | static std::vector<LatencyMode> latency_modes = {LatencyMode::FREE}; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 92 | // Helpers |
| 93 | |
| 94 | template <typename T> |
| 95 | struct identity { |
| 96 | typedef T type; |
| 97 | }; |
| 98 | |
| 99 | template <class T> |
| 100 | bool contained_in_vector(const std::vector<T>& vector, |
| 101 | const typename identity<T>::type& target) { |
| 102 | return std::find(vector.begin(), vector.end(), target) != vector.end(); |
| 103 | } |
| 104 | |
| 105 | void copy_codec_specific(CodecConfiguration::CodecSpecific& dst, |
| 106 | const CodecConfiguration::CodecSpecific& src) { |
| 107 | switch (src.getTag()) { |
| 108 | case CodecConfiguration::CodecSpecific::sbcConfig: |
| 109 | dst.set<CodecConfiguration::CodecSpecific::sbcConfig>( |
| 110 | src.get<CodecConfiguration::CodecSpecific::sbcConfig>()); |
| 111 | break; |
| 112 | case CodecConfiguration::CodecSpecific::aacConfig: |
| 113 | dst.set<CodecConfiguration::CodecSpecific::aacConfig>( |
| 114 | src.get<CodecConfiguration::CodecSpecific::aacConfig>()); |
| 115 | break; |
| 116 | case CodecConfiguration::CodecSpecific::ldacConfig: |
| 117 | dst.set<CodecConfiguration::CodecSpecific::ldacConfig>( |
| 118 | src.get<CodecConfiguration::CodecSpecific::ldacConfig>()); |
| 119 | break; |
| 120 | case CodecConfiguration::CodecSpecific::aptxConfig: |
| 121 | dst.set<CodecConfiguration::CodecSpecific::aptxConfig>( |
| 122 | src.get<CodecConfiguration::CodecSpecific::aptxConfig>()); |
| 123 | break; |
| 124 | case CodecConfiguration::CodecSpecific::lc3Config: |
| 125 | dst.set<CodecConfiguration::CodecSpecific::lc3Config>( |
| 126 | src.get<CodecConfiguration::CodecSpecific::lc3Config>()); |
| 127 | break; |
| 128 | case CodecConfiguration::CodecSpecific::aptxAdaptiveConfig: |
| 129 | dst.set<CodecConfiguration::CodecSpecific::aptxAdaptiveConfig>( |
| 130 | src.get<CodecConfiguration::CodecSpecific::aptxAdaptiveConfig>()); |
| 131 | break; |
| 132 | default: |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | class BluetoothAudioPort : public BnBluetoothAudioPort { |
| 138 | public: |
| 139 | BluetoothAudioPort() {} |
| 140 | |
Chen Chen | 0a68a92 | 2022-02-15 18:43:26 -0800 | [diff] [blame] | 141 | ndk::ScopedAStatus startStream(bool) { return ScopedAStatus::ok(); } |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 142 | |
| 143 | ndk::ScopedAStatus suspendStream() { return ScopedAStatus::ok(); } |
| 144 | |
| 145 | ndk::ScopedAStatus stopStream() { return ScopedAStatus::ok(); } |
| 146 | |
| 147 | ndk::ScopedAStatus getPresentationPosition(PresentationPosition*) { |
| 148 | return ScopedAStatus::ok(); |
| 149 | } |
| 150 | |
| 151 | ndk::ScopedAStatus updateSourceMetadata(const SourceMetadata&) { |
| 152 | return ScopedAStatus::ok(); |
| 153 | } |
| 154 | |
| 155 | ndk::ScopedAStatus updateSinkMetadata(const SinkMetadata&) { |
| 156 | return ScopedAStatus::ok(); |
| 157 | } |
| 158 | |
| 159 | ndk::ScopedAStatus setLatencyMode(const LatencyMode) { |
| 160 | return ScopedAStatus::ok(); |
| 161 | } |
| 162 | |
| 163 | ndk::ScopedAStatus setCodecType(const CodecType) { |
| 164 | return ScopedAStatus::ok(); |
| 165 | } |
| 166 | |
| 167 | protected: |
| 168 | virtual ~BluetoothAudioPort() = default; |
| 169 | }; |
| 170 | |
| 171 | class BluetoothAudioProviderFactoryAidl |
| 172 | : public testing::TestWithParam<std::string> { |
| 173 | public: |
| 174 | virtual void SetUp() override { |
| 175 | provider_factory_ = IBluetoothAudioProviderFactory::fromBinder( |
| 176 | SpAIBinder(AServiceManager_getService(GetParam().c_str()))); |
| 177 | audio_provider_ = nullptr; |
| 178 | ASSERT_NE(provider_factory_, nullptr); |
| 179 | } |
| 180 | |
| 181 | virtual void TearDown() override { provider_factory_ = nullptr; } |
| 182 | |
| 183 | void GetProviderCapabilitiesHelper(const SessionType& session_type) { |
| 184 | temp_provider_capabilities_.clear(); |
| 185 | auto aidl_retval = provider_factory_->getProviderCapabilities( |
| 186 | session_type, &temp_provider_capabilities_); |
| 187 | // AIDL calls should not be failed and callback has to be executed |
| 188 | ASSERT_TRUE(aidl_retval.isOk()); |
| 189 | switch (session_type) { |
| 190 | case SessionType::UNKNOWN: { |
| 191 | ASSERT_TRUE(temp_provider_capabilities_.empty()); |
| 192 | } break; |
| 193 | case SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH: |
| 194 | case SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH: |
| 195 | case SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH: |
| 196 | case SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH: |
| 197 | case SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH: { |
| 198 | // All software paths are mandatory and must have exact 1 |
| 199 | // "PcmParameters" |
| 200 | ASSERT_EQ(temp_provider_capabilities_.size(), 1); |
| 201 | ASSERT_EQ(temp_provider_capabilities_[0].getTag(), |
| 202 | AudioCapabilities::pcmCapabilities); |
| 203 | } break; |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 204 | case SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH: |
| 205 | case SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH: { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 206 | std::unordered_set<CodecType> codec_types; |
| 207 | // empty capability means offload is unsupported |
| 208 | for (auto& audio_capability : temp_provider_capabilities_) { |
| 209 | ASSERT_EQ(audio_capability.getTag(), |
| 210 | AudioCapabilities::a2dpCapabilities); |
| 211 | const auto& codec_capabilities = |
| 212 | audio_capability.get<AudioCapabilities::a2dpCapabilities>(); |
| 213 | // Every codec can present once at most |
| 214 | ASSERT_EQ(codec_types.count(codec_capabilities.codecType), 0); |
| 215 | switch (codec_capabilities.codecType) { |
| 216 | case CodecType::SBC: |
| 217 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 218 | CodecCapabilities::Capabilities::sbcCapabilities); |
| 219 | break; |
| 220 | case CodecType::AAC: |
| 221 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 222 | CodecCapabilities::Capabilities::aacCapabilities); |
| 223 | break; |
| 224 | case CodecType::APTX: |
| 225 | case CodecType::APTX_HD: |
| 226 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 227 | CodecCapabilities::Capabilities::aptxCapabilities); |
| 228 | break; |
| 229 | case CodecType::LDAC: |
| 230 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 231 | CodecCapabilities::Capabilities::ldacCapabilities); |
| 232 | break; |
| 233 | case CodecType::LC3: |
| 234 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 235 | CodecCapabilities::Capabilities::lc3Capabilities); |
| 236 | break; |
| 237 | case CodecType::APTX_ADAPTIVE: |
| 238 | case CodecType::VENDOR: |
| 239 | case CodecType::UNKNOWN: |
| 240 | break; |
| 241 | } |
| 242 | codec_types.insert(codec_capabilities.codecType); |
| 243 | } |
| 244 | } break; |
| 245 | case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH: |
| 246 | case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH: |
| 247 | case SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH: { |
| 248 | ASSERT_FALSE(temp_provider_capabilities_.empty()); |
| 249 | for (auto audio_capability : temp_provider_capabilities_) { |
| 250 | ASSERT_EQ(audio_capability.getTag(), |
| 251 | AudioCapabilities::leAudioCapabilities); |
| 252 | } |
| 253 | } break; |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 254 | case SessionType::A2DP_SOFTWARE_DECODING_DATAPATH: { |
| 255 | if (!temp_provider_capabilities_.empty()) { |
| 256 | ASSERT_EQ(temp_provider_capabilities_.size(), 1); |
| 257 | ASSERT_EQ(temp_provider_capabilities_[0].getTag(), |
| 258 | AudioCapabilities::pcmCapabilities); |
| 259 | } |
| 260 | } break; |
| 261 | default: { |
| 262 | ASSERT_TRUE(temp_provider_capabilities_.empty()); |
| 263 | } |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | /*** |
| 268 | * This helps to open the specified provider and check the openProvider() |
| 269 | * has corruct return values. BUT, to keep it simple, it does not consider |
| 270 | * the capability, and please do so at the SetUp of each session's test. |
| 271 | ***/ |
| 272 | void OpenProviderHelper(const SessionType& session_type) { |
| 273 | auto aidl_retval = |
| 274 | provider_factory_->openProvider(session_type, &audio_provider_); |
| 275 | if (aidl_retval.isOk()) { |
| 276 | ASSERT_NE(session_type, SessionType::UNKNOWN); |
| 277 | ASSERT_NE(audio_provider_, nullptr); |
| 278 | audio_port_ = ndk::SharedRefBase::make<BluetoothAudioPort>(); |
| 279 | } else { |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 280 | // optional session type |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 281 | ASSERT_TRUE( |
| 282 | session_type == SessionType::UNKNOWN || |
| 283 | session_type == |
| 284 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH || |
| 285 | session_type == |
| 286 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH || |
| 287 | session_type == |
| 288 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH || |
| 289 | session_type == |
| 290 | SessionType:: |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 291 | LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH || |
| 292 | session_type == |
| 293 | SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH || |
| 294 | session_type == SessionType::A2DP_SOFTWARE_DECODING_DATAPATH); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 295 | ASSERT_EQ(audio_provider_, nullptr); |
| 296 | } |
| 297 | } |
| 298 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 299 | void GetA2dpOffloadCapabilityHelper(const CodecType& codec_type) { |
| 300 | temp_codec_capabilities_ = nullptr; |
Josh Wu | 4d2938f | 2022-02-15 09:21:10 -0800 | [diff] [blame] | 301 | for (auto& codec_capability : temp_provider_capabilities_) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 302 | auto& a2dp_capabilities = |
| 303 | codec_capability.get<AudioCapabilities::a2dpCapabilities>(); |
| 304 | if (a2dp_capabilities.codecType != codec_type) { |
| 305 | continue; |
| 306 | } |
| 307 | temp_codec_capabilities_ = &a2dp_capabilities; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | std::vector<CodecConfiguration::CodecSpecific> |
| 312 | GetSbcCodecSpecificSupportedList(bool supported) { |
| 313 | std::vector<CodecConfiguration::CodecSpecific> sbc_codec_specifics; |
| 314 | if (!supported) { |
| 315 | SbcConfiguration sbc_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 316 | sbc_codec_specifics.push_back( |
| 317 | CodecConfiguration::CodecSpecific(sbc_config)); |
| 318 | return sbc_codec_specifics; |
| 319 | } |
| 320 | GetA2dpOffloadCapabilityHelper(CodecType::SBC); |
| 321 | if (temp_codec_capabilities_ == nullptr || |
| 322 | temp_codec_capabilities_->codecType != CodecType::SBC) { |
| 323 | return sbc_codec_specifics; |
| 324 | } |
| 325 | // parse the capability |
| 326 | auto& sbc_capability = |
| 327 | temp_codec_capabilities_->capabilities |
| 328 | .get<CodecCapabilities::Capabilities::sbcCapabilities>(); |
| 329 | if (sbc_capability.minBitpool > sbc_capability.maxBitpool) { |
| 330 | return sbc_codec_specifics; |
| 331 | } |
| 332 | |
| 333 | // combine those parameters into one list of |
| 334 | // CodecConfiguration::CodecSpecific |
| 335 | for (int32_t sample_rate : sbc_capability.sampleRateHz) { |
| 336 | for (int8_t block_length : sbc_capability.blockLength) { |
| 337 | for (int8_t num_subbands : sbc_capability.numSubbands) { |
| 338 | for (int8_t bits_per_sample : sbc_capability.bitsPerSample) { |
| 339 | for (auto channel_mode : sbc_capability.channelMode) { |
| 340 | for (auto alloc_method : sbc_capability.allocMethod) { |
| 341 | SbcConfiguration sbc_data = { |
| 342 | .sampleRateHz = sample_rate, |
| 343 | .channelMode = channel_mode, |
| 344 | .blockLength = block_length, |
| 345 | .numSubbands = num_subbands, |
| 346 | .allocMethod = alloc_method, |
| 347 | .bitsPerSample = bits_per_sample, |
| 348 | .minBitpool = sbc_capability.minBitpool, |
| 349 | .maxBitpool = sbc_capability.maxBitpool}; |
| 350 | sbc_codec_specifics.push_back( |
| 351 | CodecConfiguration::CodecSpecific(sbc_data)); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | return sbc_codec_specifics; |
| 359 | } |
| 360 | |
| 361 | std::vector<CodecConfiguration::CodecSpecific> |
| 362 | GetAacCodecSpecificSupportedList(bool supported) { |
| 363 | std::vector<CodecConfiguration::CodecSpecific> aac_codec_specifics; |
| 364 | if (!supported) { |
| 365 | AacConfiguration aac_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 366 | aac_codec_specifics.push_back( |
| 367 | CodecConfiguration::CodecSpecific(aac_config)); |
| 368 | return aac_codec_specifics; |
| 369 | } |
| 370 | GetA2dpOffloadCapabilityHelper(CodecType::AAC); |
| 371 | if (temp_codec_capabilities_ == nullptr || |
| 372 | temp_codec_capabilities_->codecType != CodecType::AAC) { |
| 373 | return aac_codec_specifics; |
| 374 | } |
| 375 | // parse the capability |
| 376 | auto& aac_capability = |
| 377 | temp_codec_capabilities_->capabilities |
| 378 | .get<CodecCapabilities::Capabilities::aacCapabilities>(); |
| 379 | |
| 380 | std::vector<bool> variable_bit_rate_enableds = {false}; |
| 381 | if (aac_capability.variableBitRateSupported) { |
| 382 | variable_bit_rate_enableds.push_back(true); |
| 383 | } |
| 384 | |
| 385 | // combine those parameters into one list of |
| 386 | // CodecConfiguration::CodecSpecific |
| 387 | for (auto object_type : aac_capability.objectType) { |
| 388 | for (int32_t sample_rate : aac_capability.sampleRateHz) { |
| 389 | for (auto channel_mode : aac_capability.channelMode) { |
| 390 | for (int8_t bits_per_sample : aac_capability.bitsPerSample) { |
| 391 | for (auto variable_bit_rate_enabled : variable_bit_rate_enableds) { |
| 392 | AacConfiguration aac_data{ |
| 393 | .objectType = object_type, |
| 394 | .sampleRateHz = sample_rate, |
| 395 | .channelMode = channel_mode, |
| 396 | .variableBitRateEnabled = variable_bit_rate_enabled, |
| 397 | .bitsPerSample = bits_per_sample}; |
| 398 | aac_codec_specifics.push_back( |
| 399 | CodecConfiguration::CodecSpecific(aac_data)); |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | return aac_codec_specifics; |
| 406 | } |
| 407 | |
| 408 | std::vector<CodecConfiguration::CodecSpecific> |
| 409 | GetLdacCodecSpecificSupportedList(bool supported) { |
| 410 | std::vector<CodecConfiguration::CodecSpecific> ldac_codec_specifics; |
| 411 | if (!supported) { |
| 412 | LdacConfiguration ldac_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 413 | ldac_codec_specifics.push_back( |
| 414 | CodecConfiguration::CodecSpecific(ldac_config)); |
| 415 | return ldac_codec_specifics; |
| 416 | } |
| 417 | GetA2dpOffloadCapabilityHelper(CodecType::LDAC); |
| 418 | if (temp_codec_capabilities_ == nullptr || |
| 419 | temp_codec_capabilities_->codecType != CodecType::LDAC) { |
| 420 | return ldac_codec_specifics; |
| 421 | } |
| 422 | // parse the capability |
| 423 | auto& ldac_capability = |
| 424 | temp_codec_capabilities_->capabilities |
| 425 | .get<CodecCapabilities::Capabilities::ldacCapabilities>(); |
| 426 | |
| 427 | // combine those parameters into one list of |
| 428 | // CodecConfiguration::CodecSpecific |
| 429 | for (int32_t sample_rate : ldac_capability.sampleRateHz) { |
| 430 | for (int8_t bits_per_sample : ldac_capability.bitsPerSample) { |
| 431 | for (auto channel_mode : ldac_capability.channelMode) { |
| 432 | for (auto quality_index : ldac_capability.qualityIndex) { |
| 433 | LdacConfiguration ldac_data{.sampleRateHz = sample_rate, |
| 434 | .channelMode = channel_mode, |
| 435 | .qualityIndex = quality_index, |
| 436 | .bitsPerSample = bits_per_sample}; |
| 437 | ldac_codec_specifics.push_back( |
| 438 | CodecConfiguration::CodecSpecific(ldac_data)); |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | return ldac_codec_specifics; |
| 444 | } |
| 445 | |
| 446 | std::vector<CodecConfiguration::CodecSpecific> |
| 447 | GetAptxCodecSpecificSupportedList(bool is_hd, bool supported) { |
| 448 | std::vector<CodecConfiguration::CodecSpecific> aptx_codec_specifics; |
| 449 | if (!supported) { |
| 450 | AptxConfiguration aptx_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 451 | aptx_codec_specifics.push_back( |
| 452 | CodecConfiguration::CodecSpecific(aptx_config)); |
| 453 | return aptx_codec_specifics; |
| 454 | } |
| 455 | GetA2dpOffloadCapabilityHelper( |
| 456 | (is_hd ? CodecType::APTX_HD : CodecType::APTX)); |
| 457 | if (temp_codec_capabilities_ == nullptr) { |
| 458 | return aptx_codec_specifics; |
| 459 | } |
| 460 | if ((is_hd && temp_codec_capabilities_->codecType != CodecType::APTX_HD) || |
| 461 | (!is_hd && temp_codec_capabilities_->codecType != CodecType::APTX)) { |
| 462 | return aptx_codec_specifics; |
| 463 | } |
| 464 | |
| 465 | // parse the capability |
| 466 | auto& aptx_capability = |
| 467 | temp_codec_capabilities_->capabilities |
| 468 | .get<CodecCapabilities::Capabilities::aptxCapabilities>(); |
| 469 | |
| 470 | // combine those parameters into one list of |
| 471 | // CodecConfiguration::CodecSpecific |
| 472 | for (int8_t bits_per_sample : aptx_capability.bitsPerSample) { |
| 473 | for (int32_t sample_rate : aptx_capability.sampleRateHz) { |
| 474 | for (auto channel_mode : aptx_capability.channelMode) { |
| 475 | AptxConfiguration aptx_data{.sampleRateHz = sample_rate, |
| 476 | .channelMode = channel_mode, |
| 477 | .bitsPerSample = bits_per_sample}; |
| 478 | aptx_codec_specifics.push_back( |
| 479 | CodecConfiguration::CodecSpecific(aptx_data)); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | return aptx_codec_specifics; |
| 484 | } |
| 485 | |
| 486 | std::vector<CodecConfiguration::CodecSpecific> |
| 487 | GetLc3CodecSpecificSupportedList(bool supported) { |
| 488 | std::vector<CodecConfiguration::CodecSpecific> lc3_codec_specifics; |
| 489 | if (!supported) { |
| 490 | Lc3Configuration lc3_config{.samplingFrequencyHz = 0, |
| 491 | .frameDurationUs = 0}; |
| 492 | lc3_codec_specifics.push_back( |
| 493 | CodecConfiguration::CodecSpecific(lc3_config)); |
| 494 | return lc3_codec_specifics; |
| 495 | } |
| 496 | GetA2dpOffloadCapabilityHelper(CodecType::LC3); |
| 497 | if (temp_codec_capabilities_ == nullptr || |
| 498 | temp_codec_capabilities_->codecType != CodecType::LC3) { |
| 499 | return lc3_codec_specifics; |
| 500 | } |
| 501 | // parse the capability |
| 502 | auto& lc3_capability = |
| 503 | temp_codec_capabilities_->capabilities |
| 504 | .get<CodecCapabilities::Capabilities::lc3Capabilities>(); |
| 505 | |
| 506 | // combine those parameters into one list of |
| 507 | // CodecConfiguration::CodecSpecific |
| 508 | for (int32_t samplingFrequencyHz : lc3_capability.samplingFrequencyHz) { |
| 509 | for (int32_t frameDurationUs : lc3_capability.frameDurationUs) { |
| 510 | for (auto channel_mode : lc3_capability.channelMode) { |
| 511 | Lc3Configuration lc3_data{.samplingFrequencyHz = samplingFrequencyHz, |
| 512 | .channelMode = channel_mode, |
| 513 | .frameDurationUs = frameDurationUs}; |
| 514 | lc3_codec_specifics.push_back( |
| 515 | CodecConfiguration::CodecSpecific(lc3_data)); |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | return lc3_codec_specifics; |
| 520 | } |
| 521 | |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 522 | bool IsPcmConfigSupported(const PcmConfiguration& pcm_config) { |
| 523 | if (temp_provider_capabilities_.size() != 1 || |
| 524 | temp_provider_capabilities_[0].getTag() != |
| 525 | AudioCapabilities::pcmCapabilities) { |
| 526 | return false; |
| 527 | } |
| 528 | auto pcm_capability = temp_provider_capabilities_[0] |
| 529 | .get<AudioCapabilities::pcmCapabilities>(); |
| 530 | return (contained_in_vector(pcm_capability.channelMode, |
| 531 | pcm_config.channelMode) && |
| 532 | contained_in_vector(pcm_capability.sampleRateHz, |
| 533 | pcm_config.sampleRateHz) && |
| 534 | contained_in_vector(pcm_capability.bitsPerSample, |
| 535 | pcm_config.bitsPerSample)); |
| 536 | } |
| 537 | |
| 538 | std::shared_ptr<IBluetoothAudioProviderFactory> provider_factory_; |
| 539 | std::shared_ptr<IBluetoothAudioProvider> audio_provider_; |
| 540 | std::shared_ptr<IBluetoothAudioPort> audio_port_; |
| 541 | std::vector<AudioCapabilities> temp_provider_capabilities_; |
| 542 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 543 | // temp storage saves the specified codec capability by |
| 544 | // GetOffloadCodecCapabilityHelper() |
| 545 | CodecCapabilities* temp_codec_capabilities_; |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 546 | |
| 547 | static constexpr SessionType kSessionTypes[] = { |
| 548 | SessionType::UNKNOWN, |
| 549 | SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH, |
| 550 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 551 | SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH, |
| 552 | SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH, |
| 553 | SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH, |
| 554 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 555 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 556 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH, |
| 557 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 558 | SessionType::A2DP_SOFTWARE_DECODING_DATAPATH, |
| 559 | SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 560 | }; |
| 561 | }; |
| 562 | |
| 563 | /** |
| 564 | * Test whether we can get the FactoryService from HIDL |
| 565 | */ |
| 566 | TEST_P(BluetoothAudioProviderFactoryAidl, GetProviderFactoryService) {} |
| 567 | |
| 568 | /** |
| 569 | * Test whether we can open a provider for each provider returned by |
| 570 | * getProviderCapabilities() with non-empty capabalities |
| 571 | */ |
| 572 | TEST_P(BluetoothAudioProviderFactoryAidl, |
| 573 | OpenProviderAndCheckCapabilitiesBySession) { |
| 574 | for (auto session_type : kSessionTypes) { |
| 575 | GetProviderCapabilitiesHelper(session_type); |
| 576 | OpenProviderHelper(session_type); |
| 577 | // We must be able to open a provider if its getProviderCapabilities() |
| 578 | // returns non-empty list. |
| 579 | EXPECT_TRUE(temp_provider_capabilities_.empty() || |
| 580 | audio_provider_ != nullptr); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * openProvider A2DP_SOFTWARE_ENCODING_DATAPATH |
| 586 | */ |
| 587 | class BluetoothAudioProviderA2dpEncodingSoftwareAidl |
| 588 | : public BluetoothAudioProviderFactoryAidl { |
| 589 | public: |
| 590 | virtual void SetUp() override { |
| 591 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 592 | GetProviderCapabilitiesHelper(SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH); |
| 593 | OpenProviderHelper(SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH); |
| 594 | ASSERT_NE(audio_provider_, nullptr); |
| 595 | } |
| 596 | |
| 597 | virtual void TearDown() override { |
| 598 | audio_port_ = nullptr; |
| 599 | audio_provider_ = nullptr; |
| 600 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 601 | } |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 602 | }; |
| 603 | |
| 604 | /** |
| 605 | * Test whether we can open a provider of type |
| 606 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 607 | TEST_P(BluetoothAudioProviderA2dpEncodingSoftwareAidl, |
| 608 | OpenA2dpEncodingSoftwareProvider) {} |
| 609 | |
| 610 | /** |
| 611 | * Test whether each provider of type |
| 612 | * SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH can be started and stopped with |
| 613 | * different PCM config |
| 614 | */ |
| 615 | TEST_P(BluetoothAudioProviderA2dpEncodingSoftwareAidl, |
| 616 | StartAndEndA2dpEncodingSoftwareSessionWithPossiblePcmConfig) { |
| 617 | for (auto sample_rate : a2dp_sample_rates) { |
| 618 | for (auto bits_per_sample : a2dp_bits_per_samples) { |
| 619 | for (auto channel_mode : a2dp_channel_modes) { |
| 620 | PcmConfiguration pcm_config{ |
| 621 | .sampleRateHz = sample_rate, |
| 622 | .bitsPerSample = bits_per_sample, |
| 623 | .channelMode = channel_mode, |
| 624 | }; |
| 625 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 626 | DataMQDesc mq_desc; |
| 627 | auto aidl_retval = audio_provider_->startSession( |
| 628 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 629 | &mq_desc); |
| 630 | DataMQ data_mq(mq_desc); |
| 631 | |
| 632 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 633 | if (is_codec_config_valid) { |
| 634 | EXPECT_TRUE(data_mq.isValid()); |
| 635 | } |
| 636 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * openProvider A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH |
| 644 | */ |
| 645 | class BluetoothAudioProviderA2dpEncodingHardwareAidl |
| 646 | : public BluetoothAudioProviderFactoryAidl { |
| 647 | public: |
| 648 | virtual void SetUp() override { |
| 649 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 650 | GetProviderCapabilitiesHelper( |
| 651 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 652 | OpenProviderHelper(SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 653 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 654 | audio_provider_ != nullptr); |
| 655 | } |
| 656 | |
| 657 | virtual void TearDown() override { |
| 658 | audio_port_ = nullptr; |
| 659 | audio_provider_ = nullptr; |
| 660 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 661 | } |
| 662 | |
| 663 | bool IsOffloadSupported() { return (temp_provider_capabilities_.size() > 0); } |
| 664 | }; |
| 665 | |
| 666 | /** |
| 667 | * Test whether we can open a provider of type |
| 668 | */ |
| 669 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 670 | OpenA2dpEncodingHardwareProvider) {} |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 671 | |
| 672 | /** |
| 673 | * Test whether each provider of type |
| 674 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 675 | * SBC hardware encoding config |
| 676 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 677 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 678 | StartAndEndA2dpSbcEncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 679 | if (!IsOffloadSupported()) { |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | CodecConfiguration codec_config = { |
| 684 | .codecType = CodecType::SBC, |
| 685 | .encodedAudioBitrate = 328000, |
| 686 | .peerMtu = 1005, |
| 687 | .isScmstEnabled = false, |
| 688 | }; |
| 689 | auto sbc_codec_specifics = GetSbcCodecSpecificSupportedList(true); |
| 690 | |
| 691 | for (auto& codec_specific : sbc_codec_specifics) { |
| 692 | copy_codec_specific(codec_config.config, codec_specific); |
| 693 | DataMQDesc mq_desc; |
| 694 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 695 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 696 | |
| 697 | ASSERT_TRUE(aidl_retval.isOk()); |
| 698 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * Test whether each provider of type |
| 704 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 705 | * AAC hardware encoding config |
| 706 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 707 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 708 | StartAndEndA2dpAacEncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 709 | if (!IsOffloadSupported()) { |
| 710 | return; |
| 711 | } |
| 712 | |
| 713 | CodecConfiguration codec_config = { |
| 714 | .codecType = CodecType::AAC, |
| 715 | .encodedAudioBitrate = 320000, |
| 716 | .peerMtu = 1005, |
| 717 | .isScmstEnabled = false, |
| 718 | }; |
| 719 | auto aac_codec_specifics = GetAacCodecSpecificSupportedList(true); |
| 720 | |
| 721 | for (auto& codec_specific : aac_codec_specifics) { |
| 722 | copy_codec_specific(codec_config.config, codec_specific); |
| 723 | DataMQDesc mq_desc; |
| 724 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 725 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 726 | |
| 727 | ASSERT_TRUE(aidl_retval.isOk()); |
| 728 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * Test whether each provider of type |
| 734 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 735 | * LDAC hardware encoding config |
| 736 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 737 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 738 | StartAndEndA2dpLdacEncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 739 | if (!IsOffloadSupported()) { |
| 740 | return; |
| 741 | } |
| 742 | |
| 743 | CodecConfiguration codec_config = { |
| 744 | .codecType = CodecType::LDAC, |
| 745 | .encodedAudioBitrate = 990000, |
| 746 | .peerMtu = 1005, |
| 747 | .isScmstEnabled = false, |
| 748 | }; |
| 749 | auto ldac_codec_specifics = GetLdacCodecSpecificSupportedList(true); |
| 750 | |
| 751 | for (auto& codec_specific : ldac_codec_specifics) { |
| 752 | copy_codec_specific(codec_config.config, codec_specific); |
| 753 | DataMQDesc mq_desc; |
| 754 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 755 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 756 | |
| 757 | ASSERT_TRUE(aidl_retval.isOk()); |
| 758 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * Test whether each provider of type |
| 764 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 765 | * LDAC hardware encoding config |
| 766 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 767 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 768 | StartAndEndA2dpLc3EncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 769 | if (!IsOffloadSupported()) { |
| 770 | return; |
| 771 | } |
| 772 | |
| 773 | CodecConfiguration codec_config = { |
| 774 | .codecType = CodecType::LC3, |
| 775 | .encodedAudioBitrate = 990000, |
| 776 | .peerMtu = 1005, |
| 777 | .isScmstEnabled = false, |
| 778 | }; |
| 779 | auto lc3_codec_specifics = GetLc3CodecSpecificSupportedList(true); |
| 780 | |
| 781 | for (auto& codec_specific : lc3_codec_specifics) { |
| 782 | copy_codec_specific(codec_config.config, codec_specific); |
| 783 | DataMQDesc mq_desc; |
| 784 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 785 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 786 | |
| 787 | ASSERT_TRUE(aidl_retval.isOk()); |
| 788 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | /** |
| 793 | * Test whether each provider of type |
| 794 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 795 | * AptX hardware encoding config |
| 796 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 797 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 798 | StartAndEndA2dpAptxEncodingHardwareSession) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 799 | if (!IsOffloadSupported()) { |
| 800 | return; |
| 801 | } |
| 802 | |
| 803 | for (auto codec_type : {CodecType::APTX, CodecType::APTX_HD}) { |
| 804 | CodecConfiguration codec_config = { |
| 805 | .codecType = codec_type, |
| 806 | .encodedAudioBitrate = |
| 807 | (codec_type == CodecType::APTX ? 352000 : 576000), |
| 808 | .peerMtu = 1005, |
| 809 | .isScmstEnabled = false, |
| 810 | }; |
| 811 | |
| 812 | auto aptx_codec_specifics = GetAptxCodecSpecificSupportedList( |
| 813 | (codec_type == CodecType::APTX_HD ? true : false), true); |
| 814 | |
| 815 | for (auto& codec_specific : aptx_codec_specifics) { |
| 816 | copy_codec_specific(codec_config.config, codec_specific); |
| 817 | DataMQDesc mq_desc; |
| 818 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 819 | audio_port_, AudioConfiguration(codec_config), latency_modes, |
| 820 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 821 | |
| 822 | ASSERT_TRUE(aidl_retval.isOk()); |
| 823 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | /** |
| 829 | * Test whether each provider of type |
| 830 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 831 | * an invalid codec config |
| 832 | */ |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 833 | TEST_P(BluetoothAudioProviderA2dpEncodingHardwareAidl, |
| 834 | StartAndEndA2dpEncodingHardwareSessionInvalidCodecConfig) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 835 | if (!IsOffloadSupported()) { |
| 836 | return; |
| 837 | } |
| 838 | ASSERT_NE(audio_provider_, nullptr); |
| 839 | |
| 840 | std::vector<CodecConfiguration::CodecSpecific> codec_specifics; |
| 841 | for (auto codec_type : a2dp_codec_types) { |
| 842 | switch (codec_type) { |
| 843 | case CodecType::SBC: |
| 844 | codec_specifics = GetSbcCodecSpecificSupportedList(false); |
| 845 | break; |
| 846 | case CodecType::AAC: |
| 847 | codec_specifics = GetAacCodecSpecificSupportedList(false); |
| 848 | break; |
| 849 | case CodecType::LDAC: |
| 850 | codec_specifics = GetLdacCodecSpecificSupportedList(false); |
| 851 | break; |
| 852 | case CodecType::APTX: |
| 853 | codec_specifics = GetAptxCodecSpecificSupportedList(false, false); |
| 854 | break; |
| 855 | case CodecType::APTX_HD: |
| 856 | codec_specifics = GetAptxCodecSpecificSupportedList(true, false); |
| 857 | break; |
| 858 | case CodecType::LC3: |
| 859 | codec_specifics = GetLc3CodecSpecificSupportedList(false); |
| 860 | continue; |
| 861 | case CodecType::APTX_ADAPTIVE: |
| 862 | case CodecType::VENDOR: |
| 863 | case CodecType::UNKNOWN: |
| 864 | codec_specifics.clear(); |
| 865 | break; |
| 866 | } |
| 867 | if (codec_specifics.empty()) { |
| 868 | continue; |
| 869 | } |
| 870 | |
| 871 | CodecConfiguration codec_config = { |
| 872 | .codecType = codec_type, |
| 873 | .encodedAudioBitrate = 328000, |
| 874 | .peerMtu = 1005, |
| 875 | .isScmstEnabled = false, |
| 876 | }; |
| 877 | for (auto codec_specific : codec_specifics) { |
| 878 | copy_codec_specific(codec_config.config, codec_specific); |
| 879 | DataMQDesc mq_desc; |
| 880 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 881 | audio_port_, AudioConfiguration(codec_config), latency_modes, |
| 882 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 883 | |
| 884 | // AIDL call should fail on invalid codec |
| 885 | ASSERT_FALSE(aidl_retval.isOk()); |
| 886 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 887 | } |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * openProvider HEARING_AID_SOFTWARE_ENCODING_DATAPATH |
| 893 | */ |
| 894 | class BluetoothAudioProviderHearingAidSoftwareAidl |
| 895 | : public BluetoothAudioProviderFactoryAidl { |
| 896 | public: |
| 897 | virtual void SetUp() override { |
| 898 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 899 | GetProviderCapabilitiesHelper( |
| 900 | SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH); |
| 901 | OpenProviderHelper(SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH); |
| 902 | ASSERT_NE(audio_provider_, nullptr); |
| 903 | } |
| 904 | |
| 905 | virtual void TearDown() override { |
| 906 | audio_port_ = nullptr; |
| 907 | audio_provider_ = nullptr; |
| 908 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 909 | } |
| 910 | |
| 911 | static constexpr int32_t hearing_aid_sample_rates_[] = {0, 16000, 24000}; |
| 912 | static constexpr int8_t hearing_aid_bits_per_samples_[] = {0, 16, 24}; |
| 913 | static constexpr ChannelMode hearing_aid_channel_modes_[] = { |
| 914 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 915 | }; |
| 916 | |
| 917 | /** |
| 918 | * Test whether we can open a provider of type |
| 919 | */ |
| 920 | TEST_P(BluetoothAudioProviderHearingAidSoftwareAidl, |
| 921 | OpenHearingAidSoftwareProvider) {} |
| 922 | |
| 923 | /** |
| 924 | * Test whether each provider of type |
| 925 | * SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH can be started and |
| 926 | * stopped with different PCM config |
| 927 | */ |
| 928 | TEST_P(BluetoothAudioProviderHearingAidSoftwareAidl, |
| 929 | StartAndEndHearingAidSessionWithPossiblePcmConfig) { |
| 930 | for (int32_t sample_rate : hearing_aid_sample_rates_) { |
| 931 | for (int8_t bits_per_sample : hearing_aid_bits_per_samples_) { |
| 932 | for (auto channel_mode : hearing_aid_channel_modes_) { |
| 933 | PcmConfiguration pcm_config{ |
| 934 | .sampleRateHz = sample_rate, |
| 935 | .bitsPerSample = bits_per_sample, |
| 936 | .channelMode = channel_mode, |
| 937 | }; |
| 938 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 939 | DataMQDesc mq_desc; |
| 940 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 941 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 942 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 943 | DataMQ data_mq(mq_desc); |
| 944 | |
| 945 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 946 | if (is_codec_config_valid) { |
| 947 | EXPECT_TRUE(data_mq.isValid()); |
| 948 | } |
| 949 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * openProvider LE_AUDIO_SOFTWARE_ENCODING_DATAPATH |
| 957 | */ |
| 958 | class BluetoothAudioProviderLeAudioOutputSoftwareAidl |
| 959 | : public BluetoothAudioProviderFactoryAidl { |
| 960 | public: |
| 961 | virtual void SetUp() override { |
| 962 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 963 | GetProviderCapabilitiesHelper( |
| 964 | SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH); |
| 965 | OpenProviderHelper(SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH); |
| 966 | ASSERT_NE(audio_provider_, nullptr); |
| 967 | } |
| 968 | |
| 969 | virtual void TearDown() override { |
| 970 | audio_port_ = nullptr; |
| 971 | audio_provider_ = nullptr; |
| 972 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 973 | } |
| 974 | |
| 975 | static constexpr int32_t le_audio_output_sample_rates_[] = { |
| 976 | 0, 8000, 16000, 24000, 32000, 44100, 48000, |
| 977 | }; |
| 978 | static constexpr int8_t le_audio_output_bits_per_samples_[] = {0, 16, 24}; |
| 979 | static constexpr ChannelMode le_audio_output_channel_modes_[] = { |
| 980 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 981 | static constexpr int32_t le_audio_output_data_interval_us_[] = { |
| 982 | 0 /* Invalid */, 10000 /* Valid 10ms */}; |
| 983 | }; |
| 984 | |
| 985 | /** |
| 986 | * Test whether each provider of type |
| 987 | * SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH can be started and |
| 988 | * stopped |
| 989 | */ |
| 990 | TEST_P(BluetoothAudioProviderLeAudioOutputSoftwareAidl, |
| 991 | OpenLeAudioOutputSoftwareProvider) {} |
| 992 | |
| 993 | /** |
| 994 | * Test whether each provider of type |
| 995 | * SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH can be started and |
| 996 | * stopped with different PCM config |
| 997 | */ |
| 998 | TEST_P(BluetoothAudioProviderLeAudioOutputSoftwareAidl, |
| 999 | StartAndEndLeAudioOutputSessionWithPossiblePcmConfig) { |
| 1000 | for (auto sample_rate : le_audio_output_sample_rates_) { |
| 1001 | for (auto bits_per_sample : le_audio_output_bits_per_samples_) { |
| 1002 | for (auto channel_mode : le_audio_output_channel_modes_) { |
| 1003 | for (auto data_interval_us : le_audio_output_data_interval_us_) { |
| 1004 | PcmConfiguration pcm_config{ |
| 1005 | .sampleRateHz = sample_rate, |
| 1006 | .bitsPerSample = bits_per_sample, |
| 1007 | .channelMode = channel_mode, |
| 1008 | .dataIntervalUs = data_interval_us, |
| 1009 | }; |
Josh Wu | 8a1be76 | 2022-02-15 09:37:29 -0800 | [diff] [blame] | 1010 | bool is_codec_config_valid = |
| 1011 | IsPcmConfigSupported(pcm_config) && pcm_config.dataIntervalUs > 0; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1012 | DataMQDesc mq_desc; |
| 1013 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1014 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 1015 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1016 | DataMQ data_mq(mq_desc); |
| 1017 | |
| 1018 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 1019 | if (is_codec_config_valid) { |
| 1020 | EXPECT_TRUE(data_mq.isValid()); |
| 1021 | } |
| 1022 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | /** |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame] | 1030 | * openProvider LE_AUDIO_SOFTWARE_DECODING_DATAPATH |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1031 | */ |
| 1032 | class BluetoothAudioProviderLeAudioInputSoftwareAidl |
| 1033 | : public BluetoothAudioProviderFactoryAidl { |
| 1034 | public: |
| 1035 | virtual void SetUp() override { |
| 1036 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1037 | GetProviderCapabilitiesHelper( |
| 1038 | SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH); |
| 1039 | OpenProviderHelper(SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH); |
| 1040 | ASSERT_NE(audio_provider_, nullptr); |
| 1041 | } |
| 1042 | |
| 1043 | virtual void TearDown() override { |
| 1044 | audio_port_ = nullptr; |
| 1045 | audio_provider_ = nullptr; |
| 1046 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1047 | } |
| 1048 | |
| 1049 | static constexpr int32_t le_audio_input_sample_rates_[] = { |
| 1050 | 0, 8000, 16000, 24000, 32000, 44100, 48000}; |
| 1051 | static constexpr int8_t le_audio_input_bits_per_samples_[] = {0, 16, 24}; |
| 1052 | static constexpr ChannelMode le_audio_input_channel_modes_[] = { |
| 1053 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 1054 | static constexpr int32_t le_audio_input_data_interval_us_[] = { |
| 1055 | 0 /* Invalid */, 10000 /* Valid 10ms */}; |
| 1056 | }; |
| 1057 | |
| 1058 | /** |
| 1059 | * Test whether each provider of type |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame] | 1060 | * SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1061 | * stopped |
| 1062 | */ |
| 1063 | TEST_P(BluetoothAudioProviderLeAudioInputSoftwareAidl, |
| 1064 | OpenLeAudioInputSoftwareProvider) {} |
| 1065 | |
| 1066 | /** |
| 1067 | * Test whether each provider of type |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame] | 1068 | * SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1069 | * stopped with different PCM config |
| 1070 | */ |
| 1071 | TEST_P(BluetoothAudioProviderLeAudioInputSoftwareAidl, |
| 1072 | StartAndEndLeAudioInputSessionWithPossiblePcmConfig) { |
| 1073 | for (auto sample_rate : le_audio_input_sample_rates_) { |
| 1074 | for (auto bits_per_sample : le_audio_input_bits_per_samples_) { |
| 1075 | for (auto channel_mode : le_audio_input_channel_modes_) { |
| 1076 | for (auto data_interval_us : le_audio_input_data_interval_us_) { |
| 1077 | PcmConfiguration pcm_config{ |
| 1078 | .sampleRateHz = sample_rate, |
| 1079 | .bitsPerSample = bits_per_sample, |
| 1080 | .channelMode = channel_mode, |
| 1081 | .dataIntervalUs = data_interval_us, |
| 1082 | }; |
Josh Wu | 8a1be76 | 2022-02-15 09:37:29 -0800 | [diff] [blame] | 1083 | bool is_codec_config_valid = |
| 1084 | IsPcmConfigSupported(pcm_config) && pcm_config.dataIntervalUs > 0; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1085 | DataMQDesc mq_desc; |
| 1086 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1087 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 1088 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1089 | DataMQ data_mq(mq_desc); |
| 1090 | |
| 1091 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 1092 | if (is_codec_config_valid) { |
| 1093 | EXPECT_TRUE(data_mq.isValid()); |
| 1094 | } |
| 1095 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | /** |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame] | 1103 | * openProvider LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1104 | */ |
| 1105 | class BluetoothAudioProviderLeAudioOutputHardwareAidl |
| 1106 | : public BluetoothAudioProviderFactoryAidl { |
| 1107 | public: |
| 1108 | virtual void SetUp() override { |
| 1109 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1110 | GetProviderCapabilitiesHelper( |
| 1111 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1112 | OpenProviderHelper( |
| 1113 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1114 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1115 | audio_provider_ != nullptr); |
| 1116 | } |
| 1117 | |
| 1118 | virtual void TearDown() override { |
| 1119 | audio_port_ = nullptr; |
| 1120 | audio_provider_ = nullptr; |
| 1121 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1122 | } |
| 1123 | |
| 1124 | bool IsOffloadOutputSupported() { |
| 1125 | for (auto& capability : temp_provider_capabilities_) { |
| 1126 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1127 | continue; |
| 1128 | } |
| 1129 | auto& le_audio_capability = |
| 1130 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1131 | if (le_audio_capability.unicastEncodeCapability.codecType != |
| 1132 | CodecType::UNKNOWN) |
| 1133 | return true; |
| 1134 | } |
| 1135 | return false; |
| 1136 | } |
| 1137 | |
| 1138 | std::vector<Lc3Configuration> GetUnicastLc3SupportedList(bool decoding, |
| 1139 | bool supported) { |
| 1140 | std::vector<Lc3Configuration> le_audio_codec_configs; |
| 1141 | if (!supported) { |
| 1142 | Lc3Configuration lc3_config{.samplingFrequencyHz = 0, .pcmBitDepth = 0}; |
| 1143 | le_audio_codec_configs.push_back(lc3_config); |
| 1144 | return le_audio_codec_configs; |
| 1145 | } |
| 1146 | |
| 1147 | // There might be more than one LeAudioCodecCapabilitiesSetting |
| 1148 | std::vector<Lc3Capabilities> lc3_capabilities; |
| 1149 | for (auto& capability : temp_provider_capabilities_) { |
| 1150 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1151 | continue; |
| 1152 | } |
| 1153 | auto& le_audio_capability = |
| 1154 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1155 | auto& unicast_capability = |
| 1156 | decoding ? le_audio_capability.unicastDecodeCapability |
| 1157 | : le_audio_capability.unicastEncodeCapability; |
| 1158 | if (unicast_capability.codecType != CodecType::LC3) { |
| 1159 | continue; |
| 1160 | } |
| 1161 | auto& lc3_capability = unicast_capability.leAudioCodecCapabilities.get< |
| 1162 | UnicastCapability::LeAudioCodecCapabilities::lc3Capabilities>(); |
| 1163 | lc3_capabilities.push_back(lc3_capability); |
| 1164 | } |
| 1165 | |
| 1166 | // Combine those parameters into one list of LeAudioCodecConfiguration |
| 1167 | // This seems horrible, but usually each Lc3Capability only contains a |
| 1168 | // single Lc3Configuration, which means every array has a length of 1. |
| 1169 | for (auto& lc3_capability : lc3_capabilities) { |
| 1170 | for (int32_t samplingFrequencyHz : lc3_capability.samplingFrequencyHz) { |
| 1171 | for (int32_t frameDurationUs : lc3_capability.frameDurationUs) { |
| 1172 | for (int32_t octetsPerFrame : lc3_capability.octetsPerFrame) { |
| 1173 | Lc3Configuration lc3_config = { |
| 1174 | .samplingFrequencyHz = samplingFrequencyHz, |
| 1175 | .frameDurationUs = frameDurationUs, |
| 1176 | .octetsPerFrame = octetsPerFrame, |
| 1177 | }; |
| 1178 | le_audio_codec_configs.push_back(lc3_config); |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | return le_audio_codec_configs; |
| 1185 | } |
| 1186 | |
| 1187 | LeAudioCodecCapabilitiesSetting temp_le_audio_capabilities_; |
| 1188 | }; |
| 1189 | |
| 1190 | /** |
| 1191 | * Test whether each provider of type |
| 1192 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1193 | * stopped |
| 1194 | */ |
| 1195 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 1196 | OpenLeAudioOutputHardwareProvider) {} |
| 1197 | |
| 1198 | /** |
| 1199 | * Test whether each provider of type |
| 1200 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1201 | * stopped with Unicast hardware encoding config |
| 1202 | */ |
| 1203 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 1204 | StartAndEndLeAudioOutputSessionWithPossibleUnicastConfig) { |
| 1205 | if (!IsOffloadOutputSupported()) { |
| 1206 | return; |
| 1207 | } |
| 1208 | |
| 1209 | auto lc3_codec_configs = |
| 1210 | GetUnicastLc3SupportedList(false /* decoding */, true /* supported */); |
| 1211 | LeAudioConfiguration le_audio_config = { |
| 1212 | .codecType = CodecType::LC3, |
| 1213 | .peerDelayUs = 0, |
| 1214 | }; |
| 1215 | |
| 1216 | for (auto& lc3_config : lc3_codec_configs) { |
| 1217 | le_audio_config.leAudioCodecConfig |
| 1218 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 1219 | DataMQDesc mq_desc; |
| 1220 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1221 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 1222 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1223 | |
| 1224 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1225 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | /** |
| 1230 | * Test whether each provider of type |
| 1231 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1232 | * stopped with Unicast hardware encoding config |
| 1233 | * |
| 1234 | * Disabled since offload codec checking is not ready |
| 1235 | */ |
| 1236 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 1237 | DISABLED_StartAndEndLeAudioOutputSessionWithInvalidAudioConfiguration) { |
| 1238 | if (!IsOffloadOutputSupported()) { |
| 1239 | return; |
| 1240 | } |
| 1241 | |
| 1242 | auto lc3_codec_configs = |
| 1243 | GetUnicastLc3SupportedList(false /* decoding */, false /* supported */); |
| 1244 | LeAudioConfiguration le_audio_config = { |
| 1245 | .codecType = CodecType::LC3, |
| 1246 | .peerDelayUs = 0, |
| 1247 | }; |
| 1248 | |
| 1249 | for (auto& lc3_config : lc3_codec_configs) { |
| 1250 | le_audio_config.leAudioCodecConfig |
| 1251 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 1252 | DataMQDesc mq_desc; |
| 1253 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1254 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 1255 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1256 | |
| 1257 | // AIDL call should fail on invalid codec |
| 1258 | ASSERT_FALSE(aidl_retval.isOk()); |
| 1259 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * openProvider LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH |
| 1265 | */ |
| 1266 | class BluetoothAudioProviderLeAudioInputHardwareAidl |
| 1267 | : public BluetoothAudioProviderLeAudioOutputHardwareAidl { |
| 1268 | public: |
| 1269 | virtual void SetUp() override { |
| 1270 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1271 | GetProviderCapabilitiesHelper( |
| 1272 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
| 1273 | OpenProviderHelper( |
| 1274 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
| 1275 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1276 | audio_provider_ != nullptr); |
| 1277 | } |
| 1278 | |
| 1279 | bool IsOffloadInputSupported() { |
| 1280 | for (auto& capability : temp_provider_capabilities_) { |
| 1281 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1282 | continue; |
| 1283 | } |
| 1284 | auto& le_audio_capability = |
| 1285 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1286 | if (le_audio_capability.unicastDecodeCapability.codecType != |
| 1287 | CodecType::UNKNOWN) |
| 1288 | return true; |
| 1289 | } |
| 1290 | return false; |
| 1291 | } |
| 1292 | |
| 1293 | virtual void TearDown() override { |
| 1294 | audio_port_ = nullptr; |
| 1295 | audio_provider_ = nullptr; |
| 1296 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1297 | } |
| 1298 | }; |
| 1299 | |
| 1300 | /** |
| 1301 | * Test whether each provider of type |
| 1302 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1303 | * stopped |
| 1304 | */ |
| 1305 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 1306 | OpenLeAudioInputHardwareProvider) {} |
| 1307 | |
| 1308 | /** |
| 1309 | * Test whether each provider of type |
| 1310 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1311 | * stopped with Unicast hardware encoding config |
| 1312 | */ |
| 1313 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 1314 | StartAndEndLeAudioInputSessionWithPossibleUnicastConfig) { |
| 1315 | if (!IsOffloadInputSupported()) { |
| 1316 | return; |
| 1317 | } |
| 1318 | |
| 1319 | auto lc3_codec_configs = |
| 1320 | GetUnicastLc3SupportedList(true /* decoding */, true /* supported */); |
| 1321 | LeAudioConfiguration le_audio_config = { |
| 1322 | .codecType = CodecType::LC3, |
| 1323 | .peerDelayUs = 0, |
| 1324 | }; |
| 1325 | |
| 1326 | for (auto& lc3_config : lc3_codec_configs) { |
| 1327 | le_audio_config.leAudioCodecConfig |
| 1328 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 1329 | DataMQDesc mq_desc; |
| 1330 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1331 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 1332 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1333 | |
| 1334 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1335 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | /** |
| 1340 | * Test whether each provider of type |
| 1341 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1342 | * stopped with Unicast hardware encoding config |
| 1343 | * |
| 1344 | * Disabled since offload codec checking is not ready |
| 1345 | */ |
| 1346 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 1347 | DISABLED_StartAndEndLeAudioInputSessionWithInvalidAudioConfiguration) { |
| 1348 | if (!IsOffloadInputSupported()) { |
| 1349 | return; |
| 1350 | } |
| 1351 | |
| 1352 | auto lc3_codec_configs = |
| 1353 | GetUnicastLc3SupportedList(true /* decoding */, false /* supported */); |
| 1354 | LeAudioConfiguration le_audio_config = { |
| 1355 | .codecType = CodecType::LC3, |
| 1356 | .peerDelayUs = 0, |
| 1357 | }; |
| 1358 | |
| 1359 | for (auto& lc3_config : lc3_codec_configs) { |
| 1360 | le_audio_config.leAudioCodecConfig |
| 1361 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 1362 | |
| 1363 | DataMQDesc mq_desc; |
| 1364 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1365 | audio_port_, AudioConfiguration(le_audio_config), latency_modes, |
| 1366 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1367 | |
| 1368 | // AIDL call should fail on invalid codec |
| 1369 | ASSERT_FALSE(aidl_retval.isOk()); |
| 1370 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | /** |
| 1375 | * openProvider LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH |
| 1376 | */ |
| 1377 | class BluetoothAudioProviderLeAudioBroadcastSoftwareAidl |
| 1378 | : public BluetoothAudioProviderFactoryAidl { |
| 1379 | public: |
| 1380 | virtual void SetUp() override { |
| 1381 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1382 | GetProviderCapabilitiesHelper( |
| 1383 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH); |
| 1384 | OpenProviderHelper( |
| 1385 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH); |
| 1386 | ASSERT_NE(audio_provider_, nullptr); |
| 1387 | } |
| 1388 | |
| 1389 | virtual void TearDown() override { |
| 1390 | audio_port_ = nullptr; |
| 1391 | audio_provider_ = nullptr; |
| 1392 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1393 | } |
| 1394 | |
| 1395 | static constexpr int32_t le_audio_output_sample_rates_[] = { |
| 1396 | 0, 8000, 16000, 24000, 32000, 44100, 48000, |
| 1397 | }; |
| 1398 | static constexpr int8_t le_audio_output_bits_per_samples_[] = {0, 16, 24}; |
| 1399 | static constexpr ChannelMode le_audio_output_channel_modes_[] = { |
| 1400 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 1401 | static constexpr int32_t le_audio_output_data_interval_us_[] = { |
| 1402 | 0 /* Invalid */, 10000 /* Valid 10ms */}; |
| 1403 | }; |
| 1404 | |
| 1405 | /** |
| 1406 | * Test whether each provider of type |
| 1407 | * SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH can be started and |
| 1408 | * stopped |
| 1409 | */ |
| 1410 | TEST_P(BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, |
Josh Wu | 3202eab | 2022-02-17 18:09:05 -0800 | [diff] [blame] | 1411 | OpenLeAudioOutputSoftwareProvider) {} |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1412 | |
| 1413 | /** |
| 1414 | * Test whether each provider of type |
| 1415 | * SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH can be started and |
| 1416 | * stopped with different PCM config |
| 1417 | */ |
| 1418 | TEST_P(BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, |
Josh Wu | 3202eab | 2022-02-17 18:09:05 -0800 | [diff] [blame] | 1419 | StartAndEndLeAudioOutputSessionWithPossiblePcmConfig) { |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1420 | for (auto sample_rate : le_audio_output_sample_rates_) { |
| 1421 | for (auto bits_per_sample : le_audio_output_bits_per_samples_) { |
| 1422 | for (auto channel_mode : le_audio_output_channel_modes_) { |
| 1423 | for (auto data_interval_us : le_audio_output_data_interval_us_) { |
| 1424 | PcmConfiguration pcm_config{ |
| 1425 | .sampleRateHz = sample_rate, |
| 1426 | .bitsPerSample = bits_per_sample, |
| 1427 | .channelMode = channel_mode, |
| 1428 | .dataIntervalUs = data_interval_us, |
| 1429 | }; |
Josh Wu | 8a1be76 | 2022-02-15 09:37:29 -0800 | [diff] [blame] | 1430 | bool is_codec_config_valid = |
| 1431 | IsPcmConfigSupported(pcm_config) && pcm_config.dataIntervalUs > 0; |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1432 | DataMQDesc mq_desc; |
| 1433 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 1434 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 1435 | &mq_desc); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1436 | DataMQ data_mq(mq_desc); |
| 1437 | |
| 1438 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 1439 | if (is_codec_config_valid) { |
| 1440 | EXPECT_TRUE(data_mq.isValid()); |
| 1441 | } |
| 1442 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1443 | } |
| 1444 | } |
| 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 1449 | /** |
| 1450 | * openProvider LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH |
| 1451 | */ |
| 1452 | class BluetoothAudioProviderLeAudioBroadcastHardwareAidl |
| 1453 | : public BluetoothAudioProviderFactoryAidl { |
| 1454 | public: |
| 1455 | virtual void SetUp() override { |
| 1456 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1457 | GetProviderCapabilitiesHelper( |
| 1458 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1459 | OpenProviderHelper( |
| 1460 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1461 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1462 | audio_provider_ != nullptr); |
| 1463 | } |
| 1464 | |
| 1465 | virtual void TearDown() override { |
| 1466 | audio_port_ = nullptr; |
| 1467 | audio_provider_ = nullptr; |
| 1468 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1469 | } |
| 1470 | |
| 1471 | bool IsBroadcastOffloadSupported() { |
| 1472 | for (auto& capability : temp_provider_capabilities_) { |
| 1473 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1474 | continue; |
| 1475 | } |
| 1476 | auto& le_audio_capability = |
| 1477 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1478 | if (le_audio_capability.broadcastCapability.codecType != |
| 1479 | CodecType::UNKNOWN) |
| 1480 | return true; |
| 1481 | } |
| 1482 | return false; |
| 1483 | } |
| 1484 | |
| 1485 | std::vector<Lc3Configuration> GetBroadcastLc3SupportedList(bool supported) { |
| 1486 | std::vector<Lc3Configuration> le_audio_codec_configs; |
| 1487 | if (!supported) { |
| 1488 | Lc3Configuration lc3_config{.samplingFrequencyHz = 0, .pcmBitDepth = 0}; |
| 1489 | le_audio_codec_configs.push_back(lc3_config); |
| 1490 | return le_audio_codec_configs; |
| 1491 | } |
| 1492 | |
| 1493 | // There might be more than one LeAudioCodecCapabilitiesSetting |
| 1494 | std::vector<Lc3Capabilities> lc3_capabilities; |
| 1495 | for (auto& capability : temp_provider_capabilities_) { |
| 1496 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1497 | continue; |
| 1498 | } |
| 1499 | auto& le_audio_capability = |
| 1500 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1501 | auto& broadcast_capability = le_audio_capability.broadcastCapability; |
| 1502 | if (broadcast_capability.codecType != CodecType::LC3) { |
| 1503 | continue; |
| 1504 | } |
| 1505 | auto& lc3_capability = broadcast_capability.leAudioCodecCapabilities.get< |
| 1506 | BroadcastCapability::LeAudioCodecCapabilities::lc3Capabilities>(); |
| 1507 | for (int idx = 0; idx < lc3_capability->size(); idx++) |
| 1508 | lc3_capabilities.push_back(*lc3_capability->at(idx)); |
| 1509 | } |
| 1510 | |
| 1511 | // Combine those parameters into one list of LeAudioCodecConfiguration |
| 1512 | // This seems horrible, but usually each Lc3Capability only contains a |
| 1513 | // single Lc3Configuration, which means every array has a length of 1. |
| 1514 | for (auto& lc3_capability : lc3_capabilities) { |
| 1515 | for (int32_t samplingFrequencyHz : lc3_capability.samplingFrequencyHz) { |
| 1516 | for (int32_t frameDurationUs : lc3_capability.frameDurationUs) { |
| 1517 | for (int32_t octetsPerFrame : lc3_capability.octetsPerFrame) { |
| 1518 | Lc3Configuration lc3_config = { |
| 1519 | .samplingFrequencyHz = samplingFrequencyHz, |
| 1520 | .frameDurationUs = frameDurationUs, |
| 1521 | .octetsPerFrame = octetsPerFrame, |
| 1522 | }; |
| 1523 | le_audio_codec_configs.push_back(lc3_config); |
| 1524 | } |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | return le_audio_codec_configs; |
| 1530 | } |
| 1531 | |
| 1532 | LeAudioCodecCapabilitiesSetting temp_le_audio_capabilities_; |
| 1533 | }; |
| 1534 | |
| 1535 | /** |
| 1536 | * Test whether each provider of type |
| 1537 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
| 1538 | * started and stopped |
| 1539 | */ |
| 1540 | TEST_P(BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 1541 | OpenLeAudioOutputHardwareProvider) {} |
| 1542 | |
| 1543 | /** |
| 1544 | * Test whether each provider of type |
| 1545 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
| 1546 | * started and stopped with broadcast hardware encoding config |
| 1547 | */ |
| 1548 | TEST_P(BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 1549 | StartAndEndLeAudioBroadcastSessionWithPossibleBroadcastConfig) { |
| 1550 | if (!IsBroadcastOffloadSupported()) { |
| 1551 | return; |
| 1552 | } |
| 1553 | |
| 1554 | auto lc3_codec_configs = GetBroadcastLc3SupportedList(true /* supported */); |
| 1555 | LeAudioBroadcastConfiguration le_audio_broadcast_config = { |
| 1556 | .codecType = CodecType::LC3, |
| 1557 | .streamMap = {}, |
| 1558 | }; |
| 1559 | |
| 1560 | for (auto& lc3_config : lc3_codec_configs) { |
| 1561 | le_audio_broadcast_config.streamMap[0] |
| 1562 | .leAudioCodecConfig.set<LeAudioCodecConfiguration::lc3Config>( |
| 1563 | lc3_config); |
| 1564 | DataMQDesc mq_desc; |
| 1565 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | 60d52e4 | 2022-02-16 12:19:12 -0800 | [diff] [blame] | 1566 | audio_port_, AudioConfiguration(le_audio_broadcast_config), |
| 1567 | latency_modes, &mq_desc); |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 1568 | |
| 1569 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1570 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | /** |
| 1575 | * Test whether each provider of type |
| 1576 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
| 1577 | * started and stopped with Broadcast hardware encoding config |
| 1578 | * |
| 1579 | * Disabled since offload codec checking is not ready |
| 1580 | */ |
| 1581 | TEST_P( |
| 1582 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 1583 | DISABLED_StartAndEndLeAudioBroadcastSessionWithInvalidAudioConfiguration) { |
| 1584 | if (!IsBroadcastOffloadSupported()) { |
| 1585 | return; |
| 1586 | } |
| 1587 | |
| 1588 | auto lc3_codec_configs = GetBroadcastLc3SupportedList(false /* supported */); |
| 1589 | LeAudioBroadcastConfiguration le_audio_broadcast_config = { |
| 1590 | .codecType = CodecType::LC3, |
| 1591 | .streamMap = {}, |
| 1592 | }; |
| 1593 | |
| 1594 | for (auto& lc3_config : lc3_codec_configs) { |
| 1595 | le_audio_broadcast_config.streamMap[0] |
| 1596 | .leAudioCodecConfig.set<LeAudioCodecConfiguration::lc3Config>( |
| 1597 | lc3_config); |
| 1598 | DataMQDesc mq_desc; |
| 1599 | auto aidl_retval = audio_provider_->startSession( |
Chen Chen | 60d52e4 | 2022-02-16 12:19:12 -0800 | [diff] [blame] | 1600 | audio_port_, AudioConfiguration(le_audio_broadcast_config), |
| 1601 | latency_modes, &mq_desc); |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 1602 | |
| 1603 | // AIDL call should fail on invalid codec |
| 1604 | ASSERT_FALSE(aidl_retval.isOk()); |
| 1605 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1606 | } |
| 1607 | } |
| 1608 | |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 1609 | /** |
| 1610 | * openProvider A2DP_SOFTWARE_DECODING_DATAPATH |
| 1611 | */ |
| 1612 | class BluetoothAudioProviderA2dpDecodingSoftwareAidl |
| 1613 | : public BluetoothAudioProviderFactoryAidl { |
| 1614 | public: |
| 1615 | virtual void SetUp() override { |
| 1616 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1617 | GetProviderCapabilitiesHelper(SessionType::A2DP_SOFTWARE_DECODING_DATAPATH); |
| 1618 | OpenProviderHelper(SessionType::A2DP_SOFTWARE_DECODING_DATAPATH); |
| 1619 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1620 | audio_provider_ != nullptr); |
| 1621 | } |
| 1622 | |
| 1623 | virtual void TearDown() override { |
| 1624 | audio_port_ = nullptr; |
| 1625 | audio_provider_ = nullptr; |
| 1626 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1627 | } |
| 1628 | }; |
| 1629 | |
| 1630 | /** |
| 1631 | * Test whether we can open a provider of type |
| 1632 | */ |
| 1633 | TEST_P(BluetoothAudioProviderA2dpDecodingSoftwareAidl, |
| 1634 | OpenA2dpDecodingSoftwareProvider) {} |
| 1635 | |
| 1636 | /** |
| 1637 | * Test whether each provider of type |
| 1638 | * SessionType::A2DP_SOFTWARE_DECODING_DATAPATH can be started and stopped with |
| 1639 | * different PCM config |
| 1640 | */ |
| 1641 | TEST_P(BluetoothAudioProviderA2dpDecodingSoftwareAidl, |
| 1642 | StartAndEndA2dpDecodingSoftwareSessionWithPossiblePcmConfig) { |
| 1643 | for (auto sample_rate : a2dp_sample_rates) { |
| 1644 | for (auto bits_per_sample : a2dp_bits_per_samples) { |
| 1645 | for (auto channel_mode : a2dp_channel_modes) { |
| 1646 | PcmConfiguration pcm_config{ |
| 1647 | .sampleRateHz = sample_rate, |
| 1648 | .bitsPerSample = bits_per_sample, |
| 1649 | .channelMode = channel_mode, |
| 1650 | }; |
| 1651 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 1652 | DataMQDesc mq_desc; |
| 1653 | auto aidl_retval = audio_provider_->startSession( |
| 1654 | audio_port_, AudioConfiguration(pcm_config), latency_modes, |
| 1655 | &mq_desc); |
| 1656 | DataMQ data_mq(mq_desc); |
| 1657 | |
| 1658 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 1659 | if (is_codec_config_valid) { |
| 1660 | EXPECT_TRUE(data_mq.isValid()); |
| 1661 | } |
| 1662 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1663 | } |
| 1664 | } |
| 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | /** |
| 1669 | * openProvider A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH |
| 1670 | */ |
| 1671 | class BluetoothAudioProviderA2dpDecodingHardwareAidl |
| 1672 | : public BluetoothAudioProviderFactoryAidl { |
| 1673 | public: |
| 1674 | virtual void SetUp() override { |
| 1675 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1676 | GetProviderCapabilitiesHelper( |
| 1677 | SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
| 1678 | OpenProviderHelper(SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
| 1679 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1680 | audio_provider_ != nullptr); |
| 1681 | } |
| 1682 | |
| 1683 | virtual void TearDown() override { |
| 1684 | audio_port_ = nullptr; |
| 1685 | audio_provider_ = nullptr; |
| 1686 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1687 | } |
| 1688 | |
| 1689 | bool IsOffloadSupported() { return (temp_provider_capabilities_.size() > 0); } |
| 1690 | }; |
| 1691 | |
| 1692 | /** |
| 1693 | * Test whether we can open a provider of type |
| 1694 | */ |
| 1695 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 1696 | OpenA2dpDecodingHardwareProvider) {} |
| 1697 | |
| 1698 | /** |
| 1699 | * Test whether each provider of type |
| 1700 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped with |
| 1701 | * SBC hardware encoding config |
| 1702 | */ |
| 1703 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 1704 | StartAndEndA2dpSbcDecodingHardwareSession) { |
| 1705 | if (!IsOffloadSupported()) { |
| 1706 | return; |
| 1707 | } |
| 1708 | |
| 1709 | CodecConfiguration codec_config = { |
| 1710 | .codecType = CodecType::SBC, |
| 1711 | .encodedAudioBitrate = 328000, |
| 1712 | .peerMtu = 1005, |
| 1713 | .isScmstEnabled = false, |
| 1714 | }; |
| 1715 | auto sbc_codec_specifics = GetSbcCodecSpecificSupportedList(true); |
| 1716 | |
| 1717 | for (auto& codec_specific : sbc_codec_specifics) { |
| 1718 | copy_codec_specific(codec_config.config, codec_specific); |
| 1719 | DataMQDesc mq_desc; |
| 1720 | auto aidl_retval = audio_provider_->startSession( |
| 1721 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
| 1722 | |
| 1723 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1724 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | /** |
| 1729 | * Test whether each provider of type |
| 1730 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped with |
| 1731 | * AAC hardware encoding config |
| 1732 | */ |
| 1733 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 1734 | StartAndEndA2dpAacDecodingHardwareSession) { |
| 1735 | if (!IsOffloadSupported()) { |
| 1736 | return; |
| 1737 | } |
| 1738 | |
| 1739 | CodecConfiguration codec_config = { |
| 1740 | .codecType = CodecType::AAC, |
| 1741 | .encodedAudioBitrate = 320000, |
| 1742 | .peerMtu = 1005, |
| 1743 | .isScmstEnabled = false, |
| 1744 | }; |
| 1745 | auto aac_codec_specifics = GetAacCodecSpecificSupportedList(true); |
| 1746 | |
| 1747 | for (auto& codec_specific : aac_codec_specifics) { |
| 1748 | copy_codec_specific(codec_config.config, codec_specific); |
| 1749 | DataMQDesc mq_desc; |
| 1750 | auto aidl_retval = audio_provider_->startSession( |
| 1751 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
| 1752 | |
| 1753 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1754 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1755 | } |
| 1756 | } |
| 1757 | |
| 1758 | /** |
| 1759 | * Test whether each provider of type |
| 1760 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped with |
| 1761 | * LDAC hardware encoding config |
| 1762 | */ |
| 1763 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 1764 | StartAndEndA2dpLdacDecodingHardwareSession) { |
| 1765 | if (!IsOffloadSupported()) { |
| 1766 | return; |
| 1767 | } |
| 1768 | |
| 1769 | CodecConfiguration codec_config = { |
| 1770 | .codecType = CodecType::LDAC, |
| 1771 | .encodedAudioBitrate = 990000, |
| 1772 | .peerMtu = 1005, |
| 1773 | .isScmstEnabled = false, |
| 1774 | }; |
| 1775 | auto ldac_codec_specifics = GetLdacCodecSpecificSupportedList(true); |
| 1776 | |
| 1777 | for (auto& codec_specific : ldac_codec_specifics) { |
| 1778 | copy_codec_specific(codec_config.config, codec_specific); |
| 1779 | DataMQDesc mq_desc; |
| 1780 | auto aidl_retval = audio_provider_->startSession( |
| 1781 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
| 1782 | |
| 1783 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1784 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * Test whether each provider of type |
| 1790 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped with |
| 1791 | * LDAC hardware encoding config |
| 1792 | */ |
| 1793 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 1794 | StartAndEndA2dpLc3DecodingHardwareSession) { |
| 1795 | if (!IsOffloadSupported()) { |
| 1796 | return; |
| 1797 | } |
| 1798 | |
| 1799 | CodecConfiguration codec_config = { |
| 1800 | .codecType = CodecType::LC3, |
| 1801 | .encodedAudioBitrate = 990000, |
| 1802 | .peerMtu = 1005, |
| 1803 | .isScmstEnabled = false, |
| 1804 | }; |
| 1805 | auto lc3_codec_specifics = GetLc3CodecSpecificSupportedList(true); |
| 1806 | |
| 1807 | for (auto& codec_specific : lc3_codec_specifics) { |
| 1808 | copy_codec_specific(codec_config.config, codec_specific); |
| 1809 | DataMQDesc mq_desc; |
| 1810 | auto aidl_retval = audio_provider_->startSession( |
| 1811 | audio_port_, AudioConfiguration(codec_config), latency_modes, &mq_desc); |
| 1812 | |
| 1813 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1814 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | /** |
| 1819 | * Test whether each provider of type |
| 1820 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped with |
| 1821 | * AptX hardware encoding config |
| 1822 | */ |
| 1823 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 1824 | StartAndEndA2dpAptxDecodingHardwareSession) { |
| 1825 | if (!IsOffloadSupported()) { |
| 1826 | return; |
| 1827 | } |
| 1828 | |
| 1829 | for (auto codec_type : {CodecType::APTX, CodecType::APTX_HD}) { |
| 1830 | CodecConfiguration codec_config = { |
| 1831 | .codecType = codec_type, |
| 1832 | .encodedAudioBitrate = |
| 1833 | (codec_type == CodecType::APTX ? 352000 : 576000), |
| 1834 | .peerMtu = 1005, |
| 1835 | .isScmstEnabled = false, |
| 1836 | }; |
| 1837 | |
| 1838 | auto aptx_codec_specifics = GetAptxCodecSpecificSupportedList( |
| 1839 | (codec_type == CodecType::APTX_HD ? true : false), true); |
| 1840 | |
| 1841 | for (auto& codec_specific : aptx_codec_specifics) { |
| 1842 | copy_codec_specific(codec_config.config, codec_specific); |
| 1843 | DataMQDesc mq_desc; |
| 1844 | auto aidl_retval = audio_provider_->startSession( |
| 1845 | audio_port_, AudioConfiguration(codec_config), latency_modes, |
| 1846 | &mq_desc); |
| 1847 | |
| 1848 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1849 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1850 | } |
| 1851 | } |
| 1852 | } |
| 1853 | |
| 1854 | /** |
| 1855 | * Test whether each provider of type |
| 1856 | * SessionType::A2DP_HARDWARE_DECODING_DATAPATH can be started and stopped with |
| 1857 | * an invalid codec config |
| 1858 | */ |
| 1859 | TEST_P(BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 1860 | StartAndEndA2dpDecodingHardwareSessionInvalidCodecConfig) { |
| 1861 | if (!IsOffloadSupported()) { |
| 1862 | return; |
| 1863 | } |
| 1864 | ASSERT_NE(audio_provider_, nullptr); |
| 1865 | |
| 1866 | std::vector<CodecConfiguration::CodecSpecific> codec_specifics; |
| 1867 | for (auto codec_type : a2dp_codec_types) { |
| 1868 | switch (codec_type) { |
| 1869 | case CodecType::SBC: |
| 1870 | codec_specifics = GetSbcCodecSpecificSupportedList(false); |
| 1871 | break; |
| 1872 | case CodecType::AAC: |
| 1873 | codec_specifics = GetAacCodecSpecificSupportedList(false); |
| 1874 | break; |
| 1875 | case CodecType::LDAC: |
| 1876 | codec_specifics = GetLdacCodecSpecificSupportedList(false); |
| 1877 | break; |
| 1878 | case CodecType::APTX: |
| 1879 | codec_specifics = GetAptxCodecSpecificSupportedList(false, false); |
| 1880 | break; |
| 1881 | case CodecType::APTX_HD: |
| 1882 | codec_specifics = GetAptxCodecSpecificSupportedList(true, false); |
| 1883 | break; |
| 1884 | case CodecType::LC3: |
| 1885 | codec_specifics = GetLc3CodecSpecificSupportedList(false); |
| 1886 | continue; |
| 1887 | case CodecType::APTX_ADAPTIVE: |
| 1888 | case CodecType::VENDOR: |
| 1889 | case CodecType::UNKNOWN: |
| 1890 | codec_specifics.clear(); |
| 1891 | break; |
| 1892 | } |
| 1893 | if (codec_specifics.empty()) { |
| 1894 | continue; |
| 1895 | } |
| 1896 | |
| 1897 | CodecConfiguration codec_config = { |
| 1898 | .codecType = codec_type, |
| 1899 | .encodedAudioBitrate = 328000, |
| 1900 | .peerMtu = 1005, |
| 1901 | .isScmstEnabled = false, |
| 1902 | }; |
| 1903 | for (auto codec_specific : codec_specifics) { |
| 1904 | copy_codec_specific(codec_config.config, codec_specific); |
| 1905 | DataMQDesc mq_desc; |
| 1906 | auto aidl_retval = audio_provider_->startSession( |
| 1907 | audio_port_, AudioConfiguration(codec_config), latency_modes, |
| 1908 | &mq_desc); |
| 1909 | |
| 1910 | // AIDL call should fail on invalid codec |
| 1911 | ASSERT_FALSE(aidl_retval.isOk()); |
| 1912 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1913 | } |
| 1914 | } |
| 1915 | } |
| 1916 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1917 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1918 | BluetoothAudioProviderFactoryAidl); |
| 1919 | INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAudioProviderFactoryAidl, |
| 1920 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1921 | IBluetoothAudioProviderFactory::descriptor)), |
| 1922 | android::PrintInstanceNameToString); |
| 1923 | |
| 1924 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 1925 | BluetoothAudioProviderA2dpEncodingSoftwareAidl); |
| 1926 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1927 | BluetoothAudioProviderA2dpEncodingSoftwareAidl, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1928 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1929 | IBluetoothAudioProviderFactory::descriptor)), |
| 1930 | android::PrintInstanceNameToString); |
| 1931 | |
| 1932 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 1933 | BluetoothAudioProviderA2dpEncodingHardwareAidl); |
| 1934 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1935 | BluetoothAudioProviderA2dpEncodingHardwareAidl, |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1936 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1937 | IBluetoothAudioProviderFactory::descriptor)), |
| 1938 | android::PrintInstanceNameToString); |
| 1939 | |
| 1940 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1941 | BluetoothAudioProviderHearingAidSoftwareAidl); |
| 1942 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1943 | BluetoothAudioProviderHearingAidSoftwareAidl, |
| 1944 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1945 | IBluetoothAudioProviderFactory::descriptor)), |
| 1946 | android::PrintInstanceNameToString); |
| 1947 | |
| 1948 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1949 | BluetoothAudioProviderLeAudioOutputSoftwareAidl); |
| 1950 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1951 | BluetoothAudioProviderLeAudioOutputSoftwareAidl, |
| 1952 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1953 | IBluetoothAudioProviderFactory::descriptor)), |
| 1954 | android::PrintInstanceNameToString); |
| 1955 | |
| 1956 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1957 | BluetoothAudioProviderLeAudioInputSoftwareAidl); |
| 1958 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1959 | BluetoothAudioProviderLeAudioInputSoftwareAidl, |
| 1960 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1961 | IBluetoothAudioProviderFactory::descriptor)), |
| 1962 | android::PrintInstanceNameToString); |
| 1963 | |
| 1964 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1965 | BluetoothAudioProviderLeAudioOutputHardwareAidl); |
| 1966 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1967 | BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 1968 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1969 | IBluetoothAudioProviderFactory::descriptor)), |
| 1970 | android::PrintInstanceNameToString); |
| 1971 | |
| 1972 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1973 | BluetoothAudioProviderLeAudioInputHardwareAidl); |
| 1974 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1975 | BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 1976 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1977 | IBluetoothAudioProviderFactory::descriptor)), |
| 1978 | android::PrintInstanceNameToString); |
| 1979 | |
| 1980 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1981 | BluetoothAudioProviderLeAudioBroadcastSoftwareAidl); |
| 1982 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1983 | BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, |
| 1984 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1985 | IBluetoothAudioProviderFactory::descriptor)), |
| 1986 | android::PrintInstanceNameToString); |
| 1987 | |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 1988 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1989 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl); |
| 1990 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1991 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 1992 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1993 | IBluetoothAudioProviderFactory::descriptor)), |
| 1994 | android::PrintInstanceNameToString); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1995 | |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame^] | 1996 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1997 | BluetoothAudioProviderA2dpDecodingSoftwareAidl); |
| 1998 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1999 | BluetoothAudioProviderA2dpDecodingSoftwareAidl, |
| 2000 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 2001 | IBluetoothAudioProviderFactory::descriptor)), |
| 2002 | android::PrintInstanceNameToString); |
| 2003 | |
| 2004 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 2005 | BluetoothAudioProviderA2dpDecodingHardwareAidl); |
| 2006 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 2007 | BluetoothAudioProviderA2dpDecodingHardwareAidl, |
| 2008 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 2009 | IBluetoothAudioProviderFactory::descriptor)), |
| 2010 | android::PrintInstanceNameToString); |
| 2011 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 2012 | int main(int argc, char** argv) { |
| 2013 | ::testing::InitGoogleTest(&argc, argv); |
| 2014 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 2015 | ABinderProcess_startThreadPool(); |
| 2016 | return RUN_ALL_TESTS(); |
| 2017 | } |