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

Commit e9b95b9a authored by Henri Chataing's avatar Henri Chataing Committed by Automerger Merge Worker
Browse files

Merge "Replace tA2DP_CTRL_ACK in audio HIDL and AIDL clients" into main am: 35291772

parents a18c574c 35291772
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ void start_session() {
  }
  aidl::a2dp::start_session();
}

void end_session() {
  if (HalVersionManager::GetHalTransport() ==
      BluetoothAudioHalTransport::AIDL) {
@@ -105,7 +106,8 @@ void end_session() {
    return;
  }
}
void ack_stream_started(const tA2DP_CTRL_ACK& status) {

void ack_stream_started(BluetoothAudioStatus status) {
  if (HalVersionManager::GetHalTransport() ==
      BluetoothAudioHalTransport::HIDL) {
    hidl::a2dp::ack_stream_started(status);
@@ -113,7 +115,8 @@ void ack_stream_started(const tA2DP_CTRL_ACK& status) {
  }
  return aidl::a2dp::ack_stream_started(status);
}
void ack_stream_suspended(const tA2DP_CTRL_ACK& status) {

void ack_stream_suspended(BluetoothAudioStatus status) {
  if (HalVersionManager::GetHalTransport() ==
      BluetoothAudioHalTransport::HIDL) {
    hidl::a2dp::ack_stream_suspended(status);
+21 −3
Original line number Diff line number Diff line
@@ -21,14 +21,26 @@
#include <vector>

#include "a2dp_error_codes.h"
#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
#include "avdt_api.h"
#include "common/message_loop_thread.h"
#include "hardware/bt_av.h"

namespace bluetooth {
namespace audio {
namespace a2dp {

/// Copied after the definition from the Bluetooth Audio interface:
/// hardware/interfaces/bluetooth/audio/aidl/android/hardware/bluetooth/audio/BluetoothAudioStatus.aidl
enum BluetoothAudioStatus {
  UNKNOWN = 0,
  SUCCESS = 1,
  UNSUPPORTED_CODEC_CONFIGURATION = 2,
  FAILURE = 3,
  // Not defined in BluetoothAudioStatus, but used internally for
  // state keeping.
  PENDING = 5,
};

bool update_codec_offloading_capabilities(
    const std::vector<btav_a2dp_codec_config_t>& framework_preference,
    bool supports_a2dp_hw_offload_v2);
@@ -55,8 +67,8 @@ void set_audio_low_latency_mode_allowed(bool allowed);
// StreamStarted, StreamSuspended
void start_session();
void end_session();
void ack_stream_started(const tA2DP_CTRL_ACK& status);
void ack_stream_suspended(const tA2DP_CTRL_ACK& status);
void ack_stream_started(BluetoothAudioStatus status);
void ack_stream_suspended(BluetoothAudioStatus status);

// Read from the FMQ of BluetoothAudio HAL
size_t read(uint8_t* p_buf, uint32_t len);
@@ -162,3 +174,9 @@ tA2DP_STATUS parse_a2dp_configuration(
}  // namespace a2dp
}  // namespace audio
}  // namespace bluetooth

namespace fmt {
template <>
struct formatter<::bluetooth::audio::a2dp::BluetoothAudioStatus>
    : enum_formatter<::bluetooth::audio::a2dp::BluetoothAudioStatus> {};
} // namespace fmt
+3 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <vector>

#include "a2dp_encoding.h"
#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
#include "btif/include/btif_a2dp_source.h"
#include "btif/include/btif_av.h"
#include "btif/include/btif_hf.h"
@@ -263,13 +264,12 @@ void end_session() {
void set_audio_low_latency_mode_allowed(bool allowed){
}


void ack_stream_started(const tA2DP_CTRL_ACK& ack) {
void ack_stream_started(BluetoothAudioStatus /*ack*/) {
  a2dp_pending_cmd_ = A2DP_CTRL_CMD_NONE;
  // TODO: Notify server
}

void ack_stream_suspended(const tA2DP_CTRL_ACK& ack) {
void ack_stream_suspended(BluetoothAudioStatus /*ack*/) {
  a2dp_pending_cmd_ = A2DP_CTRL_CMD_NONE;
  // TODO: Notify server
}
+30 −34
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ namespace audio {
namespace aidl {
namespace a2dp {

using ::bluetooth::audio::a2dp::BluetoothAudioStatus;

namespace {

using ::aidl::android::hardware::bluetooth::audio::A2dpStreamConfiguration;
@@ -87,29 +89,29 @@ BluetoothAudioCtrlAck A2dpTransport::StartRequest(bool is_low_latency) {
  // Check if a previous request is not finished
  if (a2dp_pending_cmd_ == A2DP_CTRL_CMD_START) {
    log::info("A2DP_CTRL_CMD_START in progress");
    return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING);
    return BluetoothAudioCtrlAck::PENDING;
  } else if (a2dp_pending_cmd_ != A2DP_CTRL_CMD_NONE) {
    log::warn("busy in pending_cmd={}", a2dp_pending_cmd_);
    return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE);
    return BluetoothAudioCtrlAck::FAILURE;
  }

  // Don't send START request to stack while we are in a call
  if (!bluetooth::headset::IsCallIdle()) {
    log::error("call state is busy");
    return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_INCALL_FAILURE);
    return BluetoothAudioCtrlAck::FAILURE_BUSY;
  }

  if (com::android::bluetooth::flags::a2dp_check_lea_iso_channel()) {
    // Don't send START request to stack while LEA sessions are in use
    if (hci::IsoManager::GetInstance()->GetNumberOfActiveIso() > 0) {
      log::error("LEA currently has active ISO channels");
      return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE);
      return BluetoothAudioCtrlAck::FAILURE;
    }
  }

  if (btif_av_stream_started_ready(A2dpType::kSource)) {
    // Already started, ACK back immediately.
    return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS);
    return BluetoothAudioCtrlAck::SUCCESS_FINISHED;
  }
  if (btif_av_stream_ready(A2dpType::kSource)) {
    // check if codec needs to be switched prior to stream start
@@ -123,23 +125,23 @@ BluetoothAudioCtrlAck A2dpTransport::StartRequest(bool is_low_latency) {
    btif_av_stream_start_with_latency(is_low_latency);
    if (btif_av_get_peer_sep(A2dpType::kSource) != AVDT_TSEP_SRC) {
      log::info("accepted");
      return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING);
      return BluetoothAudioCtrlAck::PENDING;
    }
    a2dp_pending_cmd_ = A2DP_CTRL_CMD_NONE;
    return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS);
    return BluetoothAudioCtrlAck::SUCCESS_FINISHED;
  }
  log::error("AV stream is not ready to start");
  return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE);
  return BluetoothAudioCtrlAck::FAILURE;
}

BluetoothAudioCtrlAck A2dpTransport::SuspendRequest() {
  // Previous request is not finished
  if (a2dp_pending_cmd_ == A2DP_CTRL_CMD_SUSPEND) {
    log::info("A2DP_CTRL_CMD_SUSPEND in progress");
    return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING);
    return BluetoothAudioCtrlAck::PENDING;
  } else if (a2dp_pending_cmd_ != A2DP_CTRL_CMD_NONE) {
    log::warn("busy in pending_cmd={}", a2dp_pending_cmd_);
    return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE);
    return BluetoothAudioCtrlAck::FAILURE;
  }
  // Local suspend
  if (btif_av_stream_started_ready(A2dpType::kSource)) {
@@ -153,7 +155,7 @@ BluetoothAudioCtrlAck A2dpTransport::SuspendRequest() {
   * remotely suspended, clear REMOTE SUSPEND flag.
   */
  btif_av_clear_remote_suspend_flag(A2dpType::kSource);
  return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS);
  return BluetoothAudioCtrlAck::SUCCESS_FINISHED;
}

void A2dpTransport::StopRequest() {
@@ -249,20 +251,16 @@ bool btaudio_a2dp_disabled = false;
bool is_configured = false;
bool is_low_latency_mode_allowed = false;

BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(tA2DP_CTRL_ACK ack) {
static BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(BluetoothAudioStatus ack) {
  switch (ack) {
    case A2DP_CTRL_ACK_SUCCESS:
    case BluetoothAudioStatus::SUCCESS:
      return BluetoothAudioCtrlAck::SUCCESS_FINISHED;
    case A2DP_CTRL_ACK_PENDING:
    case BluetoothAudioStatus::PENDING:
      return BluetoothAudioCtrlAck::PENDING;
    case A2DP_CTRL_ACK_INCALL_FAILURE:
      return BluetoothAudioCtrlAck::FAILURE_BUSY;
    case A2DP_CTRL_ACK_DISCONNECT_IN_PROGRESS:
      return BluetoothAudioCtrlAck::FAILURE_DISCONNECTING;
    case A2DP_CTRL_ACK_UNSUPPORTED: /* Offloading but resource failure */
    case BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION:
      return BluetoothAudioCtrlAck::FAILURE_UNSUPPORTED;
    case A2DP_CTRL_ACK_FAILURE:
      return BluetoothAudioCtrlAck::FAILURE;
    case BluetoothAudioStatus::UNKNOWN:
    case BluetoothAudioStatus::FAILURE:
    default:
      return BluetoothAudioCtrlAck::FAILURE;
  }
@@ -646,46 +644,44 @@ void end_session() {
      ->ResetPresentationPosition();
}

void ack_stream_started(const tA2DP_CTRL_ACK& ack) {
void ack_stream_started(BluetoothAudioStatus ack) {
  if (!is_hal_enabled()) {
    log::error("BluetoothAudio HAL is not enabled");
    return;
  }
  auto ctrl_ack = a2dp_ack_to_bt_audio_ctrl_ack(ack);
  log::info("result={}", ctrl_ack);
  log::info("result={}", ack);
  auto a2dp_sink =
      static_cast<A2dpTransport*>(active_hal_interface->GetTransportInstance());
  auto pending_cmd = a2dp_sink->GetPendingCmd();
  if (pending_cmd == A2DP_CTRL_CMD_START) {
    active_hal_interface->StreamStarted(ctrl_ack);
    active_hal_interface->StreamStarted(a2dp_ack_to_bt_audio_ctrl_ack(ack));
  } else {
    log::warn("pending={} ignore result={}", pending_cmd, ctrl_ack);
    log::warn("pending={} ignore result={}", pending_cmd, ack);
    return;
  }
  if (ctrl_ack != BluetoothAudioCtrlAck::PENDING) {
  if (ack != BluetoothAudioStatus::PENDING) {
    a2dp_sink->ResetPendingCmd();
  }
}

void ack_stream_suspended(const tA2DP_CTRL_ACK& ack) {
void ack_stream_suspended(BluetoothAudioStatus ack) {
  if (!is_hal_enabled()) {
    log::error("BluetoothAudio HAL is not enabled");
    return;
  }
  auto ctrl_ack = a2dp_ack_to_bt_audio_ctrl_ack(ack);
  log::info("result={}", ctrl_ack);
  log::info("result={}", ack);
  auto a2dp_sink =
      static_cast<A2dpTransport*>(active_hal_interface->GetTransportInstance());
  auto pending_cmd = a2dp_sink->GetPendingCmd();
  if (pending_cmd == A2DP_CTRL_CMD_SUSPEND) {
    active_hal_interface->StreamSuspended(ctrl_ack);
    active_hal_interface->StreamSuspended(a2dp_ack_to_bt_audio_ctrl_ack(ack));
  } else if (pending_cmd == A2DP_CTRL_CMD_STOP) {
    log::info("A2DP_CTRL_CMD_STOP result={}", ctrl_ack);
    log::info("A2DP_CTRL_CMD_STOP result={}", ack);
  } else {
    log::warn("pending={} ignore result={}", pending_cmd, ctrl_ack);
    log::warn("pending={} ignore result={}", pending_cmd, ack);
    return;
  }
  if (ctrl_ack != BluetoothAudioCtrlAck::PENDING) {
  if (ack != BluetoothAudioStatus::PENDING) {
    a2dp_sink->ResetPendingCmd();
  }
}
+3 −3
Original line number Diff line number Diff line
@@ -20,12 +20,12 @@

#include "a2dp_encoding.h"
#include "a2dp_sbc_constants.h"
#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
#include "btif/include/btif_a2dp_source.h"
#include "btif/include/btif_av.h"
#include "btif/include/btif_av_co.h"
#include "btif/include/btif_hf.h"
#include "common/message_loop_thread.h"
#include "hardware/bt_av.h"
#include "os/log.h"
#include "osi/include/properties.h"
#include "types/raw_address.h"
@@ -70,8 +70,8 @@ bool setup_codec();
 ***/
void start_session();
void end_session();
void ack_stream_started(const tA2DP_CTRL_ACK& status);
void ack_stream_suspended(const tA2DP_CTRL_ACK& status);
void ack_stream_started(::bluetooth::audio::a2dp::BluetoothAudioStatus status);
void ack_stream_suspended(::bluetooth::audio::a2dp::BluetoothAudioStatus status);

/***
 * Read from the FMQ of BluetoothAudio HAL
Loading