shithub: openh264

Download patch

ref: bc76a8f9b34fa4c77ad8baab9b04d4f5c5573efa
parent: c36f8646825e383fcd04446797bc253d546763ab
author: Sijia Chen <[email protected]>
date: Mon Jul 14 11:30:01 EDT 2014

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;
@@ -98,8 +99,18 @@
   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() {
 
   pParamExt->iPicWidth = m_iWidth;
@@ -163,13 +174,14 @@
 
 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
 }
 
+
 TEST_F (EncoderInterfaceTest, BasicInitializeTest) {
   SEncParamBase sEncParamBase;
   GetValidEncParamBase (&sEncParamBase);
@@ -178,7 +190,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 +205,6 @@
   EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
 }
 
-
-
 TEST_F (EncoderInterfaceTest, BasicInitializeTestFalse) {
   int iResult;
   SEncParamBase sEncParamBase;
@@ -280,3 +290,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));
+}
+