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

Commit 6485b3fc authored by Grzegorz Kolodziejczyk's avatar Grzegorz Kolodziejczyk Committed by Automerger Merge Worker
Browse files

Merge "le_audio: Add dump for devices PACs" am: eb897412 am: 16346481

parents f54f3c00 16346481
Loading
Loading
Loading
Loading
+50 −2
Original line number Diff line number Diff line
@@ -2090,7 +2090,7 @@ void LeAudioDeviceGroup::PrintDebugState(void) {

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

  stream << "\n    == Group id: " << group_id_
@@ -2153,6 +2153,13 @@ void LeAudioDeviceGroup::Dump(int fd, int active_group_id) {
  for (const auto& device_iter : leAudioDevices_) {
    device_iter.lock()->Dump(fd);
  }

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

/* LeAudioDevice Class methods implementation */
@@ -2194,7 +2201,9 @@ void LeAudioDevice::RegisterPACs(
              << loghex(pac.codec_id.vendor_company_id)
              << "\n\tVendor codec ID: " << loghex(pac.codec_id.vendor_codec_id)
              << "\n\tCodec spec caps:\n"
              << pac.codec_spec_caps.ToString() << "\n\tMetadata: "
              << pac.codec_spec_caps.ToString("",
                                              types::CodecCapabilitiesLtvFormat)
              << "\n\tMetadata: "
              << base::HexEncode(pac.metadata.data(), pac.metadata.size());
  }

@@ -2613,6 +2622,38 @@ void LeAudioDevice::PrintDebugState(void) {
  LOG_INFO("%s", debug_str.str().c_str());
}

void LeAudioDevice::DumpPacsDebugState(std::stringstream& stream,
                                       types::PublishedAudioCapabilities pacs) {
  if (pacs.size() > 0) {
    for (auto& pac : pacs) {
      stream << "\n\t\tvalue handle: " << loghex(std::get<0>(pac).val_hdl)
             << " / CCC handle: " << loghex(std::get<0>(pac).ccc_hdl);

      for (auto& record : std::get<1>(pac)) {
        stream << "\n\n\t\tCodecId(Coding format: "
               << static_cast<int>(record.codec_id.coding_format)
               << ", Vendor company ID: "
               << static_cast<int>(record.codec_id.vendor_company_id)
               << ", Vendor codec ID: "
               << static_cast<int>(record.codec_id.vendor_codec_id) << ")";
        stream << "\n\t\tCodec specific capabilities:\n"
               << record.codec_spec_caps.ToString(
                      "\t\t\t", types::CodecCapabilitiesLtvFormat);
        stream << "\t\tMetadata: "
               << base::HexEncode(record.metadata.data(),
                                  record.metadata.size());
      }
    }
  }
}

void LeAudioDevice::DumpPacsDebugState(std::stringstream& stream) {
  stream << "\n\tSink PACs";
  DumpPacsDebugState(stream, snk_pacs_);
  stream << "\n\tSource PACs";
  DumpPacsDebugState(stream, src_pacs_);
}

void LeAudioDevice::Dump(int fd) {
  uint16_t acl_handle = BTM_GetHCIConnHandle(address_, BT_TRANSPORT_LE);
  std::string location = "unknown location";
@@ -2660,6 +2701,7 @@ void LeAudioDevice::Dump(int fd) {
             << bluetooth::common::ToString(ase.data_path_state);
    }
  }

  stream << "\n\t====";

  dprintf(fd, "%s", stream.str().c_str());
@@ -2968,9 +3010,15 @@ void LeAudioDevices::SetInitialGroupAutoconnectState(
size_t LeAudioDevices::Size() { return (leAudioDevices_.size()); }

void LeAudioDevices::Dump(int fd, int group_id) {
  std::stringstream stream, stream_pacs;

  for (auto const& device : leAudioDevices_) {
    if (device->group_id_ == group_id) {
      device->Dump(fd);

      stream_pacs << "\n\taddress: " << device->address_;
      device->DumpPacsDebugState(stream_pacs);
      dprintf(fd, "%s", stream_pacs.str().c_str());
    }
  }
}
+4 −0
Original line number Diff line number Diff line
@@ -186,6 +186,7 @@ class LeAudioDevice {
  bool ActivateConfiguredAses(types::LeAudioContextType context_type);

  void PrintDebugState(void);
  void DumpPacsDebugState(std::stringstream& stream);
  void Dump(int fd);

  void DisconnectAcl(void);
@@ -198,6 +199,9 @@ class LeAudioDevice {
 private:
  types::BidirectionalPair<types::AudioContexts> avail_contexts_;
  types::BidirectionalPair<types::AudioContexts> supp_contexts_;

  void DumpPacsDebugState(std::stringstream& stream,
                          types::PublishedAudioCapabilities pacs);
};

/* LeAudioDevices class represents a wraper helper over all devices in le audio
+181 −4
Original line number Diff line number Diff line
@@ -450,6 +450,176 @@ const std::map<uint8_t, uint32_t> LeAudioLc3Config::frame_duration_map = {
    {codec_spec_conf::kLeAudioCodecLC3FrameDur10000us,
     LeAudioCodecConfiguration::kInterval10000Us}};

std::string CapabilityTypeToStr(const uint8_t& type) {
  switch (type) {
    case codec_spec_caps::kLeAudioCodecLC3TypeSamplingFreq:
      return "Supported Sampling Frequencies";
    case codec_spec_caps::kLeAudioCodecLC3TypeFrameDuration:
      return "Supported Frame Durations";
    case codec_spec_caps::kLeAudioCodecLC3TypeAudioChannelCounts:
      return "Supported Audio Channel Count";
    case codec_spec_caps::kLeAudioCodecLC3TypeOctetPerFrame:
      return "Supported Octets Per Codec Frame";
    case codec_spec_caps::kLeAudioCodecLC3TypeMaxCodecFramesPerSdu:
      return "Supported Max Codec Frames Per SDU";
    default:
      return "Unknown";
  }
}

std::string CapabilityValueToStr(const uint8_t& type,
                                 const std::vector<uint8_t>& value) {
  std::string string = "";

  switch (type) {
    case codec_spec_conf::kLeAudioCodecLC3TypeSamplingFreq: {
      if (value.size() != 2) {
        return "Invalid size";
      }

      uint16_t u16_val = VEC_UINT8_TO_UINT16(value);

      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq8000Hz) {
        string += "8";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq11025Hz) {
        string += std::string((string.empty() ? "" : "|")) + "11.025";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq16000Hz) {
        string += std::string((string.empty() ? "" : "|")) + "16";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq22050Hz) {
        string += std::string((string.empty() ? "" : "|")) + "22.050";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq24000Hz) {
        string += std::string((string.empty() ? "" : "|")) + "24";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq32000Hz) {
        string += std::string((string.empty() ? "" : "|")) + "32";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq44100Hz) {
        string += std::string((string.empty() ? "" : "|")) + "44.1";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq48000Hz) {
        string += std::string((string.empty() ? "" : "|")) + "48";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq88200Hz) {
        string += std::string((string.empty() ? "" : "|")) + "88.2";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq96000Hz) {
        string += std::string((string.empty() ? "" : "|")) + "96";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq176400Hz) {
        string += std::string((string.empty() ? "" : "|")) + "176.4";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq192000Hz) {
        string += std::string((string.empty() ? "" : "|")) + "192";
      }
      if (u16_val & codec_spec_caps::kLeAudioSamplingFreq384000Hz) {
        string += std::string((string.empty() ? "" : "|")) + "384";
      }

      return string += " [kHz]\n";
    }
    case codec_spec_conf::kLeAudioCodecLC3TypeFrameDuration: {
      if (value.size() != 1) {
        return "Invalid size";
      }

      uint8_t u8_val = VEC_UINT8_TO_UINT8(value);

      if (u8_val & codec_spec_caps::kLeAudioCodecLC3FrameDur7500us) {
        string += "7.5";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3FrameDur10000us) {
        string += std::string((string.empty() ? "" : "|")) + "10";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3FrameDurPrefer7500us) {
        string += std::string((string.empty() ? "" : "|")) + "7.5 preferred";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3FrameDurPrefer10000us) {
        string += std::string((string.empty() ? "" : "|")) + "10 preferred";
      }

      return string += " [ms]\n";
    }
    case codec_spec_conf::kLeAudioCodecLC3TypeAudioChannelAllocation: {
      if (value.size() != 1) {
        return "Invalid size";
      }

      uint8_t u8_val = VEC_UINT8_TO_UINT8(value);

      if (u8_val & codec_spec_caps::kLeAudioCodecLC3ChannelCountNone) {
        string += "0";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3ChannelCountSingleChannel) {
        string += std::string((string.empty() ? "" : "|")) + "1";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3ChannelCountTwoChannel) {
        string += std::string((string.empty() ? "" : "|")) + "2";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3ChannelCountThreeChannel) {
        string += std::string((string.empty() ? "" : "|")) + "3";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3ChannelCountFourChannel) {
        string += std::string((string.empty() ? "" : "|")) + "4";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3ChannelCountFiveChannel) {
        string += std::string((string.empty() ? "" : "|")) + "5";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3ChannelCountSixChannel) {
        string += std::string((string.empty() ? "" : "|")) + "6";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3ChannelCountSevenChannel) {
        string += std::string((string.empty() ? "" : "|")) + "7";
      }
      if (u8_val & codec_spec_caps::kLeAudioCodecLC3ChannelCountEightChannel) {
        string += std::string((string.empty() ? "" : "|")) + "8";
      }

      return string += " channel/s\n";
    }
    case codec_spec_conf::kLeAudioCodecLC3TypeOctetPerFrame: {
      if (value.size() != 4) {
        return "Invalid size";
      }

      uint16_t u16_min_number_of_octets = VEC_UINT8_TO_UINT16(value);
      uint16_t u16_max_number_of_octets =
          OFF_VEC_UINT8_TO_UINT16(value, sizeof(u16_min_number_of_octets));

      string += "Minimum: " + std::to_string(u16_min_number_of_octets);
      string += ", Maximum: " + std::to_string(u16_max_number_of_octets) + "\n";

      return string;
    }
    case codec_spec_conf::kLeAudioCodecLC3TypeCodecFrameBlocksPerSdu: {
      if (value.size() != 1) {
        return "Invalid size";
      }

      uint8_t u8_val = VEC_UINT8_TO_UINT8(value);

      string += std::to_string(u8_val) + " frame/s\n";

      return string;
    }
    default:
      return base::HexEncode(value.data(), value.size()) + "\n";
  }
}

std::string CodecCapabilitiesLtvFormat(const uint8_t& type,
                                       const std::vector<uint8_t>& value) {
  std::string string = "";

  string += CapabilityTypeToStr(type) + ": ";
  string += CapabilityValueToStr(type, value);

  return string;
}

std::optional<std::vector<uint8_t>> LeAudioLtvMap::Find(uint8_t type) const {
  auto iter =
      std::find_if(values.cbegin(), values.cend(),
@@ -531,15 +701,22 @@ size_t LeAudioLtvMap::RawPacketSize() const {
  return bytes;
}

std::string LeAudioLtvMap::ToString() const {
std::string LeAudioLtvMap::ToString(
    const std::string& indent_string,
    std::string (*format)(const uint8_t&, const std::vector<uint8_t>&)) const {
  std::string debug_str;

  for (const auto& value : values) {
    std::stringstream sstream;

    sstream << "\ttype: " << std::to_string(value.first)
    if (format == nullptr) {
      sstream << indent_string + "type: " << std::to_string(value.first)
              << "\tlen: " << std::to_string(value.second.size()) << "\tdata: "
            << base::HexEncode(value.second.data(), value.second.size()) + "\n";
              << base::HexEncode(value.second.data(), value.second.size()) +
                     "\n";
    } else {
      sstream << indent_string + format(value.first, value.second);
    }

    debug_str += sstream.str();
  }
+27 −1
Original line number Diff line number Diff line
@@ -226,8 +226,12 @@ constexpr uint8_t kLeAudioCodecLC3TypeMaxCodecFramesPerSdu =
/* Sampling Frequencies */
constexpr uint16_t kLeAudioSamplingFreq8000Hz =
    SamplingFreqConfig2Capability(codec_spec_conf::kLeAudioSamplingFreq8000Hz);
constexpr uint16_t kLeAudioSamplingFreq11025Hz =
    SamplingFreqConfig2Capability(codec_spec_conf::kLeAudioSamplingFreq11025Hz);
constexpr uint16_t kLeAudioSamplingFreq16000Hz =
    SamplingFreqConfig2Capability(codec_spec_conf::kLeAudioSamplingFreq16000Hz);
constexpr uint16_t kLeAudioSamplingFreq22050Hz =
    SamplingFreqConfig2Capability(codec_spec_conf::kLeAudioSamplingFreq22050Hz);
constexpr uint16_t kLeAudioSamplingFreq24000Hz =
    SamplingFreqConfig2Capability(codec_spec_conf::kLeAudioSamplingFreq24000Hz);
constexpr uint16_t kLeAudioSamplingFreq32000Hz =
@@ -236,6 +240,16 @@ constexpr uint16_t kLeAudioSamplingFreq44100Hz =
    SamplingFreqConfig2Capability(codec_spec_conf::kLeAudioSamplingFreq44100Hz);
constexpr uint16_t kLeAudioSamplingFreq48000Hz =
    SamplingFreqConfig2Capability(codec_spec_conf::kLeAudioSamplingFreq48000Hz);
constexpr uint16_t kLeAudioSamplingFreq88200Hz =
    SamplingFreqConfig2Capability(codec_spec_conf::kLeAudioSamplingFreq88200Hz);
constexpr uint16_t kLeAudioSamplingFreq96000Hz =
    SamplingFreqConfig2Capability(codec_spec_conf::kLeAudioSamplingFreq96000Hz);
constexpr uint16_t kLeAudioSamplingFreq176400Hz = SamplingFreqConfig2Capability(
    codec_spec_conf::kLeAudioSamplingFreq176400Hz);
constexpr uint16_t kLeAudioSamplingFreq192000Hz = SamplingFreqConfig2Capability(
    codec_spec_conf::kLeAudioSamplingFreq192000Hz);
constexpr uint16_t kLeAudioSamplingFreq384000Hz = SamplingFreqConfig2Capability(
    codec_spec_conf::kLeAudioSamplingFreq384000Hz);

/* Frame Durations */
constexpr uint8_t kLeAudioCodecLC3FrameDur7500us =
@@ -254,6 +268,12 @@ constexpr uint8_t kLeAudioCodecLC3FrameDurPrefer10000us = 0x20;
constexpr uint8_t kLeAudioCodecLC3ChannelCountNone = 0x00;
constexpr uint8_t kLeAudioCodecLC3ChannelCountSingleChannel = 0x01;
constexpr uint8_t kLeAudioCodecLC3ChannelCountTwoChannel = 0x02;
constexpr uint8_t kLeAudioCodecLC3ChannelCountThreeChannel = 0x04;
constexpr uint8_t kLeAudioCodecLC3ChannelCountFourChannel = 0x08;
constexpr uint8_t kLeAudioCodecLC3ChannelCountFiveChannel = 0x10;
constexpr uint8_t kLeAudioCodecLC3ChannelCountSixChannel = 0x20;
constexpr uint8_t kLeAudioCodecLC3ChannelCountSevenChannel = 0x40;
constexpr uint8_t kLeAudioCodecLC3ChannelCountEightChannel = 0x40;

/* Octets Per Frame - same as in Codec Specific Configurations but in
 * capabilities we get two values: min and max.
@@ -505,6 +525,10 @@ constexpr AudioContexts kLeAudioContextAllTypes =
    LeAudioContextType::NOTIFICATIONS | LeAudioContextType::RINGTONE |
    LeAudioContextType::ALERTS | LeAudioContextType::EMERGENCYALARM;

/* Print formaters for LTV data */
std::string CodecCapabilitiesLtvFormat(const uint8_t& type,
                                       const std::vector<uint8_t>& value);

/* Structures */
class LeAudioLtvMap {
 public:
@@ -523,7 +547,9 @@ class LeAudioLtvMap {
  const std::map<uint8_t, std::vector<uint8_t>>& Values() const {
    return values;
  }
  std::string ToString() const;
  std::string ToString(
      const std::string& indent_string,
      std::string (*format)(const uint8_t&, const std::vector<uint8_t>&)) const;
  size_t RawPacketSize() const;
  uint8_t* RawPacket(uint8_t* p_buf) const;
  std::vector<uint8_t> RawPacket() const;