diff options
Diffstat (limited to 'bluetooth/audio/utils/session')
7 files changed, 98 insertions, 29 deletions
diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession.cpp b/bluetooth/audio/utils/session/BluetoothAudioSession.cpp index 2f3ddaf213..6d5608b0a4 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession.cpp +++ b/bluetooth/audio/utils/session/BluetoothAudioSession.cpp @@ -21,10 +21,13 @@ #include <android-base/logging.h> #include <android-base/stringprintf.h> +#include "../aidl_session/HidlToAidlMiddleware_2_0.h" + namespace android { namespace bluetooth { namespace audio { +using ::aidl::android::hardware::bluetooth::audio::HidlToAidlMiddleware_2_0; using ::android::hardware::audio::common::V5_0::AudioContentType; using ::android::hardware::audio::common::V5_0::AudioUsage; using ::android::hardware::audio::common::V5_0::PlaybackTrackMetadata; @@ -149,6 +152,8 @@ void BluetoothAudioSession::ReportControlStatus( // The function helps to check if this session is ready or not // @return: true if the Bluetooth stack has started the specified session bool BluetoothAudioSession::IsSessionReady() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::IsSessionReady(session_type_); std::lock_guard<std::recursive_mutex> guard(mutex_); bool dataMQ_valid = (session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DATAPATH || @@ -200,6 +205,9 @@ bool BluetoothAudioSession::UpdateAudioConfig( // @return: cookie - the assigned number to this bluetooth_audio output uint16_t BluetoothAudioSession::RegisterStatusCback( const PortStatusCallbacks& cbacks) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::RegisterControlResultCback(session_type_, + cbacks); std::lock_guard<std::recursive_mutex> guard(mutex_); uint16_t cookie = ObserversCookieGetInitValue(session_type_); uint16_t cookie_upper_bound = ObserversCookieGetUpperBound(session_type_); @@ -227,6 +235,9 @@ uint16_t BluetoothAudioSession::RegisterStatusCback( // PortStatusCallbacks // @param: cookie - indicates which bluetooth_audio output is void BluetoothAudioSession::UnregisterStatusCback(uint16_t cookie) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::UnregisterControlResultCback(session_type_, + cookie); std::lock_guard<std::recursive_mutex> guard(mutex_); if (observers_.erase(cookie) != 1) { LOG(WARNING) << __func__ << " - SessionType=" << toString(session_type_) @@ -238,6 +249,9 @@ void BluetoothAudioSession::UnregisterStatusCback(uint16_t cookie) { // The control function is for the bluetooth_audio module to get the current // AudioConfiguration const AudioConfiguration& BluetoothAudioSession::GetAudioConfig() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return (audio_config_ = + HidlToAidlMiddleware_2_0::GetAudioConfig(session_type_)); std::lock_guard<std::recursive_mutex> guard(mutex_); if (IsSessionReady()) { return audio_config_; @@ -251,6 +265,8 @@ const AudioConfiguration& BluetoothAudioSession::GetAudioConfig() { // Those control functions are for the bluetooth_audio module to start, suspend, // stop stream, to check position, and to update metadata. bool BluetoothAudioSession::StartStream() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::StartStream(session_type_); std::lock_guard<std::recursive_mutex> guard(mutex_); if (!IsSessionReady()) { LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) @@ -267,6 +283,8 @@ bool BluetoothAudioSession::StartStream() { } bool BluetoothAudioSession::SuspendStream() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::SuspendStream(session_type_); std::lock_guard<std::recursive_mutex> guard(mutex_); if (!IsSessionReady()) { LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) @@ -283,6 +301,8 @@ bool BluetoothAudioSession::SuspendStream() { } void BluetoothAudioSession::StopStream() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::StopStream(session_type_); std::lock_guard<std::recursive_mutex> guard(mutex_); if (!IsSessionReady()) { return; @@ -297,6 +317,10 @@ void BluetoothAudioSession::StopStream() { bool BluetoothAudioSession::GetPresentationPosition( uint64_t* remote_delay_report_ns, uint64_t* total_bytes_readed, timespec* data_position) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::GetPresentationPosition( + session_type_, remote_delay_report_ns, total_bytes_readed, + data_position); std::lock_guard<std::recursive_mutex> guard(mutex_); if (!IsSessionReady()) { LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) @@ -330,6 +354,9 @@ bool BluetoothAudioSession::GetPresentationPosition( void BluetoothAudioSession::UpdateTracksMetadata( const struct source_metadata* source_metadata) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::UpdateTracksMetadata(session_type_, + source_metadata); std::lock_guard<std::recursive_mutex> guard(mutex_); if (!IsSessionReady()) { LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) @@ -374,6 +401,9 @@ void BluetoothAudioSession::UpdateTracksMetadata( // The control function writes stream to FMQ size_t BluetoothAudioSession::OutWritePcmData(const void* buffer, size_t bytes) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::OutWritePcmData(session_type_, buffer, + bytes); if (buffer == nullptr || !bytes) return 0; size_t totalWritten = 0; int ms_timeout = kFmqSendTimeoutMs; diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp index bf1f9b5b2a..276a291470 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.cpp @@ -21,9 +21,14 @@ #include <android-base/logging.h> #include <android-base/stringprintf.h> +#include "../aidl_session/HidlToAidlMiddleware_2_0.h" +#include "../aidl_session/HidlToAidlMiddleware_2_1.h" + namespace android { namespace bluetooth { namespace audio { +using ::aidl::android::hardware::bluetooth::audio::HidlToAidlMiddleware_2_0; +using ::aidl::android::hardware::bluetooth::audio::HidlToAidlMiddleware_2_1; using SessionType_2_1 = ::android::hardware::bluetooth::audio::V2_1::SessionType; using SessionType_2_0 = @@ -72,6 +77,7 @@ BluetoothAudioSession_2_1::BluetoothAudioSession_2_1( } else { session_type_2_1_ = (session_type); } + raw_session_type_ = session_type; } std::shared_ptr<BluetoothAudioSession> @@ -83,6 +89,8 @@ BluetoothAudioSession_2_1::GetAudioSession() { // AudioConfiguration const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration BluetoothAudioSession_2_1::GetAudioConfig() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_1::GetAudioConfig(raw_session_type_); std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_); if (audio_session->IsSessionReady()) { // If session is unknown it means it should be 2.0 type diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h index 5a351531a3..e6340649d8 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_1.h @@ -31,6 +31,7 @@ class BluetoothAudioSession_2_1 { std::shared_ptr<BluetoothAudioSession> audio_session; ::android::hardware::bluetooth::audio::V2_1::SessionType session_type_2_1_; + ::android::hardware::bluetooth::audio::V2_1::SessionType raw_session_type_; // audio data configuration for both software and offloading ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.cpp b/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.cpp index 60ac4ece6f..4613ddc05a 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.cpp +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.cpp @@ -22,10 +22,15 @@ #include <android-base/stringprintf.h> #include <android/hardware/bluetooth/audio/2.2/IBluetoothAudioPort.h> +#include "../aidl_session/HidlToAidlMiddleware_2_0.h" +#include "../aidl_session/HidlToAidlMiddleware_2_2.h" + namespace android { namespace bluetooth { namespace audio { +using ::aidl::android::hardware::bluetooth::audio::HidlToAidlMiddleware_2_0; +using ::aidl::android::hardware::bluetooth::audio::HidlToAidlMiddleware_2_2; using ::android::hardware::audio::common::V5_0::AudioSource; using ::android::hardware::audio::common::V5_0::RecordTrackMetadata; using ::android::hardware::audio::common::V5_0::SinkMetadata; @@ -93,6 +98,7 @@ BluetoothAudioSession_2_2::BluetoothAudioSession_2_2( } else { session_type_2_1_ = (session_type); } + raw_session_type_ = session_type; invalidSoftwareAudioConfiguration.pcmConfig(kInvalidPcmParameters); invalidOffloadAudioConfiguration.codecConfig( audio_session->kInvalidCodecConfiguration); @@ -100,6 +106,8 @@ BluetoothAudioSession_2_2::BluetoothAudioSession_2_2( } bool BluetoothAudioSession_2_2::IsSessionReady() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_2::IsSessionReady(raw_session_type_); if (session_type_2_1_ != SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH && session_type_2_1_ != @@ -122,6 +130,9 @@ BluetoothAudioSession_2_2::GetAudioSession_2_1() { void BluetoothAudioSession_2_2::UpdateSinkMetadata( const struct sink_metadata* sink_metadata) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_2::UpdateSinkMetadata(raw_session_type_, + sink_metadata); std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_); if (!IsSessionReady()) { LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_2_1_) @@ -172,6 +183,8 @@ void BluetoothAudioSession_2_2::UpdateSinkMetadata( // AudioConfiguration const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration BluetoothAudioSession_2_2::GetAudioConfig() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_2::GetAudioConfig(raw_session_type_); std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_); if (IsSessionReady()) { auto audio_config_discriminator = audio_config_2_2_.getDiscriminator(); @@ -226,6 +239,8 @@ BluetoothAudioSession_2_2::GetAudioConfig() { // Those control functions are for the bluetooth_audio module to start, suspend, // stop stream, to check position, and to update metadata. bool BluetoothAudioSession_2_2::StartStream() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_2::StartStream(raw_session_type_); std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_); if (!IsSessionReady()) { LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_2_1_) @@ -242,6 +257,8 @@ bool BluetoothAudioSession_2_2::StartStream() { } bool BluetoothAudioSession_2_2::SuspendStream() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_2::SuspendStream(raw_session_type_); std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_); if (!IsSessionReady()) { LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_2_1_) @@ -258,6 +275,8 @@ bool BluetoothAudioSession_2_2::SuspendStream() { } void BluetoothAudioSession_2_2::StopStream() { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_2::StopStream(raw_session_type_); std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_); if (!IsSessionReady()) { return; @@ -395,6 +414,9 @@ void BluetoothAudioSession_2_2::OnSessionEnded() { // @return: cookie - the assigned number to this bluetooth_audio output uint16_t BluetoothAudioSession_2_2::RegisterStatusCback( const PortStatusCallbacks_2_2& cbacks) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_2::RegisterControlResultCback( + raw_session_type_, cbacks); if (session_type_2_1_ != SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH && session_type_2_1_ != @@ -432,6 +454,9 @@ uint16_t BluetoothAudioSession_2_2::RegisterStatusCback( // PortStatusCallbacks_2_2 // @param: cookie - indicates which bluetooth_audio output is void BluetoothAudioSession_2_2::UnregisterStatusCback(uint16_t cookie) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_2::UnregisterControlResultCback( + raw_session_type_, cookie); std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_); if (session_type_2_1_ != SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH && diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.h b/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.h index 3673fd8ccf..b6f96ab25c 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.h +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.h @@ -68,6 +68,7 @@ class BluetoothAudioSession_2_2 { std::shared_ptr<BluetoothAudioSession_2_1> audio_session_2_1; ::android::hardware::bluetooth::audio::V2_1::SessionType session_type_2_1_; + ::android::hardware::bluetooth::audio::V2_1::SessionType raw_session_type_; // audio data configuration for both software and offloading ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration diff --git a/bluetooth/audio/utils/session/BluetoothAudioSupportedCodecsDB_2_2.cpp b/bluetooth/audio/utils/session/BluetoothAudioSupportedCodecsDB_2_2.cpp index 34cfd7efb7..4c99b0f620 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSupportedCodecsDB_2_2.cpp +++ b/bluetooth/audio/utils/session/BluetoothAudioSupportedCodecsDB_2_2.cpp @@ -30,16 +30,20 @@ using ::android::hardware::bluetooth::audio::V2_1::Lc3FrameDuration; using ::android::hardware::bluetooth::audio::V2_1::Lc3Parameters; using ::android::hardware::bluetooth::audio::V2_1::SampleRate; using ::android::hardware::bluetooth::audio::V2_2::AudioLocation; -using ::android::hardware::bluetooth::audio::V2_2::LeAudioCodecCapabilitiesPair; -using ::android::hardware::bluetooth::audio::V2_2::LeAudioCodecCapability; -using ::android::hardware::bluetooth::audio::V2_2::LeAudioMode; +using ::android::hardware::bluetooth::audio::V2_2::BroadcastCapability; +using ::android::hardware::bluetooth::audio::V2_2:: + LeAudioCodecCapabilitiesSetting; +using ::android::hardware::bluetooth::audio::V2_2::UnicastCapability; using SessionType_2_1 = ::android::hardware::bluetooth::audio::V2_1::SessionType; // Stores the list of offload supported capability -std::vector<LeAudioCodecCapabilitiesPair> kDefaultOffloadLeAudioCapabilities; +std::vector<LeAudioCodecCapabilitiesSetting> kDefaultOffloadLeAudioCapabilities; -static const LeAudioCodecCapability kInvalidLc3Capability = { +static const UnicastCapability kInvalidUnicastCapability = { + .codecType = CodecType::UNKNOWN}; + +static const BroadcastCapability kInvalidBroadcastCapability = { .codecType = CodecType::UNKNOWN}; // Default Supported Codecs @@ -94,53 +98,53 @@ bool IsOffloadLeAudioConfigurationValid( return true; } -LeAudioCodecCapability composeLc3Capability(AudioLocation audioLocation, - uint8_t deviceCnt, - uint8_t channelCount, - Lc3Parameters capability) { - return LeAudioCodecCapability{.codecType = CodecType::LC3, - .supportedChannel = audioLocation, - .deviceCount = deviceCnt, - .channelCountPerDevice = channelCount, - .capabilities = capability}; +UnicastCapability composeUnicastLc3Capability(AudioLocation audioLocation, + uint8_t deviceCnt, + uint8_t channelCount, + Lc3Parameters capability) { + return UnicastCapability{.codecType = CodecType::LC3, + .supportedChannel = audioLocation, + .deviceCount = deviceCnt, + .channelCountPerDevice = channelCount, + .capabilities = capability}; } -std::vector<LeAudioCodecCapabilitiesPair> GetLeAudioOffloadCodecCapabilities( +std::vector<LeAudioCodecCapabilitiesSetting> GetLeAudioOffloadCodecCapabilities( const SessionType_2_1& session_type) { if (session_type != SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH && session_type != SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH) { - return std::vector<LeAudioCodecCapabilitiesPair>(0); + return std::vector<LeAudioCodecCapabilitiesSetting>(0); } if (kDefaultOffloadLeAudioCapabilities.empty()) { for (auto [audioLocation, deviceCnt, channelCount] : supportedDeviceSetting) { for (auto capability : supportedLc3CapabilityList) { - LeAudioCodecCapability lc3Capability = composeLc3Capability( + UnicastCapability lc3Capability = composeUnicastLc3Capability( audioLocation, deviceCnt, channelCount, capability); - LeAudioCodecCapability lc3MonoCapability = - composeLc3Capability(monoAudio, 1, 1, capability); + UnicastCapability lc3MonoDecodeCapability = + composeUnicastLc3Capability(monoAudio, 1, 1, capability); // Adds the capability for encode only kDefaultOffloadLeAudioCapabilities.push_back( - {.mode = LeAudioMode::UNICAST, - .encodeCapability = lc3Capability, - .decodeCapability = kInvalidLc3Capability}); + {.unicastEncodeCapability = lc3Capability, + .unicastDecodeCapability = kInvalidUnicastCapability, + .broadcastCapability = kInvalidBroadcastCapability}); // Adds the capability for decode only kDefaultOffloadLeAudioCapabilities.push_back( - {.mode = LeAudioMode::UNICAST, - .encodeCapability = kInvalidLc3Capability, - .decodeCapability = lc3Capability}); + {.unicastEncodeCapability = kInvalidUnicastCapability, + .unicastDecodeCapability = lc3Capability, + .broadcastCapability = kInvalidBroadcastCapability}); // Adds the capability for the case that encode and decode exist at the // same time kDefaultOffloadLeAudioCapabilities.push_back( - {.mode = LeAudioMode::UNICAST, - .encodeCapability = lc3Capability, - .decodeCapability = lc3MonoCapability}); + {.unicastEncodeCapability = lc3Capability, + .unicastDecodeCapability = lc3MonoDecodeCapability, + .broadcastCapability = kInvalidBroadcastCapability}); } } } diff --git a/bluetooth/audio/utils/session/BluetoothAudioSupportedCodecsDB_2_2.h b/bluetooth/audio/utils/session/BluetoothAudioSupportedCodecsDB_2_2.h index 89da6a383f..34bba5f671 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSupportedCodecsDB_2_2.h +++ b/bluetooth/audio/utils/session/BluetoothAudioSupportedCodecsDB_2_2.h @@ -31,7 +31,7 @@ bool IsOffloadLeAudioConfigurationValid( const ::android::hardware::bluetooth::audio::V2_2::LeAudioConfiguration& le_audio_codec_config); -std::vector<hardware::bluetooth::audio::V2_2::LeAudioCodecCapabilitiesPair> +std::vector<hardware::bluetooth::audio::V2_2::LeAudioCodecCapabilitiesSetting> GetLeAudioOffloadCodecCapabilities( const ::android::hardware::bluetooth::audio::V2_1::SessionType& session_type); |