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

Commit a2b0229d authored by Qasim Javed's avatar Qasim Javed Committed by Automerger Merge Worker
Browse files

Merge "Wait until A2DP source shutdown completes when active peer is set to...

Merge "Wait until A2DP source shutdown completes when active peer is set to the empty address." am: da3540de

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2381834



Change-Id: Id6434d0873eb0593000044014f9c49cdeca3f774
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 7c5702e8 da3540de
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ bool btif_a2dp_source_end_session(const RawAddress& peer_address);

// Shutdown the A2DP Source module.
// This function should be called by the BTIF state machine to stop streaming.
void btif_a2dp_source_shutdown(void);
void btif_a2dp_source_shutdown(std::promise<void>);

// Cleanup the A2DP Source module.
// This function should be called by the BTIF state machine during graceful
+11 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <string.h>

#include <algorithm>
#include <future>

#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
#include "audio_hal_interface/a2dp_encoding.h"
@@ -242,7 +243,7 @@ static void btif_a2dp_source_start_session_delayed(
    const RawAddress& peer_address, std::promise<void> start_session_promise);
static void btif_a2dp_source_end_session_delayed(
    const RawAddress& peer_address);
static void btif_a2dp_source_shutdown_delayed(void);
static void btif_a2dp_source_shutdown_delayed(std::promise<void>);
static void btif_a2dp_source_cleanup_delayed(void);
static void btif_a2dp_source_audio_tx_start_event(void);
static void btif_a2dp_source_audio_tx_stop_event(void);
@@ -483,7 +484,7 @@ static void btif_a2dp_source_end_session_delayed(
  }
}

void btif_a2dp_source_shutdown(void) {
void btif_a2dp_source_shutdown(std::promise<void> shutdown_complete_promise) {
  LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());

  if ((btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) ||
@@ -495,10 +496,12 @@ void btif_a2dp_source_shutdown(void) {
  btif_a2dp_source_cb.SetState(BtifA2dpSource::kStateShuttingDown);

  btif_a2dp_source_thread.DoInThread(
      FROM_HERE, base::Bind(&btif_a2dp_source_shutdown_delayed));
      FROM_HERE, base::BindOnce(&btif_a2dp_source_shutdown_delayed,
                                std::move(shutdown_complete_promise)));
}

static void btif_a2dp_source_shutdown_delayed(void) {
static void btif_a2dp_source_shutdown_delayed(
    std::promise<void> shutdown_complete_promise) {
  LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());

  // Stop the timer
@@ -514,13 +517,16 @@ static void btif_a2dp_source_shutdown_delayed(void) {
  btif_a2dp_source_cb.tx_audio_queue = nullptr;

  btif_a2dp_source_cb.SetState(BtifA2dpSource::kStateOff);

  shutdown_complete_promise.set_value();
}

void btif_a2dp_source_cleanup(void) {
  LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());

  // Make sure the source is shutdown
  btif_a2dp_source_shutdown();
  std::promise<void> shutdown_complete_promise;
  btif_a2dp_source_shutdown(std::move(shutdown_complete_promise));

  btif_a2dp_source_thread.DoInThread(
      FROM_HERE, base::Bind(&btif_a2dp_source_cleanup_delayed));
+10 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <frameworks/proto_logging/stats/enums/bluetooth/a2dp/enums.pb.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>

#include <chrono>
#include <cstdint>
#include <future>
#include <memory>
@@ -502,7 +503,15 @@ class BtifAvSource {
                     << ": unable to set active peer to empty in BtaAvCo";
      }
      btif_a2dp_source_end_session(active_peer_);
      btif_a2dp_source_shutdown();
      std::promise<void> shutdown_complete_promise;
      std::future<void> shutdown_complete_future =
          shutdown_complete_promise.get_future();
      btif_a2dp_source_shutdown(std::move(shutdown_complete_promise));
      using namespace std::chrono_literals;
      if (shutdown_complete_future.wait_for(1s) ==
          std::future_status::timeout) {
        LOG_ERROR("Timed out waiting for A2DP source shutdown to complete.");
      }
      active_peer_ = peer_address;
      peer_ready_promise.set_value();
      return true;