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

Commit 4805b64f authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Improve finding max CISes count needed

Previous patch introduced function which allows to find maximum number
of CISes we need to cover given context type. This is in order prepare
CIG already as big so the late connected devices can be joined to the
group without changing CIG.

This patch improves a bit calculation of the CISes by limiting searching
the configuration only to the ones with specific strategy.

Strategy is related to the device topology e.g. earbuds using TWS
topology (only one device is connected), earbuds using new Le Audio
style (two earbuds connected to phone independly), banded headphones.
This strategy can be found by looking into device allocation, channel
count and group size.

This will help to save controller resources, as combining all those
scenarios could produce lot of CIS requirements.

Bug: 231084798
Bug: 238961038
Bug: 239651157
Sponsor: @siyuanh
Test: atest BluetoothInstrumentationTests
Tag: #feature
Merged-In: I52f671e7fa39f91cc562de2501c5d68665e5b4c8
Change-Id: I52f671e7fa39f91cc562de2501c5d68665e5b4c8
(cherry picked from commit f125a890)
parent 78df72fe
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -839,6 +839,33 @@ uint8_t LeAudioDeviceGroup::GetFirstFreeCisId(CisType cis_type) {
  return kInvalidCisId;
}

types::LeAudioConfigurationStrategy LeAudioDeviceGroup::GetGroupStrategy(void) {
  /* Simple strategy picker */
  LOG_INFO(" Group %d size %d", group_id_, Size());
  if (Size() > 1) {
    return types::LeAudioConfigurationStrategy::MONO_ONE_CIS_PER_DEVICE;
  }

  LOG_INFO("audio location 0x%04lx", snk_audio_locations_.to_ulong());
  if (!(snk_audio_locations_.to_ulong() &
        codec_spec_conf::kLeAudioLocationAnyLeft) ||
      !(snk_audio_locations_.to_ulong() &
        codec_spec_conf::kLeAudioLocationAnyRight)) {
    return types::LeAudioConfigurationStrategy::MONO_ONE_CIS_PER_DEVICE;
  }

  auto device = GetFirstDevice();
  auto channel_cnt =
      device->GetLc3SupportedChannelCount(types::kLeAudioDirectionSink);
  LOG_INFO("Channel count for group %d is %d (device %s)", group_id_,
           channel_cnt, device->address_.ToString().c_str());
  if (channel_cnt == 1) {
    return types::LeAudioConfigurationStrategy::STEREO_TWO_CISES_PER_DEVICE;
  }

  return types::LeAudioConfigurationStrategy::STEREO_ONE_CIS_PER_DEVICE;
}

void LeAudioDeviceGroup::CigGenerateCisIds(
    types::LeAudioContextType context_type) {
  LOG_INFO("Group %p, group_id: %d, context_type: %s", this, group_id_,
@@ -855,8 +882,8 @@ void LeAudioDeviceGroup::CigGenerateCisIds(
  uint8_t cis_count_bidir = 0;
  uint8_t cis_count_unidir_sink = 0;
  uint8_t cis_count_unidir_source = 0;
  get_cis_count(confs, &cis_count_bidir, &cis_count_unidir_sink,
                &cis_count_unidir_source);
  get_cis_count(confs, GetGroupStrategy(), &cis_count_bidir,
                &cis_count_unidir_sink, &cis_count_unidir_source);

  uint8_t idx = 0;
  while (cis_count_bidir > 0) {
+1 −0
Original line number Diff line number Diff line
@@ -227,6 +227,7 @@ class LeAudioDeviceGroup {
  LeAudioDevice* GetFirstDevice(void);
  LeAudioDevice* GetFirstDeviceWithActiveContext(
      types::LeAudioContextType context_type);
  le_audio::types::LeAudioConfigurationStrategy GetGroupStrategy(void);
  LeAudioDevice* GetNextDevice(LeAudioDevice* leAudioDevice);
  LeAudioDevice* GetNextDeviceWithActiveContext(
      LeAudioDevice* leAudioDevice, types::LeAudioContextType context_type);
+13 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ static uint8_t min_req_devices_cnt(
}

void get_cis_count(const AudioSetConfigurations* audio_set_confs,
                   types::LeAudioConfigurationStrategy strategy,
                   uint8_t* cis_count_bidir, uint8_t* cis_count_unidir_sink,
                   uint8_t* cis_count_unidir_source) {
  for (auto audio_set_conf : *audio_set_confs) {
@@ -78,7 +79,15 @@ void get_cis_count(const AudioSetConfigurations* audio_set_confs,
    uint8_t unidir_sink_count = 0;
    uint8_t unidir_source_count = 0;

    LOG_INFO("%s ", audio_set_conf->name.c_str());
    bool stategy_mismatch = false;
    for (auto ent : (*audio_set_conf).confs) {
      if (ent.strategy != strategy) {
        LOG_INFO("Strategy does not match (%d != %d)- skip this configuration",
                 static_cast<int>(ent.strategy), static_cast<int>(strategy));
        stategy_mismatch = true;
        break;
      }
      if (ent.direction == kLeAudioDirectionSink) {
        snk_src_pair.first += ent.device_cnt;
      }
@@ -87,6 +96,10 @@ void get_cis_count(const AudioSetConfigurations* audio_set_confs,
      }
    }

    if (stategy_mismatch) {
      continue;
    }

    bidir_count = std::min(snk_src_pair.first, snk_src_pair.second);
    unidir_sink_count = ((snk_src_pair.first - bidir_count) > 0)
                            ? (snk_src_pair.first - bidir_count)
+1 −0
Original line number Diff line number Diff line
@@ -667,6 +667,7 @@ static constexpr uint32_t kChannelAllocationStereo =

/* Declarations */
void get_cis_count(const AudioSetConfigurations* audio_set_configurations,
                   types::LeAudioConfigurationStrategy strategy,
                   uint8_t* cis_count_bidir, uint8_t* cis_count_unidir_sink,
                   uint8_t* cis_count_unidir_source);
bool check_if_may_cover_scenario(