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

Commit d9f126ec authored by Jakub Rotkiewicz's avatar Jakub Rotkiewicz
Browse files

aidl/a2dp_provider_info: refactor Source/SinkCodecIndex

Handle default A2DP codecs in SourceCodecIndex and SinkCodecIndex
functions.

Bug: 305734815
Test: m com.android.btservices
Change-Id: Iae2654e43b1858bb7b09ded2c754cc32a274e26a
parent 1bcc1b6a
Loading
Loading
Loading
Loading
+44 −17
Original line number Diff line number Diff line
@@ -218,8 +218,8 @@ ProviderInfo::ProviderInfo(std::vector<CodecInfo> source_codecs,
  }

  btav_a2dp_codec_index_t ext_sink_index = BTAV_A2DP_CODEC_INDEX_SINK_EXT_MIN;
  for (size_t i = 0; i < this->source_codecs.size(); i++) {
    auto& codec = this->source_codecs[i];
  for (size_t i = 0; i < this->sink_codecs.size(); i++) {
    auto& codec = this->sink_codecs[i];
    LOG(INFO) << "supports sink codec " << codec.name;
    auto index = assignSinkCodecIndex(codec, &ext_sink_index);
    if (index.has_value()) {
@@ -256,16 +256,35 @@ std::optional<btav_a2dp_codec_index_t> ProviderInfo::SourceCodecIndex(
std::optional<btav_a2dp_codec_index_t> ProviderInfo::SourceCodecIndex(
    uint8_t const* codec_info) const {
  LOG_ASSERT(codec_info != nullptr) << "codec_info is unexpectedly null";
  if (A2DP_GetCodecType(codec_info) != A2DP_MEDIA_CT_NON_A2DP) {
    // TODO(henrichataing): would be required if a vendor decided
    // to implement a standard codec other than SBC, AAC.
    return std::nullopt;
  auto codec_type = A2DP_GetCodecType(codec_info);
  switch (codec_type) {
    case A2DP_MEDIA_CT_SBC: {
      return SourceCodecIndex(CodecId::A2dp(CodecId::A2dp::SBC));
    }

    case A2DP_MEDIA_CT_AAC: {
      return SourceCodecIndex(CodecId::A2dp(CodecId::A2dp::AAC));
    }
    case A2DP_MEDIA_CT_NON_A2DP: {
      uint32_t vendor_id = A2DP_VendorCodecGetVendorId(codec_info);
      uint16_t codec_id = A2DP_VendorCodecGetCodecId(codec_info);
      return SourceCodecIndex(vendor_id, codec_id);
    }
    default: {
      return std::nullopt;
    }
  }
}

std::optional<btav_a2dp_codec_index_t> ProviderInfo::SinkCodecIndex(
    CodecId const& codec_id) const {
  for (auto const& [index, codec] : assigned_codec_indexes) {
    if (codec->id == codec_id && index >= BTAV_A2DP_CODEC_INDEX_SINK_MIN &&
        index < BTAV_A2DP_CODEC_INDEX_SINK_EXT_MAX) {
      return index;
    }
  }
  return std::nullopt;
}

std::optional<btav_a2dp_codec_index_t> ProviderInfo::SinkCodecIndex(
    uint32_t vendor_id, uint16_t codec_id) const {
@@ -284,16 +303,24 @@ std::optional<btav_a2dp_codec_index_t> ProviderInfo::SinkCodecIndex(
std::optional<btav_a2dp_codec_index_t> ProviderInfo::SinkCodecIndex(
    uint8_t const* codec_info) const {
  LOG_ASSERT(codec_info != nullptr) << "codec_info is unexpectedly null";
  if (A2DP_GetCodecType(codec_info) != A2DP_MEDIA_CT_NON_A2DP) {
    // TODO(henrichataing): would be required if a vendor decided
    // to implement a standard codec other than SBC, AAC.
    return std::nullopt;
  auto codec_type = A2DP_GetCodecType(codec_info);
  switch (codec_type) {
    case A2DP_MEDIA_CT_SBC: {
      return SinkCodecIndex(CodecId::A2dp(CodecId::A2dp::SBC));
    }

    case A2DP_MEDIA_CT_AAC: {
      return SinkCodecIndex(CodecId::A2dp(CodecId::A2dp::AAC));
    }
    case A2DP_MEDIA_CT_NON_A2DP: {
      uint32_t vendor_id = A2DP_VendorCodecGetVendorId(codec_info);
      uint16_t codec_id = A2DP_VendorCodecGetCodecId(codec_info);
      return SinkCodecIndex(vendor_id, codec_id);
    }
    default: {
      return std::nullopt;
    }
  }
}

std::optional<const char*> ProviderInfo::CodecIndexStr(
    btav_a2dp_codec_index_t codec_index) const {
+2 −0
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ class ProviderInfo {
  /***
   * Find the sink codec index by codec capabilities.
   ***/
  std::optional<btav_a2dp_codec_index_t> SinkCodecIndex(
      CodecId const& codec_id) const;
  std::optional<btav_a2dp_codec_index_t> SinkCodecIndex(
      uint32_t vendor_id, uint16_t codec_id) const;
  std::optional<btav_a2dp_codec_index_t> SinkCodecIndex(