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

Commit 767f1d65 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

LeAudio: Support vendor configurations in control point operations

With this change we store the raw data in ctp_codec_conf instead of
storing the source LTV formatted codec configuration, from which we
generated the raw data at the later stage when the control point is
written.

By moving the raw data generation to an earlier stage we prapare the
ctp_codec_conf structure to pass the opaque vendor codec specific data,
and not just the LTV data format used by the LC3 codec.

Bug: 308427707
Test: atest bluetooth_le_audio_test
Flag: EXEMPT; refactor for the multicodec support, only moved the data buffer generation to an earlier stage, and the end result is the same - confirmed with the unit tests.
Change-Id: Ieec55300951b94c8f1f2d2ee476fe9606d18cb58
parent e085b76c
Loading
Loading
Loading
Loading
+26 −16
Original line number Diff line number Diff line
@@ -315,22 +315,33 @@ bool PrepareAseCtpCodecConfig(const std::vector<struct ctp_codec_conf>& confs,
                              std::vector<uint8_t>& value) {
  if (confs.size() == 0) return false;

  std::string conf_ents_str;
  std::stringstream conf_ents_str;
  size_t msg_len = std::accumulate(
      confs.begin(), confs.end(),
      confs.size() * kCtpCodecConfMinLen + kAseNumSize + kCtpOpSize,
      [&conf_ents_str](size_t cur_len, auto const& conf) {
        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";
        };
        if (utils::IsCodecUsingLtvFormat(conf.codec_id)) {
          types::LeAudioLtvMap ltv;
          if (ltv.Parse(conf.codec_config.data(), conf.codec_config.size())) {
            for (const auto& [type, value] : ltv.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 + conf.codec_config.size();
          }
          LOG_ERROR("Error parsing codec configuration LTV data.");
        }

        return cur_len + conf.codec_config.RawPacketSize();
        conf_ents_str << "\t"
                      << base::HexEncode(conf.codec_config.data(),
                                         conf.codec_config.size());
        return cur_len + conf.codec_config.size();
      });
  value.resize(msg_len);

  value.resize(msg_len);
  uint8_t* msg = value.data();
  UINT8_TO_STREAM(msg, kCtpOpcodeCodecConfiguration);

@@ -343,10 +354,9 @@ 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 codec_spec_conf_len = conf.codec_config.RawPacketSize();

    UINT8_TO_STREAM(msg, codec_spec_conf_len);
    msg = conf.codec_config.RawPacket(msg);
    UINT8_TO_STREAM(msg, conf.codec_config.size());
    ARRAY_TO_STREAM(msg, conf.codec_config.data(),
                    static_cast<int>(conf.codec_config.size()));

    LOG(INFO) << __func__ << ", Codec configuration"
              << "\n\tAse id: " << loghex(conf.ase_id)
@@ -358,10 +368,10 @@ bool PrepareAseCtpCodecConfig(const std::vector<struct ctp_codec_conf>& confs,
              << "\n\tVendor codec ID: "
              << loghex(conf.codec_id.vendor_codec_id)
              << "\n\tCodec config len: "
              << static_cast<int>(codec_spec_conf_len)
              << static_cast<int>(conf.codec_config.size())
              << "\n\tCodec spec conf: "
              << "\n"
              << conf_ents_str;
              << conf_ents_str.str();
  }

  return true;
+1 −1
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ struct ctp_codec_conf {
  uint8_t target_latency;
  uint8_t target_phy;
  types::LeAudioCodecId codec_id;
  types::LeAudioLtvMap codec_config;
  std::vector<uint8_t> codec_config;
};

constexpr uint16_t kCtpQosConfMinLen = 16;
+3 −3
Original line number Diff line number Diff line
@@ -1177,7 +1177,7 @@ TEST(LeAudioClientParserTest, testPrepareAseCtpCodecConfigSingle) {
      .target_latency = 0x03,
      .target_phy = 0x02,
      .codec_id = codec_id,
      .codec_config = codec_conf,
      .codec_config = codec_conf.RawPacket(),
  });
  PrepareAseCtpCodecConfig(confs, value);

@@ -1237,7 +1237,7 @@ TEST(LeAudioClientParserTest, testPrepareAseCtpCodecConfigMultiple) {
      .target_latency = 0x03,
      .target_phy = 0x02,
      .codec_id = codec_id,
      .codec_config = codec_conf,
      .codec_config = codec_conf.RawPacket(),
  });
  PrepareAseCtpCodecConfig(confs, value);

@@ -1292,7 +1292,7 @@ TEST(LeAudioClientParserTest, testPrepareAseCtpCodecConfigMultiple) {
      .target_latency = 0x13,
      .target_phy = 0x01,
      .codec_id = codec_id2,
      .codec_config = codec_conf2,
      .codec_config = codec_conf2.RawPacket(),
  });
  PrepareAseCtpCodecConfig(confs, value);

+1 −1
Original line number Diff line number Diff line
@@ -1791,7 +1791,7 @@ 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;
      conf.codec_config = ase->codec_config.RawPacket();
      confs.push_back(conf);

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