Merge "Add support LE audio offload for HIDL 2.2" am: d2645ae70c am: 5513c4351b

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1927137

Change-Id: I80e64f02bced5e5e56c72416d024b63acaeb56ba
This commit is contained in:
Treehugger Robot
2021-12-20 14:44:13 +00:00
committed by Automerger Merge Worker
12 changed files with 87 additions and 15 deletions

View File

@@ -157,7 +157,11 @@ Return<void> BluetoothAudioProvidersFactory::getProviderCapabilities_2_1(
audio_capabilities[i].codecCapabilities(db_codec_capabilities[i]); audio_capabilities[i].codecCapabilities(db_codec_capabilities[i]);
} }
} }
} else if (sessionType != SessionType::UNKNOWN) { } else if (sessionType !=
SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH &&
sessionType !=
SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH &&
sessionType != SessionType::UNKNOWN) {
std::vector<PcmParameters> db_pcm_capabilities = std::vector<PcmParameters> db_pcm_capabilities =
android::bluetooth::audio::GetSoftwarePcmCapabilities_2_1(); android::bluetooth::audio::GetSoftwarePcmCapabilities_2_1();
if (db_pcm_capabilities.size() == 1) { if (db_pcm_capabilities.size() == 1) {

View File

@@ -21,7 +21,7 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include "BluetoothAudioSessionReport_2_2.h" #include "BluetoothAudioSessionReport_2_2.h"
#include "BluetoothAudioSupportedCodecsDB_2_1.h" #include "BluetoothAudioSupportedCodecsDB_2_2.h"
namespace android { namespace android {
namespace hardware { namespace hardware {

View File

@@ -22,7 +22,7 @@
#include "AudioPort_2_0_to_2_2_Wrapper.h" #include "AudioPort_2_0_to_2_2_Wrapper.h"
#include "BluetoothAudioSessionReport_2_2.h" #include "BluetoothAudioSessionReport_2_2.h"
#include "BluetoothAudioSupportedCodecsDB_2_1.h" #include "BluetoothAudioSupportedCodecsDB_2_2.h"
namespace android { namespace android {
namespace hardware { namespace hardware {

View File

@@ -20,7 +20,7 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include "BluetoothAudioSupportedCodecsDB_2_1.h" #include "BluetoothAudioSupportedCodecsDB_2_2.h"
namespace android { namespace android {
namespace hardware { namespace hardware {

View File

@@ -21,7 +21,7 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include "BluetoothAudioSessionReport_2_2.h" #include "BluetoothAudioSessionReport_2_2.h"
#include "BluetoothAudioSupportedCodecsDB_2_1.h" #include "BluetoothAudioSupportedCodecsDB_2_2.h"
namespace android { namespace android {
namespace hardware { namespace hardware {

View File

@@ -22,7 +22,7 @@
#include "AudioPort_2_0_to_2_2_Wrapper.h" #include "AudioPort_2_0_to_2_2_Wrapper.h"
#include "BluetoothAudioSessionReport_2_2.h" #include "BluetoothAudioSessionReport_2_2.h"
#include "BluetoothAudioSupportedCodecsDB_2_1.h" #include "BluetoothAudioSupportedCodecsDB_2_2.h"
namespace android { namespace android {
namespace hardware { namespace hardware {

View File

@@ -22,7 +22,6 @@
#include "AudioPort_2_0_to_2_2_Wrapper.h" #include "AudioPort_2_0_to_2_2_Wrapper.h"
#include "BluetoothAudioSessionReport_2_2.h" #include "BluetoothAudioSessionReport_2_2.h"
#include "BluetoothAudioSupportedCodecsDB_2_1.h"
#include "BluetoothAudioSupportedCodecsDB_2_2.h" #include "BluetoothAudioSupportedCodecsDB_2_2.h"
namespace android { namespace android {

View File

@@ -87,7 +87,7 @@ class BluetoothAudioSessionControl_2_2 {
std::shared_ptr<BluetoothAudioSession_2_2> session_ptr = std::shared_ptr<BluetoothAudioSession_2_2> session_ptr =
BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type); BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type);
if (session_ptr != nullptr) { if (session_ptr != nullptr) {
return session_ptr->GetAudioSession()->StartStream(); return session_ptr->StartStream();
} }
return false; return false;
} }
@@ -96,7 +96,7 @@ class BluetoothAudioSessionControl_2_2 {
std::shared_ptr<BluetoothAudioSession_2_2> session_ptr = std::shared_ptr<BluetoothAudioSession_2_2> session_ptr =
BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type); BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type);
if (session_ptr != nullptr) { if (session_ptr != nullptr) {
return session_ptr->GetAudioSession()->SuspendStream(); return session_ptr->SuspendStream();
} }
return false; return false;
} }
@@ -105,7 +105,7 @@ class BluetoothAudioSessionControl_2_2 {
std::shared_ptr<BluetoothAudioSession_2_2> session_ptr = std::shared_ptr<BluetoothAudioSession_2_2> session_ptr =
BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type); BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type);
if (session_ptr != nullptr) { if (session_ptr != nullptr) {
session_ptr->GetAudioSession()->StopStream(); session_ptr->StopStream();
} }
} }

View File

@@ -46,6 +46,19 @@ bool is_2_0_session_type(
return false; return false;
} }
} }
bool is_unsupported_2_1_session_type(
const ::android::hardware::bluetooth::audio::V2_1::SessionType&
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 true;
} else {
return false;
}
}
} // namespace } // namespace
BluetoothAudioSession_2_1::BluetoothAudioSession_2_1( BluetoothAudioSession_2_1::BluetoothAudioSession_2_1(
@@ -53,7 +66,8 @@ BluetoothAudioSession_2_1::BluetoothAudioSession_2_1(
session_type) session_type)
: audio_session(BluetoothAudioSessionInstance::GetSessionInstance( : audio_session(BluetoothAudioSessionInstance::GetSessionInstance(
static_cast<SessionType_2_0>(session_type))) { static_cast<SessionType_2_0>(session_type))) {
if (is_2_0_session_type(session_type)) { if (is_2_0_session_type(session_type) ||
is_unsupported_2_1_session_type(session_type)) {
session_type_2_1_ = (SessionType_2_1::UNKNOWN); session_type_2_1_ = (SessionType_2_1::UNKNOWN);
} else { } else {
session_type_2_1_ = (session_type); session_type_2_1_ = (session_type);
@@ -80,7 +94,7 @@ BluetoothAudioSession_2_1::GetAudioConfig() {
// pcmConfig only differs between 2.0 and 2.1 in AudioConfiguration // pcmConfig only differs between 2.0 and 2.1 in AudioConfiguration
if (fromConf.getDiscriminator() == if (fromConf.getDiscriminator() ==
AudioConfiguration::hidl_discriminator::codecConfig) { AudioConfiguration::hidl_discriminator::codecConfig) {
toConf.codecConfig() = fromConf.codecConfig(); toConf.codecConfig(fromConf.codecConfig());
} else { } else {
toConf.pcmConfig() = { toConf.pcmConfig() = {
.sampleRate = static_cast< .sampleRate = static_cast<

View File

@@ -76,7 +76,9 @@ BluetoothAudioSession_2_2::BluetoothAudioSession_2_2(
bool BluetoothAudioSession_2_2::IsSessionReady() { bool BluetoothAudioSession_2_2::IsSessionReady() {
if (session_type_2_1_ != if (session_type_2_1_ !=
SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH) { SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH &&
session_type_2_1_ !=
SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH) {
return audio_session->IsSessionReady(); return audio_session->IsSessionReady();
} }
@@ -157,7 +159,7 @@ BluetoothAudioSession_2_2::GetAudioConfig() {
GetAudioSession_2_1()->GetAudioConfig(); GetAudioSession_2_1()->GetAudioConfig();
if (fromConf.getDiscriminator() == if (fromConf.getDiscriminator() ==
AudioConfiguration_2_1::hidl_discriminator::pcmConfig) { AudioConfiguration_2_1::hidl_discriminator::pcmConfig) {
toConf.pcmConfig() = fromConf.pcmConfig(); toConf.pcmConfig(fromConf.pcmConfig());
return toConf; return toConf;
} }
} }
@@ -167,7 +169,7 @@ BluetoothAudioSession_2_2::GetAudioConfig() {
// pcmConfig only differs between 2.0 and 2.1 in AudioConfiguration // pcmConfig only differs between 2.0 and 2.1 in AudioConfiguration
if (fromConf.getDiscriminator() == if (fromConf.getDiscriminator() ==
AudioConfiguration::hidl_discriminator::codecConfig) { AudioConfiguration::hidl_discriminator::codecConfig) {
toConf.codecConfig() = fromConf.codecConfig(); toConf.codecConfig(fromConf.codecConfig());
} else { } else {
toConf.pcmConfig() = { toConf.pcmConfig() = {
.sampleRate = static_cast< .sampleRate = static_cast<
@@ -186,6 +188,52 @@ 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() {
std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_);
if (!IsSessionReady()) {
LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_2_1_)
<< " has NO session";
return false;
}
auto hal_retval = audio_session->stack_iface_->startStream();
if (!hal_retval.isOk()) {
LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType="
<< toString(session_type_2_1_) << " failed";
return false;
}
return true;
}
bool BluetoothAudioSession_2_2::SuspendStream() {
std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_);
if (!IsSessionReady()) {
LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_2_1_)
<< " has NO session";
return false;
}
auto hal_retval = audio_session->stack_iface_->suspendStream();
if (!hal_retval.isOk()) {
LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType="
<< toString(session_type_2_1_) << " failed";
return false;
}
return true;
}
void BluetoothAudioSession_2_2::StopStream() {
std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_);
if (!IsSessionReady()) {
return;
}
auto hal_retval = audio_session->stack_iface_->stopStream();
if (!hal_retval.isOk()) {
LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType="
<< toString(session_type_2_1_) << " failed";
}
}
bool BluetoothAudioSession_2_2::UpdateAudioConfig( bool BluetoothAudioSession_2_2::UpdateAudioConfig(
const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration& const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration&
audio_config) { audio_config) {

View File

@@ -69,6 +69,12 @@ class BluetoothAudioSession_2_2 {
const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration& const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration&
audio_config); audio_config);
// Those control functions are for the bluetooth_audio module to start,
// suspend, stop stream, to check position, and to update metadata.
bool StartStream();
bool SuspendStream();
void StopStream();
// The control function is for the bluetooth_audio module to get the current // The control function is for the bluetooth_audio module to get the current
// AudioConfiguration // AudioConfiguration
const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration

View File

@@ -19,6 +19,7 @@
#include <android/hardware/bluetooth/audio/2.2/types.h> #include <android/hardware/bluetooth/audio/2.2/types.h>
#include "BluetoothAudioSupportedCodecsDB.h" #include "BluetoothAudioSupportedCodecsDB.h"
#include "BluetoothAudioSupportedCodecsDB_2_1.h"
namespace android { namespace android {
namespace bluetooth { namespace bluetooth {