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

Commit 87b25366 authored by Cheney Ni's avatar Cheney Ni
Browse files

A2DP: Remember every peer's AVDTP delay reporting

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)
parent 921bcc3c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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,
+8 −1
Original line number Diff line number Diff line
@@ -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.
+1 −0
Original line number Diff line number Diff line
@@ -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()) {
+24 −3
Original line number Diff line number Diff line
@@ -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(); }