shithub: openh264

Download patch

ref: 3350cf75a57271249d305474a5771aabe409c55a
parent: 054a297ca79cd2cc609dfefa8b863d519b3f00ac
author: Sijia Chen <[email protected]>
date: Wed Oct 28 17:51:47 EDT 2015

add one test case

--- a/test/api/encode_decode_api_test.cpp
+++ b/test/api/encode_decode_api_test.cpp
@@ -3738,7 +3738,7 @@
   SEncParamExt   sParam;
   encoder_->GetDefaultParams (&sParam);
   prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
-  sParam.iMultipleThreadIdc = (rand()%4) + 1;
+  sParam.iMultipleThreadIdc = (rand() % 4) + 1;
   sParam.bSimulcastAVC = 1;
   sParam.sSpatialLayers[0].iVideoWidth = (iWidth >> 2);
   sParam.sSpatialLayers[0].iVideoHeight = (iHeight >> 2);
@@ -3753,7 +3753,7 @@
   sParam.sSpatialLayers[2].iVideoWidth = iWidth;
   sParam.sSpatialLayers[2].iVideoHeight = iHeight;
   sParam.sSpatialLayers[2].sSliceCfg.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
-  sParam.sSpatialLayers[2].sSliceCfg.sSliceArgument.uiSliceNum = 4;
+  sParam.sSpatialLayers[2].sSliceCfg.sSliceArgument.uiSliceNum = (rand() % 30) + 1;
 
   int rv = encoder_->InitializeExt (&sParam);
   ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
@@ -3795,3 +3795,65 @@
 
   }
 }
+
+TEST_F (EncodeDecodeTestAPI, ThreadNumAndSliceNum) {
+  int iSpatialLayerNum = 1;
+  int iWidth       = WelsClip3 ((((rand() % MAX_WIDTH) >> 1)  + 1) << 1, (64 << 2), MAX_WIDTH);
+  int iHeight      = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1)  + 1) << 1, (64 << 2),
+                                2240);//TODO: use MAX_HEIGHT after the limit is removed
+  float fFrameRate = rand() + 0.5f;
+  int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
+
+  // prepare params
+  SEncParamExt   sParam;
+  encoder_->GetDefaultParams (&sParam);
+  prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
+  sParam.iMultipleThreadIdc = (rand() % 3) + 2;
+  sParam.bSimulcastAVC = 1;
+  sParam.sSpatialLayers[0].iVideoWidth = iWidth;
+  sParam.sSpatialLayers[0].iVideoHeight = iHeight;
+  sParam.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
+  sParam.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = (rand() % 2) ? (sParam.iMultipleThreadIdc + 1) :
+      (sParam.iMultipleThreadIdc - 1);
+
+  int rv = encoder_->InitializeExt (&sParam);
+  ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
+
+  unsigned char*  pBsBuf[MAX_SPATIAL_LAYER_NUM];
+  ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];
+
+  int iIdx = 0;
+
+  //create decoder
+  for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
+    pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
+    EXPECT_TRUE (pBsBuf[iIdx] != NULL);
+
+    long rv = WelsCreateDecoder (&decoder[iIdx]);
+    ASSERT_EQ (0, rv);
+    EXPECT_TRUE (decoder[iIdx] != NULL);
+
+    SDecodingParam decParam;
+    memset (&decParam, 0, sizeof (SDecodingParam));
+    decParam.eOutputColorFormat  = videoFormatI420;
+    decParam.uiTargetDqLayer = UCHAR_MAX;
+    decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
+    decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
+
+    rv = decoder[iIdx]->Initialize (&decParam);
+    ASSERT_EQ (0, rv);
+  }
+
+  TestOneSimulcastAVC (&sParam, decoder, pBsBuf, iSpatialLayerNum, iEncFrameNum, 0);
+
+  for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
+    free (pBsBuf[iIdx]);
+
+    if (decoder[iIdx] != NULL) {
+      decoder[iIdx]->Uninitialize();
+      WelsDestroyDecoder (decoder[iIdx]);
+    }
+
+  }
+}
+