shithub: openh264

Download patch

ref: b669801e89d148be61bb8478b84f15145720f403
parent: 3a375869703696df8d0e16d709c6d4a56b2cfd2d
author: Sijia Chen <sijchen@cisco.com>
date: Mon Jul 14 14:36:35 EDT 2014

add interface UT for WelsEncoderEncodeParameterSets
and fix previous value

--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2911,6 +2911,7 @@
   pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen;
   InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize);
 
+  pCtx->iPosBsBuffer = 0;
   int32_t iReturn = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal);
   WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
 
@@ -2922,6 +2923,7 @@
 
   pCtx->eLastNalPriority      = NRI_PRI_HIGHEST;
   pFbi->iLayerNum             = 1;
+  pFbi->eFrameType            = videoFrameTypeInvalid;
 
   WelsEmms();
 
--- a/test/encoder/EncUT_EncoderExt.cpp
+++ b/test/encoder/EncUT_EncoderExt.cpp
@@ -8,6 +8,16 @@
 #define MB_SIZE (16)
 #define MAX_WIDTH (3840)
 #define MAX_HEIGHT (2160)
+#define VALID_SIZE(iSize) (((iSize)>1)?(iSize):1)
+
+#define NAL_HEADER_BYTES (4)
+#define NAL_TYPE (0x0F)
+#define SPS_NAL_TYPE (7)
+#define PPS_NAL_TYPE (8)
+#define SUBSETSPS_NAL_TYPE (15)
+#define GET_NAL_TYPE(pNalStart) (*(pNalStart+NAL_HEADER_BYTES) & NAL_TYPE)
+#define IS_PARASET(iNalType) ((iNalType==SPS_NAL_TYPE) || (iNalType==PPS_NAL_TYPE) || (iNalType==SUBSETSPS_NAL_TYPE))
+
  public:
   virtual void SetUp() {
     int rv = WelsCreateSVCEncoder (&pPtrEnc);
@@ -172,8 +182,10 @@
 
 void GetValidEncParamBase (SEncParamBase* pEncParamBase) {
   pEncParamBase->iUsageType = CAMERA_VIDEO_REAL_TIME;
-  pEncParamBase->iPicWidth = abs ((rand() * 2) + MB_SIZE) % (MAX_WIDTH + 1);
-  pEncParamBase->iPicHeight = abs ((rand() * 2) + MB_SIZE) % (MAX_HEIGHT + 1);
+  pEncParamBase->iPicWidth = ((rand() * 2) % (MAX_WIDTH));
+  pEncParamBase->iPicHeight = ((rand() * 2) % (MAX_HEIGHT));
+  pEncParamBase->iPicWidth = VALID_SIZE(pEncParamBase->iPicWidth);
+  pEncParamBase->iPicHeight = VALID_SIZE(pEncParamBase->iPicHeight);
   pEncParamBase->iTargetBitrate = rand() + 1; //!=0
   pEncParamBase->iRCMode = RC_BITRATE_MODE; //-1, 0, 1, 2
   pEncParamBase->fMaxFrameRate = rand() + 0.5f; //!=0
@@ -288,7 +300,6 @@
   EXPECT_GE (sEncParamBase.fMaxFrameRate, 1.0);
 }
 
-
 TEST_F (EncoderInterfaceTest, ForceIntraFrame) {
   SEncParamBase sEncParamBase;
   GetValidEncParamBase (&sEncParamBase);
@@ -352,5 +363,53 @@
 
   pPtrEnc->Uninitialize();
   EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+}
+
+TEST_F (EncoderInterfaceTest, EncodeParameterSets) {
+  SEncParamBase sEncParamBase;
+  GetValidEncParamBase (&sEncParamBase);
+
+  int iResult = pPtrEnc->Initialize (&sEncParamBase);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  if (iResult != cmResultSuccess) {
+    fprintf (stderr, "Unexpected ParamBase? \
+             iUsageType=%d, Pic=%dx%d, TargetBitrate=%d, iRCMode=%d, fMaxFrameRate=%.1f\n",
+             sEncParamBase.iUsageType, sEncParamBase.iPicWidth, sEncParamBase.iPicHeight,
+             sEncParamBase.iTargetBitrate, sEncParamBase.iRCMode, sEncParamBase.fMaxFrameRate);
+  }
+  PrepareOneSrcFrame();
+  EncodeOneIDRandP (pPtrEnc);
+
+  //try EncodeParameterSets
+  pPtrEnc->EncodeParameterSets (&sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeInvalid));
+
+  //check the result
+  int iNalType = 0;
+  SLayerBSInfo* pLayerBsInfo;
+  for (int i = 0; i < sFbi.iLayerNum; i++) {
+    pLayerBsInfo = & (sFbi.sLayerInfo[i]);
+    EXPECT_EQ (pLayerBsInfo->uiLayerType , static_cast<int> (NON_VIDEO_CODING_LAYER));
+
+    iNalType = GET_NAL_TYPE (pLayerBsInfo->pBsBuf);
+    EXPECT_EQ (true, IS_PARASET (iNalType));
+    for (int j = 0; j < (pLayerBsInfo->iNalCount - 1); j++) {
+      iNalType = GET_NAL_TYPE (pLayerBsInfo->pBsBuf + pLayerBsInfo->pNalLengthInByte[j]);
+      EXPECT_EQ (true, IS_PARASET (iNalType));
+    }
+  }
+
+  //try another P to make sure no impact on succeeding frames
+  iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  EXPECT_NE (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
+
+  pPtrEnc->Uninitialize();
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+}
+
+TEST_F (EncoderInterfaceTest, BasicReturnTypeTest) {
+  //TODO
 }