Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57943ba4 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

LeAudio: Configuration provider dependency inversion - Part 2

Part 2: unified SWB API

Codec Manager will provide a common interface to managing codecs, codec
configurations and their porperties (like SWB support), regardles of the
audio session type and codec location. This change moves the SWB checks
under the Codec Manager API so that the Unicast code would simply call
to the manager and not have to check for codec location and take
different actions based on that.

Bug: 308428860
Bug: 295972694
Test: atest --host bluetooth_le_audio_test bluetooth_le_audio_client_test bluetooth_test_broadcaster bluetooth_test_broadcaster_state_machine bluetooth_le_audio_codec_manager_test
Flag: EXEMPT; refactor for the multicodec support - verified with unit tests and manual testing
Change-Id: I54da33bc57d72088c9b04e4e41a784d7a31d6fb7
parent 4307070f
Loading
Loading
Loading
Loading
+31 −5
Original line number Diff line number Diff line
@@ -118,6 +118,8 @@ struct codec_manager_impl {
  }
  void start(
      const std::vector<btle_audio_codec_config_t>& offloading_preference) {
    dual_bidirection_swb_supported_ = osi_property_get_bool(
        "bluetooth.leaudio.dual_bidirection_swb.supported", false);
    bluetooth::le_audio::AudioSetConfigurationProvider::Initialize(
        GetCodecLocation());
    UpdateOffloadCapability(offloading_preference);
@@ -133,8 +135,16 @@ struct codec_manager_impl {
  }
  CodecLocation GetCodecLocation(void) const { return codec_location_; }

  bool IsOffloadDualBiDirSwbSupported(void) const {
  bool IsDualBiDirSwbSupported(void) const {
    if (GetCodecLocation() == CodecLocation::ADSP) {
      // Whether dual bidirection swb is supported by property and for offload
      return offload_dual_bidirection_swb_supported_;
    } else if (GetCodecLocation() == CodecLocation::HOST) {
      // Whether dual bidirection swb is supported for software
      return dual_bidirection_swb_supported_;
    }

    return false;
  }

  std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
@@ -195,6 +205,11 @@ struct codec_manager_impl {
               : nullptr;
  }

  bool CheckCodecConfigIsBiDirSwb(const AudioSetConfiguration& config) {
    return AudioSetConfigurationProvider::Get()->CheckConfigurationIsBiDirSwb(
        config);
  }

  void UpdateSupportedBroadcastConfig(
      const std::vector<AudioSetConfiguration>& adsp_capabilities) {
    LOG_INFO("UpdateSupportedBroadcastConfig");
@@ -782,7 +797,8 @@ struct codec_manager_impl {
                                           adsp_capabilities)) {
          LOG(INFO) << "Offload supported conf, context type: " << (int)ctx_type
                    << ", settings -> " << software_audio_set_conf->name;
          if (AudioSetConfigurationProvider::Get()
          if (dual_bidirection_swb_supported_ &&
              AudioSetConfigurationProvider::Get()
                  ->CheckConfigurationIsDualBiDirSwb(
                      *software_audio_set_conf)) {
            offload_dual_bidirection_swb_supported_ = true;
@@ -799,6 +815,7 @@ struct codec_manager_impl {
  CodecLocation codec_location_ = CodecLocation::HOST;
  bool offload_enable_ = false;
  bool offload_dual_bidirection_swb_supported_ = false;
  bool dual_bidirection_swb_supported_ = false;
  types::BidirectionalPair<offloader_stream_maps_t> offloader_stream_maps;
  std::vector<bluetooth::le_audio::broadcast_offload_config>
      supported_broadcast_config;
@@ -854,12 +871,12 @@ types::CodecLocation CodecManager::GetCodecLocation(void) const {
  return pimpl_->codec_manager_impl_->GetCodecLocation();
}

bool CodecManager::IsOffloadDualBiDirSwbSupported(void) const {
bool CodecManager::IsDualBiDirSwbSupported(void) const {
  if (!pimpl_->IsRunning()) {
    return false;
  }

  return pimpl_->codec_manager_impl_->IsOffloadDualBiDirSwbSupported();
  return pimpl_->codec_manager_impl_->IsDualBiDirSwbSupported();
}

std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
@@ -900,6 +917,15 @@ const AudioSetConfigurations* CodecManager::GetOffloadCodecConfig(
  return nullptr;
}

bool CodecManager::CheckCodecConfigIsBiDirSwb(
    const set_configurations::AudioSetConfiguration& config) const {
  if (pimpl_->IsRunning()) {
    return pimpl_->codec_manager_impl_->CheckCodecConfigIsBiDirSwb(config);
  }

  return false;
}

std::unique_ptr<broadcaster::BroadcastConfiguration>
CodecManager::GetBroadcastConfig(
    const std::vector<std::pair<types::LeAudioContextType, uint8_t>>&
+4 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ class CodecManager {
                 offloading_preference);
  void Stop(void);
  virtual types::CodecLocation GetCodecLocation(void) const;
  virtual bool IsOffloadDualBiDirSwbSupported(void) const;
  virtual bool IsDualBiDirSwbSupported(void) const;
  virtual void UpdateCisConfiguration(
      const std::vector<struct types::cis>& cises,
      const stream_parameters& stream_params, uint8_t direction);
@@ -81,6 +81,9 @@ class CodecManager {
      AudioSetConfigurations*
      GetOffloadCodecConfig(
          ::bluetooth::le_audio::types::LeAudioContextType ctx_type);
  virtual bool CheckCodecConfigIsBiDirSwb(
      const ::bluetooth::le_audio::set_configurations::AudioSetConfiguration&
          config) const;
  virtual std::unique_ptr<broadcaster::BroadcastConfiguration>
  GetBroadcastConfig(
      const std::vector<
+4 −12
Original line number Diff line number Diff line
@@ -1345,18 +1345,10 @@ bool LeAudioDeviceGroup::IsAudioSetConfigurationSupported(
   * when all devices in the group are connected.
   */
  bool dual_bidirection_swb_supported_ =
      AudioSetConfigurationProvider::Get()->IsDualBiDirSwbSupported();
  if (Size() > 1 &&
      AudioSetConfigurationProvider::Get()->CheckConfigurationIsBiDirSwb(
      CodecManager::GetInstance()->IsDualBiDirSwbSupported();
  if (Size() > 1 && CodecManager::GetInstance()->CheckCodecConfigIsBiDirSwb(
                        *audio_set_conf)) {
    if (!dual_bidirection_swb_supported_ ||
        (CodecManager::GetInstance()->GetCodecLocation() ==
             types::CodecLocation::ADSP &&
         !CodecManager::GetInstance()->IsOffloadDualBiDirSwbSupported())) {
      /* two conditions
       * 1) dual bidirection swb is not supported for both software/offload
       * 2) offload not supported
       */
    if (!dual_bidirection_swb_supported_) {
      return false;
    }
  }
+0 −1
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ class AudioSetConfigurationProvider {
  static void Cleanup();
  virtual const set_configurations::AudioSetConfigurations* GetConfigurations(
      ::bluetooth::le_audio::types::LeAudioContextType content_type) const;
  virtual bool IsDualBiDirSwbSupported(void) const;
  virtual bool CheckConfigurationIsBiDirSwb(
      const set_configurations::AudioSetConfiguration& set_configuration) const;
  virtual bool CheckConfigurationIsDualBiDirSwb(
+0 −32
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@
#include "audio_hal_client/audio_hal_client.h"
#include "audio_set_configurations_generated.h"
#include "audio_set_scenarios_generated.h"
#include "codec_manager.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/util.h"
#include "le_audio_set_configuration_provider.h"
@@ -41,7 +40,6 @@ using bluetooth::le_audio::set_configurations::SetConfiguration;
using bluetooth::le_audio::types::LeAudioContextType;

namespace bluetooth::le_audio {
using ::bluetooth::le_audio::CodecManager;

#ifdef __ANDROID__
static const std::vector<
@@ -167,10 +165,6 @@ struct AudioSetConfigurationProviderJson {
    return nullptr;
  };

  bool IsDualBiDirSwbSupported(void) const {
    return dual_bidirection_swb_supported_;
  }

 private:
  /* Codec configurations */
  std::map<std::string, const AudioSetConfiguration> configurations_;
@@ -684,24 +678,6 @@ AudioSetConfigurationProvider* AudioSetConfigurationProvider::Get() {
const set_configurations::AudioSetConfigurations*
AudioSetConfigurationProvider::GetConfigurations(
    ::bluetooth::le_audio::types::LeAudioContextType content_type) const {
  if (CodecManager::GetInstance()->GetCodecLocation() ==
      types::CodecLocation::ADSP) {
    LOG_VERBOSE("Get offload config for the context type: %d",
                (int)content_type);
    const AudioSetConfigurations* offload_confs =
        CodecManager::GetInstance()->GetOffloadCodecConfig(content_type);

    if (offload_confs != nullptr && !(*offload_confs).empty()) {
      return offload_confs;
    }

    // TODO: Need to have a mechanism to switch to software session if offload
    // doesn't support.
  }

  LOG_VERBOSE("Get software config for the context type: %d",
              (int)content_type);

  if (pimpl_->IsRunning())
    return pimpl_->config_provider_impl_->GetConfigurationsByContextType(
        content_type);
@@ -745,12 +721,4 @@ bool AudioSetConfigurationProvider::CheckConfigurationIsDualBiDirSwb(
             bluetooth::le_audio::types::kLeAudioDirectionBoth;
}

bool AudioSetConfigurationProvider::IsDualBiDirSwbSupported(void) const {
  if (pimpl_->IsRunning()) {
    return pimpl_->config_provider_impl_->IsDualBiDirSwbSupported();
  }

  return false;
}

}  // namespace bluetooth::le_audio
Loading