shithub: openh264

Download patch

ref: 30a4962135190b01d7dee836429ecfbb025672bb
parent: cb346fea5c3fd74673d8ecf1cf30bc0ec41cb122
author: sijchen@cisco.com <sijchen@cisco.com>
date: Wed Mar 14 10:57:49 EDT 2018

add new UT for ENCODER_OPTION_IDR_INTERVAL and enhance error log output

--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -374,14 +374,18 @@
  */
 int CWelsH264SVCEncoder::EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSInfo* pBsInfo) {
   if (! (kpSrcPic && m_bInitialFlag && pBsInfo)) {
+    WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::EncodeFrame(), cmInitParaError.");
     return cmInitParaError;
   }
-  if (kpSrcPic->iColorFormat != videoFormatI420)
+  if (kpSrcPic->iColorFormat != videoFormatI420) {
+    WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::EncodeFrame(), wrong iColorFormat %d", kpSrcPic->iColorFormat);
     return cmInitParaError;
+  }
 
   const int32_t kiEncoderReturn = EncodeFrameInternal (kpSrcPic, pBsInfo);
 
   if (kiEncoderReturn != cmResultSuccess) {
+    WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::EncodeFrame(), kiEncoderReturn %d", kiEncoderReturn);
     return kiEncoderReturn;
   }
 
@@ -539,7 +543,7 @@
     SSpatialLayerConfig* pSpatialCfg = &pParam->sSpatialLayers[i];
     WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
              "sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iSpatialBitrate= %d; .iMaxSpatialBitrate= %d; .sSliceArgument.uiSliceMode= %d; .sSliceArgument.iSliceNum= %d; .sSliceArgument.uiSliceSizeConstraint= %d;"
-             "uiProfileIdc = %d;uiLevelIdc = %d",
+             "uiProfileIdc = %d;uiLevelIdc = %d;iDLayerQp = %d",
              i, pSpatialCfg->iVideoWidth,
              pSpatialCfg->iVideoHeight,
              pSpatialCfg->fFrameRate,
@@ -549,7 +553,8 @@
              pSpatialCfg->sSliceArgument.uiSliceNum,
              pSpatialCfg->sSliceArgument.uiSliceSizeConstraint,
              pSpatialCfg->uiProfileIdc,
-             pSpatialCfg->uiLevelIdc
+             pSpatialCfg->uiLevelIdc,
+             pSpatialCfg->iDLayerQp
             );
     ++ i;
   }
--- a/test/api/encode_decode_api_test.cpp
+++ b/test/api/encode_decode_api_test.cpp
@@ -95,7 +95,7 @@
   memset (buf_.data() + lumaSize, rand() % 256, (frameSize - lumaSize));
   int rv = encoder_->EncodeFrame (&EncPic, &info);
   if (0 == iCheckTypeIndex)
-    ASSERT_TRUE (rv == cmResultSuccess);
+    ASSERT_TRUE (rv == cmResultSuccess) << rv;
   else if (1 == iCheckTypeIndex)
     ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason);
 }
--- a/test/api/encode_options_test.cpp
+++ b/test/api/encode_options_test.cpp
@@ -2332,3 +2332,48 @@
 
 }
 
+TEST_F (EncodeDecodeTestAPI, ENCODER_OPTION_IDR_INTERVAL) {
+  int iSpatialLayerNum = 1;
+  int iWidth       = WelsClip3 ((((rand() % MAX_WIDTH) >> 1)  + 1) << 1, 1 << iSpatialLayerNum, MAX_WIDTH);
+  int iHeight      = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1)  + 1) << 1, 1 << iSpatialLayerNum, MAX_HEIGHT);
+  float fFrameRate = rand() + 0.5f;
+  int iSliceNum        = 1;
+  encoder_->GetDefaultParams (&param_);
+  prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &param_);
+  param_.iTemporalLayerNum = 1;
+
+  int iTraceLevel = WELS_LOG_QUIET;
+  int rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
+  EXPECT_TRUE (rv == cmResultSuccess);
+
+  rv = encoder_->InitializeExt (&param_);
+  ASSERT_TRUE (rv == cmResultSuccess);
+
+  InitialEncDec (param_.iPicWidth, param_.iPicHeight);
+  EncodeOneFrame (0);
+  EXPECT_TRUE (info.eFrameType == videoFrameTypeIDR);
+
+  int iLastIdrIdx = 0;
+  int iFrame = 1;
+  int iTtlAttempt = (rand() % 5) + 2;
+  for (int iAtt = 0; iAtt < iTtlAttempt; iAtt++) {
+    int kiTargetIntraPeriod = WelsClip3 ((rand() % ENCODE_FRAME_NUM) - 1, -1, ENCODE_FRAME_NUM);
+    rv = encoder_->SetOption (ENCODER_OPTION_IDR_INTERVAL, &kiTargetIntraPeriod);
+    EXPECT_TRUE (rv == cmResultSuccess);
+
+    int iEncFrameNum = kiTargetIntraPeriod * 3;
+    for (int i = 0; i < iEncFrameNum; i++) {
+      EncodeOneFrame (0);
+
+      if ((kiTargetIntraPeriod <= 0) || (((iFrame - iLastIdrIdx) % kiTargetIntraPeriod) == 0)) {
+        EXPECT_TRUE (info.eFrameType == videoFrameTypeIDR) << "kiTargetIntraPeriod " << kiTargetIntraPeriod <<
+            " info.eFrameType " << info.eFrameType << " Frame " << i;
+        iLastIdrIdx = iFrame;
+      } else {
+        EXPECT_FALSE (info.eFrameType == videoFrameTypeIDR);
+      }
+
+      iFrame ++;
+    }
+  }
+}