Merge "Pass sink metadata to Bluetooth"

This commit is contained in:
Jakub Pawłowski
2021-12-09 20:52:58 +00:00
committed by Gerrit Code Review
19 changed files with 197 additions and 22 deletions

View File

@@ -14,6 +14,7 @@ hidl_interface {
root: "android.hardware", root: "android.hardware",
srcs: [ srcs: [
"types.hal", "types.hal",
"IBluetoothAudioPort.hal",
"IBluetoothAudioProvider.hal", "IBluetoothAudioProvider.hal",
"IBluetoothAudioProvidersFactory.hal", "IBluetoothAudioProvidersFactory.hal",
], ],

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.bluetooth.audio@2.2;
import @2.0::IBluetoothAudioPort;
import android.hardware.audio.common@5.0::SinkMetadata;
interface IBluetoothAudioPort extends @2.0::IBluetoothAudioPort {
/**
* Called when the metadata of the stream's sink has been changed.
*
* @param sinkMetadata Description of the audio that is recorded by the
* clients.
*/
updateSinkMetadata(SinkMetadata sinkMetadata);
};

View File

@@ -17,7 +17,7 @@
package android.hardware.bluetooth.audio@2.2; package android.hardware.bluetooth.audio@2.2;
import @2.1::IBluetoothAudioProvider; import @2.1::IBluetoothAudioProvider;
import @2.0::IBluetoothAudioPort; import @2.2::IBluetoothAudioPort;
import @2.0::Status; import @2.0::Status;
/** /**

View File

@@ -54,7 +54,7 @@ bool A2dpOffloadAudioProvider::isValid(const V2_1::SessionType& sessionType) {
} }
Return<void> A2dpOffloadAudioProvider::startSession( Return<void> A2dpOffloadAudioProvider::startSession(
const sp<IBluetoothAudioPort>& hostIf, const sp<V2_0::IBluetoothAudioPort>& hostIf,
const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) { const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
/** /**
* Initialize the audio platform if audioConfiguration is supported. * Initialize the audio platform if audioConfiguration is supported.

View File

@@ -70,7 +70,7 @@ bool A2dpSoftwareAudioProvider::isValid(const V2_1::SessionType& sessionType) {
} }
Return<void> A2dpSoftwareAudioProvider::startSession( Return<void> A2dpSoftwareAudioProvider::startSession(
const sp<IBluetoothAudioPort>& hostIf, const sp<V2_0::IBluetoothAudioPort>& hostIf,
const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) { const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
/** /**
* Initialize the audio platform if audioConfiguration is supported. * Initialize the audio platform if audioConfiguration is supported.

View File

@@ -40,7 +40,7 @@ class A2dpSoftwareAudioProvider : public BluetoothAudioProvider {
bool isValid(const V2_1::SessionType& sessionType) override; bool isValid(const V2_1::SessionType& sessionType) override;
bool isValid(const V2_0::SessionType& sessionType) override; bool isValid(const V2_0::SessionType& sessionType) override;
Return<void> startSession(const sp<IBluetoothAudioPort>& hostIf, Return<void> startSession(const sp<V2_0::IBluetoothAudioPort>& hostIf,
const V2_0::AudioConfiguration& audioConfig, const V2_0::AudioConfiguration& audioConfig,
startSession_cb _hidl_cb) override; startSession_cb _hidl_cb) override;

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <android/hardware/bluetooth/audio/2.2/types.h>
namespace android {
namespace hardware {
namespace bluetooth {
namespace audio {
namespace V2_2 {
namespace implementation {
using ::android::sp;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::audio::common::V5_0::SinkMetadata;
using ::android::hardware::audio::common::V5_0::SourceMetadata;
using ::android::hardware::bluetooth::audio::V2_2::IBluetoothAudioPort;
class AudioPort_2_0_to_2_2_Wrapper : public V2_2::IBluetoothAudioPort {
public:
AudioPort_2_0_to_2_2_Wrapper(const sp<V2_0::IBluetoothAudioPort>& port) {
this->port = port;
}
Return<void> startStream() override { return port->startStream(); }
Return<void> suspendStream() override { return port->suspendStream(); }
Return<void> stopStream() override { return port->stopStream(); }
Return<void> getPresentationPosition(
getPresentationPosition_cb _hidl_cb) override {
return port->getPresentationPosition(_hidl_cb);
}
Return<void> updateMetadata(const SourceMetadata& sourceMetadata) override {
return port->updateMetadata(sourceMetadata);
}
Return<void> updateSinkMetadata(const SinkMetadata&) override {
// DO NOTHING, 2.0 AudioPort doesn't support sink metadata updates
return Void();
}
sp<V2_0::IBluetoothAudioPort> port;
};
} // namespace implementation
} // namespace V2_2
} // namespace audio
} // namespace bluetooth
} // namespace hardware
} // namespace android

View File

@@ -20,6 +20,7 @@
#include <android-base/logging.h> #include <android-base/logging.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_1.h"
@@ -51,7 +52,7 @@ BluetoothAudioProvider::BluetoothAudioProvider()
audio_config_({}) {} audio_config_({}) {}
Return<void> BluetoothAudioProvider::startSession( Return<void> BluetoothAudioProvider::startSession(
const sp<IBluetoothAudioPort>& hostIf, const sp<V2_0::IBluetoothAudioPort>& hostIf,
const V2_0::AudioConfiguration& audioConfig, startSession_cb _hidl_cb) { const V2_0::AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
AudioConfiguration audioConfig_2_2; AudioConfiguration audioConfig_2_2;
@@ -67,11 +68,13 @@ Return<void> BluetoothAudioProvider::startSession(
audioConfig_2_2.codecConfig(audioConfig.codecConfig()); audioConfig_2_2.codecConfig(audioConfig.codecConfig());
} }
return startSession_2_2(hostIf, audioConfig_2_2, _hidl_cb); sp<V2_2::IBluetoothAudioPort> hostIf_2_2 =
new AudioPort_2_0_to_2_2_Wrapper(hostIf);
return startSession_2_2(hostIf_2_2, audioConfig_2_2, _hidl_cb);
} }
Return<void> BluetoothAudioProvider::startSession_2_1( Return<void> BluetoothAudioProvider::startSession_2_1(
const sp<IBluetoothAudioPort>& hostIf, const sp<V2_0::IBluetoothAudioPort>& hostIf,
const V2_1::AudioConfiguration& audioConfig, startSession_cb _hidl_cb) { const V2_1::AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
AudioConfiguration audioConfig_2_2; AudioConfiguration audioConfig_2_2;
if (audioConfig.getDiscriminator() == if (audioConfig.getDiscriminator() ==
@@ -92,11 +95,13 @@ Return<void> BluetoothAudioProvider::startSession_2_1(
audioConfig_2_2.codecConfig(audioConfig.codecConfig()); audioConfig_2_2.codecConfig(audioConfig.codecConfig());
} }
return startSession_2_2(hostIf, audioConfig_2_2, _hidl_cb); sp<V2_2::IBluetoothAudioPort> hostIf_2_2 =
new AudioPort_2_0_to_2_2_Wrapper(hostIf);
return startSession_2_2(hostIf_2_2, audioConfig_2_2, _hidl_cb);
} }
Return<void> BluetoothAudioProvider::startSession_2_2( Return<void> BluetoothAudioProvider::startSession_2_2(
const sp<IBluetoothAudioPort>& hostIf, const sp<V2_2::IBluetoothAudioPort>& hostIf,
const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) { const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
if (hostIf == nullptr) { if (hostIf == nullptr) {
_hidl_cb(BluetoothAudioStatus::FAILURE, DataMQ::Descriptor()); _hidl_cb(BluetoothAudioStatus::FAILURE, DataMQ::Descriptor());

View File

@@ -26,7 +26,7 @@ namespace V2_2 {
namespace implementation { namespace implementation {
using ::android::sp; using ::android::sp;
using ::android::hardware::bluetooth::audio::V2_0::IBluetoothAudioPort; using ::android::hardware::bluetooth::audio::V2_2::IBluetoothAudioPort;
using BluetoothAudioStatus = using BluetoothAudioStatus =
::android::hardware::bluetooth::audio::V2_0::Status; ::android::hardware::bluetooth::audio::V2_0::Status;
@@ -41,13 +41,13 @@ class BluetoothAudioProvider : public IBluetoothAudioProvider {
virtual bool isValid(const V2_1::SessionType& sessionType) = 0; virtual bool isValid(const V2_1::SessionType& sessionType) = 0;
virtual bool isValid(const V2_0::SessionType& sessionType) = 0; virtual bool isValid(const V2_0::SessionType& sessionType) = 0;
Return<void> startSession(const sp<IBluetoothAudioPort>& hostIf, Return<void> startSession(const sp<V2_0::IBluetoothAudioPort>& hostIf,
const V2_0::AudioConfiguration& audioConfig, const V2_0::AudioConfiguration& audioConfig,
startSession_cb _hidl_cb) override; startSession_cb _hidl_cb) override;
Return<void> startSession_2_1(const sp<IBluetoothAudioPort>& hostIf, Return<void> startSession_2_1(const sp<V2_0::IBluetoothAudioPort>& hostIf,
const V2_1::AudioConfiguration& audioConfig, const V2_1::AudioConfiguration& audioConfig,
startSession_cb _hidl_cb) override; startSession_cb _hidl_cb) override;
Return<void> startSession_2_2(const sp<IBluetoothAudioPort>& hostIf, Return<void> startSession_2_2(const sp<V2_2::IBluetoothAudioPort>& hostIf,
const AudioConfiguration& audioConfig, const AudioConfiguration& audioConfig,
startSession_cb _hidl_cb) override; startSession_cb _hidl_cb) override;
Return<void> streamStarted(BluetoothAudioStatus status) override; Return<void> streamStarted(BluetoothAudioStatus status) override;
@@ -59,7 +59,7 @@ class BluetoothAudioProvider : public IBluetoothAudioProvider {
V2_1::SessionType session_type_; V2_1::SessionType session_type_;
AudioConfiguration audio_config_; AudioConfiguration audio_config_;
sp<V2_0::IBluetoothAudioPort> stack_iface_; sp<V2_2::IBluetoothAudioPort> stack_iface_;
virtual Return<void> onSessionReady(startSession_cb _hidl_cb) = 0; virtual Return<void> onSessionReady(startSession_cb _hidl_cb) = 0;
}; };

View File

@@ -66,7 +66,7 @@ bool HearingAidAudioProvider::isValid(const V2_1::SessionType& sessionType) {
} }
Return<void> HearingAidAudioProvider::startSession( Return<void> HearingAidAudioProvider::startSession(
const sp<IBluetoothAudioPort>& hostIf, const sp<V2_0::IBluetoothAudioPort>& hostIf,
const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) { const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
/** /**
* Initialize the audio platform if audioConfiguration is supported. * Initialize the audio platform if audioConfiguration is supported.

View File

@@ -40,7 +40,7 @@ class HearingAidAudioProvider : public BluetoothAudioProvider {
bool isValid(const V2_1::SessionType& sessionType) override; bool isValid(const V2_1::SessionType& sessionType) override;
bool isValid(const V2_0::SessionType& sessionType) override; bool isValid(const V2_0::SessionType& sessionType) override;
Return<void> startSession(const sp<IBluetoothAudioPort>& hostIf, Return<void> startSession(const sp<V2_0::IBluetoothAudioPort>& hostIf,
const V2_0::AudioConfiguration& audioConfig, const V2_0::AudioConfiguration& audioConfig,
startSession_cb _hidl_cb) override; startSession_cb _hidl_cb) override;

View File

@@ -20,6 +20,7 @@
#include <android-base/logging.h> #include <android-base/logging.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_1.h"
@@ -83,11 +84,13 @@ Return<void> LeAudioAudioProvider::startSession_2_1(
.bitsPerSample = audioConfig.pcmConfig().bitsPerSample, .bitsPerSample = audioConfig.pcmConfig().bitsPerSample,
.dataIntervalUs = 0}); .dataIntervalUs = 0});
return startSession_2_2(hostIf, audioConfig_2_2, _hidl_cb); sp<V2_2::IBluetoothAudioPort> hostIf_2_2 =
new AudioPort_2_0_to_2_2_Wrapper(hostIf);
return startSession_2_2(hostIf_2_2, audioConfig_2_2, _hidl_cb);
} }
Return<void> LeAudioAudioProvider::startSession_2_2( Return<void> LeAudioAudioProvider::startSession_2_2(
const sp<V2_0::IBluetoothAudioPort>& hostIf, const sp<V2_2::IBluetoothAudioPort>& hostIf,
const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) { const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
/** /**
* Initialize the audio platform if audioConfiguration is supported. * Initialize the audio platform if audioConfiguration is supported.

View File

@@ -45,7 +45,7 @@ class LeAudioAudioProvider : public BluetoothAudioProvider {
const V2_1::AudioConfiguration& audioConfig, const V2_1::AudioConfiguration& audioConfig,
startSession_cb _hidl_cb) override; startSession_cb _hidl_cb) override;
Return<void> startSession_2_2(const sp<V2_0::IBluetoothAudioPort>& hostIf, Return<void> startSession_2_2(const sp<V2_2::IBluetoothAudioPort>& hostIf,
const AudioConfiguration& audioConfig, const AudioConfiguration& audioConfig,
startSession_cb _hidl_cb) override; startSession_cb _hidl_cb) override;

View File

@@ -20,6 +20,7 @@
#include <android-base/logging.h> #include <android-base/logging.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_1.h"
#include "BluetoothAudioSupportedCodecsDB_2_2.h" #include "BluetoothAudioSupportedCodecsDB_2_2.h"
@@ -91,11 +92,13 @@ Return<void> LeAudioOffloadAudioProvider::startSession_2_1(
.peerDelay = 0, .peerDelay = 0,
.lc3Config = audioConfig.leAudioCodecConfig().lc3Config}; .lc3Config = audioConfig.leAudioCodecConfig().lc3Config};
return startSession_2_2(hostIf, audioConfig_2_2, _hidl_cb); sp<V2_2::IBluetoothAudioPort> hostIf_2_2 =
new AudioPort_2_0_to_2_2_Wrapper(hostIf);
return startSession_2_2(hostIf_2_2, audioConfig_2_2, _hidl_cb);
} }
Return<void> LeAudioOffloadAudioProvider::startSession_2_2( Return<void> LeAudioOffloadAudioProvider::startSession_2_2(
const sp<V2_0::IBluetoothAudioPort>& hostIf, const sp<V2_2::IBluetoothAudioPort>& hostIf,
const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) { const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
/** /**
* Initialize the audio platform if audioConfiguration is supported. * Initialize the audio platform if audioConfiguration is supported.

View File

@@ -38,7 +38,7 @@ class LeAudioOffloadAudioProvider : public BluetoothAudioProvider {
const V2_1::AudioConfiguration& audioConfig, const V2_1::AudioConfiguration& audioConfig,
startSession_cb _hidl_cb) override; startSession_cb _hidl_cb) override;
Return<void> startSession_2_2(const sp<V2_0::IBluetoothAudioPort>& hostIf, Return<void> startSession_2_2(const sp<V2_2::IBluetoothAudioPort>& hostIf,
const AudioConfiguration& audioConfig, const AudioConfiguration& audioConfig,
startSession_cb _hidl_cb) override; startSession_cb _hidl_cb) override;

View File

@@ -22,6 +22,7 @@ cc_library_shared {
export_include_dirs: ["session/"], export_include_dirs: ["session/"],
header_libs: ["libhardware_headers"], header_libs: ["libhardware_headers"],
shared_libs: [ shared_libs: [
"android.hardware.audio.common@5.0",
"android.hardware.bluetooth.audio@2.0", "android.hardware.bluetooth.audio@2.0",
"android.hardware.bluetooth.audio@2.1", "android.hardware.bluetooth.audio@2.1",
"android.hardware.bluetooth.audio@2.2", "android.hardware.bluetooth.audio@2.2",

View File

@@ -132,6 +132,15 @@ class BluetoothAudioSessionControl_2_2 {
} }
} }
static void UpdateSinkMetadata(const SessionType_2_1& session_type,
const struct sink_metadata* sink_metadata) {
std::shared_ptr<BluetoothAudioSession_2_2> session_ptr =
BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type);
if (session_ptr != nullptr) {
session_ptr->UpdateSinkMetadata(sink_metadata);
}
}
// The control API writes stream to FMQ // The control API writes stream to FMQ
static size_t OutWritePcmData(const SessionType_2_1& session_type, static size_t OutWritePcmData(const SessionType_2_1& session_type,
const void* buffer, size_t bytes) { const void* buffer, size_t bytes) {

View File

@@ -20,10 +20,16 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android-base/stringprintf.h> #include <android-base/stringprintf.h>
#include <android/hardware/bluetooth/audio/2.2/IBluetoothAudioPort.h>
namespace android { namespace android {
namespace bluetooth { namespace bluetooth {
namespace audio { namespace audio {
using ::android::hardware::audio::common::V5_0::AudioSource;
using ::android::hardware::audio::common::V5_0::RecordTrackMetadata;
using ::android::hardware::audio::common::V5_0::SinkMetadata;
using SessionType_2_1 = using SessionType_2_1 =
::android::hardware::bluetooth::audio::V2_1::SessionType; ::android::hardware::bluetooth::audio::V2_1::SessionType;
using SessionType_2_0 = using SessionType_2_0 =
@@ -37,6 +43,9 @@ using AudioConfiguration_2_1 =
::android::hardware::bluetooth::audio::V2_2::AudioConfiguration ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
BluetoothAudioSession_2_2::invalidOffloadAudioConfiguration = {}; BluetoothAudioSession_2_2::invalidOffloadAudioConfiguration = {};
using IBluetoothAudioPort_2_2 =
::android::hardware::bluetooth::audio::V2_2::IBluetoothAudioPort;
namespace { namespace {
bool is_2_0_session_type( bool is_2_0_session_type(
const ::android::hardware::bluetooth::audio::V2_1::SessionType& const ::android::hardware::bluetooth::audio::V2_1::SessionType&
@@ -84,6 +93,54 @@ BluetoothAudioSession_2_2::GetAudioSession_2_1() {
return audio_session_2_1; return audio_session_2_1;
} }
void BluetoothAudioSession_2_2::UpdateSinkMetadata(
const struct sink_metadata* sink_metadata) {
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;
}
ssize_t track_count = sink_metadata->track_count;
LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_2_1_)
<< ", " << track_count << " track(s)";
if (session_type_2_1_ == SessionType_2_1::A2DP_SOFTWARE_ENCODING_DATAPATH ||
session_type_2_1_ == SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH) {
return;
}
struct record_track_metadata* track = sink_metadata->tracks;
SinkMetadata sinkMetadata;
RecordTrackMetadata* halMetadata;
sinkMetadata.tracks.resize(track_count);
halMetadata = sinkMetadata.tracks.data();
while (track_count && track) {
halMetadata->source = static_cast<AudioSource>(track->source);
halMetadata->gain = track->gain;
// halMetadata->destination leave unspecified
LOG(INFO) << __func__
<< " - SessionType=" << toString(GetAudioSession()->session_type_)
<< ", source=" << track->source
<< ", dest_device=" << track->dest_device
<< ", gain=" << track->gain
<< ", dest_device_address=" << track->dest_device_address;
--track_count;
++track;
++halMetadata;
}
/* This is called just for 2.2 sessions, so it's safe to do this casting*/
IBluetoothAudioPort_2_2* stack_iface_2_2_ =
static_cast<IBluetoothAudioPort_2_2*>(audio_session->stack_iface_.get());
auto hal_retval = stack_iface_2_2_->updateSinkMetadata(sinkMetadata);
if (!hal_retval.isOk()) {
LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType="
<< toString(session_type_2_1_) << " failed";
}
}
// 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

@@ -74,6 +74,8 @@ class BluetoothAudioSession_2_2 {
const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
GetAudioConfig(); GetAudioConfig();
void UpdateSinkMetadata(const struct sink_metadata* sink_metadata);
static constexpr ::android::hardware::bluetooth::audio::V2_2:: static constexpr ::android::hardware::bluetooth::audio::V2_2::
AudioConfiguration& kInvalidSoftwareAudioConfiguration = AudioConfiguration& kInvalidSoftwareAudioConfiguration =
invalidSoftwareAudioConfiguration; invalidSoftwareAudioConfiguration;