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

Commit dd4207bb authored by Henri Chataing's avatar Henri Chataing
Browse files

audio_hal_interface: Pass current codec config as parameter to setup_codec

Removes the dependency from audio_hal_interface to
  - bta_av_get_a2dp_current_codec

Bug: 365022887
Test: m com.android.btservices
Flag: EXEMPT, no logical change
Change-Id: Ib4f74fd8a4832fa98d2dead3a0b920b8987f7138
parent 6964abb8
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -70,11 +70,11 @@ void cleanup() {
}

// Set up the codec into BluetoothAudio HAL
bool setup_codec() {
bool setup_codec(A2dpCodecConfig* a2dp_config) {
  if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) {
    return hidl::a2dp::setup_codec();
    return hidl::a2dp::setup_codec(a2dp_config);
  }
  return aidl::a2dp::setup_codec();
  return aidl::a2dp::setup_codec(a2dp_config);
}

// Send command to the BluetoothAudio HAL: StartSession, EndSession,
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <sstream>
#include <vector>

#include "a2dp_codec_api.h"
#include "a2dp_constants.h"
#include "avdt_api.h"
#include "common/message_loop_thread.h"
@@ -56,7 +57,7 @@ bool init(bluetooth::common::MessageLoopThread* message_loop);
void cleanup();

// Set up the codec into BluetoothAudio HAL
bool setup_codec();
bool setup_codec(A2dpCodecConfig* a2dp_config);

// Set low latency buffer mode allowed or disallowed
void set_audio_low_latency_mode_allowed(bool allowed);
+1 −1
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ void cleanup() {
}

// Set up the codec into BluetoothAudio HAL
bool setup_codec() {
bool setup_codec(A2dpCodecConfig* /*a2dp_config*/) {
  // TODO: setup codec
  return true;
}
+9 −22
Original line number Diff line number Diff line
@@ -288,12 +288,8 @@ static uint16_t a2dp_get_peer_mtu(btav_a2dp_codec_index_t codec_index, uint8_t c
  return peer_mtu;
}

bool a2dp_get_selected_hal_codec_config(CodecConfiguration* codec_config) {
  A2dpCodecConfig* a2dp_config = bta_av_get_a2dp_current_codec();
  if (a2dp_config == nullptr) {
    log::warn("failure to get A2DP codec config");
    return false;
  }
bool a2dp_get_selected_hal_codec_config(A2dpCodecConfig* a2dp_config,
                                        CodecConfiguration* codec_config) {
  btav_a2dp_codec_config_t current_codec = a2dp_config->getCodecConfig();
  switch (current_codec.codec_type) {
    case BTAV_A2DP_CODEC_INDEX_SOURCE_SBC:
@@ -360,16 +356,11 @@ bool a2dp_get_selected_hal_codec_config(CodecConfiguration* codec_config) {
  return true;
}

bool a2dp_get_selected_hal_pcm_config(PcmConfiguration* pcm_config) {
static bool a2dp_get_selected_hal_pcm_config(A2dpCodecConfig* a2dp_codec_configs,
                                             PcmConfiguration* pcm_config) {
  if (pcm_config == nullptr) {
    return false;
  }
  A2dpCodecConfig* a2dp_codec_configs = bta_av_get_a2dp_current_codec();
  if (a2dp_codec_configs == nullptr) {
    log::warn("failure to get A2DP codec config");
    *pcm_config = BluetoothAudioSinkClientInterface::kInvalidPcmConfiguration;
    return false;
  }

  btav_a2dp_codec_config_t current_codec = a2dp_codec_configs->getCodecConfig();
  pcm_config->sampleRateHz = A2dpCodecToHalSampleRate(current_codec);
@@ -514,18 +505,14 @@ void cleanup() {
}

// Set up the codec into BluetoothAudio HAL
bool setup_codec() {
bool setup_codec(A2dpCodecConfig* a2dp_config) {
  log::assert_that(a2dp_config != nullptr, "received invalid codec configuration");

  if (!is_hal_enabled()) {
    log::error("BluetoothAudio HAL is not enabled");
    return false;
  }

  A2dpCodecConfig* a2dp_config = bta_av_get_a2dp_current_codec();
  if (a2dp_config == nullptr) {
    log::error("the current codec is not configured");
    return false;
  }

  if (provider::supports_codec(a2dp_config->codecIndex())) {
    // The codec is supported in the provider info (AIDL v4).
    // In this case, the codec is offloaded, and the configuration passed
@@ -569,7 +556,7 @@ bool setup_codec() {
  // Fallback to legacy offloading path.
  CodecConfiguration codec_config{};

  if (!a2dp_get_selected_hal_codec_config(&codec_config)) {
  if (!a2dp_get_selected_hal_codec_config(a2dp_config, &codec_config)) {
    log::error("Failed to get CodecConfiguration");
    return false;
  }
@@ -592,7 +579,7 @@ bool setup_codec() {
    audio_config.set<AudioConfiguration::a2dpConfig>(codec_config);
  } else {
    PcmConfiguration pcm_config{};
    if (!a2dp_get_selected_hal_pcm_config(&pcm_config)) {
    if (!a2dp_get_selected_hal_pcm_config(a2dp_config, &pcm_config)) {
      log::error("Failed to get PcmConfiguration");
      return false;
    }
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ void cleanup();
/***
 * Set up the codec into BluetoothAudio HAL
 ***/
bool setup_codec();
bool setup_codec(A2dpCodecConfig* a2dp_config);

/***
 * Send command to the BluetoothAudio HAL: StartSession, EndSession,
Loading