Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17f40c81 authored by Shunkai Yao's avatar Shunkai Yao Committed by Automerger Merge Worker
Browse files

Merge "Update VTSHalAudioEffectTargetTest with frameSize" into main am: d0dc9486 am: 470826b2

parents a940d2af 470826b2
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -88,7 +88,6 @@
        <effect name="extension_effect" library="extensioneffect" uuid="fa81dd00-588b-11ed-9b6a-0242ac120002" type="fa81de0e-588b-11ed-9b6a-0242ac120002"/>
        <effect name="extension_effect" library="extensioneffect" uuid="fa81dd00-588b-11ed-9b6a-0242ac120002" type="fa81de0e-588b-11ed-9b6a-0242ac120002"/>
        <effect name="acoustic_echo_canceler" library="pre_processing" uuid="bb392ec0-8d4d-11e0-a896-0002a5d5c51b"/>
        <effect name="acoustic_echo_canceler" library="pre_processing" uuid="bb392ec0-8d4d-11e0-a896-0002a5d5c51b"/>
        <effect name="noise_suppression" library="pre_processing" uuid="c06c8400-8e06-11e0-9cb6-0002a5d5c51b"/>
        <effect name="noise_suppression" library="pre_processing" uuid="c06c8400-8e06-11e0-9cb6-0002a5d5c51b"/>
        <effect name="spatializer" library="spatializersw" uuid="fa81a880-588b-11ed-9b6a-0242ac120002"/>
    </effects>
    </effects>


    <preprocess>
    <preprocess>
+86 −33
Original line number Original line Diff line number Diff line
@@ -92,6 +92,7 @@ class EffectHelper {
        ASSERT_STATUS(status, factory->createEffect(id.uuid, &effect));
        ASSERT_STATUS(status, factory->createEffect(id.uuid, &effect));
        if (status == EX_NONE) {
        if (status == EX_NONE) {
            ASSERT_NE(effect, nullptr) << toString(id.uuid);
            ASSERT_NE(effect, nullptr) << toString(id.uuid);
            ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
        }
        }
        mIsSpatializer = id.type == getEffectTypeUuidSpatializer();
        mIsSpatializer = id.type == getEffectTypeUuidSpatializer();
        mDescriptor = desc;
        mDescriptor = desc;
@@ -111,11 +112,17 @@ class EffectHelper {
        ASSERT_STATUS(status, factory->destroyEffect(effect));
        ASSERT_STATUS(status, factory->destroyEffect(effect));
    }
    }


    static void open(std::shared_ptr<IEffect> effect, const Parameter::Common& common,
    void open(std::shared_ptr<IEffect> effect, const Parameter::Common& common,
                     const std::optional<Parameter::Specific>& specific,
              const std::optional<Parameter::Specific>& specific, IEffect::OpenEffectReturn* ret,
                     IEffect::OpenEffectReturn* ret, binder_status_t status = EX_NONE) {
              binder_status_t status = EX_NONE) {
        ASSERT_NE(effect, nullptr);
        ASSERT_NE(effect, nullptr);
        ASSERT_STATUS(status, effect->open(common, specific, ret));
        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<IEffect> effect, int session = 0, binder_status_t status = EX_NONE) {
    void open(std::shared_ptr<IEffect> 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));
        ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, status));
    }
    }


    void reopen(std::shared_ptr<IEffect> 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<IEffect> effect) {
    static void closeIgnoreRet(std::shared_ptr<IEffect> effect) {
        if (effect) {
        if (effect) {
            effect->close();
            effect->close();
        }
        }
    }
    }

    static void close(std::shared_ptr<IEffect> effect, binder_status_t status = EX_NONE) {
    static void close(std::shared_ptr<IEffect> effect, binder_status_t status = EX_NONE) {
        if (effect) {
        if (effect) {
            ASSERT_STATUS(status, effect->close());
            ASSERT_STATUS(status, effect->close());
            if (status == EX_NONE) {
                ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
            }
        }
        }
    }
    }

    static void getDescriptor(std::shared_ptr<IEffect> effect, Descriptor& desc,
    static void getDescriptor(std::shared_ptr<IEffect> effect, Descriptor& desc,
                              binder_status_t status = EX_NONE) {
                              binder_status_t status = EX_NONE) {
        ASSERT_NE(effect, nullptr);
        ASSERT_NE(effect, nullptr);
        ASSERT_STATUS(status, effect->getDescriptor(&desc));
        ASSERT_STATUS(status, effect->getDescriptor(&desc));
    }
    }

    static void expectState(std::shared_ptr<IEffect> effect, State expectState,
    static void expectState(std::shared_ptr<IEffect> effect, State expectState,
                            binder_status_t status = EX_NONE) {
                            binder_status_t status = EX_NONE) {
        ASSERT_NE(effect, nullptr);
        ASSERT_NE(effect, nullptr);
@@ -147,27 +170,35 @@ class EffectHelper {
        ASSERT_STATUS(status, effect->getState(&state));
        ASSERT_STATUS(status, effect->getState(&state));
        ASSERT_EQ(expectState, state);
        ASSERT_EQ(expectState, state);
    }
    }

    static void commandIgnoreRet(std::shared_ptr<IEffect> effect, CommandId command) {
    static void commandIgnoreRet(std::shared_ptr<IEffect> effect, CommandId command) {
        if (effect) {
        if (effect) {
            effect->command(command);
            effect->command(command);
        }
        }
    }
    }

    static void command(std::shared_ptr<IEffect> effect, CommandId command,
    static void command(std::shared_ptr<IEffect> effect, CommandId command,
                        binder_status_t status = EX_NONE) {
                        binder_status_t status = EX_NONE) {
        ASSERT_NE(effect, nullptr);
        ASSERT_NE(effect, nullptr);
        ASSERT_STATUS(status, effect->command(command));
        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<DataMQ>& mq,
                                  std::vector<float>& 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>& statusMq, std::unique_ptr<DataMQ>& dataMq,
    static void writeToFmq(std::unique_ptr<StatusMQ>& statusMq, std::unique_ptr<DataMQ>& dataMq,
                           const std::vector<float>& buffer, int version) {
                           const std::vector<float>& buffer, int version) {
        const size_t available = dataMq->availableToWrite();
        const size_t available = dataMq->availableToWrite();
@@ -184,6 +215,7 @@ class EffectHelper {
                                                         : kEventFlagNotEmpty);
                                                         : kEventFlagNotEmpty);
        ASSERT_EQ(::android::OK, EventFlag::deleteEventFlag(&efGroup));
        ASSERT_EQ(::android::OK, EventFlag::deleteEventFlag(&efGroup));
    }
    }

    static void readFromFmq(std::unique_ptr<StatusMQ>& statusMq, size_t statusNum,
    static void readFromFmq(std::unique_ptr<StatusMQ>& statusMq, size_t statusNum,
                            std::unique_ptr<DataMQ>& dataMq, size_t expectFloats,
                            std::unique_ptr<DataMQ>& dataMq, size_t expectFloats,
                            std::vector<float>& buffer,
                            std::vector<float>& buffer,
@@ -204,6 +236,7 @@ class EffectHelper {
            ASSERT_TRUE(dataMq->read(buffer.data(), expectFloats));
            ASSERT_TRUE(dataMq->read(buffer.data(), expectFloats));
        }
        }
    }
    }

    static void expectDataMqUpdateEventFlag(std::unique_ptr<StatusMQ>& statusMq) {
    static void expectDataMqUpdateEventFlag(std::unique_ptr<StatusMQ>& statusMq) {
        EventFlag* efGroup;
        EventFlag* efGroup;
        ASSERT_EQ(::android::OK,
        ASSERT_EQ(::android::OK,
@@ -218,8 +251,10 @@ class EffectHelper {
    Parameter::Common createParamCommon(int session = 0, int ioHandle = -1, int iSampleRate = 48000,
    Parameter::Common createParamCommon(int session = 0, int ioHandle = -1, int iSampleRate = 48000,
                                        int oSampleRate = 48000, long iFrameCount = 0x100,
                                        int oSampleRate = 48000, long iFrameCount = 0x100,
                                        long oFrameCount = 0x100) {
                                        long oFrameCount = 0x100) {
        AudioChannelLayout defaultLayout = AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
        AudioChannelLayout inputLayout = AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
                AudioChannelLayout::LAYOUT_STEREO);
                AudioChannelLayout::LAYOUT_STEREO);
        AudioChannelLayout outputLayout = inputLayout;

        // query supported input layout and use it as the default parameter in common
        // query supported input layout and use it as the default parameter in common
        if (mIsSpatializer && isRangeValid<Range::spatializer>(Spatializer::supportedChannelLayout,
        if (mIsSpatializer && isRangeValid<Range::spatializer>(Spatializer::supportedChannelLayout,
                                                               mDescriptor.capability)) {
                                                               mDescriptor.capability)) {
@@ -229,12 +264,14 @@ class EffectHelper {
                layoutRange &&
                layoutRange &&
                0 != (layouts = layoutRange->min.get<Spatializer::supportedChannelLayout>())
                0 != (layouts = layoutRange->min.get<Spatializer::supportedChannelLayout>())
                                .size()) {
                                .size()) {
                defaultLayout = layouts[0];
                inputLayout = layouts[0];
            }
            }
        }
        }

        return createParamCommon(session, ioHandle, iSampleRate, oSampleRate, iFrameCount,
        return createParamCommon(session, ioHandle, iSampleRate, oSampleRate, iFrameCount,
                                 oFrameCount, defaultLayout, defaultLayout);
                                 oFrameCount, inputLayout, outputLayout);
    }
    }

    static Parameter::Common createParamCommon(int session, int ioHandle, int iSampleRate,
    static Parameter::Common createParamCommon(int session, int ioHandle, int iSampleRate,
                                               int oSampleRate, long iFrameCount, long oFrameCount,
                                               int oSampleRate, long iFrameCount, long oFrameCount,
                                               AudioChannelLayout inputChannelLayout,
                                               AudioChannelLayout inputChannelLayout,
@@ -333,33 +370,38 @@ class EffectHelper {


    static void processAndWriteToOutput(std::vector<float>& inputBuffer,
    static void processAndWriteToOutput(std::vector<float>& inputBuffer,
                                        std::vector<float>& outputBuffer,
                                        std::vector<float>& outputBuffer,
                                        const std::shared_ptr<IEffect>& mEffect,
                                        const std::shared_ptr<IEffect>& effect,
                                        IEffect::OpenEffectReturn* mOpenEffectReturn) {
                                        IEffect::OpenEffectReturn* openEffectReturn,
                                        int version = -1, int times = 1) {
        // Initialize AidlMessagequeues
        // Initialize AidlMessagequeues
        auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(mOpenEffectReturn->statusMQ);
        auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(openEffectReturn->statusMQ);
        ASSERT_TRUE(statusMQ->isValid());
        ASSERT_TRUE(statusMQ->isValid());
        auto inputMQ = std::make_unique<EffectHelper::DataMQ>(mOpenEffectReturn->inputDataMQ);
        auto inputMQ = std::make_unique<EffectHelper::DataMQ>(openEffectReturn->inputDataMQ);
        ASSERT_TRUE(inputMQ->isValid());
        ASSERT_TRUE(inputMQ->isValid());
        auto outputMQ = std::make_unique<EffectHelper::DataMQ>(mOpenEffectReturn->outputDataMQ);
        auto outputMQ = std::make_unique<EffectHelper::DataMQ>(openEffectReturn->outputDataMQ);
        ASSERT_TRUE(outputMQ->isValid());
        ASSERT_TRUE(outputMQ->isValid());


        // Enabling the process
        // Enabling the process
        ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
        ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
        ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));


        // Write from buffer to message queues and calling process
        // Write from buffer to message queues and calling process
        EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, [&]() {
        if (version == -1) {
            int version = 0;
            ASSERT_IS_OK(effect->getInterfaceVersion(&version));
            return (mEffect && mEffect->getInterfaceVersion(&version).isOk()) ? version : 0;
        }
        }()));


        for (int i = 0; i < times; i++) {
            EXPECT_NO_FATAL_FAILURE(
                    EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, version));
            // Read the updated message queues into buffer
            // Read the updated message queues into buffer
            EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 1, outputMQ,
            EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 1, outputMQ,
                                                              outputBuffer.size(), outputBuffer));
                                                              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
        // Disable the process
        ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
        ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
        ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
    }
    }


    // Find FFT bin indices for testFrequencies and get bin center frequencies
    // Find FFT bin indices for testFrequencies and get bin center frequencies
@@ -403,6 +445,17 @@ class EffectHelper {
        return bufferMag;
        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;
    bool mIsSpatializer;
    Descriptor mDescriptor;
    Descriptor mDescriptor;
    size_t mInputFrameSize, mOutputFrameSize;
    size_t mInputSamples, mOutputSamples;
};
};
+43 −226

File changed.

Preview size limit exceeded, changes collapsed.