Merge changes from topic "revert-2770886-AidlAudioHalModuleConfig-FQCMWOWMCH" into main am: 03a2fbc6a3
am: fb1d459f09
am: 9868600b48
am: 9ed9a05578
am: 0cfcc0f2f9
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2786757 Change-Id: I6b5a7c2db6ee69a63abc9897bb9c1716157f641e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
1261ff4f9b
25 changed files with 412 additions and 795 deletions
|
@ -12,7 +12,6 @@ cc_defaults {
|
|||
vendor: true,
|
||||
shared_libs: [
|
||||
"libalsautilsv2",
|
||||
"libaudio_aidl_conversion_common_ndk",
|
||||
"libaudioaidlcommon",
|
||||
"libaudioutils",
|
||||
"libbase",
|
||||
|
@ -20,8 +19,6 @@ cc_defaults {
|
|||
"libcutils",
|
||||
"libfmq",
|
||||
"libnbaio_mono",
|
||||
"liblog",
|
||||
"libmedia_helper",
|
||||
"libstagefright_foundation",
|
||||
"libtinyalsav2",
|
||||
"libutils",
|
||||
|
@ -34,9 +31,6 @@ cc_defaults {
|
|||
"libaudioaidl_headers",
|
||||
"libxsdc-utils",
|
||||
],
|
||||
cflags: [
|
||||
"-DBACKEND_NDK",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
|
@ -93,7 +87,6 @@ cc_library {
|
|||
"Stream.cpp",
|
||||
"StreamSwitcher.cpp",
|
||||
"Telephony.cpp",
|
||||
"XsdcConversion.cpp",
|
||||
"alsa/Mixer.cpp",
|
||||
"alsa/ModuleAlsa.cpp",
|
||||
"alsa/StreamAlsa.cpp",
|
||||
|
@ -194,7 +187,6 @@ cc_test {
|
|||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"libcutils",
|
||||
"libfmq",
|
||||
"libmedia_helper",
|
||||
"libstagefright_foundation",
|
||||
"libutils",
|
||||
|
@ -207,11 +199,9 @@ cc_test {
|
|||
],
|
||||
generated_sources: [
|
||||
"audio_policy_configuration_aidl_default",
|
||||
"audio_policy_engine_configuration_aidl_default",
|
||||
],
|
||||
generated_headers: [
|
||||
"audio_policy_configuration_aidl_default",
|
||||
"audio_policy_engine_configuration_aidl_default",
|
||||
],
|
||||
srcs: [
|
||||
"AudioPolicyConfigXmlConverter.cpp",
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
|
||||
#include "core-impl/AidlConversionXsdc.h"
|
||||
#include "core-impl/AudioPolicyConfigXmlConverter.h"
|
||||
#include "core-impl/XsdcConversion.h"
|
||||
|
||||
using aidl::android::media::audio::common::AudioFormatDescription;
|
||||
using aidl::android::media::audio::common::AudioHalEngineConfig;
|
||||
|
@ -38,39 +37,60 @@ using aidl::android::media::audio::common::AudioHalVolumeCurve;
|
|||
using aidl::android::media::audio::common::AudioHalVolumeGroup;
|
||||
using aidl::android::media::audio::common::AudioStreamType;
|
||||
|
||||
namespace ap_xsd = android::audio::policy::configuration;
|
||||
namespace xsd = android::audio::policy::configuration;
|
||||
|
||||
namespace aidl::android::hardware::audio::core::internal {
|
||||
|
||||
static const int kDefaultVolumeIndexMin = 0;
|
||||
static const int kDefaultVolumeIndexMax = 100;
|
||||
static const int KVolumeIndexDeferredToAudioService = -1;
|
||||
/**
|
||||
* Valid curve points take the form "<index>,<attenuationMb>", where the index
|
||||
* must be in the range [0,100]. kInvalidCurvePointIndex is used to indicate
|
||||
* that a point was formatted incorrectly (e.g. if a vendor accidentally typed a
|
||||
* '.' instead of a ',' in their XML) -- using such a curve point will result in
|
||||
* failed VTS tests.
|
||||
*/
|
||||
static const int8_t kInvalidCurvePointIndex = -1;
|
||||
|
||||
ConversionResult<AudioHalVolumeCurve> AudioPolicyConfigXmlConverter::convertVolumeCurveToAidl(
|
||||
const ap_xsd::Volume& xsdcVolumeCurve) {
|
||||
AudioHalVolumeCurve::CurvePoint AudioPolicyConfigXmlConverter::convertCurvePointToAidl(
|
||||
const std::string& xsdcCurvePoint) {
|
||||
AudioHalVolumeCurve::CurvePoint aidlCurvePoint{};
|
||||
if (sscanf(xsdcCurvePoint.c_str(), "%" SCNd8 ",%d", &aidlCurvePoint.index,
|
||||
&aidlCurvePoint.attenuationMb) != 2) {
|
||||
aidlCurvePoint.index = kInvalidCurvePointIndex;
|
||||
}
|
||||
return aidlCurvePoint;
|
||||
}
|
||||
|
||||
AudioHalVolumeCurve AudioPolicyConfigXmlConverter::convertVolumeCurveToAidl(
|
||||
const xsd::Volume& xsdcVolumeCurve) {
|
||||
AudioHalVolumeCurve aidlVolumeCurve;
|
||||
aidlVolumeCurve.deviceCategory =
|
||||
static_cast<AudioHalVolumeCurve::DeviceCategory>(xsdcVolumeCurve.getDeviceCategory());
|
||||
if (xsdcVolumeCurve.hasRef()) {
|
||||
if (mVolumesReferenceMap.empty()) {
|
||||
mVolumesReferenceMap = generateReferenceMap<ap_xsd::Volumes, ap_xsd::Reference>(
|
||||
mVolumesReferenceMap = generateReferenceMap<xsd::Volumes, xsd::Reference>(
|
||||
getXsdcConfig()->getVolumes());
|
||||
}
|
||||
aidlVolumeCurve.curvePoints = VALUE_OR_FATAL(
|
||||
(convertCollectionToAidl<std::string, AudioHalVolumeCurve::CurvePoint>(
|
||||
aidlVolumeCurve.curvePoints =
|
||||
convertCollectionToAidlUnchecked<std::string, AudioHalVolumeCurve::CurvePoint>(
|
||||
mVolumesReferenceMap.at(xsdcVolumeCurve.getRef()).getPoint(),
|
||||
&convertCurvePointToAidl)));
|
||||
std::bind(&AudioPolicyConfigXmlConverter::convertCurvePointToAidl, this,
|
||||
std::placeholders::_1));
|
||||
} else {
|
||||
aidlVolumeCurve.curvePoints = VALUE_OR_FATAL(
|
||||
(convertCollectionToAidl<std::string, AudioHalVolumeCurve::CurvePoint>(
|
||||
xsdcVolumeCurve.getPoint(), &convertCurvePointToAidl)));
|
||||
aidlVolumeCurve.curvePoints =
|
||||
convertCollectionToAidlUnchecked<std::string, AudioHalVolumeCurve::CurvePoint>(
|
||||
xsdcVolumeCurve.getPoint(),
|
||||
std::bind(&AudioPolicyConfigXmlConverter::convertCurvePointToAidl, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
return aidlVolumeCurve;
|
||||
}
|
||||
|
||||
void AudioPolicyConfigXmlConverter::mapStreamToVolumeCurve(const ap_xsd::Volume& xsdcVolumeCurve) {
|
||||
void AudioPolicyConfigXmlConverter::mapStreamToVolumeCurve(const xsd::Volume& xsdcVolumeCurve) {
|
||||
mStreamToVolumeCurvesMap[xsdcVolumeCurve.getStream()].push_back(
|
||||
VALUE_OR_FATAL(convertVolumeCurveToAidl(xsdcVolumeCurve)));
|
||||
convertVolumeCurveToAidl(xsdcVolumeCurve));
|
||||
}
|
||||
|
||||
const SurroundSoundConfig& AudioPolicyConfigXmlConverter::getSurroundSoundConfig() {
|
||||
|
@ -89,11 +109,6 @@ const SurroundSoundConfig& AudioPolicyConfigXmlConverter::getSurroundSoundConfig
|
|||
return aidlSurroundSoundConfig;
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioPolicyConfigXmlConverter::ModuleConfigs>
|
||||
AudioPolicyConfigXmlConverter::releaseModuleConfigs() {
|
||||
return std::move(mModuleConfigurations);
|
||||
}
|
||||
|
||||
const AudioHalEngineConfig& AudioPolicyConfigXmlConverter::getAidlEngineConfig() {
|
||||
if (mAidlEngineConfig.volumeGroups.empty() && getXsdcConfig() &&
|
||||
getXsdcConfig()->hasVolumes()) {
|
||||
|
@ -145,8 +160,8 @@ const SurroundSoundConfig& AudioPolicyConfigXmlConverter::getDefaultSurroundSoun
|
|||
|
||||
void AudioPolicyConfigXmlConverter::mapStreamsToVolumeCurves() {
|
||||
if (getXsdcConfig()->hasVolumes()) {
|
||||
for (const ap_xsd::Volumes& xsdcWrapperType : getXsdcConfig()->getVolumes()) {
|
||||
for (const ap_xsd::Volume& xsdcVolume : xsdcWrapperType.getVolume()) {
|
||||
for (const xsd::Volumes& xsdcWrapperType : getXsdcConfig()->getVolumes()) {
|
||||
for (const xsd::Volume& xsdcVolume : xsdcWrapperType.getVolume()) {
|
||||
mapStreamToVolumeCurve(xsdcVolume);
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +171,7 @@ void AudioPolicyConfigXmlConverter::mapStreamsToVolumeCurves() {
|
|||
void AudioPolicyConfigXmlConverter::addVolumeGroupstoEngineConfig() {
|
||||
for (const auto& [xsdcStream, volumeCurves] : mStreamToVolumeCurvesMap) {
|
||||
AudioHalVolumeGroup volumeGroup;
|
||||
volumeGroup.name = ap_xsd::toString(xsdcStream);
|
||||
volumeGroup.name = xsd::toString(xsdcStream);
|
||||
if (static_cast<int>(xsdcStream) >= AUDIO_STREAM_PUBLIC_CNT) {
|
||||
volumeGroup.minIndex = kDefaultVolumeIndexMin;
|
||||
volumeGroup.maxIndex = kDefaultVolumeIndexMax;
|
||||
|
@ -175,18 +190,4 @@ void AudioPolicyConfigXmlConverter::parseVolumes() {
|
|||
addVolumeGroupstoEngineConfig();
|
||||
}
|
||||
}
|
||||
|
||||
void AudioPolicyConfigXmlConverter::init() {
|
||||
if (!getXsdcConfig()->hasModules()) return;
|
||||
for (const ap_xsd::Modules& xsdcModulesType : getXsdcConfig()->getModules()) {
|
||||
if (!xsdcModulesType.has_module()) continue;
|
||||
for (const ap_xsd::Modules::Module& xsdcModule : xsdcModulesType.get_module()) {
|
||||
// 'primary' in the XML schema used by HIDL is equivalent to 'default' module.
|
||||
const std::string name =
|
||||
xsdcModule.getName() != "primary" ? xsdcModule.getName() : "default";
|
||||
mModuleConfigurations->emplace_back(
|
||||
name, VALUE_OR_FATAL(convertModuleConfigToAidl(xsdcModule)));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace aidl::android::hardware::audio::core::internal
|
||||
|
|
|
@ -43,7 +43,6 @@ using aidl::android::media::audio::common::AudioProfile;
|
|||
using aidl::android::media::audio::common::Int;
|
||||
using aidl::android::media::audio::common::MicrophoneInfo;
|
||||
using aidl::android::media::audio::common::PcmType;
|
||||
using Configuration = aidl::android::hardware::audio::core::Module::Configuration;
|
||||
|
||||
namespace aidl::android::hardware::audio::core::internal {
|
||||
|
||||
|
@ -678,19 +677,4 @@ std::unique_ptr<Configuration> getBluetoothConfiguration() {
|
|||
return std::make_unique<Configuration>(configuration);
|
||||
}
|
||||
|
||||
std::unique_ptr<Module::Configuration> getConfiguration(Module::Type moduleType) {
|
||||
switch (moduleType) {
|
||||
case Module::Type::DEFAULT:
|
||||
return getPrimaryConfiguration();
|
||||
case Module::Type::R_SUBMIX:
|
||||
return getRSubmixConfiguration();
|
||||
case Module::Type::STUB:
|
||||
return getStubConfiguration();
|
||||
case Module::Type::USB:
|
||||
return getUsbConfiguration();
|
||||
case Module::Type::BLUETOOTH:
|
||||
return getBluetoothConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::audio::core::internal
|
||||
|
|
|
@ -20,14 +20,11 @@
|
|||
#include <functional>
|
||||
#include <unordered_map>
|
||||
|
||||
#define LOG_TAG "AHAL_Config"
|
||||
#include <aidl/android/media/audio/common/AudioFlag.h>
|
||||
#include <aidl/android/media/audio/common/AudioHalEngineConfig.h>
|
||||
#include <aidl/android/media/audio/common/AudioProductStrategyType.h>
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include "core-impl/EngineConfigXmlConverter.h"
|
||||
#include "core-impl/XsdcConversion.h"
|
||||
|
||||
using aidl::android::media::audio::common::AudioAttributes;
|
||||
using aidl::android::media::audio::common::AudioContentType;
|
||||
|
@ -43,13 +40,20 @@ using aidl::android::media::audio::common::AudioProductStrategyType;
|
|||
using aidl::android::media::audio::common::AudioSource;
|
||||
using aidl::android::media::audio::common::AudioStreamType;
|
||||
using aidl::android::media::audio::common::AudioUsage;
|
||||
using ::android::BAD_VALUE;
|
||||
using ::android::base::unexpected;
|
||||
|
||||
namespace eng_xsd = android::audio::policy::engine::configuration;
|
||||
namespace xsd = android::audio::policy::engine::configuration;
|
||||
|
||||
namespace aidl::android::hardware::audio::core::internal {
|
||||
|
||||
/**
|
||||
* Valid curve points take the form "<index>,<attenuationMb>", where the index
|
||||
* must be in the range [0,100]. kInvalidCurvePointIndex is used to indicate
|
||||
* that a point was formatted incorrectly (e.g. if a vendor accidentally typed a
|
||||
* '.' instead of a ',' in their XML)-- using such a curve point will result in
|
||||
* failed VTS tests.
|
||||
*/
|
||||
static const int8_t kInvalidCurvePointIndex = -1;
|
||||
|
||||
void EngineConfigXmlConverter::initProductStrategyMap() {
|
||||
#define STRATEGY_ENTRY(name) {"STRATEGY_" #name, static_cast<int>(AudioProductStrategyType::name)}
|
||||
|
||||
|
@ -64,7 +68,7 @@ void EngineConfigXmlConverter::initProductStrategyMap() {
|
|||
#undef STRATEGY_ENTRY
|
||||
}
|
||||
|
||||
ConversionResult<int> EngineConfigXmlConverter::convertProductStrategyNameToAidl(
|
||||
int EngineConfigXmlConverter::convertProductStrategyNameToAidl(
|
||||
const std::string& xsdcProductStrategyName) {
|
||||
const auto [it, success] = mProductStrategyMap.insert(
|
||||
std::make_pair(xsdcProductStrategyName, mNextVendorStrategy));
|
||||
|
@ -81,12 +85,12 @@ bool isDefaultAudioAttributes(const AudioAttributes& attributes) {
|
|||
(attributes.tags.empty()));
|
||||
}
|
||||
|
||||
ConversionResult<AudioAttributes> EngineConfigXmlConverter::convertAudioAttributesToAidl(
|
||||
const eng_xsd::AttributesType& xsdcAudioAttributes) {
|
||||
AudioAttributes EngineConfigXmlConverter::convertAudioAttributesToAidl(
|
||||
const xsd::AttributesType& xsdcAudioAttributes) {
|
||||
if (xsdcAudioAttributes.hasAttributesRef()) {
|
||||
if (mAttributesReferenceMap.empty()) {
|
||||
mAttributesReferenceMap =
|
||||
generateReferenceMap<eng_xsd::AttributesRef, eng_xsd::AttributesRefType>(
|
||||
generateReferenceMap<xsd::AttributesRef, xsd::AttributesRefType>(
|
||||
getXsdcConfig()->getAttributesRef());
|
||||
}
|
||||
return convertAudioAttributesToAidl(
|
||||
|
@ -107,16 +111,16 @@ ConversionResult<AudioAttributes> EngineConfigXmlConverter::convertAudioAttribut
|
|||
static_cast<AudioSource>(xsdcAudioAttributes.getFirstSource()->getValue());
|
||||
}
|
||||
if (xsdcAudioAttributes.hasFlags()) {
|
||||
std::vector<eng_xsd::FlagType> xsdcFlagTypeVec =
|
||||
std::vector<xsd::FlagType> xsdcFlagTypeVec =
|
||||
xsdcAudioAttributes.getFirstFlags()->getValue();
|
||||
for (const eng_xsd::FlagType& xsdcFlagType : xsdcFlagTypeVec) {
|
||||
if (xsdcFlagType != eng_xsd::FlagType::AUDIO_FLAG_NONE) {
|
||||
for (const xsd::FlagType& xsdcFlagType : xsdcFlagTypeVec) {
|
||||
if (xsdcFlagType != xsd::FlagType::AUDIO_FLAG_NONE) {
|
||||
aidlAudioAttributes.flags |= 1 << (static_cast<int>(xsdcFlagType) - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (xsdcAudioAttributes.hasBundle()) {
|
||||
const eng_xsd::BundleType* xsdcBundle = xsdcAudioAttributes.getFirstBundle();
|
||||
const xsd::BundleType* xsdcBundle = xsdcAudioAttributes.getFirstBundle();
|
||||
aidlAudioAttributes.tags[0] = xsdcBundle->getKey() + "=" + xsdcBundle->getValue();
|
||||
}
|
||||
if (isDefaultAudioAttributes(aidlAudioAttributes)) {
|
||||
|
@ -125,54 +129,53 @@ ConversionResult<AudioAttributes> EngineConfigXmlConverter::convertAudioAttribut
|
|||
return aidlAudioAttributes;
|
||||
}
|
||||
|
||||
ConversionResult<AudioHalAttributesGroup> EngineConfigXmlConverter::convertAttributesGroupToAidl(
|
||||
const eng_xsd::AttributesGroup& xsdcAttributesGroup) {
|
||||
AudioHalAttributesGroup EngineConfigXmlConverter::convertAttributesGroupToAidl(
|
||||
const xsd::AttributesGroup& xsdcAttributesGroup) {
|
||||
AudioHalAttributesGroup aidlAttributesGroup;
|
||||
static const int kStreamTypeEnumOffset =
|
||||
static_cast<int>(eng_xsd::Stream::AUDIO_STREAM_VOICE_CALL) -
|
||||
static_cast<int>(xsd::Stream::AUDIO_STREAM_VOICE_CALL) -
|
||||
static_cast<int>(AudioStreamType::VOICE_CALL);
|
||||
aidlAttributesGroup.streamType = static_cast<AudioStreamType>(
|
||||
static_cast<int>(xsdcAttributesGroup.getStreamType()) - kStreamTypeEnumOffset);
|
||||
aidlAttributesGroup.volumeGroupName = xsdcAttributesGroup.getVolumeGroup();
|
||||
if (xsdcAttributesGroup.hasAttributes_optional()) {
|
||||
aidlAttributesGroup.attributes =
|
||||
VALUE_OR_FATAL((convertCollectionToAidl<eng_xsd::AttributesType, AudioAttributes>(
|
||||
convertCollectionToAidlUnchecked<xsd::AttributesType, AudioAttributes>(
|
||||
xsdcAttributesGroup.getAttributes_optional(),
|
||||
std::bind(&EngineConfigXmlConverter::convertAudioAttributesToAidl, this,
|
||||
std::placeholders::_1))));
|
||||
std::placeholders::_1));
|
||||
} else if (xsdcAttributesGroup.hasContentType_optional() ||
|
||||
xsdcAttributesGroup.hasUsage_optional() ||
|
||||
xsdcAttributesGroup.hasSource_optional() ||
|
||||
xsdcAttributesGroup.hasFlags_optional() ||
|
||||
xsdcAttributesGroup.hasBundle_optional()) {
|
||||
aidlAttributesGroup.attributes.push_back(VALUE_OR_FATAL(convertAudioAttributesToAidl(
|
||||
eng_xsd::AttributesType(xsdcAttributesGroup.getContentType_optional(),
|
||||
xsdcAttributesGroup.getUsage_optional(),
|
||||
xsdcAttributesGroup.getSource_optional(),
|
||||
xsdcAttributesGroup.getFlags_optional(),
|
||||
xsdcAttributesGroup.getBundle_optional(), std::nullopt))));
|
||||
aidlAttributesGroup.attributes.push_back(convertAudioAttributesToAidl(xsd::AttributesType(
|
||||
xsdcAttributesGroup.getContentType_optional(),
|
||||
xsdcAttributesGroup.getUsage_optional(), xsdcAttributesGroup.getSource_optional(),
|
||||
xsdcAttributesGroup.getFlags_optional(), xsdcAttributesGroup.getBundle_optional(),
|
||||
std::nullopt)));
|
||||
|
||||
} else {
|
||||
LOG(ERROR) << __func__ << " Review Audio Policy config: no audio attributes provided for "
|
||||
<< aidlAttributesGroup.toString();
|
||||
return unexpected(BAD_VALUE);
|
||||
// do nothing;
|
||||
// TODO: check if this is valid or if we should treat as an error.
|
||||
// Currently, attributes are not mandatory in schema, but an AttributesGroup
|
||||
// without attributes does not make much sense.
|
||||
}
|
||||
return aidlAttributesGroup;
|
||||
}
|
||||
|
||||
ConversionResult<AudioHalProductStrategy> EngineConfigXmlConverter::convertProductStrategyToAidl(
|
||||
const eng_xsd::ProductStrategies::ProductStrategy& xsdcProductStrategy) {
|
||||
AudioHalProductStrategy EngineConfigXmlConverter::convertProductStrategyToAidl(
|
||||
const xsd::ProductStrategies::ProductStrategy& xsdcProductStrategy) {
|
||||
AudioHalProductStrategy aidlProductStrategy;
|
||||
|
||||
aidlProductStrategy.id =
|
||||
VALUE_OR_FATAL(convertProductStrategyNameToAidl(xsdcProductStrategy.getName()));
|
||||
aidlProductStrategy.id = convertProductStrategyNameToAidl(xsdcProductStrategy.getName());
|
||||
|
||||
if (xsdcProductStrategy.hasAttributesGroup()) {
|
||||
aidlProductStrategy.attributesGroups = VALUE_OR_FATAL(
|
||||
(convertCollectionToAidl<eng_xsd::AttributesGroup, AudioHalAttributesGroup>(
|
||||
aidlProductStrategy.attributesGroups =
|
||||
convertCollectionToAidlUnchecked<xsd::AttributesGroup, AudioHalAttributesGroup>(
|
||||
xsdcProductStrategy.getAttributesGroup(),
|
||||
std::bind(&EngineConfigXmlConverter::convertAttributesGroupToAidl, this,
|
||||
std::placeholders::_1))));
|
||||
std::placeholders::_1));
|
||||
}
|
||||
if ((mDefaultProductStrategyId != std::nullopt) && (mDefaultProductStrategyId.value() == -1)) {
|
||||
mDefaultProductStrategyId = aidlProductStrategy.id;
|
||||
|
@ -180,42 +183,82 @@ ConversionResult<AudioHalProductStrategy> EngineConfigXmlConverter::convertProdu
|
|||
return aidlProductStrategy;
|
||||
}
|
||||
|
||||
ConversionResult<AudioHalVolumeCurve> EngineConfigXmlConverter::convertVolumeCurveToAidl(
|
||||
const eng_xsd::Volume& xsdcVolumeCurve) {
|
||||
AudioHalVolumeCurve::CurvePoint EngineConfigXmlConverter::convertCurvePointToAidl(
|
||||
const std::string& xsdcCurvePoint) {
|
||||
AudioHalVolumeCurve::CurvePoint aidlCurvePoint{};
|
||||
if (sscanf(xsdcCurvePoint.c_str(), "%" SCNd8 ",%d", &aidlCurvePoint.index,
|
||||
&aidlCurvePoint.attenuationMb) != 2) {
|
||||
aidlCurvePoint.index = kInvalidCurvePointIndex;
|
||||
}
|
||||
return aidlCurvePoint;
|
||||
}
|
||||
|
||||
AudioHalVolumeCurve EngineConfigXmlConverter::convertVolumeCurveToAidl(
|
||||
const xsd::Volume& xsdcVolumeCurve) {
|
||||
AudioHalVolumeCurve aidlVolumeCurve;
|
||||
aidlVolumeCurve.deviceCategory =
|
||||
static_cast<AudioHalVolumeCurve::DeviceCategory>(xsdcVolumeCurve.getDeviceCategory());
|
||||
if (xsdcVolumeCurve.hasRef()) {
|
||||
if (mVolumesReferenceMap.empty()) {
|
||||
mVolumesReferenceMap = generateReferenceMap<eng_xsd::VolumesType, eng_xsd::VolumeRef>(
|
||||
mVolumesReferenceMap = generateReferenceMap<xsd::VolumesType, xsd::VolumeRef>(
|
||||
getXsdcConfig()->getVolumes());
|
||||
}
|
||||
aidlVolumeCurve.curvePoints = VALUE_OR_FATAL(
|
||||
(convertCollectionToAidl<std::string, AudioHalVolumeCurve::CurvePoint>(
|
||||
aidlVolumeCurve.curvePoints =
|
||||
convertCollectionToAidlUnchecked<std::string, AudioHalVolumeCurve::CurvePoint>(
|
||||
mVolumesReferenceMap.at(xsdcVolumeCurve.getRef()).getPoint(),
|
||||
&convertCurvePointToAidl)));
|
||||
std::bind(&EngineConfigXmlConverter::convertCurvePointToAidl, this,
|
||||
std::placeholders::_1));
|
||||
} else {
|
||||
aidlVolumeCurve.curvePoints = VALUE_OR_FATAL(
|
||||
(convertCollectionToAidl<std::string, AudioHalVolumeCurve::CurvePoint>(
|
||||
xsdcVolumeCurve.getPoint(), &convertCurvePointToAidl)));
|
||||
aidlVolumeCurve.curvePoints =
|
||||
convertCollectionToAidlUnchecked<std::string, AudioHalVolumeCurve::CurvePoint>(
|
||||
xsdcVolumeCurve.getPoint(),
|
||||
std::bind(&EngineConfigXmlConverter::convertCurvePointToAidl, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
return aidlVolumeCurve;
|
||||
}
|
||||
|
||||
ConversionResult<AudioHalVolumeGroup> EngineConfigXmlConverter::convertVolumeGroupToAidl(
|
||||
const eng_xsd::VolumeGroupsType::VolumeGroup& xsdcVolumeGroup) {
|
||||
AudioHalVolumeGroup EngineConfigXmlConverter::convertVolumeGroupToAidl(
|
||||
const xsd::VolumeGroupsType::VolumeGroup& xsdcVolumeGroup) {
|
||||
AudioHalVolumeGroup aidlVolumeGroup;
|
||||
aidlVolumeGroup.name = xsdcVolumeGroup.getName();
|
||||
aidlVolumeGroup.minIndex = xsdcVolumeGroup.getIndexMin();
|
||||
aidlVolumeGroup.maxIndex = xsdcVolumeGroup.getIndexMax();
|
||||
aidlVolumeGroup.volumeCurves =
|
||||
VALUE_OR_FATAL((convertCollectionToAidl<eng_xsd::Volume, AudioHalVolumeCurve>(
|
||||
convertCollectionToAidlUnchecked<xsd::Volume, AudioHalVolumeCurve>(
|
||||
xsdcVolumeGroup.getVolume(),
|
||||
std::bind(&EngineConfigXmlConverter::convertVolumeCurveToAidl, this,
|
||||
std::placeholders::_1))));
|
||||
std::placeholders::_1));
|
||||
return aidlVolumeGroup;
|
||||
}
|
||||
|
||||
AudioHalCapCriterion EngineConfigXmlConverter::convertCapCriterionToAidl(
|
||||
const xsd::CriterionType& xsdcCriterion) {
|
||||
AudioHalCapCriterion aidlCapCriterion;
|
||||
aidlCapCriterion.name = xsdcCriterion.getName();
|
||||
aidlCapCriterion.criterionTypeName = xsdcCriterion.getType();
|
||||
aidlCapCriterion.defaultLiteralValue = xsdcCriterion.get_default();
|
||||
return aidlCapCriterion;
|
||||
}
|
||||
|
||||
std::string EngineConfigXmlConverter::convertCriterionTypeValueToAidl(
|
||||
const xsd::ValueType& xsdcCriterionTypeValue) {
|
||||
return xsdcCriterionTypeValue.getLiteral();
|
||||
}
|
||||
|
||||
AudioHalCapCriterionType EngineConfigXmlConverter::convertCapCriterionTypeToAidl(
|
||||
const xsd::CriterionTypeType& xsdcCriterionType) {
|
||||
AudioHalCapCriterionType aidlCapCriterionType;
|
||||
aidlCapCriterionType.name = xsdcCriterionType.getName();
|
||||
aidlCapCriterionType.isInclusive = !(static_cast<bool>(xsdcCriterionType.getType()));
|
||||
aidlCapCriterionType.values =
|
||||
convertWrappedCollectionToAidlUnchecked<xsd::ValuesType, xsd::ValueType, std::string>(
|
||||
xsdcCriterionType.getValues(), &xsd::ValuesType::getValue,
|
||||
std::bind(&EngineConfigXmlConverter::convertCriterionTypeValueToAidl, this,
|
||||
std::placeholders::_1));
|
||||
return aidlCapCriterionType;
|
||||
}
|
||||
|
||||
AudioHalEngineConfig& EngineConfigXmlConverter::getAidlEngineConfig() {
|
||||
return mAidlEngineConfig;
|
||||
}
|
||||
|
@ -223,42 +266,39 @@ AudioHalEngineConfig& EngineConfigXmlConverter::getAidlEngineConfig() {
|
|||
void EngineConfigXmlConverter::init() {
|
||||
initProductStrategyMap();
|
||||
if (getXsdcConfig()->hasProductStrategies()) {
|
||||
mAidlEngineConfig.productStrategies = VALUE_OR_FATAL(
|
||||
(convertWrappedCollectionToAidl<eng_xsd::ProductStrategies,
|
||||
eng_xsd::ProductStrategies::ProductStrategy,
|
||||
AudioHalProductStrategy>(
|
||||
mAidlEngineConfig.productStrategies =
|
||||
convertWrappedCollectionToAidlUnchecked<xsd::ProductStrategies,
|
||||
xsd::ProductStrategies::ProductStrategy,
|
||||
AudioHalProductStrategy>(
|
||||
getXsdcConfig()->getProductStrategies(),
|
||||
&eng_xsd::ProductStrategies::getProductStrategy,
|
||||
&xsd::ProductStrategies::getProductStrategy,
|
||||
std::bind(&EngineConfigXmlConverter::convertProductStrategyToAidl, this,
|
||||
std::placeholders::_1))));
|
||||
std::placeholders::_1));
|
||||
if (mDefaultProductStrategyId) {
|
||||
mAidlEngineConfig.defaultProductStrategyId = mDefaultProductStrategyId.value();
|
||||
}
|
||||
}
|
||||
if (getXsdcConfig()->hasVolumeGroups()) {
|
||||
mAidlEngineConfig.volumeGroups = VALUE_OR_FATAL(
|
||||
(convertWrappedCollectionToAidl<eng_xsd::VolumeGroupsType,
|
||||
eng_xsd::VolumeGroupsType::VolumeGroup,
|
||||
AudioHalVolumeGroup>(
|
||||
getXsdcConfig()->getVolumeGroups(),
|
||||
&eng_xsd::VolumeGroupsType::getVolumeGroup,
|
||||
std::bind(&EngineConfigXmlConverter::convertVolumeGroupToAidl, this,
|
||||
std::placeholders::_1))));
|
||||
mAidlEngineConfig.volumeGroups = convertWrappedCollectionToAidlUnchecked<
|
||||
xsd::VolumeGroupsType, xsd::VolumeGroupsType::VolumeGroup, AudioHalVolumeGroup>(
|
||||
getXsdcConfig()->getVolumeGroups(), &xsd::VolumeGroupsType::getVolumeGroup,
|
||||
std::bind(&EngineConfigXmlConverter::convertVolumeGroupToAidl, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
if (getXsdcConfig()->hasCriteria() && getXsdcConfig()->hasCriterion_types()) {
|
||||
AudioHalEngineConfig::CapSpecificConfig capSpecificConfig;
|
||||
capSpecificConfig.criteria = VALUE_OR_FATAL(
|
||||
(convertWrappedCollectionToAidl<eng_xsd::CriteriaType, eng_xsd::CriterionType,
|
||||
AudioHalCapCriterion>(
|
||||
getXsdcConfig()->getCriteria(), &eng_xsd::CriteriaType::getCriterion,
|
||||
&convertCapCriterionToAidl)));
|
||||
capSpecificConfig.criterionTypes =
|
||||
VALUE_OR_FATAL((convertWrappedCollectionToAidl<eng_xsd::CriterionTypesType,
|
||||
eng_xsd::CriterionTypeType,
|
||||
AudioHalCapCriterionType>(
|
||||
getXsdcConfig()->getCriterion_types(),
|
||||
&eng_xsd::CriterionTypesType::getCriterion_type,
|
||||
&convertCapCriterionTypeToAidl)));
|
||||
capSpecificConfig.criteria =
|
||||
convertWrappedCollectionToAidlUnchecked<xsd::CriteriaType, xsd::CriterionType,
|
||||
AudioHalCapCriterion>(
|
||||
getXsdcConfig()->getCriteria(), &xsd::CriteriaType::getCriterion,
|
||||
std::bind(&EngineConfigXmlConverter::convertCapCriterionToAidl, this,
|
||||
std::placeholders::_1));
|
||||
capSpecificConfig.criterionTypes = convertWrappedCollectionToAidlUnchecked<
|
||||
xsd::CriterionTypesType, xsd::CriterionTypeType, AudioHalCapCriterionType>(
|
||||
getXsdcConfig()->getCriterion_types(), &xsd::CriterionTypesType::getCriterion_type,
|
||||
std::bind(&EngineConfigXmlConverter::convertCapCriterionTypeToAidl, this,
|
||||
std::placeholders::_1));
|
||||
mAidlEngineConfig.capSpecificConfig = capSpecificConfig;
|
||||
}
|
||||
}
|
||||
} // namespace aidl::android::hardware::audio::core::internal
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <android/binder_ibinder_platform.h>
|
||||
#include <error/expected_utils.h>
|
||||
|
||||
#include "core-impl/Configuration.h"
|
||||
#include "core-impl/Module.h"
|
||||
#include "core-impl/ModuleBluetooth.h"
|
||||
#include "core-impl/ModulePrimary.h"
|
||||
|
@ -133,36 +132,21 @@ bool findAudioProfile(const AudioPort& port, const AudioFormatDescription& forma
|
|||
} // namespace
|
||||
|
||||
// static
|
||||
std::shared_ptr<Module> Module::createInstance(Type type, std::unique_ptr<Configuration>&& config) {
|
||||
std::shared_ptr<Module> Module::createInstance(Type type) {
|
||||
switch (type) {
|
||||
case Type::DEFAULT:
|
||||
return ndk::SharedRefBase::make<ModulePrimary>(std::move(config));
|
||||
return ndk::SharedRefBase::make<ModulePrimary>();
|
||||
case Type::R_SUBMIX:
|
||||
return ndk::SharedRefBase::make<ModuleRemoteSubmix>(std::move(config));
|
||||
return ndk::SharedRefBase::make<ModuleRemoteSubmix>();
|
||||
case Type::STUB:
|
||||
return ndk::SharedRefBase::make<ModuleStub>(std::move(config));
|
||||
return ndk::SharedRefBase::make<ModuleStub>();
|
||||
case Type::USB:
|
||||
return ndk::SharedRefBase::make<ModuleUsb>(std::move(config));
|
||||
return ndk::SharedRefBase::make<ModuleUsb>();
|
||||
case Type::BLUETOOTH:
|
||||
return ndk::SharedRefBase::make<ModuleBluetooth>(std::move(config));
|
||||
return ndk::SharedRefBase::make<ModuleBluetooth>();
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
std::optional<Module::Type> Module::typeFromString(const std::string& type) {
|
||||
if (type == "default")
|
||||
return Module::Type::DEFAULT;
|
||||
else if (type == "r_submix")
|
||||
return Module::Type::R_SUBMIX;
|
||||
else if (type == "stub")
|
||||
return Module::Type::STUB;
|
||||
else if (type == "usb")
|
||||
return Module::Type::USB;
|
||||
else if (type == "bluetooth")
|
||||
return Module::Type::BLUETOOTH;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, Module::Type t) {
|
||||
switch (t) {
|
||||
case Module::Type::DEFAULT:
|
||||
|
@ -337,8 +321,26 @@ std::set<int32_t> Module::portIdsFromPortConfigIds(C portConfigIds) {
|
|||
return result;
|
||||
}
|
||||
|
||||
std::unique_ptr<Module::Configuration> Module::initializeConfig() {
|
||||
return internal::getConfiguration(getType());
|
||||
std::unique_ptr<internal::Configuration> Module::initializeConfig() {
|
||||
std::unique_ptr<internal::Configuration> config;
|
||||
switch (getType()) {
|
||||
case Type::DEFAULT:
|
||||
config = std::move(internal::getPrimaryConfiguration());
|
||||
break;
|
||||
case Type::R_SUBMIX:
|
||||
config = std::move(internal::getRSubmixConfiguration());
|
||||
break;
|
||||
case Type::STUB:
|
||||
config = std::move(internal::getStubConfiguration());
|
||||
break;
|
||||
case Type::USB:
|
||||
config = std::move(internal::getUsbConfiguration());
|
||||
break;
|
||||
case Type::BLUETOOTH:
|
||||
config = std::move(internal::getBluetoothConfiguration());
|
||||
break;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
std::vector<AudioRoute*> Module::getAudioRoutesForAudioPortImpl(int32_t portId) {
|
||||
|
@ -353,7 +355,7 @@ std::vector<AudioRoute*> Module::getAudioRoutesForAudioPortImpl(int32_t portId)
|
|||
return result;
|
||||
}
|
||||
|
||||
Module::Configuration& Module::getConfig() {
|
||||
internal::Configuration& Module::getConfig() {
|
||||
if (!mConfig) {
|
||||
mConfig = std::move(initializeConfig());
|
||||
}
|
||||
|
@ -800,7 +802,7 @@ ndk::ScopedAStatus Module::openInputStream(const OpenInputStreamArguments& in_ar
|
|||
context.fillDescriptor(&_aidl_return->desc);
|
||||
std::shared_ptr<StreamIn> stream;
|
||||
RETURN_STATUS_IF_ERROR(createInputStream(std::move(context), in_args.sinkMetadata,
|
||||
getConfig().microphones, &stream));
|
||||
mConfig->microphones, &stream));
|
||||
StreamWrapper streamWrapper(stream);
|
||||
if (auto patchIt = mPatches.find(in_args.portConfigId); patchIt != mPatches.end()) {
|
||||
RETURN_STATUS_IF_ERROR(
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
#define LOG_TAG "AHAL_Telephony"
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_to_string.h>
|
||||
|
||||
#include <Utils.h>
|
||||
#include <android/binder_to_string.h>
|
||||
|
||||
#include "core-impl/Telephony.h"
|
||||
|
||||
|
|
|
@ -1,444 +0,0 @@
|
|||
#include <inttypes.h>
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#define LOG_TAG "AHAL_Config"
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/strings.h>
|
||||
|
||||
#include <aidl/android/media/audio/common/AudioPort.h>
|
||||
#include <aidl/android/media/audio/common/AudioPortConfig.h>
|
||||
#include <media/AidlConversionCppNdk.h>
|
||||
#include <media/TypeConverter.h>
|
||||
|
||||
#include "core-impl/XmlConverter.h"
|
||||
#include "core-impl/XsdcConversion.h"
|
||||
|
||||
using aidl::android::media::audio::common::AudioChannelLayout;
|
||||
using aidl::android::media::audio::common::AudioDevice;
|
||||
using aidl::android::media::audio::common::AudioDeviceAddress;
|
||||
using aidl::android::media::audio::common::AudioDeviceDescription;
|
||||
using aidl::android::media::audio::common::AudioDeviceType;
|
||||
using aidl::android::media::audio::common::AudioFormatDescription;
|
||||
using aidl::android::media::audio::common::AudioFormatType;
|
||||
using aidl::android::media::audio::common::AudioGain;
|
||||
using aidl::android::media::audio::common::AudioHalCapCriterion;
|
||||
using aidl::android::media::audio::common::AudioHalCapCriterionType;
|
||||
using aidl::android::media::audio::common::AudioHalVolumeCurve;
|
||||
using aidl::android::media::audio::common::AudioIoFlags;
|
||||
using aidl::android::media::audio::common::AudioPort;
|
||||
using aidl::android::media::audio::common::AudioPortConfig;
|
||||
using aidl::android::media::audio::common::AudioPortDeviceExt;
|
||||
using aidl::android::media::audio::common::AudioPortExt;
|
||||
using aidl::android::media::audio::common::AudioPortMixExt;
|
||||
using aidl::android::media::audio::common::AudioProfile;
|
||||
using ::android::BAD_VALUE;
|
||||
using ::android::base::unexpected;
|
||||
|
||||
namespace ap_xsd = android::audio::policy::configuration;
|
||||
namespace eng_xsd = android::audio::policy::engine::configuration;
|
||||
|
||||
namespace aidl::android::hardware::audio::core::internal {
|
||||
|
||||
inline ConversionResult<std::string> assertNonEmpty(const std::string& s) {
|
||||
if (s.empty()) {
|
||||
LOG(ERROR) << __func__ << " Review Audio Policy config: "
|
||||
<< " empty string is not valid.";
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
#define NON_EMPTY_STRING_OR_FATAL(s) VALUE_OR_FATAL(assertNonEmpty(s))
|
||||
|
||||
ConversionResult<AudioFormatDescription> convertAudioFormatToAidl(const std::string& xsdcFormat) {
|
||||
audio_format_t legacyFormat = ::android::formatFromString(xsdcFormat, AUDIO_FORMAT_DEFAULT);
|
||||
ConversionResult<AudioFormatDescription> result =
|
||||
legacy2aidl_audio_format_t_AudioFormatDescription(legacyFormat);
|
||||
if ((legacyFormat == AUDIO_FORMAT_DEFAULT && xsdcFormat.compare("AUDIO_FORMAT_DEFAULT") != 0) ||
|
||||
!result.ok()) {
|
||||
LOG(ERROR) << __func__ << " Review Audio Policy config: " << xsdcFormat
|
||||
<< " is not a valid audio format.";
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unordered_set<std::string> getAttachedDevices(const ap_xsd::Modules::Module& moduleConfig) {
|
||||
std::unordered_set<std::string> attachedDeviceSet;
|
||||
if (moduleConfig.hasAttachedDevices()) {
|
||||
for (const ap_xsd::AttachedDevices& attachedDevices : moduleConfig.getAttachedDevices()) {
|
||||
if (attachedDevices.hasItem()) {
|
||||
attachedDeviceSet.insert(attachedDevices.getItem().begin(),
|
||||
attachedDevices.getItem().end());
|
||||
}
|
||||
}
|
||||
}
|
||||
return attachedDeviceSet;
|
||||
}
|
||||
|
||||
ConversionResult<AudioDeviceDescription> convertDeviceTypeToAidl(const std::string& xType) {
|
||||
audio_devices_t legacyDeviceType = AUDIO_DEVICE_NONE;
|
||||
::android::DeviceConverter::fromString(xType, legacyDeviceType);
|
||||
ConversionResult<AudioDeviceDescription> result =
|
||||
legacy2aidl_audio_devices_t_AudioDeviceDescription(legacyDeviceType);
|
||||
if ((legacyDeviceType == AUDIO_DEVICE_NONE) || !result.ok()) {
|
||||
LOG(ERROR) << __func__ << " Review Audio Policy config: " << xType
|
||||
<< " is not a valid device type.";
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ConversionResult<AudioDevice> createAudioDevice(
|
||||
const ap_xsd::DevicePorts::DevicePort& xDevicePort) {
|
||||
AudioDevice device = {
|
||||
.type = VALUE_OR_FATAL(convertDeviceTypeToAidl(xDevicePort.getType())),
|
||||
.address = xDevicePort.hasAddress()
|
||||
? AudioDeviceAddress::make<AudioDeviceAddress::Tag::id>(
|
||||
xDevicePort.getAddress())
|
||||
: AudioDeviceAddress{}};
|
||||
if (device.type.type == AudioDeviceType::IN_MICROPHONE && device.type.connection.empty()) {
|
||||
device.address = "bottom";
|
||||
} else if (device.type.type == AudioDeviceType::IN_MICROPHONE_BACK &&
|
||||
device.type.connection.empty()) {
|
||||
device.address = "back";
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
ConversionResult<AudioPortExt> createAudioPortExt(
|
||||
const ap_xsd::DevicePorts::DevicePort& xDevicePort,
|
||||
const std::string& xDefaultOutputDevice) {
|
||||
AudioPortDeviceExt deviceExt = {
|
||||
.device = VALUE_OR_FATAL(createAudioDevice(xDevicePort)),
|
||||
.flags = (xDevicePort.getTagName() == xDefaultOutputDevice)
|
||||
? 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE
|
||||
: 0,
|
||||
.encodedFormats =
|
||||
xDevicePort.hasEncodedFormats()
|
||||
? VALUE_OR_FATAL(
|
||||
(convertCollectionToAidl<std::string, AudioFormatDescription>(
|
||||
xDevicePort.getEncodedFormats(),
|
||||
&convertAudioFormatToAidl)))
|
||||
: std::vector<AudioFormatDescription>{},
|
||||
};
|
||||
return AudioPortExt::make<AudioPortExt::Tag::device>(deviceExt);
|
||||
}
|
||||
|
||||
ConversionResult<AudioPortExt> createAudioPortExt(const ap_xsd::MixPorts::MixPort& xMixPort) {
|
||||
AudioPortMixExt mixExt = {
|
||||
.maxOpenStreamCount =
|
||||
xMixPort.hasMaxOpenCount() ? static_cast<int>(xMixPort.getMaxOpenCount()) : 0,
|
||||
.maxActiveStreamCount = xMixPort.hasMaxActiveCount()
|
||||
? static_cast<int>(xMixPort.getMaxActiveCount())
|
||||
: 1,
|
||||
.recommendedMuteDurationMs =
|
||||
xMixPort.hasRecommendedMuteDurationMs()
|
||||
? static_cast<int>(xMixPort.getRecommendedMuteDurationMs())
|
||||
: 0};
|
||||
return AudioPortExt::make<AudioPortExt::Tag::mix>(mixExt);
|
||||
}
|
||||
|
||||
ConversionResult<int> convertGainModeToAidl(const std::vector<ap_xsd::AudioGainMode>& gainModeVec) {
|
||||
static const char gainModeSeparator = ' ';
|
||||
int gainModeMask = 0;
|
||||
for (const ap_xsd::AudioGainMode& gainMode : gainModeVec) {
|
||||
gainModeMask |= static_cast<int>(::android::GainModeConverter::maskFromString(
|
||||
ap_xsd::toString(gainMode), &gainModeSeparator));
|
||||
}
|
||||
return gainModeMask;
|
||||
}
|
||||
|
||||
ConversionResult<AudioChannelLayout> convertChannelMaskToAidl(
|
||||
const ap_xsd::AudioChannelMask& xChannelMask) {
|
||||
std::string xChannelMaskLiteral = ap_xsd::toString(xChannelMask);
|
||||
audio_channel_mask_t legacyChannelMask = ::android::channelMaskFromString(xChannelMaskLiteral);
|
||||
ConversionResult<AudioChannelLayout> result =
|
||||
legacy2aidl_audio_channel_mask_t_AudioChannelLayout(
|
||||
legacyChannelMask,
|
||||
/* isInput= */ xChannelMaskLiteral.find("AUDIO_CHANNEL_IN_") == 0);
|
||||
if ((legacyChannelMask == AUDIO_CHANNEL_INVALID) || !result.ok()) {
|
||||
LOG(ERROR) << __func__ << " Review Audio Policy config: " << xChannelMaskLiteral
|
||||
<< " is not a valid audio channel mask.";
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ConversionResult<AudioGain> convertGainToAidl(const ap_xsd::Gains::Gain& xGain) {
|
||||
return AudioGain{
|
||||
.mode = VALUE_OR_FATAL(convertGainModeToAidl(xGain.getMode())),
|
||||
.channelMask =
|
||||
xGain.hasChannel_mask()
|
||||
? VALUE_OR_FATAL(convertChannelMaskToAidl(xGain.getChannel_mask()))
|
||||
: AudioChannelLayout{},
|
||||
.minValue = xGain.hasMinValueMB() ? xGain.getMinValueMB() : 0,
|
||||
.maxValue = xGain.hasMaxValueMB() ? xGain.getMaxValueMB() : 0,
|
||||
.defaultValue = xGain.hasDefaultValueMB() ? xGain.getDefaultValueMB() : 0,
|
||||
.stepValue = xGain.hasStepValueMB() ? xGain.getStepValueMB() : 0,
|
||||
.minRampMs = xGain.hasMinRampMs() ? xGain.getMinRampMs() : 0,
|
||||
.maxRampMs = xGain.hasMaxRampMs() ? xGain.getMaxRampMs() : 0,
|
||||
.useForVolume = xGain.hasUseForVolume() ? xGain.getUseForVolume() : false,
|
||||
};
|
||||
}
|
||||
|
||||
ConversionResult<AudioProfile> convertAudioProfileToAidl(const ap_xsd::Profile& xProfile) {
|
||||
return AudioProfile{
|
||||
.format = xProfile.hasFormat()
|
||||
? VALUE_OR_FATAL(convertAudioFormatToAidl(xProfile.getFormat()))
|
||||
: AudioFormatDescription{},
|
||||
.channelMasks =
|
||||
xProfile.hasChannelMasks()
|
||||
? VALUE_OR_FATAL((convertCollectionToAidl<ap_xsd::AudioChannelMask,
|
||||
AudioChannelLayout>(
|
||||
xProfile.getChannelMasks(), &convertChannelMaskToAidl)))
|
||||
: std::vector<AudioChannelLayout>{},
|
||||
.sampleRates = xProfile.hasSamplingRates()
|
||||
? VALUE_OR_FATAL((convertCollectionToAidl<int64_t, int>(
|
||||
xProfile.getSamplingRates(),
|
||||
[](const int64_t x) -> int { return x; })))
|
||||
: std::vector<int>{}};
|
||||
}
|
||||
|
||||
ConversionResult<AudioIoFlags> convertIoFlagsToAidl(
|
||||
const std::vector<ap_xsd::AudioInOutFlag>& flags, const ap_xsd::Role role,
|
||||
bool flagsForMixPort) {
|
||||
static const char flagSeparator = ' ';
|
||||
int flagMask = 0;
|
||||
if ((role == ap_xsd::Role::sink && flagsForMixPort) ||
|
||||
(role == ap_xsd::Role::source && !flagsForMixPort)) {
|
||||
for (const ap_xsd::AudioInOutFlag& flag : flags) {
|
||||
flagMask |= static_cast<int>(::android::InputFlagConverter::maskFromString(
|
||||
ap_xsd::toString(flag), &flagSeparator));
|
||||
}
|
||||
return AudioIoFlags::make<AudioIoFlags::Tag::input>(flagMask);
|
||||
} else {
|
||||
for (const ap_xsd::AudioInOutFlag& flag : flags) {
|
||||
flagMask |= static_cast<int>(::android::OutputFlagConverter::maskFromString(
|
||||
ap_xsd::toString(flag), &flagSeparator));
|
||||
}
|
||||
}
|
||||
return AudioIoFlags::make<AudioIoFlags::Tag::output>(flagMask);
|
||||
}
|
||||
|
||||
ConversionResult<AudioPort> convertDevicePortToAidl(
|
||||
const ap_xsd::DevicePorts::DevicePort& xDevicePort, const std::string& xDefaultOutputDevice,
|
||||
int32_t& nextPortId) {
|
||||
return AudioPort{
|
||||
.id = nextPortId++,
|
||||
.name = NON_EMPTY_STRING_OR_FATAL(xDevicePort.getTagName()),
|
||||
.profiles = VALUE_OR_FATAL((convertCollectionToAidl<ap_xsd::Profile, AudioProfile>(
|
||||
xDevicePort.getProfile(), convertAudioProfileToAidl))),
|
||||
.flags = VALUE_OR_FATAL(convertIoFlagsToAidl({}, xDevicePort.getRole(), false)),
|
||||
.gains = VALUE_OR_FATAL(
|
||||
(convertWrappedCollectionToAidl<ap_xsd::Gains, ap_xsd::Gains::Gain, AudioGain>(
|
||||
xDevicePort.getGains(), &ap_xsd::Gains::getGain, convertGainToAidl))),
|
||||
|
||||
.ext = VALUE_OR_FATAL(createAudioPortExt(xDevicePort, xDefaultOutputDevice))};
|
||||
}
|
||||
|
||||
ConversionResult<std::vector<AudioPort>> convertDevicePortsInModuleToAidl(
|
||||
const ap_xsd::Modules::Module& xModuleConfig, int32_t& nextPortId) {
|
||||
std::vector<AudioPort> audioPortVec;
|
||||
std::vector<ap_xsd::DevicePorts> xDevicePortsVec = xModuleConfig.getDevicePorts();
|
||||
if (xDevicePortsVec.size() > 1) {
|
||||
LOG(ERROR) << __func__ << "Having multiple '<devicePorts>' elements is not allowed, found: "
|
||||
<< xDevicePortsVec.size();
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
if (!xDevicePortsVec.empty()) {
|
||||
const std::string xDefaultOutputDevice = xModuleConfig.hasDefaultOutputDevice()
|
||||
? xModuleConfig.getDefaultOutputDevice()
|
||||
: "";
|
||||
audioPortVec.reserve(xDevicePortsVec[0].getDevicePort().size());
|
||||
for (const ap_xsd::DevicePorts& xDevicePortsType : xDevicePortsVec) {
|
||||
for (const ap_xsd::DevicePorts::DevicePort& xDevicePort :
|
||||
xDevicePortsType.getDevicePort()) {
|
||||
audioPortVec.push_back(VALUE_OR_FATAL(
|
||||
convertDevicePortToAidl(xDevicePort, xDefaultOutputDevice, nextPortId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::unordered_set<std::string> xAttachedDeviceSet = getAttachedDevices(xModuleConfig);
|
||||
for (const auto& port : audioPortVec) {
|
||||
const auto& devicePort = port.ext.get<AudioPortExt::device>();
|
||||
if (xAttachedDeviceSet.count(port.name) != devicePort.device.type.connection.empty()) {
|
||||
LOG(ERROR) << __func__ << ": Review Audio Policy config: <attachedDevices> "
|
||||
<< "list is incorrect or devicePort \"" << port.name
|
||||
<< "\" type= " << devicePort.device.type.toString() << " is incorrect.";
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
}
|
||||
return audioPortVec;
|
||||
}
|
||||
|
||||
ConversionResult<AudioPort> convertMixPortToAidl(const ap_xsd::MixPorts::MixPort& xMixPort,
|
||||
int32_t& nextPortId) {
|
||||
return AudioPort{
|
||||
.id = nextPortId++,
|
||||
.name = NON_EMPTY_STRING_OR_FATAL(xMixPort.getName()),
|
||||
.profiles = VALUE_OR_FATAL((convertCollectionToAidl<ap_xsd::Profile, AudioProfile>(
|
||||
xMixPort.getProfile(), convertAudioProfileToAidl))),
|
||||
.flags = xMixPort.hasFlags()
|
||||
? VALUE_OR_FATAL(convertIoFlagsToAidl(xMixPort.getFlags(),
|
||||
xMixPort.getRole(), true))
|
||||
: VALUE_OR_FATAL(convertIoFlagsToAidl({}, xMixPort.getRole(), true)),
|
||||
.gains = VALUE_OR_FATAL(
|
||||
(convertWrappedCollectionToAidl<ap_xsd::Gains, ap_xsd::Gains::Gain, AudioGain>(
|
||||
xMixPort.getGains(), &ap_xsd::Gains::getGain, &convertGainToAidl))),
|
||||
.ext = VALUE_OR_FATAL(createAudioPortExt(xMixPort)),
|
||||
};
|
||||
}
|
||||
|
||||
ConversionResult<std::vector<AudioPort>> convertMixPortsInModuleToAidl(
|
||||
const ap_xsd::Modules::Module& xModuleConfig, int32_t& nextPortId) {
|
||||
std::vector<AudioPort> audioPortVec;
|
||||
std::vector<ap_xsd::MixPorts> xMixPortsVec = xModuleConfig.getMixPorts();
|
||||
if (xMixPortsVec.size() > 1) {
|
||||
LOG(ERROR) << __func__ << "Having multiple '<mixPorts>' elements is not allowed, found: "
|
||||
<< xMixPortsVec.size();
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
if (!xMixPortsVec.empty()) {
|
||||
audioPortVec.reserve(xMixPortsVec[0].getMixPort().size());
|
||||
for (const ap_xsd::MixPorts& xMixPortsType : xMixPortsVec) {
|
||||
for (const ap_xsd::MixPorts::MixPort& xMixPort : xMixPortsType.getMixPort()) {
|
||||
audioPortVec.push_back(VALUE_OR_FATAL(convertMixPortToAidl(xMixPort, nextPortId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return audioPortVec;
|
||||
}
|
||||
|
||||
ConversionResult<int32_t> getSinkPortId(const ap_xsd::Routes::Route& xRoute,
|
||||
const std::unordered_map<std::string, int32_t>& portMap) {
|
||||
auto portMapIter = portMap.find(xRoute.getSink());
|
||||
if (portMapIter == portMap.end()) {
|
||||
LOG(ERROR) << __func__ << " Review Audio Policy config: audio route"
|
||||
<< "has sink: " << xRoute.getSink()
|
||||
<< " which is neither a device port nor mix port.";
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
return portMapIter->second;
|
||||
}
|
||||
|
||||
ConversionResult<std::vector<int32_t>> getSourcePortIds(
|
||||
const ap_xsd::Routes::Route& xRoute,
|
||||
const std::unordered_map<std::string, int32_t>& portMap) {
|
||||
std::vector<int32_t> sourcePortIds;
|
||||
for (const std::string& rawSource : ::android::base::Split(xRoute.getSources(), ",")) {
|
||||
const std::string source = ::android::base::Trim(rawSource);
|
||||
auto portMapIter = portMap.find(source);
|
||||
if (portMapIter == portMap.end()) {
|
||||
LOG(ERROR) << __func__ << " Review Audio Policy config: audio route"
|
||||
<< "has source \"" << source
|
||||
<< "\" which is neither a device port nor mix port.";
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
sourcePortIds.push_back(portMapIter->second);
|
||||
}
|
||||
return sourcePortIds;
|
||||
}
|
||||
|
||||
ConversionResult<AudioRoute> convertRouteToAidl(const ap_xsd::Routes::Route& xRoute,
|
||||
const std::vector<AudioPort>& aidlAudioPorts) {
|
||||
std::unordered_map<std::string, int32_t> portMap;
|
||||
for (const AudioPort& port : aidlAudioPorts) {
|
||||
portMap.insert({port.name, port.id});
|
||||
}
|
||||
return AudioRoute{.sourcePortIds = VALUE_OR_FATAL(getSourcePortIds(xRoute, portMap)),
|
||||
.sinkPortId = VALUE_OR_FATAL(getSinkPortId(xRoute, portMap)),
|
||||
.isExclusive = (xRoute.getType() == ap_xsd::MixType::mux)};
|
||||
}
|
||||
|
||||
ConversionResult<std::vector<AudioRoute>> convertRoutesInModuleToAidl(
|
||||
const ap_xsd::Modules::Module& xModuleConfig,
|
||||
const std::vector<AudioPort>& aidlAudioPorts) {
|
||||
std::vector<AudioRoute> audioRouteVec;
|
||||
std::vector<ap_xsd::Routes> xRoutesVec = xModuleConfig.getRoutes();
|
||||
if (!xRoutesVec.empty()) {
|
||||
/*
|
||||
* xRoutesVec likely only contains one element; that is, it's
|
||||
* likely that all ap_xsd::Routes::MixPort types that we need to convert
|
||||
* are inside of xRoutesVec[0].
|
||||
*/
|
||||
audioRouteVec.reserve(xRoutesVec[0].getRoute().size());
|
||||
for (const ap_xsd::Routes& xRoutesType : xRoutesVec) {
|
||||
for (const ap_xsd::Routes::Route& xRoute : xRoutesType.getRoute()) {
|
||||
audioRouteVec.push_back(VALUE_OR_FATAL(convertRouteToAidl(xRoute, aidlAudioPorts)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return audioRouteVec;
|
||||
}
|
||||
|
||||
ConversionResult<std::unique_ptr<Module::Configuration>> convertModuleConfigToAidl(
|
||||
const ap_xsd::Modules::Module& xModuleConfig) {
|
||||
auto result = std::make_unique<Module::Configuration>();
|
||||
auto& aidlModuleConfig = *result;
|
||||
std::vector<AudioPort> devicePorts = VALUE_OR_FATAL(
|
||||
convertDevicePortsInModuleToAidl(xModuleConfig, aidlModuleConfig.nextPortId));
|
||||
|
||||
// The XML config does not specify the default input device.
|
||||
// Assign the first attached input device as the default.
|
||||
for (auto& port : devicePorts) {
|
||||
if (port.flags.getTag() != AudioIoFlags::input) continue;
|
||||
auto& deviceExt = port.ext.get<AudioPortExt::device>();
|
||||
if (!deviceExt.device.type.connection.empty()) continue;
|
||||
deviceExt.flags |= 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE;
|
||||
break;
|
||||
}
|
||||
|
||||
std::vector<AudioPort> mixPorts = VALUE_OR_FATAL(
|
||||
convertMixPortsInModuleToAidl(xModuleConfig, aidlModuleConfig.nextPortId));
|
||||
aidlModuleConfig.ports.reserve(devicePorts.size() + mixPorts.size());
|
||||
aidlModuleConfig.ports.insert(aidlModuleConfig.ports.end(), devicePorts.begin(),
|
||||
devicePorts.end());
|
||||
aidlModuleConfig.ports.insert(aidlModuleConfig.ports.end(), mixPorts.begin(), mixPorts.end());
|
||||
|
||||
aidlModuleConfig.routes =
|
||||
VALUE_OR_FATAL(convertRoutesInModuleToAidl(xModuleConfig, aidlModuleConfig.ports));
|
||||
return result;
|
||||
}
|
||||
|
||||
ConversionResult<AudioHalCapCriterion> convertCapCriterionToAidl(
|
||||
const eng_xsd::CriterionType& xsdcCriterion) {
|
||||
AudioHalCapCriterion aidlCapCriterion;
|
||||
aidlCapCriterion.name = xsdcCriterion.getName();
|
||||
aidlCapCriterion.criterionTypeName = xsdcCriterion.getType();
|
||||
aidlCapCriterion.defaultLiteralValue = xsdcCriterion.get_default();
|
||||
return aidlCapCriterion;
|
||||
}
|
||||
|
||||
ConversionResult<std::string> convertCriterionTypeValueToAidl(
|
||||
const eng_xsd::ValueType& xsdcCriterionTypeValue) {
|
||||
return xsdcCriterionTypeValue.getLiteral();
|
||||
}
|
||||
|
||||
ConversionResult<AudioHalCapCriterionType> convertCapCriterionTypeToAidl(
|
||||
const eng_xsd::CriterionTypeType& xsdcCriterionType) {
|
||||
AudioHalCapCriterionType aidlCapCriterionType;
|
||||
aidlCapCriterionType.name = xsdcCriterionType.getName();
|
||||
aidlCapCriterionType.isInclusive = !(static_cast<bool>(xsdcCriterionType.getType()));
|
||||
aidlCapCriterionType.values = VALUE_OR_RETURN(
|
||||
(convertWrappedCollectionToAidl<eng_xsd::ValuesType, eng_xsd::ValueType, std::string>(
|
||||
xsdcCriterionType.getValues(), &eng_xsd::ValuesType::getValue,
|
||||
&convertCriterionTypeValueToAidl)));
|
||||
return aidlCapCriterionType;
|
||||
}
|
||||
|
||||
ConversionResult<AudioHalVolumeCurve::CurvePoint> convertCurvePointToAidl(
|
||||
const std::string& xsdcCurvePoint) {
|
||||
AudioHalVolumeCurve::CurvePoint aidlCurvePoint{};
|
||||
if ((sscanf(xsdcCurvePoint.c_str(), "%" SCNd8 ",%d", &aidlCurvePoint.index,
|
||||
&aidlCurvePoint.attenuationMb) != 2) ||
|
||||
(aidlCurvePoint.index < AudioHalVolumeCurve::CurvePoint::MIN_INDEX) ||
|
||||
(aidlCurvePoint.index > AudioHalVolumeCurve::CurvePoint::MAX_INDEX)) {
|
||||
LOG(ERROR) << __func__ << " Review Audio Policy config: volume curve point:"
|
||||
<< "\"" << xsdcCurvePoint << "\" is invalid";
|
||||
return unexpected(BAD_VALUE);
|
||||
}
|
||||
return aidlCurvePoint;
|
||||
}
|
||||
} // namespace aidl::android::hardware::audio::core::internal
|
|
@ -9,17 +9,6 @@
|
|||
<version>1</version>
|
||||
<fqname>IModule/r_submix</fqname>
|
||||
</hal>
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.audio.core</name>
|
||||
<version>1</version>
|
||||
<fqname>IModule/bluetooth</fqname>
|
||||
</hal>
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.audio.core</name>
|
||||
<version>1</version>
|
||||
<fqname>IConfig/default</fqname>
|
||||
</hal>
|
||||
<!-- Uncomment when these modules present in the configuration
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.audio.core</name>
|
||||
<version>1</version>
|
||||
|
@ -30,5 +19,14 @@
|
|||
<version>1</version>
|
||||
<fqname>IModule/usb</fqname>
|
||||
</hal>
|
||||
-->
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.audio.core</name>
|
||||
<version>1</version>
|
||||
<fqname>IModule/bluetooth</fqname>
|
||||
</hal>
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.audio.core</name>
|
||||
<version>1</version>
|
||||
<fqname>IConfig/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
|
|
|
@ -85,6 +85,16 @@ package android.audio.policy.configuration {
|
|||
enum_constant public static final android.audio.policy.configuration.AudioChannelMask AUDIO_CHANNEL_OUT_TRI_BACK;
|
||||
}
|
||||
|
||||
public enum AudioContentType {
|
||||
method @NonNull public String getRawName();
|
||||
enum_constant public static final android.audio.policy.configuration.AudioContentType AUDIO_CONTENT_TYPE_MOVIE;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioContentType AUDIO_CONTENT_TYPE_MUSIC;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioContentType AUDIO_CONTENT_TYPE_SONIFICATION;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioContentType AUDIO_CONTENT_TYPE_SPEECH;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioContentType AUDIO_CONTENT_TYPE_ULTRASOUND;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioContentType AUDIO_CONTENT_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
public enum AudioDevice {
|
||||
method @NonNull public String getRawName();
|
||||
enum_constant public static final android.audio.policy.configuration.AudioDevice AUDIO_DEVICE_IN_AMBIENT;
|
||||
|
@ -158,6 +168,13 @@ package android.audio.policy.configuration {
|
|||
enum_constant public static final android.audio.policy.configuration.AudioDevice AUDIO_DEVICE_OUT_WIRED_HEADSET;
|
||||
}
|
||||
|
||||
public enum AudioEncapsulationType {
|
||||
method @NonNull public String getRawName();
|
||||
enum_constant public static final android.audio.policy.configuration.AudioEncapsulationType AUDIO_ENCAPSULATION_TYPE_IEC61937;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioEncapsulationType AUDIO_ENCAPSULATION_TYPE_NONE;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioEncapsulationType AUDIO_ENCAPSULATION_TYPE_PCM;
|
||||
}
|
||||
|
||||
public enum AudioFormat {
|
||||
method @NonNull public String getRawName();
|
||||
enum_constant public static final android.audio.policy.configuration.AudioFormat AUDIO_FORMAT_AAC;
|
||||
|
@ -342,6 +359,29 @@ package android.audio.policy.configuration {
|
|||
enum_constant public static final android.audio.policy.configuration.AudioStreamType AUDIO_STREAM_VOICE_CALL;
|
||||
}
|
||||
|
||||
public enum AudioUsage {
|
||||
method @NonNull public String getRawName();
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_ALARM;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_ANNOUNCEMENT;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_ASSISTANCE_SONIFICATION;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_ASSISTANT;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_CALL_ASSISTANT;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_EMERGENCY;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_GAME;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_MEDIA;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_NOTIFICATION;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_NOTIFICATION_EVENT;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_SAFETY;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_UNKNOWN;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_VEHICLE_STATUS;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_VIRTUAL_SOURCE;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_VOICE_COMMUNICATION;
|
||||
enum_constant public static final android.audio.policy.configuration.AudioUsage AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING;
|
||||
}
|
||||
|
||||
public enum DeviceCategory {
|
||||
method @NonNull public String getRawName();
|
||||
enum_constant public static final android.audio.policy.configuration.DeviceCategory DEVICE_CATEGORY_EARPIECE;
|
||||
|
@ -395,6 +435,7 @@ package android.audio.policy.configuration {
|
|||
method @Nullable public int getMinRampMs();
|
||||
method @Nullable public int getMinValueMB();
|
||||
method @Nullable public java.util.List<android.audio.policy.configuration.AudioGainMode> getMode();
|
||||
method @Nullable public String getName();
|
||||
method @Nullable public int getStepValueMB();
|
||||
method @Nullable public boolean getUseForVolume();
|
||||
method public void setChannel_mask(@Nullable android.audio.policy.configuration.AudioChannelMask);
|
||||
|
@ -404,6 +445,7 @@ package android.audio.policy.configuration {
|
|||
method public void setMinRampMs(@Nullable int);
|
||||
method public void setMinValueMB(@Nullable int);
|
||||
method public void setMode(@Nullable java.util.List<android.audio.policy.configuration.AudioGainMode>);
|
||||
method public void setName(@Nullable String);
|
||||
method public void setStepValueMB(@Nullable int);
|
||||
method public void setUseForVolume(@Nullable boolean);
|
||||
}
|
||||
|
@ -436,6 +478,7 @@ package android.audio.policy.configuration {
|
|||
method @Nullable public long getMaxActiveCount();
|
||||
method @Nullable public long getMaxOpenCount();
|
||||
method @Nullable public String getName();
|
||||
method @Nullable public java.util.List<android.audio.policy.configuration.AudioUsage> getPreferredUsage();
|
||||
method @Nullable public java.util.List<android.audio.policy.configuration.Profile> getProfile();
|
||||
method @Nullable public long getRecommendedMuteDurationMs();
|
||||
method @Nullable public android.audio.policy.configuration.Role getRole();
|
||||
|
@ -444,6 +487,7 @@ package android.audio.policy.configuration {
|
|||
method public void setMaxActiveCount(@Nullable long);
|
||||
method public void setMaxOpenCount(@Nullable long);
|
||||
method public void setName(@Nullable String);
|
||||
method public void setPreferredUsage(@Nullable java.util.List<android.audio.policy.configuration.AudioUsage>);
|
||||
method public void setRecommendedMuteDurationMs(@Nullable long);
|
||||
method public void setRole(@Nullable android.audio.policy.configuration.Role);
|
||||
}
|
||||
|
@ -480,10 +524,14 @@ package android.audio.policy.configuration {
|
|||
public class Profile {
|
||||
ctor public Profile();
|
||||
method @Nullable public java.util.List<android.audio.policy.configuration.AudioChannelMask> getChannelMasks();
|
||||
method @Nullable public android.audio.policy.configuration.AudioEncapsulationType getEncapsulationType();
|
||||
method @Nullable public String getFormat();
|
||||
method @Nullable public String getName();
|
||||
method @Nullable public java.util.List<java.math.BigInteger> getSamplingRates();
|
||||
method public void setChannelMasks(@Nullable java.util.List<android.audio.policy.configuration.AudioChannelMask>);
|
||||
method public void setEncapsulationType(@Nullable android.audio.policy.configuration.AudioEncapsulationType);
|
||||
method public void setFormat(@Nullable String);
|
||||
method public void setName(@Nullable String);
|
||||
method public void setSamplingRates(@Nullable java.util.List<java.math.BigInteger>);
|
||||
}
|
||||
|
||||
|
|
|
@ -217,6 +217,20 @@
|
|||
<xs:attribute name="flags" type="audioInOutFlags"/>
|
||||
<xs:attribute name="maxOpenCount" type="xs:unsignedInt"/>
|
||||
<xs:attribute name="maxActiveCount" type="xs:unsignedInt"/>
|
||||
<xs:attribute name="preferredUsage" type="audioUsageList">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">
|
||||
When choosing the mixPort of an audio track, the audioPolicy
|
||||
first considers the mixPorts with a preferredUsage including
|
||||
the track AudioUsage preferred .
|
||||
If non support the track format, the other mixPorts are considered.
|
||||
Eg: a <mixPort preferredUsage="AUDIO_USAGE_MEDIA" /> will receive
|
||||
the audio of all apps playing with a MEDIA usage.
|
||||
It may receive audio from ALARM if there are no audio compatible
|
||||
<mixPort preferredUsage="AUDIO_USAGE_ALARM" />.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="recommendedMuteDurationMs" type="xs:unsignedInt"/>
|
||||
</xs:complexType>
|
||||
<xs:unique name="mixPortProfileUniqueness">
|
||||
|
@ -420,6 +434,56 @@
|
|||
<xs:simpleType name="extendableAudioFormat">
|
||||
<xs:union memberTypes="audioFormat vendorExtension"/>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="audioUsage">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">
|
||||
Audio usage specifies the intended use case for the sound being played.
|
||||
Please consult frameworks/base/media/java/android/media/AudioAttributes.java
|
||||
for the description of each value.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="AUDIO_USAGE_UNKNOWN" />
|
||||
<xs:enumeration value="AUDIO_USAGE_MEDIA" />
|
||||
<xs:enumeration value="AUDIO_USAGE_VOICE_COMMUNICATION" />
|
||||
<xs:enumeration value="AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING" />
|
||||
<xs:enumeration value="AUDIO_USAGE_ALARM" />
|
||||
<xs:enumeration value="AUDIO_USAGE_NOTIFICATION" />
|
||||
<xs:enumeration value="AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE" />
|
||||
<xs:enumeration value="AUDIO_USAGE_NOTIFICATION_EVENT" />
|
||||
<xs:enumeration value="AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY" />
|
||||
<xs:enumeration value="AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE" />
|
||||
<xs:enumeration value="AUDIO_USAGE_ASSISTANCE_SONIFICATION" />
|
||||
<xs:enumeration value="AUDIO_USAGE_GAME" />
|
||||
<xs:enumeration value="AUDIO_USAGE_VIRTUAL_SOURCE" />
|
||||
<xs:enumeration value="AUDIO_USAGE_ASSISTANT" />
|
||||
<xs:enumeration value="AUDIO_USAGE_CALL_ASSISTANT" />
|
||||
<xs:enumeration value="AUDIO_USAGE_EMERGENCY" />
|
||||
<xs:enumeration value="AUDIO_USAGE_SAFETY" />
|
||||
<xs:enumeration value="AUDIO_USAGE_VEHICLE_STATUS" />
|
||||
<xs:enumeration value="AUDIO_USAGE_ANNOUNCEMENT" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="audioUsageList">
|
||||
<xs:list itemType="audioUsage"/>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="audioContentType">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">
|
||||
Audio content type expresses the general category of the content.
|
||||
Please consult frameworks/base/media/java/android/media/AudioAttributes.java
|
||||
for the description of each value.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="AUDIO_CONTENT_TYPE_UNKNOWN"/>
|
||||
<xs:enumeration value="AUDIO_CONTENT_TYPE_SPEECH"/>
|
||||
<xs:enumeration value="AUDIO_CONTENT_TYPE_MUSIC"/>
|
||||
<xs:enumeration value="AUDIO_CONTENT_TYPE_MOVIE"/>
|
||||
<xs:enumeration value="AUDIO_CONTENT_TYPE_SONIFICATION"/>
|
||||
<xs:enumeration value="AUDIO_CONTENT_TYPE_ULTRASOUND"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="samplingRates">
|
||||
<xs:list itemType="xs:nonNegativeInteger" />
|
||||
</xs:simpleType>
|
||||
|
@ -515,10 +579,19 @@
|
|||
<xs:simpleType name="channelMasks">
|
||||
<xs:list itemType="audioChannelMask" />
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="audioEncapsulationType">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="AUDIO_ENCAPSULATION_TYPE_NONE"/>
|
||||
<xs:enumeration value="AUDIO_ENCAPSULATION_TYPE_IEC61937"/>
|
||||
<xs:enumeration value="AUDIO_ENCAPSULATION_TYPE_PCM"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:complexType name="profile">
|
||||
<xs:attribute name="name" type="xs:token" use="optional"/>
|
||||
<xs:attribute name="format" type="extendableAudioFormat" use="optional"/>
|
||||
<xs:attribute name="samplingRates" type="samplingRates" use="optional"/>
|
||||
<xs:attribute name="channelMasks" type="channelMasks" use="optional"/>
|
||||
<xs:attribute name="encapsulationType" type="audioEncapsulationType" use="optional"/>
|
||||
</xs:complexType>
|
||||
<xs:simpleType name="audioGainMode">
|
||||
<xs:restriction base="xs:string">
|
||||
|
@ -539,6 +612,7 @@
|
|||
<xs:sequence>
|
||||
<xs:element name="gain" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="name" type="xs:token" use="required"/>
|
||||
<xs:attribute name="mode" type="audioGainModeMask" use="required"/>
|
||||
<xs:attribute name="channel_mask" type="audioChannelMask" use="optional"/>
|
||||
<xs:attribute name="minValueMB" type="xs:int" use="optional"/>
|
||||
|
|
|
@ -16,42 +16,27 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <aidl/android/hardware/audio/core/SurroundSoundConfig.h>
|
||||
#include <aidl/android/media/audio/common/AudioHalEngineConfig.h>
|
||||
#include <android_audio_policy_configuration.h>
|
||||
#include <android_audio_policy_configuration_enums.h>
|
||||
#include <media/AidlConversionUtil.h>
|
||||
|
||||
#include "core-impl/Module.h"
|
||||
#include "core-impl/XmlConverter.h"
|
||||
|
||||
namespace aidl::android::hardware::audio::core::internal {
|
||||
|
||||
class AudioPolicyConfigXmlConverter {
|
||||
public:
|
||||
using ModuleConfiguration = std::pair<std::string, std::unique_ptr<Module::Configuration>>;
|
||||
using ModuleConfigs = std::vector<ModuleConfiguration>;
|
||||
|
||||
explicit AudioPolicyConfigXmlConverter(const std::string& configFilePath)
|
||||
: mConverter(configFilePath, &::android::audio::policy::configuration::read) {
|
||||
if (mConverter.getXsdcConfig()) {
|
||||
init();
|
||||
}
|
||||
}
|
||||
: mConverter(configFilePath, &::android::audio::policy::configuration::read) {}
|
||||
|
||||
std::string getError() const { return mConverter.getError(); }
|
||||
::android::status_t getStatus() const { return mConverter.getStatus(); }
|
||||
|
||||
const ::aidl::android::media::audio::common::AudioHalEngineConfig& getAidlEngineConfig();
|
||||
const SurroundSoundConfig& getSurroundSoundConfig();
|
||||
std::unique_ptr<ModuleConfigs> releaseModuleConfigs();
|
||||
|
||||
// Public for testing purposes.
|
||||
static const SurroundSoundConfig& getDefaultSurroundSoundConfig();
|
||||
|
@ -62,13 +47,13 @@ class AudioPolicyConfigXmlConverter {
|
|||
return mConverter.getXsdcConfig();
|
||||
}
|
||||
void addVolumeGroupstoEngineConfig();
|
||||
void init();
|
||||
void mapStreamToVolumeCurve(
|
||||
const ::android::audio::policy::configuration::Volume& xsdcVolumeCurve);
|
||||
void mapStreamsToVolumeCurves();
|
||||
void parseVolumes();
|
||||
ConversionResult<::aidl::android::media::audio::common::AudioHalVolumeCurve>
|
||||
convertVolumeCurveToAidl(
|
||||
::aidl::android::media::audio::common::AudioHalVolumeCurve::CurvePoint convertCurvePointToAidl(
|
||||
const std::string& xsdcCurvePoint);
|
||||
::aidl::android::media::audio::common::AudioHalVolumeCurve convertVolumeCurveToAidl(
|
||||
const ::android::audio::policy::configuration::Volume& xsdcVolumeCurve);
|
||||
|
||||
::aidl::android::media::audio::common::AudioHalEngineConfig mAidlEngineConfig;
|
||||
|
@ -78,7 +63,6 @@ class AudioPolicyConfigXmlConverter {
|
|||
std::unordered_map<::android::audio::policy::configuration::AudioStreamType,
|
||||
std::vector<::aidl::android::media::audio::common::AudioHalVolumeCurve>>
|
||||
mStreamToVolumeCurvesMap;
|
||||
std::unique_ptr<ModuleConfigs> mModuleConfigurations = std::make_unique<ModuleConfigs>();
|
||||
};
|
||||
|
||||
} // namespace aidl::android::hardware::audio::core::internal
|
||||
|
|
|
@ -42,16 +42,12 @@ struct ChildInterface : private std::pair<std::shared_ptr<C>, ndk::SpAIBinder> {
|
|||
C* operator->() const { return this->first; }
|
||||
// Use 'getInstance' when returning the interface instance.
|
||||
std::shared_ptr<C> getInstance() {
|
||||
(void)getBinder();
|
||||
return this->first;
|
||||
}
|
||||
AIBinder* getBinder() {
|
||||
if (this->second.get() == nullptr) {
|
||||
this->second = this->first->asBinder();
|
||||
AIBinder_setMinSchedulerPolicy(this->second.get(), SCHED_NORMAL,
|
||||
ANDROID_PRIORITY_AUDIO);
|
||||
}
|
||||
return this->second.get();
|
||||
return this->first;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -26,16 +26,11 @@ namespace aidl::android::hardware::audio::core {
|
|||
static const std::string kEngineConfigFileName = "audio_policy_engine_configuration.xml";
|
||||
|
||||
class Config : public BnConfig {
|
||||
public:
|
||||
explicit Config(internal::AudioPolicyConfigXmlConverter& apConverter)
|
||||
: mAudioPolicyConverter(apConverter) {}
|
||||
|
||||
private:
|
||||
ndk::ScopedAStatus getSurroundSoundConfig(SurroundSoundConfig* _aidl_return) override;
|
||||
ndk::ScopedAStatus getEngineConfig(
|
||||
aidl::android::media::audio::common::AudioHalEngineConfig* _aidl_return) override;
|
||||
|
||||
internal::AudioPolicyConfigXmlConverter& mAudioPolicyConverter;
|
||||
internal::AudioPolicyConfigXmlConverter mAudioPolicyConverter{
|
||||
::android::audio_get_audio_policy_config_file()};
|
||||
internal::EngineConfigXmlConverter mEngConfigConverter{
|
||||
::android::audio_find_readable_configuration_file(kEngineConfigFileName.c_str())};
|
||||
};
|
||||
|
|
|
@ -16,12 +16,37 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "Module.h"
|
||||
#include <aidl/android/hardware/audio/core/AudioPatch.h>
|
||||
#include <aidl/android/hardware/audio/core/AudioRoute.h>
|
||||
#include <aidl/android/media/audio/common/AudioPort.h>
|
||||
#include <aidl/android/media/audio/common/AudioPortConfig.h>
|
||||
#include <aidl/android/media/audio/common/MicrophoneInfo.h>
|
||||
|
||||
namespace aidl::android::hardware::audio::core::internal {
|
||||
|
||||
std::unique_ptr<Module::Configuration> getConfiguration(Module::Type moduleType);
|
||||
struct Configuration {
|
||||
std::vector<::aidl::android::media::audio::common::MicrophoneInfo> microphones;
|
||||
std::vector<::aidl::android::media::audio::common::AudioPort> ports;
|
||||
std::vector<::aidl::android::media::audio::common::AudioPortConfig> portConfigs;
|
||||
std::vector<::aidl::android::media::audio::common::AudioPortConfig> initialConfigs;
|
||||
// Port id -> List of profiles to use when the device port state is set to 'connected'
|
||||
// in connection simulation mode.
|
||||
std::map<int32_t, std::vector<::aidl::android::media::audio::common::AudioProfile>>
|
||||
connectedProfiles;
|
||||
std::vector<AudioRoute> routes;
|
||||
std::vector<AudioPatch> patches;
|
||||
int32_t nextPortId = 1;
|
||||
int32_t nextPatchId = 1;
|
||||
};
|
||||
|
||||
std::unique_ptr<Configuration> getPrimaryConfiguration();
|
||||
std::unique_ptr<Configuration> getRSubmixConfiguration();
|
||||
std::unique_ptr<Configuration> getStubConfiguration();
|
||||
std::unique_ptr<Configuration> getUsbConfiguration();
|
||||
std::unique_ptr<Configuration> getBluetoothConfiguration();
|
||||
|
||||
} // namespace aidl::android::hardware::audio::core::internal
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <utils/Errors.h>
|
||||
|
||||
#include <android_audio_policy_engine_configuration.h>
|
||||
#include <android_audio_policy_engine_configuration_enums.h>
|
||||
#include <media/AidlConversionUtil.h>
|
||||
|
||||
#include "core-impl/XmlConverter.h"
|
||||
|
||||
|
@ -48,24 +49,29 @@ class EngineConfigXmlConverter {
|
|||
}
|
||||
void init();
|
||||
void initProductStrategyMap();
|
||||
ConversionResult<::aidl::android::media::audio::common::AudioAttributes>
|
||||
convertAudioAttributesToAidl(
|
||||
::aidl::android::media::audio::common::AudioAttributes convertAudioAttributesToAidl(
|
||||
const ::android::audio::policy::engine::configuration::AttributesType&
|
||||
xsdcAudioAttributes);
|
||||
ConversionResult<::aidl::android::media::audio::common::AudioHalAttributesGroup>
|
||||
convertAttributesGroupToAidl(
|
||||
::aidl::android::media::audio::common::AudioHalAttributesGroup convertAttributesGroupToAidl(
|
||||
const ::android::audio::policy::engine::configuration::AttributesGroup&
|
||||
xsdcAttributesGroup);
|
||||
ConversionResult<::aidl::android::media::audio::common::AudioHalProductStrategy>
|
||||
convertProductStrategyToAidl(const ::android::audio::policy::engine::configuration::
|
||||
ProductStrategies::ProductStrategy& xsdcProductStrategy);
|
||||
ConversionResult<int> convertProductStrategyNameToAidl(
|
||||
const std::string& xsdcProductStrategyName);
|
||||
ConversionResult<::aidl::android::media::audio::common::AudioHalVolumeCurve>
|
||||
convertVolumeCurveToAidl(
|
||||
::aidl::android::media::audio::common::AudioHalCapCriterion convertCapCriterionToAidl(
|
||||
const ::android::audio::policy::engine::configuration::CriterionType& xsdcCriterion);
|
||||
::aidl::android::media::audio::common::AudioHalCapCriterionType convertCapCriterionTypeToAidl(
|
||||
const ::android::audio::policy::engine::configuration::CriterionTypeType&
|
||||
xsdcCriterionType);
|
||||
std::string convertCriterionTypeValueToAidl(
|
||||
const ::android::audio::policy::engine::configuration::ValueType&
|
||||
xsdcCriterionTypeValue);
|
||||
::aidl::android::media::audio::common::AudioHalVolumeCurve::CurvePoint convertCurvePointToAidl(
|
||||
const std::string& xsdcCurvePoint);
|
||||
::aidl::android::media::audio::common::AudioHalProductStrategy convertProductStrategyToAidl(
|
||||
const ::android::audio::policy::engine::configuration::ProductStrategies::
|
||||
ProductStrategy& xsdcProductStrategy);
|
||||
int convertProductStrategyNameToAidl(const std::string& xsdcProductStrategyName);
|
||||
::aidl::android::media::audio::common::AudioHalVolumeCurve convertVolumeCurveToAidl(
|
||||
const ::android::audio::policy::engine::configuration::Volume& xsdcVolumeCurve);
|
||||
ConversionResult<::aidl::android::media::audio::common::AudioHalVolumeGroup>
|
||||
convertVolumeGroupToAidl(
|
||||
::aidl::android::media::audio::common::AudioHalVolumeGroup convertVolumeGroupToAidl(
|
||||
const ::android::audio::policy::engine::configuration::VolumeGroupsType::VolumeGroup&
|
||||
xsdcVolumeGroup);
|
||||
|
||||
|
|
|
@ -19,51 +19,31 @@
|
|||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
|
||||
#include <aidl/android/hardware/audio/core/BnModule.h>
|
||||
|
||||
#include "core-impl/ChildInterface.h"
|
||||
#include "core-impl/Configuration.h"
|
||||
#include "core-impl/Stream.h"
|
||||
|
||||
namespace aidl::android::hardware::audio::core {
|
||||
|
||||
class Module : public BnModule {
|
||||
public:
|
||||
struct Configuration {
|
||||
std::vector<::aidl::android::media::audio::common::MicrophoneInfo> microphones;
|
||||
std::vector<::aidl::android::media::audio::common::AudioPort> ports;
|
||||
std::vector<::aidl::android::media::audio::common::AudioPortConfig> portConfigs;
|
||||
std::vector<::aidl::android::media::audio::common::AudioPortConfig> initialConfigs;
|
||||
// Port id -> List of profiles to use when the device port state is set to 'connected'
|
||||
// in connection simulation mode.
|
||||
std::map<int32_t, std::vector<::aidl::android::media::audio::common::AudioProfile>>
|
||||
connectedProfiles;
|
||||
std::vector<AudioRoute> routes;
|
||||
std::vector<AudioPatch> patches;
|
||||
int32_t nextPortId = 1;
|
||||
int32_t nextPatchId = 1;
|
||||
};
|
||||
// This value is used for all AudioPatches and reported by all streams.
|
||||
static constexpr int32_t kLatencyMs = 10;
|
||||
enum Type : int { DEFAULT, R_SUBMIX, STUB, USB, BLUETOOTH };
|
||||
enum BtInterface : int { BTCONF, BTA2DP, BTLE };
|
||||
|
||||
static std::shared_ptr<Module> createInstance(Type type);
|
||||
|
||||
explicit Module(Type type) : mType(type) {}
|
||||
|
||||
typedef std::tuple<std::weak_ptr<IBluetooth>, std::weak_ptr<IBluetoothA2dp>,
|
||||
std::weak_ptr<IBluetoothLe>>
|
||||
BtProfileHandles;
|
||||
|
||||
// This value is used by default for all AudioPatches and reported by all streams.
|
||||
static constexpr int32_t kLatencyMs = 10;
|
||||
|
||||
static std::shared_ptr<Module> createInstance(Type type) {
|
||||
return createInstance(type, std::make_unique<Configuration>());
|
||||
}
|
||||
static std::shared_ptr<Module> createInstance(Type type,
|
||||
std::unique_ptr<Configuration>&& config);
|
||||
static std::optional<Type> typeFromString(const std::string& type);
|
||||
|
||||
Module(Type type, std::unique_ptr<Configuration>&& config)
|
||||
: mType(type), mConfig(std::move(config)) {}
|
||||
|
||||
protected:
|
||||
// The vendor extension done via inheritance can override interface methods and augment
|
||||
// a call to the base implementation.
|
||||
|
@ -168,7 +148,7 @@ class Module : public BnModule {
|
|||
using Patches = std::multimap<int32_t, int32_t>;
|
||||
|
||||
const Type mType;
|
||||
std::unique_ptr<Configuration> mConfig;
|
||||
std::unique_ptr<internal::Configuration> mConfig;
|
||||
ModuleDebug mDebug;
|
||||
VendorDebug mVendorDebug;
|
||||
ConnectedDevicePorts mConnectedDevicePorts;
|
||||
|
@ -207,7 +187,7 @@ class Module : public BnModule {
|
|||
const ::aidl::android::media::audio::common::AudioPort& audioPort, bool connected);
|
||||
virtual ndk::ScopedAStatus onMasterMuteChanged(bool mute);
|
||||
virtual ndk::ScopedAStatus onMasterVolumeChanged(float volume);
|
||||
virtual std::unique_ptr<Configuration> initializeConfig();
|
||||
virtual std::unique_ptr<internal::Configuration> initializeConfig();
|
||||
|
||||
// Utility and helper functions accessible to subclasses.
|
||||
ndk::ScopedAStatus bluetoothParametersUpdated();
|
||||
|
@ -224,7 +204,7 @@ class Module : public BnModule {
|
|||
int32_t in_portConfigId, ::aidl::android::media::audio::common::AudioPort** port);
|
||||
std::vector<AudioRoute*> getAudioRoutesForAudioPortImpl(int32_t portId);
|
||||
virtual BtProfileHandles getBtProfileManagerHandles();
|
||||
Configuration& getConfig();
|
||||
internal::Configuration& getConfig();
|
||||
const ConnectedDevicePorts& getConnectedDevicePorts() const { return mConnectedDevicePorts; }
|
||||
bool getMasterMute() const { return mMasterMute; }
|
||||
bool getMasterVolume() const { return mMasterVolume; }
|
||||
|
|
|
@ -27,8 +27,7 @@ namespace aidl::android::hardware::audio::core {
|
|||
// provide necessary overrides for all interface methods omitted here.
|
||||
class ModuleAlsa : public Module {
|
||||
public:
|
||||
ModuleAlsa(Type type, std::unique_ptr<Configuration>&& config)
|
||||
: Module(type, std::move(config)) {}
|
||||
explicit ModuleAlsa(Module::Type type) : Module(type) {}
|
||||
|
||||
protected:
|
||||
// Extension methods of 'Module'.
|
||||
|
|
|
@ -23,8 +23,7 @@ namespace aidl::android::hardware::audio::core {
|
|||
|
||||
class ModuleBluetooth final : public Module {
|
||||
public:
|
||||
ModuleBluetooth(std::unique_ptr<Configuration>&& config)
|
||||
: Module(Type::BLUETOOTH, std::move(config)) {}
|
||||
ModuleBluetooth() : Module(Type::BLUETOOTH) {}
|
||||
|
||||
private:
|
||||
BtProfileHandles getBtProfileManagerHandles() override;
|
||||
|
|
|
@ -22,8 +22,7 @@ namespace aidl::android::hardware::audio::core {
|
|||
|
||||
class ModulePrimary final : public Module {
|
||||
public:
|
||||
ModulePrimary(std::unique_ptr<Configuration>&& config)
|
||||
: Module(Type::DEFAULT, std::move(config)) {}
|
||||
ModulePrimary() : Module(Type::DEFAULT) {}
|
||||
|
||||
protected:
|
||||
ndk::ScopedAStatus getTelephony(std::shared_ptr<ITelephony>* _aidl_return) override;
|
||||
|
|
|
@ -22,8 +22,7 @@ namespace aidl::android::hardware::audio::core {
|
|||
|
||||
class ModuleRemoteSubmix : public Module {
|
||||
public:
|
||||
ModuleRemoteSubmix(std::unique_ptr<Configuration>&& config)
|
||||
: Module(Type::R_SUBMIX, std::move(config)) {}
|
||||
ModuleRemoteSubmix() : Module(Type::R_SUBMIX) {}
|
||||
|
||||
private:
|
||||
// IModule interfaces
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace aidl::android::hardware::audio::core {
|
|||
|
||||
class ModuleStub final : public Module {
|
||||
public:
|
||||
ModuleStub(std::unique_ptr<Configuration>&& config) : Module(Type::STUB, std::move(config)) {}
|
||||
ModuleStub() : Module(Type::STUB) {}
|
||||
|
||||
protected:
|
||||
ndk::ScopedAStatus getBluetooth(std::shared_ptr<IBluetooth>* _aidl_return) override;
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace aidl::android::hardware::audio::core {
|
|||
|
||||
class ModuleUsb final : public ModuleAlsa {
|
||||
public:
|
||||
ModuleUsb(std::unique_ptr<Configuration>&& config) : ModuleAlsa(Type::USB, std::move(config)) {}
|
||||
ModuleUsb() : ModuleAlsa(Type::USB) {}
|
||||
|
||||
private:
|
||||
// IModule interfaces
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <media/AidlConversionUtil.h>
|
||||
#include <system/audio_config.h>
|
||||
#include <utils/Errors.h>
|
||||
|
||||
namespace aidl::android::hardware::audio::core::internal {
|
||||
|
||||
|
@ -84,10 +85,10 @@ class XmlConverter {
|
|||
* </Modules>
|
||||
*/
|
||||
template <typename W, typename X, typename A>
|
||||
static ConversionResult<std::vector<A>> convertWrappedCollectionToAidl(
|
||||
std::vector<A> convertWrappedCollectionToAidlUnchecked(
|
||||
const std::vector<W>& xsdcWrapperTypeVec,
|
||||
std::function<const std::vector<X>&(const W&)> getInnerTypeVec,
|
||||
std::function<ConversionResult<A>(const X&)> convertToAidl) {
|
||||
std::function<A(const X&)> convertToAidl) {
|
||||
std::vector<A> resultAidlTypeVec;
|
||||
if (!xsdcWrapperTypeVec.empty()) {
|
||||
/*
|
||||
|
@ -97,23 +98,21 @@ static ConversionResult<std::vector<A>> convertWrappedCollectionToAidl(
|
|||
*/
|
||||
resultAidlTypeVec.reserve(getInnerTypeVec(xsdcWrapperTypeVec[0]).size());
|
||||
for (const W& xsdcWrapperType : xsdcWrapperTypeVec) {
|
||||
for (const X& xsdcType : getInnerTypeVec(xsdcWrapperType)) {
|
||||
resultAidlTypeVec.push_back(VALUE_OR_FATAL(convertToAidl(xsdcType)));
|
||||
}
|
||||
std::transform(getInnerTypeVec(xsdcWrapperType).begin(),
|
||||
getInnerTypeVec(xsdcWrapperType).end(),
|
||||
std::back_inserter(resultAidlTypeVec), convertToAidl);
|
||||
}
|
||||
}
|
||||
return resultAidlTypeVec;
|
||||
}
|
||||
|
||||
template <typename X, typename A>
|
||||
static ConversionResult<std::vector<A>> convertCollectionToAidl(
|
||||
const std::vector<X>& xsdcTypeVec,
|
||||
std::function<ConversionResult<A>(const X&)> convertToAidl) {
|
||||
std::vector<A> convertCollectionToAidlUnchecked(const std::vector<X>& xsdcTypeVec,
|
||||
std::function<A(const X&)> itemConversion) {
|
||||
std::vector<A> resultAidlTypeVec;
|
||||
resultAidlTypeVec.reserve(xsdcTypeVec.size());
|
||||
for (const X& xsdcType : xsdcTypeVec) {
|
||||
resultAidlTypeVec.push_back(VALUE_OR_FATAL(convertToAidl(xsdcType)));
|
||||
}
|
||||
std::transform(xsdcTypeVec.begin(), xsdcTypeVec.end(), std::back_inserter(resultAidlTypeVec),
|
||||
itemConversion);
|
||||
return resultAidlTypeVec;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <aidl/android/media/audio/common/AudioHalCapCriterion.h>
|
||||
#include <aidl/android/media/audio/common/AudioHalCapCriterionType.h>
|
||||
#include <aidl/android/media/audio/common/AudioHalVolumeCurve.h>
|
||||
#include <aidl/android/media/audio/common/AudioPort.h>
|
||||
#include <android_audio_policy_configuration.h>
|
||||
#include <android_audio_policy_configuration_enums.h>
|
||||
#include <android_audio_policy_engine_configuration.h>
|
||||
#include <media/AidlConversionUtil.h>
|
||||
|
||||
#include "core-impl/Module.h"
|
||||
|
||||
namespace aidl::android::hardware::audio::core::internal {
|
||||
|
||||
ConversionResult<::aidl::android::media::audio::common::AudioHalCapCriterion>
|
||||
convertCapCriterionToAidl(
|
||||
const ::android::audio::policy::engine::configuration::CriterionType& xsdcCriterion);
|
||||
ConversionResult<::aidl::android::media::audio::common::AudioHalCapCriterionType>
|
||||
convertCapCriterionTypeToAidl(
|
||||
const ::android::audio::policy::engine::configuration::CriterionTypeType&
|
||||
xsdcCriterionType);
|
||||
ConversionResult<::aidl::android::media::audio::common::AudioHalVolumeCurve::CurvePoint>
|
||||
convertCurvePointToAidl(const std::string& xsdcCurvePoint);
|
||||
ConversionResult<std::unique_ptr<Module::Configuration>> convertModuleConfigToAidl(
|
||||
const ::android::audio::policy::configuration::Modules::Module& moduleConfig);
|
||||
} // namespace aidl::android::hardware::audio::core::internal
|
|
@ -16,51 +16,21 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#define LOG_TAG "AHAL_Main"
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android/binder_ibinder_platform.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
|
||||
#include "core-impl/AudioPolicyConfigXmlConverter.h"
|
||||
#include "core-impl/ChildInterface.h"
|
||||
#include "core-impl/Config.h"
|
||||
#include "core-impl/Module.h"
|
||||
|
||||
using aidl::android::hardware::audio::core::ChildInterface;
|
||||
using aidl::android::hardware::audio::core::Config;
|
||||
using aidl::android::hardware::audio::core::Module;
|
||||
using aidl::android::hardware::audio::core::internal::AudioPolicyConfigXmlConverter;
|
||||
|
||||
namespace {
|
||||
|
||||
ChildInterface<Module> createModule(const std::string& name,
|
||||
std::unique_ptr<Module::Configuration>&& config) {
|
||||
ChildInterface<Module> result;
|
||||
{
|
||||
auto moduleType = Module::typeFromString(name);
|
||||
if (!moduleType.has_value()) {
|
||||
LOG(ERROR) << __func__ << ": module type \"" << name << "\" is not supported";
|
||||
return result;
|
||||
}
|
||||
auto module = Module::createInstance(*moduleType, std::move(config));
|
||||
if (module == nullptr) return result;
|
||||
result = std::move(module);
|
||||
}
|
||||
const std::string moduleFqn = std::string().append(Module::descriptor).append("/").append(name);
|
||||
binder_status_t status = AServiceManager_addService(result.getBinder(), moduleFqn.c_str());
|
||||
if (status != STATUS_OK) {
|
||||
LOG(ERROR) << __func__ << ": failed to register service for \"" << moduleFqn << "\"";
|
||||
return ChildInterface<Module>();
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
// Random values are used in the implementation.
|
||||
|
@ -75,27 +45,29 @@ int main() {
|
|||
// Guaranteed log for b/210919187 and logd_integration_test
|
||||
LOG(INFO) << "Init for Audio AIDL HAL";
|
||||
|
||||
AudioPolicyConfigXmlConverter audioPolicyConverter{
|
||||
::android::audio_get_audio_policy_config_file()};
|
||||
|
||||
// Make the default config service
|
||||
auto config = ndk::SharedRefBase::make<Config>(audioPolicyConverter);
|
||||
const std::string configFqn = std::string().append(Config::descriptor).append("/default");
|
||||
auto config = ndk::SharedRefBase::make<Config>();
|
||||
const std::string configName = std::string() + Config::descriptor + "/default";
|
||||
binder_status_t status =
|
||||
AServiceManager_addService(config->asBinder().get(), configFqn.c_str());
|
||||
if (status != STATUS_OK) {
|
||||
LOG(ERROR) << "failed to register service for \"" << configFqn << "\"";
|
||||
}
|
||||
AServiceManager_addService(config->asBinder().get(), configName.c_str());
|
||||
CHECK_EQ(STATUS_OK, status);
|
||||
|
||||
// Make modules
|
||||
std::vector<ChildInterface<Module>> moduleInstances;
|
||||
auto configs(audioPolicyConverter.releaseModuleConfigs());
|
||||
for (std::pair<std::string, std::unique_ptr<Module::Configuration>>& configPair : *configs) {
|
||||
std::string name = configPair.first;
|
||||
if (auto instance = createModule(name, std::move(configPair.second)); instance) {
|
||||
moduleInstances.push_back(std::move(instance));
|
||||
}
|
||||
}
|
||||
auto createModule = [](Module::Type type) {
|
||||
auto module = Module::createInstance(type);
|
||||
ndk::SpAIBinder moduleBinder = module->asBinder();
|
||||
std::stringstream moduleName;
|
||||
moduleName << Module::descriptor << "/" << type;
|
||||
AIBinder_setMinSchedulerPolicy(moduleBinder.get(), SCHED_NORMAL, ANDROID_PRIORITY_AUDIO);
|
||||
binder_status_t status =
|
||||
AServiceManager_addService(moduleBinder.get(), moduleName.str().c_str());
|
||||
CHECK_EQ(STATUS_OK, status);
|
||||
return std::make_pair(module, moduleBinder);
|
||||
};
|
||||
auto modules = {createModule(Module::Type::DEFAULT), createModule(Module::Type::R_SUBMIX),
|
||||
createModule(Module::Type::USB), createModule(Module::Type::STUB),
|
||||
createModule(Module::Type::BLUETOOTH)};
|
||||
(void)modules;
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
|
|
Loading…
Reference in a new issue