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

Commit 365a0ed8 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Jakub Pawłowski
Browse files

LeAudio/CodecExtensibility: Use the AIDL configuration provider API

Bug: 308428644
Bug: 313054645
Test: atest bluetooth-test-audio-hal-le-audio-software bluetooth-test-audio-hal-aidl-leaudio-utils bluetooth_le_audio_test bluetooth_le_audio_client_test bluetooth_test_broadcaster bluetooth_test_broadcaster_state_machine bluetooth_le_audio_codec_manager_test
Merged-In: I36820b297bad042b8927e10158056746b07cfeaa
Change-Id: I36820b297bad042b8927e10158056746b07cfeaa
parent d232d878
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ cc_library_static {
                "aidl/hearing_aid_software_encoding_aidl.cc",
                "aidl/hfp_client_interface_aidl.cc",
                "aidl/le_audio_software_aidl.cc",
                "aidl/le_audio_utils.cc",
                "aidl/provider_info.cc",
                "hal_version_manager.cc",
                "hearing_aid_software_encoding.cc",
@@ -182,6 +183,7 @@ cc_test {
        "android.hardware.common.fmq-V1-ndk",
        "bluetooth_flags_c_lib",
        "libbase",
        "libbluetooth-types",
        "libbluetooth_log",
        "libbt-common",
        "libbt_shim_bridge",
@@ -340,6 +342,7 @@ cc_test {
        ":TestMockCodecManager",
        ":TestMockOsi",
        "aidl/le_audio_software_aidl.cc",
        "aidl/le_audio_utils.cc",
        "hidl/le_audio_software_hidl.cc",
        "le_audio_software.cc",
        "le_audio_software_unittest.cc",
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
#include "audio_aidl_interfaces.h"
#include "audio_ctrl_ack.h"
#include "bluetooth_audio_port_impl.h"
#include "bta/le_audio/broadcaster/broadcaster_types.h"
#include "bta/le_audio/le_audio_types.h"
#include "transport_instance.h"

#define BLUETOOTH_AUDIO_HAL_PROP_DISABLED \
+9 −1
Original line number Diff line number Diff line
@@ -519,6 +519,14 @@ GetStackDataPathFromAidlFormat(
          .configuration = {},
      }};

  // Due to AIDL not having the Transparent codec type, it uses the boolean and
  // we should manually align the codecId.
  if (config.isoDataPathConfig.isTransparent) {
    config.isoDataPathConfig.codecId.coding_format = 0x03;  // Transparent
    config.isoDataPathConfig.codecId.vendor_codec_id = 0x00;
    config.isoDataPathConfig.codecId.vendor_company_id = 0x00;
  }

  if (dp.dataPathConfiguration.configuration) {
    config.dataPathConfig = *dp.dataPathConfiguration.configuration;
  }
@@ -570,7 +578,7 @@ GetStackConfigSettingFromAidl(
  }

  ::bluetooth::le_audio::set_configurations::AudioSetConfiguration cig_config{
      .name = "",
      .name = "AIDL codec provider configuration",
      .packing = (uint8_t)aidl_ase_config.packing,
      .confs = {.sink = {}, .source = {}},
  };
+80 −1
Original line number Diff line number Diff line
@@ -22,11 +22,13 @@
#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>

#include <unordered_map>
#include <vector>

#include "aidl/android/hardware/bluetooth/audio/AudioContext.h"
#include "aidl/le_audio_software_aidl.h"
#include "aidl/le_audio_utils.h"
#include "bta/le_audio/codec_manager.h"
#include "bta/le_audio/le_audio_types.h"
#include "hal_version_manager.h"
#include "hidl/le_audio_software_hidl.h"
#include "os/log.h"
@@ -34,6 +36,13 @@

namespace bluetooth {
namespace audio {

using aidl::GetAidlLeAudioBroadcastConfigurationRequirementFromStackFormat;
using aidl::GetAidlLeAudioDeviceCapabilitiesFromStackFormat;
using aidl::GetAidlLeAudioUnicastConfigurationRequirementsFromStackFormat;
using aidl::GetStackBroadcastConfigurationFromAidlFormat;
using aidl::GetStackUnicastConfigurationFromAidlFormat;

namespace le_audio {

namespace {
@@ -43,6 +52,8 @@ using AudioConfiguration_2_1 =
    ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration;
using AudioConfigurationAIDL =
    ::aidl::android::hardware::bluetooth::audio::AudioConfiguration;
using ::aidl::android::hardware::bluetooth::audio::AudioContext;
using ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider;
using ::aidl::android::hardware::bluetooth::audio::LatencyMode;
using ::aidl::android::hardware::bluetooth::audio::LeAudioCodecConfiguration;

@@ -414,6 +425,74 @@ void LeAudioClientInterface::Sink::UpdateAudioConfigToHal(
          aidl::le_audio::offload_config_to_hal_audio_config(offload_config));
}

std::optional<::bluetooth::le_audio::broadcaster::BroadcastConfiguration>
LeAudioClientInterface::Sink::GetBroadcastConfig(
    const std::vector<
        std::pair<::bluetooth::le_audio::types::LeAudioContextType, uint8_t>>&
        subgroup_quality,
    const std::optional<
        std::vector<::bluetooth::le_audio::types::acs_ac_record>>& pacs) const {
  if (HalVersionManager::GetHalTransport() ==
      BluetoothAudioHalTransport::HIDL) {
    return std::nullopt;
  }

  if (!is_broadcaster_ || !is_aidl_offload_encoding_session(is_broadcaster_)) {
    return std::nullopt;
  }

  auto aidl_pacs = GetAidlLeAudioDeviceCapabilitiesFromStackFormat(pacs);
  auto reqs = GetAidlLeAudioBroadcastConfigurationRequirementFromStackFormat(
      subgroup_quality);
  auto aidl_broadcast_config =
      aidl::le_audio::LeAudioSourceTransport::
          interface->getLeAudioBroadcastConfiguration(aidl_pacs, reqs);

  return GetStackBroadcastConfigurationFromAidlFormat(aidl_broadcast_config);
}

// This API is for requesting a single configuration.
// Note: We need a bulk API as well to get multiple configurations for caching
std::optional<::bluetooth::le_audio::set_configurations::AudioSetConfiguration>
LeAudioClientInterface::Sink::GetUnicastConfig(
    const ::bluetooth::le_audio::CodecManager::UnicastConfigurationRequirements&
        requirements) const {
  log::debug("Requirements: {}", requirements);

  auto aidl_sink_pacs =
      GetAidlLeAudioDeviceCapabilitiesFromStackFormat(requirements.sink_pacs);

  auto aidl_source_pacs =
      GetAidlLeAudioDeviceCapabilitiesFromStackFormat(requirements.source_pacs);

  std::vector<IBluetoothAudioProvider::LeAudioConfigurationRequirement> reqs;
  reqs.push_back(GetAidlLeAudioUnicastConfigurationRequirementsFromStackFormat(
      requirements.audio_context_type, requirements.sink_requirements,
      requirements.source_requirements));

  log::debug("Making an AIDL call");
  auto aidl_configs =
      get_aidl_client_interface(is_broadcaster_)
          ->GetLeAudioAseConfiguration(aidl_sink_pacs, aidl_source_pacs, reqs);

  log::debug("Received {} configs", aidl_configs.size());

  if (aidl_configs.size() == 0) {
    log::error("Expecting a single configuration, but received none.");
    return std::nullopt;
  }

  /* Given a single requirement we should get a single response config
   * Note: For a bulk request we need to implement GetUnicastConfigs() method
   */
  if (aidl_configs.size() > 1) {
    log::warn("Expected a single configuration, but received {}",
              aidl_configs.size());
  }
  return GetStackUnicastConfigurationFromAidlFormat(
      requirements.audio_context_type, aidl_configs.at(0));
}

void LeAudioClientInterface::Sink::UpdateBroadcastAudioConfigToHal(
    const ::bluetooth::le_audio::broadcast_offload_config& offload_config) {
  if (HalVersionManager::GetHalTransport() ==
+13 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <com_android_bluetooth_flags.h>

#include <functional>
#include <optional>

#include "bta/le_audio/codec_manager.h"
#include "bta/le_audio/le_audio_types.h"
@@ -127,6 +128,18 @@ class LeAudioClientInterface {
    // Read the stream of bytes sinked to us by the upper layers
    size_t Read(uint8_t* p_buf, uint32_t len);
    bool IsBroadcaster() { return is_broadcaster_; }
    std::optional<::bluetooth::le_audio::broadcaster::BroadcastConfiguration>
    GetBroadcastConfig(
        const std::vector<std::pair<
            ::bluetooth::le_audio::types::LeAudioContextType, uint8_t>>&
            subgroup_quality,
        const std::optional<
            std::vector<::bluetooth::le_audio::types::acs_ac_record>>& pacs)
        const;
    std::optional<
        ::bluetooth::le_audio::set_configurations::AudioSetConfiguration>
    GetUnicastConfig(const ::bluetooth::le_audio::CodecManager::
                         UnicastConfigurationRequirements& requirements) const;

   private:
    bool is_broadcaster_ = false;
Loading