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

Commit a239be44 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes from topic "codec_ext_test" into main

* changes:
  aidl/a2dp_provider_info: add unit tests for ProviderInfo
  aidl/a2dp_provider_info: refactor Source/SinkCodecIndex
  aidl/a2dp_provider_info: fix Source/SinkCodecIndex
parents fe33c3d0 c3cf2881
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -322,6 +322,9 @@
    {
      "name": "bluetooth_le_audio_codec_manager_test"
    },
    {
      "name": "bluetooth-test-audio-hal-a2dp-provider-info"
    },
    {
      "name": "bluetooth_test_gdx_unit"
    },
+71 −0
Original line number Diff line number Diff line
@@ -117,3 +117,74 @@ cc_test {
    ],
    header_libs: ["libbluetooth_headers"],
}

// Bluetooth Audio Provider Info unit tests for target and host
cc_test {
    name: "bluetooth-test-audio-hal-a2dp-provider-info",
    test_suites: ["general-tests"],
    defaults: [
        "fluoride_defaults",
        "latest_android_hardware_bluetooth_audio_ndk_shared",
        "mts_defaults",
    ],
    cflags: [
        "-DBUILDCFG",
        "-DUNIT_TESTS",
        "-Wno-unused-parameter",
    ],
    host_supported: true,
    test_options: {
        unit_test: true,
    },
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
        "packages/modules/Bluetooth/system/stack/include",
    ],
    target: {
        host: {
            srcs: [
                ":BluetoothHostTestingLogCapture",
            ],
        },
        android: {
            srcs: [
                ":BluetoothAndroidTestingLogCapture",
            ],
        },
    },
    sanitize: {
        cfi: true,
        scs: true,
        address: true,
        all_undefined: true,
        integer_overflow: true,
        diag: {
            undefined: true,
        },
    },
    srcs: [
        ":TestCommonMockFunctions",
        ":TestMockAudioHalInterface",
        "aidl/a2dp_provider_info.cc",
        "aidl/a2dp_provider_info_unittest.cc",
    ],
    shared_libs: [
        "libbase",
        "libcutils",
        "libfmq",
        "liblog",
        "libutils",
        "server_configurable_flags",
    ],
    static_libs: [
        "bluetooth_flags_c_lib",
        "libbt-common",
        "libbt_shim_bridge",
        "libchrome",
        "libflagtest",
        "libgmock",
        "libosi",
    ],
    header_libs: ["libbluetooth_headers"],
}
+47 −20
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()) {
@@ -232,7 +232,7 @@ std::optional<btav_a2dp_codec_index_t> ProviderInfo::SourceCodecIndex(
    CodecId const& codec_id) const {
  for (auto const& [index, codec] : assigned_codec_indexes) {
    if (codec->id == codec_id && index >= BTAV_A2DP_CODEC_INDEX_SOURCE_MIN &&
        index < BTAV_A2DP_CODEC_INDEX_SOURCE_MAX) {
        index < BTAV_A2DP_CODEC_INDEX_SOURCE_EXT_MAX) {
      return index;
    }
  }
@@ -246,7 +246,7 @@ std::optional<btav_a2dp_codec_index_t> ProviderInfo::SourceCodecIndex(
        codec->id.get<CodecId::vendor>().id == (int)vendor_id &&
        codec->id.get<CodecId::vendor>().codecId == codec_id &&
        index >= BTAV_A2DP_CODEC_INDEX_SOURCE_MIN &&
        index < BTAV_A2DP_CODEC_INDEX_SOURCE_MAX) {
        index < BTAV_A2DP_CODEC_INDEX_SOURCE_EXT_MAX) {
      return index;
    }
  }
@@ -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 {
@@ -274,7 +293,7 @@ std::optional<btav_a2dp_codec_index_t> ProviderInfo::SinkCodecIndex(
        codec->id.get<CodecId::vendor>().id == (int)vendor_id &&
        codec->id.get<CodecId::vendor>().codecId == codec_id &&
        index >= BTAV_A2DP_CODEC_INDEX_SINK_MIN &&
        index < BTAV_A2DP_CODEC_INDEX_SINK_MAX) {
        index < BTAV_A2DP_CODEC_INDEX_SINK_EXT_MAX) {
      return index;
    }
  }
@@ -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(
+773 −0

File added.

Preview size limit exceeded, changes collapsed.