shithub: openh264

Download patch

ref: 849a73060818316b0ffef3a7edf5c099275ff883
parent: 24bd0b74ae51ee42ff061b7b9813e0ab70331102
author: lyao2 <[email protected]>
date: Mon Sep 1 13:49:59 EDT 2014

refine code

--- a/test/encoder/EncUT_EncoderExt.cpp
+++ b/test/encoder/EncUT_EncoderExt.cpp
@@ -174,7 +174,7 @@
   iResult = pPtrEnc->GetOption (eOptionId, &iReturn);
   EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
   EXPECT_EQ (iValue, iReturn);
-  
+
   PrepareOneSrcFrame();
   iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
   EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
@@ -188,7 +188,7 @@
     EXPECT_EQ (iResult, static_cast<int> (cmInitParaError));
   else{
     EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
-    
+
     iResult = pPtrEnc->GetOption (eOptionId, &fReturn);
     EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
     EXPECT_EQ (WELS_CLIP3 (fValue, 1, 30), fReturn);
@@ -248,8 +248,10 @@
 
 TEST_F (EncoderInterfaceTest, TemporalLayerSettingTest) {
 
-  pParamExt->iPicWidth = m_iWidth;
-  pParamExt->iPicHeight = m_iHeight;
+  pParamExt->iPicWidth = 1280;
+  pParamExt->iPicHeight = 720;
+  m_iWidth = pParamExt->iPicWidth;
+  m_iHeight = pParamExt->iPicHeight;
   pParamExt->iTargetBitrate = 60000;
   pParamExt->sSpatialLayers[0].iVideoHeight = pParamExt->iPicHeight;
   pParamExt->sSpatialLayers[0].iVideoWidth = pParamExt->iPicWidth;
@@ -256,11 +258,10 @@
   pParamExt->sSpatialLayers[0].iSpatialBitrate = 50000;
   pParamExt->iTemporalLayerNum = 1;
   pParamExt->iSpatialLayerNum = 1;
-  int iResult;
 
   for(int i = 0; i < 2; i++){
     pParamExt->iUsageType = (( i == 0 ) ? SCREEN_CONTENT_REAL_TIME : CAMERA_VIDEO_REAL_TIME);
-    iResult = pPtrEnc->InitializeExt (pParamExt);
+    int iResult = pPtrEnc->InitializeExt (pParamExt);
     EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
 
     PrepareOneSrcFrame();
@@ -305,6 +306,46 @@
 
     iResult = pPtrEnc->Uninitialize();
     EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  }
+
+  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();