mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Merge "SpatialAudio: Export LatencyMode functions to BluetoothAudioSession"
This commit is contained in:
@@ -39,9 +39,7 @@ bool A2dpOffloadAudioProvider::isValid(const SessionType& session_type) {
|
||||
ndk::ScopedAStatus A2dpOffloadAudioProvider::startSession(
|
||||
const std::shared_ptr<IBluetoothAudioPort>& host_if,
|
||||
const AudioConfiguration& audio_config,
|
||||
const std::vector<LatencyMode>& latency_modes,
|
||||
DataMQDesc* _aidl_return) {
|
||||
latency_modes_ = latency_modes;
|
||||
const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) {
|
||||
if (audio_config.getTag() != AudioConfiguration::a2dpConfig) {
|
||||
LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
|
||||
<< audio_config.toString();
|
||||
@@ -62,8 +60,8 @@ ndk::ScopedAStatus A2dpOffloadAudioProvider::startSession(
|
||||
ndk::ScopedAStatus A2dpOffloadAudioProvider::onSessionReady(
|
||||
DataMQDesc* _aidl_return) {
|
||||
*_aidl_return = DataMQDesc();
|
||||
BluetoothAudioSessionReport::OnSessionStarted(session_type_, stack_iface_,
|
||||
nullptr, *audio_config_);
|
||||
BluetoothAudioSessionReport::OnSessionStarted(
|
||||
session_type_, stack_iface_, nullptr, *audio_config_, latency_modes_);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
@@ -71,4 +69,4 @@ ndk::ScopedAStatus A2dpOffloadAudioProvider::onSessionReady(
|
||||
} // namespace bluetooth
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace aidl
|
||||
|
||||
@@ -62,9 +62,7 @@ bool A2dpSoftwareAudioProvider::isValid(const SessionType& sessionType) {
|
||||
ndk::ScopedAStatus A2dpSoftwareAudioProvider::startSession(
|
||||
const std::shared_ptr<IBluetoothAudioPort>& host_if,
|
||||
const AudioConfiguration& audio_config,
|
||||
const std::vector<LatencyMode>& latency_modes,
|
||||
DataMQDesc* _aidl_return) {
|
||||
latency_modes_ = latency_modes;
|
||||
const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) {
|
||||
if (audio_config.getTag() != AudioConfiguration::pcmConfig) {
|
||||
LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
|
||||
<< audio_config.toString();
|
||||
@@ -92,8 +90,8 @@ ndk::ScopedAStatus A2dpSoftwareAudioProvider::onSessionReady(
|
||||
}
|
||||
*_aidl_return = data_mq_->dupeDesc();
|
||||
auto desc = data_mq_->dupeDesc();
|
||||
BluetoothAudioSessionReport::OnSessionStarted(session_type_, stack_iface_,
|
||||
&desc, *audio_config_);
|
||||
BluetoothAudioSessionReport::OnSessionStarted(
|
||||
session_type_, stack_iface_, &desc, *audio_config_, latency_modes_);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
@@ -101,4 +99,4 @@ ndk::ScopedAStatus A2dpSoftwareAudioProvider::onSessionReady(
|
||||
} // namespace bluetooth
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace aidl
|
||||
|
||||
@@ -68,4 +68,4 @@ class BluetoothAudioProvider : public BnBluetoothAudioProvider {
|
||||
} // namespace bluetooth
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace aidl
|
||||
|
||||
@@ -57,9 +57,7 @@ bool HearingAidAudioProvider::isValid(const SessionType& sessionType) {
|
||||
ndk::ScopedAStatus HearingAidAudioProvider::startSession(
|
||||
const std::shared_ptr<IBluetoothAudioPort>& host_if,
|
||||
const AudioConfiguration& audio_config,
|
||||
const std::vector<LatencyMode>& latency_modes,
|
||||
DataMQDesc* _aidl_return) {
|
||||
latency_modes_ = latency_modes;
|
||||
const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) {
|
||||
if (audio_config.getTag() != AudioConfiguration::pcmConfig) {
|
||||
LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
|
||||
<< audio_config.toString();
|
||||
@@ -86,8 +84,8 @@ ndk::ScopedAStatus HearingAidAudioProvider::onSessionReady(
|
||||
}
|
||||
*_aidl_return = data_mq_->dupeDesc();
|
||||
auto desc = data_mq_->dupeDesc();
|
||||
BluetoothAudioSessionReport::OnSessionStarted(session_type_, stack_iface_,
|
||||
&desc, *audio_config_);
|
||||
BluetoothAudioSessionReport::OnSessionStarted(
|
||||
session_type_, stack_iface_, &desc, *audio_config_, latency_modes_);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
@@ -95,4 +93,4 @@ ndk::ScopedAStatus HearingAidAudioProvider::onSessionReady(
|
||||
} // namespace bluetooth
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace aidl
|
||||
|
||||
@@ -54,9 +54,7 @@ bool LeAudioOffloadAudioProvider::isValid(const SessionType& sessionType) {
|
||||
ndk::ScopedAStatus LeAudioOffloadAudioProvider::startSession(
|
||||
const std::shared_ptr<IBluetoothAudioPort>& host_if,
|
||||
const AudioConfiguration& audio_config,
|
||||
const std::vector<LatencyMode>& latency_modes,
|
||||
DataMQDesc* _aidl_return) {
|
||||
latency_modes_ = latency_modes;
|
||||
const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) {
|
||||
if (audio_config.getTag() != AudioConfiguration::leAudioConfig) {
|
||||
LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
|
||||
<< audio_config.toString();
|
||||
@@ -79,8 +77,8 @@ ndk::ScopedAStatus LeAudioOffloadAudioProvider::startSession(
|
||||
|
||||
ndk::ScopedAStatus LeAudioOffloadAudioProvider::onSessionReady(
|
||||
DataMQDesc* _aidl_return) {
|
||||
BluetoothAudioSessionReport::OnSessionStarted(session_type_, stack_iface_,
|
||||
nullptr, *audio_config_);
|
||||
BluetoothAudioSessionReport::OnSessionStarted(
|
||||
session_type_, stack_iface_, nullptr, *audio_config_, latency_modes_);
|
||||
*_aidl_return = DataMQDesc();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
@@ -89,4 +87,4 @@ ndk::ScopedAStatus LeAudioOffloadAudioProvider::onSessionReady(
|
||||
} // namespace bluetooth
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace aidl
|
||||
|
||||
@@ -70,9 +70,7 @@ bool LeAudioSoftwareAudioProvider::isValid(const SessionType& sessionType) {
|
||||
ndk::ScopedAStatus LeAudioSoftwareAudioProvider::startSession(
|
||||
const std::shared_ptr<IBluetoothAudioPort>& host_if,
|
||||
const AudioConfiguration& audio_config,
|
||||
const std::vector<LatencyMode>& latency_modes,
|
||||
DataMQDesc* _aidl_return) {
|
||||
latency_modes_ = latency_modes;
|
||||
const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) {
|
||||
if (audio_config.getTag() != AudioConfiguration::pcmConfig) {
|
||||
LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
|
||||
<< audio_config.toString();
|
||||
@@ -134,8 +132,8 @@ ndk::ScopedAStatus LeAudioSoftwareAudioProvider::onSessionReady(
|
||||
}
|
||||
*_aidl_return = data_mq_->dupeDesc();
|
||||
auto desc = data_mq_->dupeDesc();
|
||||
BluetoothAudioSessionReport::OnSessionStarted(session_type_, stack_iface_,
|
||||
&desc, *audio_config_);
|
||||
BluetoothAudioSessionReport::OnSessionStarted(
|
||||
session_type_, stack_iface_, &desc, *audio_config_, latency_modes_);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
@@ -143,4 +141,4 @@ ndk::ScopedAStatus LeAudioSoftwareAudioProvider::onSessionReady(
|
||||
} // namespace bluetooth
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace aidl
|
||||
|
||||
@@ -46,7 +46,8 @@ BluetoothAudioSession::BluetoothAudioSession(const SessionType& session_type)
|
||||
|
||||
void BluetoothAudioSession::OnSessionStarted(
|
||||
const std::shared_ptr<IBluetoothAudioPort> stack_iface,
|
||||
const DataMQDesc* mq_desc, const AudioConfiguration& audio_config) {
|
||||
const DataMQDesc* mq_desc, const AudioConfiguration& audio_config,
|
||||
const std::vector<LatencyMode>& latency_modes) {
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex_);
|
||||
if (stack_iface == nullptr) {
|
||||
LOG(ERROR) << __func__ << " - SessionType=" << toString(session_type_)
|
||||
@@ -61,6 +62,7 @@ void BluetoothAudioSession::OnSessionStarted(
|
||||
audio_config_ = nullptr;
|
||||
} else {
|
||||
stack_iface_ = stack_iface;
|
||||
latency_modes_ = latency_modes;
|
||||
LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
|
||||
<< ", AudioConfiguration=" << audio_config.toString();
|
||||
ReportSessionStatus();
|
||||
@@ -191,14 +193,14 @@ void BluetoothAudioSession::UnregisterStatusCback(uint16_t cookie) {
|
||||
*
|
||||
***/
|
||||
|
||||
bool BluetoothAudioSession::StartStream() {
|
||||
bool BluetoothAudioSession::StartStream(bool is_low_latency) {
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex_);
|
||||
if (!IsSessionReady()) {
|
||||
LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_)
|
||||
<< " has NO session";
|
||||
return false;
|
||||
}
|
||||
auto hal_retval = stack_iface_->startStream(false);
|
||||
auto hal_retval = stack_iface_->startStream(is_low_latency);
|
||||
if (!hal_retval.isOk()) {
|
||||
LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType="
|
||||
<< toString(session_type_) << " failed";
|
||||
@@ -418,6 +420,7 @@ void BluetoothAudioSession::ReportControlStatus(bool start_resp,
|
||||
|
||||
void BluetoothAudioSession::ReportLowLatencyModeAllowedChanged(bool allowed) {
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex_);
|
||||
low_latency_allowed_ = allowed;
|
||||
if (observers_.empty()) {
|
||||
LOG(WARNING) << __func__ << " - SessionType=" << toString(session_type_)
|
||||
<< " has NO port state observer";
|
||||
@@ -530,7 +533,25 @@ void BluetoothAudioSession::UpdateSinkMetadata(
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothAudioSession::SetLatencyMode(LatencyMode latency_mode) {
|
||||
std::vector<LatencyMode> BluetoothAudioSession::GetSupportedLatencyModes() {
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex_);
|
||||
if (!IsSessionReady()) {
|
||||
LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_)
|
||||
<< " has NO session";
|
||||
return std::vector<LatencyMode>();
|
||||
}
|
||||
if (low_latency_allowed_) return latency_modes_;
|
||||
std::vector<LatencyMode> modes;
|
||||
for (LatencyMode mode : latency_modes_) {
|
||||
if (mode == LatencyMode::LOW_LATENCY)
|
||||
// ignore those low latency mode if Bluetooth stack doesn't allow
|
||||
continue;
|
||||
modes.push_back(mode);
|
||||
}
|
||||
return modes;
|
||||
}
|
||||
|
||||
void BluetoothAudioSession::SetLatencyMode(const LatencyMode& latency_mode) {
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex_);
|
||||
if (!IsSessionReady()) {
|
||||
LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
@@ -120,7 +121,8 @@ class BluetoothAudioSession {
|
||||
***/
|
||||
void OnSessionStarted(const std::shared_ptr<IBluetoothAudioPort> stack_iface,
|
||||
const DataMQDesc* mq_desc,
|
||||
const AudioConfiguration& audio_config);
|
||||
const AudioConfiguration& audio_config,
|
||||
const std::vector<LatencyMode>& latency_modes);
|
||||
|
||||
/***
|
||||
* The report function is used to report that the Bluetooth stack has ended
|
||||
@@ -175,13 +177,15 @@ class BluetoothAudioSession {
|
||||
* Those control functions are for the bluetooth_audio module to start,
|
||||
* suspend, stop stream, to check position, and to update metadata.
|
||||
***/
|
||||
bool StartStream();
|
||||
bool StartStream(bool low_latency);
|
||||
bool SuspendStream();
|
||||
void StopStream();
|
||||
bool GetPresentationPosition(PresentationPosition& presentation_position);
|
||||
void UpdateSourceMetadata(const struct source_metadata& source_metadata);
|
||||
void UpdateSinkMetadata(const struct sink_metadata& sink_metadata);
|
||||
void SetLatencyMode(LatencyMode latency_mode);
|
||||
|
||||
std::vector<LatencyMode> GetSupportedLatencyModes();
|
||||
void SetLatencyMode(const LatencyMode& latency_mode);
|
||||
|
||||
// The control function writes stream to FMQ
|
||||
size_t OutWritePcmData(const void* buffer, size_t bytes);
|
||||
@@ -202,6 +206,8 @@ class BluetoothAudioSession {
|
||||
std::unique_ptr<DataMQ> data_mq_;
|
||||
// audio data configuration for both software and offloading
|
||||
std::unique_ptr<AudioConfiguration> audio_config_;
|
||||
std::vector<LatencyMode> latency_modes_;
|
||||
bool low_latency_allowed_ = true;
|
||||
|
||||
// saving those registered bluetooth_audio's callbacks
|
||||
std::unordered_map<uint16_t, std::shared_ptr<struct PortStatusCallbacks>>
|
||||
@@ -234,4 +240,4 @@ class BluetoothAudioSessionInstance {
|
||||
} // namespace bluetooth
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace aidl
|
||||
|
||||
@@ -98,11 +98,12 @@ class BluetoothAudioSessionControl {
|
||||
stop
|
||||
* stream, to check position, and to update metadata.
|
||||
***/
|
||||
static bool StartStream(const SessionType& session_type) {
|
||||
static bool StartStream(const SessionType& session_type,
|
||||
bool low_latency = false) {
|
||||
std::shared_ptr<BluetoothAudioSession> session_ptr =
|
||||
BluetoothAudioSessionInstance::GetSessionInstance(session_type);
|
||||
if (session_ptr != nullptr) {
|
||||
return session_ptr->StartStream();
|
||||
return session_ptr->StartStream(low_latency);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -154,6 +155,25 @@ class BluetoothAudioSessionControl {
|
||||
}
|
||||
}
|
||||
|
||||
static std::vector<LatencyMode> GetSupportedLatencyModes(
|
||||
const SessionType& session_type) {
|
||||
std::shared_ptr<BluetoothAudioSession> session_ptr =
|
||||
BluetoothAudioSessionInstance::GetSessionInstance(session_type);
|
||||
if (session_ptr != nullptr) {
|
||||
return session_ptr->GetSupportedLatencyModes();
|
||||
}
|
||||
return std::vector<LatencyMode>();
|
||||
}
|
||||
|
||||
static void SetLatencyMode(const SessionType& session_type,
|
||||
const LatencyMode& latency_mode) {
|
||||
std::shared_ptr<BluetoothAudioSession> session_ptr =
|
||||
BluetoothAudioSessionInstance::GetSessionInstance(session_type);
|
||||
if (session_ptr != nullptr) {
|
||||
session_ptr->SetLatencyMode(latency_mode);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* The control API writes stream to FMQ
|
||||
***/
|
||||
@@ -185,4 +205,4 @@ class BluetoothAudioSessionControl {
|
||||
} // namespace bluetooth
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace aidl
|
||||
|
||||
@@ -33,11 +33,13 @@ class BluetoothAudioSessionReport {
|
||||
static void OnSessionStarted(
|
||||
const SessionType& session_type,
|
||||
const std::shared_ptr<IBluetoothAudioPort> host_iface,
|
||||
const DataMQDesc* data_mq, const AudioConfiguration& audio_config) {
|
||||
const DataMQDesc* data_mq, const AudioConfiguration& audio_config,
|
||||
const std::vector<LatencyMode>& latency_modes) {
|
||||
std::shared_ptr<BluetoothAudioSession> session_ptr =
|
||||
BluetoothAudioSessionInstance::GetSessionInstance(session_type);
|
||||
if (session_ptr != nullptr) {
|
||||
session_ptr->OnSessionStarted(host_iface, data_mq, audio_config);
|
||||
session_ptr->OnSessionStarted(host_iface, data_mq, audio_config,
|
||||
latency_modes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,4 +98,4 @@ class BluetoothAudioSessionReport {
|
||||
} // namespace bluetooth
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace aidl
|
||||
|
||||
Reference in New Issue
Block a user