mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-02 02:42:35 +00:00
Virtualizer : Add minimum and maximum capabilities for params.
Bug: 263416041 Test: atest VtsHalVirtualizerTargetTest Change-Id: Ic51135ffa685f64a945898bd0f9ebf12f8832ea6
This commit is contained in:
@@ -36,8 +36,6 @@ package android.hardware.audio.effect;
|
||||
union Virtualizer {
|
||||
android.hardware.audio.effect.VendorExtension vendor;
|
||||
int strengthPm;
|
||||
const int MIN_PER_MILLE_STRENGTH = 0;
|
||||
const int MAX_PER_MILLE_STRENGTH = 1000;
|
||||
@VintfStability
|
||||
union Id {
|
||||
int vendorExtensionTag;
|
||||
@@ -46,6 +44,7 @@ union Virtualizer {
|
||||
@VintfStability
|
||||
parcelable Capability {
|
||||
android.hardware.audio.effect.VendorExtension extension;
|
||||
int maxStrengthPm;
|
||||
boolean strengthSupported;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ union Virtualizer {
|
||||
* capability definition not enough.
|
||||
*/
|
||||
VendorExtension extension;
|
||||
/**
|
||||
* Maximum possible per mille strength.
|
||||
*/
|
||||
int maxStrengthPm;
|
||||
/**
|
||||
* Indicates whether setting strength is supported. False value indicates only one strength
|
||||
* is supported and setParameter() method will always return EX_ILLEGAL_ARGUMENT.
|
||||
@@ -59,16 +63,6 @@ union Virtualizer {
|
||||
boolean strengthSupported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimal possible per mille strength.
|
||||
*/
|
||||
const int MIN_PER_MILLE_STRENGTH = 0;
|
||||
|
||||
/**
|
||||
* Maximum possible per mille strength.
|
||||
*/
|
||||
const int MAX_PER_MILLE_STRENGTH = 1000;
|
||||
|
||||
/**
|
||||
* The per mille strength of the virtualizer effect.
|
||||
*
|
||||
@@ -76,7 +70,8 @@ union Virtualizer {
|
||||
* allowed to round the given strength to the nearest supported value. In this case {@link
|
||||
* #IEffect.getParameter()} method should return the rounded value that was actually set.
|
||||
*
|
||||
* The valid range for strength is [0, 1000].
|
||||
* The value of the strength must be non-negative and not exceed the value specified by
|
||||
* the 'maxStrengthPm' capability.
|
||||
*/
|
||||
int strengthPm;
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ namespace aidl::android::hardware::audio::effect {
|
||||
|
||||
const std::string VirtualizerSw::kEffectName = "VirtualizerSw";
|
||||
const bool VirtualizerSw::kStrengthSupported = true;
|
||||
const Virtualizer::Capability VirtualizerSw::kCapability = {.strengthSupported =
|
||||
kStrengthSupported};
|
||||
const Virtualizer::Capability VirtualizerSw::kCapability = {
|
||||
.maxStrengthPm = 1000, .strengthSupported = kStrengthSupported};
|
||||
const Descriptor VirtualizerSw::kDescriptor = {
|
||||
.common = {.id = {.type = kVirtualizerTypeUUID,
|
||||
.uuid = kVirtualizerSwImplUUID,
|
||||
@@ -172,4 +172,14 @@ IEffect::Status VirtualizerSw::effectProcessImpl(float* in, float* out, int samp
|
||||
return {STATUS_OK, samples, samples};
|
||||
}
|
||||
|
||||
RetCode VirtualizerSwContext::setVrStrength(int strength) {
|
||||
if (strength < 0 || strength > VirtualizerSw::kCapability.maxStrengthPm) {
|
||||
LOG(ERROR) << __func__ << " invalid strength: " << strength;
|
||||
return RetCode::ERROR_ILLEGAL_PARAMETER;
|
||||
}
|
||||
// TODO : Add implementation to apply new strength
|
||||
mStrength = strength;
|
||||
return RetCode::SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::audio::effect
|
||||
|
||||
@@ -32,16 +32,7 @@ class VirtualizerSwContext final : public EffectContext {
|
||||
: EffectContext(statusDepth, common) {
|
||||
LOG(DEBUG) << __func__;
|
||||
}
|
||||
RetCode setVrStrength(int strength) {
|
||||
if (strength < Virtualizer::MIN_PER_MILLE_STRENGTH ||
|
||||
strength > Virtualizer::MAX_PER_MILLE_STRENGTH) {
|
||||
LOG(ERROR) << __func__ << " invalid strength " << strength;
|
||||
return RetCode::ERROR_ILLEGAL_PARAMETER;
|
||||
}
|
||||
// TODO : Add implementation to apply new strength
|
||||
mStrength = strength;
|
||||
return RetCode::SUCCESS;
|
||||
}
|
||||
RetCode setVrStrength(int strength);
|
||||
int getVrStrength() const { return mStrength; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -44,11 +44,6 @@ using VirtualizerParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>
|
||||
* otherwise expect EX_ILLEGAL_ARGUMENT.
|
||||
*/
|
||||
|
||||
const std::vector<int> kStrengthValues = {
|
||||
std::numeric_limits<int>::min(), Virtualizer::MIN_PER_MILLE_STRENGTH - 1,
|
||||
Virtualizer::MIN_PER_MILLE_STRENGTH, Virtualizer::MAX_PER_MILLE_STRENGTH,
|
||||
Virtualizer::MAX_PER_MILLE_STRENGTH + 1, std::numeric_limits<int>::max()};
|
||||
|
||||
class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTestParam>,
|
||||
public EffectHelper {
|
||||
public:
|
||||
@@ -75,8 +70,7 @@ class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTes
|
||||
}
|
||||
|
||||
Parameter::Specific getDefaultParamSpecific() {
|
||||
Virtualizer vr =
|
||||
Virtualizer::make<Virtualizer::strengthPm>(Virtualizer::MIN_PER_MILLE_STRENGTH);
|
||||
Virtualizer vr = Virtualizer::make<Virtualizer::strengthPm>(0);
|
||||
Parameter::Specific specific =
|
||||
Parameter::Specific::make<Parameter::Specific::virtualizer>(vr);
|
||||
return specific;
|
||||
@@ -86,7 +80,7 @@ class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTes
|
||||
std::shared_ptr<IFactory> mFactory;
|
||||
std::shared_ptr<IEffect> mEffect;
|
||||
Descriptor mDescriptor;
|
||||
int mParamStrength = Virtualizer::MIN_PER_MILLE_STRENGTH;
|
||||
int mParamStrength = 0;
|
||||
|
||||
void SetAndGetVirtualizerParameters() {
|
||||
for (auto& it : mTags) {
|
||||
@@ -141,8 +135,29 @@ class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTes
|
||||
}
|
||||
|
||||
bool isStrengthInRange(const Virtualizer::Capability& cap, int strength) const {
|
||||
return cap.strengthSupported && strength >= Virtualizer::MIN_PER_MILLE_STRENGTH &&
|
||||
strength <= Virtualizer::MAX_PER_MILLE_STRENGTH;
|
||||
return cap.strengthSupported && strength >= 0 && strength <= cap.maxStrengthPm;
|
||||
}
|
||||
|
||||
static std::vector<int> getStrengthTestValues(
|
||||
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kFactoryDescList) {
|
||||
const auto max = std::max_element(
|
||||
kFactoryDescList.begin(), kFactoryDescList.end(),
|
||||
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
|
||||
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
|
||||
return a.second.capability.get<Capability::virtualizer>().maxStrengthPm <
|
||||
b.second.capability.get<Capability::virtualizer>().maxStrengthPm;
|
||||
});
|
||||
if (max == kFactoryDescList.end()) {
|
||||
return {0};
|
||||
}
|
||||
int maxStrength = max->second.capability.get<Capability::virtualizer>().maxStrengthPm;
|
||||
return {std::numeric_limits<int>::min(),
|
||||
-1,
|
||||
0,
|
||||
maxStrength >> 1,
|
||||
maxStrength,
|
||||
maxStrength + 1,
|
||||
std::numeric_limits<int>::max()};
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -159,7 +174,9 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
VirtualizerTest, VirtualizerParamTest,
|
||||
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
|
||||
IFactory::descriptor, kVirtualizerTypeUUID)),
|
||||
testing::ValuesIn(kStrengthValues)),
|
||||
testing::ValuesIn(VirtualizerParamTest::getStrengthTestValues(
|
||||
EffectFactoryHelper::getAllEffectDescriptors(
|
||||
IFactory::descriptor, kVirtualizerTypeUUID)))),
|
||||
[](const testing::TestParamInfo<VirtualizerParamTest::ParamType>& info) {
|
||||
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
|
||||
std::string strength = std::to_string(std::get<PARAM_STRENGTH>(info.param));
|
||||
|
||||
Reference in New Issue
Block a user