AIDL effect: update AudioDeviceDescription to list

Bug: 261129656
Test: atest VtsHalAudioEffectTargetTest
Change-Id: I424afb287fa97a6bf39221ba64d6af50c1d697eb
This commit is contained in:
Shunkai Yao 2023-01-10 03:20:00 +00:00
parent 0edf57e04b
commit 5df4e6c4b0
4 changed files with 117 additions and 47 deletions

View file

@ -35,7 +35,7 @@ package android.hardware.audio.effect;
@VintfStability
union Parameter {
android.hardware.audio.effect.Parameter.Common common;
android.media.audio.common.AudioDeviceDescription deviceDescription;
android.media.audio.common.AudioDeviceDescription[] deviceDescription;
android.media.audio.common.AudioMode mode;
android.media.audio.common.AudioSource source;
android.hardware.audio.effect.Parameter.VolumeStereo volumeStereo;

View file

@ -120,10 +120,11 @@ union Parameter {
Common common;
/**
* Used by audio framework to set the device type to effect engine.
* Effect must implement setParameter(device) if Flags.deviceIndication set to true.
* Used by audio framework to set the device type(s) to effect engine.
* Effect engine must apply all AudioDeviceDescription in the list.
* Effect must implement setParameter(deviceDescription) if Flags.deviceIndication set to true.
*/
AudioDeviceDescription deviceDescription;
AudioDeviceDescription[] deviceDescription;
/**
* Used by audio framework to set the audio mode to effect engine.
* Effect must implement setParameter(mode) if Flags.audioModeIndication set to true.

View file

@ -91,11 +91,13 @@ class EffectContext {
int getSessionId() { return mSessionId; }
virtual RetCode setOutputDevice(
const aidl::android::media::audio::common::AudioDeviceDescription& device) {
const std::vector<aidl::android::media::audio::common::AudioDeviceDescription>&
device) {
mOutputDevice = device;
return RetCode::SUCCESS;
}
virtual aidl::android::media::audio::common::AudioDeviceDescription getOutputDevice() {
virtual std::vector<aidl::android::media::audio::common::AudioDeviceDescription>
getOutputDevice() {
return mOutputDevice;
}
@ -133,7 +135,7 @@ class EffectContext {
size_t mInputFrameSize;
size_t mOutputFrameSize;
Parameter::Common mCommon;
aidl::android::media::audio::common::AudioDeviceDescription mOutputDevice;
std::vector<aidl::android::media::audio::common::AudioDeviceDescription> mOutputDevice;
aidl::android::media::audio::common::AudioMode mMode;
aidl::android::media::audio::common::AudioSource mSource;
Parameter::VolumeStereo mVolumeStereo;

View file

@ -47,6 +47,10 @@ using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;
using aidl::android::hardware::audio::effect::Parameter;
using aidl::android::hardware::audio::effect::State;
using aidl::android::media::audio::common::AudioDeviceDescription;
using aidl::android::media::audio::common::AudioDeviceType;
using aidl::android::media::audio::common::AudioMode;
using aidl::android::media::audio::common::AudioSource;
enum ParamName { PARAM_INSTANCE_NAME };
using EffectTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>>;
@ -73,6 +77,13 @@ class AudioEffectTest : public testing::TestWithParam<EffectTestParam>, public E
std::shared_ptr<IFactory> mFactory;
std::shared_ptr<IEffect> mEffect;
Descriptor mDescriptor;
void setAndGetParameter(Parameter::Id id, const Parameter& set) {
Parameter get;
EXPECT_IS_OK(mEffect->setParameter(set));
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
}
};
TEST_P(AudioEffectTest, SetupAndTearDown) {
@ -392,14 +403,8 @@ TEST_P(AudioEffectTest, SetAndGetCommonParameter) {
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(mEffect->setParameter(set));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
@ -414,14 +419,8 @@ TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) {
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(mEffect->setParameter(set));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
@ -439,14 +438,8 @@ TEST_P(AudioEffectTest, SetAndGetParameterInIdle) {
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(mEffect->setParameter(set));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
@ -461,18 +454,11 @@ TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) {
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(mEffect->setParameter(set));
Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
@ -487,21 +473,102 @@ TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) {
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(mEffect->setParameter(set));
Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Set and get AudioDeviceDescription in Parameter
TEST_P(AudioEffectTest, SetAndGetParameterDeviceDescription) {
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
std::vector<AudioDeviceDescription> deviceDescs = {
{.type = AudioDeviceType::IN_DEFAULT,
.connection = AudioDeviceDescription::CONNECTION_ANALOG},
{.type = AudioDeviceType::IN_DEVICE,
.connection = AudioDeviceDescription::CONNECTION_BT_A2DP}};
Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::deviceDescription);
ASSERT_NO_FATAL_FAILURE(
setAndGetParameter(id, Parameter::make<Parameter::deviceDescription>(deviceDescs)));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Set and get AudioMode in Parameter
TEST_P(AudioEffectTest, SetAndGetParameterAudioMode) {
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::mode);
ASSERT_NO_FATAL_FAILURE(
setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::NORMAL)));
ASSERT_NO_FATAL_FAILURE(
setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::IN_COMMUNICATION)));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Set and get AudioSource in Parameter
TEST_P(AudioEffectTest, SetAndGetParameterAudioSource) {
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::source);
ASSERT_NO_FATAL_FAILURE(
setAndGetParameter(id, Parameter::make<Parameter::source>(AudioSource::DEFAULT)));
ASSERT_NO_FATAL_FAILURE(setAndGetParameter(
id, Parameter::make<Parameter::source>(AudioSource::VOICE_RECOGNITION)));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Set and get VolumeStereo in Parameter
TEST_P(AudioEffectTest, SetAndGetParameterVolume) {
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::volumeStereo);
Parameter::VolumeStereo volume = {.left = 10.0, .right = 10.0};
ASSERT_NO_FATAL_FAILURE(
setAndGetParameter(id, Parameter::make<Parameter::volumeStereo>(volume)));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
/// Data processing test
// Send data to effects and expect it to be consumed by checking statusMQ.
TEST_P(AudioEffectTest, ConsumeDataInProcessingState) {