diff --git a/audio/aidl/default/audio_effects_config.xml b/audio/aidl/default/audio_effects_config.xml index c01eb3f828..11683d21ee 100644 --- a/audio/aidl/default/audio_effects_config.xml +++ b/audio/aidl/default/audio_effects_config.xml @@ -88,7 +88,6 @@ - diff --git a/audio/aidl/vts/EffectHelper.h b/audio/aidl/vts/EffectHelper.h index 72a4667b0a..cad1195b32 100644 --- a/audio/aidl/vts/EffectHelper.h +++ b/audio/aidl/vts/EffectHelper.h @@ -92,6 +92,7 @@ class EffectHelper { ASSERT_STATUS(status, factory->createEffect(id.uuid, &effect)); if (status == EX_NONE) { ASSERT_NE(effect, nullptr) << toString(id.uuid); + ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT)); } mIsSpatializer = id.type == getEffectTypeUuidSpatializer(); mDescriptor = desc; @@ -111,11 +112,17 @@ class EffectHelper { ASSERT_STATUS(status, factory->destroyEffect(effect)); } - static void open(std::shared_ptr effect, const Parameter::Common& common, - const std::optional& specific, - IEffect::OpenEffectReturn* ret, binder_status_t status = EX_NONE) { + void open(std::shared_ptr effect, const Parameter::Common& common, + const std::optional& specific, IEffect::OpenEffectReturn* ret, + binder_status_t status = EX_NONE) { ASSERT_NE(effect, nullptr); ASSERT_STATUS(status, effect->open(common, specific, ret)); + if (status != EX_NONE) { + return; + } + + ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE)); + updateFrameSize(common); } void open(std::shared_ptr effect, int session = 0, binder_status_t status = EX_NONE) { @@ -125,21 +132,37 @@ class EffectHelper { ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, status)); } + void reopen(std::shared_ptr effect, const Parameter::Common& common, + IEffect::OpenEffectReturn* ret, binder_status_t status = EX_NONE) { + ASSERT_NE(effect, nullptr); + ASSERT_STATUS(status, effect->reopen(ret)); + if (status != EX_NONE) { + return; + } + updateFrameSize(common); + } + static void closeIgnoreRet(std::shared_ptr effect) { if (effect) { effect->close(); } } + static void close(std::shared_ptr effect, binder_status_t status = EX_NONE) { if (effect) { ASSERT_STATUS(status, effect->close()); + if (status == EX_NONE) { + ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT)); + } } } + static void getDescriptor(std::shared_ptr effect, Descriptor& desc, binder_status_t status = EX_NONE) { ASSERT_NE(effect, nullptr); ASSERT_STATUS(status, effect->getDescriptor(&desc)); } + static void expectState(std::shared_ptr effect, State expectState, binder_status_t status = EX_NONE) { ASSERT_NE(effect, nullptr); @@ -147,27 +170,35 @@ class EffectHelper { ASSERT_STATUS(status, effect->getState(&state)); ASSERT_EQ(expectState, state); } + static void commandIgnoreRet(std::shared_ptr effect, CommandId command) { if (effect) { effect->command(command); } } + static void command(std::shared_ptr effect, CommandId command, binder_status_t status = EX_NONE) { ASSERT_NE(effect, nullptr); ASSERT_STATUS(status, effect->command(command)); + if (status != EX_NONE) { + return; + } + + switch (command) { + case CommandId::START: + ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING)); + break; + case CommandId::STOP: + FALLTHROUGH_INTENDED; + case CommandId::RESET: + ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE)); + break; + default: + return; + } } - static void allocateInputData(const Parameter::Common common, std::unique_ptr& mq, - std::vector& buffer) { - ASSERT_NE(mq, nullptr); - auto frameSize = ::aidl::android::hardware::audio::common::getFrameSizeInBytes( - common.input.base.format, common.input.base.channelMask); - const size_t floatsToWrite = mq->availableToWrite(); - ASSERT_NE(0UL, floatsToWrite); - ASSERT_EQ(frameSize * common.input.frameCount, floatsToWrite * sizeof(float)); - buffer.resize(floatsToWrite); - std::fill(buffer.begin(), buffer.end(), 0x5a); - } + static void writeToFmq(std::unique_ptr& statusMq, std::unique_ptr& dataMq, const std::vector& buffer, int version) { const size_t available = dataMq->availableToWrite(); @@ -184,6 +215,7 @@ class EffectHelper { : kEventFlagNotEmpty); ASSERT_EQ(::android::OK, EventFlag::deleteEventFlag(&efGroup)); } + static void readFromFmq(std::unique_ptr& statusMq, size_t statusNum, std::unique_ptr& dataMq, size_t expectFloats, std::vector& buffer, @@ -204,6 +236,7 @@ class EffectHelper { ASSERT_TRUE(dataMq->read(buffer.data(), expectFloats)); } } + static void expectDataMqUpdateEventFlag(std::unique_ptr& statusMq) { EventFlag* efGroup; ASSERT_EQ(::android::OK, @@ -218,8 +251,10 @@ class EffectHelper { Parameter::Common createParamCommon(int session = 0, int ioHandle = -1, int iSampleRate = 48000, int oSampleRate = 48000, long iFrameCount = 0x100, long oFrameCount = 0x100) { - AudioChannelLayout defaultLayout = AudioChannelLayout::make( + AudioChannelLayout inputLayout = AudioChannelLayout::make( AudioChannelLayout::LAYOUT_STEREO); + AudioChannelLayout outputLayout = inputLayout; + // query supported input layout and use it as the default parameter in common if (mIsSpatializer && isRangeValid(Spatializer::supportedChannelLayout, mDescriptor.capability)) { @@ -229,12 +264,14 @@ class EffectHelper { layoutRange && 0 != (layouts = layoutRange->min.get()) .size()) { - defaultLayout = layouts[0]; + inputLayout = layouts[0]; } } + return createParamCommon(session, ioHandle, iSampleRate, oSampleRate, iFrameCount, - oFrameCount, defaultLayout, defaultLayout); + oFrameCount, inputLayout, outputLayout); } + static Parameter::Common createParamCommon(int session, int ioHandle, int iSampleRate, int oSampleRate, long iFrameCount, long oFrameCount, AudioChannelLayout inputChannelLayout, @@ -333,33 +370,38 @@ class EffectHelper { static void processAndWriteToOutput(std::vector& inputBuffer, std::vector& outputBuffer, - const std::shared_ptr& mEffect, - IEffect::OpenEffectReturn* mOpenEffectReturn) { + const std::shared_ptr& effect, + IEffect::OpenEffectReturn* openEffectReturn, + int version = -1, int times = 1) { // Initialize AidlMessagequeues - auto statusMQ = std::make_unique(mOpenEffectReturn->statusMQ); + auto statusMQ = std::make_unique(openEffectReturn->statusMQ); ASSERT_TRUE(statusMQ->isValid()); - auto inputMQ = std::make_unique(mOpenEffectReturn->inputDataMQ); + auto inputMQ = std::make_unique(openEffectReturn->inputDataMQ); ASSERT_TRUE(inputMQ->isValid()); - auto outputMQ = std::make_unique(mOpenEffectReturn->outputDataMQ); + auto outputMQ = std::make_unique(openEffectReturn->outputDataMQ); ASSERT_TRUE(outputMQ->isValid()); // Enabling the process - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); + ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START)); // Write from buffer to message queues and calling process - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, [&]() { - int version = 0; - return (mEffect && mEffect->getInterfaceVersion(&version).isOk()) ? version : 0; - }())); + if (version == -1) { + ASSERT_IS_OK(effect->getInterfaceVersion(&version)); + } - // Read the updated message queues into buffer - EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 1, outputMQ, - outputBuffer.size(), outputBuffer)); + for (int i = 0; i < times; i++) { + EXPECT_NO_FATAL_FAILURE( + EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, version)); + // Read the updated message queues into buffer + EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 1, outputMQ, + outputBuffer.size(), outputBuffer)); + } + + ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP)); + EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, outputBuffer)); // Disable the process - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); + ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET)); } // Find FFT bin indices for testFrequencies and get bin center frequencies @@ -403,6 +445,17 @@ class EffectHelper { return bufferMag; } + void updateFrameSize(const Parameter::Common& common) { + mInputFrameSize = ::aidl::android::hardware::audio::common::getFrameSizeInBytes( + common.input.base.format, common.input.base.channelMask); + mInputSamples = common.input.frameCount * mInputFrameSize / sizeof(float); + mOutputFrameSize = ::aidl::android::hardware::audio::common::getFrameSizeInBytes( + common.output.base.format, common.output.base.channelMask); + mOutputSamples = common.output.frameCount * mOutputFrameSize / sizeof(float); + } + bool mIsSpatializer; Descriptor mDescriptor; + size_t mInputFrameSize, mOutputFrameSize; + size_t mInputSamples, mOutputSamples; }; diff --git a/audio/aidl/vts/VtsHalAudioEffectTargetTest.cpp b/audio/aidl/vts/VtsHalAudioEffectTargetTest.cpp index 2f47d07702..d23bdc99e3 100644 --- a/audio/aidl/vts/VtsHalAudioEffectTargetTest.cpp +++ b/audio/aidl/vts/VtsHalAudioEffectTargetTest.cpp @@ -200,7 +200,6 @@ TEST_P(AudioEffectTest, DescriptorExistAndUnique) { // An effect instance is in INIT state by default after it was created. TEST_P(AudioEffectTest, InitStateAfterCreation) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); } @@ -208,7 +207,6 @@ TEST_P(AudioEffectTest, InitStateAfterCreation) { TEST_P(AudioEffectTest, IdleStateAfterOpen) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); } @@ -216,11 +214,8 @@ TEST_P(AudioEffectTest, IdleStateAfterOpen) { // An effect instance is in PROCESSING state after it receive an START command. TEST_P(AudioEffectTest, ProcessingStateAfterStart) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); @@ -231,9 +226,7 @@ TEST_P(AudioEffectTest, IdleStateAfterStop) { 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)); 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)); } @@ -243,9 +236,7 @@ TEST_P(AudioEffectTest, IdleStateAfterReset) { 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)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); } @@ -257,7 +248,6 @@ TEST_P(AudioEffectTest, InitStateAfterClose) { ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); } @@ -274,9 +264,7 @@ TEST_P(AudioEffectTest, NoCommandAcceptedBeforeOpen) { TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); 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)); } @@ -285,9 +273,7 @@ TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) { TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); } @@ -296,16 +282,11 @@ TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) { TEST_P(AudioEffectTest, RepeatStartAndStop) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); 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)); } @@ -314,16 +295,10 @@ TEST_P(AudioEffectTest, RepeatStartAndStop) { TEST_P(AudioEffectTest, RepeatStartAndReset) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); } @@ -332,14 +307,11 @@ TEST_P(AudioEffectTest, RepeatStartAndReset) { TEST_P(AudioEffectTest, CloseProcessingStateEffects) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); ASSERT_NO_FATAL_FAILURE(close(mEffect, EX_ILLEGAL_STATE)); 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)); } @@ -348,8 +320,6 @@ TEST_P(AudioEffectTest, CloseProcessingStateEffects) { TEST_P(AudioEffectTest, DestroyOpenEffects) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); - ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE)); // cleanup @@ -361,32 +331,22 @@ TEST_P(AudioEffectTest, DestroyOpenEffects) { TEST_P(AudioEffectTest, DestroyProcessingEffects) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); - ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE)); // cleanup 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)); } TEST_P(AudioEffectTest, NormalSequenceStates) { ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT)); ASSERT_NO_FATAL_FAILURE(open(mEffect)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); } @@ -430,7 +390,6 @@ TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) { 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::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */); @@ -447,9 +406,7 @@ TEST_P(AudioEffectTest, SetAndGetParameterInIdle) { 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)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */); @@ -465,7 +422,6 @@ TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) { 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::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */); @@ -473,7 +429,6 @@ TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) { ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make(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)); } @@ -484,7 +439,6 @@ TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) { ASSERT_NO_FATAL_FAILURE(open(mEffect)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */); @@ -492,12 +446,10 @@ TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) { ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make(common))); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make(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)); } @@ -511,9 +463,7 @@ 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 deviceDescs = { {.type = AudioDeviceType::IN_DEFAULT, @@ -525,7 +475,6 @@ TEST_P(AudioEffectTest, SetAndGetParameterDeviceDescription) { setAndGetParameter(id, Parameter::make(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)); } @@ -541,7 +490,6 @@ TEST_P(AudioEffectTest, SetAndGetParameterAudioMode) { 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::mode); ASSERT_NO_FATAL_FAILURE( @@ -550,7 +498,6 @@ TEST_P(AudioEffectTest, SetAndGetParameterAudioMode) { setAndGetParameter(id, Parameter::make(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)); } @@ -564,9 +511,7 @@ 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::source); ASSERT_NO_FATAL_FAILURE( @@ -575,7 +520,6 @@ TEST_P(AudioEffectTest, SetAndGetParameterAudioSource) { id, Parameter::make(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)); } @@ -589,9 +533,7 @@ 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::volumeStereo); Parameter::VolumeStereo volume = {.left = 10.0, .right = 10.0}; @@ -605,7 +547,6 @@ TEST_P(AudioEffectTest, SetAndGetParameterVolume) { } 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)); } @@ -638,7 +579,7 @@ TEST_P(AudioEffectDataPathTest, SetCommonParameterAndReopen) { ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make(common))); ASSERT_TRUE(statusMQ->isValid()); expectDataMqUpdateEventFlag(statusMQ); - EXPECT_IS_OK(mEffect->reopen(&ret)); + ASSERT_NO_FATAL_FAILURE(reopen(mEffect, common, &ret)); inputMQ = std::make_unique(ret.inputDataMQ); outputMQ = std::make_unique(ret.outputDataMQ); ASSERT_TRUE(statusMQ->isValid()); @@ -649,7 +590,7 @@ TEST_P(AudioEffectDataPathTest, SetCommonParameterAndReopen) { ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make(common))); ASSERT_TRUE(statusMQ->isValid()); expectDataMqUpdateEventFlag(statusMQ); - EXPECT_IS_OK(mEffect->reopen(&ret)); + ASSERT_NO_FATAL_FAILURE(reopen(mEffect, common, &ret)); inputMQ = std::make_unique(ret.inputDataMQ); outputMQ = std::make_unique(ret.outputDataMQ); ASSERT_TRUE(statusMQ->isValid()); @@ -671,26 +612,9 @@ TEST_P(AudioEffectDataPathTest, ConsumeDataInProcessingState) { kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */); IEffect::OpenEffectReturn ret; ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE)); - auto statusMQ = std::make_unique(ret.statusMQ); - ASSERT_TRUE(statusMQ->isValid()); - auto inputMQ = std::make_unique(ret.inputDataMQ); - ASSERT_TRUE(inputMQ->isValid()); - auto outputMQ = std::make_unique(ret.outputDataMQ); - ASSERT_TRUE(outputMQ->isValid()); - - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); - - std::vector buffer; - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer)); - - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer)); - + std::vector inputBuffer(mInputSamples), outputBuffer(mOutputSamples); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); } @@ -705,31 +629,12 @@ TEST_P(AudioEffectDataPathTest, ConsumeDataAfterRestart) { kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */); IEffect::OpenEffectReturn ret; ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE)); - auto statusMQ = std::make_unique(ret.statusMQ); - ASSERT_TRUE(statusMQ->isValid()); - auto inputMQ = std::make_unique(ret.inputDataMQ); - ASSERT_TRUE(inputMQ->isValid()); - auto outputMQ = std::make_unique(ret.outputDataMQ); - ASSERT_TRUE(outputMQ->isValid()); - std::vector buffer; - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 0, outputMQ, buffer.size(), buffer)); - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); - - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer)); - - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer)); + std::vector inputBuffer(mInputSamples), outputBuffer(mOutputSamples); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion)); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); @@ -751,18 +656,10 @@ TEST_P(AudioEffectDataPathTest, ConsumeDataAfterReopen) { ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE)); auto statusMQ = std::make_unique(ret.statusMQ); ASSERT_TRUE(statusMQ->isValid()); - auto inputMQ = std::make_unique(ret.inputDataMQ); - ASSERT_TRUE(inputMQ->isValid()); - auto outputMQ = std::make_unique(ret.outputDataMQ); - ASSERT_TRUE(outputMQ->isValid()); - std::vector buffer; - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer)); + std::vector inputBuffer(mInputSamples), outputBuffer(mOutputSamples); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion)); // set a new common parameter with different IO frameCount, reopen Parameter::Id id = Parameter::Id::make(Parameter::common); @@ -771,22 +668,12 @@ TEST_P(AudioEffectDataPathTest, ConsumeDataAfterReopen) { ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make(common))); ASSERT_TRUE(statusMQ->isValid()); expectDataMqUpdateEventFlag(statusMQ); - EXPECT_IS_OK(mEffect->reopen(&ret)); - inputMQ = std::make_unique(ret.inputDataMQ); - outputMQ = std::make_unique(ret.outputDataMQ); - ASSERT_TRUE(statusMQ->isValid()); - ASSERT_TRUE(inputMQ->isValid()); - ASSERT_TRUE(outputMQ->isValid()); + ASSERT_NO_FATAL_FAILURE(reopen(mEffect, common, &ret)); - // verify data consume again - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer)); - - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer)); + inputBuffer.resize(mInputSamples); + outputBuffer.resize(mOutputSamples); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); @@ -809,19 +696,15 @@ TEST_P(AudioEffectDataPathTest, SendDataAtIdleAndConsumeDataInProcessing) { auto outputMQ = std::make_unique(ret.outputDataMQ); ASSERT_TRUE(outputMQ->isValid()); - std::vector buffer; - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); + std::vector inputBuffer(mInputSamples), outputBuffer(mOutputSamples); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion)); + EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, mVersion)); ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer)); - + EffectHelper::readFromFmq(statusMQ, 1, outputMQ, outputBuffer.size(), outputBuffer)); 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)); } @@ -836,31 +719,10 @@ TEST_P(AudioEffectDataPathTest, ProcessDataMultipleTimes) { kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */); IEffect::OpenEffectReturn ret; ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE)); - auto statusMQ = std::make_unique(ret.statusMQ); - ASSERT_TRUE(statusMQ->isValid()); - auto inputMQ = std::make_unique(ret.inputDataMQ); - ASSERT_TRUE(inputMQ->isValid()); - auto outputMQ = std::make_unique(ret.outputDataMQ); - ASSERT_TRUE(outputMQ->isValid()); + std::vector inputBuffer(mInputSamples), outputBuffer(mOutputSamples); - std::vector buffer; - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer)); - - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); - - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer)); - - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer)); - - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer)); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion, 2)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); @@ -876,33 +738,12 @@ TEST_P(AudioEffectDataPathTest, ConsumeDataAndRestart) { kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */); IEffect::OpenEffectReturn ret; ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE)); - auto statusMQ = std::make_unique(ret.statusMQ); - ASSERT_TRUE(statusMQ->isValid()); - auto inputMQ = std::make_unique(ret.inputDataMQ); - ASSERT_TRUE(inputMQ->isValid()); - auto outputMQ = std::make_unique(ret.outputDataMQ); - ASSERT_TRUE(outputMQ->isValid()); + std::vector inputBuffer(mInputSamples), outputBuffer(mOutputSamples); - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); - std::vector buffer; - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer)); - - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer)); - - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer)); - - ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE)); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion, 2)); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion, 2)); ASSERT_NO_FATAL_FAILURE(close(mEffect)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); @@ -918,6 +759,7 @@ TEST_P(AudioEffectDataPathTest, NotConsumeDataByClosedEffect) { kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */); IEffect::OpenEffectReturn ret; ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE)); + std::vector inputBuffer(mInputSamples), outputBuffer(mOutputSamples); ASSERT_NO_FATAL_FAILURE(close(mEffect)); auto statusMQ = std::make_unique(ret.statusMQ); @@ -927,10 +769,8 @@ TEST_P(AudioEffectDataPathTest, NotConsumeDataByClosedEffect) { auto outputMQ = std::make_unique(ret.outputDataMQ); ASSERT_TRUE(outputMQ->isValid()); - std::vector buffer; - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer)); + EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, mVersion)); + EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, outputBuffer)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); } @@ -951,42 +791,19 @@ TEST_P(AudioEffectDataPathTest, ConsumeDataMultipleEffects) { IEffect::OpenEffectReturn ret1, ret2; ASSERT_NO_FATAL_FAILURE(open(effect1, common1, std::nullopt /* specific */, &ret1, EX_NONE)); ASSERT_NO_FATAL_FAILURE(open(effect2, common2, std::nullopt /* specific */, &ret2, EX_NONE)); - ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::PROCESSING)); - ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::START)); - ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::PROCESSING)); + std::vector inputBuffer1(kInputFrameCount * mInputFrameSize / sizeof(float)), + outputBuffer1(kOutputFrameCount * mOutputFrameSize / sizeof(float)); + std::vector inputBuffer2(2 * kInputFrameCount * mInputFrameSize / sizeof(float)), + outputBuffer2(2 * kOutputFrameCount * mOutputFrameSize / sizeof(float)); - auto statusMQ1 = std::make_unique(ret1.statusMQ); - ASSERT_TRUE(statusMQ1->isValid()); - auto inputMQ1 = std::make_unique(ret1.inputDataMQ); - ASSERT_TRUE(inputMQ1->isValid()); - auto outputMQ1 = std::make_unique(ret1.outputDataMQ); - ASSERT_TRUE(outputMQ1->isValid()); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer1, outputBuffer1, effect1, &ret1, mVersion, 2)); + ASSERT_NO_FATAL_FAILURE( + processAndWriteToOutput(inputBuffer2, outputBuffer2, effect2, &ret2, mVersion, 2)); - std::vector buffer1, buffer2; - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common1, inputMQ1, buffer1)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ1, inputMQ1, buffer1, mVersion)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ1, 1, outputMQ1, buffer1.size(), buffer1)); - - auto statusMQ2 = std::make_unique(ret2.statusMQ); - ASSERT_TRUE(statusMQ2->isValid()); - auto inputMQ2 = std::make_unique(ret2.inputDataMQ); - ASSERT_TRUE(inputMQ2->isValid()); - auto outputMQ2 = std::make_unique(ret2.outputDataMQ); - ASSERT_TRUE(outputMQ2->isValid()); - EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common2, inputMQ2, buffer2)); - EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ2, inputMQ2, buffer2, mVersion)); - EXPECT_NO_FATAL_FAILURE( - EffectHelper::readFromFmq(statusMQ2, 1, outputMQ2, buffer2.size(), buffer2)); - - ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::IDLE)); ASSERT_NO_FATAL_FAILURE(close(effect1)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1)); - ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::STOP)); - ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::IDLE)); ASSERT_NO_FATAL_FAILURE(close(effect2)); ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2)); }