Showing the changes to test/api/encode_decode_api_test.cpp (1 of 1 file). Show all
Unified · Split
| @@ -68,8 +68,7 @@ static void TestOutPutTrace (void* ctx, int level, const char* string) { · 67 unmodified lines | |||
| 68 | EXPECT_LE (level, pTraceUnit->iTarLevel); | 68 | EXPECT_LE (level, pTraceUnit->iTarLevel); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | class EncodeDecodeTestBase : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, | 71 | class EncodeDecodeTestBase : public BaseEncoderTest, public BaseDecoderTest { |
| 72 | public BaseEncoderTest, public BaseDecoderTest { | ||
| 73 | public: | 72 | public: |
| 74 | uint8_t iRandValue; | 73 | uint8_t iRandValue; |
| 75 | public: | 74 | public: |
| @@ -167,7 +166,7 @@ class EncodeDecodeTestBase : public ::testing::TestWithParam<EncodeDecodeFilePar · 91 unmodified lines | |||
| 167 | STraceUnit* pTraceInfo; | 166 | STraceUnit* pTraceInfo; |
| 168 | }; | 167 | }; |
| 169 | 168 | ||
| 170 | class EncodeDecodeTestAPI : public EncodeDecodeTestBase { | 169 | class EncodeDecodeTestAPIBase : public EncodeDecodeTestBase { |
| 171 | public: | 170 | public: |
| 172 | uint8_t iRandValue; | 171 | uint8_t iRandValue; |
| 173 | public: | 172 | public: |
| @@ -227,7 +226,17 @@ class EncodeDecodeTestAPI : public EncodeDecodeTestBase { · 53 unmodified lines | |||
| 227 | } | 226 | } |
| 228 | }; | 227 | }; |
| 229 | 228 | ||
| 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) { | ||
| 231 | 240 | ||
| 232 | // for encoder | 241 | // for encoder |
| 233 | // I420: 1(Y) + 1/4(U) + 1/4(V) | 242 | // I420: 1(Y) + 1/4(U) + 1/4(V) |
| @@ -253,7 +262,7 @@ void EncodeDecodeTestAPI::InitialEncDec (int iWidth, int iHeight) { · 19 unmodified lines | |||
| 253 | iRandValue = rand() % 256; | 262 | iRandValue = rand() % 256; |
| 254 | } | 263 | } |
| 255 | 264 | ||
| 256 | void EncodeDecodeTestAPI::RandomParamExtCombination() { | 265 | void EncodeDecodeTestAPIBase::RandomParamExtCombination() { |
| 257 | 266 | ||
| 258 | param_.iPicWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH); | 267 | param_.iPicWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH); |
| 259 | param_.iPicHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT); | 268 | param_.iPicHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT); |
| @@ -342,7 +351,7 @@ void EncodeDecodeTestAPI::RandomParamExtCombination() { · 82 unmodified lines | |||
| 342 | } | 351 | } |
| 343 | } | 352 | } |
| 344 | 353 | ||
| 345 | void EncodeDecodeTestAPI::ValidateParamExtCombination() { | 354 | void EncodeDecodeTestAPIBase::ValidateParamExtCombination() { |
| 346 | 355 | ||
| 347 | bool bDynSliceModeFlag = false; | 356 | bool bDynSliceModeFlag = false; |
| 348 | unsigned int uiGOPSize = 0; | 357 | unsigned int uiGOPSize = 0; |
| @@ -451,7 +460,7 @@ void EncodeDecodeTestAPI::ValidateParamExtCombination() { · 102 unmodified lines | |||
| 451 | } | 460 | } |
| 452 | 461 | ||
| 453 | 462 | ||
| 454 | void EncodeDecodeTestAPI::SliceParamValidationForMode2 (int iSpatialIdx) { | 463 | void EncodeDecodeTestAPIBase::SliceParamValidationForMode2 (int iSpatialIdx) { |
| 455 | 464 | ||
| 456 | unsigned int uiMbWidth = 0; | 465 | unsigned int uiMbWidth = 0; |
| 457 | unsigned int uiMbHeight = 0; | 466 | unsigned int uiMbHeight = 0; |
| @@ -488,7 +497,7 @@ void EncodeDecodeTestAPI::SliceParamValidationForMode2 (int iSpatialIdx) { · 30 unmodified lines | |||
| 488 | param_.sSpatialLayers[iSpatialIdx].sSliceCfg.sSliceArgument.uiSliceNum = uiActualSliceCount; | 497 | param_.sSpatialLayers[iSpatialIdx].sSliceCfg.sSliceArgument.uiSliceNum = uiActualSliceCount; |
| 489 | 498 | ||
| 490 | } | 499 | } |
| 491 | void EncodeDecodeTestAPI::SliceParamValidationForMode3 (int iSpatialIdx) { | 500 | void EncodeDecodeTestAPIBase::SliceParamValidationForMode3 (int iSpatialIdx) { |
| 492 | 501 | ||
| 493 | unsigned int uiMbHeight = 0; | 502 | unsigned int uiMbHeight = 0; |
| 494 | 503 | ||
| @@ -501,7 +510,7 @@ void EncodeDecodeTestAPI::SliceParamValidationForMode3 (int iSpatialIdx) { · 6 unmodified lines | |||
| 501 | 510 | ||
| 502 | } | 511 | } |
| 503 | 512 | ||
| 504 | void EncodeDecodeTestAPI::SliceParamValidationForMode4() { | 513 | void EncodeDecodeTestAPIBase::SliceParamValidationForMode4() { |
| 505 | //slice mode of all spatial layer should be set as SM_DYN_SLICE | 514 | //slice mode of all spatial layer should be set as SM_DYN_SLICE |
| 506 | for (int iSpatialIdx = 0; iSpatialIdx < param_.iSpatialLayerNum; iSpatialIdx++) { | 515 | for (int iSpatialIdx = 0; iSpatialIdx < param_.iSpatialLayerNum; iSpatialIdx++) { |
| 507 | param_.sSpatialLayers[iSpatialIdx].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 600; | 516 | param_.sSpatialLayers[iSpatialIdx].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 600; |
| @@ -1443,7 +1452,7 @@ TEST_P (EncodeDecodeTestAPI, SetOption_Trace_NULL) { · 935 unmodified lines | |||
| 1443 | } | 1452 | } |
| 1444 | } | 1453 | } |
| 1445 | 1454 | ||
| 1446 | INSTANTIATE_TEST_CASE_P (EncodeDecodeTestBase, EncodeDecodeTestAPI, | 1455 | INSTANTIATE_TEST_CASE_P (EncodeDecodeTestAPIBase, EncodeDecodeTestAPI, |
| 1447 | ::testing::ValuesIn (kFileParamArray)); | 1456 | ::testing::ValuesIn (kFileParamArray)); |
| 1448 | 1457 | ||
| 1449 | TEST_P (EncodeDecodeTestAPI, SetOptionECIDC_GeneralSliceChange) { | 1458 | TEST_P (EncodeDecodeTestAPI, SetOptionECIDC_GeneralSliceChange) { |
| @@ -1531,6 +1540,7 @@ TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificFrameChange) { · 81 unmodified lines | |||
| 1531 | uint32_t uiGet; | 1540 | uint32_t uiGet; |
| 1532 | EncodeDecodeFileParamBase p = kFileParamArray[0]; | 1541 | EncodeDecodeFileParamBase p = kFileParamArray[0]; |
| 1533 | prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, ¶m_); | 1542 | prepareParamDefault (1, p.slicenum, p.width, p.height, p.frameRate, ¶m_); |
| 1543 | |||
| 1534 | param_.iSpatialLayerNum = 1; | 1544 | param_.iSpatialLayerNum = 1; |
| 1535 | encoder_->Uninitialize(); | 1545 | encoder_->Uninitialize(); |
| 1536 | int rv = encoder_->InitializeExt (¶m_); | 1546 | int rv = encoder_->InitializeExt (¶m_); |
| @@ -1551,7 +1561,6 @@ TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificFrameChange) { · 14 unmodified lines | |||
| 1551 | int iIdx = 0; | 1561 | int iIdx = 0; |
| 1552 | int len = 0; | 1562 | int len = 0; |
| 1553 | unsigned char* pData[3] = { NULL }; | 1563 | unsigned char* pData[3] = { NULL }; |
| 1554 | |||
| 1555 | InitialEncDec (p.width, p.height); | 1564 | InitialEncDec (p.width, p.height); |
| 1556 | //Frame 0: IDR, EC_IDC=DISABLE, loss = 0 | 1565 | //Frame 0: IDR, EC_IDC=DISABLE, loss = 0 |
| 1557 | EncodeOneFrame (1); | 1566 | EncodeOneFrame (1); |
| @@ -1656,7 +1665,6 @@ TEST_F (EncodeDecodeTestAPI, SetOptionECIDC_SpecificFrameChange) { · 98 unmodified lines | |||
| 1656 | EXPECT_TRUE (rv != 0); //not sure if previous data drop would be detected in construction | 1665 | EXPECT_TRUE (rv != 0); //not sure if previous data drop would be detected in construction |
| 1657 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); | 1666 | EXPECT_EQ (dstBufInfo_.iBufferStatus, 1); |
| 1658 | iIdx++; | 1667 | iIdx++; |
| 1659 | |||
| 1660 | } | 1668 | } |
| 1661 | 1669 | ||
| 1662 | //This case contain 2 slices per picture for IDR loss | 1670 | //This case contain 2 slices per picture for IDR loss |
| @@ -2165,7 +2173,7 @@ TEST_F (EncodeDecodeTestAPI, SetOptionEncParamExt) { · 502 unmodified lines | |||
| 2165 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | 2173 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); |
| 2166 | } | 2174 | } |
| 2167 | 2175 | ||
| 2168 | class DecodeCrashTestAPI : public EncodeDecodeTestBase { | 2176 | class DecodeCrashTestAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase { |
| 2169 | public: | 2177 | public: |
| 2170 | uint8_t iRandValue; | 2178 | uint8_t iRandValue; |
| 2171 | public: | 2179 | public: |
| @@ -2386,7 +2394,7 @@ const char* pHashStr[] = { //DO NOT CHANGE! · 214 unmodified lines | |||
| 2386 | "eb9d853b7daec03052c4850027ac94adc84c3a7e" | 2394 | "eb9d853b7daec03052c4850027ac94adc84c3a7e" |
| 2387 | }; | 2395 | }; |
| 2388 | 2396 | ||
| 2389 | class DecodeParseAPI : public EncodeDecodeTestBase { | 2397 | class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, public EncodeDecodeTestBase { |
| 2390 | public: | 2398 | public: |
| 2391 | void SetUp() { | 2399 | void SetUp() { |
| 2392 | SHA1Reset (&ctx_); | 2400 | SHA1Reset (&ctx_); |
| @@ -3242,3 +3250,112 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVC) { · 849 unmodified lines | |||
| 3242 | } | 3250 | } |
| 3243 | } | 3251 | } |
| 3244 | 3252 | ||
| 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 (¶m_, 0, sizeof (SEncParamExt)); | ||
| 3310 | encoder_->GetDefaultParams (¶m_); | ||
| 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 (¶m_); | ||
| 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 | |||