diff --git a/bluetooth/audio/aidl/Android.bp b/bluetooth/audio/aidl/Android.bp index 32f8cca7d2..16b22fef36 100644 --- a/bluetooth/audio/aidl/Android.bp +++ b/bluetooth/audio/aidl/Android.bp @@ -29,7 +29,7 @@ aidl_interface { imports: [ "android.hardware.common-V2", "android.hardware.common.fmq-V1", - "android.hardware.audio.common-V1", + "android.hardware.audio.common-V2", ], backend: { cpp: { @@ -69,7 +69,7 @@ aidl_interface { imports: [ "android.hardware.common-V2", "android.hardware.common.fmq-V1", - "android.hardware.audio.common-V1", + "android.hardware.audio.common-V2", ], }, diff --git a/bluetooth/audio/aidl/vts/Android.bp b/bluetooth/audio/aidl/vts/Android.bp index 3e6953ff5d..fa85fa87f0 100644 --- a/bluetooth/audio/aidl/vts/Android.bp +++ b/bluetooth/audio/aidl/vts/Android.bp @@ -16,7 +16,7 @@ cc_test { tidy_timeout_srcs: ["VtsHalBluetoothAudioTargetTest.cpp"], srcs: ["VtsHalBluetoothAudioTargetTest.cpp"], static_libs: [ - "android.hardware.audio.common-V1-ndk", + "android.hardware.audio.common-V2-ndk", "android.hardware.bluetooth.audio-V3-ndk", "android.hardware.common-V2-ndk", "android.hardware.common.fmq-V1-ndk", diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp index 2b0caadeae..b46b62c037 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "BluetoothAudioSession.h" @@ -538,23 +539,9 @@ bool BluetoothAudioSession::GetPresentationPosition( void BluetoothAudioSession::UpdateSourceMetadata( const struct source_metadata& source_metadata) { - std::lock_guard guard(mutex_); - if (!IsSessionReady()) { - LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) - << " has NO session"; - return; - } - ssize_t track_count = source_metadata.track_count; LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_) << "," << track_count << " track(s)"; - if (session_type_ == SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH || - session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH || - session_type_ == SessionType::A2DP_SOFTWARE_DECODING_DATAPATH || - session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH) { - return; - } - SourceMetadata hal_source_metadata; hal_source_metadata.tracks.resize(track_count); for (int i = 0; i < track_count; i++) { @@ -571,33 +558,14 @@ void BluetoothAudioSession::UpdateSourceMetadata( << toString(hal_source_metadata.tracks[i].contentType) << ", gain=" << hal_source_metadata.tracks[i].gain; } - - auto hal_retval = stack_iface_->updateSourceMetadata(hal_source_metadata); - if (!hal_retval.isOk()) { - LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType=" - << toString(session_type_) << " failed"; - } + UpdateSourceMetadata(hal_source_metadata); } void BluetoothAudioSession::UpdateSinkMetadata( const struct sink_metadata& sink_metadata) { - std::lock_guard guard(mutex_); - if (!IsSessionReady()) { - LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) - << " has NO session"; - return; - } - ssize_t track_count = sink_metadata.track_count; LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_) << "," << track_count << " track(s)"; - if (session_type_ == SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH || - session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH || - session_type_ == SessionType::A2DP_SOFTWARE_DECODING_DATAPATH || - session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH) { - return; - } - SinkMetadata hal_sink_metadata; hal_sink_metadata.tracks.resize(track_count); for (int i = 0; i < track_count; i++) { @@ -612,12 +580,57 @@ void BluetoothAudioSession::UpdateSinkMetadata( << ", dest_device_address=" << sink_metadata.tracks[i].dest_device_address; } + UpdateSinkMetadata(hal_sink_metadata); +} + +bool BluetoothAudioSession::UpdateSourceMetadata( + const SourceMetadata& hal_source_metadata) { + std::lock_guard guard(mutex_); + if (!IsSessionReady()) { + LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) + << " has NO session"; + return false; + } + + if (session_type_ == SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH || + session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH || + session_type_ == SessionType::A2DP_SOFTWARE_DECODING_DATAPATH || + session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH) { + return false; + } + + auto hal_retval = stack_iface_->updateSourceMetadata(hal_source_metadata); + if (!hal_retval.isOk()) { + LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType=" + << toString(session_type_) << " failed"; + return false; + } + return true; +} + +bool BluetoothAudioSession::UpdateSinkMetadata( + const SinkMetadata& hal_sink_metadata) { + std::lock_guard guard(mutex_); + if (!IsSessionReady()) { + LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) + << " has NO session"; + return false; + } + + if (session_type_ == SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH || + session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH || + session_type_ == SessionType::A2DP_SOFTWARE_DECODING_DATAPATH || + session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH) { + return false; + } auto hal_retval = stack_iface_->updateSinkMetadata(hal_sink_metadata); if (!hal_retval.isOk()) { LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType=" << toString(session_type_) << " failed"; + return false; } + return true; } std::vector BluetoothAudioSession::GetSupportedLatencyModes() { diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h index faf4ffbabe..25c676a3ac 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h @@ -23,12 +23,15 @@ #include #include #include -#include #include #include #include +// To avoid inclusion of hardware/audio.h +struct sink_metadata; +struct source_metadata; + namespace aidl { namespace android { namespace hardware { @@ -196,6 +199,9 @@ class BluetoothAudioSession { bool GetPresentationPosition(PresentationPosition& presentation_position); void UpdateSourceMetadata(const struct source_metadata& source_metadata); void UpdateSinkMetadata(const struct sink_metadata& sink_metadata); + // New versions for AIDL-only clients. + bool UpdateSourceMetadata(const SourceMetadata& hal_source_metadata); + bool UpdateSinkMetadata(const SinkMetadata& hal_sink_metadata); std::vector GetSupportedLatencyModes(); void SetLatencyMode(const LatencyMode& latency_mode); diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h index 881c6c10b2..6c60a3b5bf 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h @@ -175,6 +175,26 @@ class BluetoothAudioSessionControl { } } + static bool UpdateSourceMetadata(const SessionType& session_type, + const SourceMetadata& source_metadata) { + std::shared_ptr session_ptr = + BluetoothAudioSessionInstance::GetSessionInstance(session_type); + if (session_ptr != nullptr) { + return session_ptr->UpdateSourceMetadata(source_metadata); + } + return false; + } + + static bool UpdateSinkMetadata(const SessionType& session_type, + const SinkMetadata& sink_metadata) { + std::shared_ptr session_ptr = + BluetoothAudioSessionInstance::GetSessionInstance(session_type); + if (session_ptr != nullptr) { + return session_ptr->UpdateSinkMetadata(sink_metadata); + } + return false; + } + static std::vector GetSupportedLatencyModes( const SessionType& session_type) { std::shared_ptr session_ptr =