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

Commit 3b20c00e authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Gerrit Code Review
Browse files

Merge changes Ic497cb7b,If8e8040a,Idbfe4a13,If3a896c9

* changes:
  leaudio: Cleanup around pending context update
  leaudio: Fix update pending contexts
  leaudio: Minor clean up
  leaudio: Notify Audio Hal if suspended for the reconfiguration
parents dc7a3d99 8462be6d
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ using ::aidl::android::hardware::bluetooth::audio::BluetoothAudioStatus;


enum class BluetoothAudioCtrlAck : uint8_t {
enum class BluetoothAudioCtrlAck : uint8_t {
  SUCCESS_FINISHED = 0,
  SUCCESS_FINISHED = 0,
  SUCCESS_RECONFIGURATION,
  PENDING,
  PENDING,
  FAILURE_UNSUPPORTED,
  FAILURE_UNSUPPORTED,
  FAILURE_BUSY,
  FAILURE_BUSY,
@@ -46,6 +47,8 @@ inline BluetoothAudioStatus BluetoothAudioCtrlAckToHalStatus(
      return BluetoothAudioStatus::FAILURE;
      return BluetoothAudioStatus::FAILURE;
    case BluetoothAudioCtrlAck::FAILURE_DISCONNECTING:
    case BluetoothAudioCtrlAck::FAILURE_DISCONNECTING:
      return BluetoothAudioStatus::FAILURE;
      return BluetoothAudioStatus::FAILURE;
    case BluetoothAudioCtrlAck::SUCCESS_RECONFIGURATION:
      return BluetoothAudioStatus::RECONFIGURATION;
    default:
    default:
      return BluetoothAudioStatus::FAILURE;
      return BluetoothAudioStatus::FAILURE;
  }
  }
+32 −0
Original line number Original line Diff line number Diff line
@@ -226,6 +226,22 @@ void LeAudioClientInterface::Sink::UpdateAudioConfigToHal(
      aidl::le_audio::offload_config_to_hal_audio_config(offload_config));
      aidl::le_audio::offload_config_to_hal_audio_config(offload_config));
}
}


void LeAudioClientInterface::Sink::SuspendedForReconfiguration() {
  if (HalVersionManager::GetHalTransport() ==
      BluetoothAudioHalTransport::HIDL) {
    return;
  }

  if (aidl::le_audio::LeAudioSinkTransport::interface->GetTransportInstance()
          ->GetSessionType() !=
      aidl::SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH) {
    return;
  }

  aidl::le_audio::LeAudioSinkTransport::interface->StreamSuspended(
      aidl::BluetoothAudioCtrlAck::SUCCESS_RECONFIGURATION);
}

size_t LeAudioClientInterface::Sink::Read(uint8_t* p_buf, uint32_t len) {
size_t LeAudioClientInterface::Sink::Read(uint8_t* p_buf, uint32_t len) {
  if (HalVersionManager::GetHalTransport() ==
  if (HalVersionManager::GetHalTransport() ==
      BluetoothAudioHalTransport::HIDL) {
      BluetoothAudioHalTransport::HIDL) {
@@ -324,6 +340,22 @@ void LeAudioClientInterface::Source::StartSession() {
  }
  }
}
}


void LeAudioClientInterface::Source::SuspendedForReconfiguration() {
  if (HalVersionManager::GetHalTransport() ==
      BluetoothAudioHalTransport::HIDL) {
    return;
  }

  if (aidl::le_audio::LeAudioSourceTransport::interface->GetTransportInstance()
          ->GetSessionType() !=
      aidl::SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH) {
    return;
  }

  aidl::le_audio::LeAudioSourceTransport::interface->StreamSuspended(
      aidl::BluetoothAudioCtrlAck::SUCCESS_RECONFIGURATION);
}

void LeAudioClientInterface::Source::ConfirmStreamingRequest() {
void LeAudioClientInterface::Source::ConfirmStreamingRequest() {
  LOG(INFO) << __func__;
  LOG(INFO) << __func__;
  if ((hidl::le_audio::LeAudioSourceTransport::instance &&
  if ((hidl::le_audio::LeAudioSourceTransport::instance &&
+3 −0
Original line number Original line Diff line number Diff line
@@ -74,6 +74,7 @@ class LeAudioClientInterface {
    virtual void CancelStreamingRequest() = 0;
    virtual void CancelStreamingRequest() = 0;
    virtual void UpdateAudioConfigToHal(
    virtual void UpdateAudioConfigToHal(
        const ::le_audio::offload_config& config) = 0;
        const ::le_audio::offload_config& config) = 0;
    virtual void SuspendedForReconfiguration() = 0;
  };
  };


 public:
 public:
@@ -90,6 +91,7 @@ class LeAudioClientInterface {
    void CancelStreamingRequest() override;
    void CancelStreamingRequest() override;
    void UpdateAudioConfigToHal(
    void UpdateAudioConfigToHal(
        const ::le_audio::offload_config& config) override;
        const ::le_audio::offload_config& config) override;
    void SuspendedForReconfiguration() override;
    // Read the stream of bytes sinked to us by the upper layers
    // Read the stream of bytes sinked to us by the upper layers
    size_t Read(uint8_t* p_buf, uint32_t len);
    size_t Read(uint8_t* p_buf, uint32_t len);
  };
  };
@@ -106,6 +108,7 @@ class LeAudioClientInterface {
    void CancelStreamingRequest() override;
    void CancelStreamingRequest() override;
    void UpdateAudioConfigToHal(
    void UpdateAudioConfigToHal(
        const ::le_audio::offload_config& config) override;
        const ::le_audio::offload_config& config) override;
    void SuspendedForReconfiguration() override;
    // Source the given stream of bytes to be sinked into the upper layers
    // Source the given stream of bytes to be sinked into the upper layers
    size_t Write(const uint8_t* p_buf, uint32_t len);
    size_t Write(const uint8_t* p_buf, uint32_t len);
  };
  };
+58 −37
Original line number Original line Diff line number Diff line
@@ -328,6 +328,15 @@ class LeAudioClientImpl : public LeAudioClient {
    }
    }
  }
  }


  void SuspendedForReconfiguration() {
    if (audio_sender_state_ > AudioState::IDLE) {
      LeAudioClientAudioSource::SuspendedForReconfiguration();
    }
    if (audio_receiver_state_ > AudioState::IDLE) {
      LeAudioClientAudioSink::SuspendedForReconfiguration();
    }
  }

  void CancelStreamingRequest() {
  void CancelStreamingRequest() {
    if (audio_sender_state_ >= AudioState::READY_TO_START) {
    if (audio_sender_state_ >= AudioState::READY_TO_START) {
      LeAudioClientAudioSource::CancelStreamingRequest();
      LeAudioClientAudioSource::CancelStreamingRequest();
@@ -3031,7 +3040,7 @@ class LeAudioClientImpl : public LeAudioClient {
        rxUnreceivedPackets, duplicatePackets);
        rxUnreceivedPackets, duplicatePackets);
  }
  }


  bool RestartStreamingAfterReconfiguration(int group_id) {
  bool IsSuspendedForReconfiguration(int group_id) {
    if (group_id != active_group_id_) return false;
    if (group_id != active_group_id_) return false;


    DLOG(INFO) << __func__ << " audio_sender_state_: " << audio_sender_state_
    DLOG(INFO) << __func__ << " audio_sender_state_: " << audio_sender_state_
@@ -3044,32 +3053,64 @@ class LeAudioClientImpl : public LeAudioClient {
    DLOG(INFO) << __func__ << " stream_conf->reconfiguration_ongoing "
    DLOG(INFO) << __func__ << " stream_conf->reconfiguration_ongoing "
               << stream_conf->reconfiguration_ongoing;
               << stream_conf->reconfiguration_ongoing;


    if (!stream_conf->reconfiguration_ongoing) return false;
    return stream_conf->reconfiguration_ongoing;
  }


    if (!groupStateMachine_->StartStream(
  bool RestartStreamingAfterReconfiguration(int group_id) {
            group, static_cast<LeAudioContextType>(current_context_type_)))
    auto group = aseGroups_.FindById(group_id);
      return false;
    LOG_ASSERT(group) << __func__ << " group does not exist: " << group_id;


    if (groupStateMachine_->StartStream(
            group, static_cast<LeAudioContextType>(current_context_type_))) {
      if (audio_sender_state_ == AudioState::RELEASING)
      if (audio_sender_state_ == AudioState::RELEASING)
        audio_sender_state_ = AudioState::READY_TO_START;
        audio_sender_state_ = AudioState::READY_TO_START;


      if (audio_receiver_state_ == AudioState::RELEASING)
      if (audio_receiver_state_ == AudioState::RELEASING)
        audio_receiver_state_ = AudioState::READY_TO_START;
        audio_receiver_state_ = AudioState::READY_TO_START;
    } else {
      audio_receiver_state_ = AudioState::IDLE;
      audio_sender_state_ = AudioState::IDLE;
    }


    stream_conf->reconfiguration_ongoing = false;
    group->stream_conf.reconfiguration_ongoing = false;
    return true;
    return true;
  }
  }


  void HandlePendingAvailableContexts(int group_id) {
    LeAudioDeviceGroup* group = aseGroups_.FindById(group_id);
    if (!group) return;

    /* Update group configuration with pending available context */
    std::optional<AudioContexts> pending_update_available_contexts =
        group->GetPendingUpdateAvailableContexts();
    if (pending_update_available_contexts) {
      std::optional<AudioContexts> updated_contexts =
          group->UpdateActiveContextsMap(*pending_update_available_contexts);

      if (updated_contexts) {
        callbacks_->OnAudioConf(group->audio_directions_, group->group_id_,
                                group->snk_audio_locations_.to_ulong(),
                                group->src_audio_locations_.to_ulong(),
                                updated_contexts->to_ulong());
      }

      group->SetPendingUpdateAvailableContexts(std::nullopt);
    }
  }

  void StatusReportCb(int group_id, GroupStreamStatus status) {
  void StatusReportCb(int group_id, GroupStreamStatus status) {
    DLOG(INFO) << __func__ << "status: " << static_cast<int>(status)
    DLOG(INFO) << __func__ << "status: " << static_cast<int>(status)
               << " audio_sender_state_: " << audio_sender_state_
               << " audio_sender_state_: " << audio_sender_state_
               << " audio_receiver_state_: " << audio_receiver_state_;
               << " audio_receiver_state_: " << audio_receiver_state_;
    switch (status) {
    switch (status) {
      case GroupStreamStatus::STREAMING:
      case GroupStreamStatus::STREAMING:
        LOG_ASSERT(group_id == active_group_id_)
            << __func__ << " invalid group id " << group_id
            << " active_group_id_ " << active_group_id_;
        if (audio_sender_state_ == AudioState::READY_TO_START)
        if (audio_sender_state_ == AudioState::READY_TO_START)
          StartSendingAudio(active_group_id_);
          StartSendingAudio(group_id);
        if (audio_receiver_state_ == AudioState::READY_TO_START)
        if (audio_receiver_state_ == AudioState::READY_TO_START)
          StartReceivingAudio(active_group_id_);
          StartReceivingAudio(group_id);


        stream_setup_end_timestamp_ =
        stream_setup_end_timestamp_ =
            bluetooth::common::time_get_os_boottime_us();
            bluetooth::common::time_get_os_boottime_us();
@@ -3081,34 +3122,14 @@ class LeAudioClientImpl : public LeAudioClient {
      case GroupStreamStatus::IDLE: {
      case GroupStreamStatus::IDLE: {
        stream_setup_end_timestamp_ = 0;
        stream_setup_end_timestamp_ = 0;
        stream_setup_start_timestamp_ = 0;
        stream_setup_start_timestamp_ = 0;

        if (IsSuspendedForReconfiguration(group_id)) {
        if (!RestartStreamingAfterReconfiguration(group_id))
          SuspendedForReconfiguration();
          RestartStreamingAfterReconfiguration(group_id);
        } else {
          CancelStreamingRequest();
          CancelStreamingRequest();

        LeAudioDeviceGroup* group = aseGroups_.FindById(active_group_id_);
        if (!group) {
          LOG(ERROR) << __func__ << ", Failed to update pending available "
                     << "contexts for group: " << group_id;
          return;
        }

        /* Update group configuration with pending available context */
        std::optional<AudioContexts> pending_update_available_contexts =
            group->GetPendingUpdateAvailableContexts();
        if (pending_update_available_contexts) {
          std::optional<AudioContexts> updated_contexts =
              group->UpdateActiveContextsMap(*pending_update_available_contexts);

          if (updated_contexts) {
            callbacks_->OnAudioConf(group->audio_directions_, group->group_id_,
                                    group->snk_audio_locations_.to_ulong(),
                                    group->src_audio_locations_.to_ulong(),
                                    updated_contexts->to_ulong());
          }

          group->SetPendingUpdateAvailableContexts(std::nullopt);
        }
        }


        HandlePendingAvailableContexts(group_id);
        break;
        break;
      }
      }
      case GroupStreamStatus::RELEASING:
      case GroupStreamStatus::RELEASING:
+22 −0
Original line number Original line Diff line number Diff line
@@ -401,6 +401,17 @@ void LeAudioClientAudioSource::ConfirmStreamingRequest() {
  start_audio_ticks();
  start_audio_ticks();
}
}


void LeAudioClientAudioSource::SuspendedForReconfiguration() {
  LOG(INFO) << __func__;
  if ((sinkClientInterface == nullptr) ||
      (le_audio_sink_hal_state != HAL_STARTED)) {
    LOG(ERROR) << "LE audio device HAL was not started!";
    return;
  }

  sinkClientInterface->SuspendedForReconfiguration();
}

void LeAudioClientAudioSource::CancelStreamingRequest() {
void LeAudioClientAudioSource::CancelStreamingRequest() {
  LOG(INFO) << __func__;
  LOG(INFO) << __func__;
  if ((sinkClientInterface == nullptr) ||
  if ((sinkClientInterface == nullptr) ||
@@ -628,3 +639,14 @@ void LeAudioClientAudioSink::UpdateAudioConfigToHal(


  sourceClientInterface->UpdateAudioConfigToHal(config);
  sourceClientInterface->UpdateAudioConfigToHal(config);
}
}

void LeAudioClientAudioSink::SuspendedForReconfiguration() {
  LOG(INFO) << __func__;
  if ((sourceClientInterface == nullptr) ||
      (le_audio_source_hal_state != HAL_STARTED)) {
    LOG(ERROR) << "LE audio device HAL was not started!";
    return;
  }

  sourceClientInterface->SuspendedForReconfiguration();
}
Loading