diff --git a/bluetooth/audio/utils/session/BluetoothAudioSessionControl_2_1.h b/bluetooth/audio/utils/session/BluetoothAudioSessionControl_2_1.h index 168de488d7..4d7be21d7a 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSessionControl_2_1.h +++ b/bluetooth/audio/utils/session/BluetoothAudioSessionControl_2_1.h @@ -25,6 +25,8 @@ namespace audio { class BluetoothAudioSessionControl_2_1 { using SessionType_2_1 = ::android::hardware::bluetooth::audio::V2_1::SessionType; + using AudioConfiguration_2_1 = + ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration; public: // The control API helps to check if session is ready or not @@ -65,18 +67,17 @@ class BluetoothAudioSessionControl_2_1 { // The control API for the bluetooth_audio module to get current // AudioConfiguration - static const AudioConfiguration& GetAudioConfig( + static const AudioConfiguration_2_1 GetAudioConfig( const SessionType_2_1& session_type) { std::shared_ptr session_ptr = BluetoothAudioSessionInstance_2_1::GetSessionInstance(session_type); if (session_ptr != nullptr) { - // TODO: map 2.1 to 2.0 audio config inside GetAudioConfig? - return session_ptr->GetAudioSession()->GetAudioConfig(); + return session_ptr->GetAudioConfig(); } else if (session_type == SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH) { - return BluetoothAudioSession::kInvalidOffloadAudioConfiguration; + return BluetoothAudioSession_2_1::kInvalidOffloadAudioConfiguration; } else { - return BluetoothAudioSession::kInvalidSoftwareAudioConfiguration; + return BluetoothAudioSession_2_1::kInvalidSoftwareAudioConfiguration; } } diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp index 4f7658fbe9..9d91196d4d 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp @@ -65,6 +65,40 @@ BluetoothAudioSession_2_1::GetAudioSession() { return audio_session; } +// The control function is for the bluetooth_audio module to get the current +// AudioConfiguration +const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration +BluetoothAudioSession_2_1::GetAudioConfig() { + std::lock_guard guard(audio_session->mutex_); + if (audio_session->IsSessionReady()) { + // If session is unknown it means it should be 2.0 type + if (session_type_2_1_ != SessionType_2_1::UNKNOWN) + return audio_config_2_1_; + + ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration toConf; + const AudioConfiguration fromConf = GetAudioSession()->GetAudioConfig(); + // pcmConfig only differs between 2.0 and 2.1 in AudioConfiguration + if (fromConf.getDiscriminator() == + AudioConfiguration::hidl_discriminator::codecConfig) { + toConf.codecConfig() = fromConf.codecConfig(); + } else { + toConf.pcmConfig() = { + .sampleRate = static_cast< + ::android::hardware::bluetooth::audio::V2_1::SampleRate>( + fromConf.pcmConfig().sampleRate), + .channelMode = fromConf.pcmConfig().channelMode, + .bitsPerSample = fromConf.pcmConfig().bitsPerSample, + .dataIntervalUs = 0}; + } + return toConf; + } else if (session_type_2_1_ == + SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH) { + return kInvalidOffloadAudioConfiguration; + } else { + return kInvalidSoftwareAudioConfiguration; + } +} + bool BluetoothAudioSession_2_1::UpdateAudioConfig( const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration& audio_config) { diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h index 927dfea013..5a351531a3 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h @@ -63,7 +63,7 @@ class BluetoothAudioSession_2_1 { // The control function is for the bluetooth_audio module to get the current // AudioConfiguration - const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration& + const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration GetAudioConfig(); static constexpr ::android::hardware::bluetooth::audio::V2_1::