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

Commit 454db571 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Add Start/End Session for A2DP offload audio interface

* Added explicit btif_a2dp_audio_interface_start_session() and
  btif_a2dp_audio_interface_end_session() and call them as appropriate.
* Removed unnecessary btif_a2dp_audio_interface_deinit() calls.

Bug: 74952724
Test: Manual: audio streaming without A2DP offload
Change-Id: I74b8c340ee258b09b9e1acbcb1cc75906ddc03fc
Merged-In: I74b8c340ee258b09b9e1acbcb1cc75906ddc03fc
(cherry picked from commit 9d73f984efd16d894bd0bcc2bb3a3871778ab898)
parent a1845300
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -31,5 +31,7 @@ void btif_a2dp_audio_on_stopped(tBTA_AV_STATUS status);
void btif_a2dp_audio_on_suspended(tBTA_AV_STATUS status);
void btif_a2dp_audio_interface_init(void);
void btif_a2dp_audio_interface_deinit(void);
void btif_a2dp_audio_interface_start_session(void);
void btif_a2dp_audio_interface_end_session(void);

#endif /* BTIF_A2DP_AUDIO_INTERFACE_H */
+19 −8
Original line number Diff line number Diff line
@@ -175,17 +175,13 @@ static void btif_a2dp_get_codec_configuration(

void btif_a2dp_audio_interface_init() {
  LOG_INFO(LOG_TAG, "%s", __func__);
  CodecConfiguration codec_info;

  btif_a2dp_get_codec_configuration(&codec_info);
  btAudio = IBluetoothAudioOffload::getService();
  CHECK(btAudio != nullptr);

  LOG_DEBUG(
      LOG_TAG, "%s: IBluetoothAudioOffload::getService() returned %p (%s)",
      __func__, btAudio.get(), (btAudio->isRemote() ? "remote" : "local"));
  android::sp<IBluetoothAudioHost> host_if = new BluetoothAudioHost();
  btAudio->startSession(host_if, codec_info);
  deinit_pending = false;
  LOG_INFO(LOG_TAG, "%s:Init returned", __func__);
}
@@ -194,16 +190,31 @@ void btif_a2dp_audio_interface_deinit() {
  LOG_INFO(LOG_TAG, "%s: start", __func__);
  if (btAudio != nullptr) {
    deinit_pending = true;
    auto ret = btAudio->endSession();
    if (!ret.isOk()) {
      LOG_ERROR(LOG_TAG, "HAL server is dead");
    }
  }
  deinit_pending = false;
  btAudio = nullptr;
  LOG_INFO(LOG_TAG, "%s: exit", __func__);
}

void btif_a2dp_audio_interface_start_session() {
  LOG_INFO(LOG_TAG, "%s", __func__);
  CHECK(btAudio != nullptr);

  CodecConfiguration codec_info;
  btif_a2dp_get_codec_configuration(&codec_info);
  android::sp<IBluetoothAudioHost> host_if = new BluetoothAudioHost();
  btAudio->startSession(host_if, codec_info);
}

void btif_a2dp_audio_interface_end_session() {
  LOG_INFO(LOG_TAG, "%s", __func__);
  CHECK(btAudio != nullptr);
  auto ret = btAudio->endSession();
  if (!ret.isOk()) {
    LOG_ERROR(LOG_TAG, "HAL server is dead");
  }
}

void btif_a2dp_audio_on_started(tBTA_AV_STATUS status) {
  LOG_INFO(LOG_TAG, "%s: status = %d", __func__, status);
  if (btAudio != nullptr) {
+6 −0
Original line number Diff line number Diff line
@@ -443,6 +443,9 @@ static void btif_a2dp_source_start_session_delayed(
    LOG_ERROR(LOG_TAG, "%s: A2DP Source media task is not running", __func__);
    return;
  }
  if (btif_av_is_a2dp_offload_enabled()) {
    btif_a2dp_audio_interface_start_session();
  }
}

bool btif_a2dp_source_end_session(const RawAddress& peer_address) {
@@ -462,6 +465,9 @@ static void btif_a2dp_source_end_session_delayed(
    LOG_ERROR(LOG_TAG, "%s: A2DP Source media task is not running", __func__);
    return;
  }
  if (btif_av_is_a2dp_offload_enabled()) {
    btif_a2dp_audio_interface_end_session();
  }
}

void btif_a2dp_source_shutdown(void) {
+0 −13
Original line number Diff line number Diff line
@@ -1801,9 +1801,6 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
        BTA_AvCloseRc(peer_.BtaHandle());
      }

      if (btif_av_is_a2dp_offload_enabled()) {
        btif_a2dp_audio_interface_deinit();
      }
      // Inform the application that we are disconnecting
      btif_report_connection_state(peer_.PeerAddress(),
                                   BTAV_CONNECTION_STATE_DISCONNECTING);
@@ -1813,9 +1810,6 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
      break;

    case BTA_AV_CLOSE_EVT:
      if (btif_av_is_a2dp_offload_enabled()) {
        btif_a2dp_audio_interface_deinit();
      }
      // AVDTP link is closed
      if (peer_.IsActivePeer()) {
        btif_a2dp_on_stopped(nullptr);
@@ -1957,10 +1951,6 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
        BTA_AvCloseRc(peer_.BtaHandle());
      }

      if (btif_av_is_a2dp_offload_enabled()) {
        btif_a2dp_audio_interface_deinit();
      }

      // Inform the application that we are disconnecting
      btif_report_connection_state(peer_.PeerAddress(),
                                   BTAV_CONNECTION_STATE_DISCONNECTING);
@@ -2036,9 +2026,6 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,

      peer_.SetFlags(BtifAvPeer::kFlagPendingStop);

      if (btif_av_is_a2dp_offload_enabled()) {
        btif_a2dp_audio_interface_deinit();
      }
      // AVDTP link is closed
      if (peer_.IsActivePeer()) {
        btif_a2dp_on_stopped(nullptr);