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

Commit 99d1760e authored by Hsin-chen Chuang's avatar Hsin-chen Chuang Committed by Gerrit Code Review
Browse files

Merge changes I7c0becd0,I658014a9 into main

* changes:
  btm_sco_hfp_hal_linux: Fix codec info for legacy devices
  btm_sco_hfp_hal: Change get_packet_size() return type to size_t
parents ed5827b4 871c522e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ bool enable_offload(bool enable) {
void set_codec_datapath(int codec_uuid) {}

// No packet size limits on Android since it will be offloaded.
int get_packet_size(int codec) { return kDefaultPacketSize; }
size_t get_packet_size(int codec) { return kDefaultPacketSize; }

void notify_sco_connection_change(RawAddress device, bool is_connected,
                                  int codec) {
+2 −2
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ struct bt_codecs {
};

// Use default packet size for codec if this value is given.
constexpr int kDefaultPacketSize = 0;
constexpr size_t kDefaultPacketSize = 0;

constexpr inline int esco_coding_to_codec(esco_coding_format_t esco_coding) {
  switch (esco_coding) {
@@ -94,7 +94,7 @@ bool enable_offload(bool enable);
void set_codec_datapath(int codec_uuid);

// Get the maximum supported packet size from the lower layer.
int get_packet_size(int codec);
size_t get_packet_size(int codec);

// Notify the lower layer about SCO connection change.
void notify_sco_connection_change(RawAddress device, bool is_connected,
+29 −42
Original line number Diff line number Diff line
@@ -38,17 +38,9 @@ namespace {
bool offload_supported = false;
bool offload_enabled = false;

struct mgmt_bt_codec {
  uint8_t codec;
  uint8_t packet_size;
  uint8_t data_path;
  uint32_t data_length;
  uint8_t data[];
} __attribute__((packed));

typedef struct cached_codec_info {
  struct bt_codec inner;
  uint8_t pkt_size;
  size_t pkt_size;
} cached_codec_info;

std::vector<cached_codec_info> cached_codecs;
@@ -93,46 +85,41 @@ struct mgmt_rp_get_codec_capabilities {
#define MGMT_POLL_TIMEOUT_MS 2000

void cache_codec_capabilities(struct mgmt_rp_get_codec_capabilities* rp) {
  const uint8_t kCodecCvsd = 0x2;
  const uint8_t kCodecTransparent = 0x3;
  const uint8_t kCodecMsbc = 0x5;

  auto codecs =
      bluetooth::shim::GetController()->GetLocalSupportedBrEdrCodecIds();

  for (uint8_t codec_id : codecs) {
  // TODO(b/323087725): Query the codec capabilities and fill in c.inner.data.
  // The capabilities are not used currently so it's safe to keep this for a
  // while.
    cached_codec_info c{};
    switch (codec_id) {
      case kCodecCvsd:
        c.inner.codec = codec::CVSD;
        break;
      case kCodecTransparent:
        if (!rp->transparent_wbs_supported) {
          // Transparent wideband speech not supported, skip it.
          continue;

  // CVSD is mandatory in HFP.
  cached_codecs.push_back({
      .inner = {.codec = codec::CVSD},
  });

  // No need to check GetLocalSupportedBrEdrCodecIds. Some legacy devices don't
  // even support HCI command Read Local Supported Codecs so WBS quirk is more
  // reliable.
  if (rp->transparent_wbs_supported) {
    cached_codecs.push_back({
        .inner = {.codec = codec::MSBC_TRANSPARENT},
        .pkt_size = rp->wbs_pkt_len,
    });
  }
        c.inner.codec = codec::MSBC_TRANSPARENT;
        c.pkt_size = rp->wbs_pkt_len;
        break;
      case kCodecMsbc:

  auto codecs =
      bluetooth::shim::GetController()->GetLocalSupportedBrEdrCodecIds();
  if (std::find(codecs.begin(), codecs.end(), kCodecMsbc) != codecs.end()) {
    offload_supported = true;
        c.inner.codec = codec::MSBC;
        c.inner.data_path = rp->hci_data_path_id;
        c.pkt_size = rp->wbs_pkt_len;
        break;
      default:
        log::debug("Unsupported codec ID: {}", codec_id);
        continue;
    cached_codecs.push_back({
        .inner = {.codec = codec::MSBC, .data_path = rp->hci_data_path_id},
        .pkt_size = rp->wbs_pkt_len,
    });
  }

  for (const auto& c : cached_codecs) {
    log::info("Caching HFP codec {}, data path {}, data len {}, pkt_size {}",
              (uint64_t)c.inner.codec, c.inner.data_path, c.inner.data.size(),
              c.pkt_size);

    cached_codecs.push_back(c);
  }
}

@@ -451,7 +438,7 @@ void set_codec_datapath(int codec_uuid) {
  }
}

int get_packet_size(int codec) {
size_t get_packet_size(int codec) {
  for (const cached_codec_info& c : cached_codecs) {
    if (c.inner.codec == codec) {
      return c.pkt_size;
+2 −2
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ bool enable_offload::return_value = false;
hfp_hal_interface::bt_codecs get_codec_capabilities::return_value = {};
bool get_offload_enabled::return_value = false;
bool get_offload_supported::return_value = false;
int get_packet_size::return_value = 0;
size_t get_packet_size::return_value = 0;
bool get_wbs_supported::return_value = false;
bool get_swb_supported::return_value = false;
bool is_coding_format_supported::return_value = false;
@@ -90,7 +90,7 @@ bool get_offload_supported() {
  inc_func_call_count(__func__);
  return test::mock::stack_btm_sco_hfp_hal::get_offload_supported();
}
int get_packet_size(int codec) {
size_t get_packet_size(int codec) {
  inc_func_call_count(__func__);
  return test::mock::stack_btm_sco_hfp_hal::get_packet_size(codec);
}
+4 −4
Original line number Diff line number Diff line
@@ -85,12 +85,12 @@ extern struct get_offload_supported get_offload_supported;

// Name: get_packet_size
// Params: int codec
// Return: int
// Return: size_t
struct get_packet_size {
  static int return_value;
  std::function<int(int /* codec */)> body{
  static size_t return_value;
  std::function<size_t(int /* codec */)> body{
      [](int /* codec */) { return return_value; }};
  int operator()(int codec) { return body(codec); };
  size_t operator()(int codec) { return body(codec); };
};
extern struct get_packet_size get_packet_size;