mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:50:18 +00:00
Bug: 238913361 Test: atest VtsHalAudioEffectTargetTest atest VtsHalAudioEffectFactoryTargetTest atest VtsHalEqualizerTargetTest Change-Id: I94b2283ca2aa0e45715e1c9ac3ea6ad809ec2a2c
234 lines
8.9 KiB
C++
234 lines
8.9 KiB
C++
/*
|
|
* Copyright (C) 2022 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <algorithm>
|
|
#include <limits>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#define LOG_TAG "VtsHalEqualizerTest"
|
|
|
|
#include <aidl/Gtest.h>
|
|
#include <aidl/Vintf.h>
|
|
#include <android-base/logging.h>
|
|
#include <android-base/properties.h>
|
|
#include <android/binder_interface_utils.h>
|
|
#include <android/binder_manager.h>
|
|
#include <android/binder_process.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <Utils.h>
|
|
#include <aidl/android/hardware/audio/effect/IEffect.h>
|
|
#include <aidl/android/hardware/audio/effect/IFactory.h>
|
|
#include <aidl/android/media/audio/common/AudioChannelLayout.h>
|
|
#include <aidl/android/media/audio/common/AudioDeviceType.h>
|
|
|
|
#include "AudioHalBinderServiceUtil.h"
|
|
#include "EffectHelper.h"
|
|
#include "TestUtils.h"
|
|
#include "effect-impl/EffectUUID.h"
|
|
|
|
using namespace android;
|
|
|
|
using aidl::android::hardware::audio::effect::Capability;
|
|
using aidl::android::hardware::audio::effect::Descriptor;
|
|
using aidl::android::hardware::audio::effect::EffectNullUuid;
|
|
using aidl::android::hardware::audio::effect::Equalizer;
|
|
using aidl::android::hardware::audio::effect::EqualizerTypeUUID;
|
|
using aidl::android::hardware::audio::effect::IEffect;
|
|
using aidl::android::hardware::audio::effect::IFactory;
|
|
using aidl::android::hardware::audio::effect::Parameter;
|
|
|
|
/**
|
|
* Here we focus on specific parameter checking, general IEffect interfaces testing performed in
|
|
* VtsAudioEfectTargetTest.
|
|
*/
|
|
using EqualizerParamTestParam = std::tuple<int, int, int>;
|
|
|
|
class EqualizerParamTest : public ::testing::TestWithParam<EqualizerParamTestParam>,
|
|
public EffectHelper {
|
|
public:
|
|
EqualizerParamTest()
|
|
: EffectHelper(android::getAidlHalInstanceNames(IFactory::descriptor)[0]),
|
|
mParamPresetIndex(std::get<0 /* kPresetIndexRange */>(GetParam())),
|
|
mParamBandIndex(std::get<1 /* kBandIndexRange */>(GetParam())),
|
|
mParamBandLevel(std::get<2 /* kBandLevelRange */>(GetParam())) {}
|
|
|
|
void SetUp() override {
|
|
CreateEffectsWithUUID(EqualizerTypeUUID);
|
|
initParamCommonFormat();
|
|
initParamCommon();
|
|
initParamSpecific();
|
|
OpenEffects(EqualizerTypeUUID);
|
|
SCOPED_TRACE(testing::Message() << "preset: " << mParamPresetIndex << " bandIdx "
|
|
<< mParamBandIndex << " level " << mParamBandLevel);
|
|
}
|
|
|
|
void TearDown() override {
|
|
CloseEffects();
|
|
DestroyEffects();
|
|
CleanUp();
|
|
}
|
|
|
|
const int mParamPresetIndex;
|
|
const int mParamBandIndex;
|
|
const int mParamBandLevel;
|
|
|
|
void SetAndGetEqualizerParameters() {
|
|
auto functor = [&](const std::shared_ptr<IEffect>& effect) {
|
|
for (auto& it : mTags) {
|
|
auto& tag = it.first;
|
|
auto& eq = it.second;
|
|
|
|
// validate parameter
|
|
Descriptor desc;
|
|
ASSERT_STATUS(EX_NONE, effect->getDescriptor(&desc));
|
|
const bool valid = isTagInRange(it.first, it.second, desc);
|
|
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
|
|
|
|
// set
|
|
Parameter expectParam;
|
|
Parameter::Specific specific;
|
|
specific.set<Parameter::Specific::equalizer>(*eq.get());
|
|
expectParam.set<Parameter::specific>(specific);
|
|
EXPECT_STATUS(expected, effect->setParameter(expectParam))
|
|
<< expectParam.toString();
|
|
|
|
// get
|
|
if (expected == EX_NONE) {
|
|
Parameter getParam;
|
|
Parameter::Specific::Id id;
|
|
id.set<Parameter::Specific::Id::equalizerTag>(tag);
|
|
// if set success, then get should match
|
|
EXPECT_STATUS(expected, effect->getParameter(id, &getParam));
|
|
EXPECT_EQ(expectParam, getParam) << "\n"
|
|
<< expectParam.toString() << "\n"
|
|
<< getParam.toString();
|
|
}
|
|
}
|
|
};
|
|
EXPECT_NO_FATAL_FAILURE(ForEachEffect(functor));
|
|
}
|
|
|
|
void addPresetParam(int preset) {
|
|
Equalizer eq;
|
|
eq.set<Equalizer::preset>(preset);
|
|
mTags.push_back({Equalizer::preset, std::make_unique<Equalizer>(std::move(eq))});
|
|
}
|
|
|
|
void addBandLevelsParam(std::vector<Equalizer::BandLevel>& bandLevels) {
|
|
Equalizer eq;
|
|
eq.set<Equalizer::bandLevels>(bandLevels);
|
|
mTags.push_back({Equalizer::bandLevels, std::make_unique<Equalizer>(std::move(eq))});
|
|
}
|
|
|
|
bool isTagInRange(const Equalizer::Tag& tag, const std::unique_ptr<Equalizer>& eq,
|
|
const Descriptor& desc) const {
|
|
std::cout << "xxx" << toString(tag) << " " << desc.toString();
|
|
const Equalizer::Capability& eqCap = desc.capability.get<Capability::equalizer>();
|
|
switch (tag) {
|
|
case Equalizer::preset: {
|
|
int index = eq->get<Equalizer::preset>();
|
|
return isPresetIndexInRange(eqCap, index);
|
|
}
|
|
case Equalizer::bandLevels: {
|
|
auto& bandLevel = eq->get<Equalizer::bandLevels>();
|
|
return isBandIndexInRange(eqCap, bandLevel);
|
|
}
|
|
default:
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool isPresetIndexInRange(const Equalizer::Capability& cap, int idx) const {
|
|
const auto [min, max] =
|
|
std::minmax_element(cap.presets.begin(), cap.presets.end(),
|
|
[](const auto& a, const auto& b) { return a.index < b.index; });
|
|
return idx >= min->index && idx <= max->index;
|
|
}
|
|
|
|
bool isBandIndexInRange(const Equalizer::Capability& cap,
|
|
const std::vector<Equalizer::BandLevel>& bandLevel) const {
|
|
for (auto& it : bandLevel) {
|
|
if (!isBandIndexInRange(cap, it.index)) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool isBandIndexInRange(const Equalizer::Capability& cap, int idx) const {
|
|
const auto [min, max] =
|
|
std::minmax_element(cap.bandFrequencies.begin(), cap.bandFrequencies.end(),
|
|
[](const auto& a, const auto& b) { return a.index < b.index; });
|
|
return idx >= min->index && idx <= max->index;
|
|
}
|
|
|
|
private:
|
|
Equalizer::VendorExtension mVendorExtension;
|
|
std::vector<std::pair<Equalizer::Tag, std::unique_ptr<Equalizer>>> mTags;
|
|
|
|
bool validCapabilityTag(Capability& cap) { return cap.getTag() == Capability::equalizer; }
|
|
|
|
void initParamSpecific() {
|
|
Equalizer eq;
|
|
eq.set<Equalizer::preset>(0);
|
|
Parameter::Specific specific;
|
|
specific.set<Parameter::Specific::equalizer>(eq);
|
|
setSpecific(specific);
|
|
}
|
|
|
|
void CleanUp() { mTags.clear(); }
|
|
};
|
|
|
|
TEST_P(EqualizerParamTest, SetAndGetPreset) {
|
|
EXPECT_NO_FATAL_FAILURE(addPresetParam(mParamPresetIndex));
|
|
SetAndGetEqualizerParameters();
|
|
}
|
|
|
|
TEST_P(EqualizerParamTest, SetAndGetSingleBand) {
|
|
Equalizer::BandLevel bandLevel = {mParamBandIndex, mParamBandLevel};
|
|
std::vector<Equalizer::BandLevel> bandLevels;
|
|
bandLevels.push_back(bandLevel);
|
|
EXPECT_NO_FATAL_FAILURE(addBandLevelsParam(bandLevels));
|
|
SetAndGetEqualizerParameters();
|
|
}
|
|
|
|
/**
|
|
Testing preset index range with [-10, 10], assuming the min/max preset index supported by
|
|
effect is in this range.
|
|
This range is verified with IEffect.getDescriptor(): for any index supported vts expect EX_NONE
|
|
from IEffect.setParameter(), otherwise expect EX_ILLEGAL_ARGUMENT.
|
|
*/
|
|
constexpr std::pair<int, int> kPresetIndexRange = {-1, 10}; // valid range [0, 9]
|
|
constexpr std::pair<int, int> kBandIndexRange = {-1, 5}; // valid range [0, 4]
|
|
constexpr std::pair<int, int> kBandLevelRange = {-5, 5}; // needs update with implementation
|
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
EqualizerTest, EqualizerParamTest,
|
|
::testing::Combine(testing::Range(kPresetIndexRange.first, kPresetIndexRange.second),
|
|
testing::Range(kBandIndexRange.first, kBandIndexRange.second),
|
|
testing::Range(kBandLevelRange.first, kBandLevelRange.second)));
|
|
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EqualizerTest);
|
|
|
|
int main(int argc, char** argv) {
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
ABinderProcess_setThreadPoolMaxThreadCount(1);
|
|
ABinderProcess_startThreadPool();
|
|
return RUN_ALL_TESTS();
|
|
}
|