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

Commit 41cd3b2f authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Improve tracking cig state

With this patch, cig state is changed to enum so we can track if group
is idle, creating, created or removing.
Group shall not be removed while CIG is not in idle.
This patch also adds asserts to catch invalid behaviour

Bug: 226709330
Bug: 150670922
test: atest --host bluetooth_le_audio_test bluetooth_le_audio_client_test
sponsor: @jpawlowski
Change-Id: If3a14dbf3c8283748c2ac1c43a13c94d4568fd8f
parent 62337915
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -427,9 +427,9 @@ class LeAudioClientImpl : public LeAudioClient {
        return;
      }
    } else {
      LOG_ASSERT(id == group_id)
          << " group id missmatch? leaudio id: " << group_id
          << " groups module " << id;
      ASSERT_LOG(id == group_id,
                 " group id missmatch? leaudio id: %d, groups module %d",
                 group_id, id);
      new_group = aseGroups_.FindById(group_id);
      if (!new_group) {
        new_group = aseGroups_.Add(group_id);
@@ -438,6 +438,8 @@ class LeAudioClientImpl : public LeAudioClient {
      }
    }

    LOG_DEBUG("New group %p, id: %d", new_group, new_group->group_id_);

    /* If device was in the group and it was not removed by the application,
     * lets do it now
     */
@@ -483,7 +485,15 @@ class LeAudioClientImpl : public LeAudioClient {
  }

  void remove_group_if_possible(LeAudioDeviceGroup* group) {
    if (group && group->IsEmpty() && !group->cig_created_) {
    if (!group) {
      LOG_DEBUG("group is null");
      return;
    }
    LOG_DEBUG("Group %p, id: %d, size: %d, is cig_state %s", group,
              group->group_id_, group->Size(),
              ToString(group->cig_state_).c_str());
    if (group->IsEmpty() &&
        (group->cig_state_ == le_audio::types::CigState::NONE)) {
      aseGroups_.Remove(group->group_id_);
    }
  }
@@ -1774,8 +1784,7 @@ class LeAudioClientImpl : public LeAudioClient {
      return;
    }

    LOG(INFO) << __func__ << " attaching to group  "
              << leAudioDevice->group_id_;
    LOG_INFO("Attaching to group: %d", leAudioDevice->group_id_);

    /* Restore configuration */
    LeAudioDeviceGroup* group = aseGroups_.FindById(active_group_id_);
@@ -3113,17 +3122,19 @@ class LeAudioClientImpl : public LeAudioClient {
      case bluetooth::hci::iso_manager::kIsoEventCigOnCreateCmpl: {
        auto* evt = static_cast<cig_create_cmpl_evt*>(data);
        LeAudioDeviceGroup* group = aseGroups_.FindById(evt->cig_id);
        ASSERT_LOG(group, "Group id: %d is null", evt->cig_id);
        groupStateMachine_->ProcessHciNotifOnCigCreate(
            group, evt->status, evt->cig_id, evt->conn_handles);
      } break;
      case bluetooth::hci::iso_manager::kIsoEventCigOnRemoveCmpl: {
        auto* evt = static_cast<cig_remove_cmpl_evt*>(data);
        LeAudioDeviceGroup* group = aseGroups_.FindById(evt->cig_id);
        ASSERT_LOG(group, "Group id: %d is null", evt->cig_id);
        groupStateMachine_->ProcessHciNotifOnCigRemove(evt->status, group);
        remove_group_if_possible(group);
      } break;
      default:
        LOG(ERROR) << __func__ << " Invalid event " << int{event_type};
        LOG_ERROR("Invalid event %d", +event_type);
    }
  }

+1 −0
Original line number Diff line number Diff line
@@ -1212,6 +1212,7 @@ void LeAudioDeviceGroup::Dump(int fd) {
  stream << "    == Group id: " << group_id_ << " == \n"
         << "      state: " << GetState() << "\n"
         << "      target state: " << GetTargetState() << "\n"
         << "      cig state: " << cig_state_ << "\n"
         << "      number of devices: " << Size() << "\n"
         << "      number of connected devices: " << NumOfConnected() << "\n"
         << "      active context types: "
+2 −2
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ class LeAudioDevices {
class LeAudioDeviceGroup {
 public:
  const int group_id_;
  bool cig_created_;
  types::CigState cig_state_;

  struct stream_configuration stream_conf;

@@ -192,7 +192,7 @@ class LeAudioDeviceGroup {

  explicit LeAudioDeviceGroup(const int group_id)
      : group_id_(group_id),
        cig_created_(false),
        cig_state_(types::CigState::NONE),
        stream_conf({}),
        audio_directions_(0),
        transport_latency_mtos_us_(0),
+2 −2
Original line number Diff line number Diff line
@@ -634,7 +634,7 @@ class UnicastTestNoInit : public Test {
          streaming_groups[group->group_id_] = group;

          /* Assume CIG is created */
          group->cig_created_ = true;
          group->cig_state_ = le_audio::types::CigState::CREATED;

          do_in_main_thread(
              FROM_HERE, base::BindOnce(
@@ -700,7 +700,7 @@ class UnicastTestNoInit : public Test {
          }

          if (group->IsEmpty()) {
            group->cig_created_ = false;
            group->cig_state_ = le_audio::types::CigState::NONE;
            InjectCigRemoved(group->group_id_);
          }
        });
+9 −0
Original line number Diff line number Diff line
@@ -457,6 +457,15 @@ uint8_t GetMaxCodecFramesPerSduFromPac(const acs_ac_record* pac) {
}

namespace types {
std::ostream& operator<<(std::ostream& os, const types::CigState& state) {
  static const char* char_value_[4] = {"NONE", "CREATING", "CREATED",
                                       "REMOVING"};

  os << char_value_[static_cast<uint8_t>(state)] << " ("
     << "0x" << std::setfill('0') << std::setw(2) << static_cast<int>(state)
     << ")";
  return os;
}
std::ostream& operator<<(std::ostream& os, const types::AseState& state) {
  static const char* char_value_[7] = {
      "IDLE",      "CODEC_CONFIGURED", "QOS_CONFIGURED", "ENABLING",
Loading