History

add UT for set MaxNalUnitLen ignore the cases: 2 MBs in one picture, and the multithreads case, enable them when code is ready

dong zhang committed 11 years ago

Commit d3b2be51 parent 442230a1 file · +131 −14Browse files

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

Unified · Split

test/api/encode_decode_api_test.cpp+131−14
@@ -68,8 +68,7 @@ static void TestOutPutTrace (void* ctx, int level, const char* string) { · 67 unmodified lines
6868 EXPECT_LE (level, pTraceUnit->iTarLevel);
6969 }
7070
71−class EncodeDecodeTestBase : public ::testing::TestWithParam<EncodeDecodeFileParamBase>,
72− public BaseEncoderTest, public BaseDecoderTest {
71+class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest {
7372 public:
7473 uint8_t iRandValue;
7574 public:
@@ -167,7 +166,7 @@ class EncodeDecodeTestBase : public ::testing::TestWithParam<EncodeDecodeFilePar · 91 unmodified lines
167166 STraceUnit* pTraceInfo;
168167 };
169168
170−class EncodeDecodeTestAPI : public EncodeDecodeTestBase {
169+class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase {
171170 public:
172171 uint8_t iRandValue;
173172 public:
@@ -227,7 +226,17 @@ class EncodeDecodeTestAPI : public EncodeDecodeTestBase { · 53 unmodified lines
227226 }
228227 };
229228
230−void EncodeDecodeTestAPI::InitialEncDec (int iWidth, int iHeight) {
229+class EncodeDecodeTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestAPIBase {
230+ void SetUp() {
231+ EncodeDecodeTestAPIBase::SetUp();
232+ }
233+
234+ void TearDown() {
235+ EncodeDecodeTestAPIBase::TearDown();
236+ }
237+};
238+
239+void EncodeDecodeTestAPIBase::InitialEncDec (int iWidth, int iHeight) {
231240
232241 // for encoder
233242 // I420: 1(Y) + 1/4(U) + 1/4(V)
@@ -253,7 +262,7 @@ void EncodeDecodeTestAPI::InitialEncDec (int iWidth, int iHeight) { · 19 unmodified lines
253262 iRandValue = rand() % 256;
254263 }
255264
256−void EncodeDecodeTestAPI::RandomParamExtCombination() {
265+void EncodeDecodeTestAPIBase::RandomParamExtCombination() {
257266
258267 param_.iPicWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
259268 param_.iPicHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT);
@@ -342,7 +351,7 @@ void EncodeDecodeTestAPI::RandomParamExtCombination() { · 82 unmodified lines
342351 }
343352 }
344353
345−void EncodeDecodeTestAPI::ValidateParamExtCombination() {
354+void EncodeDecodeTestAPIBase::ValidateParamExtCombination() {
346355
347356 bool bDynSliceModeFlag = false;
348357 unsigned int uiGOPSize = 0;
@@ -451,7 +460,7 @@ void EncodeDecodeTestAPI::ValidateParamExtCombination() { · 102 unmodified lines
451460 }
452461
453462
454−void EncodeDecodeTestAPI::SliceParamValidationForMode2 (int iSpatialIdx) {
463+void EncodeDecodeTestAPIBase::SliceParamValidationForMode2 (int iSpatialIdx) {
455464
456465 unsigned int uiMbWidth = 0;
457466 unsigned int uiMbHeight = 0;
@@ -488,7 +497,7 @@ void EncodeDecodeTestAPI::SliceParamValidationForMode2 (int iSpatialIdx) { · 30 unmodified lines
488497 param_.sSpatialLayers[iSpatialIdx].sSliceCfg.sSliceArgument.uiSliceNum = uiActualSliceCount;
489498
490499 }
491−void EncodeDecodeTestAPI::SliceParamValidationForMode3 (int iSpatialIdx) {
500+void EncodeDecodeTestAPIBase::SliceParamValidationForMode3 (int iSpatialIdx) {
492501
493502 unsigned int uiMbHeight = 0;
494503
@@ -501,7 +510,7 @@ void EncodeDecodeTestAPI::SliceParamValidationForMode3 (int iSpatialIdx) { · 6 unmodified lines
501510
502511 }
503512
504−void EncodeDecodeTestAPI::SliceParamValidationForMode4() {
513+void EncodeDecodeTestAPIBase::SliceParamValidationForMode4() {
505514 //slice mode of all spatial layer should be set as SM_DYN_SLICE
506515 for (int iSpatialIdx = 0; iSpatialIdx < param_.iSpatialLayerNum; iSpatialIdx++) {
507516 param_.sSpatialLayers[iSpatialIdx].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 600;
@@ -1443,7 +1452,7 @@ TEST_P (EncodeDecodeTestAPI, SetOption_Trace_NULL) { · 935 unmodified lines
14431452 }
14441453 }
14451454
1446−INSTANTIATE_TEST_CASE_P (EncodeDecodeTestBase, EncodeDecodeTestAPI,
1455+INSTANTIATE_TEST_CASE_P (EncodeDecodeTestAPIBase, EncodeDecodeTestAPI,
14471456 ::testing::ValuesIn (kFileParamArray));
14481457
14491458 TEST_P (EncodeDecodeTestAPI, SetOptionECIDC_GeneralSliceChange) {
@@ -1531,6 +1540,7 @@ TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificFrameChange) { · 81 unmodified lines
15311540 uint32_t uiGet;
15321541 EncodeDecodeFileParamBase p = kFileParamArray[0];
15331542 prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, &param_);
1543+
15341544 param_.iSpatialLayerNum = 1;
15351545 encoder_->Uninitialize();
15361546 int rv = encoder_->InitializeExt (&param_);
@@ -1551,7 +1561,6 @@ TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificFrameChange) { · 14 unmodified lines
15511561 int iIdx = 0;
15521562 int len = 0;
15531563 unsigned char* pData[3] = { NULL };
1554−
15551564 InitialEncDec (p.width, p.height);
15561565 //Frame 0: IDR, EC_IDC=DISABLE, loss = 0
15571566 EncodeOneFrame (1);
@@ -1656,7 +1665,6 @@ TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificFrameChange) { · 98 unmodified lines
16561665 EXPECT_TRUE (rv != 0); //not sure if previous data drop would be detected in construction
16571666 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1);
16581667 iIdx++;
1659−
16601668 }
16611669
16621670 //This case contain 2 slices per picture for IDR loss
@@ -2165,7 +2173,7 @@ TEST_F (EncodeDecodeTestAPI, SetOptionEncParamExt) { · 502 unmodified lines
21652173 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
21662174 }
21672175
2168−class DecodeCrashTestAPI : public EncodeDecodeTestBase {
2176+class DecodeCrashTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase {
21692177 public:
21702178 uint8_t iRandValue;
21712179 public:
@@ -2386,7 +2394,7 @@ const char* pHashStr[] = { //DO NOT CHANGE! · 214 unmodified lines
23862394 "eb9d853b7daec03052c4850027ac94adc84c3a7e"
23872395 };
23882396
2389−class DecodeParseAPI : public EncodeDecodeTestBase {
2397+class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase {
23902398 public:
23912399 void SetUp() {
23922400 SHA1Reset (&ctx_);
@@ -3242,3 +3250,112 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVC) { · 849 unmodified lines
32423250 }
32433251 }
32443252
3253+struct EncodeOptionParam {
3254+ int iCaseId;
3255+ int iNumframes;
3256+ int iWidth;
3257+ int iHeight;
3258+ int iQp;
3259+ int uiMaxNalLen;
3260+ float fFramerate;
3261+ int iThreads;
3262+};
3263+
3264+static const EncodeOptionParam kOptionParamArray[] = {
3265+ {0, 30, 600, 460, 1, 400, 15.0, 1},
3266+ {1, 30, 340, 96, 24, 1000, 30.0, 1},
3267+ {2, 30, 140, 196, 51, 500, 7.5, 1},
3268+ {3, 30, 110, 296, 50, 500, 7.5, 1},
3269+ {4, 30, 104, 416, 44, 500, 7.5, 1},
3270+ {5, 30, 16, 16, 2, 500, 7.5, 1},
3271+ {6, 30, 32, 16, 2, 500, 7.5, 1},
3272+ {7, 30, 600, 460, 1, 400, 15.0, 4},
3273+ {8, 30, 340, 96, 24, 1000, 30.0, 2},
3274+ {9, 30, 140, 196, 51, 500, 7.5, 3},
3275+ {10, 30, 110, 296, 50, 500, 7.5, 2},
3276+ {11, 30, 104, 416, 44, 500, 7.5, 2},
3277+ {12, 30, 16, 16, 2, 500, 7.5, 3},
3278+ {13, 30, 32, 16, 2, 500, 7.5, 3},
3279+};
3280+
3281+class EncodeTestAPI : public ::testing::TestWithParam<EncodeOptionParam>, public ::EncodeDecodeTestAPIBase {
3282+ public:
3283+ void SetUp() {
3284+ EncodeDecodeTestAPIBase::SetUp();
3285+ }
3286+
3287+ void TearDown() {
3288+ EncodeDecodeTestAPIBase::TearDown();
3289+ }
3290+ void EncodeOneFrameAllRandom (int iCheckTypeIndex) {
3291+ int frameSize = EncPic.iPicWidth * EncPic.iPicHeight * 3 / 2;
3292+ uint8_t* ptr = buf_.data();
3293+ for (int i = 0; i < frameSize; i++) {
3294+ ptr[i] = rand() % 256;
3295+ }
3296+ int rv = encoder_->EncodeFrame (&EncPic, &info);
3297+ if (0 == iCheckTypeIndex)
3298+ ASSERT_TRUE (rv == cmResultSuccess);
3299+ else if (1 == iCheckTypeIndex)
3300+ ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnkonwReason);
3301+ }
3302+};
3303+
3304+INSTANTIATE_TEST_CASE_P (EncodeDecodeTestAPIBase, EncodeTestAPI,
3305+ ::testing::ValuesIn (kOptionParamArray));
3306+
3307+TEST_P (EncodeTestAPI, SetEncOptionNalSize) {
3308+ EncodeOptionParam p = GetParam();
3309+ memset (&param_, 0, sizeof (SEncParamExt));
3310+ encoder_->GetDefaultParams (&param_);
3311+ param_.uiMaxNalSize = p.uiMaxNalLen;
3312+ param_.iTemporalLayerNum = (rand() % 4) + 1;
3313+ param_.iSpatialLayerNum = 1;
3314+ param_.iUsageType = CAMERA_VIDEO_REAL_TIME;
3315+ param_.iPicWidth = p.iWidth;
3316+ param_.iPicHeight = p.iHeight;
3317+ param_.fMaxFrameRate = p.fFramerate;
3318+ param_.iRCMode = RC_OFF_MODE; //rc off
3319+ param_.iMultipleThreadIdc = p.iThreads;
3320+ param_.iNumRefFrame = AUTO_REF_PIC_COUNT;
3321+ param_.sSpatialLayers[0].iVideoWidth = p.iWidth ;
3322+ param_.sSpatialLayers[0].iVideoHeight = p.iHeight;
3323+ param_.sSpatialLayers[0].fFrameRate = p.fFramerate;
3324+ param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_DYN_SLICE;
3325+
3326+ encoder_->Uninitialize();
3327+ int rv = encoder_->InitializeExt (&param_);
3328+ ASSERT_TRUE (rv == cmResultSuccess);
3329+ InitialEncDec (p.iWidth, p.iHeight);
3330+
3331+ int32_t iTraceLevel = WELS_LOG_QUIET;
3332+ encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
3333+ decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
3334+ int32_t iSpsPpsIdAddition = 1;
3335+ encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition);
3336+ int32_t iIDRPeriod = (int32_t) pow (2.0f, (param_.iTemporalLayerNum - 1)) * ((rand() % 5) + 1);
3337+ encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod);
3338+ int iIdx = 0;
3339+ while (iIdx <= p.iNumframes) {
3340+ EncodeOneFrameAllRandom (1);
3341+ int iLayer = 0;
3342+ while (iLayer < info.iLayerNum) {
3343+ SLayerBSInfo* pLayerBsInfo = &info.sLayerInfo[iLayer];
3344+ if (pLayerBsInfo != NULL) {
3345+ int iNalIdx = WELS_MAX (pLayerBsInfo->iNalCount - 2, 0); // ignore last slice under single slice mode
3346+ do {
3347+ if (p.iCaseId <
3348+ 6) { // ignore the case that 2 MBs in one picture, and the multithreads case, enable them when code is ready
3349+ ASSERT_GE (((int)param_.uiMaxNalSize), pLayerBsInfo->pNalLengthInByte[iNalIdx]);
3350+ }
3351+ -- iNalIdx;
3352+ } while (iNalIdx >= 0);
3353+ }
3354+ ++ iLayer;
3355+ }
3356+ iIdx++;
3357+ }
3358+}
3359+
3360+
3361+

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