Showing the changes to test/decoder (1 of 1 file). Show all
Unified · Split
| @@ -10,13 +10,19 @@ · 9 unmodified lines | |||
| 10 | using namespace WelsDec; | 10 | using namespace WelsDec; |
| 11 | 11 | ||
| 12 | #define BUF_SIZE 100 | 12 | #define BUF_SIZE 100 |
| 13 | typedef enum DecCase { | ||
| 14 | CorrectDec = 0, | ||
| 15 | ErrorDec = 1, | ||
| 16 | CorrectParseOnly = 2, | ||
| 17 | ErrorParseOnly = 3, | ||
| 18 | RESERVED, | ||
| 19 | } EDecCase; | ||
| 13 | 20 | ||
| 14 | DECODING_STATE DecodeFrame (const unsigned char* kpSrc, | 21 | DECODING_STATE DecodeFrame (const unsigned char* kpSrc, |
| 15 | const int kiSrcLen, | 22 | const int kiSrcLen, |
| 16 | unsigned char** ppDst, | 23 | unsigned char** ppDst, |
| 17 | SBufferInfo* pDstInfo, | 24 | SBufferInfo* pDstInfo, |
| 18 | PWelsDecoderContext pCtx) { | 25 | PWelsDecoderContext pCtx) { |
| 19 | |||
| 20 | PWelsDecoderContext m_pDecContext = pCtx; | 26 | PWelsDecoderContext m_pDecContext = pCtx; |
| 21 | if (CheckBsBuffer (m_pDecContext, kiSrcLen)) { | 27 | if (CheckBsBuffer (m_pDecContext, kiSrcLen)) { |
| 22 | return dsOutOfMemory; | 28 | return dsOutOfMemory; |
| @@ -55,7 +61,7 @@ DECODING_STATE DecodeFrame (const unsigned char* kpSrc, · 32 unmodified lines | |||
| 55 | pDstInfo, NULL); //iErrorCode has been modified in this function | 61 | pDstInfo, NULL); //iErrorCode has been modified in this function |
| 56 | m_pDecContext->bInstantDecFlag = false; //reset no-delay flag | 62 | m_pDecContext->bInstantDecFlag = false; //reset no-delay flag |
| 57 | 63 | ||
| 58 | return dsErrorFree; | 64 | return (DECODING_STATE) m_pDecContext->iErrorCode; |
| 59 | } | 65 | } |
| 60 | 66 | ||
| 61 | void UninitDecoder (PWelsDecoderContext& pCtx) { | 67 | void UninitDecoder (PWelsDecoderContext& pCtx) { |
| @@ -132,13 +138,14 @@ class DecoderParseSyntaxTest : public ::testing::Test { · 70 unmodified lines | |||
| 132 | //Uninit members | 138 | //Uninit members |
| 133 | void Uninit(); | 139 | void Uninit(); |
| 134 | //Decoder real bitstream | 140 | //Decoder real bitstream |
| 135 | bool DecodeBs (const char* sFileName); | 141 | bool DecodeBs (const char* sFileName, EDecCase eDecCase); |
| 136 | //Parse real bitstream | 142 | //Parse real bitstream |
| 137 | bool ParseBs (const char* sFileName); | 143 | bool ParseBs (const char* sFileName, EDecCase eDecCase); |
| 138 | //Scalinglist | 144 | //Scalinglist |
| 139 | void TestScalingList(); | 145 | void TestScalingList(); |
| 140 | //specific bitstream test | 146 | //specific bitstream test |
| 141 | void TestSpecificBs(); | 147 | void TestSpecificBs(); |
| 148 | void TestSpecificBsError(); | ||
| 142 | //Do whole tests here | 149 | //Do whole tests here |
| 143 | void DecoderParseSyntaxTestAll(); | 150 | void DecoderParseSyntaxTestAll(); |
| 144 | 151 | ||
| @@ -204,17 +211,17 @@ void DecoderParseSyntaxTest::Uninit() { · 59 unmodified lines | |||
| 204 | m_iBufLength = 0; | 211 | m_iBufLength = 0; |
| 205 | } | 212 | } |
| 206 | 213 | ||
| 207 | bool DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { | 214 | bool DecoderParseSyntaxTest::DecodeBs (const char* sFileName, EDecCase eDecCase) { |
| 208 | 215 | ||
| 209 | uint8_t* pBuf = NULL; | 216 | uint8_t* pBuf = NULL; |
| 210 | int32_t iBufPos = 0; | 217 | int32_t iBufPos = 0; |
| 211 | int32_t iFileSize; | 218 | int32_t iFileSize; |
| 212 | int32_t i = 0; | 219 | int32_t i = 0; |
| 213 | int32_t iSliceSize; | 220 | int32_t iSliceSize; |
| 214 | int32_t iSliceIndex = 0; | ||
| 215 | int32_t iEndOfStreamFlag = 0; | 221 | int32_t iEndOfStreamFlag = 0; |
| 216 | FILE* pH264File; | 222 | FILE* pH264File; |
| 217 | uint8_t uiStartCode[4] = {0, 0, 0, 1}; | 223 | uint8_t uiStartCode[4] = {0, 0, 0, 1}; |
| 224 | int iRet = 0; | ||
| 218 | 225 | ||
| 219 | #if defined(ANDROID_NDK) | 226 | #if defined(ANDROID_NDK) |
| 220 | std::string filename = std::string ("/sdcard/") + sFileName; | 227 | std::string filename = std::string ("/sdcard/") + sFileName; |
| @@ -255,12 +262,13 @@ bool DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { · 34 unmodified lines | |||
| 255 | } | 262 | } |
| 256 | } | 263 | } |
| 257 | iSliceSize = i; | 264 | iSliceSize = i; |
| 258 | DecodeFrame (pBuf + iBufPos, iSliceSize, m_pData, &m_sBufferInfo, m_pCtx); | 265 | iRet |= DecodeFrame (pBuf + iBufPos, iSliceSize, m_pData, &m_sBufferInfo, m_pCtx); |
| 259 | iBufPos += iSliceSize; | 266 | iBufPos += iSliceSize; |
| 260 | ++ iSliceIndex; | ||
| 261 | if (iSliceIndex == 4) | ||
| 262 | break; | ||
| 263 | } | 267 | } |
| 268 | if (eDecCase == CorrectDec) | ||
| 269 | EXPECT_TRUE (iRet == dsErrorFree); | ||
| 270 | else if (eDecCase == ErrorDec) | ||
| 271 | EXPECT_TRUE ((iRet & (dsBitstreamError | dsRefLost | dsDataErrorConcealed)) != 0) << "iRet = " << iRet; | ||
| 264 | 272 | ||
| 265 | fclose (pH264File); | 273 | fclose (pH264File); |
| 266 | if (pBuf) { | 274 | if (pBuf) { |
| @@ -270,7 +278,7 @@ bool DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { · 3 unmodified lines | |||
| 270 | 278 | ||
| 271 | return true; | 279 | return true; |
| 272 | } | 280 | } |
| 273 | bool DecoderParseSyntaxTest::ParseBs (const char* sFileName) { | 281 | bool DecoderParseSyntaxTest::ParseBs (const char* sFileName, EDecCase eDecCase) { |
| 274 | 282 | ||
| 275 | uint8_t* pBuf = NULL; | 283 | uint8_t* pBuf = NULL; |
| 276 | int32_t iBufPos = 0; | 284 | int32_t iBufPos = 0; |
| @@ -281,7 +289,7 @@ bool DecoderParseSyntaxTest::ParseBs (const char* sFileName) { · 4 unmodified lines | |||
| 281 | int32_t iEndOfStreamFlag = 0; | 289 | int32_t iEndOfStreamFlag = 0; |
| 282 | FILE* pH264File; | 290 | FILE* pH264File; |
| 283 | uint8_t uiStartCode[4] = { 0, 0, 0, 1 }; | 291 | uint8_t uiStartCode[4] = { 0, 0, 0, 1 }; |
| 284 | int iRet; | 292 | int iRet = 0; |
| 285 | 293 | ||
| 286 | #if defined(ANDROID_NDK) | 294 | #if defined(ANDROID_NDK) |
| 287 | std::string filename = std::string ("/sdcard/") + sFileName; | 295 | std::string filename = std::string ("/sdcard/") + sFileName; |
| @@ -323,15 +331,17 @@ bool DecoderParseSyntaxTest::ParseBs (const char* sFileName) { · 35 unmodified lines | |||
| 323 | } | 331 | } |
| 324 | iSliceSize = i; | 332 | iSliceSize = i; |
| 325 | memset (&m_sParserBsInfo, 0, sizeof (SParserBsInfo)); | 333 | memset (&m_sParserBsInfo, 0, sizeof (SParserBsInfo)); |
| 326 | iRet = m_pDec->DecodeParser (pBuf + iBufPos, iSliceSize, &m_sParserBsInfo); | 334 | iRet |= m_pDec->DecodeParser (pBuf + iBufPos, iSliceSize, &m_sParserBsInfo); |
| 327 | EXPECT_TRUE (iRet == dsErrorFree || iRet == dsFramePending); | 335 | iRet |= m_pDec->DecodeParser (NULL, 0, &m_sParserBsInfo); |
| 328 | iRet = m_pDec->DecodeParser (NULL, 0, &m_sParserBsInfo); | 336 | if (eDecCase == CorrectParseOnly) |
| 329 | EXPECT_TRUE (iRet == dsErrorFree || iRet == dsFramePending); | 337 | EXPECT_TRUE (iRet == dsErrorFree || iRet == dsFramePending); |
| 330 | iBufPos += iSliceSize; | 338 | iBufPos += iSliceSize; |
| 331 | ++iSliceIndex; | 339 | ++iSliceIndex; |
| 332 | if (iSliceIndex == 4) | 340 | if (iSliceIndex == 4) |
| 333 | break; | 341 | break; |
| 334 | } | 342 | } |
| 343 | if (eDecCase == ErrorDec) | ||
| 344 | EXPECT_TRUE ((iRet & (dsBitstreamError | dsRefLost | dsDataErrorConcealed)) != 0) << iRet; | ||
| 335 | 345 | ||
| 336 | fclose (pH264File); | 346 | fclose (pH264File); |
| 337 | if (pBuf) { | 347 | if (pBuf) { |
| @@ -366,7 +376,7 @@ void DecoderParseSyntaxTest::TestScalingList() { · 28 unmodified lines | |||
| 366 | int32_t iRet = ERR_NONE; | 376 | int32_t iRet = ERR_NONE; |
| 367 | iRet = Init(); | 377 | iRet = Init(); |
| 368 | ASSERT_EQ (iRet, ERR_NONE); | 378 | ASSERT_EQ (iRet, ERR_NONE); |
| 369 | ASSERT_TRUE (DecodeBs ("res/BA_MW_D.264")); | 379 | ASSERT_TRUE (DecodeBs ("res/BA_MW_D.264", CorrectDec)); |
| 370 | ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag == false); | 380 | ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag == false); |
| 371 | EXPECT_EQ (0, memcmp (iScalingListZero, m_pCtx->sSpsBuffer[0].iScalingList4x4, 6 * 16 * sizeof (uint8_t))); | 381 | EXPECT_EQ (0, memcmp (iScalingListZero, m_pCtx->sSpsBuffer[0].iScalingList4x4, 6 * 16 * sizeof (uint8_t))); |
| 372 | ASSERT_TRUE (m_pCtx->sPpsBuffer[0].bPicScalingMatrixPresentFlag == false); | 382 | ASSERT_TRUE (m_pCtx->sPpsBuffer[0].bPicScalingMatrixPresentFlag == false); |
| @@ -375,7 +385,7 @@ void DecoderParseSyntaxTest::TestScalingList() { · 2 unmodified lines | |||
| 375 | //Scalinglist value just written into sps and pps | 385 | //Scalinglist value just written into sps and pps |
| 376 | iRet = Init(); | 386 | iRet = Init(); |
| 377 | ASSERT_EQ (iRet, ERR_NONE); | 387 | ASSERT_EQ (iRet, ERR_NONE); |
| 378 | ASSERT_TRUE (DecodeBs ("res/test_scalinglist_jm.264")); | 388 | ASSERT_TRUE (DecodeBs ("res/test_scalinglist_jm.264", CorrectDec)); |
| 379 | ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag); | 389 | ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag); |
| 380 | for (int i = 0; i < 6; i++) { | 390 | for (int i = 0; i < 6; i++) { |
| 381 | EXPECT_EQ (0, memcmp (iScalingList[i], m_pCtx->sSpsBuffer[0].iScalingList4x4[i], 16 * sizeof (uint8_t))); | 391 | EXPECT_EQ (0, memcmp (iScalingList[i], m_pCtx->sSpsBuffer[0].iScalingList4x4[i], 16 * sizeof (uint8_t))); |
| @@ -390,20 +400,28 @@ void DecoderParseSyntaxTest::TestScalingList() { · 8 unmodified lines | |||
| 390 | 400 | ||
| 391 | void DecoderParseSyntaxTest::TestSpecificBs() { | 401 | void DecoderParseSyntaxTest::TestSpecificBs() { |
| 392 | int32_t iRet = ERR_NONE; | 402 | int32_t iRet = ERR_NONE; |
| 393 | Uninit(); | ||
| 394 | m_sDecParam.bParseOnly = true; | 403 | m_sDecParam.bParseOnly = true; |
| 395 | m_sDecParam.eEcActiveIdc = ERROR_CON_DISABLE; | 404 | m_sDecParam.eEcActiveIdc = ERROR_CON_DISABLE; |
| 396 | iRet = m_pDec->Initialize (&m_sDecParam); | 405 | iRet = m_pDec->Initialize (&m_sDecParam); |
| 397 | ASSERT_EQ (iRet, ERR_NONE); | 406 | ASSERT_EQ (iRet, ERR_NONE); |
| 398 | ASSERT_TRUE (ParseBs ("res/jm_1080p_allslice.264")); | 407 | ASSERT_TRUE (ParseBs ("res/jm_1080p_allslice.264", CorrectParseOnly)); |
| 399 | m_pDec->Uninitialize(); | 408 | m_pDec->Uninitialize(); |
| 400 | //Uninit(); | ||
| 401 | } | 409 | } |
| 410 | |||
| 411 | void DecoderParseSyntaxTest::TestSpecificBsError() { | ||
| 412 | int32_t iRet = ERR_NONE; | ||
| 413 | Init(); | ||
| 414 | ASSERT_EQ (iRet, ERR_NONE); | ||
| 415 | ASSERT_TRUE (DecodeBs ("res/Cisco_Men_whisper_640x320_CAVLC_Bframe_9.264", ErrorDec)); | ||
| 416 | Uninit(); | ||
| 417 | } | ||
| 418 | |||
| 402 | //TEST here for whole tests | 419 | //TEST here for whole tests |
| 403 | TEST_F (DecoderParseSyntaxTest, DecoderParseSyntaxTestAll) { | 420 | TEST_F (DecoderParseSyntaxTest, DecoderParseSyntaxTestAll) { |
| 404 | 421 | ||
| 405 | TestScalingList(); | 422 | TestScalingList(); |
| 406 | TestSpecificBs(); | 423 | TestSpecificBs(); |
| 424 | TestSpecificBsError(); | ||
| 407 | } | 425 | } |
| 408 | 426 | ||
| 409 | 427 | ||