Loading system/bta/le_audio/codec_manager.cc +40 −40 Original line number Diff line number Diff line Loading @@ -280,25 +280,49 @@ public: return true; } AudioSetConfigurations GetSupportedCodecConfigurations( const CodecManager::UnicastConfigurationRequirements& requirements) const { std::unique_ptr<AudioSetConfiguration> GetLocalCodecConfigurations( const CodecManager::UnicastConfigurationRequirements& requirements, CodecManager::UnicastConfigurationProvider provider) const { AudioSetConfigurations configs; if (GetCodecLocation() == le_audio::types::CodecLocation::ADSP) { log::verbose("Get offload config for the context type: {}", (int)requirements.audio_context_type); // TODO: Need to have a mechanism to switch to software session if offload // doesn't support. return context_type_offload_config_map_.count(requirements.audio_context_type) configs = context_type_offload_config_map_.count(requirements.audio_context_type) ? context_type_offload_config_map_.at(requirements.audio_context_type) : AudioSetConfigurations(); } } else { log::verbose("Get software config for the context type: {}", (int)requirements.audio_context_type); return *AudioSetConfigurationProvider::Get()->GetConfigurations( configs = *AudioSetConfigurationProvider::Get()->GetConfigurations( requirements.audio_context_type); } if (configs.empty()) { log::error("No valid configuration matching the requirements: {}", requirements); PrintDebugState(); return nullptr; } // Remove the dual bidir SWB config if not supported if (!IsDualBiDirSwbSupported()) { configs.erase(std::remove_if(configs.begin(), configs.end(), [](auto const& el) { if (el->confs.source.empty()) { return false; } return AudioSetConfigurationProvider::Get() ->CheckConfigurationIsDualBiDirSwb(*el); }), configs.end()); } // Note: For the software configuration provider, we use the provider matcher // logic to match the proper configuration with group capabilities. return provider(requirements, &configs); } void PrintDebugState() const { for (types::LeAudioContextType ctx_type : types::kLeAudioContextAllTypesArray) { std::stringstream os; Loading @@ -317,6 +341,10 @@ public: } bool IsUsingCodecExtensibility() const { if (GetCodecLocation() == types::CodecLocation::HOST) { return false; } auto codec_ext_status = osi_property_get_bool("bluetooth.core.le_audio.codec_extension_aidl.enabled", false) && com::android::bluetooth::flags::leaudio_multicodec_aidl_support(); Loading @@ -333,37 +361,9 @@ public: if (hal_config) { return std::make_unique<AudioSetConfiguration>(*hal_config); } log::debug( "No configuration received from AIDL, fall back to static " "configuration."); } auto configs = GetSupportedCodecConfigurations(requirements); if (configs.empty()) { log::error("No valid configuration matching the requirements: {}", requirements); PrintDebugState(); return nullptr; log::debug("No configuration received from AIDL, fall back to static configuration."); } // Remove the dual bidir SWB config if not supported if (!IsDualBiDirSwbSupported()) { configs.erase(std::remove_if(configs.begin(), configs.end(), [](auto const& el) { if (el->confs.source.empty()) { return false; } return AudioSetConfigurationProvider::Get() ->CheckConfigurationIsDualBiDirSwb(*el); }), configs.end()); } // Note: For the only supported right now legacy software configuration // provider, we use the device group logic to match the proper // configuration with group capabilities. Note that this path only // supports the LC3 codec format. For the multicodec support we should // rely on the configuration matcher behind the AIDL interface. return provider(requirements, &configs); return GetLocalCodecConfigurations(requirements, provider); } bool CheckCodecConfigIsBiDirSwb(const AudioSetConfiguration& config) { Loading system/bta/le_audio/codec_manager_test.cc +34 −0 Original line number Diff line number Diff line Loading @@ -265,6 +265,8 @@ void set_mock_offload_capabilities(const std::vector<AudioSetConfiguration>& cap } static constexpr char kPropLeAudioOffloadSupported[] = "ro.bluetooth.leaudio_offload.supported"; static constexpr char kPropLeAudioCodecExtensibility[] = "bluetooth.core.le_audio.codec_extension_aidl.enabled"; static constexpr char kPropLeAudioOffloadDisabled[] = "persist.bluetooth.leaudio_offload.disabled"; static constexpr char kPropLeAudioBidirSwbSupported[] = "bluetooth.leaudio.dual_bidirection_swb.supported"; Loading Loading @@ -823,6 +825,10 @@ public: // Allow for bidir SWB configurations osi_property_set_bool(kPropLeAudioBidirSwbSupported, true); // Codec extensibility disabled by default com::android::bluetooth::flags::provider_->leaudio_multicodec_aidl_support(false); osi_property_set_bool(kPropLeAudioCodecExtensibility, false); CodecManagerTestBase::SetUp(); } }; Loading @@ -837,6 +843,10 @@ public: // Do not allow for bidir SWB configurations osi_property_set_bool(kPropLeAudioBidirSwbSupported, false); // Codec extensibility disabled by default com::android::bluetooth::flags::provider_->leaudio_multicodec_aidl_support(false); osi_property_set_bool(kPropLeAudioCodecExtensibility, false); CodecManagerTestBase::SetUp(); } }; Loading Loading @@ -1295,4 +1305,28 @@ TEST_F(CodecManagerTestHost, test_dont_update_broadcast_offloader) { ASSERT_FALSE(was_called); } TEST_F(CodecManagerTestHost, test_dont_call_hal_for_config) { com::android::bluetooth::flags::provider_->leaudio_multicodec_aidl_support(true); osi_property_set_bool(kPropLeAudioCodecExtensibility, true); // Set the offloader capabilities std::vector<AudioSetConfiguration> offload_capabilities; set_mock_offload_capabilities(offload_capabilities); const std::vector<bluetooth::le_audio::btle_audio_codec_config_t> offloading_preference = {}; codec_manager->Start(offloading_preference); codec_manager->UpdateActiveUnicastAudioHalClient(mock_le_audio_source_hal_client_, mock_le_audio_sink_hal_client_, true); EXPECT_CALL(*mock_le_audio_source_hal_client_, GetUnicastConfig(_)).Times(0); codec_manager->GetCodecConfig( {.audio_context_type = types::LeAudioContextType::MEDIA}, [&](const CodecManager::UnicastConfigurationRequirements& /*requirements*/, const set_configurations::AudioSetConfigurations* /*confs*/) -> std::unique_ptr<set_configurations::AudioSetConfiguration> { // In this case the chosen configuration doesn't matter - select none return nullptr; }); } } // namespace bluetooth::le_audio Loading
system/bta/le_audio/codec_manager.cc +40 −40 Original line number Diff line number Diff line Loading @@ -280,25 +280,49 @@ public: return true; } AudioSetConfigurations GetSupportedCodecConfigurations( const CodecManager::UnicastConfigurationRequirements& requirements) const { std::unique_ptr<AudioSetConfiguration> GetLocalCodecConfigurations( const CodecManager::UnicastConfigurationRequirements& requirements, CodecManager::UnicastConfigurationProvider provider) const { AudioSetConfigurations configs; if (GetCodecLocation() == le_audio::types::CodecLocation::ADSP) { log::verbose("Get offload config for the context type: {}", (int)requirements.audio_context_type); // TODO: Need to have a mechanism to switch to software session if offload // doesn't support. return context_type_offload_config_map_.count(requirements.audio_context_type) configs = context_type_offload_config_map_.count(requirements.audio_context_type) ? context_type_offload_config_map_.at(requirements.audio_context_type) : AudioSetConfigurations(); } } else { log::verbose("Get software config for the context type: {}", (int)requirements.audio_context_type); return *AudioSetConfigurationProvider::Get()->GetConfigurations( configs = *AudioSetConfigurationProvider::Get()->GetConfigurations( requirements.audio_context_type); } if (configs.empty()) { log::error("No valid configuration matching the requirements: {}", requirements); PrintDebugState(); return nullptr; } // Remove the dual bidir SWB config if not supported if (!IsDualBiDirSwbSupported()) { configs.erase(std::remove_if(configs.begin(), configs.end(), [](auto const& el) { if (el->confs.source.empty()) { return false; } return AudioSetConfigurationProvider::Get() ->CheckConfigurationIsDualBiDirSwb(*el); }), configs.end()); } // Note: For the software configuration provider, we use the provider matcher // logic to match the proper configuration with group capabilities. return provider(requirements, &configs); } void PrintDebugState() const { for (types::LeAudioContextType ctx_type : types::kLeAudioContextAllTypesArray) { std::stringstream os; Loading @@ -317,6 +341,10 @@ public: } bool IsUsingCodecExtensibility() const { if (GetCodecLocation() == types::CodecLocation::HOST) { return false; } auto codec_ext_status = osi_property_get_bool("bluetooth.core.le_audio.codec_extension_aidl.enabled", false) && com::android::bluetooth::flags::leaudio_multicodec_aidl_support(); Loading @@ -333,37 +361,9 @@ public: if (hal_config) { return std::make_unique<AudioSetConfiguration>(*hal_config); } log::debug( "No configuration received from AIDL, fall back to static " "configuration."); } auto configs = GetSupportedCodecConfigurations(requirements); if (configs.empty()) { log::error("No valid configuration matching the requirements: {}", requirements); PrintDebugState(); return nullptr; log::debug("No configuration received from AIDL, fall back to static configuration."); } // Remove the dual bidir SWB config if not supported if (!IsDualBiDirSwbSupported()) { configs.erase(std::remove_if(configs.begin(), configs.end(), [](auto const& el) { if (el->confs.source.empty()) { return false; } return AudioSetConfigurationProvider::Get() ->CheckConfigurationIsDualBiDirSwb(*el); }), configs.end()); } // Note: For the only supported right now legacy software configuration // provider, we use the device group logic to match the proper // configuration with group capabilities. Note that this path only // supports the LC3 codec format. For the multicodec support we should // rely on the configuration matcher behind the AIDL interface. return provider(requirements, &configs); return GetLocalCodecConfigurations(requirements, provider); } bool CheckCodecConfigIsBiDirSwb(const AudioSetConfiguration& config) { Loading
system/bta/le_audio/codec_manager_test.cc +34 −0 Original line number Diff line number Diff line Loading @@ -265,6 +265,8 @@ void set_mock_offload_capabilities(const std::vector<AudioSetConfiguration>& cap } static constexpr char kPropLeAudioOffloadSupported[] = "ro.bluetooth.leaudio_offload.supported"; static constexpr char kPropLeAudioCodecExtensibility[] = "bluetooth.core.le_audio.codec_extension_aidl.enabled"; static constexpr char kPropLeAudioOffloadDisabled[] = "persist.bluetooth.leaudio_offload.disabled"; static constexpr char kPropLeAudioBidirSwbSupported[] = "bluetooth.leaudio.dual_bidirection_swb.supported"; Loading Loading @@ -823,6 +825,10 @@ public: // Allow for bidir SWB configurations osi_property_set_bool(kPropLeAudioBidirSwbSupported, true); // Codec extensibility disabled by default com::android::bluetooth::flags::provider_->leaudio_multicodec_aidl_support(false); osi_property_set_bool(kPropLeAudioCodecExtensibility, false); CodecManagerTestBase::SetUp(); } }; Loading @@ -837,6 +843,10 @@ public: // Do not allow for bidir SWB configurations osi_property_set_bool(kPropLeAudioBidirSwbSupported, false); // Codec extensibility disabled by default com::android::bluetooth::flags::provider_->leaudio_multicodec_aidl_support(false); osi_property_set_bool(kPropLeAudioCodecExtensibility, false); CodecManagerTestBase::SetUp(); } }; Loading Loading @@ -1295,4 +1305,28 @@ TEST_F(CodecManagerTestHost, test_dont_update_broadcast_offloader) { ASSERT_FALSE(was_called); } TEST_F(CodecManagerTestHost, test_dont_call_hal_for_config) { com::android::bluetooth::flags::provider_->leaudio_multicodec_aidl_support(true); osi_property_set_bool(kPropLeAudioCodecExtensibility, true); // Set the offloader capabilities std::vector<AudioSetConfiguration> offload_capabilities; set_mock_offload_capabilities(offload_capabilities); const std::vector<bluetooth::le_audio::btle_audio_codec_config_t> offloading_preference = {}; codec_manager->Start(offloading_preference); codec_manager->UpdateActiveUnicastAudioHalClient(mock_le_audio_source_hal_client_, mock_le_audio_sink_hal_client_, true); EXPECT_CALL(*mock_le_audio_source_hal_client_, GetUnicastConfig(_)).Times(0); codec_manager->GetCodecConfig( {.audio_context_type = types::LeAudioContextType::MEDIA}, [&](const CodecManager::UnicastConfigurationRequirements& /*requirements*/, const set_configurations::AudioSetConfigurations* /*confs*/) -> std::unique_ptr<set_configurations::AudioSetConfiguration> { // In this case the chosen configuration doesn't matter - select none return nullptr; }); } } // namespace bluetooth::le_audio