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

Commit fb6449ed authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Łukasz Rymanowski
Browse files

LeAudio: Remove Lc3 spec. code from client_parser

Bug: 295972694
Test: atest bluetooth_le_audio_test bluetooth_le_audio_client_test  bluetooth_test_broadcaster bluetooth_test_broadcaster_state_machine
Change-Id: Iec29b128a97fe013d44be94c6c34e282cfe83279
parent 634365bb
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -321,15 +321,14 @@ bool PrepareAseCtpCodecConfig(const std::vector<struct ctp_codec_conf>& confs,
      confs.begin(), confs.end(),
      confs.size() * kCtpCodecConfMinLen + kAseNumSize + kCtpOpSize,
      [&conf_ents_str](size_t cur_len, auto const& conf) {
        auto ltv_map = conf.codec_config.GetAsLtvMap();
        for (const auto& [type, value] : ltv_map.Values()) {
        for (const auto& [type, value] : conf.codec_config.Values()) {
          conf_ents_str +=
              "\ttype: " + std::to_string(type) +
              "\tlen: " + std::to_string(value.size()) +
              "\tdata: " + base::HexEncode(value.data(), value.size()) + "\n";
        };

        return cur_len + ltv_map.RawPacketSize();
        return cur_len + conf.codec_config.RawPacketSize();
      });
  value.resize(msg_len);

@@ -345,11 +344,10 @@ bool PrepareAseCtpCodecConfig(const std::vector<struct ctp_codec_conf>& confs,
    UINT16_TO_STREAM(msg, conf.codec_id.vendor_company_id);
    UINT16_TO_STREAM(msg, conf.codec_id.vendor_codec_id);

    auto ltv_map = conf.codec_config.GetAsLtvMap();
    auto codec_spec_conf_len = ltv_map.RawPacketSize();
    auto codec_spec_conf_len = conf.codec_config.RawPacketSize();

    UINT8_TO_STREAM(msg, codec_spec_conf_len);
    msg = ltv_map.RawPacket(msg);
    msg = conf.codec_config.RawPacket(msg);

    LOG(INFO) << __func__ << ", Codec configuration"
              << "\n\tAse id: " << loghex(conf.ase_id)
+1 −1
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ struct ctp_codec_conf {
  uint8_t target_latency;
  uint8_t target_phy;
  types::LeAudioCodecId codec_id;
  types::LeAudioLc3Config codec_config;
  types::LeAudioLtvMap codec_config;
};

constexpr uint16_t kCtpQosConfMinLen = 16;
+27 −12
Original line number Diff line number Diff line
@@ -1112,10 +1112,15 @@ TEST(LeAudioClientParserTest, testPrepareAseCtpCodecConfigSingle) {
  types::LeAudioCodecId codec_id{.coding_format = 0x06,
                                 .vendor_company_id = 0x0203,
                                 .vendor_codec_id = 0x0405};
  types::LeAudioLc3Config codec_conf{.sampling_frequency = 0x10,
                                     .frame_duration = 0x03,
                                     .audio_channel_allocation = 0x04050607,
                                     .octets_per_codec_frame = 0x0203};
  types::LeAudioLtvMap codec_conf =
      types::LeAudioLtvMap()
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeSamplingFreq, (uint8_t)0x10)
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeFrameDuration,
               (uint8_t)0x03)
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeAudioChannelAllocation,
               (uint32_t)0x04050607)
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeOctetPerFrame,
               (uint16_t)0x0203);

  confs.push_back(ctp_codec_conf{
      .ase_id = 0x05,
@@ -1168,10 +1173,15 @@ TEST(LeAudioClientParserTest, testPrepareAseCtpCodecConfigMultiple) {
  types::LeAudioCodecId codec_id{.coding_format = 0x06,
                                 .vendor_company_id = 0x0203,
                                 .vendor_codec_id = 0x0405};
  types::LeAudioLc3Config codec_conf{.sampling_frequency = 0x10,
                                     .frame_duration = 0x03,
                                     .audio_channel_allocation = 0x04050607,
                                     .octets_per_codec_frame = 0x0203};
  types::LeAudioLtvMap codec_conf =
      types::LeAudioLtvMap()
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeSamplingFreq, (uint8_t)0x10)
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeFrameDuration,
               (uint8_t)0x03)
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeAudioChannelAllocation,
               (uint32_t)0x04050607)
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeOctetPerFrame,
               (uint16_t)0x0203);

  confs.push_back(ctp_codec_conf{
      .ase_id = 0x05,
@@ -1219,10 +1229,15 @@ TEST(LeAudioClientParserTest, testPrepareAseCtpCodecConfigMultiple) {
  types::LeAudioCodecId codec_id2{.coding_format = 0x16,
                                  .vendor_company_id = 0x1213,
                                  .vendor_codec_id = 0x1415};
  types::LeAudioLc3Config codec_conf2{.sampling_frequency = 0x11,
                                      .frame_duration = 0x13,
                                      .audio_channel_allocation = 0x14151617,
                                      .octets_per_codec_frame = 0x1213};
  types::LeAudioLtvMap codec_conf2 =
      types::LeAudioLtvMap()
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeSamplingFreq, (uint8_t)0x11)
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeFrameDuration,
               (uint8_t)0x13)
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeAudioChannelAllocation,
               (uint32_t)0x14151617)
          .Add(codec_spec_conf::kLeAudioCodecLC3TypeOctetPerFrame,
               (uint16_t)0x1213);

  confs.push_back(ctp_codec_conf{
      .ase_id = 0x15,
+26 −1
Original line number Diff line number Diff line
@@ -544,8 +544,33 @@ class LeAudioLtvMap {
      : values(std::move(values)) {}

  std::optional<std::vector<uint8_t>> Find(uint8_t type) const;
  void Add(uint8_t type, std::vector<uint8_t> value) {
  LeAudioLtvMap& Add(uint8_t type, std::vector<uint8_t> value) {
    values.insert_or_assign(type, std::move(value));
    return *this;
  }
  LeAudioLtvMap& Add(uint8_t type, uint8_t value) {
    std::vector<uint8_t> v(sizeof(value));
    auto ptr = v.data();

    UINT8_TO_STREAM(ptr, value);
    values.insert_or_assign(type, v);
    return *this;
  }
  LeAudioLtvMap& Add(uint8_t type, uint16_t value) {
    std::vector<uint8_t> v(sizeof(value));
    auto ptr = v.data();

    UINT16_TO_STREAM(ptr, value);
    values.insert_or_assign(type, std::move(v));
    return *this;
  }
  LeAudioLtvMap& Add(uint8_t type, uint32_t value) {
    std::vector<uint8_t> v(sizeof(value));
    auto ptr = v.data();

    UINT32_TO_STREAM(ptr, value);
    values.insert_or_assign(type, std::move(v));
    return *this;
  }
  void Remove(uint8_t type) { values.erase(type); }
  bool IsEmpty() const { return values.empty(); }
+2 −1
Original line number Diff line number Diff line
@@ -1655,7 +1655,8 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
      conf.target_latency = ase->target_latency;
      conf.target_phy = group->GetTargetPhy(ase->direction);
      conf.codec_id = ase->codec_id;
      conf.codec_config = ase->codec_config;
      // FIXME: Use LtvMap in ASE
      conf.codec_config = ase->codec_config.GetAsLtvMap();
      confs.push_back(conf);

      msg_stream << "ASE_ID " << +conf.ase_id << ",";