ref: 832bf7c45d461d3505aad76083efee8596da4649
parent: 010e423b2b589efa45b9d6acf790ee0c82da125f
parent: d633f8584af5bb19b86d53f17f9d7e431aeba84f
author: ruil2 <[email protected]>
date: Tue Jul 15 12:37:27 EDT 2014
Merge pull request #1176 from lyao2/ut_memcheck add interface UT for memory align check
--- a/test/encoder/EncUT_EncoderExt.cpp
+++ b/test/encoder/EncUT_EncoderExt.cpp
@@ -53,6 +53,7 @@
}
void TemporalLayerSettingTest();
+ void MemoryCheckTest();
void EncodeOneFrame (SEncParamBase* pEncParamBase);
void PrepareOneSrcFrame();
void EncodeOneIDRandP (ISVCEncoder* pPtrEnc);
@@ -130,54 +131,141 @@
pParamExt->iTemporalLayerNum = 1;
pParamExt->iSpatialLayerNum = 1;
+ for(int i = 0; i < 2; i++){
+ pParamExt->iUsageType = (( i == 0 ) ? SCREEN_CONTENT_REAL_TIME : CAMERA_VIDEO_REAL_TIME);
+ int iResult = pPtrEnc->InitializeExt (pParamExt);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+
+ PrepareOneSrcFrame();
+
+ iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
+
+ pSrcPic->uiTimeStamp = 30;
+ iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP));
+
+ memcpy (pOption, pParamExt, sizeof (SEncParamExt));
+ pOption ->iTemporalLayerNum = 4;
+
+ ENCODER_OPTION eOptionId = ENCODER_OPTION_SVC_ENCODE_PARAM_EXT;
+ iResult = pPtrEnc->SetOption (eOptionId, pOption);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+
+ pSrcPic->uiTimeStamp = 60;
+ iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
+
+ pOption ->iTemporalLayerNum = 2;
+ iResult = pPtrEnc->SetOption (eOptionId, pOption);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ pSrcPic->uiTimeStamp = 90;
+ iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP));
+
+ pOption ->iTemporalLayerNum = 4;
+ iResult = pPtrEnc->SetOption (eOptionId, pOption);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ pSrcPic->uiTimeStamp = 120;
+ iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP));
+
+ pPtrEnc->Uninitialize();
+ }
+}
+
+TEST_F (EncoderInterfaceTest, TestTemporalLayerSetting) {
+ TemporalLayerSettingTest();
+}
+
+void EncoderInterfaceTest::MemoryCheckTest() {
+ #define MEM_VARY_SIZE 1024
+ #define IMAGE_VARY_SIZE 512
+ #define TEST_FRAMES 500
+
+ pParamExt->iPicWidth = 1280;
+ pParamExt->iPicHeight = 720;
+ pParamExt->iTargetBitrate = 60000;
+ pParamExt->sSpatialLayers[0].iVideoHeight = pParamExt->iPicHeight;
+ pParamExt->sSpatialLayers[0].iVideoWidth = pParamExt->iPicWidth;
+ pParamExt->sSpatialLayers[0].iSpatialBitrate = 50000;
+ pParamExt->iTemporalLayerNum = 3;
+ pParamExt->iSpatialLayerNum = 1;
+
int iResult = pPtrEnc->InitializeExt (pParamExt);
- EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ const int kiFrameNumber = TEST_FRAMES;
+ m_iWidth = pParamExt->iPicWidth;
+ m_iHeight = pParamExt->iPicHeight;
+ m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1;
+ delete []pYUV;
+ pYUV = new unsigned char [m_iPicResSize];
PrepareOneSrcFrame();
- iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
- EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
- EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
+ for(int i = 0; i < kiFrameNumber; i ++){
+ int iStartX = rand() % (m_iPicResSize >> 1);
+ int iEndX = (iStartX + (rand() % MEM_VARY_SIZE)) % m_iPicResSize;
+ for (int j = iStartX; j < iEndX; j++)
+ pYUV[j] = rand() % 256;
- pSrcPic->uiTimeStamp = 30;
- iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
- EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
- EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP));
+ iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ pSrcPic->uiTimeStamp += 30;
+ }
- memcpy (pOption, pParamExt, sizeof (SEncParamExt));
- pOption ->iTemporalLayerNum = 4;
+ pParamExt->iPicWidth += (rand() << 1) % IMAGE_VARY_SIZE;
+ pParamExt->iPicHeight += (rand() << 1) % IMAGE_VARY_SIZE;
+ m_iWidth = pParamExt->iPicWidth;
+ m_iHeight = pParamExt->iPicHeight;
+ m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1;
+ delete []pYUV;
+ pYUV = new unsigned char [m_iPicResSize];
+ iResult = pPtrEnc->InitializeExt (pParamExt);
+ PrepareOneSrcFrame();
+
ENCODER_OPTION eOptionId = ENCODER_OPTION_SVC_ENCODE_PARAM_EXT;
+ memcpy (pOption, pParamExt, sizeof (SEncParamExt));
+ pOption ->iPicWidth = m_iWidth;
+ pOption ->iPicHeight = m_iHeight;
iResult = pPtrEnc->SetOption (eOptionId, pOption);
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
- pSrcPic->uiTimeStamp = 60;
- iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
- EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
- EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
+ for(int i = 0; i < kiFrameNumber; i ++){
+ int iStartX = rand() % (m_iPicResSize >> 1);
+ int iEndX = (iStartX + (rand() % MEM_VARY_SIZE)) % m_iPicResSize;
+ for (int j = iStartX; j < iEndX; j++)
+ pYUV[j] = rand() % 256;
- pOption ->iTemporalLayerNum = 2;
- iResult = pPtrEnc->SetOption (eOptionId, pOption);
- EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
- pSrcPic->uiTimeStamp = 90;
- iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
- EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
- EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP));
+ iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ pSrcPic->uiTimeStamp += 30;
+ }
- pOption ->iTemporalLayerNum = 4;
+ pOption ->iLTRRefNum += rand() % 8 + 1;
iResult = pPtrEnc->SetOption (eOptionId, pOption);
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
- pSrcPic->uiTimeStamp = 120;
- iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
- EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
- EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP));
- pPtrEnc->Uninitialize();
+ for(int i = 0; i < kiFrameNumber; i ++){
+ int iStartX = rand() % (m_iPicResSize >> 1);
+ int iEndX = (iStartX + (rand() % MEM_VARY_SIZE)) % m_iPicResSize;
+ for (int j = iStartX; j < iEndX; j++)
+ pYUV[j] = rand() % 256;
+ iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ pSrcPic->uiTimeStamp += 30;
+ }
+ pPtrEnc->Uninitialize();
}
-TEST_F (EncoderInterfaceTest, TestTemporalLayerSetting) {
- TemporalLayerSettingTest();
+TEST_F (EncoderInterfaceTest, MemoryCheck) {
+ MemoryCheckTest();
}
void GetValidEncParamBase (SEncParamBase* pEncParamBase) {
@@ -210,7 +298,7 @@
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
- pPtrEnc->Uninitialize();
+ iResult = pPtrEnc->Uninitialize();
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
}