Merge changes I2dfd304c,I978432e2 am: a335badc22

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2300098

Change-Id: I6a9e8991b7953f6ae594f2675cecfdcdbbd5a4d7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2022-11-17 22:40:43 +00:00 committed by Automerger Merge Worker
commit 509d54d0d4
4 changed files with 238 additions and 104 deletions

View file

@ -76,16 +76,60 @@ ndk::ScopedAStatus LoudnessEnhancerSw::setParameterSpecific(const Parameter::Spe
std::lock_guard lg(mMutex);
RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");
mSpecificParam = specific.get<Parameter::Specific::loudnessEnhancer>();
LOG(DEBUG) << __func__ << " success with: " << specific.toString();
return ndk::ScopedAStatus::ok();
auto& leParam = specific.get<Parameter::Specific::loudnessEnhancer>();
auto tag = leParam.getTag();
switch (tag) {
case LoudnessEnhancer::gainMb: {
RETURN_IF(mContext->setLeGainMb(leParam.get<LoudnessEnhancer::gainMb>()) !=
RetCode::SUCCESS,
EX_ILLEGAL_ARGUMENT, "setGainMbFailed");
return ndk::ScopedAStatus::ok();
}
default: {
LOG(ERROR) << __func__ << " unsupported tag: " << toString(tag);
return ndk::ScopedAStatus::fromExceptionCodeWithMessage(
EX_ILLEGAL_ARGUMENT, "LoudnessEnhancerTagNotSupported");
}
}
}
ndk::ScopedAStatus LoudnessEnhancerSw::getParameterSpecific(const Parameter::Id& id,
Parameter::Specific* specific) {
auto tag = id.getTag();
RETURN_IF(Parameter::Id::loudnessEnhancerTag != tag, EX_ILLEGAL_ARGUMENT, "wrongIdTag");
specific->set<Parameter::Specific::loudnessEnhancer>(mSpecificParam);
auto leId = id.get<Parameter::Id::loudnessEnhancerTag>();
auto leIdTag = leId.getTag();
switch (leIdTag) {
case LoudnessEnhancer::Id::commonTag:
return getParameterLoudnessEnhancer(leId.get<LoudnessEnhancer::Id::commonTag>(),
specific);
default:
LOG(ERROR) << __func__ << " unsupported tag: " << toString(leIdTag);
return ndk::ScopedAStatus::fromExceptionCodeWithMessage(
EX_ILLEGAL_ARGUMENT, "LoudnessEnhancerTagNotSupported");
}
}
ndk::ScopedAStatus LoudnessEnhancerSw::getParameterLoudnessEnhancer(
const LoudnessEnhancer::Tag& tag, Parameter::Specific* specific) {
std::lock_guard lg(mMutex);
RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");
LoudnessEnhancer leParam;
switch (tag) {
case LoudnessEnhancer::gainMb: {
leParam.set<LoudnessEnhancer::gainMb>(mContext->getLeGainMb());
break;
}
default: {
LOG(ERROR) << __func__ << " unsupported tag: " << toString(tag);
return ndk::ScopedAStatus::fromExceptionCodeWithMessage(
EX_ILLEGAL_ARGUMENT, "LoudnessEnhancerTagNotSupported");
}
}
specific->set<Parameter::Specific::loudnessEnhancer>(leParam);
return ndk::ScopedAStatus::ok();
}

View file

@ -32,7 +32,16 @@ class LoudnessEnhancerSwContext final : public EffectContext {
: EffectContext(statusDepth, common) {
LOG(DEBUG) << __func__;
}
// TODO: add specific context here
RetCode setLeGainMb(int gainMb) {
// TODO : Add implementation to apply new gain
mGainMb = gainMb;
return RetCode::SUCCESS;
}
int getLeGainMb() const { return mGainMb; }
private:
int mGainMb = 0; // Default Gain
};
class LoudnessEnhancerSw final : public EffectImpl {
@ -66,7 +75,7 @@ class LoudnessEnhancerSw final : public EffectImpl {
.name = "LoudnessEnhancerSw"},
.capability = Capability::make<Capability::loudnessEnhancer>(kCapability)};
/* parameters */
LoudnessEnhancer mSpecificParam;
ndk::ScopedAStatus getParameterLoudnessEnhancer(const LoudnessEnhancer::Tag& tag,
Parameter::Specific* specific);
};
} // namespace aidl::android::hardware::audio::effect

View file

@ -7,136 +7,72 @@ package {
default_applicable_licenses: ["hardware_interfaces_license"],
}
cc_test {
name: "VtsHalAudioCoreTargetTest",
cc_defaults {
name: "VtsHalAudioTargetTestDefaults",
defaults: [
"VtsHalTargetTestDefaults",
"use_libaidlvintf_gtest_helper_static",
"latest_android_hardware_audio_common_ndk_static",
"latest_android_hardware_audio_core_ndk_static",
"latest_android_media_audio_common_types_ndk_static",
"use_libaidlvintf_gtest_helper_static",
"VtsHalTargetTestDefaults",
],
shared_libs: [
"libbinder_ndk",
"libcutils",
"libfmq",
],
static_libs: [
"android.hardware.audio.effect-V1-ndk",
"android.hardware.common-V2-ndk",
"android.hardware.common.fmq-V1-ndk",
"libaudioaidlcommon",
],
header_libs: ["libaudioaidl_headers"],
cflags: [
"-Wall",
"-Wextra",
"-Werror",
"-Wthread-safety",
],
test_suites: [
"general-tests",
"vts",
],
}
cc_test {
name: "VtsHalAudioCoreTargetTest",
defaults: [
"VtsHalAudioTargetTestDefaults",
"latest_android_hardware_audio_core_ndk_static",
],
shared_libs: [
"libcutils",
],
srcs: [
"ModuleConfig.cpp",
"VtsHalAudioCoreTargetTest.cpp",
],
test_suites: [
"general-tests",
"vts",
],
}
cc_test {
name: "VtsHalAudioEffectFactoryTargetTest",
defaults: [
"latest_android_media_audio_common_types_ndk_static",
"VtsHalTargetTestDefaults",
"use_libaidlvintf_gtest_helper_static",
],
srcs: [
"VtsHalAudioEffectFactoryTargetTest.cpp",
],
shared_libs: [
"libbinder_ndk",
],
static_libs: [
"android.hardware.audio.effect-V1-ndk",
"android.hardware.common-V2-ndk",
"android.hardware.common.fmq-V1-ndk",
],
header_libs: ["libaudioaidl_headers"],
cflags: [
"-Wall",
"-Wextra",
"-Werror",
"-Wthread-safety",
],
test_suites: [
"general-tests",
"vts",
],
defaults: ["VtsHalAudioTargetTestDefaults"],
srcs: ["VtsHalAudioEffectFactoryTargetTest.cpp"],
}
cc_test {
name: "VtsHalAudioEffectTargetTest",
defaults: [
"latest_android_hardware_audio_common_ndk_static",
"latest_android_media_audio_common_types_ndk_static",
"VtsHalTargetTestDefaults",
"use_libaidlvintf_gtest_helper_static",
],
srcs: [
"VtsHalAudioEffectTargetTest.cpp",
],
shared_libs: [
"libbinder_ndk",
"libfmq",
],
static_libs: [
"android.hardware.audio.effect-V1-ndk",
"android.hardware.common-V2-ndk",
"android.hardware.common.fmq-V1-ndk",
"libaudioaidlcommon",
],
header_libs: ["libaudioaidl_headers"],
cflags: [
"-Wall",
"-Wextra",
"-Werror",
"-Wthread-safety",
],
test_suites: [
"general-tests",
"vts",
],
defaults: ["VtsHalAudioTargetTestDefaults"],
srcs: ["VtsHalAudioEffectTargetTest.cpp"],
}
cc_test {
name: "VtsHalEqualizerTargetTest",
defaults: [
"latest_android_hardware_audio_common_ndk_static",
"latest_android_media_audio_common_types_ndk_static",
"VtsHalTargetTestDefaults",
"use_libaidlvintf_gtest_helper_static",
],
srcs: [
"VtsHalEqualizerTargetTest.cpp",
],
shared_libs: [
"libbinder_ndk",
"libfmq",
],
static_libs: [
"android.hardware.audio.effect-V1-ndk",
"android.hardware.common-V2-ndk",
"android.hardware.common.fmq-V1-ndk",
"libaudioaidlcommon",
],
header_libs: ["libaudioaidl_headers"],
cflags: [
"-Wall",
"-Wextra",
"-Werror",
"-Wthread-safety",
],
test_suites: [
"general-tests",
"vts",
],
defaults: ["VtsHalAudioTargetTestDefaults"],
srcs: ["VtsHalEqualizerTargetTest.cpp"],
}
cc_test {
name: "VtsHalLoudnessEnhancerTargetTest",
defaults: ["VtsHalAudioTargetTestDefaults"],
srcs: ["VtsHalLoudnessEnhancerTargetTest.cpp"],
}

View file

@ -0,0 +1,145 @@
/*
* 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 <aidl/Vintf.h>
#define LOG_TAG "VtsHalLoudnessEnhancerTest"
#include <Utils.h>
#include "EffectHelper.h"
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;
using aidl::android::hardware::audio::effect::LoudnessEnhancer;
using aidl::android::hardware::audio::effect::LoudnessEnhancerTypeUUID;
using aidl::android::hardware::audio::effect::Parameter;
/**
* Here we focus on specific parameter checking, general IEffect interfaces testing performed in
* VtsAudioEffectTargetTest.
*/
enum ParamName { PARAM_INSTANCE_NAME, PARAM_GAIN_MB };
using LoudnessEnhancerParamTestParam = std::tuple<std::string, int>;
// Every int 32 bit value is a valid gain, so testing the corner cases and one regular value.
// TODO : Update the test values once range/capability is updated by implementation.
const std::vector<int> kGainMbValues = {std::numeric_limits<int>::min(), 100,
std::numeric_limits<int>::max()};
class LoudnessEnhancerParamTest : public ::testing::TestWithParam<LoudnessEnhancerParamTestParam>,
public EffectHelper {
public:
LoudnessEnhancerParamTest()
: EffectHelper(std::get<PARAM_INSTANCE_NAME>(GetParam())),
mParamGainMb(std::get<PARAM_GAIN_MB>(GetParam())) {}
void SetUp() override {
CreateEffectsWithUUID(LoudnessEnhancerTypeUUID);
initParamCommonFormat();
initParamCommon();
initParamSpecific();
OpenEffects(LoudnessEnhancerTypeUUID);
SCOPED_TRACE(testing::Message() << "gainMb: " << mParamGainMb);
}
void TearDown() override {
CloseEffects();
DestroyEffects();
CleanUp();
}
int mParamGainMb = 0;
void SetAndGetLoudnessEnhancerParameters() {
auto functor = [&](const std::shared_ptr<IEffect>& effect) {
for (auto& it : mTags) {
auto& tag = it.first;
auto& le = it.second;
// set parameter
Parameter expectParam;
Parameter::Specific specific;
specific.set<Parameter::Specific::loudnessEnhancer>(le);
expectParam.set<Parameter::specific>(specific);
// All values are valid, set parameter should succeed
EXPECT_STATUS(EX_NONE, effect->setParameter(expectParam)) << expectParam.toString();
// get parameter
Parameter getParam;
Parameter::Id id;
LoudnessEnhancer::Id leId;
leId.set<LoudnessEnhancer::Id::commonTag>(tag);
id.set<Parameter::Id::loudnessEnhancerTag>(leId);
EXPECT_STATUS(EX_NONE, effect->getParameter(id, &getParam));
EXPECT_EQ(expectParam, getParam);
}
};
EXPECT_NO_FATAL_FAILURE(ForEachEffect(functor));
}
void addGainMbParam(int gainMb) {
LoudnessEnhancer le;
le.set<LoudnessEnhancer::gainMb>(gainMb);
mTags.push_back({LoudnessEnhancer::gainMb, le});
}
private:
std::vector<std::pair<LoudnessEnhancer::Tag, LoudnessEnhancer>> mTags;
void initParamSpecific() {
LoudnessEnhancer le;
le.set<LoudnessEnhancer::gainMb>(0);
Parameter::Specific specific;
specific.set<Parameter::Specific::loudnessEnhancer>(le);
setSpecific(specific);
}
void CleanUp() { mTags.clear(); }
};
TEST_P(LoudnessEnhancerParamTest, SetAndGetGainMb) {
EXPECT_NO_FATAL_FAILURE(addGainMbParam(mParamGainMb));
SetAndGetLoudnessEnhancerParameters();
}
INSTANTIATE_TEST_SUITE_P(
LoudnessEnhancerTest, LoudnessEnhancerParamTest,
::testing::Combine(
testing::ValuesIn(android::getAidlHalInstanceNames(IFactory::descriptor)),
testing::ValuesIn(kGainMbValues)),
[](const testing::TestParamInfo<LoudnessEnhancerParamTest::ParamType>& info) {
std::string instance = std::get<PARAM_INSTANCE_NAME>(info.param);
std::string gainMb = std::to_string(std::get<PARAM_GAIN_MB>(info.param));
std::string name = instance + "_gainMb" + gainMb;
std::replace_if(
name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
return name;
});
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(LoudnessEnhancerParamTest);
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
ABinderProcess_setThreadPoolMaxThreadCount(1);
ABinderProcess_startThreadPool();
return RUN_ALL_TESTS();
}