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

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

Merge changes I92197f14,I4e8916eb into main am: 86373416

parents 5f2ad80e 86373416
Loading
Loading
Loading
Loading
+41 −25
Original line number Diff line number Diff line
@@ -404,8 +404,37 @@ bool is_hal_offloading() {
         SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH;
}

// Opens the HAL client interface of the specified session type and check
// that is is valid. Returns nullptr if the client interface did not open
// properly.
static BluetoothAudioSinkClientInterface* new_hal_interface(
    SessionType session_type) {
  auto a2dp_transport = new A2dpTransport(session_type);
  auto hal_interface = new BluetoothAudioSinkClientInterface(a2dp_transport);
  if (hal_interface->IsValid()) {
    return hal_interface;
  } else {
    LOG(ERROR) << __func__ << "BluetoothAudio HAL for a2dp is invalid";
    delete a2dp_transport;
    delete hal_interface;
    return nullptr;
  }
}

/// Delete the selected HAL client interface.
static void delete_hal_interface(
    BluetoothAudioSinkClientInterface* hal_interface) {
  if (hal_interface == nullptr) {
    return;
  }
  auto a2dp_transport =
      static_cast<A2dpTransport*>(hal_interface->GetTransportInstance());
  delete a2dp_transport;
  delete hal_interface;
}

// Initialize BluetoothAudio HAL: openProvider
bool init(bluetooth::common::MessageLoopThread* message_loop) {
bool init(bluetooth::common::MessageLoopThread* /*message_loop*/) {
  LOG(INFO) << __func__;

  if (software_hal_interface != nullptr) {
@@ -423,34 +452,19 @@ bool init(bluetooth::common::MessageLoopThread* message_loop) {
    return false;
  }

  auto a2dp_sink =
      new A2dpTransport(SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH);
  software_hal_interface =
      new BluetoothAudioSinkClientInterface(a2dp_sink, message_loop);
  if (!software_hal_interface->IsValid()) {
    LOG(WARNING) << __func__ << ": BluetoothAudio HAL for A2DP is invalid?!";
    delete software_hal_interface;
    software_hal_interface = nullptr;
    delete a2dp_sink;
      new_hal_interface(SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH);
  if (software_hal_interface == nullptr) {
    return false;
  }

  if (btif_av_is_a2dp_offload_enabled()) {
    a2dp_sink =
        new A2dpTransport(SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH);
  if (btif_av_is_a2dp_offload_enabled() &&
      offloading_hal_interface == nullptr) {
    offloading_hal_interface =
        new BluetoothAudioSinkClientInterface(a2dp_sink, message_loop);
    if (!offloading_hal_interface->IsValid()) {
      LOG(FATAL) << __func__
                 << ": BluetoothAudio HAL for A2DP offloading is invalid?!";
      delete offloading_hal_interface;
      offloading_hal_interface = nullptr;
      delete a2dp_sink;
      a2dp_sink = static_cast<A2dpTransport*>(
          software_hal_interface->GetTransportInstance());
      delete software_hal_interface;
        new_hal_interface(SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH);
    if (offloading_hal_interface == nullptr) {
      delete_hal_interface(software_hal_interface);
      software_hal_interface = nullptr;
      delete a2dp_sink;
      return false;
    }
  }
@@ -920,8 +934,10 @@ provider::get_a2dp_configuration(
  }
  LOG(INFO) << "hint: " << hint.toString();

  if (offloading_hal_interface == nullptr) {
    LOG(ERROR) << __func__ << "the offloading HAL interface was never opened!";
  if (offloading_hal_interface == nullptr &&
      (offloading_hal_interface = new_hal_interface(
           SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH)) == nullptr) {
    LOG(ERROR) << __func__ << "the offloading HAL interface cannot be opened";
    return std::nullopt;
  }

+3 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <android/binder_manager.h>
#include <android_bluetooth_flags.h>

#include <thread>
#include <vector>

#include "include/check.h"
@@ -238,8 +239,7 @@ void BluetoothAudioClientInterface::FetchAudioProvider() {
}

BluetoothAudioSinkClientInterface::BluetoothAudioSinkClientInterface(
    IBluetoothSinkTransportInstance* sink,
    bluetooth::common::MessageLoopThread* message_loop)
    IBluetoothSinkTransportInstance* sink)
    : BluetoothAudioClientInterface{sink}, sink_(sink) {
  FetchAudioProvider();
}
@@ -252,8 +252,7 @@ BluetoothAudioSinkClientInterface::~BluetoothAudioSinkClientInterface() {
}

BluetoothAudioSourceClientInterface::BluetoothAudioSourceClientInterface(
    IBluetoothSourceTransportInstance* source,
    bluetooth::common::MessageLoopThread* message_loop)
    IBluetoothSourceTransportInstance* source)
    : BluetoothAudioClientInterface{source}, source_(source) {
  FetchAudioProvider();
}
+4 −10
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
#include "audio_aidl_interfaces.h"
#include "audio_ctrl_ack.h"
#include "bluetooth_audio_port_impl.h"
#include "common/message_loop_thread.h"
#include "transport_instance.h"

#define BLUETOOTH_AUDIO_HAL_PROP_DISABLED \
@@ -195,12 +194,9 @@ class BluetoothAudioSinkClientInterface : public BluetoothAudioClientInterface {
 public:
  /***
   * Constructs an BluetoothAudioSinkClientInterface to communicate to
   * BluetoothAudio HAL. |sink| is the implementation for the transport, and
   * |message_loop| is the thread where callbacks are invoked.
   * BluetoothAudio HAL. |sink| is the implementation for the transport.
   ***/
  BluetoothAudioSinkClientInterface(
      IBluetoothSinkTransportInstance* sink,
      bluetooth::common::MessageLoopThread* message_loop);
  BluetoothAudioSinkClientInterface(IBluetoothSinkTransportInstance* sink);
  virtual ~BluetoothAudioSinkClientInterface();

  IBluetoothSinkTransportInstance* GetTransportInstance() const {
@@ -224,12 +220,10 @@ class BluetoothAudioSourceClientInterface
 public:
  /***
   * Constructs an BluetoothAudioSourceClientInterface to communicate to
   * BluetoothAudio HAL. |source| is the implementation for the transport, and
   * |message_loop| is the thread where callbacks are invoked.
   * BluetoothAudio HAL. |source| is the implementation for the transport.
   ***/
  BluetoothAudioSourceClientInterface(
      IBluetoothSourceTransportInstance* source,
      bluetooth::common::MessageLoopThread* message_loop);
      IBluetoothSourceTransportInstance* source);
  virtual ~BluetoothAudioSourceClientInterface();

  IBluetoothSourceTransportInstance* GetTransportInstance() const {
+2 −2
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ namespace hearing_aid {
bool is_hal_enabled() { return hearing_aid_hal_clientinterface != nullptr; }

bool init(StreamCallbacks stream_cb,
          bluetooth::common::MessageLoopThread* message_loop) {
          bluetooth::common::MessageLoopThread* /*message_loop*/) {
  LOG(INFO) << __func__;

  if (is_hal_force_disabled()) {
@@ -196,7 +196,7 @@ bool init(StreamCallbacks stream_cb,
  hearing_aid_sink = new HearingAidTransport(std::move(stream_cb));
  hearing_aid_hal_clientinterface =
      new bluetooth::audio::aidl::BluetoothAudioSinkClientInterface(
          hearing_aid_sink, message_loop);
          hearing_aid_sink);
  if (!hearing_aid_hal_clientinterface->IsValid()) {
    LOG(WARNING) << __func__
                 << ": BluetoothAudio HAL for Hearing Aid is invalid?!";
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
#include <cstdint>

#include "client_interface_aidl.h"
#include "common/message_loop_thread.h"

namespace bluetooth {
namespace audio {
Loading