shithub: openh264

Download patch

ref: 3a375869703696df8d0e16d709c6d4a56b2cfd2d
parent: c36f8646825e383fcd04446797bc253d546763ab
parent: d1123a8bb193ff4f7e064fba7298c95515ff646f
author: lyao2 <[email protected]>
date: Mon Jul 14 12:10:20 EDT 2014

Merge pull request #1162 from sijchen/interfaceUT11

[Encoder] add interface UT for ForceIntraFrame

--- a/test/encoder/EncUT_EncoderExt.cpp
+++ b/test/encoder/EncUT_EncoderExt.cpp
@@ -45,6 +45,7 @@
   void TemporalLayerSettingTest();
   void EncodeOneFrame (SEncParamBase* pEncParamBase);
   void PrepareOneSrcFrame();
+  void EncodeOneIDRandP (ISVCEncoder* pPtrEnc);
 
  public:
   ISVCEncoder* pPtrEnc;
@@ -83,7 +84,6 @@
 
 void EncoderInterfaceTest::EncodeOneFrame (SEncParamBase* pEncParamBase) {
   int iResult;
-
   iResult = pPtrEnc->Initialize (pEncParamBase);
   EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
   PrepareOneSrcFrame();
@@ -98,7 +98,16 @@
   EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
 }
 
+void EncoderInterfaceTest::EncodeOneIDRandP (ISVCEncoder* pPtrEnc) {
+  int iResult;
+  iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
 
+  iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+  EXPECT_NE (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR));
+}
 
 void EncoderInterfaceTest::TemporalLayerSettingTest() {
 
@@ -163,8 +172,8 @@
 
 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 = abs ((rand() * 2) + MB_SIZE) % (MAX_WIDTH + 1);
+  pEncParamBase->iPicHeight = abs ((rand() * 2) + MB_SIZE) % (MAX_HEIGHT + 1);
   pEncParamBase->iTargetBitrate = rand() + 1; //!=0
   pEncParamBase->iRCMode = RC_BITRATE_MODE; //-1, 0, 1, 2
   pEncParamBase->fMaxFrameRate = rand() + 0.5f; //!=0
@@ -178,7 +187,7 @@
   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",
+             iUsageType=%d, Pic=%dx%d, TargetBitrate=%d, iRCMode=%d, fMaxFrameRate=%.1f\n",
              sEncParamBase.iUsageType, sEncParamBase.iPicWidth, sEncParamBase.iPicHeight,
              sEncParamBase.iTargetBitrate, sEncParamBase.iRCMode, sEncParamBase.fMaxFrameRate);
   }
@@ -193,8 +202,6 @@
   EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
 }
 
-
-
 TEST_F (EncoderInterfaceTest, BasicInitializeTestFalse) {
   int iResult;
   SEncParamBase sEncParamBase;
@@ -280,3 +287,70 @@
   EXPECT_LE (sEncParamBase.fMaxFrameRate, 30.0);
   EXPECT_GE (sEncParamBase.fMaxFrameRate, 1.0);
 }
+
+
+TEST_F (EncoderInterfaceTest, ForceIntraFrame) {
+  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();
+
+  bool bIDR = true;
+  pPtrEnc->ForceIntraFrame (bIDR);
+  EncodeOneIDRandP (pPtrEnc);
+
+  //call next frame to be IDR
+  pPtrEnc->ForceIntraFrame (bIDR);
+  EncodeOneIDRandP (pPtrEnc);
+
+  pPtrEnc->Uninitialize();
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+}
+
+TEST_F (EncoderInterfaceTest, ForceIntraFrameWithTemporal) {
+  SEncParamExt sEncParamExt;
+  pPtrEnc->GetDefaultParams (&sEncParamExt);
+  sEncParamExt.iUsageType = CAMERA_VIDEO_REAL_TIME;
+  sEncParamExt.iPicWidth = abs ((rand() * 2) + MB_SIZE) % (MAX_WIDTH + 1);
+  sEncParamExt.iPicHeight = abs ((rand() * 2) + MB_SIZE) % (MAX_HEIGHT + 1);
+  sEncParamExt.iTargetBitrate = rand() + 1; //!=0
+  sEncParamExt.iRCMode = RC_BITRATE_MODE; //-1, 0, 1, 2
+  sEncParamExt.fMaxFrameRate = rand() + 0.5f; //!=0
+  sEncParamExt.sSpatialLayers[0].iVideoWidth = sEncParamExt.iPicWidth;
+  sEncParamExt.sSpatialLayers[0].iVideoHeight = sEncParamExt.iPicHeight;
+  sEncParamExt.sSpatialLayers[0].iSpatialBitrate = sEncParamExt.iTargetBitrate;
+
+  int iTargetTemporalLayerNum = rand() % MAX_TEMPORAL_LAYER_NUM;
+  sEncParamExt.iTemporalLayerNum = (iTargetTemporalLayerNum > 2) ? iTargetTemporalLayerNum : 2;
+
+  int iResult = pPtrEnc->InitializeExt (&sEncParamExt);
+  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",
+             sEncParamExt.iUsageType, sEncParamExt.iPicWidth, sEncParamExt.iPicHeight,
+             sEncParamExt.iTargetBitrate, sEncParamExt.iRCMode, sEncParamExt.fMaxFrameRate);
+  }
+
+  PrepareOneSrcFrame();
+
+  bool bIDR = true;
+  EncodeOneIDRandP (pPtrEnc);
+
+  //call next frame to be IDR
+  pPtrEnc->ForceIntraFrame (bIDR);
+  EncodeOneIDRandP (pPtrEnc);
+
+  pPtrEnc->Uninitialize();
+  EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+}
+