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

Commit 24d909eb authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Improve enabling stream

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

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

Change-Id: Icfdd55e613a4a6c7dd995b9d83f2084fc0fd95d9
parent b255f3b6
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -347,6 +347,18 @@ bool LeAudioDeviceGroup::IsDeviceInTheGroup(LeAudioDevice* leAudioDevice) {
  return true;
}

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

  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
@@ -295,6 +295,7 @@ class LeAudioDeviceGroup {
  bool IsDeviceInTheGroup(LeAudioDevice* leAudioDevice);
  bool HaveAllActiveDevicesAsesTheSameState(types::AseState state);
  bool IsGroupStreamReady(void);
  bool IsGroupReadyToCreateStream(void);
  bool HaveAllCisesDisconnected(void);
  uint8_t GetFirstFreeCisId(void);
  uint8_t GetFirstFreeCisId(types::CisType cis_type);
+30 −12
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {

        /* All ASEs should aim to achieve target state */
        SetTargetState(group, AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING);
        PrepareAndSendEnable(leAudioDevice);
        PrepareAndSendEnableToTheGroup(group);
        break;
      }

@@ -1928,7 +1928,7 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
          leAudioDevice = group->GetFirstActiveDevice();
          LOG_ASSERT(leAudioDevice)
              << __func__ << " Shouldn't be called without an active device.";
          PrepareAndSendEnable(leAudioDevice);
          PrepareAndSendEnableToTheGroup(group);
        }

        break;
@@ -1994,6 +1994,22 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
    }
  }

  void PrepareAndSendEnableToTheGroup(LeAudioDeviceGroup* group) {
    LOG_INFO("group_id: %d", group->group_id_);

    auto leAudioDevice = group->GetFirstActiveDevice();
    if (!leAudioDevice) {
      LOG_ERROR("No active for the group,");
      StopStream(group);
      return;
    }

    for (; leAudioDevice;
         leAudioDevice = group->GetNextActiveDevice(leAudioDevice)) {
      PrepareAndSendEnable(leAudioDevice);
    }
  }

  void PrepareAndSendEnable(LeAudioDevice* leAudioDevice) {
    struct le_audio::client_parser::ascs::ctp_enable conf;
    std::vector<struct le_audio::client_parser::ascs::ctp_enable> confs;
@@ -2277,7 +2293,7 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
        }

        if (leAudioDevice->IsReadyToCreateStream())
          ProcessGroupEnable(group, leAudioDevice);
          ProcessGroupEnable(group);

        break;

@@ -2332,7 +2348,7 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
        }

        if (leAudioDevice->IsReadyToCreateStream())
          ProcessGroupEnable(group, leAudioDevice);
          ProcessGroupEnable(group);

        break;

@@ -2532,14 +2548,18 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
    }
  }

  void ProcessGroupEnable(LeAudioDeviceGroup* group, LeAudioDevice* device) {
    /* Enable ASEs for next device in group. */
    LeAudioDevice* deviceNext = group->GetNextActiveDevice(device);
    if (deviceNext) {
      PrepareAndSendEnable(deviceNext);
  void ProcessGroupEnable(LeAudioDeviceGroup* group) {
    if (group->GetState() != AseState::BTA_LE_AUDIO_ASE_STATE_ENABLING) {
      if (!group->IsGroupReadyToCreateStream()) {
        LOG_DEBUG(
            "Waiting for more ASEs to be in enabling or directly in streaming "
            "state");
        return;
      }

      group->SetState(AseState::BTA_LE_AUDIO_ASE_STATE_ENABLING);
    }

    /* At this point all of the active ASEs within group are enabled. The server
     * might perform autonomous state transition for Sink ASE and skip Enabling
     * state notification and transit to Streaming directly. So check the group
@@ -2547,8 +2567,6 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
    if (group->HaveAllActiveDevicesAsesTheSameState(
            AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING)) {
      group->SetState(AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING);
    } else {
      group->SetState(AseState::BTA_LE_AUDIO_ASE_STATE_ENABLING);
    }

    if (group->GetTargetState() == AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {