History

parse only add and UT

huili2 committed 11 years ago

Commit b231e3f1 parent 53c14dc13 files · +607 −60Browse files

Showing the changes to test/api/encode_decode_api_test.cpp (1 of 13 files). Show all

Unified · Split

test/api/encode_decode_api_test.cpp+174−1
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 #include "BaseDecoderTest.h"
66 #include "BaseEncoderTest.h"
77 #include "wels_common_defs.h"
8+#include "utils/HashFunctions.h"
89 #include <string>
910 #include <vector>
1011 using namespace WelsCommon;
@@ -68,6 +69,8 @@ static void TestOutPutTrace (void* ctx, int level, const char* string) { · 57 unmodified lines
6869
6970 class EncodeDecodeTestBase : public ::testing::TestWithParam<EncodeDecodeFileParamBase>,
7071 public BaseEncoderTest, public BaseDecoderTest {
72+ public:
73+ uint8_t iRandValue;
7174 public:
7275 virtual void SetUp() {
7376 BaseEncoderTest::SetUp();
@@ -103,6 +106,26 @@ class EncodeDecodeTestBase : public ::testing::TestWithParam<EncodeDecodeFilePar · 29 unmodified lines
103106
104107
105108 }
109+ virtual void prepareEncDecParam (const EncodeDecodeFileParamBase EncDecFileParam) {
110+ //for encoder
111+ //I420: 1(Y) + 1/4(U) + 1/4(V)
112+ int frameSize = EncDecFileParam.width * EncDecFileParam.height * 3 / 2;
113+ buf_.SetLength (frameSize);
114+ ASSERT_TRUE (buf_.Length() == (size_t)frameSize);
115+ memset (&EncPic, 0, sizeof (SSourcePicture));
116+ EncPic.iPicWidth = EncDecFileParam.width;
117+ EncPic.iPicHeight = EncDecFileParam.height;
118+ EncPic.iColorFormat = videoFormatI420;
119+ EncPic.iStride[0] = EncPic.iPicWidth;
120+ EncPic.iStride[1] = EncPic.iStride[2] = EncPic.iPicWidth >> 1;
121+ EncPic.pData[0] = buf_.data();
122+ EncPic.pData[1] = EncPic.pData[0] + EncDecFileParam.width * EncDecFileParam.height;
123+ EncPic.pData[2] = EncPic.pData[1] + (EncDecFileParam.width * EncDecFileParam.height >> 2);
124+ //for decoder
125+ memset (&info, 0, sizeof (SFrameBSInfo));
126+ //set a fixed random value
127+ iRandValue = rand() % 256;
128+ }
106129
107130 virtual void encToDecData (const SFrameBSInfo& info, int& len) {
108131 len = 0;
@@ -1983,7 +2006,6 @@ TEST_F (EncodeDecodeTestAPI, Engine_SVC_Switch_P) { · 1874 unmodified lines
19832006 }
19842007 }
19852008
1986−
19872009 TEST_F (EncodeDecodeTestAPI, SetOptionEncParamExt) {
19882010 int iWidth = (((rand() % MAX_WIDTH) >> 1) + 16) << 1;
19892011 int iHeight = (((rand() % MAX_HEIGHT) >> 1) + 16) << 1;
@@ -2237,3 +2259,154 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 247 unmodified lines
22372259 #endif
22382260
22392261 }
2262+
2263+const uint32_t kiTotalLayer = 3; //DO NOT CHANGE!
2264+const uint32_t kiSliceNum = 2; //DO NOT CHANGE!
2265+const uint32_t kiWidth = 160; //DO NOT CHANGE!
2266+const uint32_t kiHeight = 96; //DO NOT CHANGE!
2267+const uint32_t kiFrameRate = 12; //DO NOT CHANGE!
2268+const uint32_t kiFrameNum = 100; //DO NOT CHANGE!
2269+const uint32_t kiMaxBsSize = 10000000; //DO NOT CHANGE!
2270+const char* pHashStr[] = { //DO NOT CHANGE!
2271+ "c58322f886a3ba958c6f60b46b98f67b5d860866",
2272+ "f2799e1e5f6e33c6274f4e1f6273c721475492d0",
2273+ "8f0fafeaa2746e04d42fb17104efb61c9dbd1a6f"
2274+};
2275+
2276+class DecodeParseAPI : public EncodeDecodeTestBase {
2277+ public:
2278+ void SetUp() {
2279+ SHA1Reset (&ctx_);
2280+ EncodeDecodeTestBase::SetUp();
2281+
2282+ if (decoder_)
2283+ decoder_->Uninitialize();
2284+ SDecodingParam decParam;
2285+ memset (&decParam, 0, sizeof (SDecodingParam));
2286+ decParam.eOutputColorFormat = videoFormatI420;
2287+ decParam.uiTargetDqLayer = UCHAR_MAX;
2288+ decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
2289+ decParam.bParseOnly = true;
2290+ decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
2291+
2292+ int rv = decoder_->Initialize (&decParam);
2293+ ASSERT_EQ (0, rv);
2294+ memset (&BsInfo_, 0, sizeof (SParserBsInfo));
2295+ BsInfo_.pDstBuff = NULL;
2296+ BsInfo_.pDstBuff = new unsigned char [kiMaxBsSize];
2297+ ASSERT_TRUE (BsInfo_.pDstBuff != NULL);
2298+ fYuv_ = fopen ("./res/CiscoVT2people_160x96_6fps.yuv", "rb");
2299+ ASSERT_TRUE (fYuv_ != NULL);
2300+ iWidth_ = kiWidth;
2301+ iHeight_ = kiHeight;
2302+ }
2303+ void TearDown() {
2304+ EncodeDecodeTestBase::TearDown();
2305+ if (BsInfo_.pDstBuff) {
2306+ delete[] BsInfo_.pDstBuff;
2307+ BsInfo_.pDstBuff = NULL;
2308+ }
2309+ fclose (fYuv_);
2310+ }
2311+
2312+ void prepareEncDecParam (const EncodeDecodeFileParamBase p) {
2313+ EncodeDecodeTestBase::prepareEncDecParam (p);
2314+ unsigned char* pTmpPtr = BsInfo_.pDstBuff; //store for restore
2315+ memset (&BsInfo_, 0, sizeof (SParserBsInfo));
2316+ BsInfo_.pDstBuff = pTmpPtr;
2317+ }
2318+
2319+ void EncodeOneFrame (int iIdx) {
2320+ int iFrameSize = iWidth_ * iHeight_ * 3 / 2;
2321+ int iSize = fread (buf_.data(), sizeof (char), iFrameSize, fYuv_);
2322+ if (feof (fYuv_) || iSize != iFrameSize) {
2323+ rewind (fYuv_);
2324+ iSize = fread (buf_.data(), sizeof (char), iFrameSize, fYuv_);
2325+ ASSERT_TRUE (iSize == iFrameSize);
2326+ }
2327+ int rv = encoder_->EncodeFrame (&EncPic, &info);
2328+ ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnkonwReason);
2329+ }
2330+
2331+ protected:
2332+ SParserBsInfo BsInfo_;
2333+ FILE* fYuv_;
2334+ int iWidth_;
2335+ int iHeight_;
2336+ SHA1Context ctx_;
2337+};
2338+
2339+//#define DEBUG_FILE_SAVE
2340+TEST_F (DecodeParseAPI, ParseOnly_General) {
2341+ EncodeDecodeFileParamBase p;
2342+ p.width = iWidth_;
2343+ p.height = iHeight_;
2344+ p.frameRate = kiFrameRate;
2345+ p.numframes = kiFrameNum;
2346+ prepareParam (kiTotalLayer, kiSliceNum, p.width, p.height, p.frameRate);
2347+ param_.iSpatialLayerNum = kiTotalLayer;
2348+ encoder_->Uninitialize();
2349+ int rv = encoder_->InitializeExt (&param_);
2350+ ASSERT_TRUE (rv == 0);
2351+ int32_t iTraceLevel = WELS_LOG_QUIET;
2352+ encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2353+ decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
2354+ uint32_t uiTargetLayerId = rand() % kiTotalLayer; //run only once
2355+#ifdef DEBUG_FILE_SAVE
2356+ FILE* fDec = fopen ("output.264", "wb");
2357+ FILE* fEnc = fopen ("enc.264", "wb");
2358+ FILE* fExtract = fopen ("extract.264", "wb");
2359+#endif
2360+ if (uiTargetLayerId < kiTotalLayer) { //should always be true
2361+ //Start for enc
2362+ int iLen = 0;
2363+ prepareEncDecParam (p);
2364+ int iFrame = 0;
2365+
2366+ while (iFrame < p.numframes) {
2367+ //encode
2368+ EncodeOneFrame (iFrame);
2369+ //extract target layer data
2370+ encToDecData (info, iLen);
2371+#ifdef DEBUG_FILE_SAVE
2372+ fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fEnc);
2373+#endif
2374+ ExtractDidNal (&info, iLen, &m_SLostSim, uiTargetLayerId);
2375+#ifdef DEBUG_FILE_SAVE
2376+ fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fExtract);
2377+#endif
2378+ //parseonly
2379+ //BsInfo_.pDstBuff = new unsigned char [1000000];
2380+ rv = decoder_->DecodeParser (info.sLayerInfo[0].pBsBuf, iLen, &BsInfo_);
2381+ EXPECT_TRUE (rv == 0);
2382+ EXPECT_TRUE (BsInfo_.iNalNum == 0);
2383+ rv = decoder_->DecodeParser (NULL, 0, &BsInfo_);
2384+ EXPECT_TRUE (rv == 0);
2385+ EXPECT_TRUE (BsInfo_.iNalNum != 0);
2386+ //get final output bs
2387+ iLen = 0;
2388+ int i = 0;
2389+ while (i < BsInfo_.iNalNum) {
2390+ iLen += BsInfo_.iNalLenInByte[i];
2391+ i++;
2392+ }
2393+#ifdef DEBUG_FILE_SAVE
2394+ fwrite (BsInfo_.pDstBuff, iLen, 1, fDec);
2395+#endif
2396+ SHA1Input (&ctx_, BsInfo_.pDstBuff, iLen);
2397+ iFrame++;
2398+ }
2399+ //calculate final SHA1 value
2400+ unsigned char digest[SHA_DIGEST_LENGTH];
2401+ SHA1Result (&ctx_, digest);
2402+ if (!HasFatalFailure()) {
2403+ CompareHash (digest, pHashStr[uiTargetLayerId]);
2404+ }
2405+ } //while
2406+#ifdef DEBUG_FILE_SAVE
2407+ fclose (fEnc);
2408+ fclose (fExtract);
2409+ fclose (fDec);
2410+#endif
2411+}
2412+

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t