From c12dc4d9e01d7b526df1577bbac81ff87715bf79 Mon Sep 17 00:00:00 2001 From: Cheney Ni Date: Mon, 23 Mar 2020 22:40:39 +0800 Subject: [PATCH] A2DP: Remember every peer's AVDTP delay reporting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Almost every headset has its own delay reporting. This change remembers those particular values individually, and applies when the peer is the active device. Bug: 152276107 Test: manually Change-Id: I634dfd18a034fe4020f48139d7e0f14a1309098a Merged-In: I634dfd18a034fe4020f48139d7e0f14a1309098a (cherry picked from commit 0bf47fa2cf71188728aac2d232e2f02e8661d92c) --- btif/co/bta_av_co.cc | 2 +- btif/include/btif_av.h | 9 ++++++++- btif/src/btif_a2dp_source.cc | 1 + btif/src/btif_av.cc | 27 ++++++++++++++++++++++++--- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/btif/co/bta_av_co.cc b/btif/co/bta_av_co.cc index 60b407c33..b2a02d9e9 100644 --- a/btif/co/bta_av_co.cc +++ b/btif/co/bta_av_co.cc @@ -1378,7 +1378,7 @@ void BtaAvCo::ProcessAudioDelay(tBTA_AV_HNDL bta_av_handle, APPL_TRACE_DEBUG("%s: peer %s bta_av_handle: 0x%x delay:0x%x", __func__, peer_address.ToString().c_str(), bta_av_handle, delay); - btif_av_set_audio_delay(delay); + btif_av_set_audio_delay(peer_address, delay); } void BtaAvCo::UpdateMtu(tBTA_AV_HNDL bta_av_handle, diff --git a/btif/include/btif_av.h b/btif/include/btif_av.h index 1c596f961..adbc33324 100644 --- a/btif/include/btif_av.h +++ b/btif/include/btif_av.h @@ -163,9 +163,16 @@ void btif_debug_av_dump(int fd); /** * Set the audio delay for the stream. * + * @param peer_address the address of the peer to report * @param delay the delay to set in units of 1/10ms */ -void btif_av_set_audio_delay(uint16_t delay); +void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay); + +/** + * Get the audio delay for the stream. + * @param none + */ +uint16_t btif_av_get_audio_delay(void); /** * Reset the audio delay and count of audio bytes sent to zero. diff --git a/btif/src/btif_a2dp_source.cc b/btif/src/btif_a2dp_source.cc index ceb8bc61b..cd06a1219 100644 --- a/btif/src/btif_a2dp_source.cc +++ b/btif/src/btif_a2dp_source.cc @@ -399,6 +399,7 @@ static void btif_a2dp_source_start_session_delayed( } if (bluetooth::audio::a2dp::is_hal_2_0_enabled()) { bluetooth::audio::a2dp::start_session(); + bluetooth::audio::a2dp::set_remote_delay(btif_av_get_audio_delay()); BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart( bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0); } else if (btif_av_is_a2dp_offload_enabled()) { diff --git a/btif/src/btif_av.cc b/btif/src/btif_av.cc index 543cc91ff..8dc2f2572 100644 --- a/btif/src/btif_av.cc +++ b/btif/src/btif_av.cc @@ -282,6 +282,10 @@ class BtifAvPeer { void SetSilence(bool silence) { is_silenced_ = silence; }; + // AVDTP delay reporting in 1/10 milliseconds + void SetDelayReport(uint16_t delay) { delay_report_ = delay; }; + uint16_t GetDelayReport() const { return delay_report_; }; + /** * Check whether any of the flags specified by the bitlags mask is set. * @@ -330,6 +334,7 @@ class BtifAvPeer { uint8_t flags_; bool self_initiated_connection_; bool is_silenced_; + uint16_t delay_report_; }; class BtifAvSource { @@ -864,7 +869,8 @@ BtifAvPeer::BtifAvPeer(const RawAddress& peer_address, uint8_t peer_sep, av_open_on_rc_timer_(nullptr), edr_(0), flags_(0), - self_initiated_connection_(false) {} + self_initiated_connection_(false), + delay_report_(0) {} BtifAvPeer::~BtifAvPeer() { alarm_free(av_open_on_rc_timer_); } @@ -3263,6 +3269,7 @@ static void btif_debug_av_peer_dump(int fd, const BtifAvPeer& peer) { dprintf(fd, " Support 3Mbps: %s\n", peer.Is3Mbps() ? "true" : "false"); dprintf(fd, " Self Initiated Connection: %s\n", peer.SelfInitiatedConnection() ? "true" : "false"); + dprintf(fd, " Delay Reporting: %u\n", peer.GetDelayReport()); } static void btif_debug_av_source_dump(int fd) { @@ -3297,9 +3304,23 @@ void btif_debug_av_dump(int fd) { btif_debug_av_sink_dump(fd); } -void btif_av_set_audio_delay(uint16_t delay) { +void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay) { btif_a2dp_control_set_audio_delay(delay); - bluetooth::audio::a2dp::set_remote_delay(delay); + BtifAvPeer* peer = btif_av_find_peer(peer_address); + if (peer != nullptr && peer->IsSink()) { + peer->SetDelayReport(delay); + if (peer->IsActivePeer()) { + bluetooth::audio::a2dp::set_remote_delay(peer->GetDelayReport()); + } + } +} + +uint16_t btif_av_get_audio_delay() { + BtifAvPeer* peer = btif_av_find_active_peer(); + if (peer != nullptr && peer->IsSink()) { + return peer->GetDelayReport(); + } + return 0; } void btif_av_reset_audio_delay(void) { btif_a2dp_control_reset_audio_delay(); } -- 2.11.0