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

Commit 092b019c authored by Harish Mahendrakar's avatar Harish Mahendrakar
Browse files

C2 VTS: Update SetUp() to reduce code duplications

- Renamed and moved getting file name functions to SetUp
- Added checks to mark tests as skipped, when no valid files
  are found for a mime
- Removed references to URL as these were just file names
- Updated audio encoder tests to call getting supported
  sample rate and channel counts in SetUp

Bug: 183454262
Bug: 189154961

Test: atest VtsHalMediaC2V1_0TargetAudioDecTest \
 VtsHalMediaC2V1_0TargetAudioEncTest \
 VtsHalMediaC2V1_0TargetVideoDecTest \
 VtsHalMediaC2V1_0TargetVideoEncTest

Change-Id: Icf3cff3690140e3297299d3bb2ce7b9f24dfd791
parent d7e271fb
Loading
Loading
Loading
Loading
+43 −64
Original line number Original line Diff line number Diff line
@@ -36,13 +36,13 @@ static std::vector<DecodeTestParameters> gDecodeTestParameters;
using CsdFlushTestParameters = std::tuple<std::string, std::string, bool>;
using CsdFlushTestParameters = std::tuple<std::string, std::string, bool>;
static std::vector<CsdFlushTestParameters> gCsdFlushTestParameters;
static std::vector<CsdFlushTestParameters> gCsdFlushTestParameters;


struct CompToURL {
struct CompToFiles {
    std::string mime;
    std::string mime;
    std::string mURL;
    std::string inputFile;
    std::string info;
    std::string infoFile;
};
};


std::vector<CompToURL> gCompToURL = {
std::vector<CompToFiles> gCompToFiles = {
        {"mp4a-latm", "bbb_aac_stereo_128kbps_48000hz.aac", "bbb_aac_stereo_128kbps_48000hz.info"},
        {"mp4a-latm", "bbb_aac_stereo_128kbps_48000hz.aac", "bbb_aac_stereo_128kbps_48000hz.info"},
        {"mp4a-latm", "bbb_aac_stereo_128kbps_48000hz.aac",
        {"mp4a-latm", "bbb_aac_stereo_128kbps_48000hz.aac",
         "bbb_aac_stereo_128kbps_48000hz_multi_frame.info"},
         "bbb_aac_stereo_128kbps_48000hz_multi_frame.info"},
@@ -110,6 +110,15 @@ class Codec2AudioDecHidlTestBase : public ::testing::Test {
        mTimestampUs = 0u;
        mTimestampUs = 0u;
        mWorkResult = C2_OK;
        mWorkResult = C2_OK;
        mTimestampDevTest = false;
        mTimestampDevTest = false;

        bool valid = getFileNames(mStreamIndex);
        if (!valid) {
            GTEST_SKIP() << "No test file for  mime " << mMime << " index: " << mStreamIndex;
        }
        ALOGV("mStreamIndex : %zu", mStreamIndex);
        ALOGV("mInputFile : %s", mInputFile.c_str());
        ALOGV("mInfoFile : %s", mInfoFile.c_str());

        if (mDisableTest) std::cout << "[   WARN   ] Test Disabled \n";
        if (mDisableTest) std::cout << "[   WARN   ] Test Disabled \n";
    }
    }


@@ -126,7 +135,7 @@ class Codec2AudioDecHidlTestBase : public ::testing::Test {


    virtual void validateTimestampList(int32_t* bitStreamInfo);
    virtual void validateTimestampList(int32_t* bitStreamInfo);


    void GetURLForComponent(char* mURL, char* info, size_t streamIndex = 0);
    bool getFileNames(size_t streamIndex = 0);


    struct outputMetaData {
    struct outputMetaData {
        uint64_t timestampUs;
        uint64_t timestampUs;
@@ -193,6 +202,10 @@ class Codec2AudioDecHidlTestBase : public ::testing::Test {
    std::shared_ptr<android::Codec2Client::Listener> mListener;
    std::shared_ptr<android::Codec2Client::Listener> mListener;
    std::shared_ptr<android::Codec2Client::Component> mComponent;
    std::shared_ptr<android::Codec2Client::Component> mComponent;


    std::string mInputFile;
    std::string mInfoFile;
    size_t mStreamIndex = 0;

  protected:
  protected:
    static void description(const std::string& description) {
    static void description(const std::string& description) {
        RecordProperty("description", description);
        RecordProperty("description", description);
@@ -204,6 +217,7 @@ class Codec2AudioDecHidlTest : public Codec2AudioDecHidlTestBase,
    void getParams() {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
        mComponentName = std::get<1>(GetParam());
        mStreamIndex = 0;
    }
    }
};
};


@@ -285,18 +299,20 @@ void getInputChannelInfo(const std::shared_ptr<android::Codec2Client::Component>
}
}


// LookUpTable of clips and metadata for component testing
// LookUpTable of clips and metadata for component testing
void Codec2AudioDecHidlTestBase::GetURLForComponent(char* mURL, char* info, size_t streamIndex) {
bool Codec2AudioDecHidlTestBase::getFileNames(size_t streamIndex) {
    int streamCount = 0;
    int streamCount = 0;
    for (size_t i = 0; i < gCompToURL.size(); ++i) {

        if (mMime.find(gCompToURL[i].mime) != std::string::npos) {
    for (size_t i = 0; i < gCompToFiles.size(); ++i) {
        if (mMime.find(gCompToFiles[i].mime) != std::string::npos) {
            if (streamCount == streamIndex) {
            if (streamCount == streamIndex) {
                strcat(mURL, gCompToURL[i].mURL.c_str());
                mInputFile = sResourceDir + gCompToFiles[i].inputFile;
                strcat(info, gCompToURL[i].info.c_str());
                mInfoFile = sResourceDir + gCompToFiles[i].infoFile;
                return;
                return true;
            }
            }
            streamCount++;
            streamCount++;
        }
        }
    }
    }
    return false;
}
}


void decodeNFrames(const std::shared_ptr<android::Codec2Client::Component>& component,
void decodeNFrames(const std::shared_ptr<android::Codec2Client::Component>& component,
@@ -429,6 +445,7 @@ class Codec2AudioDecDecodeTest : public Codec2AudioDecHidlTestBase,
    void getParams() {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
        mComponentName = std::get<1>(GetParam());
        mStreamIndex = std::get<2>(GetParam());
    }
    }
};
};


@@ -436,22 +453,12 @@ TEST_P(Codec2AudioDecDecodeTest, DecodeTest) {
    description("Decodes input file");
    description("Decodes input file");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";


    uint32_t streamIndex = std::get<2>(GetParam());
    bool signalEOS = std::get<3>(GetParam());
    bool signalEOS = std::get<3>(GetParam());
    mTimestampDevTest = true;
    mTimestampDevTest = true;
    char mURL[512], info[512];
    android::Vector<FrameInfo> Info;
    android::Vector<FrameInfo> Info;


    strcpy(mURL, sResourceDir.c_str());
    int32_t numCsds = populateInfoVector(mInfoFile, &Info, mTimestampDevTest, &mTimestampUslist);
    strcpy(info, sResourceDir.c_str());
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file: " << mInfoFile;
    GetURLForComponent(mURL, info, streamIndex);
    if (!strcmp(mURL, sResourceDir.c_str())) {
        ALOGV("EMPTY INPUT sResourceDir.c_str() %s mURL  %s ", sResourceDir.c_str(), mURL);
        return;
    }

    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
    // Reset total no of frames received
    mFramesReceived = 0;
    mFramesReceived = 0;
@@ -468,9 +475,8 @@ TEST_P(Codec2AudioDecDecodeTest, DecodeTest) {
        return;
        return;
    }
    }
    ASSERT_EQ(mComponent->start(), C2_OK);
    ASSERT_EQ(mComponent->start(), C2_OK);
    ALOGV("mURL : %s", mURL);
    std::ifstream eleStream;
    std::ifstream eleStream;
    eleStream.open(mURL, std::ifstream::binary);
    eleStream.open(mInputFile, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                          mFlushedIndices, mLinearPool, eleStream, &Info, 0,
                                          mFlushedIndices, mLinearPool, eleStream, &Info, 0,
@@ -507,15 +513,10 @@ TEST_P(Codec2AudioDecHidlTest, ThumbnailTest) {
    description("Test Request for thumbnail");
    description("Test Request for thumbnail");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";


    char mURL[512], info[512];
    android::Vector<FrameInfo> Info;
    android::Vector<FrameInfo> Info;


    strcpy(mURL, sResourceDir.c_str());
    int32_t numCsds = populateInfoVector(mInfoFile, &Info, mTimestampDevTest, &mTimestampUslist);
    strcpy(info, sResourceDir.c_str());
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file: " << mInfoFile;
    GetURLForComponent(mURL, info);

    int32_t numCsds = populateInfoVector(info, &Info, mTimestampDevTest, &mTimestampUslist);
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file: " << info;


    int32_t bitStreamInfo[2] = {0};
    int32_t bitStreamInfo[2] = {0};
    if (mMime.find("raw") != std::string::npos) {
    if (mMime.find("raw") != std::string::npos) {
@@ -529,7 +530,6 @@ TEST_P(Codec2AudioDecHidlTest, ThumbnailTest) {
        return;
        return;
    }
    }
    ASSERT_EQ(mComponent->start(), C2_OK);
    ASSERT_EQ(mComponent->start(), C2_OK);
    ALOGV("mURL : %s", mURL);


    // request EOS for thumbnail
    // request EOS for thumbnail
    // signal EOS flag with last frame
    // signal EOS flag with last frame
@@ -542,7 +542,7 @@ TEST_P(Codec2AudioDecHidlTest, ThumbnailTest) {


    } while (!(flags & SYNC_FRAME));
    } while (!(flags & SYNC_FRAME));
    std::ifstream eleStream;
    std::ifstream eleStream;
    eleStream.open(mURL, std::ifstream::binary);
    eleStream.open(mInputFile, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                          mFlushedIndices, mLinearPool, eleStream, &Info, 0,
                                          mFlushedIndices, mLinearPool, eleStream, &Info, 0,
@@ -599,15 +599,10 @@ TEST_P(Codec2AudioDecHidlTest, EOSTest) {
TEST_P(Codec2AudioDecHidlTest, FlushTest) {
TEST_P(Codec2AudioDecHidlTest, FlushTest) {
    description("Tests Flush calls");
    description("Tests Flush calls");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    char mURL[512], info[512];
    android::Vector<FrameInfo> Info;
    android::Vector<FrameInfo> Info;


    strcpy(mURL, sResourceDir.c_str());
    int32_t numCsds = populateInfoVector(mInfoFile, &Info, mTimestampDevTest, &mTimestampUslist);
    strcpy(info, sResourceDir.c_str());
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file: " << mInfoFile;
    GetURLForComponent(mURL, info);

    int32_t numCsds = populateInfoVector(info, &Info, mTimestampDevTest, &mTimestampUslist);
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file: " << info;


    int32_t bitStreamInfo[2] = {0};
    int32_t bitStreamInfo[2] = {0};
    if (mMime.find("raw") != std::string::npos) {
    if (mMime.find("raw") != std::string::npos) {
@@ -629,9 +624,8 @@ TEST_P(Codec2AudioDecHidlTest, FlushTest) {
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);


    ALOGV("mURL : %s", mURL);
    std::ifstream eleStream;
    std::ifstream eleStream;
    eleStream.open(mURL, std::ifstream::binary);
    eleStream.open(mInputFile, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_EQ(eleStream.is_open(), true);
    // Decode 30 frames and flush.
    // Decode 30 frames and flush.
    uint32_t numFramesFlushed = FLUSH_INTERVAL;
    uint32_t numFramesFlushed = FLUSH_INTERVAL;
@@ -684,15 +678,10 @@ TEST_P(Codec2AudioDecHidlTest, DecodeTestEmptyBuffersInserted) {
    description("Decode with multiple empty input frames");
    description("Decode with multiple empty input frames");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";


    char mURL[512], info[512];
    std::ifstream eleStream, eleInfo;
    std::ifstream eleStream, eleInfo;


    strcpy(mURL, sResourceDir.c_str());
    eleInfo.open(mInfoFile);
    strcpy(info, sResourceDir.c_str());
    ASSERT_EQ(eleInfo.is_open(), true) << mInputFile << " - file not found";
    GetURLForComponent(mURL, info);

    eleInfo.open(info);
    ASSERT_EQ(eleInfo.is_open(), true) << mURL << " - file not found";
    android::Vector<FrameInfo> Info;
    android::Vector<FrameInfo> Info;
    int bytesCount = 0;
    int bytesCount = 0;
    uint32_t frameId = 0;
    uint32_t frameId = 0;
@@ -730,8 +719,7 @@ TEST_P(Codec2AudioDecHidlTest, DecodeTestEmptyBuffersInserted) {
        return;
        return;
    }
    }
    ASSERT_EQ(mComponent->start(), C2_OK);
    ASSERT_EQ(mComponent->start(), C2_OK);
    ALOGV("mURL : %s", mURL);
    eleStream.open(mInputFile, std::ifstream::binary);
    eleStream.open(mURL, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                          mFlushedIndices, mLinearPool, eleStream, &Info, 0,
                                          mFlushedIndices, mLinearPool, eleStream, &Info, 0,
@@ -759,6 +747,7 @@ class Codec2AudioDecCsdInputTests : public Codec2AudioDecHidlTestBase,
    void getParams() {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
        mComponentName = std::get<1>(GetParam());
        mStreamIndex = 0;
    }
    }
};
};


@@ -768,19 +757,9 @@ TEST_P(Codec2AudioDecCsdInputTests, CSDFlushTest) {
    description("Tests codecs for flush at different states");
    description("Tests codecs for flush at different states");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";


    char mURL[512], info[512];
    android::Vector<FrameInfo> Info;
    android::Vector<FrameInfo> Info;


    strcpy(mURL, sResourceDir.c_str());
    int32_t numCsds = populateInfoVector(mInfoFile, &Info, mTimestampDevTest, &mTimestampUslist);
    strcpy(info, sResourceDir.c_str());
    GetURLForComponent(mURL, info);
    if (!strcmp(mURL, sResourceDir.c_str())) {
        ALOGV("EMPTY INPUT sResourceDir.c_str() %s mURL  %s ", sResourceDir.c_str(), mURL);
        return;
    }
    ALOGV("mURL : %s", mURL);

    int32_t numCsds = populateInfoVector(info, &Info, mTimestampDevTest, &mTimestampUslist);
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file";
    ASSERT_GE(numCsds, 0) << "Error in parsing input info file";


    int32_t bitStreamInfo[2] = {0};
    int32_t bitStreamInfo[2] = {0};
@@ -797,7 +776,7 @@ TEST_P(Codec2AudioDecCsdInputTests, CSDFlushTest) {


    ASSERT_EQ(mComponent->start(), C2_OK);
    ASSERT_EQ(mComponent->start(), C2_OK);
    std::ifstream eleStream;
    std::ifstream eleStream;
    eleStream.open(mURL, std::ifstream::binary);
    eleStream.open(mInputFile, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_EQ(eleStream.is_open(), true);


    bool signalEOS = false;
    bool signalEOS = false;
+62 −115
Original line number Original line Diff line number Diff line
@@ -84,6 +84,17 @@ class Codec2AudioEncHidlTestBase : public ::testing::Test {
        mWorkResult = C2_OK;
        mWorkResult = C2_OK;
        mOutputSize = 0u;
        mOutputSize = 0u;
        getInputMaxBufSize();
        getInputMaxBufSize();

        c2_status_t status = getChannelCount(&mNumChannels);
        ASSERT_EQ(status, C2_OK) << "Unable to get supported channel count";

        status = getSampleRate(&mSampleRate);
        ASSERT_EQ(status, C2_OK) << "Unable to get supported sample rate";

        status = getSamplesPerFrame(mNumChannels, &mSamplesPerFrame);
        ASSERT_EQ(status, C2_OK) << "Unable to get supported number of samples per frame";

        getFile(mNumChannels, mSampleRate);
    }
    }


    virtual void TearDown() override {
    virtual void TearDown() override {
@@ -97,7 +108,11 @@ class Codec2AudioEncHidlTestBase : public ::testing::Test {
    // Get the test parameters from GetParam call.
    // Get the test parameters from GetParam call.
    virtual void getParams() {}
    virtual void getParams() {}


    void GetURLForComponent(char* mURL, int32_t channelCount, int32_t sampleRate);
    c2_status_t getChannelCount(int32_t* nChannels);
    c2_status_t getSampleRate(int32_t* nSampleRate);
    c2_status_t getSamplesPerFrame(int32_t nChannels, int32_t* samplesPerFrame);

    void getFile(int32_t channelCount, int32_t sampleRate);


    // callback function to process onWorkDone received by Listener
    // callback function to process onWorkDone received by Listener
    void handleWorkDone(std::list<std::unique_ptr<C2Work>>& workItems) {
    void handleWorkDone(std::list<std::unique_ptr<C2Work>>& workItems) {
@@ -145,6 +160,12 @@ class Codec2AudioEncHidlTestBase : public ::testing::Test {
    std::shared_ptr<android::Codec2Client::Listener> mListener;
    std::shared_ptr<android::Codec2Client::Listener> mListener;
    std::shared_ptr<android::Codec2Client::Component> mComponent;
    std::shared_ptr<android::Codec2Client::Component> mComponent;


    int32_t mNumChannels;
    int32_t mSampleRate;
    int32_t mSamplesPerFrame;

    std::string mInputFile;

  protected:
  protected:
    static void description(const std::string& description) {
    static void description(const std::string& description) {
        RecordProperty("description", description);
        RecordProperty("description", description);
@@ -222,14 +243,13 @@ bool setupConfigParam(const std::shared_ptr<android::Codec2Client::Component>& c
    return false;
    return false;
}
}


c2_status_t getChannelCount(const std::shared_ptr<android::Codec2Client::Component>& component,
c2_status_t Codec2AudioEncHidlTestBase::getChannelCount(int32_t* nChannels) {
                            int32_t* nChannels) {
    std::unique_ptr<C2StreamChannelCountInfo::input> channelCount =
    std::unique_ptr<C2StreamChannelCountInfo::input> channelCount =
            std::make_unique<C2StreamChannelCountInfo::input>();
            std::make_unique<C2StreamChannelCountInfo::input>();
    std::vector<C2FieldSupportedValuesQuery> validValueInfos = {
    std::vector<C2FieldSupportedValuesQuery> validValueInfos = {
            C2FieldSupportedValuesQuery::Current(
            C2FieldSupportedValuesQuery::Current(
                    C2ParamField(channelCount.get(), &C2StreamChannelCountInfo::value))};
                    C2ParamField(channelCount.get(), &C2StreamChannelCountInfo::value))};
    c2_status_t c2err = component->querySupportedValues(validValueInfos, C2_DONT_BLOCK);
    c2_status_t c2err = mComponent->querySupportedValues(validValueInfos, C2_DONT_BLOCK);
    if (c2err != C2_OK || validValueInfos.size() != 1u) {
    if (c2err != C2_OK || validValueInfos.size() != 1u) {
        ALOGE("querySupportedValues_vb failed for channelCount");
        ALOGE("querySupportedValues_vb failed for channelCount");
        return c2err;
        return c2err;
@@ -264,12 +284,10 @@ c2_status_t getChannelCount(const std::shared_ptr<android::Codec2Client::Compone
    }
    }
    return C2_OK;
    return C2_OK;
}
}

c2_status_t Codec2AudioEncHidlTestBase::getSampleRate(int32_t* nSampleRate) {
c2_status_t getSampleRate(const std::shared_ptr<android::Codec2Client::Component>& component,
    // Use the default sample rate for mComponents
                          int32_t* nSampleRate) {
    // Use the default sample rate for components
    std::vector<std::unique_ptr<C2Param>> queried;
    std::vector<std::unique_ptr<C2Param>> queried;
    c2_status_t c2err = component->query({}, {C2StreamSampleRateInfo::input::PARAM_TYPE},
    c2_status_t c2err = mComponent->query({}, {C2StreamSampleRateInfo::input::PARAM_TYPE},
                                          C2_DONT_BLOCK, &queried);
                                          C2_DONT_BLOCK, &queried);
    if (c2err != C2_OK || queried.size() == 0) return c2err;
    if (c2err != C2_OK || queried.size() == 0) return c2err;


@@ -280,10 +298,10 @@ c2_status_t getSampleRate(const std::shared_ptr<android::Codec2Client::Component
    return C2_OK;
    return C2_OK;
}
}


c2_status_t getSamplesPerFrame(const std::shared_ptr<android::Codec2Client::Component>& component,
c2_status_t Codec2AudioEncHidlTestBase::getSamplesPerFrame(int32_t nChannels,
                               int32_t nChannels, int32_t* samplesPerFrame) {
                                                           int32_t* samplesPerFrame) {
    std::vector<std::unique_ptr<C2Param>> queried;
    std::vector<std::unique_ptr<C2Param>> queried;
    c2_status_t c2err = component->query({}, {C2StreamMaxBufferSizeInfo::input::PARAM_TYPE},
    c2_status_t c2err = mComponent->query({}, {C2StreamMaxBufferSizeInfo::input::PARAM_TYPE},
                                          C2_DONT_BLOCK, &queried);
                                          C2_DONT_BLOCK, &queried);
    if (c2err != C2_OK || queried.size() == 0) return c2err;
    if (c2err != C2_OK || queried.size() == 0) return c2err;


@@ -295,24 +313,8 @@ c2_status_t getSamplesPerFrame(const std::shared_ptr<android::Codec2Client::Comp
    return C2_OK;
    return C2_OK;
}
}


// Get config params for a component
bool getConfigParams(const std::shared_ptr<android::Codec2Client::Component>& component,
                     int32_t* nChannels, int32_t* nSampleRate, int32_t* samplesPerFrame) {
    c2_status_t status = getChannelCount(component, nChannels);
    if (status != C2_OK) return false;

    status = getSampleRate(component, nSampleRate);
    if (status != C2_OK) return false;

    status = getSamplesPerFrame(component, *nChannels, samplesPerFrame);
    if (status != C2_OK) return false;

    return true;
}

// LookUpTable of clips and metadata for component testing
// LookUpTable of clips and metadata for component testing
void Codec2AudioEncHidlTestBase::GetURLForComponent(char* mURL, int32_t channelCount,
void Codec2AudioEncHidlTestBase::getFile(int32_t channelCount, int32_t sampleRate) {
                                                    int32_t sampleRate) {
    std::string rawInput = "bbb_raw_1ch_8khz_s16le.raw";
    std::string rawInput = "bbb_raw_1ch_8khz_s16le.raw";
    if (channelCount == 1 && sampleRate == 16000) {
    if (channelCount == 1 && sampleRate == 16000) {
        rawInput = "bbb_raw_1ch_16khz_s16le.raw";
        rawInput = "bbb_raw_1ch_16khz_s16le.raw";
@@ -320,7 +322,7 @@ void Codec2AudioEncHidlTestBase::GetURLForComponent(char* mURL, int32_t channelC
        rawInput = "bbb_raw_2ch_48khz_s16le.raw";
        rawInput = "bbb_raw_2ch_48khz_s16le.raw";
    }
    }


    strcat(mURL, rawInput.c_str());
    mInputFile = sResourceDir + rawInput;
}
}


void encodeNFrames(const std::shared_ptr<android::Codec2Client::Component>& component,
void encodeNFrames(const std::shared_ptr<android::Codec2Client::Component>& component,
@@ -440,38 +442,23 @@ TEST_P(Codec2AudioEncEncodeTest, EncodeTest) {
    bool signalEOS = std::get<2>(GetParam());
    bool signalEOS = std::get<2>(GetParam());
    // Ratio w.r.t to mInputMaxBufSize
    // Ratio w.r.t to mInputMaxBufSize
    int32_t inputMaxBufRatio = std::get<3>(GetParam());
    int32_t inputMaxBufRatio = std::get<3>(GetParam());
    mSamplesPerFrame = ((mInputMaxBufSize / inputMaxBufRatio) / (mNumChannels * 2));


    int32_t nChannels;
    ALOGV("signalEOS %d mInputMaxBufSize %d mSamplesPerFrame %d", signalEOS, mInputMaxBufSize,
    int32_t nSampleRate;
          mSamplesPerFrame);
    int32_t samplesPerFrame;

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

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


    if (!setupConfigParam(mComponent, nChannels, nSampleRate)) {
    ASSERT_TRUE(setupConfigParam(mComponent, mNumChannels, mSampleRate))
        std::cout << "[   WARN   ] Test Skipped \n";
            << "Unable to configure for channels: " << mNumChannels << " and sampling rate "
        return;
            << mSampleRate;
    }
    char mURL[512];
    strcpy(mURL, sResourceDir.c_str());
    GetURLForComponent(mURL, nChannels, nSampleRate);


    ASSERT_EQ(mComponent->start(), C2_OK);
    ASSERT_EQ(mComponent->start(), C2_OK);
    std::ifstream eleStream;
    std::ifstream eleStream;
    uint32_t numFrames = 16;
    uint32_t numFrames = 16;
    eleStream.open(mURL, std::ifstream::binary);
    eleStream.open(mInputFile, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_EQ(eleStream.is_open(), true);
    ALOGV("mURL : %s", mURL);
    ASSERT_NO_FATAL_FAILURE(encodeNFrames(
    ASSERT_NO_FATAL_FAILURE(encodeNFrames(
            mComponent, mQueueLock, mQueueCondition, mWorkQueue, mFlushedIndices, mLinearPool,
            mComponent, mQueueLock, mQueueCondition, mWorkQueue, mFlushedIndices, mLinearPool,
            eleStream, numFrames, samplesPerFrame, nChannels, nSampleRate, false, signalEOS));
            eleStream, numFrames, mSamplesPerFrame, mNumChannels, mSampleRate, false, signalEOS));


    // If EOS is not sent, sending empty input with EOS flag
    // If EOS is not sent, sending empty input with EOS flag
    if (!signalEOS) {
    if (!signalEOS) {
@@ -545,30 +532,17 @@ TEST_P(Codec2AudioEncHidlTest, FlushTest) {
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";


    mFlushedIndices.clear();
    mFlushedIndices.clear();
    int32_t nChannels;
    int32_t nSampleRate;
    int32_t samplesPerFrame;


    if (!getConfigParams(mComponent, &nChannels, &nSampleRate, &samplesPerFrame)) {
    ASSERT_TRUE(setupConfigParam(mComponent, mNumChannels, mSampleRate))
        std::cout << "Failed to get the config params for " << mComponentName << "\n";
            << "Unable to configure for channels: " << mNumChannels << " and sampling rate "
        std::cout << "[   WARN   ] Test Skipped \n";
            << mSampleRate;
        return;
    }

    if (!setupConfigParam(mComponent, nChannels, nSampleRate)) {
        std::cout << "[   WARN   ] Test Skipped \n";
        return;
    }
    char mURL[512];
    strcpy(mURL, sResourceDir.c_str());
    GetURLForComponent(mURL, nChannels, nSampleRate);


    ASSERT_EQ(mComponent->start(), C2_OK);
    ASSERT_EQ(mComponent->start(), C2_OK);


    std::ifstream eleStream;
    std::ifstream eleStream;
    uint32_t numFramesFlushed = 30;
    uint32_t numFramesFlushed = 30;
    uint32_t numFrames = 128;
    uint32_t numFrames = 128;
    eleStream.open(mURL, std::ifstream::binary);
    eleStream.open(mInputFile, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true);
    ASSERT_EQ(eleStream.is_open(), true);
    // flush
    // flush
    std::list<std::unique_ptr<C2Work>> flushedWork;
    std::list<std::unique_ptr<C2Work>> flushedWork;
@@ -577,10 +551,9 @@ TEST_P(Codec2AudioEncHidlTest, FlushTest) {
    ASSERT_NO_FATAL_FAILURE(
    ASSERT_NO_FATAL_FAILURE(
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
            verifyFlushOutput(flushedWork, mWorkQueue, mFlushedIndices, mQueueLock));
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);
    ALOGV("mURL : %s", mURL);
    ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
    ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                          mFlushedIndices, mLinearPool, eleStream, numFramesFlushed,
                                          mFlushedIndices, mLinearPool, eleStream, numFramesFlushed,
                                          samplesPerFrame, nChannels, nSampleRate));
                                          mSamplesPerFrame, mNumChannels, mSampleRate));
    err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    ASSERT_EQ(err, C2_OK);
    ASSERT_EQ(err, C2_OK);
    waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
    waitOnInputConsumption(mQueueLock, mQueueCondition, mWorkQueue,
@@ -590,8 +563,8 @@ TEST_P(Codec2AudioEncHidlTest, FlushTest) {
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);
    ASSERT_EQ(mWorkQueue.size(), MAX_INPUT_BUFFERS);
    ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
    ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                          mFlushedIndices, mLinearPool, eleStream,
                                          mFlushedIndices, mLinearPool, eleStream,
                                          numFrames - numFramesFlushed, samplesPerFrame, nChannels,
                                          numFrames - numFramesFlushed, mSamplesPerFrame,
                                          nSampleRate, true));
                                          mNumChannels, mSampleRate, true));
    eleStream.close();
    eleStream.close();
    err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    err = mComponent->flush(C2Component::FLUSH_COMPONENT, &flushedWork);
    ASSERT_EQ(err, C2_OK);
    ASSERT_EQ(err, C2_OK);
@@ -609,33 +582,20 @@ TEST_P(Codec2AudioEncHidlTest, MultiChannelCountTest) {
    description("Encodes input file for different channel count");
    description("Encodes input file for different channel count");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";


    int32_t nSampleRate;
    int32_t samplesPerFrame;
    int32_t nChannels;
    int32_t numFrames = 16;
    int32_t numFrames = 16;
    int32_t maxChannelCount = 8;
    int32_t maxChannelCount = 8;


    if (!getConfigParams(mComponent, &nChannels, &nSampleRate, &samplesPerFrame)) {
        std::cout << "Failed to get the config params for " << mComponentName << "\n";
        std::cout << "[   WARN   ] Test Skipped \n";
        return;
    }
    char mURL[512];
    strcpy(mURL, sResourceDir.c_str());
    GetURLForComponent(mURL, nChannels, nSampleRate);

    std::ifstream eleStream;
    std::ifstream eleStream;
    eleStream.open(mURL, std::ifstream::binary);
    eleStream.open(mInputFile, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true) << mURL << " file not found";
    ASSERT_EQ(eleStream.is_open(), true) << mInputFile << " file not found";
    ALOGV("mURL : %s", mURL);


    uint64_t prevOutputSize = 0u;
    uint64_t prevOutputSize = 0u;
    uint32_t prevChannelCount = 0u;
    uint32_t prevChannelCount = 0u;


    // Looping through the maximum number of channel count supported by encoder
    // Looping through the maximum number of channel count supported by encoder
    for (nChannels = 1; nChannels < maxChannelCount; nChannels++) {
    for (int32_t nChannels = 1; nChannels < maxChannelCount; nChannels++) {
        ALOGV("Configuring encoder %s  for channel count = %d", mComponentName.c_str(), nChannels);
        ALOGV("Configuring encoder %s  for channel count = %d", mComponentName.c_str(), nChannels);
        if (!setupConfigParam(mComponent, nChannels, nSampleRate)) {
        if (!setupConfigParam(mComponent, nChannels, mSampleRate)) {
            std::cout << "[   WARN   ] Test Skipped \n";
            std::cout << "[   WARN   ] Test Skipped \n";
            return;
            return;
        }
        }
@@ -656,9 +616,9 @@ TEST_P(Codec2AudioEncHidlTest, MultiChannelCountTest) {


        // To check if the input stream is sufficient to encode for the higher channel count
        // To check if the input stream is sufficient to encode for the higher channel count
        struct stat buf;
        struct stat buf;
        stat(mURL, &buf);
        stat(mInputFile.c_str(), &buf);
        size_t fileSize = buf.st_size;
        size_t fileSize = buf.st_size;
        int32_t bytesCount = (samplesPerFrame * nChannels * 2) * numFrames;
        int32_t bytesCount = (mSamplesPerFrame * nChannels * 2) * numFrames;
        if (fileSize < bytesCount) {
        if (fileSize < bytesCount) {
            std::cout << "[   WARN   ] Test Skipped for ChannelCount " << nChannels
            std::cout << "[   WARN   ] Test Skipped for ChannelCount " << nChannels
                      << " because of insufficient input data\n";
                      << " because of insufficient input data\n";
@@ -669,7 +629,7 @@ TEST_P(Codec2AudioEncHidlTest, MultiChannelCountTest) {


        ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
        ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                              mFlushedIndices, mLinearPool, eleStream, numFrames,
                                              mFlushedIndices, mLinearPool, eleStream, numFrames,
                                              samplesPerFrame, nChannels, nSampleRate));
                                              mSamplesPerFrame, nChannels, mSampleRate));


        // mDisableTest will be set if buffer was not fetched properly.
        // mDisableTest will be set if buffer was not fetched properly.
        // This may happen when config params is not proper but config succeeded
        // This may happen when config params is not proper but config succeeded
@@ -711,24 +671,11 @@ TEST_P(Codec2AudioEncHidlTest, MultiSampleRateTest) {
    description("Encodes input file for different SampleRate");
    description("Encodes input file for different SampleRate");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";


    int32_t nSampleRate;
    int32_t samplesPerFrame;
    int32_t nChannels;
    int32_t numFrames = 16;
    int32_t numFrames = 16;


    if (!getConfigParams(mComponent, &nChannels, &nSampleRate, &samplesPerFrame)) {
        std::cout << "Failed to get the config params for " << mComponentName << "\n";
        std::cout << "[   WARN   ] Test Skipped \n";
        return;
    }
    char mURL[512];
    strcpy(mURL, sResourceDir.c_str());
    GetURLForComponent(mURL, nChannels, nSampleRate);

    std::ifstream eleStream;
    std::ifstream eleStream;
    eleStream.open(mURL, std::ifstream::binary);
    eleStream.open(mInputFile, std::ifstream::binary);
    ASSERT_EQ(eleStream.is_open(), true) << mURL << " file not found";
    ASSERT_EQ(eleStream.is_open(), true) << mInputFile << " file not found";
    ALOGV("mURL : %s", mURL);


    int32_t sampleRateValues[] = {1000, 8000, 16000, 24000, 48000, 96000, 192000};
    int32_t sampleRateValues[] = {1000, 8000, 16000, 24000, 48000, 96000, 192000};


@@ -737,7 +684,7 @@ TEST_P(Codec2AudioEncHidlTest, MultiSampleRateTest) {


    for (int32_t nSampleRate : sampleRateValues) {
    for (int32_t nSampleRate : sampleRateValues) {
        ALOGV("Configuring encoder %s  for SampleRate = %d", mComponentName.c_str(), nSampleRate);
        ALOGV("Configuring encoder %s  for SampleRate = %d", mComponentName.c_str(), nSampleRate);
        if (!setupConfigParam(mComponent, nChannels, nSampleRate)) {
        if (!setupConfigParam(mComponent, mNumChannels, nSampleRate)) {
            std::cout << "[   WARN   ] Test Skipped \n";
            std::cout << "[   WARN   ] Test Skipped \n";
            return;
            return;
        }
        }
@@ -759,9 +706,9 @@ TEST_P(Codec2AudioEncHidlTest, MultiSampleRateTest) {


        // To check if the input stream is sufficient to encode for the higher SampleRate
        // To check if the input stream is sufficient to encode for the higher SampleRate
        struct stat buf;
        struct stat buf;
        stat(mURL, &buf);
        stat(mInputFile.c_str(), &buf);
        size_t fileSize = buf.st_size;
        size_t fileSize = buf.st_size;
        int32_t bytesCount = (samplesPerFrame * nChannels * 2) * numFrames;
        int32_t bytesCount = (mSamplesPerFrame * mNumChannels * 2) * numFrames;
        if (fileSize < bytesCount) {
        if (fileSize < bytesCount) {
            std::cout << "[   WARN   ] Test Skipped for SampleRate " << nSampleRate
            std::cout << "[   WARN   ] Test Skipped for SampleRate " << nSampleRate
                      << " because of insufficient input data\n";
                      << " because of insufficient input data\n";
@@ -772,7 +719,7 @@ TEST_P(Codec2AudioEncHidlTest, MultiSampleRateTest) {


        ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
        ASSERT_NO_FATAL_FAILURE(encodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
                                              mFlushedIndices, mLinearPool, eleStream, numFrames,
                                              mFlushedIndices, mLinearPool, eleStream, numFrames,
                                              samplesPerFrame, nChannels, nSampleRate));
                                              mSamplesPerFrame, mNumChannels, nSampleRate));


        // mDisableTest will be set if buffer was not fetched properly.
        // mDisableTest will be set if buffer was not fetched properly.
        // This may happen when config params is not proper but config succeeded
        // This may happen when config params is not proper but config succeeded
+59 −88

File changed.

Preview size limit exceeded, changes collapsed.

+17 −32

File changed.

Preview size limit exceeded, changes collapsed.