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

Commit bdf23e56 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Allow audio AIDL clients to set all latency modes support

Audio AIDL clients can only specify whether low latency mode is
supported or not.
This change adds support in the Audio AIDL client interface to allow
clients to provide the list latency modes supported.

Test: m com.android.btservices
Bug: 304840881
Change-Id: Ife2a1d9cab465dafcdb26248d5e06edbb3a3be49
parent c559c9f7
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -486,7 +486,11 @@ void start_session() {
    LOG(ERROR) << __func__ << ": BluetoothAudio HAL is not enabled";
    return;
  }
  active_hal_interface->SetLowLatencyModeAllowed(is_low_latency_mode_allowed);
  std::vector<LatencyMode> latency_modes = {LatencyMode::FREE};
  if (is_low_latency_mode_allowed) {
    latency_modes.push_back(LatencyMode::LOW_LATENCY);
  }
  active_hal_interface->SetAllowedLatencyModes(latency_modes);
  active_hal_interface->StartSession();
}

@@ -576,7 +580,11 @@ void set_low_latency_mode_allowed(bool allowed) {
    LOG(ERROR) << __func__ << ": BluetoothAudio HAL is not enabled";
    return;
  }
  active_hal_interface->SetLowLatencyModeAllowed(allowed);
  std::vector<LatencyMode> latency_modes = {LatencyMode::FREE};
  if (is_low_latency_mode_allowed) {
    latency_modes.push_back(LatencyMode::LOW_LATENCY);
  }
  active_hal_interface->SetAllowedLatencyModes(latency_modes);
}

}  // namespace a2dp
+16 −11
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ BluetoothAudioClientInterface::BluetoothAudioClientInterface(
      provider_factory_(nullptr),
      session_started_(false),
      data_mq_(nullptr),
      transport_(instance) {
      transport_(instance),
      latency_modes_({LatencyMode::FREE}) {
  death_recipient_ = ::ndk::ScopedAIBinder_DeathRecipient(
      AIBinder_DeathRecipient_new(binderDiedCallbackAidl));
}
@@ -241,8 +242,16 @@ bool BluetoothAudioClientInterface::UpdateAudioConfig(
  return true;
}

bool BluetoothAudioClientInterface::SetLowLatencyModeAllowed(bool allowed) {
  is_low_latency_allowed_ = allowed;
bool BluetoothAudioClientInterface::SetAllowedLatencyModes(
    std::vector<LatencyMode> latency_modes) {
  /* Ensure that FREE is always included and remove duplicates if any */
  std::set<LatencyMode> temp_set(latency_modes.begin(), latency_modes.end());
  temp_set.insert(LatencyMode::FREE);
  latency_modes_.clear();
  latency_modes_.assign(temp_set.begin(), temp_set.end());

  bool allowed = (latency_modes_.size() > 1);

  if (provider_ == nullptr) {
    LOG(INFO) << __func__ << ": BluetoothAudioHal nullptr";
    return false;
@@ -251,8 +260,7 @@ bool BluetoothAudioClientInterface::SetLowLatencyModeAllowed(bool allowed) {
  auto aidl_retval = provider_->setLowLatencyModeAllowed(allowed);
  if (!aidl_retval.isOk()) {
    LOG(WARNING) << __func__ << ": BluetoothAudioHal is not ready: "
               << aidl_retval.getDescription()
               << ". is_low_latency_allowed_ is saved "
                 << aidl_retval.getDescription() << ". latency_modes_ is saved "
                 << "and it will be sent to BluetoothAudioHal at StartSession.";
  }
  return true;
@@ -275,12 +283,9 @@ int BluetoothAudioClientInterface::StartSession() {

  std::unique_ptr<DataMQ> data_mq;
  DataMQDesc mq_desc;
  std::vector<LatencyMode> latency_modes = {LatencyMode::FREE};
  if (is_low_latency_allowed_) {
    latency_modes.push_back(LatencyMode::LOW_LATENCY);
  }

  auto aidl_retval = provider_->startSession(
      stack_if, transport_->GetAudioConfiguration(), latency_modes, &mq_desc);
      stack_if, transport_->GetAudioConfiguration(), latency_modes_, &mq_desc);
  if (!aidl_retval.isOk()) {
    if (aidl_retval.getExceptionCode() == EX_ILLEGAL_ARGUMENT) {
      LOG(ERROR) << __func__ << ": BluetoothAudioHal Error: "
+2 −2
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ class BluetoothAudioClientInterface {

  bool UpdateAudioConfig(const AudioConfiguration& audioConfig);

  bool SetLowLatencyModeAllowed(bool allowed);
  bool SetAllowedLatencyModes(std::vector<LatencyMode> latency_modes);

  void FlushAudioData();

@@ -121,7 +121,7 @@ class BluetoothAudioClientInterface {
 private:
  IBluetoothTransportInstance* transport_;
  std::vector<AudioCapabilities> capabilities_;
  bool is_low_latency_allowed_{false};
  std::vector<LatencyMode> latency_modes_;
};

/***