Make sure the random test bitrate is high enough
Showing the changes to test/decoder/DecUT_ParseSyntax.cpp (1 of 16 files). Show all
Unified · Split
| @@ -0,0 +1,278 @@ | ||
| 1 | +#include <gtest/gtest.h> | |
| 2 | +#include "codec_app_def.h" | |
| 3 | +#include "codec_api.h" | |
| 4 | +#include "decoder_context.h" | |
| 5 | +#include "decoder.h" | |
| 6 | +#include "decoder_core.h" | |
| 7 | +#include "welsCodecTrace.h" | |
| 8 | +#include "../../common/src/welsCodecTrace.cpp" | |
| 9 | + | |
| 10 | +using namespace WelsDec; | |
| 11 | + | |
| 12 | +#define BUF_SIZE 100 | |
| 13 | + | |
| 14 | +DECODING_STATE DecodeFrame (const unsigned char* kpSrc, | |
| 15 | + const int kiSrcLen, | |
| 16 | + unsigned char** ppDst, | |
| 17 | + SBufferInfo* pDstInfo, | |
| 18 | + PWelsDecoderContext pCtx) { | |
| 19 | + | |
| 20 | + PWelsDecoderContext m_pDecContext = pCtx; | |
| 21 | + if (CheckBsBuffer (m_pDecContext, kiSrcLen)) { | |
| 22 | + return dsOutOfMemory; | |
| 23 | + } | |
| 24 | + if (kiSrcLen > 0 && kpSrc != NULL) { | |
| 25 | + m_pDecContext->bEndOfStreamFlag = false; | |
| 26 | + } else { | |
| 27 | + //For application MODE, the error detection should be added for safe. | |
| 28 | + //But for CONSOLE MODE, when decoding LAST AU, kiSrcLen==0 && kpSrc==NULL. | |
| 29 | + m_pDecContext->bEndOfStreamFlag = true; | |
| 30 | + m_pDecContext->bInstantDecFlag = true; | |
| 31 | + } | |
| 32 | + | |
| 33 | + | |
| 34 | + ppDst[0] = ppDst[1] = ppDst[2] = NULL; | |
| 35 | + m_pDecContext->iErrorCode = dsErrorFree; //initialize at the starting of AU decoding. | |
| 36 | + m_pDecContext->iFeedbackVclNalInAu = FEEDBACK_UNKNOWN_NAL; //initialize | |
| 37 | + unsigned long long uiInBsTimeStamp = pDstInfo->uiInBsTimeStamp; | |
| 38 | + memset (pDstInfo, 0, sizeof (SBufferInfo)); | |
| 39 | + pDstInfo->uiInBsTimeStamp = uiInBsTimeStamp; | |
| 40 | + | |
| 41 | + m_pDecContext->bReferenceLostAtT0Flag = false; //initialize for LTR | |
| 42 | + m_pDecContext->bCurAuContainLtrMarkSeFlag = false; | |
| 43 | + m_pDecContext->iFrameNumOfAuMarkedLtr = 0; | |
| 44 | + m_pDecContext->iFrameNum = -1; //initialize | |
| 45 | + | |
| 46 | + | |
| 47 | + m_pDecContext->iFeedbackTidInAu = -1; //initialize | |
| 48 | + if (pDstInfo) { | |
| 49 | + pDstInfo->uiOutYuvTimeStamp = 0; | |
| 50 | + m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp; | |
| 51 | + } else { | |
| 52 | + m_pDecContext->uiTimeStamp = 0; | |
| 53 | + } | |
| 54 | + WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, ppDst, | |
| 55 | + pDstInfo, NULL); //iErrorCode has been modified in this function | |
| 56 | + m_pDecContext->bInstantDecFlag = false; //reset no-delay flag | |
| 57 | + | |
| 58 | + return dsErrorFree; | |
| 59 | +} | |
| 60 | + | |
| 61 | + | |
| 62 | +int32_t InitDecoder (const bool bParseOnly, PWelsDecoderContext pCtx, SLogContext* pLogCtx) { | |
| 63 | + | |
| 64 | + | |
| 65 | + if (NULL == pCtx) | |
| 66 | + return cmMallocMemeError; | |
| 67 | + | |
| 68 | + | |
| 69 | + return WelsInitDecoder (pCtx, bParseOnly, pLogCtx); | |
| 70 | +} | |
| 71 | + | |
| 72 | +long Initialize (const SDecodingParam* pParam, PWelsDecoderContext pCtx, SLogContext* pLogCtx) { | |
| 73 | + int iRet = ERR_NONE; | |
| 74 | + if (pParam == NULL) { | |
| 75 | + return cmInitParaError; | |
| 76 | + } | |
| 77 | + | |
| 78 | + // H.264 decoder initialization,including memory allocation,then open it ready to decode | |
| 79 | + iRet = InitDecoder (pParam->bParseOnly, pCtx, pLogCtx); | |
| 80 | + if (iRet) | |
| 81 | + return iRet; | |
| 82 | + | |
| 83 | + iRet = DecoderConfigParam (pCtx, pParam); | |
| 84 | + if (iRet) | |
| 85 | + return iRet; | |
| 86 | + | |
| 87 | + return cmResultSuccess; | |
| 88 | +} | |
| 89 | + | |
| 90 | +void UninitDecoder (PWelsDecoderContext pCtx) { | |
| 91 | + if (NULL == pCtx) | |
| 92 | + return; | |
| 93 | + | |
| 94 | + WelsEndDecoder (pCtx); | |
| 95 | + if (NULL != pCtx) { | |
| 96 | + free (pCtx); | |
| 97 | + pCtx = NULL; | |
| 98 | + } | |
| 99 | + | |
| 100 | +} | |
| 101 | +class DecoderParseSyntaxTest : public ::testing::Test { | |
| 102 | + public: | |
| 103 | + virtual void SetUp() { | |
| 104 | + | |
| 105 | + int rv = WelsCreateDecoder (&m_pDec); | |
| 106 | + ASSERT_EQ (0, rv); | |
| 107 | + ASSERT_TRUE (m_pDec != NULL); | |
| 108 | + } | |
| 109 | + | |
| 110 | + virtual void TearDown() { | |
| 111 | + if (m_pDec) { | |
| 112 | + WelsDestroyDecoder (m_pDec); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + //Init members | |
| 116 | + void Init(); | |
| 117 | + //Uninit members | |
| 118 | + void Uninit(); | |
| 119 | + //Decoder real bitstream | |
| 120 | +// void DecoderBs (const char* sFileName); | |
| 121 | + //Parse real bitstream | |
| 122 | + void DecodeBs (const char* sFileName); | |
| 123 | + //Scalinglist | |
| 124 | + void TestScalingList(); | |
| 125 | + //Do whole tests here | |
| 126 | + void DecoderParseSyntaxTestAll(); | |
| 127 | + | |
| 128 | + | |
| 129 | + public: | |
| 130 | + ISVCDecoder* m_pDec; | |
| 131 | + SDecodingParam m_sDecParam; | |
| 132 | + SBufferInfo m_sBufferInfo; | |
| 133 | + SParserBsInfo m_sParserBsInfo; | |
| 134 | + uint8_t* m_pData[3]; | |
| 135 | + unsigned char m_szBuffer[BUF_SIZE]; //for mocking packet | |
| 136 | + int m_iBufLength; //record the valid data in m_szBuffer | |
| 137 | + PWelsDecoderContext m_pCtx; | |
| 138 | + welsCodecTrace* m_pWelsTrace; | |
| 139 | + | |
| 140 | +}; | |
| 141 | + | |
| 142 | +//Init members | |
| 143 | +void DecoderParseSyntaxTest::Init() { | |
| 144 | + memset (&m_sBufferInfo, 0, sizeof (SBufferInfo)); | |
| 145 | + memset (&m_sDecParam, 0, sizeof (SDecodingParam)); | |
| 146 | + memset (&m_sParserBsInfo, 0, sizeof (SParserBsInfo)); | |
| 147 | + m_sDecParam.pFileNameRestructed = NULL; | |
| 148 | + m_sDecParam.eOutputColorFormat = videoFormatI420; | |
| 149 | + m_sDecParam.uiCpuLoad = rand() % 100; | |
| 150 | + m_sDecParam.uiTargetDqLayer = rand() % 100; | |
| 151 | + m_sDecParam.eEcActiveIdc = (ERROR_CON_IDC)7; | |
| 152 | + m_sDecParam.sVideoProperty.size = sizeof (SVideoProperty); | |
| 153 | + m_sDecParam.sVideoProperty.eVideoBsType = (VIDEO_BITSTREAM_TYPE) (rand() % 3); | |
| 154 | + m_sDecParam.bParseOnly = false; | |
| 155 | + | |
| 156 | + m_pData[0] = m_pData[1] = m_pData[2] = NULL; | |
| 157 | + m_szBuffer[0] = m_szBuffer[1] = m_szBuffer[2] = 0; | |
| 158 | + m_szBuffer[3] = 1; | |
| 159 | + m_iBufLength = 4; | |
| 160 | + // | |
| 161 | + m_pCtx = (PWelsDecoderContext)malloc (sizeof (SWelsDecoderContext)); | |
| 162 | + | |
| 163 | + m_pWelsTrace = new welsCodecTrace(); | |
| 164 | + if (m_pWelsTrace != NULL) { | |
| 165 | + m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR); | |
| 166 | + } | |
| 167 | + CM_RETURN eRet = (CM_RETURN)Initialize (&m_sDecParam, m_pCtx, &m_pWelsTrace->m_sLogCtx); | |
| 168 | +} | |
| 169 | + | |
| 170 | +void DecoderParseSyntaxTest::Uninit() { | |
| 171 | + if (m_pCtx) { | |
| 172 | + UninitDecoder (m_pCtx); | |
| 173 | + } | |
| 174 | + if (m_pWelsTrace) { | |
| 175 | + delete m_pWelsTrace; | |
| 176 | + m_pWelsTrace = NULL; | |
| 177 | + } | |
| 178 | + memset (&m_sDecParam, 0, sizeof (SDecodingParam)); | |
| 179 | + memset (&m_sBufferInfo, 0, sizeof (SBufferInfo)); | |
| 180 | + m_pData[0] = m_pData[1] = m_pData[2] = NULL; | |
| 181 | + m_iBufLength = 0; | |
| 182 | +} | |
| 183 | + | |
| 184 | +void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { | |
| 185 | + | |
| 186 | + uint8_t* pBuf = NULL; | |
| 187 | + int32_t iBufPos = 0; | |
| 188 | + int32_t iFileSize; | |
| 189 | + int32_t i = 0; | |
| 190 | + int32_t iSliceSize; | |
| 191 | + int32_t iSliceIndex = 0; | |
| 192 | + int32_t iEndOfStreamFlag = 0; | |
| 193 | + FILE* pH264File; | |
| 194 | + uint8_t uiStartCode[4] = {0, 0, 0, 1}; | |
| 195 | + | |
| 196 | +#if defined(ANDROID_NDK) | |
| 197 | + std::string filename = std::string ("/sdcard/") + sFileName; | |
| 198 | + ASSERT_TRUE (pH264File = fopen (filename.c_str(), "rb")); | |
| 199 | +#else | |
| 200 | + ASSERT_TRUE (pH264File = fopen (sFileName, "rb")); | |
| 201 | +#endif | |
| 202 | + fseek (pH264File, 0L, SEEK_END); | |
| 203 | + iFileSize = (int32_t) ftell (pH264File); | |
| 204 | + fseek (pH264File, 0L, SEEK_SET); | |
| 205 | + pBuf = new uint8_t[iFileSize + 4]; | |
| 206 | + ASSERT_EQ (fread (pBuf, 1, iFileSize, pH264File), (unsigned int) iFileSize); | |
| 207 | + memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage | |
| 208 | + while (true) { | |
| 209 | + if (iBufPos >= iFileSize) { | |
| 210 | + iEndOfStreamFlag = true; | |
| 211 | + if (iEndOfStreamFlag) | |
| 212 | + m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, (void*)&iEndOfStreamFlag); | |
| 213 | + break; | |
| 214 | + } | |
| 215 | + for (i = 0; i < iFileSize; i++) { | |
| 216 | + if ((pBuf[iBufPos + i] == 0 && pBuf[iBufPos + i + 1] == 0 && pBuf[iBufPos + i + 2] == 0 && pBuf[iBufPos + i + 3] == 1 | |
| 217 | + && i > 0)) { | |
| 218 | + break; | |
| 219 | + } | |
| 220 | + } | |
| 221 | + iSliceSize = i; | |
| 222 | + DecodeFrame (pBuf + iBufPos, iSliceSize, m_pData, &m_sBufferInfo, m_pCtx); | |
| 223 | + iBufPos += iSliceSize; | |
| 224 | + ++ iSliceIndex; | |
| 225 | + if (iSliceIndex == 4) | |
| 226 | + break; | |
| 227 | + } | |
| 228 | + | |
| 229 | + fclose (pH264File); | |
| 230 | + if (pBuf) { | |
| 231 | + delete[] pBuf; | |
| 232 | + pBuf = NULL; | |
| 233 | + } | |
| 234 | + | |
| 235 | + | |
| 236 | +} | |
| 237 | +void DecoderParseSyntaxTest::TestScalingList() { | |
| 238 | + uint8_t iScalingList[6][16] = { | |
| 239 | + {17, 17, 16, 16, 17, 16, 15, 15, 16, 15, 15, 15, 16, 15, 15, 15 }, | |
| 240 | + { 6, 12, 19, 26, 12, 19, 26, 31, 19, 26, 31, 35, 26, 31, 35, 39 }, | |
| 241 | + { 6, 12, 19, 26, 12, 19, 26, 31, 19, 26, 31, 35, 26, 31, 35, 40 }, | |
| 242 | + {17, 17, 16, 16, 17, 16, 15, 15, 16, 15, 15, 15, 16, 15, 15, 14 }, | |
| 243 | + {10, 14, 20, 24, 14, 20, 24, 27, 20, 24, 27, 30, 24, 27, 30, 34 }, | |
| 244 | + { 9, 13, 18, 21, 13, 18, 21, 24, 18, 21, 24, 27, 21, 24, 27, 27 } | |
| 245 | + }; | |
| 246 | + uint8_t iScalingListPPS[6][16]; | |
| 247 | + memset (iScalingListPPS, 0, 6 * 16 * sizeof (uint8_t)); | |
| 248 | + //Scalinglist matrix not written into sps or pps | |
| 249 | + Init(); | |
| 250 | + DecodeBs ("res/BA_MW_D.264"); | |
| 251 | + ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag == false); | |
| 252 | + EXPECT_EQ (0, memcmp (iScalingListPPS, m_pCtx->sSpsBuffer[0].iScalingList4x4, 6 * 16 * sizeof (uint8_t)));; | |
| 253 | + ASSERT_TRUE (m_pCtx->sPpsBuffer[0].bSeqScalingMatrixPresentFlag == false); | |
| 254 | + EXPECT_EQ (0, memcmp (iScalingListPPS, m_pCtx->sPpsBuffer[0].iScalingList4x4, 6 * 16 * sizeof (uint8_t)));; | |
| 255 | + Uninit(); | |
| 256 | + //Scalinglist value just written into sps and pps | |
| 257 | + Init(); | |
| 258 | + DecodeBs ("test_scalinglist_jm.264"); | |
| 259 | + ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag); | |
| 260 | + for (int i = 0; i < 6; i++) { | |
| 261 | + EXPECT_EQ (0, memcmp (iScalingList[i], m_pCtx->sSpsBuffer[0].iScalingList4x4[i], 16 * sizeof (uint8_t))); | |
| 262 | + } | |
| 263 | + | |
| 264 | + ASSERT_TRUE (m_pCtx->sPpsBuffer[0].bSeqScalingMatrixPresentFlag); | |
| 265 | + EXPECT_EQ (0, memcmp (iScalingList, m_pCtx->sPpsBuffer[0].iScalingList4x4, 6 * 16 * sizeof (uint8_t))); | |
| 266 | + Uninit(); | |
| 267 | + | |
| 268 | + | |
| 269 | +} | |
| 270 | + | |
| 271 | +//TEST here for whole tests | |
| 272 | +TEST_F (DecoderParseSyntaxTest, DecoderParseSyntaxTestAll) { | |
| 273 | + | |
| 274 | + TestScalingList(); | |
| 275 | + | |
| 276 | +} | |
| 277 | + | |
| 278 | + | |