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

Commit 9c224f62 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Improve Codec Configure operation

With this patch, group state machine will send Codec Config
command simultaneously to all active devices.

Bug: 265501806
Test: atest bluetooth_le_audio_test
Test: atest BluetoothInstrumentationTests
Tag: #feature

Change-Id: If750f680a16f8c95a2223d4a2a0293833feddb62
parent fef336e7
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -371,6 +371,18 @@ bool LeAudioDeviceGroup::IsGroupReadyToSuspendStream(void) {
  return iter == leAudioDevices_.end();
}

bool LeAudioDeviceGroup::HaveAnyActiveDeviceInUnconfiguredState() {
  auto iter =
      std::find_if(leAudioDevices_.begin(), leAudioDevices_.end(), [](auto& d) {
        if (d.expired())
          return false;
        else
          return (((d.lock()).get())->HaveAnyUnconfiguredAses());
      });

  return iter != leAudioDevices_.end();
}

bool LeAudioDeviceGroup::HaveAllActiveDevicesAsesTheSameState(AseState state) {
  auto iter = std::find_if(
      leAudioDevices_.begin(), leAudioDevices_.end(), [&state](auto& d) {
+1 −0
Original line number Diff line number Diff line
@@ -294,6 +294,7 @@ class LeAudioDeviceGroup {
      types::AudioStreamDataPathState data_path_state);
  bool IsDeviceInTheGroup(LeAudioDevice* leAudioDevice);
  bool HaveAllActiveDevicesAsesTheSameState(types::AseState state);
  bool HaveAnyActiveDeviceInUnconfiguredState();
  bool IsGroupStreamReady(void);
  bool IsGroupReadyToCreateStream(void);
  bool IsGroupReadyToSuspendStream(void);
+86 −78
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
        group->CigGenerateCisIds(context_type);
        /* All ASEs should aim to achieve target state */
        SetTargetState(group, AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING);
        PrepareAndSendCodecConfigure(group, group->GetFirstActiveDevice());
        PrepareAndSendCodecConfigToTheGroup(group);
        break;

      case AseState::BTA_LE_AUDIO_ASE_STATE_QOS_CONFIGURED: {
@@ -263,9 +263,7 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {

    group->CigGenerateCisIds(context_type);
    SetTargetState(group, AseState::BTA_LE_AUDIO_ASE_STATE_CODEC_CONFIGURED);
    PrepareAndSendCodecConfigure(group, group->GetFirstActiveDevice());

    return true;
    return PrepareAndSendCodecConfigToTheGroup(group);
  }

  void SuspendStream(LeAudioDeviceGroup* group) override {
@@ -1552,6 +1550,21 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
    }
  }

  bool PrepareAndSendCodecConfigToTheGroup(LeAudioDeviceGroup* group) {
    LOG_INFO("group_id: %d", group->group_id_);
    auto leAudioDevice = group->GetFirstActiveDevice();
    if (!leAudioDevice) {
      LOG(ERROR) << __func__ << ", no active devices in group";
      return false;
    }

    for (; leAudioDevice;
         leAudioDevice = group->GetNextActiveDevice(leAudioDevice)) {
      PrepareAndSendCodecConfigure(group, leAudioDevice);
    }
    return true;
  }

  void PrepareAndSendCodecConfigure(LeAudioDeviceGroup* group,
                                    LeAudioDevice* leAudioDevice) {
    struct le_audio::client_parser::ascs::ctp_codec_conf conf;
@@ -1608,8 +1621,6 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
          ase->id = arh.id;
        }

        LeAudioDevice* leAudioDeviceNext;

        struct le_audio::client_parser::ascs::ase_codec_configured_state_params
            rsp;

@@ -1683,12 +1694,12 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
          return;
        }

        leAudioDeviceNext = group->GetNextActiveDevice(leAudioDevice);

        /* Configure ASEs for next device in group */
        if (leAudioDeviceNext) {
          PrepareAndSendCodecConfigure(group, leAudioDeviceNext);
        } else {
        if (group->HaveAnyActiveDeviceInUnconfiguredState()) {
          LOG_DEBUG("Waiting for all the ASES in the Configured state");
          return;
        }

        /* Last node configured, process group to codec configured state */
        group->SetState(AseState::BTA_LE_AUDIO_ASE_STATE_CODEC_CONFIGURED);

@@ -1732,8 +1743,6 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
                  ToString(group->GetState()).c_str(),
                  ToString(group->GetTargetState()).c_str());
        StopStream(group);
          return;
        }

        break;
      }
@@ -1784,13 +1793,13 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
          return;
        }

        LeAudioDevice* leAudioDeviceNext =
            group->GetNextActiveDevice(leAudioDevice);
        if (group->HaveAnyActiveDeviceInUnconfiguredState()) {
          LOG_DEBUG(
              "Waiting for all the devices to be configured for group id %d",
              group->group_id_);
          return;
        }

        /* Configure ASEs for next device in group */
        if (leAudioDeviceNext) {
          PrepareAndSendCodecConfigure(group, leAudioDeviceNext);
        } else {
        /* Last node configured, process group to codec configured state */
        group->SetState(AseState::BTA_LE_AUDIO_ASE_STATE_CODEC_CONFIGURED);

@@ -1820,7 +1829,6 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
        LOG_ERROR(", Autonomouse change, from: %s to %s",
                  ToString(group->GetState()).c_str(),
                  ToString(group->GetTargetState()).c_str());
        }

        break;
      }