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}; |
| 91 | |
| 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 | |
| 141 | ndk::ScopedAStatus startStream() { return ScopedAStatus::ok(); } |
| 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; |
| 204 | case SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH: { |
| 205 | std::unordered_set<CodecType> codec_types; |
| 206 | // empty capability means offload is unsupported |
| 207 | for (auto& audio_capability : temp_provider_capabilities_) { |
| 208 | ASSERT_EQ(audio_capability.getTag(), |
| 209 | AudioCapabilities::a2dpCapabilities); |
| 210 | const auto& codec_capabilities = |
| 211 | audio_capability.get<AudioCapabilities::a2dpCapabilities>(); |
| 212 | // Every codec can present once at most |
| 213 | ASSERT_EQ(codec_types.count(codec_capabilities.codecType), 0); |
| 214 | switch (codec_capabilities.codecType) { |
| 215 | case CodecType::SBC: |
| 216 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 217 | CodecCapabilities::Capabilities::sbcCapabilities); |
| 218 | break; |
| 219 | case CodecType::AAC: |
| 220 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 221 | CodecCapabilities::Capabilities::aacCapabilities); |
| 222 | break; |
| 223 | case CodecType::APTX: |
| 224 | case CodecType::APTX_HD: |
| 225 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 226 | CodecCapabilities::Capabilities::aptxCapabilities); |
| 227 | break; |
| 228 | case CodecType::LDAC: |
| 229 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 230 | CodecCapabilities::Capabilities::ldacCapabilities); |
| 231 | break; |
| 232 | case CodecType::LC3: |
| 233 | ASSERT_EQ(codec_capabilities.capabilities.getTag(), |
| 234 | CodecCapabilities::Capabilities::lc3Capabilities); |
| 235 | break; |
| 236 | case CodecType::APTX_ADAPTIVE: |
| 237 | case CodecType::VENDOR: |
| 238 | case CodecType::UNKNOWN: |
| 239 | break; |
| 240 | } |
| 241 | codec_types.insert(codec_capabilities.codecType); |
| 242 | } |
| 243 | } break; |
| 244 | case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH: |
| 245 | case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH: |
| 246 | case SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH: { |
| 247 | ASSERT_FALSE(temp_provider_capabilities_.empty()); |
| 248 | for (auto audio_capability : temp_provider_capabilities_) { |
| 249 | ASSERT_EQ(audio_capability.getTag(), |
| 250 | AudioCapabilities::leAudioCapabilities); |
| 251 | } |
| 252 | } break; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | /*** |
| 257 | * This helps to open the specified provider and check the openProvider() |
| 258 | * has corruct return values. BUT, to keep it simple, it does not consider |
| 259 | * the capability, and please do so at the SetUp of each session's test. |
| 260 | ***/ |
| 261 | void OpenProviderHelper(const SessionType& session_type) { |
| 262 | auto aidl_retval = |
| 263 | provider_factory_->openProvider(session_type, &audio_provider_); |
| 264 | if (aidl_retval.isOk()) { |
| 265 | ASSERT_NE(session_type, SessionType::UNKNOWN); |
| 266 | ASSERT_NE(audio_provider_, nullptr); |
| 267 | audio_port_ = ndk::SharedRefBase::make<BluetoothAudioPort>(); |
| 268 | } else { |
| 269 | // Hardware offloading is optional |
| 270 | ASSERT_TRUE( |
| 271 | session_type == SessionType::UNKNOWN || |
| 272 | session_type == |
| 273 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH || |
| 274 | session_type == |
| 275 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH || |
| 276 | session_type == |
| 277 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH || |
| 278 | session_type == |
| 279 | SessionType:: |
| 280 | LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 281 | ASSERT_EQ(audio_provider_, nullptr); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | bool IsPcmConfigSupported(const PcmConfiguration& pcm_config) { |
| 286 | if (temp_provider_capabilities_.size() != 1 || |
| 287 | temp_provider_capabilities_[0].getTag() != |
| 288 | AudioCapabilities::pcmCapabilities) { |
| 289 | return false; |
| 290 | } |
| 291 | auto pcm_capability = temp_provider_capabilities_[0] |
| 292 | .get<AudioCapabilities::pcmCapabilities>(); |
| 293 | return (contained_in_vector(pcm_capability.channelMode, |
| 294 | pcm_config.channelMode) && |
| 295 | contained_in_vector(pcm_capability.sampleRateHz, |
| 296 | pcm_config.sampleRateHz) && |
| 297 | contained_in_vector(pcm_capability.bitsPerSample, |
| 298 | pcm_config.bitsPerSample)); |
| 299 | } |
| 300 | |
| 301 | std::shared_ptr<IBluetoothAudioProviderFactory> provider_factory_; |
| 302 | std::shared_ptr<IBluetoothAudioProvider> audio_provider_; |
| 303 | std::shared_ptr<IBluetoothAudioPort> audio_port_; |
| 304 | std::vector<AudioCapabilities> temp_provider_capabilities_; |
| 305 | |
| 306 | static constexpr SessionType kSessionTypes[] = { |
| 307 | SessionType::UNKNOWN, |
| 308 | SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH, |
| 309 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 310 | SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH, |
| 311 | SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH, |
| 312 | SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH, |
| 313 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 314 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH, |
| 315 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH, |
| 316 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH, |
| 317 | }; |
| 318 | }; |
| 319 | |
| 320 | /** |
| 321 | * Test whether we can get the FactoryService from HIDL |
| 322 | */ |
| 323 | TEST_P(BluetoothAudioProviderFactoryAidl, GetProviderFactoryService) {} |
| 324 | |
| 325 | /** |
| 326 | * Test whether we can open a provider for each provider returned by |
| 327 | * getProviderCapabilities() with non-empty capabalities |
| 328 | */ |
| 329 | TEST_P(BluetoothAudioProviderFactoryAidl, |
| 330 | OpenProviderAndCheckCapabilitiesBySession) { |
| 331 | for (auto session_type : kSessionTypes) { |
| 332 | GetProviderCapabilitiesHelper(session_type); |
| 333 | OpenProviderHelper(session_type); |
| 334 | // We must be able to open a provider if its getProviderCapabilities() |
| 335 | // returns non-empty list. |
| 336 | EXPECT_TRUE(temp_provider_capabilities_.empty() || |
| 337 | audio_provider_ != nullptr); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * openProvider A2DP_SOFTWARE_ENCODING_DATAPATH |
| 343 | */ |
| 344 | class BluetoothAudioProviderA2dpSoftwareAidl |
| 345 | : public BluetoothAudioProviderFactoryAidl { |
| 346 | public: |
| 347 | virtual void SetUp() override { |
| 348 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 349 | GetProviderCapabilitiesHelper(SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH); |
| 350 | OpenProviderHelper(SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH); |
| 351 | ASSERT_NE(audio_provider_, nullptr); |
| 352 | } |
| 353 | |
| 354 | virtual void TearDown() override { |
| 355 | audio_port_ = nullptr; |
| 356 | audio_provider_ = nullptr; |
| 357 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 358 | } |
| 359 | }; |
| 360 | |
| 361 | /** |
| 362 | * Test whether we can open a provider of type |
| 363 | */ |
| 364 | TEST_P(BluetoothAudioProviderA2dpSoftwareAidl, OpenA2dpSoftwareProvider) {} |
| 365 | |
| 366 | /** |
| 367 | * Test whether each provider of type |
| 368 | * SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH can be started and stopped with |
| 369 | * different PCM config |
| 370 | */ |
| 371 | TEST_P(BluetoothAudioProviderA2dpSoftwareAidl, |
| 372 | StartAndEndA2dpSoftwareSessionWithPossiblePcmConfig) { |
| 373 | for (auto sample_rate : a2dp_sample_rates) { |
| 374 | for (auto bits_per_sample : a2dp_bits_per_samples) { |
| 375 | for (auto channel_mode : a2dp_channel_modes) { |
| 376 | PcmConfiguration pcm_config{ |
| 377 | .sampleRateHz = sample_rate, |
| 378 | .bitsPerSample = bits_per_sample, |
| 379 | .channelMode = channel_mode, |
| 380 | }; |
| 381 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 382 | DataMQDesc mq_desc; |
| 383 | auto aidl_retval = audio_provider_->startSession( |
| 384 | audio_port_, AudioConfiguration(pcm_config), &mq_desc); |
| 385 | DataMQ data_mq(mq_desc); |
| 386 | |
| 387 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 388 | if (is_codec_config_valid) { |
| 389 | EXPECT_TRUE(data_mq.isValid()); |
| 390 | } |
| 391 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * openProvider A2DP_HARDWARE_OFFLOAD_DATAPATH |
| 399 | */ |
| 400 | class BluetoothAudioProviderA2dpHardwareAidl |
| 401 | : public BluetoothAudioProviderFactoryAidl { |
| 402 | public: |
| 403 | virtual void SetUp() override { |
| 404 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 405 | GetProviderCapabilitiesHelper( |
| 406 | SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 407 | OpenProviderHelper(SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 408 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 409 | audio_provider_ != nullptr); |
| 410 | } |
| 411 | |
| 412 | virtual void TearDown() override { |
| 413 | audio_port_ = nullptr; |
| 414 | audio_provider_ = nullptr; |
| 415 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 416 | } |
| 417 | |
| 418 | bool IsOffloadSupported() { return (temp_provider_capabilities_.size() > 0); } |
| 419 | |
| 420 | void GetA2dpOffloadCapabilityHelper(const CodecType& codec_type) { |
| 421 | temp_codec_capabilities_ = nullptr; |
| 422 | for (auto codec_capability : temp_provider_capabilities_) { |
| 423 | auto& a2dp_capabilities = |
| 424 | codec_capability.get<AudioCapabilities::a2dpCapabilities>(); |
| 425 | if (a2dp_capabilities.codecType != codec_type) { |
| 426 | continue; |
| 427 | } |
| 428 | temp_codec_capabilities_ = &a2dp_capabilities; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | std::vector<CodecConfiguration::CodecSpecific> |
| 433 | GetSbcCodecSpecificSupportedList(bool supported) { |
| 434 | std::vector<CodecConfiguration::CodecSpecific> sbc_codec_specifics; |
| 435 | if (!supported) { |
| 436 | SbcConfiguration sbc_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 437 | sbc_codec_specifics.push_back( |
| 438 | CodecConfiguration::CodecSpecific(sbc_config)); |
| 439 | return sbc_codec_specifics; |
| 440 | } |
| 441 | GetA2dpOffloadCapabilityHelper(CodecType::SBC); |
| 442 | if (temp_codec_capabilities_ == nullptr || |
| 443 | temp_codec_capabilities_->codecType != CodecType::SBC) { |
| 444 | return sbc_codec_specifics; |
| 445 | } |
| 446 | // parse the capability |
| 447 | auto& sbc_capability = |
| 448 | temp_codec_capabilities_->capabilities |
| 449 | .get<CodecCapabilities::Capabilities::sbcCapabilities>(); |
| 450 | if (sbc_capability.minBitpool > sbc_capability.maxBitpool) { |
| 451 | return sbc_codec_specifics; |
| 452 | } |
| 453 | |
| 454 | // combine those parameters into one list of |
| 455 | // CodecConfiguration::CodecSpecific |
| 456 | for (int32_t sample_rate : sbc_capability.sampleRateHz) { |
| 457 | for (int8_t block_length : sbc_capability.blockLength) { |
| 458 | for (int8_t num_subbands : sbc_capability.numSubbands) { |
| 459 | for (int8_t bits_per_sample : sbc_capability.bitsPerSample) { |
| 460 | for (auto channel_mode : sbc_capability.channelMode) { |
| 461 | for (auto alloc_method : sbc_capability.allocMethod) { |
| 462 | SbcConfiguration sbc_data = { |
| 463 | .sampleRateHz = sample_rate, |
| 464 | .channelMode = channel_mode, |
| 465 | .blockLength = block_length, |
| 466 | .numSubbands = num_subbands, |
| 467 | .allocMethod = alloc_method, |
| 468 | .bitsPerSample = bits_per_sample, |
| 469 | .minBitpool = sbc_capability.minBitpool, |
| 470 | .maxBitpool = sbc_capability.maxBitpool}; |
| 471 | sbc_codec_specifics.push_back( |
| 472 | CodecConfiguration::CodecSpecific(sbc_data)); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | return sbc_codec_specifics; |
| 480 | } |
| 481 | |
| 482 | std::vector<CodecConfiguration::CodecSpecific> |
| 483 | GetAacCodecSpecificSupportedList(bool supported) { |
| 484 | std::vector<CodecConfiguration::CodecSpecific> aac_codec_specifics; |
| 485 | if (!supported) { |
| 486 | AacConfiguration aac_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 487 | aac_codec_specifics.push_back( |
| 488 | CodecConfiguration::CodecSpecific(aac_config)); |
| 489 | return aac_codec_specifics; |
| 490 | } |
| 491 | GetA2dpOffloadCapabilityHelper(CodecType::AAC); |
| 492 | if (temp_codec_capabilities_ == nullptr || |
| 493 | temp_codec_capabilities_->codecType != CodecType::AAC) { |
| 494 | return aac_codec_specifics; |
| 495 | } |
| 496 | // parse the capability |
| 497 | auto& aac_capability = |
| 498 | temp_codec_capabilities_->capabilities |
| 499 | .get<CodecCapabilities::Capabilities::aacCapabilities>(); |
| 500 | |
| 501 | std::vector<bool> variable_bit_rate_enableds = {false}; |
| 502 | if (aac_capability.variableBitRateSupported) { |
| 503 | variable_bit_rate_enableds.push_back(true); |
| 504 | } |
| 505 | |
| 506 | // combine those parameters into one list of |
| 507 | // CodecConfiguration::CodecSpecific |
| 508 | for (auto object_type : aac_capability.objectType) { |
| 509 | for (int32_t sample_rate : aac_capability.sampleRateHz) { |
| 510 | for (auto channel_mode : aac_capability.channelMode) { |
| 511 | for (int8_t bits_per_sample : aac_capability.bitsPerSample) { |
| 512 | for (auto variable_bit_rate_enabled : variable_bit_rate_enableds) { |
| 513 | AacConfiguration aac_data{ |
| 514 | .objectType = object_type, |
| 515 | .sampleRateHz = sample_rate, |
| 516 | .channelMode = channel_mode, |
| 517 | .variableBitRateEnabled = variable_bit_rate_enabled, |
| 518 | .bitsPerSample = bits_per_sample}; |
| 519 | aac_codec_specifics.push_back( |
| 520 | CodecConfiguration::CodecSpecific(aac_data)); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | return aac_codec_specifics; |
| 527 | } |
| 528 | |
| 529 | std::vector<CodecConfiguration::CodecSpecific> |
| 530 | GetLdacCodecSpecificSupportedList(bool supported) { |
| 531 | std::vector<CodecConfiguration::CodecSpecific> ldac_codec_specifics; |
| 532 | if (!supported) { |
| 533 | LdacConfiguration ldac_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 534 | ldac_codec_specifics.push_back( |
| 535 | CodecConfiguration::CodecSpecific(ldac_config)); |
| 536 | return ldac_codec_specifics; |
| 537 | } |
| 538 | GetA2dpOffloadCapabilityHelper(CodecType::LDAC); |
| 539 | if (temp_codec_capabilities_ == nullptr || |
| 540 | temp_codec_capabilities_->codecType != CodecType::LDAC) { |
| 541 | return ldac_codec_specifics; |
| 542 | } |
| 543 | // parse the capability |
| 544 | auto& ldac_capability = |
| 545 | temp_codec_capabilities_->capabilities |
| 546 | .get<CodecCapabilities::Capabilities::ldacCapabilities>(); |
| 547 | |
| 548 | // combine those parameters into one list of |
| 549 | // CodecConfiguration::CodecSpecific |
| 550 | for (int32_t sample_rate : ldac_capability.sampleRateHz) { |
| 551 | for (int8_t bits_per_sample : ldac_capability.bitsPerSample) { |
| 552 | for (auto channel_mode : ldac_capability.channelMode) { |
| 553 | for (auto quality_index : ldac_capability.qualityIndex) { |
| 554 | LdacConfiguration ldac_data{.sampleRateHz = sample_rate, |
| 555 | .channelMode = channel_mode, |
| 556 | .qualityIndex = quality_index, |
| 557 | .bitsPerSample = bits_per_sample}; |
| 558 | ldac_codec_specifics.push_back( |
| 559 | CodecConfiguration::CodecSpecific(ldac_data)); |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | return ldac_codec_specifics; |
| 565 | } |
| 566 | |
| 567 | std::vector<CodecConfiguration::CodecSpecific> |
| 568 | GetAptxCodecSpecificSupportedList(bool is_hd, bool supported) { |
| 569 | std::vector<CodecConfiguration::CodecSpecific> aptx_codec_specifics; |
| 570 | if (!supported) { |
| 571 | AptxConfiguration aptx_config{.sampleRateHz = 0, .bitsPerSample = 0}; |
| 572 | aptx_codec_specifics.push_back( |
| 573 | CodecConfiguration::CodecSpecific(aptx_config)); |
| 574 | return aptx_codec_specifics; |
| 575 | } |
| 576 | GetA2dpOffloadCapabilityHelper( |
| 577 | (is_hd ? CodecType::APTX_HD : CodecType::APTX)); |
| 578 | if (temp_codec_capabilities_ == nullptr) { |
| 579 | return aptx_codec_specifics; |
| 580 | } |
| 581 | if ((is_hd && temp_codec_capabilities_->codecType != CodecType::APTX_HD) || |
| 582 | (!is_hd && temp_codec_capabilities_->codecType != CodecType::APTX)) { |
| 583 | return aptx_codec_specifics; |
| 584 | } |
| 585 | |
| 586 | // parse the capability |
| 587 | auto& aptx_capability = |
| 588 | temp_codec_capabilities_->capabilities |
| 589 | .get<CodecCapabilities::Capabilities::aptxCapabilities>(); |
| 590 | |
| 591 | // combine those parameters into one list of |
| 592 | // CodecConfiguration::CodecSpecific |
| 593 | for (int8_t bits_per_sample : aptx_capability.bitsPerSample) { |
| 594 | for (int32_t sample_rate : aptx_capability.sampleRateHz) { |
| 595 | for (auto channel_mode : aptx_capability.channelMode) { |
| 596 | AptxConfiguration aptx_data{.sampleRateHz = sample_rate, |
| 597 | .channelMode = channel_mode, |
| 598 | .bitsPerSample = bits_per_sample}; |
| 599 | aptx_codec_specifics.push_back( |
| 600 | CodecConfiguration::CodecSpecific(aptx_data)); |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | return aptx_codec_specifics; |
| 605 | } |
| 606 | |
| 607 | std::vector<CodecConfiguration::CodecSpecific> |
| 608 | GetLc3CodecSpecificSupportedList(bool supported) { |
| 609 | std::vector<CodecConfiguration::CodecSpecific> lc3_codec_specifics; |
| 610 | if (!supported) { |
| 611 | Lc3Configuration lc3_config{.samplingFrequencyHz = 0, |
| 612 | .frameDurationUs = 0}; |
| 613 | lc3_codec_specifics.push_back( |
| 614 | CodecConfiguration::CodecSpecific(lc3_config)); |
| 615 | return lc3_codec_specifics; |
| 616 | } |
| 617 | GetA2dpOffloadCapabilityHelper(CodecType::LC3); |
| 618 | if (temp_codec_capabilities_ == nullptr || |
| 619 | temp_codec_capabilities_->codecType != CodecType::LC3) { |
| 620 | return lc3_codec_specifics; |
| 621 | } |
| 622 | // parse the capability |
| 623 | auto& lc3_capability = |
| 624 | temp_codec_capabilities_->capabilities |
| 625 | .get<CodecCapabilities::Capabilities::lc3Capabilities>(); |
| 626 | |
| 627 | // combine those parameters into one list of |
| 628 | // CodecConfiguration::CodecSpecific |
| 629 | for (int32_t samplingFrequencyHz : lc3_capability.samplingFrequencyHz) { |
| 630 | for (int32_t frameDurationUs : lc3_capability.frameDurationUs) { |
| 631 | for (auto channel_mode : lc3_capability.channelMode) { |
| 632 | Lc3Configuration lc3_data{.samplingFrequencyHz = samplingFrequencyHz, |
| 633 | .channelMode = channel_mode, |
| 634 | .frameDurationUs = frameDurationUs}; |
| 635 | lc3_codec_specifics.push_back( |
| 636 | CodecConfiguration::CodecSpecific(lc3_data)); |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | return lc3_codec_specifics; |
| 641 | } |
| 642 | |
| 643 | // temp storage saves the specified codec capability by |
| 644 | // GetOffloadCodecCapabilityHelper() |
| 645 | CodecCapabilities* temp_codec_capabilities_; |
| 646 | }; |
| 647 | |
| 648 | /** |
| 649 | * Test whether we can open a provider of type |
| 650 | */ |
| 651 | TEST_P(BluetoothAudioProviderA2dpHardwareAidl, OpenA2dpHardwareProvider) {} |
| 652 | |
| 653 | /** |
| 654 | * Test whether each provider of type |
| 655 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 656 | * SBC hardware encoding config |
| 657 | */ |
| 658 | TEST_P(BluetoothAudioProviderA2dpHardwareAidl, |
| 659 | StartAndEndA2dpSbcHardwareSession) { |
| 660 | if (!IsOffloadSupported()) { |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | CodecConfiguration codec_config = { |
| 665 | .codecType = CodecType::SBC, |
| 666 | .encodedAudioBitrate = 328000, |
| 667 | .peerMtu = 1005, |
| 668 | .isScmstEnabled = false, |
| 669 | }; |
| 670 | auto sbc_codec_specifics = GetSbcCodecSpecificSupportedList(true); |
| 671 | |
| 672 | for (auto& codec_specific : sbc_codec_specifics) { |
| 673 | copy_codec_specific(codec_config.config, codec_specific); |
| 674 | DataMQDesc mq_desc; |
| 675 | auto aidl_retval = audio_provider_->startSession( |
| 676 | audio_port_, AudioConfiguration(codec_config), &mq_desc); |
| 677 | |
| 678 | ASSERT_TRUE(aidl_retval.isOk()); |
| 679 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Test whether each provider of type |
| 685 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 686 | * AAC hardware encoding config |
| 687 | */ |
| 688 | TEST_P(BluetoothAudioProviderA2dpHardwareAidl, |
| 689 | StartAndEndA2dpAacHardwareSession) { |
| 690 | if (!IsOffloadSupported()) { |
| 691 | return; |
| 692 | } |
| 693 | |
| 694 | CodecConfiguration codec_config = { |
| 695 | .codecType = CodecType::AAC, |
| 696 | .encodedAudioBitrate = 320000, |
| 697 | .peerMtu = 1005, |
| 698 | .isScmstEnabled = false, |
| 699 | }; |
| 700 | auto aac_codec_specifics = GetAacCodecSpecificSupportedList(true); |
| 701 | |
| 702 | for (auto& codec_specific : aac_codec_specifics) { |
| 703 | copy_codec_specific(codec_config.config, codec_specific); |
| 704 | DataMQDesc mq_desc; |
| 705 | auto aidl_retval = audio_provider_->startSession( |
| 706 | audio_port_, AudioConfiguration(codec_config), &mq_desc); |
| 707 | |
| 708 | ASSERT_TRUE(aidl_retval.isOk()); |
| 709 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | /** |
| 714 | * Test whether each provider of type |
| 715 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 716 | * LDAC hardware encoding config |
| 717 | */ |
| 718 | TEST_P(BluetoothAudioProviderA2dpHardwareAidl, |
| 719 | StartAndEndA2dpLdacHardwareSession) { |
| 720 | if (!IsOffloadSupported()) { |
| 721 | return; |
| 722 | } |
| 723 | |
| 724 | CodecConfiguration codec_config = { |
| 725 | .codecType = CodecType::LDAC, |
| 726 | .encodedAudioBitrate = 990000, |
| 727 | .peerMtu = 1005, |
| 728 | .isScmstEnabled = false, |
| 729 | }; |
| 730 | auto ldac_codec_specifics = GetLdacCodecSpecificSupportedList(true); |
| 731 | |
| 732 | for (auto& codec_specific : ldac_codec_specifics) { |
| 733 | copy_codec_specific(codec_config.config, codec_specific); |
| 734 | DataMQDesc mq_desc; |
| 735 | auto aidl_retval = audio_provider_->startSession( |
| 736 | audio_port_, AudioConfiguration(codec_config), &mq_desc); |
| 737 | |
| 738 | ASSERT_TRUE(aidl_retval.isOk()); |
| 739 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Test whether each provider of type |
| 745 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 746 | * LDAC hardware encoding config |
| 747 | */ |
| 748 | TEST_P(BluetoothAudioProviderA2dpHardwareAidl, |
| 749 | StartAndEndA2dpLc3HardwareSession) { |
| 750 | if (!IsOffloadSupported()) { |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | CodecConfiguration codec_config = { |
| 755 | .codecType = CodecType::LC3, |
| 756 | .encodedAudioBitrate = 990000, |
| 757 | .peerMtu = 1005, |
| 758 | .isScmstEnabled = false, |
| 759 | }; |
| 760 | auto lc3_codec_specifics = GetLc3CodecSpecificSupportedList(true); |
| 761 | |
| 762 | for (auto& codec_specific : lc3_codec_specifics) { |
| 763 | copy_codec_specific(codec_config.config, codec_specific); |
| 764 | DataMQDesc mq_desc; |
| 765 | auto aidl_retval = audio_provider_->startSession( |
| 766 | audio_port_, AudioConfiguration(codec_config), &mq_desc); |
| 767 | |
| 768 | ASSERT_TRUE(aidl_retval.isOk()); |
| 769 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | /** |
| 774 | * Test whether each provider of type |
| 775 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 776 | * AptX hardware encoding config |
| 777 | */ |
| 778 | TEST_P(BluetoothAudioProviderA2dpHardwareAidl, |
| 779 | StartAndEndA2dpAptxHardwareSession) { |
| 780 | if (!IsOffloadSupported()) { |
| 781 | return; |
| 782 | } |
| 783 | |
| 784 | for (auto codec_type : {CodecType::APTX, CodecType::APTX_HD}) { |
| 785 | CodecConfiguration codec_config = { |
| 786 | .codecType = codec_type, |
| 787 | .encodedAudioBitrate = |
| 788 | (codec_type == CodecType::APTX ? 352000 : 576000), |
| 789 | .peerMtu = 1005, |
| 790 | .isScmstEnabled = false, |
| 791 | }; |
| 792 | |
| 793 | auto aptx_codec_specifics = GetAptxCodecSpecificSupportedList( |
| 794 | (codec_type == CodecType::APTX_HD ? true : false), true); |
| 795 | |
| 796 | for (auto& codec_specific : aptx_codec_specifics) { |
| 797 | copy_codec_specific(codec_config.config, codec_specific); |
| 798 | DataMQDesc mq_desc; |
| 799 | auto aidl_retval = audio_provider_->startSession( |
| 800 | audio_port_, AudioConfiguration(codec_config), &mq_desc); |
| 801 | |
| 802 | ASSERT_TRUE(aidl_retval.isOk()); |
| 803 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * Test whether each provider of type |
| 810 | * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with |
| 811 | * an invalid codec config |
| 812 | */ |
| 813 | TEST_P(BluetoothAudioProviderA2dpHardwareAidl, |
| 814 | StartAndEndA2dpHardwareSessionInvalidCodecConfig) { |
| 815 | if (!IsOffloadSupported()) { |
| 816 | return; |
| 817 | } |
| 818 | ASSERT_NE(audio_provider_, nullptr); |
| 819 | |
| 820 | std::vector<CodecConfiguration::CodecSpecific> codec_specifics; |
| 821 | for (auto codec_type : a2dp_codec_types) { |
| 822 | switch (codec_type) { |
| 823 | case CodecType::SBC: |
| 824 | codec_specifics = GetSbcCodecSpecificSupportedList(false); |
| 825 | break; |
| 826 | case CodecType::AAC: |
| 827 | codec_specifics = GetAacCodecSpecificSupportedList(false); |
| 828 | break; |
| 829 | case CodecType::LDAC: |
| 830 | codec_specifics = GetLdacCodecSpecificSupportedList(false); |
| 831 | break; |
| 832 | case CodecType::APTX: |
| 833 | codec_specifics = GetAptxCodecSpecificSupportedList(false, false); |
| 834 | break; |
| 835 | case CodecType::APTX_HD: |
| 836 | codec_specifics = GetAptxCodecSpecificSupportedList(true, false); |
| 837 | break; |
| 838 | case CodecType::LC3: |
| 839 | codec_specifics = GetLc3CodecSpecificSupportedList(false); |
| 840 | continue; |
| 841 | case CodecType::APTX_ADAPTIVE: |
| 842 | case CodecType::VENDOR: |
| 843 | case CodecType::UNKNOWN: |
| 844 | codec_specifics.clear(); |
| 845 | break; |
| 846 | } |
| 847 | if (codec_specifics.empty()) { |
| 848 | continue; |
| 849 | } |
| 850 | |
| 851 | CodecConfiguration codec_config = { |
| 852 | .codecType = codec_type, |
| 853 | .encodedAudioBitrate = 328000, |
| 854 | .peerMtu = 1005, |
| 855 | .isScmstEnabled = false, |
| 856 | }; |
| 857 | for (auto codec_specific : codec_specifics) { |
| 858 | copy_codec_specific(codec_config.config, codec_specific); |
| 859 | DataMQDesc mq_desc; |
| 860 | auto aidl_retval = audio_provider_->startSession( |
| 861 | audio_port_, AudioConfiguration(codec_config), &mq_desc); |
| 862 | |
| 863 | // AIDL call should fail on invalid codec |
| 864 | ASSERT_FALSE(aidl_retval.isOk()); |
| 865 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * openProvider HEARING_AID_SOFTWARE_ENCODING_DATAPATH |
| 872 | */ |
| 873 | class BluetoothAudioProviderHearingAidSoftwareAidl |
| 874 | : public BluetoothAudioProviderFactoryAidl { |
| 875 | public: |
| 876 | virtual void SetUp() override { |
| 877 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 878 | GetProviderCapabilitiesHelper( |
| 879 | SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH); |
| 880 | OpenProviderHelper(SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH); |
| 881 | ASSERT_NE(audio_provider_, nullptr); |
| 882 | } |
| 883 | |
| 884 | virtual void TearDown() override { |
| 885 | audio_port_ = nullptr; |
| 886 | audio_provider_ = nullptr; |
| 887 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 888 | } |
| 889 | |
| 890 | static constexpr int32_t hearing_aid_sample_rates_[] = {0, 16000, 24000}; |
| 891 | static constexpr int8_t hearing_aid_bits_per_samples_[] = {0, 16, 24}; |
| 892 | static constexpr ChannelMode hearing_aid_channel_modes_[] = { |
| 893 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 894 | }; |
| 895 | |
| 896 | /** |
| 897 | * Test whether we can open a provider of type |
| 898 | */ |
| 899 | TEST_P(BluetoothAudioProviderHearingAidSoftwareAidl, |
| 900 | OpenHearingAidSoftwareProvider) {} |
| 901 | |
| 902 | /** |
| 903 | * Test whether each provider of type |
| 904 | * SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH can be started and |
| 905 | * stopped with different PCM config |
| 906 | */ |
| 907 | TEST_P(BluetoothAudioProviderHearingAidSoftwareAidl, |
| 908 | StartAndEndHearingAidSessionWithPossiblePcmConfig) { |
| 909 | for (int32_t sample_rate : hearing_aid_sample_rates_) { |
| 910 | for (int8_t bits_per_sample : hearing_aid_bits_per_samples_) { |
| 911 | for (auto channel_mode : hearing_aid_channel_modes_) { |
| 912 | PcmConfiguration pcm_config{ |
| 913 | .sampleRateHz = sample_rate, |
| 914 | .bitsPerSample = bits_per_sample, |
| 915 | .channelMode = channel_mode, |
| 916 | }; |
| 917 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 918 | DataMQDesc mq_desc; |
| 919 | auto aidl_retval = audio_provider_->startSession( |
| 920 | audio_port_, AudioConfiguration(pcm_config), &mq_desc); |
| 921 | DataMQ data_mq(mq_desc); |
| 922 | |
| 923 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 924 | if (is_codec_config_valid) { |
| 925 | EXPECT_TRUE(data_mq.isValid()); |
| 926 | } |
| 927 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * openProvider LE_AUDIO_SOFTWARE_ENCODING_DATAPATH |
| 935 | */ |
| 936 | class BluetoothAudioProviderLeAudioOutputSoftwareAidl |
| 937 | : public BluetoothAudioProviderFactoryAidl { |
| 938 | public: |
| 939 | virtual void SetUp() override { |
| 940 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 941 | GetProviderCapabilitiesHelper( |
| 942 | SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH); |
| 943 | OpenProviderHelper(SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH); |
| 944 | ASSERT_NE(audio_provider_, nullptr); |
| 945 | } |
| 946 | |
| 947 | virtual void TearDown() override { |
| 948 | audio_port_ = nullptr; |
| 949 | audio_provider_ = nullptr; |
| 950 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 951 | } |
| 952 | |
| 953 | static constexpr int32_t le_audio_output_sample_rates_[] = { |
| 954 | 0, 8000, 16000, 24000, 32000, 44100, 48000, |
| 955 | }; |
| 956 | static constexpr int8_t le_audio_output_bits_per_samples_[] = {0, 16, 24}; |
| 957 | static constexpr ChannelMode le_audio_output_channel_modes_[] = { |
| 958 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 959 | static constexpr int32_t le_audio_output_data_interval_us_[] = { |
| 960 | 0 /* Invalid */, 10000 /* Valid 10ms */}; |
| 961 | }; |
| 962 | |
| 963 | /** |
| 964 | * Test whether each provider of type |
| 965 | * SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH can be started and |
| 966 | * stopped |
| 967 | */ |
| 968 | TEST_P(BluetoothAudioProviderLeAudioOutputSoftwareAidl, |
| 969 | OpenLeAudioOutputSoftwareProvider) {} |
| 970 | |
| 971 | /** |
| 972 | * Test whether each provider of type |
| 973 | * SessionType::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH can be started and |
| 974 | * stopped with different PCM config |
| 975 | */ |
| 976 | TEST_P(BluetoothAudioProviderLeAudioOutputSoftwareAidl, |
| 977 | StartAndEndLeAudioOutputSessionWithPossiblePcmConfig) { |
| 978 | for (auto sample_rate : le_audio_output_sample_rates_) { |
| 979 | for (auto bits_per_sample : le_audio_output_bits_per_samples_) { |
| 980 | for (auto channel_mode : le_audio_output_channel_modes_) { |
| 981 | for (auto data_interval_us : le_audio_output_data_interval_us_) { |
| 982 | PcmConfiguration pcm_config{ |
| 983 | .sampleRateHz = sample_rate, |
| 984 | .bitsPerSample = bits_per_sample, |
| 985 | .channelMode = channel_mode, |
| 986 | .dataIntervalUs = data_interval_us, |
| 987 | }; |
| 988 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 989 | DataMQDesc mq_desc; |
| 990 | auto aidl_retval = audio_provider_->startSession( |
| 991 | audio_port_, AudioConfiguration(pcm_config), &mq_desc); |
| 992 | DataMQ data_mq(mq_desc); |
| 993 | |
| 994 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 995 | if (is_codec_config_valid) { |
| 996 | EXPECT_TRUE(data_mq.isValid()); |
| 997 | } |
| 998 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | /** |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame^] | 1006 | * openProvider LE_AUDIO_SOFTWARE_DECODING_DATAPATH |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1007 | */ |
| 1008 | class BluetoothAudioProviderLeAudioInputSoftwareAidl |
| 1009 | : public BluetoothAudioProviderFactoryAidl { |
| 1010 | public: |
| 1011 | virtual void SetUp() override { |
| 1012 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1013 | GetProviderCapabilitiesHelper( |
| 1014 | SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH); |
| 1015 | OpenProviderHelper(SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH); |
| 1016 | ASSERT_NE(audio_provider_, nullptr); |
| 1017 | } |
| 1018 | |
| 1019 | virtual void TearDown() override { |
| 1020 | audio_port_ = nullptr; |
| 1021 | audio_provider_ = nullptr; |
| 1022 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1023 | } |
| 1024 | |
| 1025 | static constexpr int32_t le_audio_input_sample_rates_[] = { |
| 1026 | 0, 8000, 16000, 24000, 32000, 44100, 48000}; |
| 1027 | static constexpr int8_t le_audio_input_bits_per_samples_[] = {0, 16, 24}; |
| 1028 | static constexpr ChannelMode le_audio_input_channel_modes_[] = { |
| 1029 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 1030 | static constexpr int32_t le_audio_input_data_interval_us_[] = { |
| 1031 | 0 /* Invalid */, 10000 /* Valid 10ms */}; |
| 1032 | }; |
| 1033 | |
| 1034 | /** |
| 1035 | * Test whether each provider of type |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame^] | 1036 | * SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1037 | * stopped |
| 1038 | */ |
| 1039 | TEST_P(BluetoothAudioProviderLeAudioInputSoftwareAidl, |
| 1040 | OpenLeAudioInputSoftwareProvider) {} |
| 1041 | |
| 1042 | /** |
| 1043 | * Test whether each provider of type |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame^] | 1044 | * SessionType::LE_AUDIO_SOFTWARE_DECODING_DATAPATH can be started and |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1045 | * stopped with different PCM config |
| 1046 | */ |
| 1047 | TEST_P(BluetoothAudioProviderLeAudioInputSoftwareAidl, |
| 1048 | StartAndEndLeAudioInputSessionWithPossiblePcmConfig) { |
| 1049 | for (auto sample_rate : le_audio_input_sample_rates_) { |
| 1050 | for (auto bits_per_sample : le_audio_input_bits_per_samples_) { |
| 1051 | for (auto channel_mode : le_audio_input_channel_modes_) { |
| 1052 | for (auto data_interval_us : le_audio_input_data_interval_us_) { |
| 1053 | PcmConfiguration pcm_config{ |
| 1054 | .sampleRateHz = sample_rate, |
| 1055 | .bitsPerSample = bits_per_sample, |
| 1056 | .channelMode = channel_mode, |
| 1057 | .dataIntervalUs = data_interval_us, |
| 1058 | }; |
| 1059 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 1060 | DataMQDesc mq_desc; |
| 1061 | auto aidl_retval = audio_provider_->startSession( |
| 1062 | audio_port_, AudioConfiguration(pcm_config), &mq_desc); |
| 1063 | DataMQ data_mq(mq_desc); |
| 1064 | |
| 1065 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 1066 | if (is_codec_config_valid) { |
| 1067 | EXPECT_TRUE(data_mq.isValid()); |
| 1068 | } |
| 1069 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1070 | } |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | /** |
Alice Kuo | 04a399a | 2022-02-16 09:19:56 +0800 | [diff] [blame^] | 1077 | * openProvider LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1078 | */ |
| 1079 | class BluetoothAudioProviderLeAudioOutputHardwareAidl |
| 1080 | : public BluetoothAudioProviderFactoryAidl { |
| 1081 | public: |
| 1082 | virtual void SetUp() override { |
| 1083 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1084 | GetProviderCapabilitiesHelper( |
| 1085 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1086 | OpenProviderHelper( |
| 1087 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1088 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1089 | audio_provider_ != nullptr); |
| 1090 | } |
| 1091 | |
| 1092 | virtual void TearDown() override { |
| 1093 | audio_port_ = nullptr; |
| 1094 | audio_provider_ = nullptr; |
| 1095 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1096 | } |
| 1097 | |
| 1098 | bool IsOffloadOutputSupported() { |
| 1099 | for (auto& capability : temp_provider_capabilities_) { |
| 1100 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1101 | continue; |
| 1102 | } |
| 1103 | auto& le_audio_capability = |
| 1104 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1105 | if (le_audio_capability.unicastEncodeCapability.codecType != |
| 1106 | CodecType::UNKNOWN) |
| 1107 | return true; |
| 1108 | } |
| 1109 | return false; |
| 1110 | } |
| 1111 | |
| 1112 | std::vector<Lc3Configuration> GetUnicastLc3SupportedList(bool decoding, |
| 1113 | bool supported) { |
| 1114 | std::vector<Lc3Configuration> le_audio_codec_configs; |
| 1115 | if (!supported) { |
| 1116 | Lc3Configuration lc3_config{.samplingFrequencyHz = 0, .pcmBitDepth = 0}; |
| 1117 | le_audio_codec_configs.push_back(lc3_config); |
| 1118 | return le_audio_codec_configs; |
| 1119 | } |
| 1120 | |
| 1121 | // There might be more than one LeAudioCodecCapabilitiesSetting |
| 1122 | std::vector<Lc3Capabilities> lc3_capabilities; |
| 1123 | for (auto& capability : temp_provider_capabilities_) { |
| 1124 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1125 | continue; |
| 1126 | } |
| 1127 | auto& le_audio_capability = |
| 1128 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1129 | auto& unicast_capability = |
| 1130 | decoding ? le_audio_capability.unicastDecodeCapability |
| 1131 | : le_audio_capability.unicastEncodeCapability; |
| 1132 | if (unicast_capability.codecType != CodecType::LC3) { |
| 1133 | continue; |
| 1134 | } |
| 1135 | auto& lc3_capability = unicast_capability.leAudioCodecCapabilities.get< |
| 1136 | UnicastCapability::LeAudioCodecCapabilities::lc3Capabilities>(); |
| 1137 | lc3_capabilities.push_back(lc3_capability); |
| 1138 | } |
| 1139 | |
| 1140 | // Combine those parameters into one list of LeAudioCodecConfiguration |
| 1141 | // This seems horrible, but usually each Lc3Capability only contains a |
| 1142 | // single Lc3Configuration, which means every array has a length of 1. |
| 1143 | for (auto& lc3_capability : lc3_capabilities) { |
| 1144 | for (int32_t samplingFrequencyHz : lc3_capability.samplingFrequencyHz) { |
| 1145 | for (int32_t frameDurationUs : lc3_capability.frameDurationUs) { |
| 1146 | for (int32_t octetsPerFrame : lc3_capability.octetsPerFrame) { |
| 1147 | Lc3Configuration lc3_config = { |
| 1148 | .samplingFrequencyHz = samplingFrequencyHz, |
| 1149 | .frameDurationUs = frameDurationUs, |
| 1150 | .octetsPerFrame = octetsPerFrame, |
| 1151 | }; |
| 1152 | le_audio_codec_configs.push_back(lc3_config); |
| 1153 | } |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | return le_audio_codec_configs; |
| 1159 | } |
| 1160 | |
| 1161 | LeAudioCodecCapabilitiesSetting temp_le_audio_capabilities_; |
| 1162 | }; |
| 1163 | |
| 1164 | /** |
| 1165 | * Test whether each provider of type |
| 1166 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1167 | * stopped |
| 1168 | */ |
| 1169 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 1170 | OpenLeAudioOutputHardwareProvider) {} |
| 1171 | |
| 1172 | /** |
| 1173 | * Test whether each provider of type |
| 1174 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1175 | * stopped with Unicast hardware encoding config |
| 1176 | */ |
| 1177 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 1178 | StartAndEndLeAudioOutputSessionWithPossibleUnicastConfig) { |
| 1179 | if (!IsOffloadOutputSupported()) { |
| 1180 | return; |
| 1181 | } |
| 1182 | |
| 1183 | auto lc3_codec_configs = |
| 1184 | GetUnicastLc3SupportedList(false /* decoding */, true /* supported */); |
| 1185 | LeAudioConfiguration le_audio_config = { |
| 1186 | .codecType = CodecType::LC3, |
| 1187 | .peerDelayUs = 0, |
| 1188 | }; |
| 1189 | |
| 1190 | for (auto& lc3_config : lc3_codec_configs) { |
| 1191 | le_audio_config.leAudioCodecConfig |
| 1192 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 1193 | DataMQDesc mq_desc; |
| 1194 | auto aidl_retval = audio_provider_->startSession( |
| 1195 | audio_port_, AudioConfiguration(le_audio_config), &mq_desc); |
| 1196 | |
| 1197 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1198 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | /** |
| 1203 | * Test whether each provider of type |
| 1204 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1205 | * stopped with Unicast hardware encoding config |
| 1206 | * |
| 1207 | * Disabled since offload codec checking is not ready |
| 1208 | */ |
| 1209 | TEST_P(BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 1210 | DISABLED_StartAndEndLeAudioOutputSessionWithInvalidAudioConfiguration) { |
| 1211 | if (!IsOffloadOutputSupported()) { |
| 1212 | return; |
| 1213 | } |
| 1214 | |
| 1215 | auto lc3_codec_configs = |
| 1216 | GetUnicastLc3SupportedList(false /* decoding */, false /* supported */); |
| 1217 | LeAudioConfiguration le_audio_config = { |
| 1218 | .codecType = CodecType::LC3, |
| 1219 | .peerDelayUs = 0, |
| 1220 | }; |
| 1221 | |
| 1222 | for (auto& lc3_config : lc3_codec_configs) { |
| 1223 | le_audio_config.leAudioCodecConfig |
| 1224 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 1225 | DataMQDesc mq_desc; |
| 1226 | auto aidl_retval = audio_provider_->startSession( |
| 1227 | audio_port_, AudioConfiguration(le_audio_config), &mq_desc); |
| 1228 | |
| 1229 | // AIDL call should fail on invalid codec |
| 1230 | ASSERT_FALSE(aidl_retval.isOk()); |
| 1231 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * openProvider LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH |
| 1237 | */ |
| 1238 | class BluetoothAudioProviderLeAudioInputHardwareAidl |
| 1239 | : public BluetoothAudioProviderLeAudioOutputHardwareAidl { |
| 1240 | public: |
| 1241 | virtual void SetUp() override { |
| 1242 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1243 | GetProviderCapabilitiesHelper( |
| 1244 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
| 1245 | OpenProviderHelper( |
| 1246 | SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH); |
| 1247 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1248 | audio_provider_ != nullptr); |
| 1249 | } |
| 1250 | |
| 1251 | bool IsOffloadInputSupported() { |
| 1252 | for (auto& capability : temp_provider_capabilities_) { |
| 1253 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1254 | continue; |
| 1255 | } |
| 1256 | auto& le_audio_capability = |
| 1257 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1258 | if (le_audio_capability.unicastDecodeCapability.codecType != |
| 1259 | CodecType::UNKNOWN) |
| 1260 | return true; |
| 1261 | } |
| 1262 | return false; |
| 1263 | } |
| 1264 | |
| 1265 | virtual void TearDown() override { |
| 1266 | audio_port_ = nullptr; |
| 1267 | audio_provider_ = nullptr; |
| 1268 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1269 | } |
| 1270 | }; |
| 1271 | |
| 1272 | /** |
| 1273 | * Test whether each provider of type |
| 1274 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1275 | * stopped |
| 1276 | */ |
| 1277 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 1278 | OpenLeAudioInputHardwareProvider) {} |
| 1279 | |
| 1280 | /** |
| 1281 | * Test whether each provider of type |
| 1282 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1283 | * stopped with Unicast hardware encoding config |
| 1284 | */ |
| 1285 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 1286 | StartAndEndLeAudioInputSessionWithPossibleUnicastConfig) { |
| 1287 | if (!IsOffloadInputSupported()) { |
| 1288 | return; |
| 1289 | } |
| 1290 | |
| 1291 | auto lc3_codec_configs = |
| 1292 | GetUnicastLc3SupportedList(true /* decoding */, true /* supported */); |
| 1293 | LeAudioConfiguration le_audio_config = { |
| 1294 | .codecType = CodecType::LC3, |
| 1295 | .peerDelayUs = 0, |
| 1296 | }; |
| 1297 | |
| 1298 | for (auto& lc3_config : lc3_codec_configs) { |
| 1299 | le_audio_config.leAudioCodecConfig |
| 1300 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 1301 | DataMQDesc mq_desc; |
| 1302 | auto aidl_retval = audio_provider_->startSession( |
| 1303 | audio_port_, AudioConfiguration(le_audio_config), &mq_desc); |
| 1304 | |
| 1305 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1306 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | /** |
| 1311 | * Test whether each provider of type |
| 1312 | * SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be started and |
| 1313 | * stopped with Unicast hardware encoding config |
| 1314 | * |
| 1315 | * Disabled since offload codec checking is not ready |
| 1316 | */ |
| 1317 | TEST_P(BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 1318 | DISABLED_StartAndEndLeAudioInputSessionWithInvalidAudioConfiguration) { |
| 1319 | if (!IsOffloadInputSupported()) { |
| 1320 | return; |
| 1321 | } |
| 1322 | |
| 1323 | auto lc3_codec_configs = |
| 1324 | GetUnicastLc3SupportedList(true /* decoding */, false /* supported */); |
| 1325 | LeAudioConfiguration le_audio_config = { |
| 1326 | .codecType = CodecType::LC3, |
| 1327 | .peerDelayUs = 0, |
| 1328 | }; |
| 1329 | |
| 1330 | for (auto& lc3_config : lc3_codec_configs) { |
| 1331 | le_audio_config.leAudioCodecConfig |
| 1332 | .set<LeAudioCodecConfiguration::lc3Config>(lc3_config); |
| 1333 | |
| 1334 | DataMQDesc mq_desc; |
| 1335 | auto aidl_retval = audio_provider_->startSession( |
| 1336 | audio_port_, AudioConfiguration(le_audio_config), &mq_desc); |
| 1337 | |
| 1338 | // AIDL call should fail on invalid codec |
| 1339 | ASSERT_FALSE(aidl_retval.isOk()); |
| 1340 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * openProvider LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH |
| 1346 | */ |
| 1347 | class BluetoothAudioProviderLeAudioBroadcastSoftwareAidl |
| 1348 | : public BluetoothAudioProviderFactoryAidl { |
| 1349 | public: |
| 1350 | virtual void SetUp() override { |
| 1351 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1352 | GetProviderCapabilitiesHelper( |
| 1353 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH); |
| 1354 | OpenProviderHelper( |
| 1355 | SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH); |
| 1356 | ASSERT_NE(audio_provider_, nullptr); |
| 1357 | } |
| 1358 | |
| 1359 | virtual void TearDown() override { |
| 1360 | audio_port_ = nullptr; |
| 1361 | audio_provider_ = nullptr; |
| 1362 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1363 | } |
| 1364 | |
| 1365 | static constexpr int32_t le_audio_output_sample_rates_[] = { |
| 1366 | 0, 8000, 16000, 24000, 32000, 44100, 48000, |
| 1367 | }; |
| 1368 | static constexpr int8_t le_audio_output_bits_per_samples_[] = {0, 16, 24}; |
| 1369 | static constexpr ChannelMode le_audio_output_channel_modes_[] = { |
| 1370 | ChannelMode::UNKNOWN, ChannelMode::MONO, ChannelMode::STEREO}; |
| 1371 | static constexpr int32_t le_audio_output_data_interval_us_[] = { |
| 1372 | 0 /* Invalid */, 10000 /* Valid 10ms */}; |
| 1373 | }; |
| 1374 | |
| 1375 | /** |
| 1376 | * Test whether each provider of type |
| 1377 | * SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH can be started and |
| 1378 | * stopped |
| 1379 | */ |
| 1380 | TEST_P(BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, |
| 1381 | DISABLED_OpenLeAudioOutputSoftwareProvider) {} |
| 1382 | |
| 1383 | /** |
| 1384 | * Test whether each provider of type |
| 1385 | * SessionType::LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH can be started and |
| 1386 | * stopped with different PCM config |
| 1387 | */ |
| 1388 | TEST_P(BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, |
| 1389 | DISABLED_StartAndEndLeAudioOutputSessionWithPossiblePcmConfig) { |
| 1390 | for (auto sample_rate : le_audio_output_sample_rates_) { |
| 1391 | for (auto bits_per_sample : le_audio_output_bits_per_samples_) { |
| 1392 | for (auto channel_mode : le_audio_output_channel_modes_) { |
| 1393 | for (auto data_interval_us : le_audio_output_data_interval_us_) { |
| 1394 | PcmConfiguration pcm_config{ |
| 1395 | .sampleRateHz = sample_rate, |
| 1396 | .bitsPerSample = bits_per_sample, |
| 1397 | .channelMode = channel_mode, |
| 1398 | .dataIntervalUs = data_interval_us, |
| 1399 | }; |
| 1400 | bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); |
| 1401 | DataMQDesc mq_desc; |
| 1402 | auto aidl_retval = audio_provider_->startSession( |
| 1403 | audio_port_, AudioConfiguration(pcm_config), &mq_desc); |
| 1404 | DataMQ data_mq(mq_desc); |
| 1405 | |
| 1406 | EXPECT_EQ(aidl_retval.isOk(), is_codec_config_valid); |
| 1407 | if (is_codec_config_valid) { |
| 1408 | EXPECT_TRUE(data_mq.isValid()); |
| 1409 | } |
| 1410 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1411 | } |
| 1412 | } |
| 1413 | } |
| 1414 | } |
| 1415 | } |
| 1416 | |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 1417 | /** |
| 1418 | * openProvider LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH |
| 1419 | */ |
| 1420 | class BluetoothAudioProviderLeAudioBroadcastHardwareAidl |
| 1421 | : public BluetoothAudioProviderFactoryAidl { |
| 1422 | public: |
| 1423 | virtual void SetUp() override { |
| 1424 | BluetoothAudioProviderFactoryAidl::SetUp(); |
| 1425 | GetProviderCapabilitiesHelper( |
| 1426 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1427 | OpenProviderHelper( |
| 1428 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH); |
| 1429 | ASSERT_TRUE(temp_provider_capabilities_.empty() || |
| 1430 | audio_provider_ != nullptr); |
| 1431 | } |
| 1432 | |
| 1433 | virtual void TearDown() override { |
| 1434 | audio_port_ = nullptr; |
| 1435 | audio_provider_ = nullptr; |
| 1436 | BluetoothAudioProviderFactoryAidl::TearDown(); |
| 1437 | } |
| 1438 | |
| 1439 | bool IsBroadcastOffloadSupported() { |
| 1440 | for (auto& capability : temp_provider_capabilities_) { |
| 1441 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1442 | continue; |
| 1443 | } |
| 1444 | auto& le_audio_capability = |
| 1445 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1446 | if (le_audio_capability.broadcastCapability.codecType != |
| 1447 | CodecType::UNKNOWN) |
| 1448 | return true; |
| 1449 | } |
| 1450 | return false; |
| 1451 | } |
| 1452 | |
| 1453 | std::vector<Lc3Configuration> GetBroadcastLc3SupportedList(bool supported) { |
| 1454 | std::vector<Lc3Configuration> le_audio_codec_configs; |
| 1455 | if (!supported) { |
| 1456 | Lc3Configuration lc3_config{.samplingFrequencyHz = 0, .pcmBitDepth = 0}; |
| 1457 | le_audio_codec_configs.push_back(lc3_config); |
| 1458 | return le_audio_codec_configs; |
| 1459 | } |
| 1460 | |
| 1461 | // There might be more than one LeAudioCodecCapabilitiesSetting |
| 1462 | std::vector<Lc3Capabilities> lc3_capabilities; |
| 1463 | for (auto& capability : temp_provider_capabilities_) { |
| 1464 | if (capability.getTag() != AudioCapabilities::leAudioCapabilities) { |
| 1465 | continue; |
| 1466 | } |
| 1467 | auto& le_audio_capability = |
| 1468 | capability.get<AudioCapabilities::leAudioCapabilities>(); |
| 1469 | auto& broadcast_capability = le_audio_capability.broadcastCapability; |
| 1470 | if (broadcast_capability.codecType != CodecType::LC3) { |
| 1471 | continue; |
| 1472 | } |
| 1473 | auto& lc3_capability = broadcast_capability.leAudioCodecCapabilities.get< |
| 1474 | BroadcastCapability::LeAudioCodecCapabilities::lc3Capabilities>(); |
| 1475 | for (int idx = 0; idx < lc3_capability->size(); idx++) |
| 1476 | lc3_capabilities.push_back(*lc3_capability->at(idx)); |
| 1477 | } |
| 1478 | |
| 1479 | // Combine those parameters into one list of LeAudioCodecConfiguration |
| 1480 | // This seems horrible, but usually each Lc3Capability only contains a |
| 1481 | // single Lc3Configuration, which means every array has a length of 1. |
| 1482 | for (auto& lc3_capability : lc3_capabilities) { |
| 1483 | for (int32_t samplingFrequencyHz : lc3_capability.samplingFrequencyHz) { |
| 1484 | for (int32_t frameDurationUs : lc3_capability.frameDurationUs) { |
| 1485 | for (int32_t octetsPerFrame : lc3_capability.octetsPerFrame) { |
| 1486 | Lc3Configuration lc3_config = { |
| 1487 | .samplingFrequencyHz = samplingFrequencyHz, |
| 1488 | .frameDurationUs = frameDurationUs, |
| 1489 | .octetsPerFrame = octetsPerFrame, |
| 1490 | }; |
| 1491 | le_audio_codec_configs.push_back(lc3_config); |
| 1492 | } |
| 1493 | } |
| 1494 | } |
| 1495 | } |
| 1496 | |
| 1497 | return le_audio_codec_configs; |
| 1498 | } |
| 1499 | |
| 1500 | LeAudioCodecCapabilitiesSetting temp_le_audio_capabilities_; |
| 1501 | }; |
| 1502 | |
| 1503 | /** |
| 1504 | * Test whether each provider of type |
| 1505 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
| 1506 | * started and stopped |
| 1507 | */ |
| 1508 | TEST_P(BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 1509 | OpenLeAudioOutputHardwareProvider) {} |
| 1510 | |
| 1511 | /** |
| 1512 | * Test whether each provider of type |
| 1513 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
| 1514 | * started and stopped with broadcast hardware encoding config |
| 1515 | */ |
| 1516 | TEST_P(BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 1517 | StartAndEndLeAudioBroadcastSessionWithPossibleBroadcastConfig) { |
| 1518 | if (!IsBroadcastOffloadSupported()) { |
| 1519 | return; |
| 1520 | } |
| 1521 | |
| 1522 | auto lc3_codec_configs = GetBroadcastLc3SupportedList(true /* supported */); |
| 1523 | LeAudioBroadcastConfiguration le_audio_broadcast_config = { |
| 1524 | .codecType = CodecType::LC3, |
| 1525 | .streamMap = {}, |
| 1526 | }; |
| 1527 | |
| 1528 | for (auto& lc3_config : lc3_codec_configs) { |
| 1529 | le_audio_broadcast_config.streamMap[0] |
| 1530 | .leAudioCodecConfig.set<LeAudioCodecConfiguration::lc3Config>( |
| 1531 | lc3_config); |
| 1532 | DataMQDesc mq_desc; |
| 1533 | auto aidl_retval = audio_provider_->startSession( |
| 1534 | audio_port_, AudioConfiguration(le_audio_broadcast_config), &mq_desc); |
| 1535 | |
| 1536 | ASSERT_TRUE(aidl_retval.isOk()); |
| 1537 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | /** |
| 1542 | * Test whether each provider of type |
| 1543 | * SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH can be |
| 1544 | * started and stopped with Broadcast hardware encoding config |
| 1545 | * |
| 1546 | * Disabled since offload codec checking is not ready |
| 1547 | */ |
| 1548 | TEST_P( |
| 1549 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 1550 | DISABLED_StartAndEndLeAudioBroadcastSessionWithInvalidAudioConfiguration) { |
| 1551 | if (!IsBroadcastOffloadSupported()) { |
| 1552 | return; |
| 1553 | } |
| 1554 | |
| 1555 | auto lc3_codec_configs = GetBroadcastLc3SupportedList(false /* supported */); |
| 1556 | LeAudioBroadcastConfiguration le_audio_broadcast_config = { |
| 1557 | .codecType = CodecType::LC3, |
| 1558 | .streamMap = {}, |
| 1559 | }; |
| 1560 | |
| 1561 | for (auto& lc3_config : lc3_codec_configs) { |
| 1562 | le_audio_broadcast_config.streamMap[0] |
| 1563 | .leAudioCodecConfig.set<LeAudioCodecConfiguration::lc3Config>( |
| 1564 | lc3_config); |
| 1565 | DataMQDesc mq_desc; |
| 1566 | auto aidl_retval = audio_provider_->startSession( |
| 1567 | audio_port_, AudioConfiguration(le_audio_broadcast_config), &mq_desc); |
| 1568 | |
| 1569 | // AIDL call should fail on invalid codec |
| 1570 | ASSERT_FALSE(aidl_retval.isOk()); |
| 1571 | EXPECT_TRUE(audio_provider_->endSession().isOk()); |
| 1572 | } |
| 1573 | } |
| 1574 | |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1575 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1576 | BluetoothAudioProviderFactoryAidl); |
| 1577 | INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAudioProviderFactoryAidl, |
| 1578 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1579 | IBluetoothAudioProviderFactory::descriptor)), |
| 1580 | android::PrintInstanceNameToString); |
| 1581 | |
| 1582 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1583 | BluetoothAudioProviderA2dpSoftwareAidl); |
| 1584 | INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAudioProviderA2dpSoftwareAidl, |
| 1585 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1586 | IBluetoothAudioProviderFactory::descriptor)), |
| 1587 | android::PrintInstanceNameToString); |
| 1588 | |
| 1589 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1590 | BluetoothAudioProviderA2dpHardwareAidl); |
| 1591 | INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAudioProviderA2dpHardwareAidl, |
| 1592 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1593 | IBluetoothAudioProviderFactory::descriptor)), |
| 1594 | android::PrintInstanceNameToString); |
| 1595 | |
| 1596 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1597 | BluetoothAudioProviderHearingAidSoftwareAidl); |
| 1598 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1599 | BluetoothAudioProviderHearingAidSoftwareAidl, |
| 1600 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1601 | IBluetoothAudioProviderFactory::descriptor)), |
| 1602 | android::PrintInstanceNameToString); |
| 1603 | |
| 1604 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1605 | BluetoothAudioProviderLeAudioOutputSoftwareAidl); |
| 1606 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1607 | BluetoothAudioProviderLeAudioOutputSoftwareAidl, |
| 1608 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1609 | IBluetoothAudioProviderFactory::descriptor)), |
| 1610 | android::PrintInstanceNameToString); |
| 1611 | |
| 1612 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1613 | BluetoothAudioProviderLeAudioInputSoftwareAidl); |
| 1614 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1615 | BluetoothAudioProviderLeAudioInputSoftwareAidl, |
| 1616 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1617 | IBluetoothAudioProviderFactory::descriptor)), |
| 1618 | android::PrintInstanceNameToString); |
| 1619 | |
| 1620 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1621 | BluetoothAudioProviderLeAudioOutputHardwareAidl); |
| 1622 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1623 | BluetoothAudioProviderLeAudioOutputHardwareAidl, |
| 1624 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1625 | IBluetoothAudioProviderFactory::descriptor)), |
| 1626 | android::PrintInstanceNameToString); |
| 1627 | |
| 1628 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1629 | BluetoothAudioProviderLeAudioInputHardwareAidl); |
| 1630 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1631 | BluetoothAudioProviderLeAudioInputHardwareAidl, |
| 1632 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1633 | IBluetoothAudioProviderFactory::descriptor)), |
| 1634 | android::PrintInstanceNameToString); |
| 1635 | |
| 1636 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1637 | BluetoothAudioProviderLeAudioBroadcastSoftwareAidl); |
| 1638 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1639 | BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, |
| 1640 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1641 | IBluetoothAudioProviderFactory::descriptor)), |
| 1642 | android::PrintInstanceNameToString); |
| 1643 | |
Alice Kuo | 336d90c | 2022-02-16 09:09:59 +0800 | [diff] [blame] | 1644 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( |
| 1645 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl); |
| 1646 | INSTANTIATE_TEST_SUITE_P(PerInstance, |
| 1647 | BluetoothAudioProviderLeAudioBroadcastHardwareAidl, |
| 1648 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1649 | IBluetoothAudioProviderFactory::descriptor)), |
| 1650 | android::PrintInstanceNameToString); |
Josh Wu | 049e2cd | 2022-01-12 05:42:58 -0800 | [diff] [blame] | 1651 | |
| 1652 | int main(int argc, char** argv) { |
| 1653 | ::testing::InitGoogleTest(&argc, argv); |
| 1654 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 1655 | ABinderProcess_startThreadPool(); |
| 1656 | return RUN_ALL_TESTS(); |
| 1657 | } |