Showing the changes to test/api/encode_decode_api_test.cpp (1 of 4 files). Show all
Unified · Split
| @@ -4,16 +4,28 @@ · 3 unmodified lines | |||
| 4 | #include "utils/FileInputStream.h" | 4 | #include "utils/FileInputStream.h" |
| 5 | #include "BaseDecoderTest.h" | 5 | #include "BaseDecoderTest.h" |
| 6 | #include "BaseEncoderTest.h" | 6 | #include "BaseEncoderTest.h" |
| 7 | #include "wels_common_defs.h" | ||
| 7 | #include <string> | 8 | #include <string> |
| 9 | #include <vector> | ||
| 10 | using namespace WelsCommon; | ||
| 11 | |||
| 12 | typedef struct SLost_Sim { | ||
| 13 | WelsCommon::EWelsNalUnitType eNalType; | ||
| 14 | bool isLost; | ||
| 15 | } SLostSim; | ||
| 16 | |||
| 8 | 17 | ||
| 9 | struct EncodeDecodeFileParamBase { | 18 | struct EncodeDecodeFileParamBase { |
| 10 | int numframes; | 19 | int numframes; |
| 11 | int width; | 20 | int width; |
| 12 | int height; | 21 | int height; |
| 13 | float frameRate; | 22 | float frameRate; |
| 23 | int slicenum; | ||
| 24 | bool bLostPara; | ||
| 25 | const char* pLossSequence; | ||
| 14 | }; | 26 | }; |
| 15 | 27 | ||
| 16 | class EncodeDecodeTestBase : public ::testing::Test, | 28 | class EncodeDecodeTestBase : public ::testing::TestWithParam<EncodeDecodeFileParamBase>, |
| 17 | public BaseEncoderTest, public BaseDecoderTest { | 29 | public BaseEncoderTest, public BaseDecoderTest { |
| 18 | public: | 30 | public: |
| 19 | virtual void SetUp() { | 31 | virtual void SetUp() { |
| @@ -54,6 +66,7 @@ class EncodeDecodeTestBase : public ::testing::Test, · 34 unmodified lines | |||
| 54 | SEncParamExt param_; | 66 | SEncParamExt param_; |
| 55 | BufferedData buf_; | 67 | BufferedData buf_; |
| 56 | SBufferInfo dstBufInfo_; | 68 | SBufferInfo dstBufInfo_; |
| 69 | std::vector<SLostSim> m_SLostSim; | ||
| 57 | }; | 70 | }; |
| 58 | 71 | ||
| 59 | class EncodeDecodeTestAPI : public EncodeDecodeTestBase { | 72 | class EncodeDecodeTestAPI : public EncodeDecodeTestBase { |
| @@ -71,12 +84,15 @@ class EncodeDecodeTestAPI : public EncodeDecodeTestBase { · 11 unmodified lines | |||
| 71 | } | 84 | } |
| 72 | }; | 85 | }; |
| 73 | 86 | ||
| 74 | static const EncodeDecodeFileParamBase kFileParamArray = | 87 | static const EncodeDecodeFileParamBase kFileParamArray[] = { |
| 75 | {300, 160, 96, 6.0f}; | 88 | {300, 160, 96, 6.0f, 2, 1, "000000000000001010101010101010101010101001101010100000010101000011"}, |
| 89 | {300, 140, 96, 6.0f, 4, 1, "000000000000001010101010101010101010101001101010100000010101000011"}, | ||
| 90 | }; | ||
| 76 | 91 | ||
| 77 | TEST_F (EncodeDecodeTestAPI, DecoderVclNal) { | 92 | TEST_P (EncodeDecodeTestAPI, DecoderVclNal) { |
| 78 | EncodeDecodeFileParamBase p = kFileParamArray; | 93 | EncodeDecodeFileParamBase p = GetParam(); |
| 79 | prepareParam (p.width, p.height, p.frameRate); | 94 | prepareParam (p.width, p.height, p.frameRate); |
| 95 | encoder_->Uninitialize(); | ||
| 80 | int rv = encoder_->InitializeExt (¶m_); | 96 | int rv = encoder_->InitializeExt (¶m_); |
| 81 | ASSERT_TRUE (rv == cmResultSuccess); | 97 | ASSERT_TRUE (rv == cmResultSuccess); |
| 82 | 98 | ||
| @@ -86,7 +102,9 @@ TEST_F (EncodeDecodeTestAPI, DecoderVclNal) { · 3 unmodified lines | |||
| 86 | 102 | ||
| 87 | buf_.SetLength (frameSize); | 103 | buf_.SetLength (frameSize); |
| 88 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); | 104 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); |
| 89 | 105 | int32_t iTraceLevel = WELS_LOG_QUIET; | |
| 106 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 107 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 90 | SFrameBSInfo info; | 108 | SFrameBSInfo info; |
| 91 | memset (&info, 0, sizeof (SFrameBSInfo)); | 109 | memset (&info, 0, sizeof (SFrameBSInfo)); |
| 92 | 110 | ||
| @@ -123,16 +141,19 @@ TEST_F (EncodeDecodeTestAPI, DecoderVclNal) { · 30 unmodified lines | |||
| 123 | //ignore last frame | 141 | //ignore last frame |
| 124 | } | 142 | } |
| 125 | 143 | ||
| 126 | TEST_F (EncodeDecodeTestAPI, GetOptionFramenum) { | 144 | TEST_P (EncodeDecodeTestAPI, GetOptionFramenum) { |
| 127 | EncodeDecodeFileParamBase p = kFileParamArray; | 145 | EncodeDecodeFileParamBase p = GetParam(); |
| 128 | prepareParam (p.width, p.height, p.frameRate); | 146 | prepareParam (p.width, p.height, p.frameRate); |
| 147 | encoder_->Uninitialize(); | ||
| 129 | int rv = encoder_->InitializeExt (¶m_); | 148 | int rv = encoder_->InitializeExt (¶m_); |
| 130 | ASSERT_TRUE (rv == cmResultSuccess); | 149 | ASSERT_TRUE (rv == cmResultSuccess); |
| 131 | 150 | ||
| 132 | //init for encoder | 151 | //init for encoder |
| 133 | // I420: 1(Y) + 1/4(U) + 1/4(V) | 152 | // I420: 1(Y) + 1/4(U) + 1/4(V) |
| 134 | int frameSize = p.width * p.height * 3 / 2; | 153 | int frameSize = p.width * p.height * 3 / 2; |
| 135 | 154 | int32_t iTraceLevel = WELS_LOG_QUIET; | |
| 155 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 156 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 136 | buf_.SetLength (frameSize); | 157 | buf_.SetLength (frameSize); |
| 137 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); | 158 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); |
| 138 | 159 | ||
| @@ -175,16 +196,19 @@ TEST_F (EncodeDecodeTestAPI, GetOptionFramenum) { · 36 unmodified lines | |||
| 175 | //ignore last frame | 196 | //ignore last frame |
| 176 | } | 197 | } |
| 177 | 198 | ||
| 178 | TEST_F (EncodeDecodeTestAPI, GetOptionIDR) { | 199 | TEST_P (EncodeDecodeTestAPI, GetOptionIDR) { |
| 179 | EncodeDecodeFileParamBase p = kFileParamArray; | 200 | EncodeDecodeFileParamBase p = GetParam(); |
| 180 | prepareParam (p.width, p.height, p.frameRate); | 201 | prepareParam (p.width, p.height, p.frameRate); |
| 202 | encoder_->Uninitialize(); | ||
| 181 | int rv = encoder_->InitializeExt (¶m_); | 203 | int rv = encoder_->InitializeExt (¶m_); |
| 182 | ASSERT_TRUE (rv == cmResultSuccess); | 204 | ASSERT_TRUE (rv == cmResultSuccess); |
| 183 | 205 | ||
| 184 | //init for encoder | 206 | //init for encoder |
| 185 | // I420: 1(Y) + 1/4(U) + 1/4(V) | 207 | // I420: 1(Y) + 1/4(U) + 1/4(V) |
| 186 | int frameSize = p.width * p.height * 3 / 2; | 208 | int frameSize = p.width * p.height * 3 / 2; |
| 187 | 209 | int32_t iTraceLevel = WELS_LOG_QUIET; | |
| 210 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 211 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 188 | buf_.SetLength (frameSize); | 212 | buf_.SetLength (frameSize); |
| 189 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); | 213 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); |
| 190 | 214 | ||
| @@ -236,3 +260,478 @@ TEST_F (EncodeDecodeTestAPI, GetOptionIDR) { · 45 unmodified lines | |||
| 236 | } | 260 | } |
| 237 | 261 | ||
| 238 | 262 | ||
| 263 | long IsKeyFrameLost (ISVCDecoder* pDecoder, SLTRRecoverRequest* p_LTR_Recover_Request, long hr) { | ||
| 264 | long bLost = NO_RECOVERY_REQUSET; | ||
| 265 | int tempInt = -1; | ||
| 266 | int temple_id = -1; | ||
| 267 | bool m_P2PmodeFlag = true; | ||
| 268 | pDecoder->GetOption (DECODER_OPTION_TEMPORAL_ID, &temple_id); | ||
| 269 | if (hr == dsErrorFree) { | ||
| 270 | if (m_P2PmodeFlag && temple_id == 0) { | ||
| 271 | pDecoder->GetOption (DECODER_OPTION_IDR_PIC_ID, &tempInt); | ||
| 272 | // idr_pic_id change ,reset last correct position | ||
| 273 | if (p_LTR_Recover_Request->uiIDRPicId != tempInt) { | ||
| 274 | p_LTR_Recover_Request->uiIDRPicId = tempInt; | ||
| 275 | p_LTR_Recover_Request->iLastCorrectFrameNum = -1; | ||
| 276 | } | ||
| 277 | pDecoder->GetOption (DECODER_OPTION_FRAME_NUM, &tempInt); | ||
| 278 | if (tempInt >= 0) { | ||
| 279 | p_LTR_Recover_Request->iLastCorrectFrameNum = tempInt; | ||
| 280 | } | ||
| 281 | } | ||
| 282 | bLost = NO_RECOVERY_REQUSET; | ||
| 283 | } else if (hr & dsNoParamSets) { | ||
| 284 | bLost = IDR_RECOVERY_REQUEST; | ||
| 285 | } else if (((hr & dsRefLost) && (1 == temple_id)) || ((dsErrorFree != hr) && (0 == temple_id))) { | ||
| 286 | bLost = LTR_RECOVERY_REQUEST; | ||
| 287 | } else { | ||
| 288 | bLost = NO_RECOVERY_REQUSET; | ||
| 289 | } | ||
| 290 | return bLost; | ||
| 291 | } | ||
| 292 | |||
| 293 | bool IsLTRMarking (ISVCDecoder* pDecoder) { | ||
| 294 | int bLTR_marking_flag = 0; | ||
| 295 | pDecoder->GetOption (DECODER_OPTION_LTR_MARKING_FLAG, &bLTR_marking_flag); | ||
| 296 | return (bLTR_marking_flag) ? (true) : (false); | ||
| 297 | } | ||
| 298 | |||
| 299 | void LTRRecoveryRequest (ISVCDecoder* pDecoder, ISVCEncoder* pEncoder, SLTRRecoverRequest* p_LTR_Recover_Request, | ||
| 300 | long hr) { | ||
| 301 | |||
| 302 | long bKLost = IsKeyFrameLost (pDecoder, p_LTR_Recover_Request, hr); | ||
| 303 | bool m_P2PmodeFlag = true; | ||
| 304 | if (m_P2PmodeFlag) { | ||
| 305 | if (bKLost == IDR_RECOVERY_REQUEST) { | ||
| 306 | pEncoder->ForceIntraFrame (true); | ||
| 307 | } else if (bKLost == LTR_RECOVERY_REQUEST) { | ||
| 308 | p_LTR_Recover_Request->uiFeedbackType = LTR_RECOVERY_REQUEST; | ||
| 309 | pDecoder->GetOption (DECODER_OPTION_FRAME_NUM, &p_LTR_Recover_Request->iCurrentFrameNum); | ||
| 310 | pDecoder->GetOption (DECODER_OPTION_IDR_PIC_ID, &p_LTR_Recover_Request->uiIDRPicId); | ||
| 311 | pEncoder->SetOption (ENCODER_LTR_RECOVERY_REQUEST, p_LTR_Recover_Request); | ||
| 312 | } | ||
| 313 | } else { | ||
| 314 | if (bKLost == IDR_RECOVERY_REQUEST || bKLost == LTR_RECOVERY_REQUEST) { | ||
| 315 | p_LTR_Recover_Request->uiFeedbackType = IDR_RECOVERY_REQUEST; | ||
| 316 | pDecoder->GetOption (DECODER_OPTION_FRAME_NUM, &p_LTR_Recover_Request->iCurrentFrameNum); | ||
| 317 | pDecoder->GetOption (DECODER_OPTION_IDR_PIC_ID, &p_LTR_Recover_Request->uiIDRPicId); | ||
| 318 | pEncoder->SetOption (ENCODER_LTR_RECOVERY_REQUEST, p_LTR_Recover_Request); | ||
| 319 | } | ||
| 320 | } | ||
| 321 | } | ||
| 322 | |||
| 323 | void LTRMarkFeedback (ISVCDecoder* pDecoder, ISVCEncoder* pEncoder, SLTRMarkingFeedback* p_LTR_Marking_Feedback, | ||
| 324 | long hr) { | ||
| 325 | if (IsLTRMarking (pDecoder) == true) { | ||
| 326 | p_LTR_Marking_Feedback->uiFeedbackType = (hr == dsErrorFree) ? (LTR_MARKING_SUCCESS) : (LTR_MARKING_FAILED); | ||
| 327 | pDecoder->GetOption (DECODER_OPTION_IDR_PIC_ID, &p_LTR_Marking_Feedback->uiIDRPicId); | ||
| 328 | pDecoder->GetOption (DECODER_OPTION_LTR_MARKED_FRAME_NUM, &p_LTR_Marking_Feedback->iLTRFrameNum); | ||
| 329 | pEncoder->SetOption (ENCODER_LTR_MARKING_FEEDBACK, p_LTR_Marking_Feedback); | ||
| 330 | } | ||
| 331 | } | ||
| 332 | |||
| 333 | |||
| 334 | int SimulateNALLoss (const unsigned char* pSrc, int& iSrcLen, std::vector<SLostSim>* p_SLostSim, | ||
| 335 | const char* pLossChars, bool bLossPara, int& iLossIdx, bool& bVCLLoss) { | ||
| 336 | unsigned char* pDst = new unsigned char[iSrcLen]; | ||
| 337 | int iLossCharLen = strlen (pLossChars); | ||
| 338 | int iSkipedBytes = 0; | ||
| 339 | int iDstLen = 0; | ||
| 340 | int iBufPos = 0; | ||
| 341 | int ilastprefixlen = 0; | ||
| 342 | int i = 0; | ||
| 343 | bool bLost; | ||
| 344 | bVCLLoss = false; | ||
| 345 | SLostSim tmpSLostSim; | ||
| 346 | p_SLostSim->clear(); | ||
| 347 | for (i = 0; i < iSrcLen;) { | ||
| 348 | if (pSrc[i] == 0 && pSrc[i + 1] == 0 && pSrc[i + 2] == 0 && pSrc[i + 3] == 1) { | ||
| 349 | if (i - iBufPos) { | ||
| 350 | tmpSLostSim.eNalType = (EWelsNalUnitType) ((* (pSrc + iBufPos + ilastprefixlen)) & 0x1f); // eNalUnitType | ||
| 351 | bLost = iLossIdx < iLossCharLen ? (pLossChars[iLossIdx] == '1') : (rand() % 2 == 1); | ||
| 352 | bLost = (!bLossPara) && (IS_PARAM_SETS_NALS (tmpSLostSim.eNalType)) ? false : bLost; | ||
| 353 | iLossIdx++; | ||
| 354 | tmpSLostSim.isLost = bLost; | ||
| 355 | p_SLostSim->push_back (tmpSLostSim); | ||
| 356 | if (!bLost) { | ||
| 357 | memcpy (pDst + iDstLen, pSrc + iBufPos, i - iBufPos); | ||
| 358 | iDstLen += (i - iBufPos); | ||
| 359 | } else { | ||
| 360 | bVCLLoss = (IS_VCL_NAL (tmpSLostSim.eNalType, 1)) ? true : bVCLLoss; | ||
| 361 | iSkipedBytes += (i - iBufPos); | ||
| 362 | } | ||
| 363 | } | ||
| 364 | ilastprefixlen = 4; | ||
| 365 | iBufPos = i; | ||
| 366 | i = i + 4; | ||
| 367 | } else if (pSrc[i] == 0 && pSrc[i + 1] == 0 && pSrc[i + 2] == 1) { | ||
| 368 | if (i - iBufPos) { | ||
| 369 | tmpSLostSim.eNalType = (EWelsNalUnitType) ((* (pSrc + iBufPos + ilastprefixlen)) & 0x1f); // eNalUnitType | ||
| 370 | bLost = iLossIdx < iLossCharLen ? (pLossChars[iLossIdx] == '1') : (rand() % 2 == 1); | ||
| 371 | bLost = (!bLossPara) && (IS_PARAM_SETS_NALS (tmpSLostSim.eNalType)) ? false : bLost; | ||
| 372 | iLossIdx++; | ||
| 373 | tmpSLostSim.isLost = bLost; | ||
| 374 | p_SLostSim->push_back (tmpSLostSim); | ||
| 375 | if (!bLost) { | ||
| 376 | memcpy (pDst + iDstLen, pSrc + iBufPos, i - iBufPos); | ||
| 377 | iDstLen += (i - iBufPos); | ||
| 378 | } else { | ||
| 379 | bVCLLoss = (IS_VCL_NAL (tmpSLostSim.eNalType, 1)) ? true : bVCLLoss; | ||
| 380 | iSkipedBytes += (i - iBufPos); | ||
| 381 | } | ||
| 382 | } | ||
| 383 | ilastprefixlen = 3; | ||
| 384 | iBufPos = i; | ||
| 385 | i = i + 3; | ||
| 386 | } else { | ||
| 387 | i++; | ||
| 388 | } | ||
| 389 | } | ||
| 390 | if (i - iBufPos) { | ||
| 391 | tmpSLostSim.eNalType = (EWelsNalUnitType) ((* (pSrc + iBufPos + ilastprefixlen)) & 0x1f); // eNalUnitType | ||
| 392 | bLost = iLossIdx < iLossCharLen ? (pLossChars[iLossIdx] == '1') : (rand() % 2 == 1); | ||
| 393 | bLost = (!bLossPara) && (IS_PARAM_SETS_NALS (tmpSLostSim.eNalType)) ? false : bLost; | ||
| 394 | iLossIdx++; | ||
| 395 | tmpSLostSim.isLost = bLost; | ||
| 396 | p_SLostSim->push_back (tmpSLostSim); | ||
| 397 | if (!bLost) { | ||
| 398 | memcpy (pDst + iDstLen, pSrc + iBufPos, i - iBufPos); | ||
| 399 | iDstLen += (i - iBufPos); | ||
| 400 | } else { | ||
| 401 | bVCLLoss = (IS_VCL_NAL (tmpSLostSim.eNalType, 1)) ? true : bVCLLoss; | ||
| 402 | iSkipedBytes += (i - iBufPos); | ||
| 403 | } | ||
| 404 | } | ||
| 405 | memset ((void*)pSrc, 0, iSrcLen); | ||
| 406 | memcpy ((void*)pSrc, pDst, iDstLen); | ||
| 407 | iSrcLen = iDstLen; | ||
| 408 | delete pDst; | ||
| 409 | return iSkipedBytes; | ||
| 410 | } | ||
| 411 | |||
| 412 | TEST_P (EncodeDecodeTestAPI, GetOptionLTR_ALLIDR) { | ||
| 413 | EncodeDecodeFileParamBase p = GetParam(); | ||
| 414 | prepareParam (p.width, p.height, p.frameRate); | ||
| 415 | encoder_->Uninitialize(); | ||
| 416 | int rv = encoder_->InitializeExt (¶m_); | ||
| 417 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 418 | int frameSize = p.width * p.height * 3 / 2; | ||
| 419 | buf_.SetLength (frameSize); | ||
| 420 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); | ||
| 421 | |||
| 422 | SFrameBSInfo info; | ||
| 423 | memset (&info, 0, sizeof (SFrameBSInfo)); | ||
| 424 | SSourcePicture pic; | ||
| 425 | memset (&pic, 0, sizeof (SSourcePicture)); | ||
| 426 | pic.iPicWidth = p.width; | ||
| 427 | pic.iPicHeight = p.height; | ||
| 428 | pic.iColorFormat = videoFormatI420; | ||
| 429 | pic.iStride[0] = pic.iPicWidth; | ||
| 430 | pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1; | ||
| 431 | pic.pData[0] = buf_.data(); | ||
| 432 | pic.pData[1] = pic.pData[0] + p.width * p.height; | ||
| 433 | pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2); | ||
| 434 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 435 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 436 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 437 | int32_t iSpsPpsIdAddition = 1; | ||
| 438 | encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition); | ||
| 439 | int32_t iIDRPeriod = 60; | ||
| 440 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 441 | SLTRConfig sLtrConfigVal; | ||
| 442 | sLtrConfigVal.bEnableLongTermReference = 1; | ||
| 443 | sLtrConfigVal.iLTRRefNum = 1; | ||
| 444 | encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal); | ||
| 445 | int32_t iLtrPeriod = 2; | ||
| 446 | encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod); | ||
| 447 | int iIdx = 0; | ||
| 448 | while (iIdx <= p.numframes) { | ||
| 449 | memset (buf_.data(), rand() % 256, frameSize); | ||
| 450 | rv = encoder_->EncodeFrame (&pic, &info); | ||
| 451 | ASSERT_EQ (rv, cmResultSuccess); | ||
| 452 | ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 453 | encoder_->ForceIntraFrame (true); | ||
| 454 | iIdx++; | ||
| 455 | } | ||
| 456 | } | ||
| 457 | |||
| 458 | TEST_P (EncodeDecodeTestAPI, GetOptionLTR_ALLLTR) { | ||
| 459 | SLTRMarkingFeedback m_LTR_Marking_Feedback; | ||
| 460 | SLTRRecoverRequest m_LTR_Recover_Request; | ||
| 461 | EncodeDecodeFileParamBase p = GetParam(); | ||
| 462 | prepareParam (p.width, p.height, p.frameRate); | ||
| 463 | encoder_->Uninitialize(); | ||
| 464 | int rv = encoder_->InitializeExt (¶m_); | ||
| 465 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 466 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 467 | int frameSize = p.width * p.height * 3 / 2; | ||
| 468 | buf_.SetLength (frameSize); | ||
| 469 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); | ||
| 470 | SFrameBSInfo info; | ||
| 471 | memset (&info, 0, sizeof (SFrameBSInfo)); | ||
| 472 | |||
| 473 | SSourcePicture pic; | ||
| 474 | memset (&pic, 0, sizeof (SSourcePicture)); | ||
| 475 | pic.iPicWidth = p.width; | ||
| 476 | pic.iPicHeight = p.height; | ||
| 477 | pic.iColorFormat = videoFormatI420; | ||
| 478 | pic.iStride[0] = pic.iPicWidth; | ||
| 479 | pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1; | ||
| 480 | pic.pData[0] = buf_.data(); | ||
| 481 | pic.pData[1] = pic.pData[0] + p.width * p.height; | ||
| 482 | pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2); | ||
| 483 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 484 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 485 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 486 | int32_t iSpsPpsIdAddition = 1; | ||
| 487 | encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition); | ||
| 488 | int32_t iIDRPeriod = 60; | ||
| 489 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 490 | SLTRConfig sLtrConfigVal; | ||
| 491 | sLtrConfigVal.bEnableLongTermReference = 1; | ||
| 492 | sLtrConfigVal.iLTRRefNum = 1; | ||
| 493 | encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal); | ||
| 494 | int32_t iLtrPeriod = 2; | ||
| 495 | encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod); | ||
| 496 | int iIdx = 0; | ||
| 497 | while (iIdx <= p.numframes) { | ||
| 498 | memset (buf_.data(), rand() % 256, frameSize); | ||
| 499 | rv = encoder_->EncodeFrame (&pic, &info); | ||
| 500 | if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) { | ||
| 501 | ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 502 | } | ||
| 503 | ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnkonwReason); | ||
| 504 | m_LTR_Recover_Request.uiFeedbackType = LTR_RECOVERY_REQUEST; | ||
| 505 | m_LTR_Recover_Request.iCurrentFrameNum = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000; | ||
| 506 | m_LTR_Recover_Request.uiIDRPicId = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000; | ||
| 507 | encoder_->SetOption (ENCODER_LTR_RECOVERY_REQUEST, &m_LTR_Recover_Request); | ||
| 508 | m_LTR_Marking_Feedback.uiFeedbackType = rand() % 2 == 1 ? LTR_MARKING_SUCCESS : LTR_MARKING_FAILED; | ||
| 509 | m_LTR_Marking_Feedback.uiIDRPicId = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000; | ||
| 510 | m_LTR_Marking_Feedback.iLTRFrameNum = rand() % 2 == 1 ? -rand() % 10000 : rand() % 10000; | ||
| 511 | encoder_->SetOption (ENCODER_LTR_MARKING_FEEDBACK, &m_LTR_Marking_Feedback); | ||
| 512 | iIdx++; | ||
| 513 | } | ||
| 514 | } | ||
| 515 | |||
| 516 | TEST_P (EncodeDecodeTestAPI, GetOptionLTR_Engine) { | ||
| 517 | SLTRMarkingFeedback m_LTR_Marking_Feedback; | ||
| 518 | SLTRRecoverRequest m_LTR_Recover_Request; | ||
| 519 | EncodeDecodeFileParamBase p = GetParam(); | ||
| 520 | prepareParam (p.width, p.height, p.frameRate); | ||
| 521 | param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_FIXEDSLCNUM_SLICE; | ||
| 522 | param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = p.slicenum; | ||
| 523 | encoder_->Uninitialize(); | ||
| 524 | int rv = encoder_->InitializeExt (¶m_); | ||
| 525 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 526 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 527 | int frameSize = p.width * p.height * 3 / 2; | ||
| 528 | buf_.SetLength (frameSize); | ||
| 529 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); | ||
| 530 | SFrameBSInfo info; | ||
| 531 | memset (&info, 0, sizeof (SFrameBSInfo)); | ||
| 532 | |||
| 533 | SSourcePicture pic; | ||
| 534 | memset (&pic, 0, sizeof (SSourcePicture)); | ||
| 535 | pic.iPicWidth = p.width; | ||
| 536 | pic.iPicHeight = p.height; | ||
| 537 | pic.iColorFormat = videoFormatI420; | ||
| 538 | pic.iStride[0] = pic.iPicWidth; | ||
| 539 | pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1; | ||
| 540 | pic.pData[0] = buf_.data(); | ||
| 541 | pic.pData[1] = pic.pData[0] + p.width * p.height; | ||
| 542 | pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2); | ||
| 543 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 544 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 545 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 546 | int32_t iSpsPpsIdAddition = 1; | ||
| 547 | encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition); | ||
| 548 | int32_t iIDRPeriod = 60; | ||
| 549 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 550 | SLTRConfig sLtrConfigVal; | ||
| 551 | sLtrConfigVal.bEnableLongTermReference = 1; | ||
| 552 | sLtrConfigVal.iLTRRefNum = 1; | ||
| 553 | encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal); | ||
| 554 | int32_t iLtrPeriod = 2; | ||
| 555 | encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod); | ||
| 556 | int iIdx = 0; | ||
| 557 | int iLossIdx = 0; | ||
| 558 | bool bVCLLoss = false; | ||
| 559 | while (iIdx <= p.numframes) { | ||
| 560 | memset (buf_.data(), rand() % 256, frameSize); | ||
| 561 | rv = encoder_->EncodeFrame (&pic, &info); | ||
| 562 | if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) { | ||
| 563 | ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 564 | } | ||
| 565 | ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnkonwReason); | ||
| 566 | //decoding after each encoding frame | ||
| 567 | int len = 0; | ||
| 568 | encToDecData (info, len); | ||
| 569 | unsigned char* pData[3] = { NULL }; | ||
| 570 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 571 | SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, bVCLLoss); | ||
| 572 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 573 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 574 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv); | ||
| 575 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 576 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv); | ||
| 577 | LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv); | ||
| 578 | iIdx++; | ||
| 579 | } | ||
| 580 | } | ||
| 581 | |||
| 582 | TEST_P (EncodeDecodeTestAPI, SetOptionECFlag_ERROR_CON_DISABLE) { | ||
| 583 | SLTRMarkingFeedback m_LTR_Marking_Feedback; | ||
| 584 | SLTRRecoverRequest m_LTR_Recover_Request; | ||
| 585 | EncodeDecodeFileParamBase p = GetParam(); | ||
| 586 | prepareParam (p.width, p.height, p.frameRate); | ||
| 587 | param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_FIXEDSLCNUM_SLICE; | ||
| 588 | param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = p.slicenum; | ||
| 589 | param_.bEnableLongTermReference = true; | ||
| 590 | param_.iLTRRefNum = 1; | ||
| 591 | encoder_->Uninitialize(); | ||
| 592 | int rv = encoder_->InitializeExt (¶m_); | ||
| 593 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 594 | if (decoder_ != NULL) { | ||
| 595 | decoder_->Uninitialize(); | ||
| 596 | } | ||
| 597 | SDecodingParam decParam; | ||
| 598 | memset (&decParam, 0, sizeof (SDecodingParam)); | ||
| 599 | decParam.eOutputColorFormat = videoFormatI420; | ||
| 600 | decParam.uiTargetDqLayer = UCHAR_MAX; | ||
| 601 | decParam.eEcActiveIdc = ERROR_CON_DISABLE; | ||
| 602 | decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT; | ||
| 603 | rv = decoder_->Initialize (&decParam); | ||
| 604 | ASSERT_EQ (0, rv); | ||
| 605 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 606 | int frameSize = p.width * p.height * 3 / 2; | ||
| 607 | buf_.SetLength (frameSize); | ||
| 608 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); | ||
| 609 | SFrameBSInfo info; | ||
| 610 | memset (&info, 0, sizeof (SFrameBSInfo)); | ||
| 611 | |||
| 612 | SSourcePicture pic; | ||
| 613 | memset (&pic, 0, sizeof (SSourcePicture)); | ||
| 614 | pic.iPicWidth = p.width; | ||
| 615 | pic.iPicHeight = p.height; | ||
| 616 | pic.iColorFormat = videoFormatI420; | ||
| 617 | pic.iStride[0] = pic.iPicWidth; | ||
| 618 | pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1; | ||
| 619 | pic.pData[0] = buf_.data(); | ||
| 620 | pic.pData[1] = pic.pData[0] + p.width * p.height; | ||
| 621 | pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2); | ||
| 622 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 623 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 624 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 625 | int32_t iSpsPpsIdAddition = 1; | ||
| 626 | encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition); | ||
| 627 | int32_t iIDRPeriod = 60; | ||
| 628 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 629 | SLTRConfig sLtrConfigVal; | ||
| 630 | sLtrConfigVal.bEnableLongTermReference = 1; | ||
| 631 | sLtrConfigVal.iLTRRefNum = 1; | ||
| 632 | encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal); | ||
| 633 | int32_t iLtrPeriod = 2; | ||
| 634 | encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod); | ||
| 635 | int iIdx = 0; | ||
| 636 | int iLossIdx = 0; | ||
| 637 | int iSkipedBytes; | ||
| 638 | bool bVCLLoss = false; | ||
| 639 | while (iIdx <= p.numframes) { | ||
| 640 | memset (buf_.data(), rand() % 256, frameSize); | ||
| 641 | rv = encoder_->EncodeFrame (&pic, &info); | ||
| 642 | if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) { | ||
| 643 | ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 644 | } | ||
| 645 | ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnkonwReason); | ||
| 646 | //decoding after each encoding frame | ||
| 647 | int len = 0; | ||
| 648 | encToDecData (info, len); | ||
| 649 | unsigned char* pData[3] = { NULL }; | ||
| 650 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 651 | iSkipedBytes = SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, | ||
| 652 | bVCLLoss); | ||
| 653 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 654 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 655 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv); | ||
| 656 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 657 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv); | ||
| 658 | LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv); | ||
| 659 | if (iSkipedBytes && bVCLLoss) { | ||
| 660 | ASSERT_TRUE (dstBufInfo_.iBufferStatus == 0); | ||
| 661 | } | ||
| 662 | iIdx++; | ||
| 663 | } | ||
| 664 | } | ||
| 665 | |||
| 666 | TEST_P (EncodeDecodeTestAPI, SetOptionECFlag_ERROR_CON_SLICE_COPY) { | ||
| 667 | SLTRMarkingFeedback m_LTR_Marking_Feedback; | ||
| 668 | SLTRRecoverRequest m_LTR_Recover_Request; | ||
| 669 | EncodeDecodeFileParamBase p = GetParam(); | ||
| 670 | prepareParam (p.width, p.height, p.frameRate); | ||
| 671 | param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_FIXEDSLCNUM_SLICE; | ||
| 672 | param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = p.slicenum; | ||
| 673 | encoder_->Uninitialize(); | ||
| 674 | int rv = encoder_->InitializeExt (¶m_); | ||
| 675 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 676 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 677 | int frameSize = p.width * p.height * 3 / 2; | ||
| 678 | buf_.SetLength (frameSize); | ||
| 679 | ASSERT_TRUE (buf_.Length() == (size_t)frameSize); | ||
| 680 | SFrameBSInfo info; | ||
| 681 | memset (&info, 0, sizeof (SFrameBSInfo)); | ||
| 682 | |||
| 683 | SSourcePicture pic; | ||
| 684 | memset (&pic, 0, sizeof (SSourcePicture)); | ||
| 685 | pic.iPicWidth = p.width; | ||
| 686 | pic.iPicHeight = p.height; | ||
| 687 | pic.iColorFormat = videoFormatI420; | ||
| 688 | pic.iStride[0] = pic.iPicWidth; | ||
| 689 | pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1; | ||
| 690 | pic.pData[0] = buf_.data(); | ||
| 691 | pic.pData[1] = pic.pData[0] + p.width * p.height; | ||
| 692 | pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2); | ||
| 693 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 694 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 695 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 696 | int32_t iSpsPpsIdAddition = 1; | ||
| 697 | encoder_->SetOption (ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION, &iSpsPpsIdAddition); | ||
| 698 | int32_t iIDRPeriod = 60; | ||
| 699 | encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &iIDRPeriod); | ||
| 700 | SLTRConfig sLtrConfigVal; | ||
| 701 | sLtrConfigVal.bEnableLongTermReference = 1; | ||
| 702 | sLtrConfigVal.iLTRRefNum = 1; | ||
| 703 | encoder_->SetOption (ENCODER_OPTION_LTR, &sLtrConfigVal); | ||
| 704 | int32_t iLtrPeriod = 2; | ||
| 705 | encoder_->SetOption (ENCODER_LTR_MARKING_PERIOD, &iLtrPeriod); | ||
| 706 | int iIdx = 0; | ||
| 707 | int iLossIdx = 0; | ||
| 708 | int iSkipedBytes; | ||
| 709 | bool bVCLLoss = false; | ||
| 710 | while (iIdx <= p.numframes) { | ||
| 711 | memset (buf_.data(), rand() % 256, frameSize); | ||
| 712 | rv = encoder_->EncodeFrame (&pic, &info); | ||
| 713 | if (m_LTR_Recover_Request.uiFeedbackType == IDR_RECOVERY_REQUEST) { | ||
| 714 | ASSERT_TRUE (info.eFrameType == videoFrameTypeIDR); | ||
| 715 | } | ||
| 716 | ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnkonwReason); | ||
| 717 | //decoding after each encoding frame | ||
| 718 | int len = 0; | ||
| 719 | encToDecData (info, len); | ||
| 720 | unsigned char* pData[3] = { NULL }; | ||
| 721 | memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | ||
| 722 | iSkipedBytes = SimulateNALLoss (info.sLayerInfo[0].pBsBuf, len, &m_SLostSim, p.pLossSequence, p.bLostPara, iLossIdx, | ||
| 723 | bVCLLoss); | ||
| 724 | uint32_t uiEcIdc = rand() % 2 == 1 ? ERROR_CON_DISABLE : ERROR_CON_SLICE_COPY; | ||
| 725 | decoder_->SetOption (DECODER_OPTION_ERROR_CON_IDC, &uiEcIdc); | ||
| 726 | rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_); | ||
| 727 | m_LTR_Recover_Request.uiFeedbackType = NO_RECOVERY_REQUSET; | ||
| 728 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv); | ||
| 729 | rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction | ||
| 730 | LTRRecoveryRequest (decoder_, encoder_, &m_LTR_Recover_Request, rv); | ||
| 731 | LTRMarkFeedback (decoder_, encoder_, &m_LTR_Marking_Feedback, rv); | ||
| 732 | iIdx++; | ||
| 733 | } | ||
| 734 | } | ||
| 735 | |||
| 736 | INSTANTIATE_TEST_CASE_P (EncodeDecodeTestBase, EncodeDecodeTestAPI, | ||
| 737 | ::testing::ValuesIn (kFileParamArray)); | ||