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

Commit 2a668731 authored by Snehal N Bhamare's avatar Snehal N Bhamare Committed by Pawin Vongmasa
Browse files

VTS: Refactor Video and Audio decoder test functions

Move info file handling and Audio Decoder's timestamp
validation to a function

Bug: 154736583
Test: atest VtsHalMediaC2V1_0TargetAudioDecTest \
  VtsHalMediaC2V1_0TargetVideoDecTest

Change-Id: Iead1be0228896b10d92d49ea27a9692d0745046b
parent 48237318
Loading
Loading
Loading
Loading
+47 −77
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;

@@ -122,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;
@@ -461,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");
@@ -497,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());
@@ -507,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;
@@ -538,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,
@@ -562,30 +571,9 @@ 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);
@@ -597,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;
@@ -633,12 +611,14 @@ 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,
@@ -698,26 +678,15 @@ TEST_P(Codec2AudioDecHidlTest, FlushTest) {
    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;
@@ -731,6 +700,7 @@ TEST_P(Codec2AudioDecHidlTest, FlushTest) {
    }
    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);
    // Decode 128 frames and flush. here 128 is chosen to ensure there is a key
@@ -767,7 +737,7 @@ TEST_P(Codec2AudioDecHidlTest, FlushTest) {
    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) {
+31 −1
Original line number Diff line number Diff line
@@ -161,3 +161,33 @@ const std::vector<std::tuple<std::string, std::string>>& getTestParameters(

    return parameters;
}

// Populate Info vector and return number of CSDs
int32_t populateInfoVector(std::string info, android::Vector<FrameInfo>* frameInfo,
                           bool timestampDevTest, std::list<uint64_t>* timestampUslist) {
    std::ifstream eleInfo;
    eleInfo.open(info);
    if (!eleInfo.is_open()) {
        ALOGE("Can't open info file");
        return -1;
    }
    int32_t numCsds = 0;
    int32_t bytesCount = 0;
    uint32_t flags = 0;
    uint32_t timestamp = 0;
    while (1) {
        if (!(eleInfo >> bytesCount)) break;
        eleInfo >> flags;
        eleInfo >> timestamp;
        bool codecConfig = flags ? ((1 << (flags - 1)) & C2FrameData::FLAG_CODEC_CONFIG) != 0 : 0;
        if (codecConfig) numCsds++;
        bool nonDisplayFrame = ((flags & FLAG_NON_DISPLAY_FRAME) != 0);
        if (timestampDevTest && !codecConfig && !nonDisplayFrame) {
            timestampUslist->push_back(timestamp);
        }
        frameInfo->push_back({bytesCount, flags, timestamp});
    }
    ALOGV("numCsds : %d", numCsds);
    eleInfo.close();
    return numCsds;
}
+11 −0
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@
#include <gtest/gtest.h>
#include <hidl/HidlSupport.h>
#include <chrono>
#include <fstream>

#define FLAG_NON_DISPLAY_FRAME (1 << 4)
#define MAX_RETRY 20
#define TIME_OUT 400ms
#define MAX_INPUT_BUFFERS 8
@@ -39,6 +41,12 @@ using namespace ::std::chrono;

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

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

/*
 * Handle Callback functions onWorkDone(), onTripped(),
 * onError(), onDeath(), onFramesRendered()
@@ -123,4 +131,7 @@ void workDone(const std::shared_ptr<android::Codec2Client::Component>& component

int64_t getNowUs();

int32_t populateInfoVector(std::string info, android::Vector<FrameInfo>* frameInfo,
                           bool timestampDevTest, std::list<uint64_t>* timestampUslist);

#endif  // MEDIA_C2_HIDL_TEST_COMMON_H
+22 −56
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <stdio.h>
#include <fstream>

#include <C2AllocatorIon.h>
#include <C2Buffer.h>
@@ -39,12 +38,6 @@ using android::C2AllocatorIon;
#include "media_c2_hidl_test_common.h"
#include "media_c2_video_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;

@@ -467,38 +460,27 @@ TEST_P(Codec2VideoDecDecodeTest, DecodeTest) {

    uint32_t streamIndex = std::stoi(std::get<2>(GetParam()));
    bool signalEOS = !std::get<2>(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());

    GetURLForComponent(mCompName, mURL, info, streamIndex);

    eleInfo.open(info);
    ASSERT_EQ(eleInfo.is_open(), true) << mURL << " - file not found";
    android::Vector<FrameInfo> Info;
    int bytesCount = 0;
    uint32_t flags = 0;
    uint32_t timestamp = 0;
    mTimestampDevTest = true;
    mFlushedIndices.clear();
    mTimestampUslist.clear();
    while (1) {
        if (!(eleInfo >> bytesCount)) break;
        eleInfo >> flags;
        eleInfo >> timestamp;
        bool codecConfig = flags ? ((1 << (flags - 1)) & C2FrameData::FLAG_CODEC_CONFIG) != 0 : 0;
        bool nonDisplayFrame = ((flags & FLAG_NON_DISPLAY_FRAME) != 0);
        if (mTimestampDevTest && !codecConfig && !nonDisplayFrame)
            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;

    ASSERT_EQ(mComponent->start(), C2_OK);
    // Reset total no of frames received
    mFramesReceived = 0;
    mTimestampUs = 0;
    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,
@@ -645,26 +627,16 @@ TEST_P(Codec2VideoDecHidlTest, 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;

    uint32_t flags = 0;
    for (size_t i = 0; i < MAX_ITERATIONS; i++) {
        ASSERT_EQ(mComponent->start(), C2_OK);

@@ -677,6 +649,8 @@ TEST_P(Codec2VideoDecHidlTest, ThumbnailTest) {
            if (Info[j].flags) flags = 1u << (Info[j].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,
@@ -738,29 +712,21 @@ TEST_P(Codec2VideoDecHidlTest, FlushTest) {
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";
    typedef std::unique_lock<std::mutex> ULock;
    ASSERT_EQ(mComponent->start(), C2_OK);

    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;

    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
@@ -796,7 +762,7 @@ TEST_P(Codec2VideoDecHidlTest, FlushTest) {
    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) {
+0 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
#define ENC_DEFAULT_FRAME_WIDTH 352
#define ENC_DEFAULT_FRAME_HEIGHT 288
#define MAX_ITERATIONS 128
#define FLAG_NON_DISPLAY_FRAME (1 << 4)

#define ALIGN(_sz, _align) ((_sz + (_align - 1)) & ~(_align - 1))