ref: 4d0c832b4767e918614c2a8505df4c494da919d3
parent: 7624b360f0a355dabac820a9e1f897386e5a2d71
parent: 562f38affffab0844e52df7fbc653595bc2848ec
author: ruil2 <[email protected]>
date: Fri Jul 25 09:06:05 EDT 2014
Merge pull request #1216 from lyao2/ut_bs_commit3 add interface UT for RC and code refactor
--- a/test/encoder/EncUT_EncoderExt.cpp
+++ b/test/encoder/EncUT_EncoderExt.cpp
@@ -9,6 +9,9 @@
#define MAX_WIDTH (3840)
#define MAX_HEIGHT (2160)
#define VALID_SIZE(iSize) (((iSize)>1)?(iSize):1)
+#define MEM_VARY_SIZE (512)
+#define IMAGE_VARY_SIZE (512)
+#define TEST_FRAMES (200)
#define NAL_HEADER_BYTES (4)
#define NAL_TYPE (0x0F)
@@ -52,6 +55,7 @@
}
}
+ void InitializeParamExt();
void TemporalLayerSettingTest();
void MemoryCheckTest();
void EncodeOneFrame (SEncParamBase* pEncParamBase);
@@ -120,8 +124,19 @@
EXPECT_NE (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
}
-void EncoderInterfaceTest::TemporalLayerSettingTest() {
+void EncoderInterfaceTest::InitializeParamExt() {
+ pParamExt->iPicWidth = 1280;
+ pParamExt->iPicHeight = 720;
+ pParamExt->iTargetBitrate = 50000;
+ pParamExt->iTemporalLayerNum = 3;
+ pParamExt->iSpatialLayerNum = 1;
+ pParamExt->sSpatialLayers[0].iVideoHeight = pParamExt->iPicHeight;
+ pParamExt->sSpatialLayers[0].iVideoWidth = pParamExt->iPicWidth;
+ pParamExt->sSpatialLayers[0].iSpatialBitrate = 50000;
+}
+TEST_F (EncoderInterfaceTest, TemporalLayerSettingTest) {
+
pParamExt->iPicWidth = m_iWidth;
pParamExt->iPicHeight = m_iHeight;
pParamExt->iTargetBitrate = 60000;
@@ -175,27 +190,60 @@
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP));
- pPtrEnc->Uninitialize();
+ iResult = pPtrEnc->Uninitialize();
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
}
-}
-TEST_F (EncoderInterfaceTest, TestTemporalLayerSetting) {
- TemporalLayerSettingTest();
+ InitializeParamExt();
+ pParamExt->iUsageType = (rand() % 2) ? SCREEN_CONTENT_REAL_TIME : CAMERA_VIDEO_REAL_TIME;
+ pParamExt->iRCMode = (rand() % 2) ? RC_BITRATE_MODE : RC_QUALITY_MODE;
+
+ int iResult = pPtrEnc->InitializeExt (pParamExt);
+ 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];
+ ASSERT_TRUE (pYUV != NULL);
+ PrepareOneSrcFrame();
+
+ ENCODER_OPTION eOptionId = ENCODER_OPTION_SVC_ENCODE_PARAM_EXT;
+ memcpy (pOption, pParamExt, sizeof (SEncParamExt));
+
+ for(int i = 0; i < kiFrameNumber; i ++){
+ if ((i%7) == 0){
+ if (pOption->iTemporalLayerNum<4){
+ pOption->iTemporalLayerNum++;
+ } else {
+ pOption->iTemporalLayerNum--;
+ }
+ iResult = pPtrEnc->SetOption (eOptionId, pOption);
+ EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess));
+ pSrcPic->uiTimeStamp += 30;
+ }
+
+ 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<int32_t> (cmResultSuccess));
+ pSrcPic->uiTimeStamp += 30;
+ }
+
+ iResult = pPtrEnc->Uninitialize();
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+
}
-void EncoderInterfaceTest::MemoryCheckTest() {
- #define MEM_VARY_SIZE 1024
- #define IMAGE_VARY_SIZE 512
- #define TEST_FRAMES 500
+TEST_F (EncoderInterfaceTest, MemoryCheckTest) {
+ InitializeParamExt();
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);
const int kiFrameNumber = TEST_FRAMES;
@@ -261,11 +309,9 @@
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
pSrcPic->uiTimeStamp += 30;
}
- pPtrEnc->Uninitialize();
-}
-TEST_F (EncoderInterfaceTest, MemoryCheck) {
- MemoryCheckTest();
+ iResult = pPtrEnc->Uninitialize();
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
}
void GetValidEncParamBase (SEncParamBase* pEncParamBase) {
@@ -498,11 +544,10 @@
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
EXPECT_NE (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
- pPtrEnc->Uninitialize();
+ iResult = pPtrEnc->Uninitialize();
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
}
TEST_F (EncoderInterfaceTest, BasicReturnTypeTest) {
//TODO
-}
-
+}
\ No newline at end of file