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

Commit ff603f4b authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Automerger Merge Worker
Browse files

Merge changes Id461e2d4,Iab51e88e,Ie83da880 am: c3bffe09 am: b6818cc5

parents f10bd97f b6818cc5
Loading
Loading
Loading
Loading
+115 −39
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
#include <base/bind.h>
#include <base/strings/string_number_conversions.h>

#include <deque>

#include "advertise_data_parser.h"
#include "audio_hal_interface/le_audio_software.h"
#include "bta/csis/csis_types.h"
@@ -66,6 +68,7 @@ using bluetooth::le_audio::GroupStatus;
using bluetooth::le_audio::GroupStreamStatus;
using le_audio::CodecManager;
using le_audio::ContentControlIdKeeper;
using le_audio::DeviceConnectState;
using le_audio::LeAudioDevice;
using le_audio::LeAudioDeviceGroup;
using le_audio::LeAudioDeviceGroups;
@@ -471,7 +474,7 @@ class LeAudioClientImpl : public LeAudioClient {
      if (group_id == bluetooth::groups::kGroupUnknown) return;

      LOG(INFO) << __func__ << "Set member adding ...";
      leAudioDevices_.Add(address, true);
      leAudioDevices_.Add(address, DeviceConnectState::CONNECTING_BY_USER);
      leAudioDevice = leAudioDevices_.FindByAddress(address);
    } else {
      if (leAudioDevice->group_id_ != bluetooth::groups::kGroupUnknown) {
@@ -739,13 +742,15 @@ class LeAudioClientImpl : public LeAudioClient {
      return false;
    }

    if (group->GetState() != AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
      stream_setup_start_timestamp_ =
          bluetooth::common::time_get_os_boottime_us();
    }

    bool result = groupStateMachine_->StartStream(
        group, static_cast<LeAudioContextType>(final_context_type),
        adjusted_metadata_context_type,
        GetAllCcids(adjusted_metadata_context_type));
    if (result)
      stream_setup_start_timestamp_ =
          bluetooth::common::time_get_os_boottime_us();

    return result;
  }
@@ -988,7 +993,7 @@ class LeAudioClientImpl : public LeAudioClient {

    if (leAudioDevice->conn_id_ != GATT_INVALID_CONN_ID) {
      Disconnect(address);
      leAudioDevice->removing_device_ = true;
      leAudioDevice->SetConnectionState(DeviceConnectState::REMOVING);
      return;
    }

@@ -1007,9 +1012,10 @@ class LeAudioClientImpl : public LeAudioClient {
  void Connect(const RawAddress& address) override {
    LeAudioDevice* leAudioDevice = leAudioDevices_.FindByAddress(address);
    if (!leAudioDevice) {
      leAudioDevices_.Add(address, true);
      leAudioDevices_.Add(address, DeviceConnectState::CONNECTING_BY_USER);

    } else {
      leAudioDevice->connecting_actively_ = true;
      leAudioDevice->SetConnectionState(DeviceConnectState::CONNECTING_BY_USER);

      le_audio::MetricsCollector::Get()->OnConnectionStateChanged(
          leAudioDevice->group_id_, address, ConnectionState::CONNECTING,
@@ -1058,7 +1064,7 @@ class LeAudioClientImpl : public LeAudioClient {
        source_audio_location, sink_supported_context_types,
        source_supported_context_types);

    leAudioDevices_.Add(address, false);
    leAudioDevices_.Add(address, DeviceConnectState::DISCONNECTED);
    leAudioDevice = leAudioDevices_.FindByAddress(address);

    int group_id = DeviceGroups::Get()->GetGroupId(
@@ -1105,6 +1111,9 @@ class LeAudioClientImpl : public LeAudioClient {
    }

    if (autoconnect) {
      leAudioDevice->SetConnectionState(
          DeviceConnectState::CONNECTING_AUTOCONNECT);
      leAudioDevice->autoconnect_flag_ = true;
      BTA_GATTC_Open(gatt_if_, address, false, false);
    }
  }
@@ -1150,6 +1159,8 @@ class LeAudioClientImpl : public LeAudioClient {
               << " to background connect to connected group: "
               << leAudioDevice->group_id_;

    leAudioDevice->SetConnectionState(
        DeviceConnectState::CONNECTING_AUTOCONNECT);
    BTA_GATTC_Open(gatt_if_, leAudioDevice->address_, false, false);
  }

@@ -1163,9 +1174,9 @@ class LeAudioClientImpl : public LeAudioClient {
    }

    /* cancel pending direct connect */
    if (leAudioDevice->connecting_actively_) {
    if (leAudioDevice->GetConnectionState() ==
        DeviceConnectState::CONNECTING_BY_USER) {
      BTA_GATTC_CancelOpen(gatt_if_, address, true);
      leAudioDevice->connecting_actively_ = false;
    }

    /* Removes all registrations for connection */
@@ -1175,6 +1186,7 @@ class LeAudioClientImpl : public LeAudioClient {
      /* User is disconnecting the device, we shall remove the autoconnect flag
       */
      btif_storage_set_leaudio_autoconnect(address, false);
      leAudioDevice->autoconnect_flag_ = false;

      auto group = aseGroups_.FindById(leAudioDevice->group_id_);
      if (group &&
@@ -1200,6 +1212,8 @@ class LeAudioClientImpl : public LeAudioClient {
      return;
    }

    leAudioDevice->SetConnectionState(DeviceConnectState::DISCONNECTING);

    if (acl_force_disconnect) {
     leAudioDevice->DisconnectAcl();
     return;
@@ -1509,7 +1523,13 @@ class LeAudioClientImpl : public LeAudioClient {

    if (status != GATT_SUCCESS) {
      /* autoconnect connection failed, that's ok */
      if (!leAudioDevice->connecting_actively_) return;
      if (leAudioDevice->GetConnectionState() ==
          DeviceConnectState::CONNECTING_AUTOCONNECT) {
        leAudioDevice->SetConnectionState(DeviceConnectState::DISCONNECTED);
        return;
      }

      leAudioDevice->SetConnectionState(DeviceConnectState::DISCONNECTED);

      LOG(ERROR) << "Failed to connect to LeAudio leAudioDevice, status: "
                 << +status;
@@ -1527,7 +1547,15 @@ class LeAudioClientImpl : public LeAudioClient {

    BTM_RequestPeerSCA(leAudioDevice->address_, transport);

    leAudioDevice->connecting_actively_ = false;
    if (leAudioDevice->GetConnectionState() ==
        DeviceConnectState::CONNECTING_AUTOCONNECT) {
      leAudioDevice->SetConnectionState(
          DeviceConnectState::CONNECTED_AUTOCONNECT_GETTING_READY);
    } else {
      leAudioDevice->SetConnectionState(
          DeviceConnectState::CONNECTED_BY_USER_GETTING_READY);
    }

    leAudioDevice->conn_id_ = conn_id;
    leAudioDevice->mtu_ = mtu;

@@ -1633,13 +1661,17 @@ class LeAudioClientImpl : public LeAudioClient {
    if (status != BTM_SUCCESS) {
      LOG(ERROR) << "Encryption failed"
                 << " status: " << int{status};
      BTA_GATTC_Close(leAudioDevice->conn_id_);
      if (leAudioDevice->connecting_actively_) {
      if (leAudioDevice->GetConnectionState() ==
          DeviceConnectState::CONNECTED_BY_USER_GETTING_READY) {
        callbacks_->OnConnectionState(ConnectionState::DISCONNECTED, address);
        le_audio::MetricsCollector::Get()->OnConnectionStateChanged(
            leAudioDevice->group_id_, address, ConnectionState::CONNECTED,
            le_audio::ConnectionStatus::FAILED);
      }

      leAudioDevice->SetConnectionState(DeviceConnectState::DISCONNECTING);

      BTA_GATTC_Close(leAudioDevice->conn_id_);
      return;
    }

@@ -1694,7 +1726,7 @@ class LeAudioClientImpl : public LeAudioClient {
        leAudioDevice->group_id_, address, ConnectionState::DISCONNECTED,
        le_audio::ConnectionStatus::SUCCESS);

    if (leAudioDevice->removing_device_) {
    if (leAudioDevice->GetConnectionState() == DeviceConnectState::REMOVING) {
      if (leAudioDevice->group_id_ != bluetooth::groups::kGroupUnknown) {
        auto group = aseGroups_.FindById(leAudioDevice->group_id_);
        group_remove_node(group, address, true);
@@ -1704,7 +1736,11 @@ class LeAudioClientImpl : public LeAudioClient {
    }
    /* Attempt background re-connect if disconnect was not intended locally */
    if (reason != GATT_CONN_TERMINATE_LOCAL_HOST) {
      leAudioDevice->SetConnectionState(
          DeviceConnectState::CONNECTING_AUTOCONNECT);
      BTA_GATTC_Open(gatt_if_, address, false, false);
    } else {
      leAudioDevice->SetConnectionState(DeviceConnectState::DISCONNECTED);
    }
  }

@@ -2223,6 +2259,8 @@ class LeAudioClientImpl : public LeAudioClient {
       * codec configuration */
      group->SetPendingConfiguration();
      groupStateMachine_->StopStream(group);
      stream_setup_start_timestamp_ =
          bluetooth::common::time_get_os_boottime_us();
      return;
    }

@@ -2230,6 +2268,9 @@ class LeAudioClientImpl : public LeAudioClient {
      LOG_WARN("Could not add device %s to the group %d streaming. ",
               leAudioDevice->address_.ToString().c_str(), group->group_id_);
      scheduleAttachDeviceToTheStream(leAudioDevice->address_);
    } else {
      stream_setup_start_timestamp_ =
          bluetooth::common::time_get_os_boottime_us();
    }
  }

@@ -2258,22 +2299,29 @@ class LeAudioClientImpl : public LeAudioClient {
  }

  void connectionReady(LeAudioDevice* leAudioDevice) {
    LOG_DEBUG("%s,  %s", leAudioDevice->address_.ToString().c_str(),
              bluetooth::common::ToString(leAudioDevice->GetConnectionState())
                  .c_str());
    callbacks_->OnConnectionState(ConnectionState::CONNECTED,
                                  leAudioDevice->address_);

    if (leAudioDevice->group_id_ != bluetooth::groups::kGroupUnknown) {
      LeAudioDeviceGroup* group = aseGroups_.FindById(leAudioDevice->group_id_);
      UpdateContextAndLocations(group, leAudioDevice);
      AttachToStreamingGroupIfNeeded(leAudioDevice);
    }

    if (leAudioDevice->first_connection_) {
    if (leAudioDevice->GetConnectionState() ==
            DeviceConnectState::CONNECTED_BY_USER_GETTING_READY &&
        (leAudioDevice->autoconnect_flag_ == false)) {
      btif_storage_set_leaudio_autoconnect(leAudioDevice->address_, true);
      leAudioDevice->first_connection_ = false;
      leAudioDevice->autoconnect_flag_ = true;
    }

    leAudioDevice->SetConnectionState(DeviceConnectState::CONNECTED);
    le_audio::MetricsCollector::Get()->OnConnectionStateChanged(
        leAudioDevice->group_id_, leAudioDevice->address_,
        ConnectionState::CONNECTED, le_audio::ConnectionStatus::SUCCESS);

    if (leAudioDevice->group_id_ != bluetooth::groups::kGroupUnknown) {
      LeAudioDeviceGroup* group = aseGroups_.FindById(leAudioDevice->group_id_);
      UpdateContextAndLocations(group, leAudioDevice);
      AttachToStreamingGroupIfNeeded(leAudioDevice);
    }
  }

  bool IsAseAcceptingAudioData(struct ase* ase) {
@@ -2838,16 +2886,16 @@ class LeAudioClientImpl : public LeAudioClient {
    std::stringstream stream;
    if (print_audio_state) {
      if (sender) {
        stream << "   audio sender state: " << audio_sender_state_ << "\n";
        stream << "\taudio sender state: " << audio_sender_state_ << "\n";
      } else {
        stream << "   audio receiver state: " << audio_receiver_state_ << "\n";
        stream << "\taudio receiver state: " << audio_receiver_state_ << "\n";
      }
    }

    stream << "   num_channels: " << +conf->num_channels << "\n"
           << "   sample rate: " << +conf->sample_rate << "\n"
           << "   bits pers sample: " << +conf->bits_per_sample << "\n"
           << "   data_interval_us: " << +conf->data_interval_us << "\n";
    stream << "\tsample rate: " << +conf->sample_rate
           << ",\tchan: " << +conf->num_channels
           << ",\tbits: " << +conf->bits_per_sample
           << ",\tdata_interval_us: " << +conf->data_interval_us << "\n";

    dprintf(fd, "%s", stream.str().c_str());
  }
@@ -2880,17 +2928,27 @@ class LeAudioClientImpl : public LeAudioClient {

  void Dump(int fd) {
    dprintf(fd, "  Active group: %d\n", active_group_id_);
    dprintf(fd, "    configuration content type: 0x%08hx\n",
    dprintf(fd, "    configuration: %s  (0x%08hx)\n",
            bluetooth::common::ToString(configuration_context_type_).c_str(),
            configuration_context_type_);
    dprintf(fd, "    metadata context type mask: ");

    for (auto ctx : le_audio::types::kLeAudioContextAllTypesArray) {
      if (static_cast<uint16_t>(ctx) & metadata_context_types_.to_ulong()) {
        dprintf(fd, "%s, ", bluetooth::common::ToString(ctx).c_str());
      }
    }
    dprintf(fd, "\n");
    dprintf(fd, "    TBS state: %s\n", in_call_ ? " In call" : "No calls");
    dprintf(
        fd, "    stream setup time if started: %d ms\n",
        (int)((stream_setup_end_timestamp_ - stream_setup_start_timestamp_) /
              1000));
    dprintf(fd, "    Start time: ");
    for (auto t : stream_start_history_queue_) {
      dprintf(fd, ", %d ms", static_cast<int>(t));
    }
    dprintf(fd, "\n");
    printCurrentStreamConfiguration(fd);
    dprintf(fd, "  ----------------\n ");
    dprintf(fd, "  LE Audio Groups:\n");
    aseGroups_.Dump(fd);
    aseGroups_.Dump(fd, active_group_id_);
    dprintf(fd, "\n  Not grouped devices:\n");
    leAudioDevices_.Dump(fd, bluetooth::groups::kGroupUnknown);
  }
@@ -3827,6 +3885,23 @@ class LeAudioClientImpl : public LeAudioClient {
    }
  }

  void take_stream_time(void) {
    if (stream_setup_start_timestamp_ == 0) {
      return;
    }

    if (stream_start_history_queue_.size() == 10) {
      stream_start_history_queue_.pop_back();
    }

    stream_setup_end_timestamp_ = bluetooth::common::time_get_os_boottime_us();
    stream_start_history_queue_.emplace_front(
        (stream_setup_end_timestamp_ - stream_setup_start_timestamp_) / 1000);

    stream_setup_end_timestamp_ = 0;
    stream_setup_start_timestamp_ = 0;
  }

  void StatusReportCb(int group_id, GroupStreamStatus status) {
    LOG_INFO("status: %d , audio_sender_state %s, audio_receiver_state %s",
             static_cast<int>(status),
@@ -3845,8 +3920,8 @@ class LeAudioClientImpl : public LeAudioClient {
        if (audio_receiver_state_ == AudioState::READY_TO_START)
          StartReceivingAudio(group_id);

        stream_setup_end_timestamp_ =
            bluetooth::common::time_get_os_boottime_us();
        take_stream_time();

        le_audio::MetricsCollector::Get()->OnStreamStarted(
            active_group_id_, configuration_context_type_);
        break;
@@ -3884,8 +3959,6 @@ class LeAudioClientImpl : public LeAudioClient {
         */
        FALLTHROUGH;
      case GroupStreamStatus::IDLE: {
        stream_setup_end_timestamp_ = 0;
        stream_setup_start_timestamp_ = 0;
        if (group && group->IsPendingConfiguration()) {
          SuspendedForReconfiguration();
          auto adjusted_metedata_context_type =
@@ -3898,6 +3971,8 @@ class LeAudioClientImpl : public LeAudioClient {
            return;
          }
        }
        stream_setup_end_timestamp_ = 0;
        stream_setup_start_timestamp_ = 0;
        CancelStreamingRequest();
        if (group) {
          NotifyUpperLayerGroupTurnedIdleDuringCall(group->group_id_);
@@ -3933,6 +4008,7 @@ class LeAudioClientImpl : public LeAudioClient {
  AudioContexts metadata_context_types_;
  uint64_t stream_setup_start_timestamp_;
  uint64_t stream_setup_end_timestamp_;
  std::deque<uint64_t> stream_start_history_queue_;

  /* Microphone (s) */
  AudioState audio_receiver_state_;
+123 −62
Original line number Diff line number Diff line
@@ -54,6 +54,42 @@ using le_audio::types::LeAudioContextType;
using le_audio::types::LeAudioLc3Config;

namespace le_audio {
std::ostream& operator<<(std::ostream& os, const DeviceConnectState& state) {
  const char* char_value_ = "UNKNOWN";

  switch (state) {
    case DeviceConnectState::CONNECTED:
      char_value_ = "CONNECTED";
      break;
    case DeviceConnectState::DISCONNECTED:
      char_value_ = "DISCONNECTED";
      break;
    case DeviceConnectState::REMOVING:
      char_value_ = "REMOVING";
      break;
    case DeviceConnectState::DISCONNECTING:
      char_value_ = "DISCONNECTING";
      break;
    case DeviceConnectState::CONNECTING_BY_USER:
      char_value_ = "CONNECTING_BY_USER";
      break;
    case DeviceConnectState::CONNECTED_BY_USER_GETTING_READY:
      char_value_ = "CONNECTED_BY_USER_GETTING_READY";
      break;
    case DeviceConnectState::CONNECTING_AUTOCONNECT:
      char_value_ = "CONNECTING_AUTOCONNECT";
      break;
    case DeviceConnectState::CONNECTED_AUTOCONNECT_GETTING_READY:
      char_value_ = "CONNECTED_AUTOCONNECT_GETTING_READY";
      break;
  }

  os << char_value_ << " ("
     << "0x" << std::setfill('0') << std::setw(2) << static_cast<int>(state)
     << ")";
  return os;
}

/* LeAudioDeviceGroup Class methods implementation */
void LeAudioDeviceGroup::AddNode(
    const std::shared_ptr<LeAudioDevice>& leAudioDevice) {
@@ -973,7 +1009,11 @@ bool LeAudioDeviceGroup::CigAssignCisIds(LeAudioDevice* leAudioDevice) {
  LOG_INFO("device: %s", leAudioDevice->address_.ToString().c_str());

  struct ase* ase = leAudioDevice->GetFirstActiveAse();
  ASSERT_LOG(ase, " Shouldn't be called without an active ASE");
  if (!ase) {
    LOG_ERROR(" Device %s shouldn't be called without an active ASE",
              leAudioDevice->address_.ToString().c_str());
    return false;
  }

  for (; ase != nullptr; ase = leAudioDevice->GetNextActiveAse(ase)) {
    uint8_t cis_id = kInvalidCisId;
@@ -1536,8 +1576,16 @@ bool LeAudioDeviceGroup::ConfigureAses(
        continue;
      }

      /* For the moment, we configure only connected devices. */
      if (device->conn_id_ == GATT_INVALID_CONN_ID) continue;
      /* For the moment, we configure only connected devices and when it is
       * ready to stream i.e. All ASEs are discovered and device is reported as
       * connected
       */
      if (device->GetConnectionState() != DeviceConnectState::CONNECTED) {
        LOG_WARN(
            "Device %s, in the state %s", device->address_.ToString().c_str(),
            bluetooth::common::ToString(device->GetConnectionState()).c_str());
        continue;
      }

      if (!device->ConfigureAses(ent, context_type, &active_ase_num,
                                 group_snk_audio_locations,
@@ -1859,67 +1907,72 @@ bool LeAudioDeviceGroup::Configure(LeAudioContextType context_type,
}

LeAudioDeviceGroup::~LeAudioDeviceGroup(void) { this->Cleanup(); }
void LeAudioDeviceGroup::Dump(int fd) {
void LeAudioDeviceGroup::Dump(int fd, int active_group_id) {
  bool is_active = (group_id_ == active_group_id);
  std::stringstream stream;
  auto* active_conf = GetActiveConfiguration();
  uint32_t context_type_mask = GetActiveContexts().to_ulong();

  stream << "\n    == Group id: " << group_id_
         << " == " << (is_active ? ",\tActive\n" : ",\tInactive\n")
         << "      state: " << GetState()
         << ",\ttarget state: " << GetTargetState()
         << ",\tcig state: " << cig_state_ << "\n"
         << "      active context type mask: " << context_type_mask;

  for (auto ctx : types::kLeAudioContextAllTypesArray) {
    if (static_cast<uint16_t>(ctx) & static_cast<uint16_t>(context_type_mask)) {
      stream << ", " << bluetooth::common::ToString(ctx).c_str();
    }
  }

  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: "
         << loghex(GetActiveContexts().to_ulong()) << "\n"
         << "      current context type: "
         << static_cast<int>(GetCurrentContextType()) << "\n"
         << "      active stream configuration name: "
  stream << ",\n      current context type: "
         << bluetooth::common::ToString(GetCurrentContextType()).c_str() << "\n"
         << "      active configuration name: "
         << (active_conf ? active_conf->name : " not set") << "\n"
         << "    Last used stream configuration: \n"
         << "      pending_configuration: " << stream_conf.pending_configuration
         << "      stream configuration: "
         << (stream_conf.conf != nullptr ? stream_conf.conf->name : " unknown ")
         << "\n"
         << "      codec id : " << +(stream_conf.id.coding_format) << "\n"
         << "      name: "
         << (stream_conf.conf != nullptr ? stream_conf.conf->name : " null ")
         << "      codec id: " << +(stream_conf.id.coding_format)
         << ",\tpending_configuration: " << stream_conf.pending_configuration
         << "\n"
         << "      number of sinks in the configuration "
         << stream_conf.sink_num_of_devices << "\n"
         << "      number of sink_streams connected: "
         << stream_conf.sink_streams.size() << "\n"
         << "      number of sources in the configuration "
         << stream_conf.source_num_of_devices << "\n"
         << "      number of source_streams connected: "
         << stream_conf.source_streams.size() << "\n"
         << "      num of devices(connected): " << Size() << "("
         << NumOfConnected() << ")\n"
         << ",     num of sinks(connected): " << stream_conf.sink_num_of_devices
         << "(" << stream_conf.sink_streams.size() << ")\n"
         << "      num of sources(connected): "
         << stream_conf.source_num_of_devices << "("
         << stream_conf.source_streams.size() << ")\n"
         << "      allocated CISes: " << static_cast<int>(cises_.size());

  if (cises_.size() > 0) {
    stream << "\n\t === CISes === ";
    stream << "\n\t == CISes == ";
    for (auto cis : cises_) {
      stream << "\n\t cis id: " << static_cast<int>(cis.id)
             << ", type: " << static_cast<int>(cis.type)
             << ", conn_handle: " << static_cast<int>(cis.conn_handle)
             << ", addr: " << cis.addr;
             << ",\ttype: " << static_cast<int>(cis.type)
             << ",\tconn_handle: " << static_cast<int>(cis.conn_handle)
             << ",\taddr: " << cis.addr;
    }
    stream << "\n\t ====";
  }

  if (GetFirstActiveDevice() != nullptr) {
    uint32_t sink_delay;
    stream << "\n      presentation_delay for sink (speaker): ";
    if (GetPresentationDelay(&sink_delay, le_audio::types::kLeAudioDirectionSink)) {
      stream << sink_delay << " us";
    if (GetPresentationDelay(&sink_delay,
                             le_audio::types::kLeAudioDirectionSink)) {
      stream << "\n      presentation_delay for sink (speaker): " << sink_delay
             << " us";
    }
    stream << "\n      presentation_delay for source (microphone): ";

    uint32_t source_delay;
    if (GetPresentationDelay(&source_delay, le_audio::types::kLeAudioDirectionSource)) {
      stream << source_delay << " us";
    if (GetPresentationDelay(&source_delay,
                             le_audio::types::kLeAudioDirectionSource)) {
      stream << "\n      presentation_delay for source (microphone): "
             << source_delay << " us";
    }
    stream << "\n";
  } else {
    stream << "\n      presentation_delay for sink (speaker):\n"
           << "      presentation_delay for source (microphone): \n";
  }

  stream << "      === devices: ===";
  stream << "\n      == devices: ==";

  dprintf(fd, "%s", stream.str().c_str());

@@ -1929,6 +1982,17 @@ void LeAudioDeviceGroup::Dump(int fd) {
}

/* LeAudioDevice Class methods implementation */
void LeAudioDevice::SetConnectionState(DeviceConnectState state) {
  LOG_DEBUG(" %s --> %s",
            bluetooth::common::ToString(connection_state_).c_str(),
            bluetooth::common::ToString(state).c_str());
  connection_state_ = state;
}

DeviceConnectState LeAudioDevice::GetConnectionState(void) {
  return connection_state_;
}

void LeAudioDevice::ClearPACs(void) {
  snk_pacs_.clear();
  src_pacs_.clear();
@@ -2341,32 +2405,29 @@ void LeAudioDevice::SetSupportedContexts(AudioContexts snk_contexts,
}

void LeAudioDevice::Dump(int fd) {
  uint16_t acl_handle = BTM_GetHCIConnHandle(address_, BT_TRANSPORT_LE);

  std::stringstream stream;
  stream << std::boolalpha;
  stream << "\n\taddress: " << address_
         << (conn_id_ == GATT_INVALID_CONN_ID ? "\n\t  Not connected "
                                              : "\n\t  Connected conn_id =")
  stream << "\n\taddress: " << address_ << ": " << connection_state_ << ": "
         << (conn_id_ == GATT_INVALID_CONN_ID ? "" : std::to_string(conn_id_))
         << "\n\t  set member: " << csis_member_
         << "\n\t  known_service_handles_: " << known_service_handles_
         << "\n\t  notify_connected_after_read_: "
         << notify_connected_after_read_
         << "\n\t  removing_device_: " << removing_device_
         << "\n\t  first_connection_: " << first_connection_
         << "\n\t  encrypted_: " << encrypted_
         << "\n\t  connecting_actively_: " << connecting_actively_
         << ", acl_handle: " << std::to_string(acl_handle) << ",\t"
         << (encrypted_ ? "Encrypted" : "Unecrypted")
         << ",mtu: " << std::to_string(mtu_)
         << "\n\tnumber of ases_: " << static_cast<int>(ases_.size());

  if (ases_.size() > 0) {
    stream << "\n\t  == ASE == ";
    stream << "\n\t  == ASEs == ";
    for (auto& ase : ases_) {
      stream << "\n\t  id: " << static_cast<int>(ase.id)
             << ", active: " << ase.active << ", direction: "
             << ",\tactive: " << ase.active << ", dir: "
             << (ase.direction == types::kLeAudioDirectionSink ? "sink"
                                                               : "source")
             << ", allocated cis id: " << static_cast<int>(ase.cis_id);
             << ",\tcis_id: " << static_cast<int>(ase.cis_id) << ",\tstate: "
             << bluetooth::common::ToString(ase.data_path_state);
    }
  }
  stream << "\n\t  ====";

  dprintf(fd, "%s", stream.str().c_str());
}
@@ -2504,9 +2565,9 @@ void LeAudioDeviceGroups::Cleanup(void) {
  groups_.clear();
}

void LeAudioDeviceGroups::Dump(int fd) {
void LeAudioDeviceGroups::Dump(int fd, int active_group_id) {
  for (auto& g : groups_) {
    g->Dump(fd);
    g->Dump(fd, active_group_id);
  }
}

@@ -2534,7 +2595,7 @@ std::vector<int> LeAudioDeviceGroups::GetGroupsIds(void) {
}

/* LeAudioDevices Class methods implementation */
void LeAudioDevices::Add(const RawAddress& address, bool first_connection,
void LeAudioDevices::Add(const RawAddress& address, DeviceConnectState state,
                         int group_id) {
  auto device = FindByAddress(address);
  if (device != nullptr) {
@@ -2544,7 +2605,7 @@ void LeAudioDevices::Add(const RawAddress& address, bool first_connection,
  }

  leAudioDevices_.emplace_back(
      std::make_shared<LeAudioDevice>(address, first_connection, group_id));
      std::make_shared<LeAudioDevice>(address, state, group_id));
}

void LeAudioDevices::Remove(const RawAddress& address) {
+35 −13

File changed.

Preview size limit exceeded, changes collapsed.

+27 −25

File changed.

Preview size limit exceeded, changes collapsed.

+11 −0
Original line number Diff line number Diff line
@@ -578,6 +578,17 @@ uint32_t AdjustAllocationForOffloader(uint32_t allocation) {
}

namespace types {
std::ostream& operator<<(std::ostream& os,
                         const AudioStreamDataPathState& state) {
  static const char* char_value_[6] = {
      "IDLE",        "CIS_DISCONNECTING", "CIS_ASSIGNED",
      "CIS_PENDING", "CIS_ESTABLISHED",   "DATA_PATH_ESTABLISHED"};

  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::CigState& state) {
  static const char* char_value_[5] = {"NONE", "CREATING", "CREATED",
                                       "REMOVING", "RECOVERING"};
Loading