diff options
19 files changed, 149 insertions, 136 deletions
diff --git a/system/audio_hal_interface/a2dp_encoding.cc b/system/audio_hal_interface/a2dp_encoding.cc index 590ea1c70f..266944df2d 100644 --- a/system/audio_hal_interface/a2dp_encoding.cc +++ b/system/audio_hal_interface/a2dp_encoding.cc @@ -94,6 +94,7 @@ void start_session() { } aidl::a2dp::start_session(); } + void end_session() { if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::AIDL) { @@ -105,7 +106,8 @@ void end_session() { return; } } -void ack_stream_started(const tA2DP_CTRL_ACK& status) { + +void ack_stream_started(BluetoothAudioStatus status) { if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) { hidl::a2dp::ack_stream_started(status); @@ -113,7 +115,8 @@ void ack_stream_started(const tA2DP_CTRL_ACK& status) { } return aidl::a2dp::ack_stream_started(status); } -void ack_stream_suspended(const tA2DP_CTRL_ACK& status) { + +void ack_stream_suspended(BluetoothAudioStatus status) { if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) { hidl::a2dp::ack_stream_suspended(status); diff --git a/system/audio_hal_interface/a2dp_encoding.h b/system/audio_hal_interface/a2dp_encoding.h index f6205f69ac..df8371a129 100644 --- a/system/audio_hal_interface/a2dp_encoding.h +++ b/system/audio_hal_interface/a2dp_encoding.h @@ -21,14 +21,26 @@ #include <vector> #include "a2dp_error_codes.h" -#include "audio_a2dp_hw/include/audio_a2dp_hw.h" #include "avdt_api.h" #include "common/message_loop_thread.h" +#include "hardware/bt_av.h" namespace bluetooth { namespace audio { namespace a2dp { +/// Copied after the definition from the Bluetooth Audio interface: +/// hardware/interfaces/bluetooth/audio/aidl/android/hardware/bluetooth/audio/BluetoothAudioStatus.aidl +enum BluetoothAudioStatus { + UNKNOWN = 0, + SUCCESS = 1, + UNSUPPORTED_CODEC_CONFIGURATION = 2, + FAILURE = 3, + // Not defined in BluetoothAudioStatus, but used internally for + // state keeping. + PENDING = 5, +}; + bool update_codec_offloading_capabilities( const std::vector<btav_a2dp_codec_config_t>& framework_preference, bool supports_a2dp_hw_offload_v2); @@ -55,8 +67,8 @@ void set_audio_low_latency_mode_allowed(bool allowed); // StreamStarted, StreamSuspended void start_session(); void end_session(); -void ack_stream_started(const tA2DP_CTRL_ACK& status); -void ack_stream_suspended(const tA2DP_CTRL_ACK& status); +void ack_stream_started(BluetoothAudioStatus status); +void ack_stream_suspended(BluetoothAudioStatus status); // Read from the FMQ of BluetoothAudio HAL size_t read(uint8_t* p_buf, uint32_t len); @@ -162,3 +174,9 @@ tA2DP_STATUS parse_a2dp_configuration( } // namespace a2dp } // namespace audio } // namespace bluetooth + +namespace fmt { +template <> +struct formatter<::bluetooth::audio::a2dp::BluetoothAudioStatus> + : enum_formatter<::bluetooth::audio::a2dp::BluetoothAudioStatus> {}; +} // namespace fmt diff --git a/system/audio_hal_interface/a2dp_encoding_host.cc b/system/audio_hal_interface/a2dp_encoding_host.cc index b449ef346f..4488ed13f5 100644 --- a/system/audio_hal_interface/a2dp_encoding_host.cc +++ b/system/audio_hal_interface/a2dp_encoding_host.cc @@ -24,6 +24,7 @@ #include <vector> #include "a2dp_encoding.h" +#include "audio_a2dp_hw/include/audio_a2dp_hw.h" #include "btif/include/btif_a2dp_source.h" #include "btif/include/btif_av.h" #include "btif/include/btif_hf.h" @@ -263,13 +264,12 @@ void end_session() { void set_audio_low_latency_mode_allowed(bool allowed){ } - -void ack_stream_started(const tA2DP_CTRL_ACK& ack) { +void ack_stream_started(BluetoothAudioStatus /*ack*/) { a2dp_pending_cmd_ = A2DP_CTRL_CMD_NONE; // TODO: Notify server } -void ack_stream_suspended(const tA2DP_CTRL_ACK& ack) { +void ack_stream_suspended(BluetoothAudioStatus /*ack*/) { a2dp_pending_cmd_ = A2DP_CTRL_CMD_NONE; // TODO: Notify server } diff --git a/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc b/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc index 397c424ecd..2f2b0ec6eb 100644 --- a/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc +++ b/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc @@ -46,6 +46,8 @@ namespace audio { namespace aidl { namespace a2dp { +using ::bluetooth::audio::a2dp::BluetoothAudioStatus; + namespace { using ::aidl::android::hardware::bluetooth::audio::A2dpStreamConfiguration; @@ -87,29 +89,29 @@ BluetoothAudioCtrlAck A2dpTransport::StartRequest(bool is_low_latency) { // Check if a previous request is not finished if (a2dp_pending_cmd_ == A2DP_CTRL_CMD_START) { log::info("A2DP_CTRL_CMD_START in progress"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING); + return BluetoothAudioCtrlAck::PENDING; } else if (a2dp_pending_cmd_ != A2DP_CTRL_CMD_NONE) { log::warn("busy in pending_cmd={}", a2dp_pending_cmd_); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE); + return BluetoothAudioCtrlAck::FAILURE; } // Don't send START request to stack while we are in a call if (!bluetooth::headset::IsCallIdle()) { log::error("call state is busy"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_INCALL_FAILURE); + return BluetoothAudioCtrlAck::FAILURE_BUSY; } if (com::android::bluetooth::flags::a2dp_check_lea_iso_channel()) { // Don't send START request to stack while LEA sessions are in use if (hci::IsoManager::GetInstance()->GetNumberOfActiveIso() > 0) { log::error("LEA currently has active ISO channels"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE); + return BluetoothAudioCtrlAck::FAILURE; } } if (btif_av_stream_started_ready(A2dpType::kSource)) { // Already started, ACK back immediately. - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS); + return BluetoothAudioCtrlAck::SUCCESS_FINISHED; } if (btif_av_stream_ready(A2dpType::kSource)) { // check if codec needs to be switched prior to stream start @@ -123,23 +125,23 @@ BluetoothAudioCtrlAck A2dpTransport::StartRequest(bool is_low_latency) { btif_av_stream_start_with_latency(is_low_latency); if (btif_av_get_peer_sep(A2dpType::kSource) != AVDT_TSEP_SRC) { log::info("accepted"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING); + return BluetoothAudioCtrlAck::PENDING; } a2dp_pending_cmd_ = A2DP_CTRL_CMD_NONE; - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS); + return BluetoothAudioCtrlAck::SUCCESS_FINISHED; } log::error("AV stream is not ready to start"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE); + return BluetoothAudioCtrlAck::FAILURE; } BluetoothAudioCtrlAck A2dpTransport::SuspendRequest() { // Previous request is not finished if (a2dp_pending_cmd_ == A2DP_CTRL_CMD_SUSPEND) { log::info("A2DP_CTRL_CMD_SUSPEND in progress"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING); + return BluetoothAudioCtrlAck::PENDING; } else if (a2dp_pending_cmd_ != A2DP_CTRL_CMD_NONE) { log::warn("busy in pending_cmd={}", a2dp_pending_cmd_); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE); + return BluetoothAudioCtrlAck::FAILURE; } // Local suspend if (btif_av_stream_started_ready(A2dpType::kSource)) { @@ -153,7 +155,7 @@ BluetoothAudioCtrlAck A2dpTransport::SuspendRequest() { * remotely suspended, clear REMOTE SUSPEND flag. */ btif_av_clear_remote_suspend_flag(A2dpType::kSource); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS); + return BluetoothAudioCtrlAck::SUCCESS_FINISHED; } void A2dpTransport::StopRequest() { @@ -249,20 +251,16 @@ bool btaudio_a2dp_disabled = false; bool is_configured = false; bool is_low_latency_mode_allowed = false; -BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(tA2DP_CTRL_ACK ack) { +static BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(BluetoothAudioStatus ack) { switch (ack) { - case A2DP_CTRL_ACK_SUCCESS: + case BluetoothAudioStatus::SUCCESS: return BluetoothAudioCtrlAck::SUCCESS_FINISHED; - case A2DP_CTRL_ACK_PENDING: + case BluetoothAudioStatus::PENDING: return BluetoothAudioCtrlAck::PENDING; - case A2DP_CTRL_ACK_INCALL_FAILURE: - return BluetoothAudioCtrlAck::FAILURE_BUSY; - case A2DP_CTRL_ACK_DISCONNECT_IN_PROGRESS: - return BluetoothAudioCtrlAck::FAILURE_DISCONNECTING; - case A2DP_CTRL_ACK_UNSUPPORTED: /* Offloading but resource failure */ + case BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION: return BluetoothAudioCtrlAck::FAILURE_UNSUPPORTED; - case A2DP_CTRL_ACK_FAILURE: - return BluetoothAudioCtrlAck::FAILURE; + case BluetoothAudioStatus::UNKNOWN: + case BluetoothAudioStatus::FAILURE: default: return BluetoothAudioCtrlAck::FAILURE; } @@ -646,46 +644,44 @@ void end_session() { ->ResetPresentationPosition(); } -void ack_stream_started(const tA2DP_CTRL_ACK& ack) { +void ack_stream_started(BluetoothAudioStatus ack) { if (!is_hal_enabled()) { log::error("BluetoothAudio HAL is not enabled"); return; } - auto ctrl_ack = a2dp_ack_to_bt_audio_ctrl_ack(ack); - log::info("result={}", ctrl_ack); + log::info("result={}", ack); auto a2dp_sink = static_cast<A2dpTransport*>(active_hal_interface->GetTransportInstance()); auto pending_cmd = a2dp_sink->GetPendingCmd(); if (pending_cmd == A2DP_CTRL_CMD_START) { - active_hal_interface->StreamStarted(ctrl_ack); + active_hal_interface->StreamStarted(a2dp_ack_to_bt_audio_ctrl_ack(ack)); } else { - log::warn("pending={} ignore result={}", pending_cmd, ctrl_ack); + log::warn("pending={} ignore result={}", pending_cmd, ack); return; } - if (ctrl_ack != BluetoothAudioCtrlAck::PENDING) { + if (ack != BluetoothAudioStatus::PENDING) { a2dp_sink->ResetPendingCmd(); } } -void ack_stream_suspended(const tA2DP_CTRL_ACK& ack) { +void ack_stream_suspended(BluetoothAudioStatus ack) { if (!is_hal_enabled()) { log::error("BluetoothAudio HAL is not enabled"); return; } - auto ctrl_ack = a2dp_ack_to_bt_audio_ctrl_ack(ack); - log::info("result={}", ctrl_ack); + log::info("result={}", ack); auto a2dp_sink = static_cast<A2dpTransport*>(active_hal_interface->GetTransportInstance()); auto pending_cmd = a2dp_sink->GetPendingCmd(); if (pending_cmd == A2DP_CTRL_CMD_SUSPEND) { - active_hal_interface->StreamSuspended(ctrl_ack); + active_hal_interface->StreamSuspended(a2dp_ack_to_bt_audio_ctrl_ack(ack)); } else if (pending_cmd == A2DP_CTRL_CMD_STOP) { - log::info("A2DP_CTRL_CMD_STOP result={}", ctrl_ack); + log::info("A2DP_CTRL_CMD_STOP result={}", ack); } else { - log::warn("pending={} ignore result={}", pending_cmd, ctrl_ack); + log::warn("pending={} ignore result={}", pending_cmd, ack); return; } - if (ctrl_ack != BluetoothAudioCtrlAck::PENDING) { + if (ack != BluetoothAudioStatus::PENDING) { a2dp_sink->ResetPendingCmd(); } } diff --git a/system/audio_hal_interface/aidl/a2dp_encoding_aidl.h b/system/audio_hal_interface/aidl/a2dp_encoding_aidl.h index 8de810254b..25051078a6 100644 --- a/system/audio_hal_interface/aidl/a2dp_encoding_aidl.h +++ b/system/audio_hal_interface/aidl/a2dp_encoding_aidl.h @@ -20,12 +20,12 @@ #include "a2dp_encoding.h" #include "a2dp_sbc_constants.h" -#include "audio_a2dp_hw/include/audio_a2dp_hw.h" #include "btif/include/btif_a2dp_source.h" #include "btif/include/btif_av.h" #include "btif/include/btif_av_co.h" #include "btif/include/btif_hf.h" #include "common/message_loop_thread.h" +#include "hardware/bt_av.h" #include "os/log.h" #include "osi/include/properties.h" #include "types/raw_address.h" @@ -70,8 +70,8 @@ bool setup_codec(); ***/ void start_session(); void end_session(); -void ack_stream_started(const tA2DP_CTRL_ACK& status); -void ack_stream_suspended(const tA2DP_CTRL_ACK& status); +void ack_stream_started(::bluetooth::audio::a2dp::BluetoothAudioStatus status); +void ack_stream_suspended(::bluetooth::audio::a2dp::BluetoothAudioStatus status); /*** * Read from the FMQ of BluetoothAudio HAL diff --git a/system/audio_hal_interface/aidl/a2dp_transport.h b/system/audio_hal_interface/aidl/a2dp_transport.h index 7d840103aa..3ef42836ee 100644 --- a/system/audio_hal_interface/aidl/a2dp_transport.h +++ b/system/audio_hal_interface/aidl/a2dp_transport.h @@ -27,8 +27,6 @@ namespace { using ::bluetooth::audio::aidl::LatencyMode; -BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(tA2DP_CTRL_ACK ack); - // Provide call-in APIs for the Bluetooth Audio HAL class A2dpTransport : public ::bluetooth::audio::aidl::IBluetoothSinkTransportInstance { diff --git a/system/audio_hal_interface/aidl/audio_ctrl_ack.h b/system/audio_hal_interface/aidl/audio_ctrl_ack.h index 664fea4aab..220a55cf66 100644 --- a/system/audio_hal_interface/aidl/audio_ctrl_ack.h +++ b/system/audio_hal_interface/aidl/audio_ctrl_ack.h @@ -24,8 +24,6 @@ namespace bluetooth { namespace audio { namespace aidl { -using ::aidl::android::hardware::bluetooth::audio::BluetoothAudioStatus; - enum class BluetoothAudioCtrlAck : uint8_t { SUCCESS_FINISHED = 0, SUCCESS_RECONFIGURATION, @@ -38,8 +36,9 @@ enum class BluetoothAudioCtrlAck : uint8_t { std::ostream& operator<<(std::ostream& os, const BluetoothAudioCtrlAck& ack); -inline BluetoothAudioStatus BluetoothAudioCtrlAckToHalStatus( - const BluetoothAudioCtrlAck& ack) { +inline ::aidl::android::hardware::bluetooth::audio::BluetoothAudioStatus +BluetoothAudioCtrlAckToHalStatus(const BluetoothAudioCtrlAck& ack) { + using ::aidl::android::hardware::bluetooth::audio::BluetoothAudioStatus; switch (ack) { case BluetoothAudioCtrlAck::SUCCESS_FINISHED: return BluetoothAudioStatus::SUCCESS; diff --git a/system/audio_hal_interface/aidl/client_interface_aidl.cc b/system/audio_hal_interface/aidl/client_interface_aidl.cc index a3ff52c4a6..32e96872d0 100644 --- a/system/audio_hal_interface/aidl/client_interface_aidl.cc +++ b/system/audio_hal_interface/aidl/client_interface_aidl.cc @@ -469,8 +469,8 @@ void BluetoothAudioClientInterface::StreamStarted( log::info("{} ignored", ack); return; } - BluetoothAudioStatus status = BluetoothAudioCtrlAckToHalStatus(ack); + auto status = BluetoothAudioCtrlAckToHalStatus(ack); auto aidl_retval = provider_->streamStarted(status); if (!aidl_retval.isOk()) { @@ -488,8 +488,8 @@ void BluetoothAudioClientInterface::StreamSuspended( log::info("{} ignored", ack); return; } - BluetoothAudioStatus status = BluetoothAudioCtrlAckToHalStatus(ack); + auto status = BluetoothAudioCtrlAckToHalStatus(ack); auto aidl_retval = provider_->streamSuspended(status); if (!aidl_retval.isOk()) { diff --git a/system/audio_hal_interface/aidl/client_interface_aidl.h b/system/audio_hal_interface/aidl/client_interface_aidl.h index 9b92319b5b..4b87cd7569 100644 --- a/system/audio_hal_interface/aidl/client_interface_aidl.h +++ b/system/audio_hal_interface/aidl/client_interface_aidl.h @@ -43,7 +43,6 @@ using ::aidl::android::hardware::bluetooth::audio::A2dpRemoteCapabilities; using ::aidl::android::hardware::bluetooth::audio::A2dpStatus; using ::aidl::android::hardware::bluetooth::audio::AudioCapabilities; using ::aidl::android::hardware::bluetooth::audio::AudioConfiguration; -using ::aidl::android::hardware::bluetooth::audio::BluetoothAudioStatus; using ::aidl::android::hardware::bluetooth::audio::CodecId; using ::aidl::android::hardware::bluetooth::audio::CodecInfo; using ::aidl::android::hardware::bluetooth::audio::CodecParameters; diff --git a/system/audio_hal_interface/fuzzer/README.md b/system/audio_hal_interface/fuzzer/README.md index 6e79d5a207..6d92d8f81f 100644 --- a/system/audio_hal_interface/fuzzer/README.md +++ b/system/audio_hal_interface/fuzzer/README.md @@ -32,7 +32,8 @@ Fuzzers assigns values to the following parameters to pass on to libbt-audio-hal | Parameter| Valid Values| Configured Value| |------------- |-------------| ----- | -| `status` | 0.`A2DP_CTRL_ACK_SUCCESS` 1.`A2DP_CTRL_ACK_FAILURE` 2.`A2DP_CTRL_ACK_INCALL_FAILURE` 3.`A2DP_CTRL_ACK_UNSUPPORTED` 4.`A2DP_CTRL_ACK_PENDING` 5.`A2DP_CTRL_ACK_DISCONNECT_IN_PROGRESS` | Value obtained from FuzzedDataProvider | +| `status` | 0.`UNKNOWN` 1.`SUCCESS` 2.`UNSUPPORTED_CODEC_CONFIGURATION` +3.`FAILURE` 4.`PENDING` | Value obtained from FuzzedDataProvider | | `index` | 0.`BTAV_A2DP_CODEC_INDEX_SOURCE_SBC` 1.`BTAV_A2DP_CODEC_INDEX_SOURCE_AAC` 2.`BTAV_A2DP_CODEC_INDEX_SOURCE_APTX` 3.`BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD` 4.`BTAV_A2DP_CODEC_INDEX_SOURCE_LDAC` 5.`BTAV_A2DP_CODEC_INDEX_SINK_SBC` 6.`BTAV_A2DP_CODEC_INDEX_SINK_AAC` 7.`BTAV_A2DP_CODEC_INDEX_SINK_LDAC` | Value obtained from FuzzedDataProvider | | `sessionType` | 0.`SessionType::UNKNOWN` 1.`SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH` 2.`SessionType::A2DP_HARDWARE_OFFLOAD_DATAPATH` 3.`SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH` | Value obtained from FuzzedDataProvider | | `sessionType_2_1` | 0.`SessionType_2_1::UNKNOWN` 1.`SessionType_2_1::A2DP_SOFTWARE_ENCODING_DATAPATH` 2.`SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH` 3.`SessionType_2_1::HEARING_AID_SOFTWARE_ENCODING_DATAPATH` 4.`SessionType_2_1::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH` 5.`SessionType_2_1::LE_AUDIO_SOFTWARE_DECODED_DATAPATH` 6.`SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH` 7.`SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH` | Value obtained from FuzzedDataProvider | diff --git a/system/audio_hal_interface/fuzzer/libbt_audio_hal_a2dp_encoding_fuzzer.cpp b/system/audio_hal_interface/fuzzer/libbt_audio_hal_a2dp_encoding_fuzzer.cpp index baf77f98b8..e0c4a392cb 100644 --- a/system/audio_hal_interface/fuzzer/libbt_audio_hal_a2dp_encoding_fuzzer.cpp +++ b/system/audio_hal_interface/fuzzer/libbt_audio_hal_a2dp_encoding_fuzzer.cpp @@ -22,6 +22,7 @@ #include "include/btif_av_co.h" #include "osi/include/properties.h" +using ::bluetooth::audio::a2dp::BluetoothAudioStatus; using ::bluetooth::audio::a2dp::update_codec_offloading_capabilities; extern "C" { @@ -30,10 +31,13 @@ struct android_namespace_t* android_get_exported_namespace(const char*) { } } -constexpr tA2DP_CTRL_ACK kCtrlAckStatus[] = { - A2DP_CTRL_ACK_SUCCESS, A2DP_CTRL_ACK_FAILURE, - A2DP_CTRL_ACK_INCALL_FAILURE, A2DP_CTRL_ACK_UNSUPPORTED, - A2DP_CTRL_ACK_PENDING, A2DP_CTRL_ACK_DISCONNECT_IN_PROGRESS}; +constexpr BluetoothAudioStatus kBluetoothAudioStatus[] = { + BluetoothAudioStatus::UNKNOWN, + BluetoothAudioStatus::SUCCESS, + BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION, + BluetoothAudioStatus::FAILURE, + BluetoothAudioStatus::PENDING, +}; constexpr int32_t kRandomStringLength = 256; @@ -103,13 +107,13 @@ void A2dpEncodingFuzzer::process(const uint8_t* data, size_t size) { bluetooth::audio::a2dp::start_session(); - tA2DP_CTRL_ACK status = fdp.PickValueInArray(kCtrlAckStatus); + BluetoothAudioStatus status = fdp.PickValueInArray(kBluetoothAudioStatus); bluetooth::audio::a2dp::ack_stream_started(status); for (auto offloadingPreference : CodecOffloadingPreferenceGenerator()) { update_codec_offloading_capabilities(offloadingPreference, false); } - status = fdp.PickValueInArray(kCtrlAckStatus); + status = fdp.PickValueInArray(kBluetoothAudioStatus); bluetooth::audio::a2dp::ack_stream_suspended(status); bluetooth::audio::a2dp::cleanup(); messageLoopThread.ShutDown(); diff --git a/system/audio_hal_interface/hidl/a2dp_encoding_hidl.cc b/system/audio_hal_interface/hidl/a2dp_encoding_hidl.cc index 868bd50e34..948543da58 100644 --- a/system/audio_hal_interface/hidl/a2dp_encoding_hidl.cc +++ b/system/audio_hal_interface/hidl/a2dp_encoding_hidl.cc @@ -41,6 +41,11 @@ struct formatter<audio_content_type_t> : enum_formatter<audio_content_type_t> { }; } // namespace fmt +namespace bluetooth { +namespace audio { +namespace hidl { +namespace a2dp { + namespace { using ::bluetooth::audio::hidl::AudioCapabilities; @@ -62,9 +67,7 @@ using ::bluetooth::audio::hidl::codec::A2dpLdacToHalConfig; using ::bluetooth::audio::hidl::codec::A2dpSbcToHalConfig; using ::bluetooth::audio::hidl::codec::CodecConfiguration; -using namespace bluetooth; - -BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(tA2DP_CTRL_ACK ack); +using ::bluetooth::audio::a2dp::BluetoothAudioStatus; // Provide call-in APIs for the Bluetooth Audio HAL class A2dpTransport @@ -82,21 +85,21 @@ class A2dpTransport // Check if a previous request is not finished if (a2dp_pending_cmd_ == A2DP_CTRL_CMD_START) { log::info("A2DP_CTRL_CMD_START in progress"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING); + return BluetoothAudioCtrlAck::PENDING; } else if (a2dp_pending_cmd_ != A2DP_CTRL_CMD_NONE) { log::warn("busy in pending_cmd={}", a2dp_pending_cmd_); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE); + return BluetoothAudioCtrlAck::FAILURE; } // Don't send START request to stack while we are in a call if (!bluetooth::headset::IsCallIdle()) { log::error("call state is busy"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_INCALL_FAILURE); + return BluetoothAudioCtrlAck::FAILURE_BUSY; } if (btif_av_stream_started_ready(A2dpType::kSource)) { // Already started, ACK back immediately. - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS); + return BluetoothAudioCtrlAck::SUCCESS_FINISHED; } if (btif_av_stream_ready(A2dpType::kSource)) { /* @@ -108,23 +111,23 @@ class A2dpTransport btif_av_stream_start(A2dpType::kSource); if (btif_av_get_peer_sep(A2dpType::kSource) != AVDT_TSEP_SRC) { log::info("accepted"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING); + return BluetoothAudioCtrlAck::PENDING; } a2dp_pending_cmd_ = A2DP_CTRL_CMD_NONE; - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS); + return BluetoothAudioCtrlAck::SUCCESS_FINISHED; } log::error("AV stream is not ready to start"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE); + return BluetoothAudioCtrlAck::FAILURE; } BluetoothAudioCtrlAck SuspendRequest() override { // Previous request is not finished if (a2dp_pending_cmd_ == A2DP_CTRL_CMD_SUSPEND) { log::info("A2DP_CTRL_CMD_SUSPEND in progress"); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING); + return BluetoothAudioCtrlAck::PENDING; } else if (a2dp_pending_cmd_ != A2DP_CTRL_CMD_NONE) { log::warn("busy in pending_cmd={}", a2dp_pending_cmd_); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE); + return BluetoothAudioCtrlAck::FAILURE; } // Local suspend if (btif_av_stream_started_ready(A2dpType::kSource)) { @@ -138,7 +141,7 @@ class A2dpTransport * remotely suspended, clear REMOTE SUSPEND flag. */ btif_av_clear_remote_suspend_flag(A2dpType::kSource); - return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS); + return BluetoothAudioCtrlAck::SUCCESS_FINISHED; } void StopRequest() override { @@ -220,20 +223,16 @@ uint16_t remote_delay = 0; bool btaudio_a2dp_disabled = false; bool is_configured = false; -BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(tA2DP_CTRL_ACK ack) { +static BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(BluetoothAudioStatus ack) { switch (ack) { - case A2DP_CTRL_ACK_SUCCESS: + case BluetoothAudioStatus::SUCCESS: return BluetoothAudioCtrlAck::SUCCESS_FINISHED; - case A2DP_CTRL_ACK_PENDING: + case BluetoothAudioStatus::PENDING: return BluetoothAudioCtrlAck::PENDING; - case A2DP_CTRL_ACK_INCALL_FAILURE: - return BluetoothAudioCtrlAck::FAILURE_BUSY; - case A2DP_CTRL_ACK_DISCONNECT_IN_PROGRESS: - return BluetoothAudioCtrlAck::FAILURE_DISCONNECTING; - case A2DP_CTRL_ACK_UNSUPPORTED: /* Offloading but resource failure */ + case BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION: return BluetoothAudioCtrlAck::FAILURE_UNSUPPORTED; - case A2DP_CTRL_ACK_FAILURE: - return BluetoothAudioCtrlAck::FAILURE; + case BluetoothAudioStatus::UNKNOWN: + case BluetoothAudioStatus::FAILURE: default: return BluetoothAudioCtrlAck::FAILURE; } @@ -337,11 +336,6 @@ bool is_hal_2_0_force_disabled() { } } // namespace -namespace bluetooth { -namespace audio { -namespace hidl { -namespace a2dp { - bool update_codec_offloading_capabilities( const std::vector<btav_a2dp_codec_config_t>& framework_preference) { return ::bluetooth::audio::hidl::codec::UpdateOffloadingCapabilities( @@ -494,46 +488,44 @@ void end_session() { ->ResetPresentationPosition(); } -void ack_stream_started(const tA2DP_CTRL_ACK& ack) { +void ack_stream_started(BluetoothAudioStatus ack) { if (!is_hal_2_0_enabled()) { log::error("BluetoothAudio HAL is not enabled"); return; } - auto ctrl_ack = a2dp_ack_to_bt_audio_ctrl_ack(ack); - log::info("result={}", ctrl_ack); + log::info("result={}", ack); auto a2dp_sink = static_cast<A2dpTransport*>(active_hal_interface->GetTransportInstance()); auto pending_cmd = a2dp_sink->GetPendingCmd(); if (pending_cmd == A2DP_CTRL_CMD_START) { - active_hal_interface->StreamStarted(ctrl_ack); + active_hal_interface->StreamStarted(a2dp_ack_to_bt_audio_ctrl_ack(ack)); } else { - log::warn("pending={} ignore result={}", pending_cmd, ctrl_ack); + log::warn("pending={} ignore result={}", pending_cmd, ack); return; } - if (ctrl_ack != bluetooth::audio::hidl::BluetoothAudioCtrlAck::PENDING) { + if (ack != BluetoothAudioStatus::PENDING) { a2dp_sink->ResetPendingCmd(); } } -void ack_stream_suspended(const tA2DP_CTRL_ACK& ack) { +void ack_stream_suspended(BluetoothAudioStatus ack) { if (!is_hal_2_0_enabled()) { log::error("BluetoothAudio HAL is not enabled"); return; } - auto ctrl_ack = a2dp_ack_to_bt_audio_ctrl_ack(ack); - log::info("result={}", ctrl_ack); + log::info("result={}", ack); auto a2dp_sink = static_cast<A2dpTransport*>(active_hal_interface->GetTransportInstance()); auto pending_cmd = a2dp_sink->GetPendingCmd(); if (pending_cmd == A2DP_CTRL_CMD_SUSPEND) { - active_hal_interface->StreamSuspended(ctrl_ack); + active_hal_interface->StreamSuspended(a2dp_ack_to_bt_audio_ctrl_ack(ack)); } else if (pending_cmd == A2DP_CTRL_CMD_STOP) { - log::info("A2DP_CTRL_CMD_STOP result={}", ctrl_ack); + log::info("A2DP_CTRL_CMD_STOP result={}", ack); } else { - log::warn("pending={} ignore result={}", pending_cmd, ctrl_ack); + log::warn("pending={} ignore result={}", pending_cmd, ack); return; } - if (ctrl_ack != bluetooth::audio::hidl::BluetoothAudioCtrlAck::PENDING) { + if (ack != BluetoothAudioStatus::PENDING) { a2dp_sink->ResetPendingCmd(); } } @@ -567,7 +559,7 @@ void set_remote_delay(uint16_t delay_report) { ->SetRemoteDelay(delay_report); } -} // namespace a2dp -} // namespace hidl -} // namespace audio -} // namespace bluetooth +} // namespace a2dp +} // namespace hidl +} // namespace audio +} // namespace bluetooth diff --git a/system/audio_hal_interface/hidl/a2dp_encoding_hidl.h b/system/audio_hal_interface/hidl/a2dp_encoding_hidl.h index 98a8f68632..c7933c864b 100644 --- a/system/audio_hal_interface/hidl/a2dp_encoding_hidl.h +++ b/system/audio_hal_interface/hidl/a2dp_encoding_hidl.h @@ -18,8 +18,9 @@ #include <vector> -#include "audio_a2dp_hw/include/audio_a2dp_hw.h" +#include "a2dp_encoding.h" #include "common/message_loop_thread.h" +#include "hardware/bt_av.h" namespace bluetooth { namespace audio { @@ -48,8 +49,8 @@ bool setup_codec(); // StreamStarted, StreamSuspended void start_session(); void end_session(); -void ack_stream_started(const tA2DP_CTRL_ACK& status); -void ack_stream_suspended(const tA2DP_CTRL_ACK& status); +void ack_stream_started(::bluetooth::audio::a2dp::BluetoothAudioStatus status); +void ack_stream_suspended(::bluetooth::audio::a2dp::BluetoothAudioStatus status); // Read from the FMQ of BluetoothAudio HAL size_t read(uint8_t* p_buf, uint32_t len); diff --git a/system/btif/src/btif_a2dp.cc b/system/btif/src/btif_a2dp.cc index fe148ef4d2..057e50872d 100644 --- a/system/btif/src/btif_a2dp.cc +++ b/system/btif/src/btif_a2dp.cc @@ -39,8 +39,7 @@ #include "types/raw_address.h" using namespace bluetooth; - -using namespace bluetooth; +using bluetooth::audio::a2dp::BluetoothAudioStatus; void btif_a2dp_on_idle(const RawAddress& peer_addr, const A2dpType local_a2dp_type) { @@ -73,11 +72,11 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, fmt::ptr(p_av_start)); if (p_av_start == NULL) { - tA2DP_CTRL_ACK status = A2DP_CTRL_ACK_SUCCESS; + auto status = BluetoothAudioStatus::SUCCESS; if (!bluetooth::headset::IsCallIdle()) { log::error("peer {} call in progress, do not start A2DP stream", peer_addr); - status = A2DP_CTRL_ACK_INCALL_FAILURE; + status = BluetoothAudioStatus::FAILURE; } /* just ack back a local start request, do not start the media encoder since * this is not for BTA_AV_START_EVT. */ @@ -102,14 +101,14 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, btif_a2dp_source_start_audio_req(); } if (p_av_start->initiator) { - bluetooth::audio::a2dp::ack_stream_started(A2DP_CTRL_ACK_SUCCESS); + bluetooth::audio::a2dp::ack_stream_started(BluetoothAudioStatus::SUCCESS); return true; } } } else if (p_av_start->initiator) { log::error("peer {} A2DP start request failed: status = {}", peer_addr, p_av_start->status); - bluetooth::audio::a2dp::ack_stream_started(A2DP_CTRL_ACK_FAILURE); + bluetooth::audio::a2dp::ack_stream_started(BluetoothAudioStatus::FAILURE); return true; } return false; @@ -164,22 +163,23 @@ void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend, void btif_a2dp_on_offload_started(const RawAddress& peer_addr, tBTA_AV_STATUS status) { - tA2DP_CTRL_ACK ack; + BluetoothAudioStatus ack; log::info("peer {} status {}", peer_addr, status); switch (status) { case BTA_AV_SUCCESS: - ack = A2DP_CTRL_ACK_SUCCESS; + ack = BluetoothAudioStatus::SUCCESS; break; case BTA_AV_FAIL_RESOURCES: log::error("peer {} FAILED UNSUPPORTED", peer_addr); - ack = A2DP_CTRL_ACK_UNSUPPORTED; + ack = BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION; break; default: log::error("peer {} FAILED: status = {}", peer_addr, status); - ack = A2DP_CTRL_ACK_FAILURE; + ack = BluetoothAudioStatus::FAILURE; break; } + if (btif_av_is_a2dp_offload_running()) { if (ack != BTA_AV_SUCCESS && btif_av_stream_started_ready(A2dpType::kSource)) { diff --git a/system/btif/src/btif_a2dp_sink.cc b/system/btif/src/btif_a2dp_sink.cc index ffa783cdab..c495eec39e 100644 --- a/system/btif/src/btif_a2dp_sink.cc +++ b/system/btif/src/btif_a2dp_sink.cc @@ -32,8 +32,9 @@ #include "btif/include/btif_av.h" #include "btif/include/btif_av_co.h" #include "btif/include/btif_avrcp_audio_track.h" -#include "btif/include/btif_util.h" // CASE_RETURN_STR +#include "btif/include/btif_util.h" // CASE_RETURN_STR #include "common/message_loop_thread.h" +#include "hardware/bt_av.h" #include "os/log.h" #include "osi/include/alarm.h" #include "osi/include/allocator.h" diff --git a/system/btif/src/btif_a2dp_source.cc b/system/btif/src/btif_a2dp_source.cc index eaff149fa4..c80dfb9ef3 100644 --- a/system/btif/src/btif_a2dp_source.cc +++ b/system/btif/src/btif_a2dp_source.cc @@ -53,6 +53,7 @@ #include "stack/include/bt_hdr.h" #include "types/raw_address.h" +using bluetooth::audio::a2dp::BluetoothAudioStatus; using bluetooth::common::A2dpSessionMetrics; using bluetooth::common::BluetoothMetricsLogger; using bluetooth::common::RepeatingTimer; @@ -719,10 +720,10 @@ void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) { log::error("A2DP stop failed: status={}, initiator={}", p_av_suspend->status, p_av_suspend->initiator); if (p_av_suspend->initiator) { - bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_FAILURE); + bluetooth::audio::a2dp::ack_stream_suspended(BluetoothAudioStatus::FAILURE); } } else { - bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_SUCCESS); + bluetooth::audio::a2dp::ack_stream_suspended(BluetoothAudioStatus::SUCCESS); return; } @@ -752,10 +753,10 @@ void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) { log::warn("A2DP suspend failed: status={}, initiator={}", p_av_suspend->status, p_av_suspend->initiator); if (p_av_suspend->initiator) { - bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_FAILURE); + bluetooth::audio::a2dp::ack_stream_suspended(BluetoothAudioStatus::FAILURE); } } else if (btif_av_is_a2dp_offload_running()) { - bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_SUCCESS); + bluetooth::audio::a2dp::ack_stream_suspended(BluetoothAudioStatus::SUCCESS); return; } @@ -838,7 +839,7 @@ static void btif_a2dp_source_audio_tx_stop_event(void) { btif_a2dp_source_cb.media_alarm.CancelAndWait(); wakelock_release(); - bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_SUCCESS); + bluetooth::audio::a2dp::ack_stream_suspended(BluetoothAudioStatus::SUCCESS); /* audio engine stopped, reset tx suspended flag */ btif_a2dp_source_cb.tx_flush = false; diff --git a/system/btif/src/btif_av.cc b/system/btif/src/btif_av.cc index 544ca4f4e7..70aba87587 100644 --- a/system/btif/src/btif_av.cc +++ b/system/btif/src/btif_av.cc @@ -2569,7 +2569,8 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event, log::error("Peer {} : cannot proceed to do AvStart", peer_.PeerAddress()); peer_.ClearFlags(BtifAvPeer::kFlagPendingStart); - bluetooth::audio::a2dp::ack_stream_started(A2DP_CTRL_ACK_FAILURE); + bluetooth::audio::a2dp::ack_stream_started( + bluetooth::audio::a2dp::BluetoothAudioStatus::FAILURE); } if (peer_.IsSink()) { btif_av_source_disconnect(peer_.PeerAddress()); diff --git a/system/test/mock/mock_audio_hal_interface_a2dp_encoding.cc b/system/test/mock/mock_audio_hal_interface_a2dp_encoding.cc index acde6d1a6f..237f8d6967 100644 --- a/system/test/mock/mock_audio_hal_interface_a2dp_encoding.cc +++ b/system/test/mock/mock_audio_hal_interface_a2dp_encoding.cc @@ -92,11 +92,11 @@ bool update_codec_offloading_capabilities::return_value = false; } // namespace test // Mocked functions, if any -void ack_stream_started(const tA2DP_CTRL_ACK& status) { +void ack_stream_started(BluetoothAudioStatus status) { inc_func_call_count(__func__); test::mock::audio_hal_interface_a2dp_encoding::ack_stream_started(status); } -void ack_stream_suspended(const tA2DP_CTRL_ACK& status) { +void ack_stream_suspended(BluetoothAudioStatus status) { inc_func_call_count(__func__); test::mock::audio_hal_interface_a2dp_encoding::ack_stream_suspended(status); } diff --git a/system/test/mock/mock_audio_hal_interface_a2dp_encoding.h b/system/test/mock/mock_audio_hal_interface_a2dp_encoding.h index da94f0ea43..e463ab4613 100644 --- a/system/test/mock/mock_audio_hal_interface_a2dp_encoding.h +++ b/system/test/mock/mock_audio_hal_interface_a2dp_encoding.h @@ -34,6 +34,7 @@ #include "audio_hal_interface/a2dp_encoding.h" // Original usings +using bluetooth::audio::a2dp::BluetoothAudioStatus; using bluetooth::audio::a2dp::provider::a2dp_configuration; using bluetooth::audio::a2dp::provider::a2dp_remote_capabilities; @@ -45,22 +46,20 @@ namespace audio_hal_interface_a2dp_encoding { // Shared state between mocked functions and tests // Name: ack_stream_started -// Params: const tA2DP_CTRL_ACK& status +// Params: BluetoothAudioStatus // Return: void struct ack_stream_started { - std::function<void(const tA2DP_CTRL_ACK& status)> body{ - [](const tA2DP_CTRL_ACK& /* status */) {}}; - void operator()(const tA2DP_CTRL_ACK& status) { body(status); }; + std::function<void(BluetoothAudioStatus status)> body{[](BluetoothAudioStatus /* status */) {}}; + void operator()(BluetoothAudioStatus status) { body(status); } }; extern struct ack_stream_started ack_stream_started; // Name: ack_stream_suspended -// Params: const tA2DP_CTRL_ACK& status +// Params: BluetoothAudioStatus // Return: void struct ack_stream_suspended { - std::function<void(const tA2DP_CTRL_ACK& status)> body{ - [](const tA2DP_CTRL_ACK& /* status */) {}}; - void operator()(const tA2DP_CTRL_ACK& status) { body(status); }; + std::function<void(BluetoothAudioStatus status)> body{[](BluetoothAudioStatus /* status */) {}}; + void operator()(BluetoothAudioStatus status) { body(status); } }; extern struct ack_stream_suspended ack_stream_suspended; |