shithub: openh264

Download patch

ref: 613645fb407bb19b6357ad0f6b5755f1819b4358
parent: 297e043f7bc26dfbcc9e8ff72df3138ec7723477
parent: 2883852000a864b20cb281eeee3d593090bf6ed9
author: guangwei <GuangweiWang@users.noreply.github.com>
date: Tue Oct 10 10:23:35 EDT 2017

Merge pull request #2855 from huili2/profile_svc_check_ut

add encoder avc/svc style check

--- a/test/api/encode_options_test.cpp
+++ b/test/api/encode_options_test.cpp
@@ -2058,3 +2058,61 @@
   rv = encoder_->Uninitialize();
   ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv;
 }
+
+TEST_F (EncodeDecodeTestAPI, AVCSVCExtensionCheck) {
+  int iWidth       = 640;
+  int iHeight      = 360;
+  float fFrameRate = rand() % 30 + 0.5f;
+  int iTotalFrame  = 10; //total test enc frame num
+  int iSliceNum    = 1;
+
+  int iRet;
+  int iSpatialLayerNumList[] = {1, 3};
+  int iLoopNum = 5;
+  for (int i = 0; i < iLoopNum; ++i) {
+    // prepare params
+    SEncParamExt sParam;
+    encoder_->GetDefaultParams (&sParam);
+    int iCurrSpatialLayerNum = iSpatialLayerNumList[rand() % 2];
+    prepareParamDefault (iCurrSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam);
+    sParam.bSimulcastAVC = rand() & 1; //0 or 1
+    sParam.iRCMode = RC_TIMESTAMP_MODE;
+    sParam.iNumRefFrame = 1;
+    sParam.fMaxFrameRate = fFrameRate;
+    sParam.sSpatialLayers[0].iSpatialBitrate = sParam.iTargetBitrate = 500;
+    sParam.sSpatialLayers[1].iSpatialBitrate = sParam.iTargetBitrate = 1000;
+    sParam.sSpatialLayers[2].iSpatialBitrate = sParam.iTargetBitrate = 2200;
+    sParam.iTargetBitrate = 4000;
+    //int TraceLevel = WELS_LOG_DEBUG;
+    //encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &TraceLevel);
+    //decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &TraceLevel);
+    iRet = encoder_->InitializeExt (&sParam);
+    ASSERT_TRUE (iRet == cmResultSuccess) << "InitializeExt: iRet = " << iRet << " at " << sParam.iPicWidth << "x" <<
+                                          sParam.iPicHeight;
+    ASSERT_TRUE (InitialEncDec (iWidth, iHeight));
+    int iLen = 0;
+    for (int j = 0; j < iTotalFrame; ++j) {
+      EncodeOneFrame (0);
+      encToDecData (info, iLen);
+      uint8_t cTypeByte;
+      for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) {
+        SLayerBSInfo* pLayerBsInfo = &info.sLayerInfo[iLayer];
+        for (int iPacketNum = 0; iPacketNum < pLayerBsInfo->iNalCount; ++iPacketNum) {
+          cTypeByte = (* (pLayerBsInfo->pBsBuf + 4)) & 0x1f;
+          if (sParam.bSimulcastAVC) {
+            EXPECT_TRUE (cTypeByte <= 8) << "simulcastAVC, spatial_id = " << pLayerBsInfo->uiSpatialId << ", typeByte = " <<
+                                         cTypeByte;
+          } else {
+            if (pLayerBsInfo->uiSpatialId == 0)
+              EXPECT_TRUE (cTypeByte <= 8 || cTypeByte == 14) << "simulcastSVC, spatial_id = 0, typeByte = " << cTypeByte;
+            else
+              EXPECT_TRUE (cTypeByte >= 14) << "simulcastSVC, spatial_id = " << pLayerBsInfo->uiSpatialId << ", typeByte = " <<
+                                            cTypeByte;;
+          }
+        }
+      }
+    }
+    iRet = encoder_->Uninitialize();
+    ASSERT_TRUE (iRet == cmResultSuccess) << "rv = " << iRet;
+  }
+}