aboutsummaryrefslogtreecommitdiff
path: root/btif
diff options
context:
space:
mode:
authorCheney Ni <cheneyni@google.com>2019-12-11 20:57:10 +0800
committerCheney Ni <cheneyni@google.com>2019-12-17 16:35:31 +0800
commit9cfcd653a97273471b3c4c2c0c01318b60e09c5d (patch)
treedb7d92eee4bb2b84e96916430870e3c6901d8c9e /btif
parent13a4af54bce53206db01b9674ae1a3e84749c95b (diff)
downloadbt-9cfcd653a97273471b3c4c2c0c01318b60e09c5d.tar.gz
A2DP: Based on the HAL session type to control the encoder
Because we are now runtime switching the audio HAL between software and hardare data path, it is not suitable any more to simply check whether the offloading is enabled or not when handling the AV state change, and here we check whether the current HAL is running under offloading. TODO: BluetoothA2dp@1.0 is deprecated, and there would be UIPC and BluetoothAudio@2.0 after related code removed. Bug: 143922003 Test: Switching A2DP active devices and codec configurations Change-Id: Iaa35013aa9dd4c928437b68bfa317696b8fad633
Diffstat (limited to 'btif')
-rw-r--r--btif/src/btif_a2dp.cc13
-rw-r--r--btif/src/btif_a2dp_source.cc41
2 files changed, 33 insertions, 21 deletions
diff --git a/btif/src/btif_a2dp.cc b/btif/src/btif_a2dp.cc
index e2d613274..c9f45928f 100644
--- a/btif/src/btif_a2dp.cc
+++ b/btif/src/btif_a2dp.cc
@@ -60,6 +60,7 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start
if (bluetooth::audio::a2dp::is_hal_2_0_enabled()) {
bluetooth::audio::a2dp::ack_stream_started(status);
} else if (btif_av_is_a2dp_offload_enabled()) {
+ // TODO: BluetoothA2dp@1.0 is deprecated
btif_a2dp_audio_on_started(status);
} else {
btif_a2dp_command_ack(status);
@@ -75,7 +76,7 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start
LOG(WARNING) << __func__ << ": peer " << peer_addr << " A2DP is suspending and ignores the started event";
return false;
}
- if (btif_av_is_a2dp_offload_enabled()) {
+ if (btif_av_is_a2dp_offload_running()) {
btif_av_stream_start_offload();
} else if (bluetooth::audio::a2dp::is_hal_2_0_enabled()) {
if (btif_av_get_peer_sep() == AVDT_TSEP_SNK) {
@@ -98,6 +99,7 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start
if (bluetooth::audio::a2dp::is_hal_2_0_enabled()) {
bluetooth::audio::a2dp::ack_stream_started(A2DP_CTRL_ACK_FAILURE);
} else if (btif_av_is_a2dp_offload_enabled()) {
+ // TODO: BluetoothA2dp@1.0 is deprecated
btif_a2dp_audio_on_started(p_av_start->status);
} else {
btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
@@ -116,9 +118,10 @@ void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
return;
}
if (bluetooth::audio::a2dp::is_hal_2_0_enabled() ||
- !btif_av_is_a2dp_offload_enabled()) {
+ !btif_av_is_a2dp_offload_running()) {
btif_a2dp_source_on_stopped(p_av_suspend);
} else if (p_av_suspend != NULL) {
+ // TODO: BluetoothA2dp@1.0 is deprecated
btif_a2dp_audio_on_stopped(p_av_suspend->status);
}
}
@@ -131,9 +134,10 @@ void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) {
return;
}
if (bluetooth::audio::a2dp::is_hal_2_0_enabled() ||
- !btif_av_is_a2dp_offload_enabled()) {
+ !btif_av_is_a2dp_offload_running()) {
btif_a2dp_source_on_suspended(p_av_suspend);
} else if (p_av_suspend != NULL) {
+ // TODO: BluetoothA2dp@1.0 is deprecated
btif_a2dp_audio_on_suspended(p_av_suspend->status);
}
}
@@ -159,7 +163,7 @@ void btif_a2dp_on_offload_started(const RawAddress& peer_addr,
ack = A2DP_CTRL_ACK_FAILURE;
break;
}
- if (btif_av_is_a2dp_offload_enabled()) {
+ if (btif_av_is_a2dp_offload_running()) {
if (ack != BTA_AV_SUCCESS && btif_av_stream_started_ready()) {
// Offload request will return with failure from btif_av sm if
// suspend is triggered for remote start. Disconnect only if SoC
@@ -173,6 +177,7 @@ void btif_a2dp_on_offload_started(const RawAddress& peer_addr,
bluetooth::audio::a2dp::ack_stream_started(ack);
} else {
btif_a2dp_command_ack(ack);
+ // TODO: BluetoothA2dp@1.0 is deprecated
btif_a2dp_audio_on_started(status);
}
}
diff --git a/btif/src/btif_a2dp_source.cc b/btif/src/btif_a2dp_source.cc
index 72e3122cc..ceb8bc61b 100644
--- a/btif/src/btif_a2dp_source.cc
+++ b/btif/src/btif_a2dp_source.cc
@@ -359,6 +359,7 @@ static void btif_a2dp_source_startup_delayed() {
}
if (!bluetooth::audio::a2dp::init(&btif_a2dp_source_thread)) {
if (btif_av_is_a2dp_offload_enabled()) {
+ // TODO: BluetoothA2dp@1.0 is deprecated
LOG(WARNING) << __func__ << ": Using BluetoothA2dp HAL";
} else {
LOG(WARNING) << __func__ << ": Using legacy HAL";
@@ -401,6 +402,7 @@ static void btif_a2dp_source_start_session_delayed(
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
} else if (btif_av_is_a2dp_offload_enabled()) {
+ // TODO: BluetoothA2dp@1.0 is deprecated
btif_a2dp_audio_interface_start_session();
} else {
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
@@ -467,6 +469,7 @@ static void btif_a2dp_source_end_session_delayed(
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
} else if (btif_av_is_a2dp_offload_enabled()) {
+ // TODO: BluetoothA2dp@1.0 is deprecated
btif_a2dp_audio_interface_end_session();
} else {
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
@@ -501,6 +504,7 @@ static void btif_a2dp_source_shutdown_delayed(void) {
if (bluetooth::audio::a2dp::is_hal_2_0_enabled()) {
bluetooth::audio::a2dp::cleanup();
} else if (btif_av_is_a2dp_offload_enabled()) {
+ // TODO: BluetoothA2dp@1.0 is deprecated
btif_a2dp_audio_interface_end_session();
} else {
btif_a2dp_control_cleanup();
@@ -718,7 +722,7 @@ void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
}
}
- } else if (btif_av_is_a2dp_offload_enabled()) {
+ } else if (btif_av_is_a2dp_offload_running()) {
bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_SUCCESS);
return;
}
@@ -754,7 +758,7 @@ void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) {
btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
}
}
- } else if (btif_av_is_a2dp_offload_enabled()) {
+ } else if (btif_av_is_a2dp_offload_running()) {
bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_SUCCESS);
return;
}
@@ -776,13 +780,13 @@ void btif_a2dp_source_set_tx_flush(bool enable) {
}
static void btif_a2dp_source_audio_tx_start_event(void) {
- LOG_INFO(LOG_TAG, "%s: media_alarm is %srunning, streaming %s state=%s",
- __func__,
- btif_a2dp_source_cb.media_alarm.IsScheduled() ? "" : "not ",
- btif_a2dp_source_is_streaming() ? "true" : "false",
- btif_a2dp_source_cb.StateStr().c_str());
+ LOG_INFO(
+ LOG_TAG, "%s: media_alarm is %s, streaming %s state=%s", __func__,
+ btif_a2dp_source_cb.media_alarm.IsScheduled() ? "running" : "stopped",
+ btif_a2dp_source_is_streaming() ? "true" : "false",
+ btif_a2dp_source_cb.StateStr().c_str());
- if (btif_av_is_a2dp_offload_enabled()) return;
+ if (btif_av_is_a2dp_offload_running()) return;
/* Reset the media feeding state */
CHECK(btif_a2dp_source_cb.encoder_interface != nullptr);
@@ -792,6 +796,9 @@ static void btif_a2dp_source_audio_tx_start_event(void) {
"%s: starting timer %" PRIu64 " ms", __func__,
btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms());
+ /* audio engine starting, reset tx suspended flag */
+ btif_a2dp_source_cb.tx_flush = false;
+
wakelock_acquire();
btif_a2dp_source_cb.media_alarm.SchedulePeriodic(
btif_a2dp_source_thread.GetWeakPtr(), FROM_HERE,
@@ -816,13 +823,13 @@ static void btif_a2dp_source_audio_tx_start_event(void) {
}
static void btif_a2dp_source_audio_tx_stop_event(void) {
- LOG_INFO(LOG_TAG, "%s: media_alarm is %srunning, streaming %s state=%s",
- __func__,
- btif_a2dp_source_cb.media_alarm.IsScheduled() ? "" : "not ",
- btif_a2dp_source_is_streaming() ? "true" : "false",
- btif_a2dp_source_cb.StateStr().c_str());
+ LOG_INFO(
+ LOG_TAG, "%s: media_alarm is %s, streaming %s state=%s", __func__,
+ btif_a2dp_source_cb.media_alarm.IsScheduled() ? "running" : "stopped",
+ btif_a2dp_source_is_streaming() ? "true" : "false",
+ btif_a2dp_source_cb.StateStr().c_str());
- if (btif_av_is_a2dp_offload_enabled()) return;
+ if (btif_av_is_a2dp_offload_running()) return;
btif_a2dp_source_cb.stats.session_end_us =
bluetooth::common::time_get_os_boottime_us();
@@ -876,7 +883,7 @@ static void btif_a2dp_source_audio_tx_stop_event(void) {
}
static void btif_a2dp_source_audio_handle_timer(void) {
- if (btif_av_is_a2dp_offload_enabled()) return;
+ if (btif_av_is_a2dp_offload_running()) return;
uint64_t timestamp_us = bluetooth::common::time_get_os_boottime_us();
log_tstamps_us("A2DP Source tx timer", timestamp_us);
@@ -1029,7 +1036,7 @@ static void btif_a2dp_source_audio_tx_flush_event(void) {
/* Flush all enqueued audio buffers (encoded) */
LOG_INFO(LOG_TAG, "%s: state=%s", __func__,
btif_a2dp_source_cb.StateStr().c_str());
- if (btif_av_is_a2dp_offload_enabled()) return;
+ if (btif_av_is_a2dp_offload_running()) return;
if (btif_a2dp_source_cb.encoder_interface != nullptr)
btif_a2dp_source_cb.encoder_interface->feeding_flush();
@@ -1289,7 +1296,7 @@ static void btif_a2dp_source_update_metrics(void) {
SchedulingStats enqueue_stats = stats.tx_queue_enqueue_stats;
A2dpSessionMetrics metrics;
metrics.codec_index = stats.codec_index;
- metrics.is_a2dp_offload = btif_av_is_a2dp_offload_enabled();
+ metrics.is_a2dp_offload = btif_av_is_a2dp_offload_running();
// session_start_us is 0 when btif_a2dp_source_start_audio_req() is not called
// mark the metric duration as invalid (-1) in this case
if (stats.session_start_us != 0) {