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

Commit 9ab66438 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." into tm-qpr-dev am: a10aa601

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



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


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


#include <algorithm>
#include <algorithm>
#include <future>


#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
#include "audio_hal_interface/a2dp_encoding.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);
    const RawAddress& peer_address, std::promise<void> start_session_promise);
static void btif_a2dp_source_end_session_delayed(
static void btif_a2dp_source_end_session_delayed(
    const RawAddress& peer_address);
    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_cleanup_delayed(void);
static void btif_a2dp_source_audio_tx_start_event(void);
static void btif_a2dp_source_audio_tx_start_event(void);
static void btif_a2dp_source_audio_tx_stop_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());
  LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());


  if ((btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) ||
  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_cb.SetState(BtifA2dpSource::kStateShuttingDown);


  btif_a2dp_source_thread.DoInThread(
  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());
  LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());


  // Stop the timer
  // 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.tx_audio_queue = nullptr;


  btif_a2dp_source_cb.SetState(BtifA2dpSource::kStateOff);
  btif_a2dp_source_cb.SetState(BtifA2dpSource::kStateOff);

  shutdown_complete_promise.set_value();
}
}


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


  // Make sure the source is shutdown
  // 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(
  btif_a2dp_source_thread.DoInThread(
      FROM_HERE, base::Bind(&btif_a2dp_source_cleanup_delayed));
      FROM_HERE, base::Bind(&btif_a2dp_source_cleanup_delayed));
+10 −1
Original line number Original line 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/a2dp/enums.pb.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>


#include <chrono>
#include <cstdint>
#include <cstdint>
#include <future>
#include <future>
#include <memory>
#include <memory>
@@ -500,7 +501,15 @@ class BtifAvSource {
                     << ": unable to set active peer to empty in BtaAvCo";
                     << ": unable to set active peer to empty in BtaAvCo";
      }
      }
      btif_a2dp_source_end_session(active_peer_);
      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;
      active_peer_ = peer_address;
      peer_ready_promise.set_value();
      peer_ready_promise.set_value();
      return true;
      return true;