bluetooth: Add AudioSession/Control methods for AIDL track metadata

Add overloads for UpdateSink/SourceMetadata that
accept android.hardware.audio.common.Sink/SourceMetadata types.
Move include of hardware/audio.h to BluetoothAudioSession.cpp.
This allows to use this code from "pure AIDL" modules.

Bug: 228804498
Test: m
Change-Id: Ib0b8c6d1c7db9b846a508d6d4001f67feb2111c6
(cherry picked from commit d5f0d13ef0)
Merged-In: Ib0b8c6d1c7db9b846a508d6d4001f67feb2111c6
This commit is contained in:
Mikhail Naganov 2023-07-26 17:26:02 -07:00
parent a7d3a0dc06
commit 4bb14a9cdf
3 changed files with 74 additions and 35 deletions

View file

@ -20,6 +20,7 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android-base/stringprintf.h> #include <android-base/stringprintf.h>
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <hardware/audio.h>
#include "BluetoothAudioSession.h" #include "BluetoothAudioSession.h"
@ -476,23 +477,9 @@ bool BluetoothAudioSession::GetPresentationPosition(
void BluetoothAudioSession::UpdateSourceMetadata( void BluetoothAudioSession::UpdateSourceMetadata(
const struct source_metadata& source_metadata) { const struct source_metadata& source_metadata) {
std::lock_guard<std::recursive_mutex> guard(mutex_);
if (!IsSessionReady()) {
LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_)
<< " has NO session";
return;
}
ssize_t track_count = source_metadata.track_count; ssize_t track_count = source_metadata.track_count;
LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_) << "," LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_) << ","
<< track_count << " track(s)"; << 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; SourceMetadata hal_source_metadata;
hal_source_metadata.tracks.resize(track_count); hal_source_metadata.tracks.resize(track_count);
for (int i = 0; i < track_count; i++) { for (int i = 0; i < track_count; i++) {
@ -509,33 +496,14 @@ void BluetoothAudioSession::UpdateSourceMetadata(
<< toString(hal_source_metadata.tracks[i].contentType) << toString(hal_source_metadata.tracks[i].contentType)
<< ", gain=" << hal_source_metadata.tracks[i].gain; << ", gain=" << hal_source_metadata.tracks[i].gain;
} }
UpdateSourceMetadata(hal_source_metadata);
auto hal_retval = stack_iface_->updateSourceMetadata(hal_source_metadata);
if (!hal_retval.isOk()) {
LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType="
<< toString(session_type_) << " failed";
}
} }
void BluetoothAudioSession::UpdateSinkMetadata( void BluetoothAudioSession::UpdateSinkMetadata(
const struct sink_metadata& sink_metadata) { const struct sink_metadata& sink_metadata) {
std::lock_guard<std::recursive_mutex> guard(mutex_);
if (!IsSessionReady()) {
LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_)
<< " has NO session";
return;
}
ssize_t track_count = sink_metadata.track_count; ssize_t track_count = sink_metadata.track_count;
LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_) << "," LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_) << ","
<< track_count << " track(s)"; << 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; SinkMetadata hal_sink_metadata;
hal_sink_metadata.tracks.resize(track_count); hal_sink_metadata.tracks.resize(track_count);
for (int i = 0; i < track_count; i++) { for (int i = 0; i < track_count; i++) {
@ -550,12 +518,57 @@ void BluetoothAudioSession::UpdateSinkMetadata(
<< ", dest_device_address=" << ", dest_device_address="
<< sink_metadata.tracks[i].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<std::recursive_mutex> 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<std::recursive_mutex> 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); auto hal_retval = stack_iface_->updateSinkMetadata(hal_sink_metadata);
if (!hal_retval.isOk()) { if (!hal_retval.isOk()) {
LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType=" LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType="
<< toString(session_type_) << " failed"; << toString(session_type_) << " failed";
return false;
} }
return true;
} }
std::vector<LatencyMode> BluetoothAudioSession::GetSupportedLatencyModes() { std::vector<LatencyMode> BluetoothAudioSession::GetSupportedLatencyModes() {

View file

@ -23,12 +23,15 @@
#include <aidl/android/hardware/bluetooth/audio/LatencyMode.h> #include <aidl/android/hardware/bluetooth/audio/LatencyMode.h>
#include <aidl/android/hardware/bluetooth/audio/SessionType.h> #include <aidl/android/hardware/bluetooth/audio/SessionType.h>
#include <fmq/AidlMessageQueue.h> #include <fmq/AidlMessageQueue.h>
#include <hardware/audio.h>
#include <mutex> #include <mutex>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
// To avoid inclusion of hardware/audio.h
struct sink_metadata;
struct source_metadata;
namespace aidl { namespace aidl {
namespace android { namespace android {
namespace hardware { namespace hardware {
@ -183,6 +186,9 @@ class BluetoothAudioSession {
bool GetPresentationPosition(PresentationPosition& presentation_position); bool GetPresentationPosition(PresentationPosition& presentation_position);
void UpdateSourceMetadata(const struct source_metadata& source_metadata); void UpdateSourceMetadata(const struct source_metadata& source_metadata);
void UpdateSinkMetadata(const struct sink_metadata& sink_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<LatencyMode> GetSupportedLatencyModes(); std::vector<LatencyMode> GetSupportedLatencyModes();
void SetLatencyMode(const LatencyMode& latency_mode); void SetLatencyMode(const LatencyMode& latency_mode);

View file

@ -156,6 +156,26 @@ class BluetoothAudioSessionControl {
} }
} }
static bool UpdateSourceMetadata(const SessionType& session_type,
const SourceMetadata& source_metadata) {
std::shared_ptr<BluetoothAudioSession> 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<BluetoothAudioSession> session_ptr =
BluetoothAudioSessionInstance::GetSessionInstance(session_type);
if (session_ptr != nullptr) {
return session_ptr->UpdateSinkMetadata(sink_metadata);
}
return false;
}
static std::vector<LatencyMode> GetSupportedLatencyModes( static std::vector<LatencyMode> GetSupportedLatencyModes(
const SessionType& session_type) { const SessionType& session_type) {
std::shared_ptr<BluetoothAudioSession> session_ptr = std::shared_ptr<BluetoothAudioSession> session_ptr =