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

Commit d9ea5054 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ie3b71978,Iead1be02,Id79fad2d,Ie3759e6c into rvc-dev

* changes:
  VTS: move output validation after flush to a method
  VTS: Refactor Video and Audio decoder test functions
  VTS: Refactor Audio Encoder Test Code
  VTS: add validation for work result
parents 1b0be545 5a9a3f93
Loading
Loading
Loading
Loading
+81 −125
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
#include <hidl/GtestPrinter.h>
#include <stdio.h>
#include <algorithm>
#include <fstream>

#include <C2AllocatorIon.h>
#include <C2Buffer.h>
@@ -35,12 +34,6 @@ using android::C2AllocatorIon;

#include "media_c2_hidl_test_common.h"

struct FrameInfo {
    int bytesCount;
    uint32_t flags;
    int64_t timestamp;
};

static std::vector<std::tuple<std::string, std::string, std::string, std::string>>
        kDecodeTestParameters;

@@ -105,6 +98,7 @@ class Codec2AudioDecHidlTestBase : public ::testing::Test {
        mEos = false;
        mFramesReceived = 0;
        mTimestampUs = 0u;
        mWorkResult = C2_OK;
        mTimestampDevTest = false;
        if (mCompName == unknown_comp) mDisableTest = true;
        if (mDisableTest) std::cout << "[   WARN   ] Test Disabled \n";
@@ -121,6 +115,8 @@ class Codec2AudioDecHidlTestBase : public ::testing::Test {
    // Get the test parameters from GetParam call.
    virtual void getParams() {}

    virtual void validateTimestampList(int32_t* bitStreamInfo);

    struct outputMetaData {
        uint64_t timestampUs;
        uint32_t rangeLength;
@@ -131,6 +127,7 @@ class Codec2AudioDecHidlTestBase : public ::testing::Test {
            if (!work->worklets.empty()) {
                // For decoder components current timestamp always exceeds
                // previous timestamp
                mWorkResult |= work->result;
                bool codecConfig = ((work->worklets.front()->output.flags &
                                     C2FrameData::FLAG_CODEC_CONFIG) != 0);
                if (!codecConfig && !work->worklets.front()->output.buffers.empty()) {
@@ -182,6 +179,8 @@ class Codec2AudioDecHidlTestBase : public ::testing::Test {
    bool mDisableTest;
    bool mTimestampDevTest;
    standardComp mCompName;

    int32_t mWorkResult;
    uint64_t mTimestampUs;
    uint32_t mFramesReceived;
    std::list<uint64_t> mFlushedIndices;
@@ -457,6 +456,31 @@ void decodeNFrames(const std::shared_ptr<android::Codec2Client::Component>& comp
    }
}

void Codec2AudioDecHidlTestBase::validateTimestampList(int32_t* bitStreamInfo) {
    uint32_t samplesReceived = 0;
    // Update SampleRate and ChannelCount
    ASSERT_NO_FATAL_FAILURE(getInputChannelInfo(mComponent, mCompName, bitStreamInfo));
    int32_t nSampleRate = bitStreamInfo[0];
    int32_t nChannels = bitStreamInfo[1];
    std::list<uint64_t>::iterator itIn = mTimestampUslist.begin();
    auto itOut = oBufferMetaData.begin();
    EXPECT_EQ(*itIn, itOut->timestampUs);
    uint64_t expectedTimeStamp = *itIn;
    while (itOut != oBufferMetaData.end()) {
        EXPECT_EQ(expectedTimeStamp, itOut->timestampUs);
        if (expectedTimeStamp != itOut->timestampUs) break;
        // buffer samples = ((total bytes) / (ac * (bits per sample / 8))
        samplesReceived += ((itOut->rangeLength) / (nChannels * 2));
        expectedTimeStamp = samplesReceived * 1000000ll / nSampleRate;
        itOut++;
    }
    itIn = mTimestampUslist.end();
    --itIn;
    EXPECT_GT(expectedTimeStamp, *itIn);
    oBufferMetaData.clear();
    mTimestampUslist.clear();
}

TEST_P(Codec2AudioDecHidlTest, validateCompName) {
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    ALOGV("Checks if the given component is a valid audio component");
@@ -493,7 +517,7 @@ TEST_P(Codec2AudioDecDecodeTest, DecodeTest) {
    bool signalEOS = !std::get<3>(GetParam()).compare("true");
    mTimestampDevTest = true;
    char mURL[512], info[512];
    std::ifstream eleStream, eleInfo;
    android::Vector<FrameInfo> Info;

    strcpy(mURL, sResourceDir.c_str());
    strcpy(info, sResourceDir.c_str());
@@ -503,21 +527,9 @@ TEST_P(Codec2AudioDecDecodeTest, DecodeTest) {
        return;
    }

    eleInfo.open(info);
    ASSERT_EQ(eleInfo.is_open(), true);
    android::Vector<FrameInfo> Info;
    int bytesCount = 0;
    uint32_t flags = 0;
    uint32_t timestamp = 0;
    while (1) {
        if (!(eleInfo >> bytesCount)) break;
        eleInfo >> flags;
        eleInfo >> timestamp;
        bool codecConfig = ((1 << (flags - 1)) & C2FrameData::FLAG_CODEC_CONFIG) != 0;
        if (mTimestampDevTest && !codecConfig) mTimestampUslist.push_back(timestamp);
        Info.push_back({bytesCount, flags, timestamp});
    }
    eleInfo.close();
    int32_t numCsds = populateInfoVector(info, &Info, mTimestampDevTest, &mTimestampUslist);
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file: " << info;

    // Reset total no of frames received
    mFramesReceived = 0;
    mTimestampUs = 0;
@@ -534,6 +546,7 @@ TEST_P(Codec2AudioDecDecodeTest, DecodeTest) {
    }
    ASSERT_EQ(mComponent->start(), C2_OK);
    ALOGV("mURL : %s", mURL);
    std::ifstream eleStream;
    eleStream.open(mURL, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
@@ -550,7 +563,7 @@ TEST_P(Codec2AudioDecDecodeTest, DecodeTest) {
    }
    // blocking call to ensures application to Wait till all the inputs are
    // consumed
    ASSERT_NO_FATAL_FAILURE(waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue));
    waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue);
    eleStream.close();
    if (mFramesReceived != infoSize) {
        ALOGE("Input buffer count and Output buffer count mismatch");
@@ -558,32 +571,12 @@ TEST_P(Codec2AudioDecDecodeTest, DecodeTest) {
        ASSERT_TRUE(false);
    }
    ASSERT_EQ(mEos, true);

    if (mTimestampDevTest) {
        uint64_t expTs;
        uint32_t samplesReceived = 0;
        // Update SampleRate and ChannelCount
        ASSERT_NO_FATAL_FAILURE(getInputChannelInfo(mComponent, mCompName, bitStreamInfo));
        int nSampleRate = bitStreamInfo[0];
        int nChannels = bitStreamInfo[1];
        std::list<uint64_t>::iterator itIn = mTimestampUslist.begin();
        auto itOut = oBufferMetaData.begin();
        EXPECT_EQ(*itIn, itOut->timestampUs);
        expTs = *itIn;
        while (itOut != oBufferMetaData.end()) {
            EXPECT_EQ(expTs, itOut->timestampUs);
            if (expTs != itOut->timestampUs) break;
            // buffer samples = ((total bytes) / (ac * (bits per sample / 8))
            samplesReceived += ((itOut->rangeLength) / (nChannels * 2));
            expTs = samplesReceived * 1000000ll / nSampleRate;
            itOut++;
        }
        itIn = mTimestampUslist.end();
        --itIn;
        EXPECT_GT(expTs, *itIn);
        oBufferMetaData.clear();
        mTimestampUslist.clear();
        validateTimestampList(bitStreamInfo);
    }
    ASSERT_EQ(mComponent->stop(), C2_OK);
    ASSERT_EQ(mWorkResult, C2_OK);
}

// thumbnail test
@@ -592,25 +585,15 @@ TEST_P(Codec2AudioDecHidlTest, ThumbnailTest) {
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";

    char mURL[512], info[512];
    std::ifstream eleStream, eleInfo;
    android::Vector<FrameInfo> Info;

    strcpy(mURL, sResourceDir.c_str());
    strcpy(info, sResourceDir.c_str());
    GetURLForComponent(mCompName, mURL, info);

    eleInfo.open(info);
    ASSERT_EQ(eleInfo.is_open(), true);
    android::Vector<FrameInfo> Info;
    int bytesCount = 0;
    uint32_t flags = 0;
    uint32_t timestamp = 0;
    while (1) {
        if (!(eleInfo >> bytesCount)) break;
        eleInfo >> flags;
        eleInfo >> timestamp;
        Info.push_back({bytesCount, flags, timestamp});
    }
    eleInfo.close();
    int32_t numCsds = populateInfoVector(info, &Info, mTimestampDevTest, &mTimestampUslist);
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file: " << info;

    int32_t bitStreamInfo[2] = {0};
    if (mCompName == raw) {
        bitStreamInfo[0] = 8000;
@@ -628,22 +611,25 @@ TEST_P(Codec2AudioDecHidlTest, ThumbnailTest) {
    // request EOS for thumbnail
    // signal EOS flag with last frame
    size_t i = -1;
    uint32_t flags;
    do {
        i++;
        flags = 0;
        if (Info[i].flags) flags = 1u << (Info[i].flags - 1);

    } while (!(flags & SYNC_FRAME));
    std::ifstream eleStream;
    eleStream.open(mURL, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                          mFlushedIndices, mLinearPool, eleStream, &Info, 0,
                                          i + 1));
    ASSERT_NO_FATAL_FAILURE(waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue));
    waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue);
    eleStream.close();
    EXPECT_GE(mFramesReceived, 1U);
    ASSERT_EQ(mEos, true);
    ASSERT_EQ(mComponent->stop(), C2_OK);
    ASSERT_EQ(mWorkResult, C2_OK);
}

TEST_P(Codec2AudioDecHidlTest, EOSTest) {
@@ -684,33 +670,22 @@ TEST_P(Codec2AudioDecHidlTest, EOSTest) {
    ASSERT_EQ(mEos, true);
    ASSERT_EQ(mWorkQueue.size(), (size_t)MAX_INPUT_BUFFERS);
    ASSERT_EQ(mComponent->stop(), C2_OK);
    ASSERT_EQ(mWorkResult, C2_OK);
}

TEST_P(Codec2AudioDecHidlTest, FlushTest) {
    description("Tests Flush calls");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    typedef std::unique_lock<std::mutex> ULock;
    char mURL[512], info[512];
    std::ifstream eleStream, eleInfo;
    android::Vector<FrameInfo> Info;

    strcpy(mURL, sResourceDir.c_str());
    strcpy(info, sResourceDir.c_str());
    GetURLForComponent(mCompName, mURL, info);

    eleInfo.open(info);
    ASSERT_EQ(eleInfo.is_open(), true);
    android::Vector<FrameInfo> Info;
    int bytesCount = 0;
    uint32_t flags = 0;
    uint32_t timestamp = 0;
    mFlushedIndices.clear();
    while (1) {
        if (!(eleInfo >> bytesCount)) break;
        eleInfo >> flags;
        eleInfo >> timestamp;
        Info.push_back({bytesCount, flags, timestamp});
    }
    eleInfo.close();
    int32_t numCsds = populateInfoVector(info, &Info, mTimestampDevTest, &mTimestampUslist);
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file: " << info;

    int32_t bitStreamInfo[2] = {0};
    if (mCompName == raw) {
        bitStreamInfo[0] = 8000;
@@ -723,44 +698,37 @@ TEST_P(Codec2AudioDecHidlTest, FlushTest) {
        return;
    }
    ASSERT_EQ(mComponent->start(), C2_OK);
    // flush
    std::list<std::unique_ptr<C2Work>> flushedWork;
    c2_status_t err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    ASSERT_EQ(err, C2_OK);
    ASSERT_NO_FATAL_FAILURE(
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);

    ALOGV("mURL : %s", mURL);
    std::ifstream eleStream;
    eleStream.open(mURL, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    // Decode 128 frames and flush. here 128 is chosen to ensure there is a key
    // frame after this so that the below section can be covered for all
    // components
    uint32_t numFramesFlushed = 128;
    // Decode 30 frames and flush.
    uint32_t numFramesFlushed = FLUSH_INTERVAL;
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                          mFlushedIndices, mLinearPool, eleStream, &Info, 0,
                                          numFramesFlushed, false));
    // flush
    std::list<std::unique_ptr<C2Work>> flushedWork;
    c2_status_t err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    ASSERT_EQ(err, C2_OK);
    ASSERT_NO_FATAL_FAILURE(waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
                                                   (size_t)MAX_INPUT_BUFFERS - flushedWork.size()));
    uint64_t frameIndex;
    {
        // Update mFlushedIndices based on the index received from flush()
        ULock l(mQueueLock);
        for (std::unique_ptr<C2Work>& work : flushedWork) {
            ASSERT_NE(work, nullptr);
            frameIndex = work->input.ordinal.frameIndex.peeku();
            std::list<uint64_t>::iterator frameIndexIt =
                    std::find(mFlushedIndices.begin(), mFlushedIndices.end(), frameIndex);
            if (!mFlushedIndices.empty() && (frameIndexIt != mFlushedIndices.end())) {
                mFlushedIndices.erase(frameIndexIt);
                work->input.buffers.clear();
                work->worklets.clear();
                mWorkQueue.push_back(std::move(work));
            }
        }
    }
    waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
                           (size_t)MAX_INPUT_BUFFERS - flushedWork.size());
    ASSERT_NO_FATAL_FAILURE(
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);

    // Seek to next key frame and start decoding till the end
    mFlushedIndices.clear();
    int index = numFramesFlushed;
    bool keyFrame = false;
    flags = 0;
    uint32_t flags = 0;
    while (index < (int)Info.size()) {
        if (Info[index].flags) flags = 1u << (Info[index].flags - 1);
        if ((flags & SYNC_FRAME) == SYNC_FRAME) {
@@ -779,25 +747,13 @@ TEST_P(Codec2AudioDecHidlTest, FlushTest) {
    eleStream.close();
    err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    ASSERT_EQ(err, C2_OK);
    ASSERT_NO_FATAL_FAILURE(waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
                                                   (size_t)MAX_INPUT_BUFFERS - flushedWork.size()));
    {
        // Update mFlushedIndices based on the index received from flush()
        ULock l(mQueueLock);
        for (std::unique_ptr<C2Work>& work : flushedWork) {
            ASSERT_NE(work, nullptr);
            frameIndex = work->input.ordinal.frameIndex.peeku();
            std::list<uint64_t>::iterator frameIndexIt =
                    std::find(mFlushedIndices.begin(), mFlushedIndices.end(), frameIndex);
            if (!mFlushedIndices.empty() && (frameIndexIt != mFlushedIndices.end())) {
                mFlushedIndices.erase(frameIndexIt);
                work->input.buffers.clear();
                work->worklets.clear();
                mWorkQueue.push_back(std::move(work));
            }
        }
    }
    ASSERT_EQ(mFlushedIndices.empty(), true);
    waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
                           (size_t)MAX_INPUT_BUFFERS - flushedWork.size());
    ASSERT_NO_FATAL_FAILURE(
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);
    // TODO: (b/154671521)
    // Add assert for mWorkResult
    ASSERT_EQ(mComponent->stop(), C2_OK);
}

@@ -862,7 +818,7 @@ TEST_P(Codec2AudioDecHidlTest, DecodeTestEmptyBuffersInserted) {
    // consumed
    if (!mEos) {
        ALOGV("Waiting for input consumption");
        ASSERT_NO_FATAL_FAILURE(waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue));
        waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue);
    }

    eleStream.close();
+82 −105
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ class Codec2AudioEncHidlTestBase : public ::testing::Test {
        mEos = false;
        mCsd = false;
        mFramesReceived = 0;
        mWorkResult = C2_OK;
        if (mCompName == unknown_comp) mDisableTest = true;
        if (mDisableTest) std::cout << "[   WARN   ] Test Disabled \n";
        getInputMaxBufSize();
@@ -115,6 +116,7 @@ class Codec2AudioEncHidlTestBase : public ::testing::Test {
    void handleWorkDone(std::list<std::unique_ptr<C2Work>>& workItems) {
        for (std::unique_ptr<C2Work>& work : workItems) {
            if (!work->worklets.empty()) {
                mWorkResult |= work->result;
                workDone(mComponent, work, mFlushedIndices, mQueueLock, mQueueCondition, mWorkQueue,
                         mEos, mCsd, mFramesReceived);
            }
@@ -135,6 +137,8 @@ class Codec2AudioEncHidlTestBase : public ::testing::Test {
    bool mCsd;
    bool mDisableTest;
    standardComp mCompName;

    int32_t mWorkResult;
    uint32_t mFramesReceived;
    int32_t mInputMaxBufSize;
    std::list<uint64_t> mFlushedIndices;
@@ -236,6 +240,41 @@ bool setupConfigParam(const std::shared_ptr<android::Codec2Client::Component>& c
    return false;
}

// Get config params for a component
bool getConfigParams(Codec2AudioEncHidlTest::standardComp compName, int32_t* nChannels,
                     int32_t* nSampleRate, int32_t* samplesPerFrame) {
    switch (compName) {
        case Codec2AudioEncHidlTest::aac:
            *nChannels = 2;
            *nSampleRate = 48000;
            *samplesPerFrame = 1024;
            break;
        case Codec2AudioEncHidlTest::flac:
            *nChannels = 2;
            *nSampleRate = 48000;
            *samplesPerFrame = 1152;
            break;
        case Codec2AudioEncHidlTest::opus:
            *nChannels = 2;
            *nSampleRate = 48000;
            *samplesPerFrame = 960;
            break;
        case Codec2AudioEncHidlTest::amrnb:
            *nChannels = 1;
            *nSampleRate = 8000;
            *samplesPerFrame = 160;
            break;
        case Codec2AudioEncHidlTest::amrwb:
            *nChannels = 1;
            *nSampleRate = 16000;
            *samplesPerFrame = 160;
            break;
        default:
            return false;
    }
    return true;
}

// LookUpTable of clips and metadata for component testing
void GetURLForComponent(Codec2AudioEncHidlTest::standardComp comp, char* mURL) {
    struct CompToURL {
@@ -367,36 +406,18 @@ TEST_P(Codec2AudioEncEncodeTest, EncodeTest) {
    bool signalEOS = !std::get<2>(GetParam()).compare("true");
    // Ratio w.r.t to mInputMaxBufSize
    int32_t inputMaxBufRatio = std::stoi(std::get<3>(GetParam()));
    ;

    // Setting default sampleRate
    int32_t nChannels = 2;
    int32_t nSampleRate = 44100;
    switch (mCompName) {
        case aac:
            nChannels = 2;
            nSampleRate = 48000;
            break;
        case flac:
            nChannels = 2;
            nSampleRate = 48000;
            break;
        case opus:
            nChannels = 2;
            nSampleRate = 48000;
            break;
        case amrnb:
            nChannels = 1;
            nSampleRate = 8000;
            break;
        case amrwb:
            nChannels = 1;
            nSampleRate = 16000;
            break;
        default:
            ASSERT_TRUE(false);

    int32_t nChannels;
    int32_t nSampleRate;
    int32_t samplesPerFrame;

    if (!getConfigParams(mCompName, &nChannels, &nSampleRate, &samplesPerFrame)) {
        std::cout << "Failed to get the config params for " << mCompName << " component\n";
        std::cout << "[   WARN   ] Test Skipped \n";
        return;
    }
    int32_t samplesPerFrame = ((mInputMaxBufSize / inputMaxBufRatio) / (nChannels * 2));

    samplesPerFrame = ((mInputMaxBufSize / inputMaxBufRatio) / (nChannels * 2));
    ALOGV("signalEOS %d mInputMaxBufSize %d samplesPerFrame %d", signalEOS, mInputMaxBufSize,
          samplesPerFrame);

@@ -416,7 +437,7 @@ TEST_P(Codec2AudioEncEncodeTest, EncodeTest) {

    // If EOS is not sent, sending empty input with EOS flag
    if (!signalEOS) {
        ASSERT_NO_FATAL_FAILURE(waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue, 1));
        waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue, 1);
        ASSERT_NO_FATAL_FAILURE(testInputBuffer(mComponent, mQueueLock, mWorkQueue,
                                                C2FrameData::FLAG_END_OF_STREAM, false));
        numFrames += 1;
@@ -424,7 +445,7 @@ TEST_P(Codec2AudioEncEncodeTest, EncodeTest) {

    // blocking call to ensures application to Wait till all the inputs are
    // consumed
    ASSERT_NO_FATAL_FAILURE(waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue));
    waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue);
    eleStream.close();
    if (mFramesReceived != numFrames) {
        ALOGE("Input buffer count and Output buffer count mismatch");
@@ -439,6 +460,7 @@ TEST_P(Codec2AudioEncEncodeTest, EncodeTest) {
    }
    ASSERT_EQ(mEos, true);
    ASSERT_EQ(mComponent->stop(), C2_OK);
    ASSERT_EQ(mWorkResult, C2_OK);
}

TEST_P(Codec2AudioEncHidlTest, EOSTest) {
@@ -479,50 +501,26 @@ TEST_P(Codec2AudioEncHidlTest, EOSTest) {
    }
    ASSERT_EQ(mEos, true);
    ASSERT_EQ(mComponent->stop(), C2_OK);
    ASSERT_EQ(mWorkResult, C2_OK);
}

TEST_P(Codec2AudioEncHidlTest, FlushTest) {
    description("Test Request for flush");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";

    typedef std::unique_lock<std::mutex> ULock;
    char mURL[512];
    strcpy(mURL, sResourceDir.c_str());
    GetURLForComponent(mCompName, mURL);

    // Setting default configuration
    mFlushedIndices.clear();
    int32_t nChannels = 2;
    int32_t nSampleRate = 44100;
    int32_t samplesPerFrame = 1024;
    switch (mCompName) {
        case aac:
            nChannels = 2;
            nSampleRate = 48000;
            samplesPerFrame = 1024;
            break;
        case flac:
            nChannels = 2;
            nSampleRate = 48000;
            samplesPerFrame = 1152;
            break;
        case opus:
            nChannels = 2;
            nSampleRate = 48000;
            samplesPerFrame = 960;
            break;
        case amrnb:
            nChannels = 1;
            nSampleRate = 8000;
            samplesPerFrame = 160;
            break;
        case amrwb:
            nChannels = 1;
            nSampleRate = 16000;
            samplesPerFrame = 160;
            break;
        default:
            ASSERT_TRUE(false);
    int32_t nChannels;
    int32_t nSampleRate;
    int32_t samplesPerFrame;

    if (!getConfigParams(mCompName, &nChannels, &nSampleRate, &samplesPerFrame)) {
        std::cout << "Failed to get the config params for " << mCompName << " component\n";
        std::cout << "[   WARN   ] Test Skipped \n";
        return;
    }

    if (!setupConfigParam(mComponent, nChannels, nSampleRate)) {
@@ -536,33 +534,24 @@ TEST_P(Codec2AudioEncHidlTest, FlushTest) {
    uint32_t numFrames = 128;
    eleStream.open(mURL, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    // flush
    std::list<std::unique_ptr<C2Work>> flushedWork;
    c2_status_t err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    ASSERT_EQ(err, C2_OK);
    ASSERT_NO_FATAL_FAILURE(
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);
    ALOGV("mURL : %s", mURL);
    ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                          mFlushedIndices, mLinearPool, eleStream, numFramesFlushed,
                                          samplesPerFrame, nChannels, nSampleRate));
    std::list<std::unique_ptr<C2Work>> flushedWork;
    c2_status_t err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    ASSERT_EQ(err, C2_OK);
    ASSERT_NO_FATAL_FAILURE(waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
                                                   (size_t)MAX_INPUT_BUFFERS - flushedWork.size()));
    uint64_t frameIndex;
    {
        // Update mFlushedIndices based on the index received from flush()
        ULock l(mQueueLock);
        for (std::unique_ptr<C2Work>& work : flushedWork) {
            ASSERT_NE(work, nullptr);
            frameIndex = work->input.ordinal.frameIndex.peeku();
            std::list<uint64_t>::iterator frameIndexIt =
                    std::find(mFlushedIndices.begin(), mFlushedIndices.end(), frameIndex);
            if (!mFlushedIndices.empty() && (frameIndexIt != mFlushedIndices.end())) {
                mFlushedIndices.erase(frameIndexIt);
                work->input.buffers.clear();
                work->worklets.clear();
                mWorkQueue.push_back(std::move(work));
            }
        }
    }
    mFlushedIndices.clear();
    waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
                           (size_t)MAX_INPUT_BUFFERS - flushedWork.size());
    ASSERT_NO_FATAL_FAILURE(
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);
    ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                          mFlushedIndices, mLinearPool, eleStream,
                                          numFrames - numFramesFlushed, samplesPerFrame, nChannels,
@@ -570,25 +559,13 @@ TEST_P(Codec2AudioEncHidlTest, FlushTest) {
    eleStream.close();
    err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    ASSERT_EQ(err, C2_OK);
    ASSERT_NO_FATAL_FAILURE(waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
                                                   (size_t)MAX_INPUT_BUFFERS - flushedWork.size()));
    {
        // Update mFlushedIndices based on the index received from flush()
        ULock l(mQueueLock);
        for (std::unique_ptr<C2Work>& work : flushedWork) {
            ASSERT_NE(work, nullptr);
            frameIndex = work->input.ordinal.frameIndex.peeku();
            std::list<uint64_t>::iterator frameIndexIt =
                    std::find(mFlushedIndices.begin(), mFlushedIndices.end(), frameIndex);
            if (!mFlushedIndices.empty() && (frameIndexIt != mFlushedIndices.end())) {
                mFlushedIndices.erase(frameIndexIt);
                work->input.buffers.clear();
                work->worklets.clear();
                mWorkQueue.push_back(std::move(work));
            }
        }
    }
    ASSERT_EQ(mFlushedIndices.empty(), true);
    waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
                           (size_t)MAX_INPUT_BUFFERS - flushedWork.size());
    ASSERT_NO_FATAL_FAILURE(
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);
    // TODO: (b/154671521)
    // Add assert for mWorkResult
    ASSERT_EQ(mComponent->stop(), C2_OK);
}

+54 −1

File changed.

Preview size limit exceeded, changes collapsed.

+15 −0

File changed.

Preview size limit exceeded, changes collapsed.

+61 −105

File changed.

Preview size limit exceeded, changes collapsed.

Loading