From a80a851ada3b4973427879be859cdb7bc18f20c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ko=C5=82odziejczyk?= Date: Tue, 23 Feb 2021 11:53:08 +0000 Subject: [PATCH] audio: Implement OnSessionStarted for HAL 2.1 Patch implements OnSessionStarted for HAL 2.1. Bug: Tag: #feature Test: vts-tradefed run vts -m VtsHalBluetoothAudioV2_1TargetTest Sponsor: jpawlowski@ Change-Id: Ide76fe59c323726ae98e6311f7360eb733c1c7cc Change-Id: I84302cf653ffebcba3b4c875f6a156293d8dae75 --- .../utils/session/BluetoothAudioSession.h | 2 + .../session/BluetoothAudioSession_2_1.cpp | 58 ++++++++++++++++++- .../utils/session/BluetoothAudioSession_2_1.h | 12 ++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession.h b/bluetooth/audio/utils/session/BluetoothAudioSession.h index 8d02387d83..83e20ad588 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession.h +++ b/bluetooth/audio/utils/session/BluetoothAudioSession.h @@ -79,6 +79,8 @@ struct PortStatusCallbacks { }; class BluetoothAudioSession { + friend class BluetoothAudioSession_2_1; + private: // using recursive_mutex to allow hwbinder to re-enter agian. std::recursive_mutex mutex_; diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp index 9e1baf4f6e..4f7658fbe9 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp @@ -29,6 +29,11 @@ using SessionType_2_1 = using SessionType_2_0 = ::android::hardware::bluetooth::audio::V2_0::SessionType; +::android::hardware::bluetooth::audio::V2_1::AudioConfiguration + BluetoothAudioSession_2_1::invalidSoftwareAudioConfiguration = {}; +::android::hardware::bluetooth::audio::V2_1::AudioConfiguration + BluetoothAudioSession_2_1::invalidOffloadAudioConfiguration = {}; + namespace { bool is_2_0_session_type( const ::android::hardware::bluetooth::audio::V2_1::SessionType& @@ -60,6 +65,37 @@ BluetoothAudioSession_2_1::GetAudioSession() { return audio_session; } +bool BluetoothAudioSession_2_1::UpdateAudioConfig( + const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration& + audio_config) { + bool is_software_session = + (session_type_2_1_ == SessionType_2_1::A2DP_SOFTWARE_ENCODING_DATAPATH || + session_type_2_1_ == + SessionType_2_1::HEARING_AID_SOFTWARE_ENCODING_DATAPATH || + session_type_2_1_ == + SessionType_2_1::LE_AUDIO_SOFTWARE_ENCODING_DATAPATH || + session_type_2_1_ == + SessionType_2_1::LE_AUDIO_SOFTWARE_DECODED_DATAPATH); + bool is_offload_session = + (session_type_2_1_ == SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH); + auto audio_config_discriminator = audio_config.getDiscriminator(); + bool is_software_audio_config = + (is_software_session && + audio_config_discriminator == + ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration:: + hidl_discriminator::pcmConfig); + bool is_offload_audio_config = + (is_offload_session && + audio_config_discriminator == + ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration:: + hidl_discriminator::codecConfig); + if (!is_software_audio_config && !is_offload_audio_config) { + return false; + } + audio_config_2_1_ = audio_config; + return true; +} + // The report function is used to report that the Bluetooth stack has started // this session without any failure, and will invoke session_changed_cb_ to // notify those registered bluetooth_audio outputs @@ -86,7 +122,27 @@ void BluetoothAudioSession_2_1::OnSessionStarted( audio_session->OnSessionStarted(stack_iface, dataMQ, config); } else { - LOG(FATAL) << " Not implemented yet!!"; + std::lock_guard guard(audio_session->mutex_); + if (stack_iface == nullptr) { + LOG(ERROR) << __func__ << " - SessionType=" << toString(session_type_2_1_) + << ", IBluetoothAudioPort Invalid"; + } else if (!UpdateAudioConfig(audio_config)) { + LOG(ERROR) << __func__ << " - SessionType=" << toString(session_type_2_1_) + << ", AudioConfiguration=" << toString(audio_config) + << " Invalid"; + } else if (!audio_session->UpdateDataPath(dataMQ)) { + LOG(ERROR) << __func__ << " - SessionType=" << toString(session_type_2_1_) + << " DataMQ Invalid"; + audio_config_2_1_ = + (session_type_2_1_ == SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH + ? kInvalidOffloadAudioConfiguration + : kInvalidSoftwareAudioConfiguration); + } else { + audio_session->stack_iface_ = stack_iface; + LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_2_1_) + << ", AudioConfiguration=" << toString(audio_config); + audio_session->ReportSessionStatus(); + }; } } diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h index 0e9c12b849..927dfea013 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h @@ -40,6 +40,11 @@ class BluetoothAudioSession_2_1 { const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration& audio_config); + static ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration + invalidSoftwareAudioConfiguration; + static ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration + invalidOffloadAudioConfiguration; + public: BluetoothAudioSession_2_1( const ::android::hardware::bluetooth::audio::V2_1::SessionType& @@ -60,6 +65,13 @@ class BluetoothAudioSession_2_1 { // AudioConfiguration const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration& GetAudioConfig(); + + static constexpr ::android::hardware::bluetooth::audio::V2_1:: + AudioConfiguration& kInvalidSoftwareAudioConfiguration = + invalidSoftwareAudioConfiguration; + static constexpr ::android::hardware::bluetooth::audio::V2_1:: + AudioConfiguration& kInvalidOffloadAudioConfiguration = + invalidOffloadAudioConfiguration; }; class BluetoothAudioSessionInstance_2_1 {