shithub: openh264

Download patch

ref: 54c24dfd604ee9765bb305b610bae8e045f30391
parent: c83ab3bca16bc6091692a81822d3db5a990c3ee8
author: huashi <huashi@cisco.com>
date: Wed Oct 29 09:50:18 EDT 2014

refactor --for BaseEncoderTest

--- a/test/BaseEncoderTest.h
+++ b/test/BaseEncoderTest.h
@@ -14,10 +14,8 @@
   BaseEncoderTest();
   void SetUp();
   void TearDown();
-  void EncodeFile (const char* fileName, EUsageType usageType, int width, int height, float frameRate,
-                   SliceModeEnum slices, bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac, Callback* cbk);
-  void EncodeStream (InputStream* in, EUsageType usageType, int width, int height, float frameRate, SliceModeEnum slices,
-                     bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac, Callback* cbk);
+  void EncodeFile (const char* fileName, SEncParamExt* pEncParamExt, Callback* cbk);
+  void EncodeStream (InputStream* in,  SEncParamExt* pEncParamExt, Callback* cbk);
 
   ISVCEncoder* encoder_;
  private:
--- a/test/api/BaseEncoderTest.cpp
+++ b/test/api/BaseEncoderTest.cpp
@@ -5,16 +5,20 @@
 #include "utils/FileInputStream.h"
 #include "BaseEncoderTest.h"
 
-static int InitWithParam (ISVCEncoder* encoder, EUsageType usageType, int width,
-                          int height, float frameRate, SliceModeEnum sliceMode, bool denoise, int layers, bool losslessLink, bool enableLtr,bool cabac) {
-  if (SM_SINGLE_SLICE == sliceMode && !denoise && layers == 1 && !losslessLink && !enableLtr &&!cabac) {
+static int InitWithParam (ISVCEncoder* encoder, SEncParamExt* pEncParamExt) {
+
+  SliceModeEnum eSliceMode = pEncParamExt->sSpatialLayers[0].sSliceCfg.uiSliceMode;
+  bool bBaseParamFlag      = (SM_SINGLE_SLICE == eSliceMode             && !pEncParamExt->bEnableDenoise
+                              && pEncParamExt->iSpatialLayerNum == 1     && !pEncParamExt->bIsLosslessLink
+                              && !pEncParamExt->bEnableLongTermReference && !pEncParamExt->iEntropyCodingModeFlag) ? true : false;
+  if (bBaseParamFlag) {
     SEncParamBase param;
     memset (&param, 0, sizeof (SEncParamBase));
 
-    param.iUsageType = usageType;
-    param.fMaxFrameRate = frameRate;
-    param.iPicWidth = width;
-    param.iPicHeight = height;
+    param.iUsageType     = pEncParamExt->iUsageType;
+    param.fMaxFrameRate  = pEncParamExt->fMaxFrameRate;
+    param.iPicWidth      = pEncParamExt->iPicWidth;
+    param.iPicHeight     = pEncParamExt->iPicHeight;
     param.iTargetBitrate = 5000000;
 
     return encoder->Initialize (&param);
@@ -22,27 +26,27 @@
     SEncParamExt param;
     encoder->GetDefaultParams (&param);
 
-    param.iUsageType = usageType;
-    param.fMaxFrameRate = frameRate;
-    param.iPicWidth = width;
-    param.iPicHeight = height;
-    param.iTargetBitrate = 5000000;
-    param.bEnableDenoise = denoise;
-    param.iSpatialLayerNum = layers;
-    param.bIsLosslessLink = losslessLink;
-    param.bEnableLongTermReference = enableLtr;
-    param.iEntropyCodingModeFlag = cabac?1:0;
-    if (sliceMode != SM_SINGLE_SLICE && sliceMode != SM_DYN_SLICE) //SM_DYN_SLICE don't support multi-thread now
+    param.iUsageType       = pEncParamExt->iUsageType;
+    param.fMaxFrameRate    = pEncParamExt->fMaxFrameRate;
+    param.iPicWidth        = pEncParamExt->iPicWidth;
+    param.iPicHeight       = pEncParamExt->iPicHeight;
+    param.iTargetBitrate   = 5000000;
+    param.bEnableDenoise   = pEncParamExt->bEnableDenoise;
+    param.iSpatialLayerNum = pEncParamExt->iSpatialLayerNum;
+    param.bIsLosslessLink  = pEncParamExt->bIsLosslessLink;
+    param.bEnableLongTermReference = pEncParamExt->bEnableLongTermReference;
+    param.iEntropyCodingModeFlag   = pEncParamExt->iEntropyCodingModeFlag ? 1 : 0;
+    if (eSliceMode != SM_SINGLE_SLICE && eSliceMode != SM_DYN_SLICE) //SM_DYN_SLICE don't support multi-thread now
       param.iMultipleThreadIdc = 2;
 
     for (int i = 0; i < param.iSpatialLayerNum; i++) {
-      param.sSpatialLayers[i].iVideoWidth = width >> (param.iSpatialLayerNum - 1 - i);
-      param.sSpatialLayers[i].iVideoHeight = height >> (param.iSpatialLayerNum - 1 - i);
-      param.sSpatialLayers[i].fFrameRate = frameRate;
+      param.sSpatialLayers[i].iVideoWidth     = pEncParamExt->iPicWidth  >> (param.iSpatialLayerNum - 1 - i);
+      param.sSpatialLayers[i].iVideoHeight    = pEncParamExt->iPicHeight >> (param.iSpatialLayerNum - 1 - i);
+      param.sSpatialLayers[i].fFrameRate      = pEncParamExt->fMaxFrameRate;
       param.sSpatialLayers[i].iSpatialBitrate = param.iTargetBitrate;
 
-      param.sSpatialLayers[i].sSliceCfg.uiSliceMode = sliceMode;
-      if (sliceMode == SM_DYN_SLICE) {
+      param.sSpatialLayers[i].sSliceCfg.uiSliceMode = eSliceMode;
+      if (eSliceMode == SM_DYN_SLICE) {
         param.sSpatialLayers[i].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 600;
         param.uiMaxNalSize = 1500;
       }
@@ -68,13 +72,15 @@
   }
 }
 
-void BaseEncoderTest::EncodeStream (InputStream* in, EUsageType usageType, int width, int height,
-                                    float frameRate, SliceModeEnum slices, bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac,Callback* cbk) {
-  int rv = InitWithParam (encoder_, usageType, width, height, frameRate, slices, denoise, layers, losslessLink, enableLtr,cabac);
+void BaseEncoderTest::EncodeStream (InputStream* in, SEncParamExt* pEncParamExt, Callback* cbk) {
+
+  ASSERT_TRUE (NULL != pEncParamExt);
+
+  int rv = InitWithParam (encoder_, pEncParamExt);
   ASSERT_TRUE (rv == cmResultSuccess);
 
   // I420: 1(Y) + 1/4(U) + 1/4(V)
-  int frameSize = width * height * 3 / 2;
+  int frameSize = pEncParamExt->iPicWidth * pEncParamExt->iPicHeight * 3 / 2;
 
   BufferedData buf;
   buf.SetLength (frameSize);
@@ -85,14 +91,14 @@
 
   SSourcePicture pic;
   memset (&pic, 0, sizeof (SSourcePicture));
-  pic.iPicWidth = width;
-  pic.iPicHeight = height;
+  pic.iPicWidth    = pEncParamExt->iPicWidth;
+  pic.iPicHeight   = pEncParamExt->iPicHeight;
   pic.iColorFormat = videoFormatI420;
-  pic.iStride[0] = pic.iPicWidth;
-  pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
-  pic.pData[0] = buf.data();
-  pic.pData[1] = pic.pData[0] + width * height;
-  pic.pData[2] = pic.pData[1] + (width * height >> 2);
+  pic.iStride[0]   = pic.iPicWidth;
+  pic.iStride[1]   = pic.iStride[2] = pic.iPicWidth >> 1;
+  pic.pData[0]     = buf.data();
+  pic.pData[1]     = pic.pData[0] + pEncParamExt->iPicWidth * pEncParamExt->iPicHeight;
+  pic.pData[2]     = pic.pData[1] + (pEncParamExt->iPicWidth * pEncParamExt->iPicHeight >> 2);
   while (in->read (buf.data(), frameSize) == frameSize) {
     rv = encoder_->EncodeFrame (&pic, &info);
     ASSERT_TRUE (rv == cmResultSuccess);
@@ -102,9 +108,9 @@
   }
 }
 
-void BaseEncoderTest::EncodeFile (const char* fileName, EUsageType usageType, int width, int height,
-                                  float frameRate, SliceModeEnum slices, bool denoise, int layers, bool losslessLink, bool enableLtr, bool cabac,Callback* cbk) {
+void BaseEncoderTest::EncodeFile (const char* fileName, SEncParamExt* pEncParamExt, Callback* cbk) {
   FileInputStream fileStream;
   ASSERT_TRUE (fileStream.Open (fileName));
-  EncodeStream (&fileStream, usageType, width, height, frameRate, slices, denoise, layers, losslessLink, enableLtr, cabac,cbk);
+  ASSERT_TRUE (NULL != pEncParamExt);
+  EncodeStream (&fileStream, pEncParamExt, cbk);
 }
--- a/test/api/decode_encode_test.cpp
+++ b/test/api/decode_encode_test.cpp
@@ -91,8 +91,31 @@
   BufferedData buf_;
 };
 
+void DecEncFileParamToParamExt (DecodeEncodeFileParam * pDecEncFileParam, SEncParamExt* pEnxParamExt) {
+  ASSERT_TRUE (NULL != pDecEncFileParam && NULL != pEnxParamExt);
+
+  pEnxParamExt->iPicWidth      = pDecEncFileParam->width;
+  pEnxParamExt->iPicHeight     = pDecEncFileParam->height;
+  pEnxParamExt->fMaxFrameRate  = pDecEncFileParam->frameRate;
+
+  //default value
+  pEnxParamExt->iUsageType        = CAMERA_VIDEO_REAL_TIME;
+  pEnxParamExt->iSpatialLayerNum  = 1;
+  pEnxParamExt->bEnableDenoise    = false;
+  pEnxParamExt->bIsLosslessLink   = false;
+  pEnxParamExt->bEnableLongTermReference  = false;
+  pEnxParamExt->iEntropyCodingModeFlag    = 0;
+
+  for (int i = 0; i < pEnxParamExt->iSpatialLayerNum; i++) {
+     pEnxParamExt->sSpatialLayers[i].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
+  }
+
+}
 TEST_P (DecodeEncodeTest, CompareOutput) {
   DecodeEncodeFileParam p = GetParam();
+  SEncParamExt  EnxParamExt;
+  DecEncFileParamToParamExt(&p,&EnxParamExt);
+
 #if defined(ANDROID_NDK)
   std::string filename = std::string ("/sdcard/") + p.fileName;
   ASSERT_TRUE (Open (filename.c_str()));
@@ -99,7 +122,7 @@
 #else
   ASSERT_TRUE (Open (p.fileName));
 #endif
-  EncodeStream (this, CAMERA_VIDEO_REAL_TIME, p.width, p.height, p.frameRate, SM_SINGLE_SLICE, false, 1, false, false,false, this);
+  EncodeStream (this, &EnxParamExt, this);
   unsigned char digest[SHA_DIGEST_LENGTH];
   SHA1Result (&ctx_, digest);
   if (!HasFatalFailure()) {
--- a/test/api/encode_decode_api_test.cpp
+++ b/test/api/encode_decode_api_test.cpp
@@ -231,7 +231,7 @@
   param_.bEnableFrameCroppingFlag   = (rand() % 2 == 0) ? false : true;
   param_.bEnableSceneChangeDetect   = (rand() % 2 == 0) ? false : true;
 
-//for rc
+  //for rc
   param_.iRCMode            = static_cast<RC_MODES> (rand() % RC_MODE_RANGE - 1);
   param_.iMaxBitrate        = rand() % BIT_RATE_RANGE;
   param_.iTargetBitrate     = rand() % BIT_RATE_RANGE;
@@ -286,7 +286,7 @@
     param_.uiIntraPeriod = 0;
   }
 
-//RefNum
+  //RefNum
   int32_t iRefUpperBound    = (param_.iUsageType == CAMERA_VIDEO_REAL_TIME) ?
                               MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA : MAX_REFERENCE_PICTURE_COUNT_NUM_SCREEN;
   param_.iNumRefFrame       = WELS_CLIP3 (param_.iNumRefFrame, MIN_REF_PIC_COUNT, iRefUpperBound);
@@ -2003,7 +2003,6 @@
   ASSERT_TRUE (rv == cmResultSuccess);
 
   for (int i = 0; i < iEncFrameNum; i++) {
-    //for (int i = 0; i < 9; i++) {
     int iResult;
     int len = 0;
     unsigned char* pData[3] = { NULL };
--- a/test/api/encoder_test.cpp
+++ b/test/api/encoder_test.cpp
@@ -2,6 +2,7 @@
 #include "utils/HashFunctions.h"
 #include "BaseEncoderTest.h"
 #include <string>
+
 static void UpdateHashFromFrame (const SFrameBSInfo& info, SHA1Context* ctx) {
   for (int i = 0; i < info.iLayerNum; ++i) {
     const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
@@ -26,20 +27,40 @@
 TEST_F (EncoderInitTest, JustInit) {}
 
 struct EncodeFileParam {
-  const char* fileName;
-  const char* hashStr;
-  EUsageType usageType;
-  int width;
-  int height;
-  float frameRate;
-  SliceModeEnum slices;
-  bool denoise;
-  int layers;
-  bool isLossless;
-  bool enableLtr;
-  bool cabac;
+  const char* pkcFileName;
+  const char* pkcHashStr;
+  EUsageType eUsageType;
+  int iWidth;
+  int iHeight;
+  float fFrameRate;
+  SliceModeEnum eSliceMode;
+  bool bDenoise;
+  int  iLayerNum;
+  bool bLossless;
+  bool bEnableLtr;
+  bool bCabac;
+// unsigned short iMultipleThreadIdc;
 };
 
+void EncFileParamToParamExt (EncodeFileParam* pEncFileParam, SEncParamExt* pEnxParamExt) {
+  ASSERT_TRUE (NULL != pEncFileParam && NULL != pEnxParamExt);
+  pEnxParamExt->iUsageType       = pEncFileParam->eUsageType;
+  pEnxParamExt->iPicWidth        = pEncFileParam->iWidth;
+  pEnxParamExt->iPicHeight       = pEncFileParam->iHeight;
+  pEnxParamExt->fMaxFrameRate    = pEncFileParam->fFrameRate;
+  pEnxParamExt->iSpatialLayerNum = pEncFileParam->iLayerNum;
+
+  pEnxParamExt->bEnableDenoise   = pEncFileParam->bDenoise;
+  pEnxParamExt->bIsLosslessLink  = pEncFileParam->bLossless;
+  pEnxParamExt->bEnableLongTermReference = pEncFileParam->bEnableLtr;
+  pEnxParamExt->iEntropyCodingModeFlag   = pEncFileParam->bCabac ? 1 : 0;
+
+  for (int i = 0; i < pEnxParamExt->iSpatialLayerNum; i++) {
+     pEnxParamExt->sSpatialLayers[i].sSliceCfg.uiSliceMode = pEncFileParam->eSliceMode;
+  }
+
+}
+
 class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>,
   public EncoderInitTest , public BaseEncoderTest::Callback {
  public:
@@ -53,6 +74,7 @@
   virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) {
     UpdateHashFromFrame (frameInfo, &ctx_);
   }
+
  protected:
   SHA1Context ctx_;
 };
@@ -60,13 +82,15 @@
 
 TEST_P (EncoderOutputTest, CompareOutput) {
   EncodeFileParam p = GetParam();
+  SEncParamExt EnxParamExt;
+
+  EncFileParamToParamExt (&p, &EnxParamExt);
+
 #if defined(ANDROID_NDK)
-  std::string filename = std::string ("/sdcard/") + p.fileName;
-  EncodeFile (filename.c_str(), p.usageType , p.width, p.height, p.frameRate, p.slices, p.denoise, p.layers, p.isLossless,
-              p.enableLtr,p.cabac, this);
+  std::string filename = std::string ("/sdcard/") + p.pkcFileName;
+  EncodeFile (p.pkcFileName, &EnxParamExt, this);
 #else
-  EncodeFile (p.fileName, p.usageType , p.width, p.height, p.frameRate, p.slices, p.denoise, p.layers, p.isLossless,
-              p.enableLtr, p.cabac, this);
+    EncodeFile (p.pkcFileName, &EnxParamExt, this);
 #endif
   //will remove this after screen content algorithms are ready,
   //because the bitstream output will vary when the different algorithms are added.
@@ -73,7 +97,7 @@
   unsigned char digest[SHA_DIGEST_LENGTH];
   SHA1Result (&ctx_, digest);
   if (!HasFatalFailure()) {
-    CompareHash (digest, p.hashStr);
+    CompareHash (digest, p.pkcHashStr);
   }
 }
 static const EncodeFileParam kFileParamArray[] = {