Template and schema of HFP provider info

Bug: 322280104
Test: make
Change-Id: Iac4f96db08b3b7fb2c5f0b080ba3e972e6020982
This commit is contained in:
Bao Do 2024-01-29 17:50:34 +08:00
parent 4fbb997e17
commit 2fa1ab4bd5
13 changed files with 319 additions and 3 deletions

View file

@ -39,6 +39,9 @@ namespace audio {
static const std::string kLeAudioOffloadProviderName =
"LE_AUDIO_OFFLOAD_HARDWARE_OFFLOAD_PROVIDER";
static const std::string kHfpOffloadProviderName =
"HFP_OFFLOAD_HARDWARE_OFFLOAD_PROVIDER";
BluetoothAudioProviderFactory::BluetoothAudioProviderFactory() {}
ndk::ScopedAStatus BluetoothAudioProviderFactory::openProvider(
@ -170,6 +173,7 @@ ndk::ScopedAStatus BluetoothAudioProviderFactory::getProviderInfo(
provider_info.name = a2dp_offload_codec_factory_.name;
for (auto codec : a2dp_offload_codec_factory_.codecs)
provider_info.codecInfos.push_back(codec->info);
return ndk::ScopedAStatus::ok();
}
if (session_type ==
@ -184,12 +188,23 @@ ndk::ScopedAStatus BluetoothAudioProviderFactory::getProviderInfo(
auto& provider_info = _aidl_return->emplace();
provider_info.name = kLeAudioOffloadProviderName;
provider_info.codecInfos = db_codec_info;
*_aidl_return = provider_info;
return ndk::ScopedAStatus::ok();
}
}
return ndk::ScopedAStatus::ok();
if (session_type == SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH) {
std::vector<CodecInfo> db_codec_info =
BluetoothAudioCodecs::GetHfpOffloadCodecInfo();
if (!db_codec_info.empty()) {
auto& provider_info = _aidl_return->emplace();
provider_info.name = kHfpOffloadProviderName;
provider_info.codecInfos = db_codec_info;
return ndk::ScopedAStatus::ok();
}
}
// Unsupported for other sessions
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
} // namespace audio

View file

@ -1944,6 +1944,7 @@ class BluetoothAudioProviderHfpHardwareAidl
BluetoothAudioHalVersion::VERSION_AIDL_V4) {
GTEST_SKIP();
}
GetProviderInfoHelper(SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH);
OpenProviderHelper(SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH);
// Can open or empty capability
ASSERT_TRUE(temp_provider_capabilities_.empty() ||

View file

@ -42,6 +42,7 @@ cc_library_shared {
"aidl_session/BluetoothAudioSession.cpp",
"aidl_session/HidlToAidlMiddleware.cpp",
"aidl_session/BluetoothLeAudioCodecsProvider.cpp",
"aidl_session/BluetoothHfpCodecsProvider.cpp",
"aidl_session/BluetoothLeAudioAseConfigurationSettingProvider.cpp",
],
export_include_dirs: ["aidl_session/"],
@ -68,9 +69,13 @@ cc_library_shared {
static_libs: [
"btaudiohal_flags_c_lib",
],
generated_sources: ["le_audio_codec_capabilities"],
generated_sources: [
"le_audio_codec_capabilities",
"hfp_codec_capabilities",
],
generated_headers: [
"le_audio_codec_capabilities",
"hfp_codec_capabilities",
"AIDLLeAudioSetConfigSchemas_h",
],
required: [
@ -78,9 +83,12 @@ cc_library_shared {
"aidl_audio_set_configurations_json",
"aidl_audio_set_scenarios_bfbs",
"aidl_audio_set_scenarios_json",
"hfp_codec_capabilities_xml",
],
}
// TODO: Write test for BluetoothHfpCodecsProvider.cpp
cc_test {
name: "BluetoothLeAudioCodecsProviderTest",
srcs: [
@ -114,6 +122,14 @@ xsd_config {
root_elements: ["leAudioOffloadSetting"],
}
xsd_config {
name: "hfp_codec_capabilities",
srcs: ["hfp_codec_capabilities/hfp_codec_capabilities.xsd"],
package_name: "aidl.android.hardware.bluetooth.audio.hfp.setting",
api_dir: "hfp_codec_capabilities/schema",
root_elements: ["hfpOffloadSetting"],
}
genrule {
name: "AIDLLeAudioSetConfigSchemas_h",
tools: [
@ -176,6 +192,14 @@ prebuilt_etc {
vendor: true,
}
prebuilt_etc {
name: "hfp_codec_capabilities_xml",
src: "hfp_codec_capabilities/hfp_codec_capabilities.xml",
filename: "hfp_codec_capabilities.xml",
sub_dir: "aidl/hfp",
vendor: true,
}
prebuilt_etc {
name: "aidl_audio_set_configurations_bfbs",
src: ":AIDLLeAudioSetConfigsSchema_bfbs",

View file

@ -32,6 +32,7 @@
#include <aidl/android/hardware/bluetooth/audio/SbcChannelMode.h>
#include <android-base/logging.h>
#include "BluetoothHfpCodecsProvider.h"
#include "BluetoothLeAudioAseConfigurationSettingProvider.h"
#include "BluetoothLeAudioCodecsProvider.h"
@ -100,6 +101,7 @@ const std::vector<CodecCapabilities> kDefaultOffloadA2dpCodecCapabilities = {
std::vector<LeAudioCodecCapabilitiesSetting> kDefaultOffloadLeAudioCapabilities;
std::unordered_map<SessionType, std::vector<CodecInfo>>
kDefaultOffloadLeAudioCodecInfoMap;
std::vector<CodecInfo> kDefaultOffloadHfpCodecInfo;
template <class T>
bool BluetoothAudioCodecs::ContainedInVector(
@ -439,6 +441,17 @@ std::vector<CodecInfo> BluetoothAudioCodecs::GetLeAudioOffloadCodecInfo(
return codec_info_map_iter->second;
}
std::vector<CodecInfo> BluetoothAudioCodecs::GetHfpOffloadCodecInfo() {
if (kDefaultOffloadHfpCodecInfo.empty()) {
auto hfp_offload_setting =
BluetoothHfpCodecsProvider::ParseFromHfpOffloadSettingFile();
// Load file into list
kDefaultOffloadHfpCodecInfo =
BluetoothHfpCodecsProvider::GetHfpAudioCodecInfo(hfp_offload_setting);
}
return kDefaultOffloadHfpCodecInfo;
}
std::vector<LeAudioAseConfigurationSetting>
BluetoothAudioCodecs::GetLeAudioAseConfigurationSettings() {
return AudioSetConfigurationProviderJson::

View file

@ -57,6 +57,8 @@ class BluetoothAudioCodecs {
static std::vector<LeAudioAseConfigurationSetting>
GetLeAudioAseConfigurationSettings();
static std::vector<CodecInfo> GetHfpOffloadCodecInfo();
private:
template <typename T>
struct identity {

View file

@ -0,0 +1,40 @@
/*
* Copyright (C) 2024 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.
*/
#include "BluetoothHfpCodecsProvider.h"
namespace aidl {
namespace android {
namespace hardware {
namespace bluetooth {
namespace audio {
std::optional<HfpOffloadSetting>
BluetoothHfpCodecsProvider::ParseFromHfpOffloadSettingFile() {
return std::nullopt;
}
std::vector<CodecInfo> BluetoothHfpCodecsProvider::GetHfpAudioCodecInfo(
const std::optional<HfpOffloadSetting>& hfp_offload_setting) {
(void)hfp_offload_setting;
return std::vector<CodecInfo>();
}
} // namespace audio
} // namespace bluetooth
} // namespace hardware
} // namespace android
} // namespace aidl

View file

@ -0,0 +1,45 @@
/*
* Copyright (C) 2024 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-base/logging.h>
#include <vector>
#include "aidl/android/hardware/bluetooth/audio/CodecInfo.h"
#include "aidl_android_hardware_bluetooth_audio_hfp_setting.h"
namespace aidl {
namespace android {
namespace hardware {
namespace bluetooth {
namespace audio {
using hfp::setting::HfpOffloadSetting;
class BluetoothHfpCodecsProvider {
public:
static std::optional<HfpOffloadSetting> ParseFromHfpOffloadSettingFile();
static std::vector<CodecInfo> GetHfpAudioCodecInfo(
const std::optional<HfpOffloadSetting>& hfp_offload_setting);
};
} // namespace audio
} // namespace bluetooth
} // namespace hardware
} // namespace android
} // namespace aidl

View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!---
This is an example to configure HFP hardware offload supported capability settings
There are 3 list in this file. Add element into each list as needed.
pathConfiguration: input / output path configuration
transportConfiguration: transmit / receive configuration
configuration:
For each configuration, there are attributes:
- name
- codec
- useControllerCodec
- maxLatencyMs
- packetTypes
- retransmissionEffort
- input and output path configuration (reference by name)
- transmit and receive configuration (reference by name)
-->
<hfpOffloadSetting>
<pathConfiguration name="CVSD_IO" bandwidth="16000" codec="CVSD" codedDataSize="16" pcmDataFormat="2" pcmPayloadMsbPosition="0" dataPath="1" transportUnitSize="0" />
<pathConfiguration name="MSBC_IO" bandwidth="32000" codec="MSBC" codedDataSize="16" pcmDataFormat="2" pcmPayloadMsbPosition="0" dataPath="1" transportUnitSize="0" />
<pathConfiguration name="LC3_IO" bandwidth="64000" codec="MSBC" codedDataSize="16" pcmDataFormat="2" pcmPayloadMsbPosition="0" dataPath="1" transportUnitSize="0" />
<transportConfiguration name="CVSD_TXRX" bandwidth="8000" codec="CVSD" codedFrameSize="60" />
<transportConfiguration name="MSBC_TXRX" bandwidth="8000" codec="MSBC" codedFrameSize="60" />
<transportConfiguration name="LC3_TXRX" bandwidth="8000" codec="LC3" codedFrameSize="60" />
<configuration name="CVSD_D1_controller" codec="CVSD" maxLatencyMs="65535" packetTypes="7" retransmissionEffort="0" useControllerCodec="true" inputPathConfiguration="CVSD_IO" outputPathConfiguration="CVSD_IO" inputTransportConfiguration="CVSD_TXRX" outTransportConfiguration="CVSD_TXRX" />
<configuration name="CVSD_S3_controller" codec="CVSD" maxLatencyMs="10" packetTypes="959" retransmissionEffort="1" useControllerCodec="true" inputPathConfiguration="CVSD_IO" outputPathConfiguration="CVSD_IO" inputTransportConfiguration="CVSD_TXRX" outTransportConfiguration="CVSD_TXRX" />
<configuration name="CVSD_S4_controller" codec="CVSD" maxLatencyMs="12" packetTypes="959" retransmissionEffort="2" useControllerCodec="true" inputPathConfiguration="CVSD_IO" outputPathConfiguration="CVSD_IO" inputTransportConfiguration="CVSD_TXRX" outTransportConfiguration="CVSD_TXRX" />
<configuration name="MSBC_T1_controller" codec="MSBC" maxLatencyMs="8" packetTypes="968" retransmissionEffort="2" useControllerCodec="true" inputPathConfiguration="MSBC_IO" outputPathConfiguration="MSBC_IO" inputTransportConfiguration="MSBC_TXRX" outTransportConfiguration="MSBC_TXRX" />
<configuration name="MSBC_T2_controller" codec="MSBC" maxLatencyMs="13" packetTypes="904" retransmissionEffort="2" useControllerCodec="true" inputPathConfiguration="MSBC_IO" outputPathConfiguration="MSBC_IO" inputTransportConfiguration="MSBC_TXRX" outTransportConfiguration="MSBC_TXRX" />
<configuration name="LC3_T1_controller" codec="LC3" maxLatencyMs="8" packetTypes="968" retransmissionEffort="2" useControllerCodec="true" inputPathConfiguration="LC3_IO" outputPathConfiguration="LC3_IO" inputTransportConfiguration="LC3_TXRX" outTransportConfiguration="LC3_TXRX" />
<configuration name="LC3_T2_controller" codec="LC3" maxLatencyMs="13" packetTypes="896" retransmissionEffort="2" useControllerCodec="true" inputPathConfiguration="LC3_IO" outputPathConfiguration="LC3_IO" inputTransportConfiguration="LC3_TXRX" outTransportConfiguration="LC3_TXRX" />
</hfpOffloadSetting>

View file

@ -0,0 +1,51 @@
<!-- HFP Offload Codec Capability Schema -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="hfpOffloadSetting">
<xs:complexType>
<xs:element ref="pathConfiguration" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="transportConfiguration" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="configuration" minOccurs="1" maxOccurs="unbounded"/>
</xs:complexType>
</xs:element>
<xs:element name="pathConfiguration">
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="bandwidth" type="xs:unsignedInt"/>
<xs:attribute name="codec" type="codecType"/>
<xs:attribute name="codedDataSize" type="xs:unsignedShort"/>
<xs:attribute name="pcmDataFormat" type="xs:unsignedByte"/>
<xs:attribute name="pcmPayloadMsbPosition" type="xs:unsignedByte"/>
<xs:attribute name="dataPath" type="xs:unsignedByte"/>
<xs:attribute name="transportUnitSize" type="xs:unsignedByte"/>
</xs:complexType>
</xs:element>
<xs:element name="transportConfiguration">
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="bandwidth" type="xs:unsignedInt"/>
<xs:attribute name="codec" type="codecType"/>
<xs:attribute name="codedFrameSize" type="xs:unsignedShort"/>
</xs:complexType>
</xs:element>
<xs:element name="configuration">
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="codec" type="codecType"/>
<xs:attribute name="maxLatencyMs" type="xs:unsignedShort"/>
<xs:attribute name="packetTypes" type="xs:unsignedShort"/>
<xs:attribute name="retransmissionEffort" type="xs:unsignedByte"/>
<xs:attribute name="useControllerCodec" type="xs:boolean"/>
<xs:attribute name="inputPathConfiguration" type="xs:string"/>
<xs:attribute name="outputPathConfiguration" type="xs:string"/>
<xs:attribute name="inputTransportConfiguration" type="xs:string"/>
<xs:attribute name="outputTransportConfiguration" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:simpleType name="codecType">
<xs:restriction base="xs:string">
<xs:enumeration value="LC3"/>
<xs:enumeration value="CVSD"/>
<xs:enumeration value="MSBC"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View file

@ -0,0 +1,82 @@
// Signature format: 2.0
package aidl.android.hardware.bluetooth.audio.hfp.setting {
public enum CodecType {
method public String getRawName();
enum_constant public static final aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType CVSD;
enum_constant public static final aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType LC3;
enum_constant public static final aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType MSBC;
}
public class Configuration {
ctor public Configuration();
method public aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType getCodec();
method public String getInputPathConfiguration();
method public String getInputTransportConfiguration();
method public int getMaxLatencyMs();
method public String getName();
method public String getOutputPathConfiguration();
method public String getOutputTransportConfiguration();
method public int getPacketTypes();
method public short getRetransmissionEffort();
method public boolean getUseControllerCodec();
method public void setCodec(aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType);
method public void setInputPathConfiguration(String);
method public void setInputTransportConfiguration(String);
method public void setMaxLatencyMs(int);
method public void setName(String);
method public void setOutputPathConfiguration(String);
method public void setOutputTransportConfiguration(String);
method public void setPacketTypes(int);
method public void setRetransmissionEffort(short);
method public void setUseControllerCodec(boolean);
}
public class HfpOffloadSetting {
ctor public HfpOffloadSetting();
method public java.util.List<aidl.android.hardware.bluetooth.audio.hfp.setting.Configuration> getConfiguration();
method public java.util.List<aidl.android.hardware.bluetooth.audio.hfp.setting.PathConfiguration> getPathConfiguration();
method public java.util.List<aidl.android.hardware.bluetooth.audio.hfp.setting.TransportConfiguration> getTransportConfiguration();
}
public class PathConfiguration {
ctor public PathConfiguration();
method public long getBandwidth();
method public aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType getCodec();
method public int getCodedDataSize();
method public short getDataPath();
method public String getName();
method public short getPcmDataFormat();
method public short getPcmPayloadMsbPosition();
method public short getTransportUnitSize();
method public void setBandwidth(long);
method public void setCodec(aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType);
method public void setCodedDataSize(int);
method public void setDataPath(short);
method public void setName(String);
method public void setPcmDataFormat(short);
method public void setPcmPayloadMsbPosition(short);
method public void setTransportUnitSize(short);
}
public class TransportConfiguration {
ctor public TransportConfiguration();
method public long getBandwidth();
method public aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType getCodec();
method public int getCodedFrameSize();
method public String getName();
method public void setBandwidth(long);
method public void setCodec(aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType);
method public void setCodedFrameSize(int);
method public void setName(String);
}
public class XmlParser {
ctor public XmlParser();
method public static aidl.android.hardware.bluetooth.audio.hfp.setting.HfpOffloadSetting readHfpOffloadSetting(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public static String readText(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public static void skip(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
}
}

View file

@ -0,0 +1 @@
// Signature format: 2.0