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

Commit e66b8de9 authored by Hsin-yu Chao's avatar Hsin-yu Chao
Browse files

HFP Audio client - fix sink/source naming

In HFP software encoding/decoding data path, the encode path
reads data from audio sink, encodes the data and then sends to SCO.
The decoding path receives data from SCO, decodes the data and then
writes to audio source.

This change fixes the naming in HFP client. The affected classes and
functions don't have real users at the moment.

Added unittest to cover the read/write operations in HFP client
interface.

Bug: 349290628
Test: atest --host bluetooth-test-audio-hal-hfp-client-interface
Change-Id: I907015f62f2dacecaed8ebc59dc816a923c6c1d3
parent 48bbf9d9
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -360,3 +360,29 @@ cc_test {
        "-DBUILDCFG",
    ],
}

// HFP client interface library unit tests
cc_test {
    name: "bluetooth-test-audio-hal-hfp-client-interface",
    host_supported: true,
    defaults: [
        "libbt_audio_hal_interface_test_defaults",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system/audio_hal_interface",
        "packages/modules/Bluetooth/system/audio_hal_interface/aidl",
        "packages/modules/Bluetooth/system/bta",
    ],
    srcs: [
        "hfp_client_interface.cc",
        "hfp_client_interface_unittest.cc",
    ],
    static_libs: [
        "server_configurable_flags",
    ],
    header_libs: ["libbluetooth_headers"],
    cflags: [
        "-DBUILDCFG",
        "-Wno-unused-parameter",
    ],
}
+4 −4
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ bool HfpTransport::GetPresentationPosition(uint64_t* remote_delay_report_ns,

// Source / sink functions
HfpDecodingTransport::HfpDecodingTransport(SessionType session_type)
    : IBluetoothSinkTransportInstance(session_type, (AudioConfiguration){}) {
    : IBluetoothSourceTransportInstance(session_type, (AudioConfiguration){}) {
  transport_ = new HfpTransport();
}

@@ -204,7 +204,7 @@ void HfpDecodingTransport::SinkMetadataChanged(const sink_metadata_v7_t& sink_me

void HfpDecodingTransport::ResetPresentationPosition() { transport_->ResetPresentationPosition(); }

void HfpDecodingTransport::LogBytesRead(size_t bytes_written) {
void HfpDecodingTransport::LogBytesWritten(size_t bytes_written) {
  transport_->LogBytesProcessed(bytes_written);
}

@@ -215,7 +215,7 @@ void HfpDecodingTransport::ResetPendingCmd() { transport_->ResetPendingCmd(); }
void HfpDecodingTransport::StopRequest() { transport_->StopRequest(); }

HfpEncodingTransport::HfpEncodingTransport(SessionType session_type)
    : IBluetoothSourceTransportInstance(session_type, (AudioConfiguration){}) {
    : IBluetoothSinkTransportInstance(session_type, (AudioConfiguration){}) {
  transport_ = new HfpTransport();
}

@@ -252,7 +252,7 @@ void HfpEncodingTransport::SinkMetadataChanged(const sink_metadata_v7_t& sink_me

void HfpEncodingTransport::ResetPresentationPosition() { transport_->ResetPresentationPosition(); }

void HfpEncodingTransport::LogBytesWritten(size_t bytes_written) {
void HfpEncodingTransport::LogBytesRead(size_t bytes_written) {
  transport_->LogBytesProcessed(bytes_written);
}

+11 −11
Original line number Diff line number Diff line
@@ -78,8 +78,8 @@ private:
  tHFP_CTRL_CMD hfp_pending_cmd_;
};

// Sink transport implementation
class HfpDecodingTransport : public ::bluetooth::audio::aidl::IBluetoothSinkTransportInstance {
// Source transport implementation
class HfpDecodingTransport : public ::bluetooth::audio::aidl::IBluetoothSourceTransportInstance {
public:
  HfpDecodingTransport(SessionType sessionType);

@@ -102,22 +102,22 @@ public:

  void ResetPresentationPosition();

  void LogBytesRead(size_t bytes_read) override;
  void LogBytesWritten(size_t bytes_written) override;

  uint8_t GetPendingCmd() const;

  void ResetPendingCmd();

  static inline HfpDecodingTransport* instance_ = nullptr;
  static inline BluetoothAudioSinkClientInterface* software_hal_interface = nullptr;
  static inline BluetoothAudioSinkClientInterface* offloading_hal_interface = nullptr;
  static inline BluetoothAudioSinkClientInterface* active_hal_interface = nullptr;
  static inline BluetoothAudioSourceClientInterface* software_hal_interface = nullptr;
  static inline BluetoothAudioSourceClientInterface* offloading_hal_interface = nullptr;
  static inline BluetoothAudioSourceClientInterface* active_hal_interface = nullptr;

private:
  HfpTransport* transport_;
};

class HfpEncodingTransport : public ::bluetooth::audio::aidl::IBluetoothSourceTransportInstance {
class HfpEncodingTransport : public ::bluetooth::audio::aidl::IBluetoothSinkTransportInstance {
public:
  HfpEncodingTransport(SessionType sessionType);

@@ -140,16 +140,16 @@ public:

  void ResetPresentationPosition();

  void LogBytesWritten(size_t bytes_written) override;
  void LogBytesRead(size_t bytes_read) override;

  uint8_t GetPendingCmd() const;

  void ResetPendingCmd();

  static inline HfpEncodingTransport* instance_ = nullptr;
  static inline BluetoothAudioSourceClientInterface* software_hal_interface = nullptr;
  static inline BluetoothAudioSourceClientInterface* offloading_hal_interface = nullptr;
  static inline BluetoothAudioSourceClientInterface* active_hal_interface = nullptr;
  static inline BluetoothAudioSinkClientInterface* software_hal_interface = nullptr;
  static inline BluetoothAudioSinkClientInterface* offloading_hal_interface = nullptr;
  static inline BluetoothAudioSinkClientInterface* active_hal_interface = nullptr;

private:
  HfpTransport* transport_;
+9 −9
Original line number Diff line number Diff line
@@ -40,11 +40,11 @@ namespace audio {
namespace hfp {

// Helper functions
aidl::BluetoothAudioSinkClientInterface* get_decode_client_interface() {
aidl::BluetoothAudioSourceClientInterface* get_decode_client_interface() {
  return HfpDecodingTransport::active_hal_interface;
}

aidl::BluetoothAudioSourceClientInterface* get_encode_client_interface() {
aidl::BluetoothAudioSinkClientInterface* get_encode_client_interface() {
  return HfpEncodingTransport::active_hal_interface;
}

@@ -172,13 +172,13 @@ void HfpClientInterface::Decode::UpdateAudioConfigToHal(
  return;
}

size_t HfpClientInterface::Decode::Read(uint8_t* p_buf, uint32_t len) {
size_t HfpClientInterface::Decode::Write(const uint8_t* p_buf, uint32_t len) {
  if (!is_aidl_support_hfp()) {
    log::warn("Unsupported HIDL or AIDL version");
    return 0;
  }
  log::info("decode");
  return get_decode_client_interface()->ReadAudioData(p_buf, len);
  return get_decode_client_interface()->WriteAudioData(p_buf, len);
}

void HfpClientInterface::Decode::ConfirmStreamingRequest() {
@@ -240,7 +240,7 @@ HfpClientInterface::Decode* HfpClientInterface::GetDecode(
  HfpDecodingTransport::instance_ =
          new HfpDecodingTransport(aidl::SessionType::HFP_SOFTWARE_DECODING_DATAPATH);
  HfpDecodingTransport::software_hal_interface =
          new aidl::BluetoothAudioSinkClientInterface(HfpDecodingTransport::instance_);
          new aidl::BluetoothAudioSourceClientInterface(HfpDecodingTransport::instance_);
  if (!HfpDecodingTransport::software_hal_interface->IsValid()) {
    log::warn("BluetoothAudio HAL for HFP is invalid");
    delete HfpDecodingTransport::software_hal_interface;
@@ -323,13 +323,13 @@ void HfpClientInterface::Encode::UpdateAudioConfigToHal(
  return;
}

size_t HfpClientInterface::Encode::Write(const uint8_t* p_buf, uint32_t len) {
size_t HfpClientInterface::Encode::Read(uint8_t* p_buf, uint32_t len) {
  if (!is_aidl_support_hfp()) {
    log::warn("Unsupported HIDL or AIDL version");
    return 0;
  }
  log::info("encode");
  return get_encode_client_interface()->WriteAudioData(p_buf, len);
  return get_encode_client_interface()->ReadAudioData(p_buf, len);
}

void HfpClientInterface::Encode::ConfirmStreamingRequest() {
@@ -391,7 +391,7 @@ HfpClientInterface::Encode* HfpClientInterface::GetEncode(
  HfpEncodingTransport::instance_ =
          new HfpEncodingTransport(aidl::SessionType::HFP_SOFTWARE_ENCODING_DATAPATH);
  HfpEncodingTransport::software_hal_interface =
          new aidl::BluetoothAudioSourceClientInterface(HfpEncodingTransport::instance_);
          new aidl::BluetoothAudioSinkClientInterface(HfpEncodingTransport::instance_);
  if (!HfpEncodingTransport::software_hal_interface->IsValid()) {
    log::warn("BluetoothAudio HAL for HFP is invalid");
    delete HfpEncodingTransport::software_hal_interface;
@@ -541,7 +541,7 @@ HfpClientInterface::Offload* HfpClientInterface::GetOffload(
    HfpEncodingTransport::instance_ =
            new HfpEncodingTransport(aidl::SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH);
    HfpEncodingTransport::offloading_hal_interface =
            new aidl::BluetoothAudioSourceClientInterface(HfpEncodingTransport::instance_);
            new aidl::BluetoothAudioSinkClientInterface(HfpEncodingTransport::instance_);
    if (!HfpEncodingTransport::offloading_hal_interface->IsValid()) {
      log::fatal("BluetoothAudio HAL for HFP offloading is invalid");
      delete HfpEncodingTransport::offloading_hal_interface;
+2 −2
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ public:
    void UpdateAudioConfigToHal(const ::hfp::offload_config& config) override;
    void ConfirmStreamingRequest() override;
    void CancelStreamingRequest() override;
    size_t Read(uint8_t* p_buf, uint32_t len);
    size_t Write(const uint8_t* p_buf, uint32_t len);
  };

  class Encode : public IClientInterfaceEndpoint {
@@ -65,7 +65,7 @@ public:
    void UpdateAudioConfigToHal(const ::hfp::offload_config& config) override;
    void ConfirmStreamingRequest() override;
    void CancelStreamingRequest() override;
    size_t Write(const uint8_t* p_buf, uint32_t len);
    size_t Read(uint8_t* p_buf, uint32_t len);
  };

  class Offload : public IClientInterfaceEndpoint {
Loading