BassBoost : Add minimum and maximum capabilities for params.
Bug: 263416041
Test: atest VtsHalBassBoostTargetTest
Change-Id: I9ab9c6aa10dd860104ed2d45f9cf96e32d55cc1f
diff --git a/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/BassBoost.aidl b/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/BassBoost.aidl
index 09ad015..f8baa2a 100644
--- a/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/BassBoost.aidl
+++ b/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/BassBoost.aidl
@@ -36,8 +36,6 @@
union BassBoost {
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 @@
@VintfStability
parcelable Capability {
ParcelableHolder extension;
+ int maxStrengthPm;
boolean strengthSupported;
}
}
diff --git a/audio/aidl/android/hardware/audio/effect/BassBoost.aidl b/audio/aidl/android/hardware/audio/effect/BassBoost.aidl
index 9e5d8aa..6a94242 100644
--- a/audio/aidl/android/hardware/audio/effect/BassBoost.aidl
+++ b/audio/aidl/android/hardware/audio/effect/BassBoost.aidl
@@ -52,6 +52,10 @@
*/
ParcelableHolder 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 return EX_ILLEGAL_ARGUMENT.
*/
@@ -59,23 +63,14 @@
}
/**
- * 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 bass boost effect.
*
* If the implementation does not support per mille accuracy for setting the strength, it is
* 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;
}
diff --git a/audio/aidl/default/bassboost/BassBoostSw.cpp b/audio/aidl/default/bassboost/BassBoostSw.cpp
index 8e4779d..0c7ebe1 100644
--- a/audio/aidl/default/bassboost/BassBoostSw.cpp
+++ b/audio/aidl/default/bassboost/BassBoostSw.cpp
@@ -62,7 +62,8 @@
const std::string BassBoostSw::kEffectName = "BassBoostSw";
const bool BassBoostSw::kStrengthSupported = true;
-const BassBoost::Capability BassBoostSw::kCapability = {.strengthSupported = kStrengthSupported};
+const BassBoost::Capability BassBoostSw::kCapability = {.maxStrengthPm = 1000,
+ .strengthSupported = kStrengthSupported};
const Descriptor BassBoostSw::kDescriptor = {
.common = {.id = {.type = kBassBoostTypeUUID,
.uuid = kBassBoostSwImplUUID,
@@ -171,4 +172,14 @@
return {STATUS_OK, samples, samples};
}
+RetCode BassBoostSwContext::setBbStrengthPm(int strength) {
+ if (strength < 0 || strength > BassBoostSw::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
diff --git a/audio/aidl/default/bassboost/BassBoostSw.h b/audio/aidl/default/bassboost/BassBoostSw.h
index 91086e9..65c01c8 100644
--- a/audio/aidl/default/bassboost/BassBoostSw.h
+++ b/audio/aidl/default/bassboost/BassBoostSw.h
@@ -33,16 +33,7 @@
LOG(DEBUG) << __func__;
}
- RetCode setBbStrengthPm(int strength) {
- if (strength < BassBoost::MIN_PER_MILLE_STRENGTH ||
- strength > BassBoost::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 setBbStrengthPm(int strength);
int getBbStrengthPm() const { return mStrength; }
private:
diff --git a/audio/aidl/vts/VtsHalBassBoostTargetTest.cpp b/audio/aidl/vts/VtsHalBassBoostTargetTest.cpp
index 724a9c3..d49a865 100644
--- a/audio/aidl/vts/VtsHalBassBoostTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalBassBoostTargetTest.cpp
@@ -46,15 +46,6 @@
* otherwise expect EX_ILLEGAL_ARGUMENT.
*/
-const std::vector<int> kStrengthValues = {
- std::numeric_limits<int>::min(),
- BassBoost::MIN_PER_MILLE_STRENGTH - 1,
- BassBoost::MIN_PER_MILLE_STRENGTH,
- (BassBoost::MIN_PER_MILLE_STRENGTH + BassBoost::MAX_PER_MILLE_STRENGTH) >> 1,
- BassBoost::MAX_PER_MILLE_STRENGTH,
- BassBoost::MAX_PER_MILLE_STRENGTH + 2,
- std::numeric_limits<int>::max()};
-
class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestParam>,
public EffectHelper {
public:
@@ -81,7 +72,7 @@
}
Parameter::Specific getDefaultParamSpecific() {
- BassBoost bb = BassBoost::make<BassBoost::strengthPm>(BassBoost::MIN_PER_MILLE_STRENGTH);
+ BassBoost bb = BassBoost::make<BassBoost::strengthPm>(0);
Parameter::Specific specific =
Parameter::Specific::make<Parameter::Specific::bassBoost>(bb);
return specific;
@@ -91,7 +82,7 @@
std::shared_ptr<IFactory> mFactory;
std::shared_ptr<IEffect> mEffect;
Descriptor mDescriptor;
- int mParamStrength = BassBoost::MIN_PER_MILLE_STRENGTH;
+ int mParamStrength = 0;
void SetAndGetBassBoostParameters() {
for (auto& it : mTags) {
@@ -146,8 +137,29 @@
}
bool isStrengthInRange(const BassBoost::Capability& cap, int strength) const {
- return cap.strengthSupported && strength >= BassBoost::MIN_PER_MILLE_STRENGTH &&
- strength <= BassBoost::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::bassBoost>().maxStrengthPm <
+ b.second.capability.get<Capability::bassBoost>().maxStrengthPm;
+ });
+ if (max == kFactoryDescList.end()) {
+ return {0};
+ }
+ int maxStrength = max->second.capability.get<Capability::bassBoost>().maxStrengthPm;
+ return {std::numeric_limits<int>::min(),
+ -1,
+ 0,
+ maxStrength >> 1,
+ maxStrength,
+ maxStrength + 1,
+ std::numeric_limits<int>::max()};
}
private:
@@ -162,9 +174,12 @@
INSTANTIATE_TEST_SUITE_P(
BassBoostTest, BassBoostParamTest,
- ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
- IFactory::descriptor, kBassBoostTypeUUID)),
- testing::ValuesIn(kStrengthValues)),
+ ::testing::Combine(
+ testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
+ kBassBoostTypeUUID)),
+ testing::ValuesIn(BassBoostParamTest::getStrengthTestValues(
+ EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
+ kBassBoostTypeUUID)))),
[](const testing::TestParamInfo<BassBoostParamTest::ParamType>& info) {
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string strength = std::to_string(std::get<PARAM_STRENGTH>(info.param));