shithub: openh264

Download patch

ref: 5921e5e7d3c947db3eb6a3e09e126faeb6ab56b7
parent: 4048b9791a9bdcd431bc7315a6a86029ee9034e6
parent: 2c44dbae5c6930e75c65ecf826927d2494d0b3e5
author: ruil2 <ruil2@cisco.com>
date: Thu Mar 5 10:47:24 EST 2015

Merge pull request #1836 from sijchen/imp_ut4

[UT] add more condition to improve the coverage of DecoderCrashTest

--- a/test/api/encode_decode_api_test.cpp
+++ b/test/api/encode_decode_api_test.cpp
@@ -2316,14 +2316,20 @@
   int iTarBitrate;
 };
 
-
+#define NUM_OF_POSSIBLE_RESOLUTION (9)
 static const EncodeDecodeParamBase kParamArray[] = {
   {160, 90, 6.0f, 250000},
+  {90, 160, 6.0f, 250000},
   {320, 180, 12.0f, 500000},
+  {180, 320, 12.0f, 500000},
+  {480, 270, 12.0f, 600000},
+  {270, 480, 12.0f, 600000},
   {640, 360, 24.0f, 800000},
+  {360, 640, 24.0f, 800000},
+  {1280, 720, 24.0f, 1000000},
 };
 
-//#define DEBUG_FILE_SAVE
+//#define DEBUG_FILE_SAVE_CRA
 TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
   uint32_t uiGet;
   encoder_->Uninitialize();
@@ -2332,33 +2338,62 @@
   unsigned int uiLoopRound = 0;
   unsigned char* pucBuf = ucBuf_;
   int iDecAuSize;
-#ifdef DEBUG_FILE_SAVE
+#ifdef DEBUG_FILE_SAVE_CRA
   //open file to save tested BS
-  FILE* f = fopen ("test_crash.264", "wb");
+  FILE* fDataFile = fopen ("test_crash.264", "wb");
+  FILE* fLenFile = fopen ("test_crash_len.log", "w");
   int iFileSize = 0;
 #endif
 
+  //set eCurStrategy for one test
+  EParameterSetStrategy eCurStrategy = CONSTANT_ID;
+  switch (rand() % 7) {
+  case 1:
+    eCurStrategy = INCREASING_ID;
+    break;
+  case 2:
+    eCurStrategy = SPS_LISTING;
+    break;
+  case 3:
+    eCurStrategy = SPS_LISTING_AND_PPS_INCREASING;
+    break;
+  case 6:
+    eCurStrategy = SPS_PPS_LISTING;
+    break;
+  default:
+    //using the initial value
+    break;
+  }
+
   do {
     int iTotalFrameNum = (rand() % 100) + 1;
-    int iSeed = rand() % 3; //3 indicates the length of kParamArray[] used in the following
+    int iSeed = rand() % NUM_OF_POSSIBLE_RESOLUTION;
     EncodeDecodeParamBase p = kParamArray[iSeed];
+#ifdef DEBUG_FILE_SAVE_CRA
+    printf ("using param set %d in loop %d\n", iSeed, uiLoopRound);
+#endif
     //Initialize Encoder
     prepareParam (1, 1, p.width, p.height, p.frameRate, &param_);
-    param_.iRCMode = RC_BITRATE_MODE;
+    param_.iRCMode = RC_TIMESTAMP_MODE;
     param_.iTargetBitrate = p.iTarBitrate;
     param_.uiIntraPeriod = 0;
-    param_.eSpsPpsIdStrategy = INCREASING_ID;
+    param_.eSpsPpsIdStrategy = eCurStrategy;
     param_.bEnableBackgroundDetection = true;
-    param_.bEnableSceneChangeDetect = true;
-    param_.bPrefixNalAddingCtrl = true;
+    param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false;
+    param_.bPrefixNalAddingCtrl = (rand() % 2) ? true : false;
     param_.iEntropyCodingModeFlag = 0;
     param_.bEnableFrameSkip = true;
-    param_.uiMaxNalSize = 1400;
     param_.iMultipleThreadIdc = 0;
     param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;
     param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;
-    param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_DYN_SLICE;
-    param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 1000;
+    param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = (rand() % 2) ? SM_DYN_SLICE : SM_SINGLE_SLICE;
+    if (param_.sSpatialLayers[0].sSliceCfg.uiSliceMode == SM_DYN_SLICE) {
+      param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 1400;
+      param_.uiMaxNalSize = 1400;
+    } else {
+      param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 0;
+      param_.uiMaxNalSize = 0;
+    }
 
     int rv = encoder_->InitializeExt (&param_);
     ASSERT_TRUE (rv == cmResultSuccess);
@@ -2379,11 +2414,11 @@
     prepareEncDecParam (pInput);
     while (iIdx++ < iTotalFrameNum) { // loop in frame
       EncodeOneFrame();
-#ifdef DEBUG_FILE_SAVE
+#ifdef DEBUG_FILE_SAVE_CRA
       //reset file if file size large
       if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {
-        fclose (f);
-        f = fopen ("test_crash.264", "wb");
+        fclose (fDataFile);
+        fDataFile = fopen ("test_crash.264", "wb");
         iFileSize = 0;
         decoder_->Uninitialize();
 
@@ -2411,7 +2446,8 @@
         for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) {  //loop in NAL
           int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];
           //packet loss
-          int iLossRate = (rand() % 11); //loss rate among 0 ~ 10%
+          int iLossRateRange = (uiLoopRound % 100) + 1; //1-100
+          int iLossRate = (rand() % iLossRateRange);
           bool bPacketLost = (rand() % 101) > (100 -
                                                iLossRate);   // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS
           if (!bPacketLost) { //no loss
@@ -2419,15 +2455,29 @@
             pucBuf += iPacketSize;
             iDecAuSize += iPacketSize;
           }
+#ifdef DEBUG_FILE_SAVE_CRA
+          else {
+            printf ("lost packet size=%d at frame-type=%d at loss rate %d (%d)\n", iPacketSize, info.eFrameType, iLossRate,
+                    iLossRateRange);
+          }
+#endif
           //update bs info
           pBsBuf += iPacketSize;
         } //nal
       } //layer
 
-#ifdef DEBUG_FILE_SAVE
+#ifdef DEBUG_FILE_SAVE_CRA
       //save to file
-      fwrite (ucBuf_, 1, iDecAuSize, f);
+      fwrite (ucBuf_, 1, iDecAuSize, fDataFile);
+      fflush (fDataFile);
       iFileSize += iDecAuSize;
+
+      //save to len file
+      unsigned long ulTmp[4];
+      ulTmp[0] = ulTmp[1] = ulTmp[2] = iIdx;
+      ulTmp[3] = iDecAuSize;
+      fwrite (ulTmp, sizeof (unsigned long), 4, fLenFile); // index, timeStamp, data size
+      fflush (fLenFile);
 #endif
 
       //decode
@@ -2443,11 +2493,12 @@
     uiLoopRound ++;
     if (uiLoopRound >= (1 << 30))
       uiLoopRound = 0;
-#ifdef DEBUG_FILE_SAVE
+#ifdef DEBUG_FILE_SAVE_CRA
     if (uiLoopRound % 100 == 0)
       printf ("run %d times.\n", uiLoopRound);
   } while (1); //while (iLoopRound<100);
-  fclose (f);
+  fclose (fDataFile);
+  fclose (fLenFile);
 #else
   }
   while (uiLoopRound < 10);