shithub: openh264

Download patch

ref: b51ff5138779f24c9cec6415f32d1242da2baada
parent: 40015510279615b041a0c0bab7d5195088e2cf56
parent: 15124b125841e58cc28721d3ad11b4f6589d8a33
author: huili2 <huili2@cisco.com>
date: Mon Sep 15 05:15:28 EDT 2014

Merge pull request #1350 from lyao2/ut_interface2

add encoder Interface additional option set test 

--- a/test/encoder/EncUT_EncoderExt.cpp
+++ b/test/encoder/EncUT_EncoderExt.cpp
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include "codec_api.h"
 #include "codec_app_def.h"
+#include "svc_enc_slice_segment.h"
 #include "test_stdint.h"
 //TODO: consider using BaseEncoderTest class from #include "../BaseEncoderTest.h"
 
@@ -57,6 +58,7 @@
   }
 
   void InitializeParamExt();
+  void SetRandomParams();
   void TemporalLayerSettingTest();
   void MemoryCheckTest();
   void EncodeOneFrame (SEncParamBase* pEncParamBase);
@@ -65,12 +67,10 @@
 
  public:
   ISVCEncoder* pPtrEnc;
-
   SEncParamExt* pParamExt;
   SSourcePicture* pSrcPic;
   SEncParamExt* pOption;
   unsigned char* pYUV;
-
   SFrameBSInfo sFbi;
 
   int m_iWidth;
@@ -84,9 +84,13 @@
   pSrcPic->iPicWidth = pParamExt->iPicWidth;
   pSrcPic->iPicHeight = pParamExt->iPicHeight;
 
-  for (int i = 0; i < m_iPicResSize; i++)
-    pYUV[i] = rand() % 256;
-
+  pYUV[0] = rand() % 256;
+  for (int i = 1; i < m_iPicResSize; i++){
+    if((i%256) == 0)
+      pYUV[i] = rand() % 256;
+    else
+      pYUV[i] = WELS_CLIP3(pYUV[i-1]+(rand()%3)-1,0,255);
+  }
   pSrcPic->iStride[0] = m_iWidth;
   pSrcPic->iStride[1] = pSrcPic->iStride[2] = pSrcPic->iStride[0] >> 1;
 
@@ -94,7 +98,6 @@
   pSrcPic->pData[1] = pSrcPic->pData[0] + (m_iWidth * m_iHeight);
   pSrcPic->pData[2] = pSrcPic->pData[1] + (m_iWidth * m_iHeight >> 2);
 
-  //clean the output
   memset (&sFbi, 0, sizeof (SFrameBSInfo));
 }
 
@@ -136,6 +139,115 @@
   pParamExt->sSpatialLayers[0].iSpatialBitrate = 50000;
 }
 
+TEST_F (EncoderInterfaceTest, EncoderAdditionalOptionSetTest) {
+  int iResult, iValue, iReturn;
+  float fValue, fReturn;
+
+  InitializeParamExt();
+  iResult = pPtrEnc->InitializeExt (pParamExt);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+
+  PrepareOneSrcFrame();
+
+  ENCODER_OPTION eOptionId = ENCODER_OPTION_DATAFORMAT;
+  iValue = rand() % 256;
+  iResult = pPtrEnc->SetOption (eOptionId, &iValue);
+
+  if (iValue ==0)
+    EXPECT_EQ (iResult, static_cast<int> (cmInitParaError));
+  else
+    EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+
+  iResult = pPtrEnc->GetOption (eOptionId, &iReturn);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  EXPECT_EQ (iValue, iReturn);
+
+  iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  pSrcPic->uiTimeStamp += 30;
+
+  eOptionId = ENCODER_OPTION_IDR_INTERVAL;
+  iValue = rand() % 256 - 5;
+  iResult = pPtrEnc->SetOption (eOptionId, &iValue);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+
+  iResult = pPtrEnc->GetOption (eOptionId, &iReturn);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  if (iValue < -1 || iValue == 0)
+    iValue = 1;
+  EXPECT_EQ (iValue, iReturn);
+
+  PrepareOneSrcFrame();
+  iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  pSrcPic->uiTimeStamp += 30;
+
+  eOptionId = ENCODER_OPTION_FRAME_RATE;
+  fValue = static_cast<int> (rand() % 60 - 5);
+  iResult = pPtrEnc->SetOption (eOptionId, &fValue);
+
+  if (fValue <=0)
+    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);
+  }
+  PrepareOneSrcFrame();
+  iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  pSrcPic->uiTimeStamp += 30;
+
+  eOptionId = ENCODER_OPTION_BITRATE;
+  SBitrateInfo sInfo,sReturn;
+  sInfo.iBitrate = rand() % 100000 - 100;
+  sInfo.iLayer = static_cast<LAYER_NUM>(pParamExt->iSpatialLayerNum);
+  iResult = pPtrEnc->SetOption (eOptionId, &sInfo);
+  if (sInfo.iBitrate <=0)
+    EXPECT_EQ (iResult, static_cast<int> (cmInitParaError));
+  else{
+    EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+    sReturn.iLayer = static_cast<LAYER_NUM>(pParamExt->iSpatialLayerNum);
+    iResult = pPtrEnc->GetOption (eOptionId, &sReturn);
+    EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+    EXPECT_EQ (WELS_CLIP3 (sInfo.iBitrate, 1, 2147483647), sReturn.iBitrate);
+  }
+  PrepareOneSrcFrame();
+  iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  pSrcPic->uiTimeStamp += 30;
+
+  eOptionId = ENCODER_OPTION_MAX_BITRATE;
+  sInfo.iBitrate = rand() % 100000 - 100;
+  sInfo.iLayer = static_cast<LAYER_NUM>(pParamExt->iSpatialLayerNum);
+  iResult = pPtrEnc->SetOption (eOptionId, &sInfo);
+  if (sInfo.iBitrate <=0)
+    EXPECT_EQ (iResult, static_cast<int> (cmInitParaError));
+  else{
+    EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+    sReturn.iLayer = static_cast<LAYER_NUM>(pParamExt->iSpatialLayerNum);
+    iResult = pPtrEnc->GetOption (eOptionId, &sReturn);
+    EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+    EXPECT_EQ (WELS_CLIP3 (sInfo.iBitrate, 1, 2147483647), sReturn.iBitrate);
+  }
+  PrepareOneSrcFrame();
+  iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  pSrcPic->uiTimeStamp += 30;
+
+  eOptionId = ENCODER_OPTION_RC_MODE;
+  iValue = (rand() % 4) - 1;
+  iResult = pPtrEnc->SetOption (eOptionId, &iValue);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+
+  PrepareOneSrcFrame();
+  iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  pSrcPic->uiTimeStamp += 30;
+}
+
 TEST_F (EncoderInterfaceTest, TemporalLayerSettingTest) {
 
   pParamExt->iPicWidth = 1280;
@@ -224,7 +336,7 @@
         pOption->iTemporalLayerNum--;
       }
       iResult = pPtrEnc->SetOption (eOptionId, pOption);
-      EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess));
+      EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
       pSrcPic->uiTimeStamp += 30;
     }
 
@@ -234,7 +346,7 @@
       pYUV[j] = rand() % 256;
 
     iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
-    EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess));
+    EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
     pSrcPic->uiTimeStamp += 30;
   }