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

Commit 392e1aff authored by Henri Chataing's avatar Henri Chataing
Browse files

btif_a2dp_source: Run a2dp::set_audio_low_latency_mode_allowed on bt_a2dp_source_worker_thread

a2dp::cleanup is run from bt_a2dp_source_worker_thread and executing
a2dp::set_audio_low_latency_mode_allowed on a different thread
will open a potential data race.

Bug: 329537023
Test: m com.android.btservices
Flag: EXEMPT, minor bugfix
Change-Id: I164532c642b26a8cd73d14d6acc4a9e102298896
parent fc5f6077
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@ bool btif_a2dp_source_restart_session(const RawAddress& old_peer_address,
// streaming session for |peer_address|.
bool btif_a2dp_source_end_session(const RawAddress& peer_address);

// Update allowed low latency modes for the active session.
void btif_a2dp_source_allow_low_latency_audio(bool allowed);

// Shutdown the A2DP Source module.
// This function should be called by the BTIF state machine to stop streaming.
void btif_a2dp_source_shutdown(std::promise<void>);
+2 −3
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@
#include "bta/include/bta_vc_api.h"
#include "btif/avrcp/avrcp_service.h"
#include "btif/include/btif_a2dp.h"
#include "btif/include/btif_a2dp_source.h"
#include "btif/include/btif_api.h"
#include "btif/include/btif_av.h"
#include "btif/include/btif_bqr.h"
@@ -1117,9 +1118,7 @@ static int set_dynamic_audio_buffer_size(int codec, int size) {
}

static bool allow_low_latency_audio(bool allowed, const RawAddress& /* address */) {
  log::info("{}", allowed);
  do_in_main_thread(
          base::BindOnce(bluetooth::audio::a2dp::set_audio_low_latency_mode_allowed, allowed));
  btif_a2dp_source_allow_low_latency_audio(allowed);
  return true;
}

+8 −0
Original line number Diff line number Diff line
@@ -515,6 +515,14 @@ static void btif_a2dp_source_end_session_delayed(const RawAddress& peer_address)
  }
}

void btif_a2dp_source_allow_low_latency_audio(bool allowed) {
  log::info("allowed={}", allowed);

  btif_a2dp_source_thread.DoInThread(
          FROM_HERE,
          base::BindOnce(bluetooth::audio::a2dp::set_audio_low_latency_mode_allowed, allowed));
}

void btif_a2dp_source_shutdown(std::promise<void> shutdown_complete_promise) {
  log::info("state={}", btif_a2dp_source_cb.StateStr());