diff options
author | Cheney Ni <cheneyni@google.com> | 2022-03-03 00:12:48 +0800 |
---|---|---|
committer | Cheney Ni <cheneyni@google.com> | 2022-03-08 11:55:41 +0800 |
commit | 6ecbc76603672e88007479c1a2d395a477799d14 (patch) | |
tree | a396fcb852953842c302d1f20398c9502554985c /bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp | |
parent | 90019d46c2fd7009677e5e8b6c1b1b0042cb38af (diff) |
SpatialAudio: Export LatencyMode functions to BluetoothAudioSession
BluetoothAudioSession utility supports latency control functions, so
audio_bluetooth_hw can get / set the LatencyMode easily.
Bug: 214615268
Bug: 218708371
Test: build
Tag: #feature
Change-Id: Ia85581c74fc91f406309539755d60d36c173f5e0
Diffstat (limited to 'bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp')
-rw-r--r-- | bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp index e700e7e4ef..37ac9678e8 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp @@ -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_) |