diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2019-12-30 18:50:15 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-12-30 18:50:15 +0000 |
commit | be7a88318fafc095959c4beb96de19c4283908f4 (patch) | |
tree | f7c46973372032be2280de68ae3d00bd4ce465e1 /btif | |
parent | bf1d6893e24064b0a8336c380556d7435d7a2f24 (diff) | |
parent | 9cfcd653a97273471b3c4c2c0c01318b60e09c5d (diff) | |
download | bt-be7a88318fafc095959c4beb96de19c4283908f4.tar.gz |
Merge changes from topic "A2DP_HAL_SWHW_SWITCH"
* changes:
A2DP: Based on the HAL session type to control the encoder
A2DP: HALs switching between software and offloading sessions
Diffstat (limited to 'btif')
-rw-r--r-- | btif/include/btif_av.h | 6 | ||||
-rw-r--r-- | btif/src/btif_a2dp.cc | 13 | ||||
-rw-r--r-- | btif/src/btif_a2dp_source.cc | 41 | ||||
-rw-r--r-- | btif/src/btif_av.cc | 12 |
4 files changed, 51 insertions, 21 deletions
diff --git a/btif/include/btif_av.h b/btif/include/btif_av.h index e42f0565c..1c596f961 100644 --- a/btif/include/btif_av.h +++ b/btif/include/btif_av.h @@ -188,6 +188,12 @@ void btif_av_src_disconnect_sink(const RawAddress& peer_address); bool btif_av_is_a2dp_offload_enabled(void); /** + * check A2DP offload enabled and running + * @param none + */ +bool btif_av_is_a2dp_offload_running(void); + +/** * Check whether peer device is silenced * * @param peer_address to check 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) { diff --git a/btif/src/btif_av.cc b/btif/src/btif_av.cc index bd9d11c6f..902541fd0 100644 --- a/btif/src/btif_av.cc +++ b/btif/src/btif_av.cc @@ -3268,6 +3268,18 @@ bool btif_av_is_a2dp_offload_enabled() { return btif_av_source.A2dpOffloadEnabled(); } +bool btif_av_is_a2dp_offload_running() { + if (!btif_av_is_a2dp_offload_enabled()) { + return false; + } + if (!bluetooth::audio::a2dp::is_hal_2_0_enabled()) { + // since android::hardware::bluetooth::a2dp::V1_0 deprecated, offloading + // is supported by Bluetooth Audio HAL 2.0 only. + return false; + } + return bluetooth::audio::a2dp::is_hal_2_0_offloading(); +} + bool btif_av_is_peer_silenced(const RawAddress& peer_address) { return btif_av_source.IsPeerSilenced(peer_address); } |