Merge changes I9f6bb947,Iff72dbea into main am: c3790fe083

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2912386

Change-Id: Iddd879e32452984e4ebeec586dcf2834c0db792a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Antoine Soulier 2024-01-23 00:10:26 +00:00 committed by Automerger Merge Worker
commit 716c79d130
18 changed files with 101 additions and 79 deletions

View file

@ -39,7 +39,7 @@ parcelable CodecParameters {
int bitdepth;
int minBitrate;
int maxBitrate;
boolean lowLatency;
boolean lossless;
boolean lowLatency = false;
boolean lossless = false;
byte[] vendorSpecificParameters;
}

View file

@ -41,7 +41,7 @@ interface IBluetoothAudioProvider {
void updateAudioConfiguration(in android.hardware.bluetooth.audio.AudioConfiguration audioConfig);
void setLowLatencyModeAllowed(in boolean allowed);
android.hardware.bluetooth.audio.A2dpStatus parseA2dpConfiguration(in android.hardware.bluetooth.audio.CodecId codecId, in byte[] configuration, out android.hardware.bluetooth.audio.CodecParameters codecParameters);
@nullable android.hardware.bluetooth.audio.A2dpConfiguration getA2dpConfiguration(in List<android.hardware.bluetooth.audio.A2dpRemoteCapabilities> remoteA2dpCapabilities, in android.hardware.bluetooth.audio.A2dpConfigurationHint hint);
@nullable android.hardware.bluetooth.audio.A2dpConfiguration getA2dpConfiguration(in android.hardware.bluetooth.audio.A2dpRemoteCapabilities[] remoteA2dpCapabilities, in android.hardware.bluetooth.audio.A2dpConfigurationHint hint);
void setCodecPriority(in android.hardware.bluetooth.audio.CodecId codecId, int priority);
android.hardware.bluetooth.audio.IBluetoothAudioProvider.LeAudioAseConfigurationSetting[] getLeAudioAseConfiguration(in @nullable android.hardware.bluetooth.audio.IBluetoothAudioProvider.LeAudioDeviceCapabilities[] remoteSinkAudioCapabilities, in @nullable android.hardware.bluetooth.audio.IBluetoothAudioProvider.LeAudioDeviceCapabilities[] remoteSourceAudioCapabilities, in android.hardware.bluetooth.audio.IBluetoothAudioProvider.LeAudioConfigurationRequirement[] requirements);
android.hardware.bluetooth.audio.IBluetoothAudioProvider.LeAudioAseQosConfigurationPair getLeAudioAseQosConfiguration(in android.hardware.bluetooth.audio.IBluetoothAudioProvider.LeAudioAseQosConfigurationRequirement qosRequirement);

View file

@ -26,6 +26,7 @@ import android.hardware.bluetooth.audio.CodecParameters;
parcelable A2dpConfiguration {
/**
* Remote Stream Endpoint Identifier
* This matches `A2dpRemoteCapabilities.seid` given by the framework.
*/
int remoteSeid;
@ -35,7 +36,7 @@ parcelable A2dpConfiguration {
* `configuration`. Using `id.a2dp`, the format is given by the `Codec
* Specific Information Elements` [A2DP - 4.3-6.2], and using `id.vendor`,
* by `Vendor Specific Value` [A2DP - 4.7.2].
* In any case, this byte array is limited by the framework to 128 Bytes.
* In any case, this byte array must be limited to 128 bytes.
*/
CodecId id;
CodecParameters parameters;

View file

@ -25,6 +25,8 @@ import android.hardware.bluetooth.audio.CodecId;
parcelable A2dpRemoteCapabilities {
/**
* Remote Stream Endpoint identifier
* Allocated by the remote device to identify a specific codec and capabilities,
* in the meaning of the AVDTP standard.
*/
int seid;

View file

@ -21,7 +21,9 @@ import android.hardware.bluetooth.audio.CodecId;
@VintfStability
parcelable A2dpStreamConfiguration {
/**
* Peer MTU (16 bits)
* Peer Maximum Transfer Unit (MTU), 16 bits value [Core - 3.A.5.1]
* It's the remote device indication of the maximum amount of data that
* can be received on the AVDTP Stream Channel.
*/
int peerMtu;
@ -29,6 +31,7 @@ parcelable A2dpStreamConfiguration {
* Optional SCMS-T Content Protection header
* that precedes audio content when enabled [A2DP - 3.2.1-2].
* The content protection byte is defined by [Assigned Number - 6.3.2].
* When the content protection is not enabled, this field should be left `null`.
*/
@nullable byte[1] cpHeaderScmst;

View file

@ -35,24 +35,29 @@ parcelable CodecParameters {
int bitdepth;
/**
* Encoding parameters:
*
* - Bitrate limits on a frame basis, defined in bits per second.
* The encoder bitrate mode can be encoded following this rule:
* . minBitrate equals to maxBitrate for constant bitrate
* . minBitrate set to 0, for VBR with peak bitrate at maxBitratre value.
* . minBitrate greater than 0, for ABR, the bitrate of the stream varies
* between minBitrate to maxBitrate according to link quality.
* The 0 value for both means "undefined" or "don't care".
*
* - Low-latency configuration privileged
* - Lossless effort indication. The 'False' value can be used as "don't care"
* Bitrate limits on a frame basis, defined in bits per second.
* The encoder bitrate mode can be encoded following this rule:
* . minBitrate equals to maxBitrate for constant bitrate
* . minBitrate set to 0, for VBR with peak bitrate at maxBitratre value.
* . minBitrate greater than 0, for ABR, the bitrate of the stream varies
* between minBitrate to maxBitrate according to link quality.
* The 0 value for both means "undefined" or "don't care".
*/
int minBitrate;
int maxBitrate;
boolean lowLatency;
boolean lossless;
/**
* Low-latency configuration. The interpretation is vendor specific.
* When returned to the client, the assessment of the low latency configuration is left
* to the vendor's discretion. When set by the client, it indicates that we are entering
* a low-latency context (e.g. gaming), and such a configuration should be privileged.
*/
boolean lowLatency = false;
/**
* Lossless effort indication. The 'False' value can be used as "don't care"
*/
boolean lossless = false;
/**
* Vendor specific parameters, inserted in the Vendor Specific HCI Command

View file

@ -133,7 +133,7 @@ interface IBluetoothAudioProvider {
* when no suitable configuration has been found.
*/
@nullable A2dpConfiguration getA2dpConfiguration(
in List<A2dpRemoteCapabilities> remoteA2dpCapabilities, in A2dpConfigurationHint hint);
in A2dpRemoteCapabilities[] remoteA2dpCapabilities, in A2dpConfigurationHint hint);
/**
* Predefined values for the codec priority, used by `setCodecPriority()`.

View file

@ -23,7 +23,6 @@
#include <android-base/logging.h>
#include "A2dpOffloadCodecAac.h"
#include "A2dpOffloadCodecFactory.h"
#include "A2dpOffloadCodecSbc.h"
namespace aidl {
@ -32,17 +31,21 @@ namespace hardware {
namespace bluetooth {
namespace audio {
A2dpOffloadEncodingAudioProvider::A2dpOffloadEncodingAudioProvider()
: A2dpOffloadAudioProvider() {
A2dpOffloadEncodingAudioProvider::A2dpOffloadEncodingAudioProvider(
const A2dpOffloadCodecFactory& codec_factory)
: A2dpOffloadAudioProvider(codec_factory) {
session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH;
}
A2dpOffloadDecodingAudioProvider::A2dpOffloadDecodingAudioProvider()
: A2dpOffloadAudioProvider() {
A2dpOffloadDecodingAudioProvider::A2dpOffloadDecodingAudioProvider(
const A2dpOffloadCodecFactory& codec_factory)
: A2dpOffloadAudioProvider(codec_factory) {
session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH;
}
A2dpOffloadAudioProvider::A2dpOffloadAudioProvider() {}
A2dpOffloadAudioProvider::A2dpOffloadAudioProvider(
const A2dpOffloadCodecFactory& codec_factory)
: codec_factory_(codec_factory) {}
bool A2dpOffloadAudioProvider::isValid(const SessionType& session_type) {
return (session_type == session_type_);
@ -56,17 +59,29 @@ ndk::ScopedAStatus A2dpOffloadAudioProvider::startSession(
auto a2dp_config = audio_config.get<AudioConfiguration::Tag::a2dp>();
A2dpStatus a2dp_status = A2dpStatus::NOT_SUPPORTED_CODEC_TYPE;
if (a2dp_config.codecId ==
A2dpOffloadCodecSbc::GetInstance()->GetCodecId()) {
SbcParameters sbc_parameters;
a2dp_status = A2dpOffloadCodecSbc::GetInstance()->ParseConfiguration(
a2dp_config.configuration, &sbc_parameters);
auto codec = codec_factory_.GetCodec(a2dp_config.codecId);
if (!codec) {
LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
<< " - CodecId=" << a2dp_config.codecId.toString()
<< " is not found";
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
}
} else if (a2dp_config.codecId ==
A2dpOffloadCodecAac::GetInstance()->GetCodecId()) {
if (codec->info.id == CodecId(CodecId::A2dp::SBC)) {
SbcParameters sbc_parameters;
auto codec_sbc =
std::static_pointer_cast<const A2dpOffloadCodecSbc>(codec);
a2dp_status = codec_sbc->ParseConfiguration(a2dp_config.configuration,
&sbc_parameters);
} else if (codec->info.id == CodecId(CodecId::A2dp::AAC)) {
AacParameters aac_parameters;
a2dp_status = A2dpOffloadCodecAac::GetInstance()->ParseConfiguration(
a2dp_config.configuration, &aac_parameters);
auto codec_aac =
std::static_pointer_cast<const A2dpOffloadCodecAac>(codec);
a2dp_status = codec_aac->ParseConfiguration(a2dp_config.configuration,
&aac_parameters);
}
if (a2dp_status != A2dpStatus::OK) {
LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
@ -105,7 +120,7 @@ ndk::ScopedAStatus A2dpOffloadAudioProvider::onSessionReady(
ndk::ScopedAStatus A2dpOffloadAudioProvider::parseA2dpConfiguration(
const CodecId& codec_id, const std::vector<uint8_t>& configuration,
CodecParameters* codec_parameters, A2dpStatus* _aidl_return) {
auto codec = A2dpOffloadCodecFactory::GetInstance()->GetCodec(codec_id);
auto codec = codec_factory_.GetCodec(codec_id);
if (!codec) {
LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
<< " - CodecId=" << codec_id.toString() << " is not found";
@ -124,8 +139,8 @@ ndk::ScopedAStatus A2dpOffloadAudioProvider::getA2dpConfiguration(
*_aidl_return = std::nullopt;
A2dpConfiguration avdtp_configuration;
if (A2dpOffloadCodecFactory::GetInstance()->GetConfiguration(
remote_a2dp_capabilities, hint, &avdtp_configuration))
if (codec_factory_.GetConfiguration(remote_a2dp_capabilities, hint,
&avdtp_configuration))
*_aidl_return =
std::make_optional<A2dpConfiguration>(std::move(avdtp_configuration));

View file

@ -16,6 +16,7 @@
#pragma once
#include "A2dpOffloadCodecFactory.h"
#include "BluetoothAudioProvider.h"
namespace aidl {
@ -26,8 +27,6 @@ namespace audio {
class A2dpOffloadAudioProvider : public BluetoothAudioProvider {
public:
A2dpOffloadAudioProvider();
bool isValid(const SessionType& session_type) override;
ndk::ScopedAStatus startSession(
@ -45,18 +44,23 @@ class A2dpOffloadAudioProvider : public BluetoothAudioProvider {
const A2dpConfigurationHint& hint,
std::optional<audio::A2dpConfiguration>* _aidl_return) override;
protected:
A2dpOffloadAudioProvider(const A2dpOffloadCodecFactory&);
private:
const A2dpOffloadCodecFactory& codec_factory_;
ndk::ScopedAStatus onSessionReady(DataMQDesc* _aidl_return) override;
};
class A2dpOffloadEncodingAudioProvider : public A2dpOffloadAudioProvider {
public:
A2dpOffloadEncodingAudioProvider();
A2dpOffloadEncodingAudioProvider(const A2dpOffloadCodecFactory&);
};
class A2dpOffloadDecodingAudioProvider : public A2dpOffloadAudioProvider {
public:
A2dpOffloadDecodingAudioProvider();
A2dpOffloadDecodingAudioProvider(const A2dpOffloadCodecFactory&);
};
} // namespace audio

View file

@ -18,10 +18,9 @@
#include <aidl/android/hardware/bluetooth/audio/A2dpStatus.h>
#include <aidl/android/hardware/bluetooth/audio/ChannelMode.h>
#include <aidl/android/hardware/bluetooth/audio/CodecInfo.h>
#include <aidl/android/hardware/bluetooth/audio/CodecParameters.h>
#include "BluetoothAudioProviderFactory.h"
namespace aidl::android::hardware::bluetooth::audio {
class A2dpOffloadCodec {

View file

@ -194,11 +194,6 @@ static ChannelMode GetChannelModeEnum(int channel_mode) {
* AAC Class implementation
*/
const A2dpOffloadCodecAac* A2dpOffloadCodecAac::GetInstance() {
static A2dpOffloadCodecAac instance;
return &instance;
}
A2dpOffloadCodecAac::A2dpOffloadCodecAac()
: A2dpOffloadCodec(info_),
info_({.id = CodecId(CodecId::A2dp::AAC), .name = "AAC"}) {

View file

@ -29,14 +29,12 @@ struct AacParameters : public CodecParameters {
class A2dpOffloadCodecAac : public A2dpOffloadCodec {
CodecInfo info_;
A2dpOffloadCodecAac();
A2dpStatus ParseConfiguration(const std::vector<uint8_t>& configuration,
CodecParameters* codec_parameters,
AacParameters* aac_parameters) const;
public:
static const A2dpOffloadCodecAac* GetInstance();
A2dpOffloadCodecAac();
A2dpStatus ParseConfiguration(
const std::vector<uint8_t>& configuration,

View file

@ -37,20 +37,18 @@ enum : bool {
* Class implementation
*/
const A2dpOffloadCodecFactory* A2dpOffloadCodecFactory::GetInstance() {
static A2dpOffloadCodecFactory instance;
return &instance;
}
A2dpOffloadCodecFactory::A2dpOffloadCodecFactory()
: name("Offload"), codecs(ranked_codecs_) {
ranked_codecs_.reserve(kEnableAac + kEnableSbc);
if (kEnableAac) ranked_codecs_.push_back(A2dpOffloadCodecAac::GetInstance());
if (kEnableSbc) ranked_codecs_.push_back(A2dpOffloadCodecSbc::GetInstance());
if (kEnableAac)
ranked_codecs_.push_back(std::make_shared<A2dpOffloadCodecAac>());
if (kEnableSbc)
ranked_codecs_.push_back(std::make_shared<A2dpOffloadCodecSbc>());
}
const A2dpOffloadCodec* A2dpOffloadCodecFactory::GetCodec(CodecId id) const {
std::shared_ptr<const A2dpOffloadCodec> A2dpOffloadCodecFactory::GetCodec(
CodecId id) const {
auto codec = std::find_if(begin(ranked_codecs_), end(ranked_codecs_),
[&](auto c) { return id == c->info.id; });

View file

@ -16,22 +16,26 @@
#pragma once
#include <aidl/android/hardware/bluetooth/audio/A2dpConfiguration.h>
#include <aidl/android/hardware/bluetooth/audio/A2dpConfigurationHint.h>
#include <aidl/android/hardware/bluetooth/audio/A2dpRemoteCapabilities.h>
#include <memory>
#include "A2dpOffloadCodec.h"
namespace aidl::android::hardware::bluetooth::audio {
class A2dpOffloadCodecFactory {
std::vector<const A2dpOffloadCodec*> ranked_codecs_;
A2dpOffloadCodecFactory();
std::vector<std::shared_ptr<const A2dpOffloadCodec>> ranked_codecs_;
public:
const std::string name;
const std::vector<const A2dpOffloadCodec*>& codecs;
const std::vector<std::shared_ptr<const A2dpOffloadCodec>>& codecs;
static const A2dpOffloadCodecFactory* GetInstance();
A2dpOffloadCodecFactory();
const A2dpOffloadCodec* GetCodec(CodecId id) const;
std::shared_ptr<const A2dpOffloadCodec> GetCodec(CodecId id) const;
bool GetConfiguration(const std::vector<A2dpRemoteCapabilities>&,
const A2dpConfigurationHint& hint,

View file

@ -257,11 +257,6 @@ static uint8_t GetBitpool(const A2dpBits& configuration, int bitrate) {
* SBC Class implementation
*/
const A2dpOffloadCodecSbc* A2dpOffloadCodecSbc::GetInstance() {
static A2dpOffloadCodecSbc instance;
return &instance;
}
A2dpOffloadCodecSbc::A2dpOffloadCodecSbc()
: A2dpOffloadCodec(info_),
info_({.id = CodecId(CodecId::A2dp::SBC), .name = "SBC"}) {

View file

@ -33,14 +33,12 @@ struct SbcParameters : public CodecParameters {
class A2dpOffloadCodecSbc : public A2dpOffloadCodec {
CodecInfo info_;
A2dpOffloadCodecSbc();
A2dpStatus ParseConfiguration(const std::vector<uint8_t>& configuration,
CodecParameters* codec_parameters,
SbcParameters* sbc_parameters) const;
public:
static const A2dpOffloadCodecSbc* GetInstance();
A2dpOffloadCodecSbc();
A2dpStatus ParseConfiguration(
const std::vector<uint8_t>& configuration,

View file

@ -22,7 +22,6 @@
#include <android-base/logging.h>
#include "A2dpOffloadAudioProvider.h"
#include "A2dpOffloadCodecFactory.h"
#include "A2dpSoftwareAudioProvider.h"
#include "BluetoothAudioProvider.h"
#include "HearingAidAudioProvider.h"
@ -53,7 +52,8 @@ ndk::ScopedAStatus BluetoothAudioProviderFactory::openProvider(
provider = ndk::SharedRefBase::make<A2dpSoftwareEncodingAudioProvider>();
break;
case SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH:
provider = ndk::SharedRefBase::make<A2dpOffloadEncodingAudioProvider>();
provider = ndk::SharedRefBase::make<A2dpOffloadEncodingAudioProvider>(
a2dp_offload_codec_factory_);
break;
case SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH:
provider = ndk::SharedRefBase::make<HearingAidAudioProvider>();
@ -82,7 +82,8 @@ ndk::ScopedAStatus BluetoothAudioProviderFactory::openProvider(
provider = ndk::SharedRefBase::make<A2dpSoftwareDecodingAudioProvider>();
break;
case SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH:
provider = ndk::SharedRefBase::make<A2dpOffloadDecodingAudioProvider>();
provider = ndk::SharedRefBase::make<A2dpOffloadDecodingAudioProvider>(
a2dp_offload_codec_factory_);
break;
case SessionType::HFP_SOFTWARE_ENCODING_DATAPATH:
provider = ndk::SharedRefBase::make<HfpSoftwareOutputAudioProvider>();
@ -160,8 +161,8 @@ ndk::ScopedAStatus BluetoothAudioProviderFactory::getProviderInfo(
session_type == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH) {
auto& provider_info = _aidl_return->emplace();
provider_info.name = A2dpOffloadCodecFactory::GetInstance()->name;
for (auto codec : A2dpOffloadCodecFactory::GetInstance()->codecs)
provider_info.name = a2dp_offload_codec_factory_.name;
for (auto codec : a2dp_offload_codec_factory_.codecs)
provider_info.codecInfos.push_back(codec->info);
}

View file

@ -18,6 +18,8 @@
#include <aidl/android/hardware/bluetooth/audio/BnBluetoothAudioProviderFactory.h>
#include "A2dpOffloadCodecFactory.h"
namespace aidl {
namespace android {
namespace hardware {
@ -25,6 +27,8 @@ namespace bluetooth {
namespace audio {
class BluetoothAudioProviderFactory : public BnBluetoothAudioProviderFactory {
const A2dpOffloadCodecFactory a2dp_offload_codec_factory_;
public:
BluetoothAudioProviderFactory();