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

Commit d29d3c5d authored by Jakub Tyszkowski (xWF)'s avatar Jakub Tyszkowski (xWF) Committed by Gerrit Code Review
Browse files

Merge changes I822b96b8,I5ba5b54f into main

* changes:
  LeAudio: Add names to audio set configurations from AIDL
  LeAudio: Improve the debug state dumps and logs
parents 6acfa338 3f578a3f
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
@@ -507,6 +507,73 @@ static ::bluetooth::le_audio::set_configurations::AseConfiguration GetStackAseCo
  return config;
}

static std::string GenerateNameForConfig(
        const ::bluetooth::le_audio::set_configurations::AudioSetConfiguration& config) {
  auto namegen = [](const std::vector<::bluetooth::le_audio::set_configurations::AseConfiguration>&
                            configs,
                    const char* dir_str) {
    std::stringstream cfg_str;
    if (configs.size() > 0) {
      auto current_config = configs.begin();
      while (current_config != configs.end()) {
        uint8_t cfg_multiplier = 1;
        auto last_equal_config = current_config;
        auto current_codec = current_config->codec;
        while (++last_equal_config != configs.end()) {
          // For the purpose of name generation, ignore the audio channel allocation
          auto current_codec_no_channels = current_codec;
          auto last_codec_no_channels = last_equal_config->codec;
          current_codec_no_channels.params.Add(
                  le_audio::codec_spec_conf::kLeAudioLtvTypeAudioChannelAllocation, (uint32_t)0);
          last_codec_no_channels.params.Add(
                  le_audio::codec_spec_conf::kLeAudioLtvTypeAudioChannelAllocation, (uint32_t)0);

          if (current_codec_no_channels != last_codec_no_channels) {
            break;
          }
          ++cfg_multiplier;
          current_config = last_equal_config;
        }

        // Channel configuration
        cfg_str << +cfg_multiplier << "-" << +current_codec.GetChannelCountPerIsoStream() << "chan";
        cfg_str << "-" << dir_str << "Ase-";
        // Codec Id
        cfg_str << "CodecId_" << +current_codec.id.coding_format << "_"
                << +current_codec.id.vendor_company_id << "_" << +current_codec.id.vendor_codec_id
                << "-";
        // Codec parameters
        cfg_str << current_codec.GetSamplingFrequencyHz() << "hz";
        if (current_codec.id.coding_format ==
            ::bluetooth::le_audio::types::kLeAudioCodingFormatLC3) {
          cfg_str << "_" << current_codec.GetOctetsPerFrame() << "oct";
          cfg_str << "_" << current_codec.GetDataIntervalUs() << "us";
        }
        // QoS
        cfg_str << "-TargetLatency_" << +current_config->qos.target_latency;

        if (last_equal_config == configs.end()) {
          break;
        }

        // Check if there are some different configs left
        ++current_config;
      }
    }
    return cfg_str.str();
  };

  std::stringstream name;
  name << "AIDL";
  if (!config.confs.sink.empty()) {
    name << "-" << namegen(config.confs.sink, "Sink");
  }
  if (!config.confs.source.empty()) {
    name << "-" << namegen(config.confs.source, "Source");
  }
  return name.str();
}

static ::bluetooth::le_audio::set_configurations::AudioSetConfiguration
GetStackConfigSettingFromAidl(
        ::bluetooth::le_audio::types::LeAudioContextType ctx_type,
@@ -540,6 +607,7 @@ GetStackConfigSettingFromAidl(
    }
  }

  cig_config.name = GenerateNameForConfig(cig_config);
  return cig_config;
}

+6 −0
Original line number Diff line number Diff line
@@ -918,6 +918,9 @@ TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackUnicastConfigurationFrom
  ASSERT_EQ(stack_config->confs.sink.size(), 2ul);
  ASSERT_EQ(stack_config->confs.source.size(), 2ul);
  ASSERT_EQ(*stack_config, expected_stack_config);
  ASSERT_EQ(stack_config->name,
            "AIDL-2-1chan-SinkAse-CodecId_6_0_0-48000hz_120oct_7500us-TargetLatency_2-"
            "2-1chan-SourceAse-CodecId_6_0_0-24000hz_80oct_7500us-TargetLatency_1");
}

TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackUnicastConfigurationFromAidlFormatMonoLoc) {
@@ -931,6 +934,9 @@ TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackUnicastConfigurationFrom
  ASSERT_EQ(stack_config->confs.sink.size(), 2ul);
  ASSERT_EQ(stack_config->confs.source.size(), 1ul);
  ASSERT_EQ(*stack_config, expected_stack_config);
  ASSERT_EQ(stack_config->name,
            "AIDL-2-1chan-SinkAse-CodecId_6_0_0-48000hz_120oct_7500us-TargetLatency_2-"
            "1-1chan-SourceAse-CodecId_6_0_0-24000hz_80oct_7500us-TargetLatency_1");
}

TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackBisConfigFromAidlFormat) {
+2 −4
Original line number Diff line number Diff line
@@ -51,15 +51,13 @@ void GmapClient::AddFromStorage(const RawAddress &addr, const uint8_t role,
  UGT_feature_handle_ = UGT_feature_handle;
}

void GmapClient::DebugDump(int fd) {
  std::stringstream stream;
void GmapClient::DebugDump(std::stringstream &stream) {
  if (!IsGmapClientEnabled()) {
    dprintf(fd, "%s", "GmapClient not enabled");
    stream << "GmapClient not enabled\n";
    return;
  }
  stream << "GmapClient device: " << addr_ << ", Role: " << role_ << ", ";
  stream << "UGT Feature: " << UGT_feature_ << "\n";
  dprintf(fd, "%s", stream.str().c_str());
}

bool GmapClient::IsGmapClientEnabled() {
+63 −42
Original line number Diff line number Diff line
@@ -352,6 +352,7 @@ public:
            close_vbc_timeout_, timeoutMs,
            [](void*) {
              if (instance) {
                log::debug("Reconfigure after VBC close");
                instance->ReconfigureAfterVbcClose();
              }
            },
@@ -382,7 +383,9 @@ public:
            suspend_timeout_, timeoutMs,
            [](void* data) {
              if (instance) {
                instance->GroupStop(PTR_TO_INT(data));
                auto const group_id = PTR_TO_INT(data);
                log::debug("No resume request received. Stop the group ID: {}", group_id);
                instance->GroupStop(group_id);
              }
            },
            INT_TO_PTR(active_group_id_));
@@ -3301,7 +3304,7 @@ public:
  }

  void scheduleAttachDeviceToTheStream(const RawAddress& addr) {
    log::info("Device {} scheduler for stream", addr);
    log::info("Device {} is scheduled for streaming", addr);
    do_in_main_thread_delayed(base::BindOnce(&LeAudioClientImpl::restartAttachToTheStream,
                                             weak_factory_.GetWeakPtr(), addr),
                              std::chrono::milliseconds(kDeviceAttachDelayMs));
@@ -3886,64 +3889,79 @@ public:
    stack::l2cap::get_interface().L2CA_SetEcosystemBaseInterval(0 /* clear recommendation */);
  }

  void printCurrentStreamConfiguration(int fd) {
    std::stringstream stream;
  void printCurrentStreamConfiguration(std::stringstream& stream) {
    auto config_printer = [&stream](LeAudioCodecConfiguration& conf) {
      stream << "\tsample rate: " << +conf.sample_rate << ",\tchan: " << +conf.num_channels
             << ",\tbits: " << +conf.bits_per_sample
             << ",\tdata_interval_us: " << +conf.data_interval_us << "\n";
      stream << "\tsample rate: " << +conf.sample_rate << ", chan: " << +conf.num_channels
             << ", bits: " << +conf.bits_per_sample
             << ", data_interval_us: " << +conf.data_interval_us << "\n";
    };

    stream << " Speaker codec config (audio framework) \n";
    stream << "\n";
    stream << "  Speaker codec config (audio framework):\n";
    stream << "\taudio sender state: " << audio_sender_state_ << "\n";
    config_printer(audio_framework_source_config);

    stream << " Microphone codec config (audio framework) \n";
    stream << "  Microphone codec config (audio framework):\n";
    stream << "\taudio receiver state: " << audio_receiver_state_ << "\n";
    config_printer(audio_framework_sink_config);

    stream << " Speaker codec config (SW encoder)\n";
    stream << "  Speaker codec config (SW encoder):\n";
    config_printer(current_encoder_config_);

    stream << " Microphone codec config (SW decoder)\n";
    stream << "  Microphone codec config (SW decoder):\n";
    config_printer(current_decoder_config_);

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

  void Dump(int fd) {
    dprintf(fd, "  APP ID: %d \n", gatt_if_);
    dprintf(fd, "  Active group: %d\n", active_group_id_);
    dprintf(fd, "  reconnection mode: %s \n",
            (reconnection_mode_ == BTM_BLE_BKG_CONNECT_ALLOW_LIST ? "Allow List"
                                                                  : "Targeted Announcements"));
    dprintf(fd, "  configuration: %s  (0x%08x)\n",
            bluetooth::common::ToString(configuration_context_type_).c_str(),
            static_cast<uint16_t>(configuration_context_type_));
    dprintf(fd, "  local source metadata context type mask: %s\n",
            local_metadata_context_types_.source.to_string().c_str());
    dprintf(fd, "  local sink metadata context type mask: %s\n",
            local_metadata_context_types_.sink.to_string().c_str());
    dprintf(fd, "  TBS state: %s\n", in_call_ ? " In call" : "No calls");
    dprintf(fd, "  Sink listening mode: %s\n", sink_monitor_mode_ ? "true" : "false");
    std::stringstream stream;

    stream << "  APP ID: " << +gatt_if_ << "\n";
    stream << "  TBS state: " << (in_call_ ? " In call" : "No calls") << "\n";
    stream << "  Active group: " << +active_group_id_ << "\n";
    stream << "  Reconnection mode: "
           << (reconnection_mode_ == BTM_BLE_BKG_CONNECT_ALLOW_LIST ? "Allow List"
                                                                    : "Targeted Announcements")
           << "\n";
    stream << "  Configuration: " << bluetooth::common::ToString(configuration_context_type_)
           << " (" << loghex(static_cast<uint16_t>(configuration_context_type_)) << ")\n";
    stream << "  Local source metadata context type mask: "
           << local_metadata_context_types_.source.to_string() << "\n";
    stream << "  Local sink metadata context type mask: "
           << local_metadata_context_types_.sink.to_string() << "\n";
    stream << "  Sink listening mode: " << (sink_monitor_mode_ ? "true" : "false") << "\n";
    if (sink_monitor_notified_status_) {
      dprintf(fd, "  Local sink notified state: %d\n",
              static_cast<int>(sink_monitor_notified_status_.value()));
      stream << "  Local sink notified state: "
             << static_cast<int>(sink_monitor_notified_status_.value()) << "\n";
    }
    stream << "  Source monitor mode: " << (source_monitor_mode_ ? "true" : "false") << "\n";

    auto codec_loc = CodecManager::GetInstance()->GetCodecLocation();
    if (codec_loc == bluetooth::le_audio::types::CodecLocation::HOST) {
      stream << "  Codec location: HOST\n";
    } else if (codec_loc == bluetooth::le_audio::types::CodecLocation::CONTROLLER) {
      stream << "  Codec location: CONTROLLER\n";
    } else if (codec_loc == bluetooth::le_audio::types::CodecLocation::ADSP) {
      stream << "  Codec location: ADSP"
             << (CodecManager::GetInstance()->IsUsingCodecExtensibility() ? " (codec extensibility)"
                                                                          : "")
             << "\n";
    } else {
      dprintf(fd, "  Codec location: UNKNOWN\n");
    }
    dprintf(fd, "  Source monitor mode: %s\n", source_monitor_mode_ ? "true" : "false");
    dprintf(fd, "  Codec extensibility: %s\n",
            CodecManager::GetInstance()->IsUsingCodecExtensibility() ? "true" : "false");
    dprintf(fd, "  Start time: ");

    stream << "  Start time: ";
    for (auto t : stream_start_history_queue_) {
      dprintf(fd, ", %d ms", static_cast<int>(t));
      stream << static_cast<int>(t) << " ms, ";
    }
    dprintf(fd, "\n");
    printCurrentStreamConfiguration(fd);
    dprintf(fd, "  ----------------\n ");
    dprintf(fd, "  LE Audio Groups:\n");
    aseGroups_.Dump(fd, active_group_id_);
    dprintf(fd, "\n  Not grouped devices:\n");
    leAudioDevices_.Dump(fd, bluetooth::groups::kGroupUnknown);
    stream << "\n";
    printCurrentStreamConfiguration(stream);
    stream << "\n";
    aseGroups_.Dump(stream, active_group_id_);
    stream << "\n ";
    stream << "  Not grouped devices:\n";
    leAudioDevices_.Dump(stream, bluetooth::groups::kGroupUnknown);

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

    if (leAudioHealthStatus_) {
      leAudioHealthStatus_->DebugDump(fd);
@@ -4060,7 +4078,9 @@ public:
              disable_timer_, kAudioDisableTimeoutMs,
              [](void* data) {
                if (instance) {
                  instance->GroupSuspend(PTR_TO_INT(data));
                  auto const group_id = PTR_TO_INT(data);
                  log::debug("No resume request received. Suspend the group ID: {}", group_id);
                  instance->GroupSuspend(group_id);
                }
              },
              INT_TO_PTR(active_group_id_));
@@ -4615,6 +4635,7 @@ public:
    }

    StopSuspendTimeout();
    /* If group suspend is scheduled, cancel as we are stopping it anyway */

    /* Need to reconfigure stream. At this point pre_configuration_context_type shall be set */

+37 −42
Original line number Diff line number Diff line
@@ -2101,7 +2101,7 @@ void LeAudioDeviceGroup::PrintDebugState(void) const {
            << bluetooth::common::ToString(GetSupportedContexts())
            << ", \n group available contexts: "
            << bluetooth::common::ToString(GetAvailableContexts())
            << ", \n group allowed contexts: "
            << ", \n group user allowed contexts: "
            << bluetooth::common::ToString(GetAllowedContextMask())
            << ", \n configuration context type: "
            << bluetooth::common::ToString(GetConfigurationContextType())
@@ -2142,42 +2142,29 @@ void LeAudioDeviceGroup::PrintDebugState(void) const {
  }
}

void LeAudioDeviceGroup::Dump(int fd, int active_group_id) const {
void LeAudioDeviceGroup::Dump(std::stringstream& stream, int active_group_id) const {
  bool is_active = (group_id_ == active_group_id);
  std::stringstream stream, stream_pacs;
  auto active_conf = GetActiveConfiguration();

  stream << "\n    == Group id: " << group_id_ << (is_enabled_ ? " enabled" : " disabled")
         << " == " << (is_active ? ",\tActive\n" : ",\tInactive\n") << "      state: " << GetState()
  stream << "     Group id: " << group_id_ << ", " << (is_enabled_ ? "Enabled" : "Disabled")
         << ", " << (is_active ? "Active\n" : "Inactive\n") << "      Current state: " << GetState()
         << ",\ttarget state: " << GetTargetState() << ",\tcig state: " << cig.GetState() << "\n"
         << "      group supported contexts: " << GetSupportedContexts() << "\n"
         << "      group available contexts: " << GetAvailableContexts() << "\n"
         << "      group allowed contexts: " << GetAllowedContextMask() << "\n"
         << "      configuration context type: "
         << "      Group supported contexts: " << GetSupportedContexts() << "\n"
         << "      Group available contexts: " << GetAvailableContexts() << "\n"
         << "      Group user allowed contexts: " << GetAllowedContextMask() << "\n"
         << "      Configuration context type: "
         << bluetooth::common::ToString(GetConfigurationContextType()).c_str() << "\n"
         << "      active configuration name: " << (active_conf ? active_conf->name : " not set")
         << "      Active configuration name:\t" << (active_conf ? active_conf->name : "Not set")
         << "\n"
         << "      stream configuration: "
         << (stream_conf.conf != nullptr ? stream_conf.conf->name : " unknown ") << "\n"
         << "      codec id: " << +(stream_conf.codec_id.coding_format)
         << ",\tpending_configuration: " << stream_conf.pending_configuration << "\n"
         << "      num of devices(connected): " << Size() << "(" << NumOfConnected() << ")\n"
         << ",     num of sinks(connected): " << stream_conf.stream_params.sink.num_of_devices
         << "(" << stream_conf.stream_params.sink.stream_locations.size() << ")\n"
         << "      num of sources(connected): " << stream_conf.stream_params.source.num_of_devices
         << "(" << stream_conf.stream_params.source.stream_locations.size() << ")\n"
         << "      allocated CISes: " << static_cast<int>(cig.cises.size());

  if (cig.cises.size() > 0) {
    stream << "\n\t == CISes == ";
    for (auto cis : cig.cises) {
      stream << "\n\t cis id: " << static_cast<int>(cis.id)
             << ",\ttype: " << static_cast<int>(cis.type)
             << ",\tconn_handle: " << static_cast<int>(cis.conn_handle)
             << ",\taddr: " << ADDRESS_TO_LOGGABLE_STR(cis.addr);
    }
    stream << "\n\t ====";
  }
         << "      Stream configuration:\t\t"
         << (stream_conf.conf != nullptr ? stream_conf.conf->name : "Not set ") << "\n"
         << "      Codec ID: " << +(stream_conf.codec_id.coding_format)
         << ",\tpending reconfiguration: " << stream_conf.pending_configuration << "\n"
         << "      Num of devices:\t" << Size() << " (" << NumOfConnected() << " connected)\n"
         << "      Num of sinks:\t" << stream_conf.stream_params.sink.num_of_devices << " ("
         << stream_conf.stream_params.sink.stream_locations.size() << " connected)\n"
         << "      Num of sources:\t" << stream_conf.stream_params.source.num_of_devices << " ("
         << stream_conf.stream_params.source.stream_locations.size() << " connected)";

  if (GetFirstActiveDevice() != nullptr) {
    uint32_t sink_delay;
@@ -2190,21 +2177,27 @@ void LeAudioDeviceGroup::Dump(int fd, int active_group_id) const {
      stream << "\n      presentation_delay for source (microphone): " << source_delay << " us";
    }
  }
  stream << "\n";

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

  dprintf(fd, "%s", stream.str().c_str());
  stream << "      == CISes (" << static_cast<int>(cig.cises.size()) << "):";
  if (cig.cises.size() > 0) {
    for (auto cis : cig.cises) {
      stream << "\n\t cis id: " << static_cast<int>(cis.id)
             << ",\ttype: " << static_cast<int>(cis.type)
             << ",\tconn_handle: " << static_cast<int>(cis.conn_handle)
             << ",\taddr: " << ADDRESS_TO_LOGGABLE_STR(cis.addr);
    }
  }
  stream << "\n";

  for (const auto& device_iter : leAudioDevices_) {
    device_iter.lock()->Dump(fd);
    device_iter.lock()->Dump(stream);
  }

  for (const auto& device_iter : leAudioDevices_) {
    auto device = device_iter.lock();
    stream_pacs << "\n\taddress: " << device->address_;
    device->DumpPacsDebugState(stream_pacs);
    device_iter.lock()->DumpPacsDebugState(stream);
  }
  dprintf(fd, "%s", stream_pacs.str().c_str());
  stream << "\n";
}

LeAudioDeviceGroup* LeAudioDeviceGroups::Add(int group_id) {
@@ -2244,19 +2237,21 @@ void LeAudioDeviceGroups::Cleanup(void) {
  groups_.clear();
}

void LeAudioDeviceGroups::Dump(int fd, int active_group_id) const {
void LeAudioDeviceGroups::Dump(std::stringstream& stream, int active_group_id) const {
  /* Dump first active group */
  stream << "  == Active Groups:\n";
  for (auto& g : groups_) {
    if (g->group_id_ == active_group_id) {
      g->Dump(fd, active_group_id);
      g->Dump(stream, active_group_id);
      break;
    }
  }

  /* Dump non active group */
  stream << "  == Inactive Groups:\n";
  for (auto& g : groups_) {
    if (g->group_id_ != active_group_id) {
      g->Dump(fd, active_group_id);
      g->Dump(stream, active_group_id);
    }
  }
}
Loading