Showing the changes to test/api/decode_api_test.cpp (1 of 8 files). Show all
Unified · Split
| @@ -801,8 +801,13 @@ class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase · 800 unmodified lines | |||
| 801 | int rv = decoder_->Initialize (&decParam); | 801 | int rv = decoder_->Initialize (&decParam); |
| 802 | ASSERT_EQ (0, rv); | 802 | ASSERT_EQ (0, rv); |
| 803 | memset (&BsInfo_, 0, sizeof (SParserBsInfo)); | 803 | memset (&BsInfo_, 0, sizeof (SParserBsInfo)); |
| 804 | fYuv_ = fopen ("./res/CiscoVT2people_160x96_6fps.yuv", "rb"); | 804 | const char* sFileName = "res/CiscoVT2people_160x96_6fps.yuv"; |
| 805 | ASSERT_TRUE (fYuv_ != NULL); | 805 | #if defined(ANDROID_NDK) |
| 806 | std::string filename = std::string ("/sdcard/") + sFileName; | ||
| 807 | ASSERT_TRUE ((fYuv_ = fopen (filename.c_str(), "rb")) != NULL); | ||
| 808 | #else | ||
| 809 | ASSERT_TRUE ((fYuv_ = fopen (sFileName, "rb")) != NULL); | ||
| 810 | #endif | ||
| 806 | iWidth_ = kiWidth; | 811 | iWidth_ = kiWidth; |
| 807 | iHeight_ = kiHeight; | 812 | iHeight_ = kiHeight; |
| 808 | } | 813 | } |
| @@ -810,6 +815,7 @@ class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase · 1 unmodified line | |||
| 810 | EncodeDecodeTestBase::TearDown(); | 815 | EncodeDecodeTestBase::TearDown(); |
| 811 | if (fYuv_ != NULL) { | 816 | if (fYuv_ != NULL) { |
| 812 | fclose (fYuv_); | 817 | fclose (fYuv_); |
| 818 | fYuv_ = NULL; | ||
| 813 | } | 819 | } |
| 814 | } | 820 | } |
| 815 | 821 | ||
| @@ -820,7 +826,15 @@ class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase · 4 unmodified lines | |||
| 820 | BsInfo_.pDstBuff = pTmpPtr; | 826 | BsInfo_.pDstBuff = pTmpPtr; |
| 821 | } | 827 | } |
| 822 | 828 | ||
| 823 | void EncodeOneFrame (int iIdx) { | 829 | void MockInputData (uint8_t* pData, int32_t iSize) { |
| 830 | int32_t iCurr = 0; | ||
| 831 | while (iCurr < iSize) { | ||
| 832 | * (pData + iCurr) = (* (pData + iCurr) + (rand() % 20) + 256) & 0x00ff; | ||
| 833 | iCurr++; | ||
| 834 | } | ||
| 835 | } | ||
| 836 | |||
| 837 | void EncodeOneFrame (bool bMock) { | ||
| 824 | int iFrameSize = iWidth_ * iHeight_ * 3 / 2; | 838 | int iFrameSize = iWidth_ * iHeight_ * 3 / 2; |
| 825 | int iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_); | 839 | int iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_); |
| 826 | if (feof (fYuv_) || iSize != iFrameSize) { | 840 | if (feof (fYuv_) || iSize != iFrameSize) { |
| @@ -828,6 +842,9 @@ class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase · 1 unmodified line | |||
| 828 | iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_); | 842 | iSize = (int) fread (buf_.data(), sizeof (char), iFrameSize, fYuv_); |
| 829 | ASSERT_TRUE (iSize == iFrameSize); | 843 | ASSERT_TRUE (iSize == iFrameSize); |
| 830 | } | 844 | } |
| 845 | if (bMock) { | ||
| 846 | MockInputData (buf_.data(), iWidth_ * iHeight_); | ||
| 847 | } | ||
| 831 | int rv = encoder_->EncodeFrame (&EncPic, &info); | 848 | int rv = encoder_->EncodeFrame (&EncPic, &info); |
| 832 | ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason); | 849 | ASSERT_TRUE (rv == cmResultSuccess || rv == cmUnknownReason); |
| 833 | } | 850 | } |
| @@ -845,7 +862,7 @@ class DecodeParseAPI : public ::testing::TestWithParam<EncodeDecodeFileParamBase · 11 unmodified lines | |||
| 845 | SHA1Context ctx_; | 862 | SHA1Context ctx_; |
| 846 | }; | 863 | }; |
| 847 | 864 | ||
| 848 | //#define DEBUG_FILE_SAVE | 865 | //#define DEBUG_FILE_SAVE_PARSEONLY_GENERAL |
| 849 | TEST_F (DecodeParseAPI, ParseOnly_General) { | 866 | TEST_F (DecodeParseAPI, ParseOnly_General) { |
| 850 | EncodeDecodeFileParamBase p; | 867 | EncodeDecodeFileParamBase p; |
| 851 | p.width = iWidth_; | 868 | p.width = iWidth_; |
| @@ -861,7 +878,7 @@ TEST_F (DecodeParseAPI, ParseOnly_General) { · 9 unmodified lines | |||
| 861 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | 878 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); |
| 862 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | 879 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); |
| 863 | uint32_t uiTargetLayerId = rand() % kiTotalLayer; //run only once | 880 | uint32_t uiTargetLayerId = rand() % kiTotalLayer; //run only once |
| 864 | #ifdef DEBUG_FILE_SAVE | 881 | #ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL |
| 865 | FILE* fDec = fopen ("output.264", "wb"); | 882 | FILE* fDec = fopen ("output.264", "wb"); |
| 866 | FILE* fEnc = fopen ("enc.264", "wb"); | 883 | FILE* fEnc = fopen ("enc.264", "wb"); |
| 867 | FILE* fExtract = fopen ("extract.264", "wb"); | 884 | FILE* fExtract = fopen ("extract.264", "wb"); |
| @@ -874,14 +891,14 @@ TEST_F (DecodeParseAPI, ParseOnly_General) { · 6 unmodified lines | |||
| 874 | 891 | ||
| 875 | while (iFrame < p.numframes) { | 892 | while (iFrame < p.numframes) { |
| 876 | //encode | 893 | //encode |
| 877 | EncodeOneFrame (iFrame); | 894 | EncodeOneFrame (0); |
| 878 | //extract target layer data | 895 | //extract target layer data |
| 879 | encToDecData (info, iLen); | 896 | encToDecData (info, iLen); |
| 880 | #ifdef DEBUG_FILE_SAVE | 897 | #ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL |
| 881 | fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fEnc); | 898 | fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fEnc); |
| 882 | #endif | 899 | #endif |
| 883 | ExtractDidNal (&info, iLen, &m_SLostSim, uiTargetLayerId); | 900 | ExtractDidNal (&info, iLen, &m_SLostSim, uiTargetLayerId); |
| 884 | #ifdef DEBUG_FILE_SAVE | 901 | #ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL |
| 885 | fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fExtract); | 902 | fwrite (info.sLayerInfo[0].pBsBuf, iLen, 1, fExtract); |
| 886 | #endif | 903 | #endif |
| 887 | //parseonly | 904 | //parseonly |
| @@ -896,10 +913,10 @@ TEST_F (DecodeParseAPI, ParseOnly_General) { · 8 unmodified lines | |||
| 896 | iLen = 0; | 913 | iLen = 0; |
| 897 | int i = 0; | 914 | int i = 0; |
| 898 | while (i < BsInfo_.iNalNum) { | 915 | while (i < BsInfo_.iNalNum) { |
| 899 | iLen += BsInfo_.iNalLenInByte[i]; | 916 | iLen += BsInfo_.pNalLenInByte[i]; |
| 900 | i++; | 917 | i++; |
| 901 | } | 918 | } |
| 902 | #ifdef DEBUG_FILE_SAVE | 919 | #ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL |
| 903 | fwrite (BsInfo_.pDstBuff, iLen, 1, fDec); | 920 | fwrite (BsInfo_.pDstBuff, iLen, 1, fDec); |
| 904 | #endif | 921 | #endif |
| 905 | SHA1Input (&ctx_, BsInfo_.pDstBuff, iLen); | 922 | SHA1Input (&ctx_, BsInfo_.pDstBuff, iLen); |
| @@ -909,10 +926,10 @@ TEST_F (DecodeParseAPI, ParseOnly_General) { · 3 unmodified lines | |||
| 909 | unsigned char digest[SHA_DIGEST_LENGTH]; | 926 | unsigned char digest[SHA_DIGEST_LENGTH]; |
| 910 | SHA1Result (&ctx_, digest); | 927 | SHA1Result (&ctx_, digest); |
| 911 | if (!HasFatalFailure()) { | 928 | if (!HasFatalFailure()) { |
| 912 | CompareHashAnyOf (digest, pHashStr[uiTargetLayerId], sizeof *pHashStr / sizeof **pHashStr); | 929 | CompareHashAnyOf (digest, pHashStr[uiTargetLayerId], sizeof * pHashStr / sizeof** pHashStr); |
| 913 | } | 930 | } |
| 914 | } //while | 931 | } //while |
| 915 | #ifdef DEBUG_FILE_SAVE | 932 | #ifdef DEBUG_FILE_SAVE_PARSEONLY_GENERAL |
| 916 | fclose (fEnc); | 933 | fclose (fEnc); |
| 917 | fclose (fExtract); | 934 | fclose (fExtract); |
| 918 | fclose (fDec); | 935 | fclose (fDec); |
| @@ -947,7 +964,7 @@ TEST_F (DecodeParseAPI, ParseOnly_SpecSliceLoss) { · 28 unmodified lines | |||
| 947 | 964 | ||
| 948 | while (iFrame < p.numframes) { | 965 | while (iFrame < p.numframes) { |
| 949 | //encode | 966 | //encode |
| 950 | EncodeOneFrame (iFrame); | 967 | EncodeOneFrame (0); |
| 951 | //parseonly | 968 | //parseonly |
| 952 | if (iFrame == iMissedPicNum) { //make current frame partly missing | 969 | if (iFrame == iMissedPicNum) { //make current frame partly missing |
| 953 | //Frame: P, first slice loss | 970 | //Frame: P, first slice loss |
| @@ -979,5 +996,197 @@ TEST_F (DecodeParseAPI, ParseOnly_SpecSliceLoss) { · 25 unmodified lines | |||
| 979 | } //while | 996 | } //while |
| 980 | } | 997 | } |
| 981 | 998 | ||
| 999 | //Test parseonly crash cases | ||
| 1000 | class DecodeParseCrashAPI : public DecodeParseAPI { | ||
| 1001 | public: | ||
| 1002 | DecodeParseCrashAPI() { | ||
| 1003 | } | ||
| 1004 | void SetUp() { | ||
| 1005 | DecodeParseAPI::SetUp(); | ||
| 1006 | iWidth_ = 1280; | ||
| 1007 | iHeight_ = 720; | ||
| 1008 | |||
| 1009 | ucBuf_ = NULL; | ||
| 1010 | ucBuf_ = new unsigned char[1000000]; | ||
| 1011 | ASSERT_TRUE (ucBuf_ != NULL); | ||
| 1012 | |||
| 1013 | } | ||
| 1014 | void TearDown() { | ||
| 1015 | DecodeParseAPI::TearDown(); | ||
| 1016 | if (NULL != ucBuf_) { | ||
| 1017 | delete[] ucBuf_; | ||
| 1018 | ucBuf_ = NULL; | ||
| 1019 | } | ||
| 1020 | ASSERT_TRUE (ucBuf_ == NULL); | ||
| 1021 | } | ||
| 1022 | |||
| 1023 | protected: | ||
| 1024 | unsigned char* ucBuf_; | ||
| 1025 | }; | ||
| 1026 | |||
| 1027 | //#define DEBUG_FILE_SAVE_PARSE_CRA1 | ||
| 1028 | TEST_F (DecodeParseCrashAPI, ParseOnlyCrash_General) { | ||
| 1029 | if (fYuv_) | ||
| 1030 | fclose (fYuv_); | ||
| 1031 | const char* sFileName = "res/Cisco_Absolute_Power_1280x720_30fps.yuv"; | ||
| 1032 | #if defined(ANDROID_NDK) | ||
| 1033 | std::string filename = std::string ("/sdcard/") + sFileName; | ||
| 1034 | ASSERT_TRUE ((fYuv_ = fopen (filename.c_str(), "rb")) != NULL); | ||
| 1035 | #else | ||
| 1036 | ASSERT_TRUE ((fYuv_ = fopen (sFileName, "rb")) != NULL); | ||
| 1037 | #endif | ||
| 1038 | uint32_t uiGet; | ||
| 1039 | encoder_->Uninitialize(); | ||
| 1040 | //do tests until crash | ||
| 1041 | unsigned int uiLoopRound = 0; | ||
| 1042 | unsigned char* pucBuf = ucBuf_; | ||
| 1043 | int iDecAuSize; | ||
| 1044 | #ifdef DEBUG_FILE_SAVE_PARSE_CRA1 | ||
| 1045 | //open file to save tested BS | ||
| 1046 | FILE* fDataFile = fopen ("test_parseonly_crash.264", "wb"); | ||
| 1047 | FILE* fLenFile = fopen ("test_parseonly_crash_len.log", "w"); | ||
| 1048 | int iFileSize = 0; | ||
| 1049 | #endif | ||
| 1050 | |||
| 1051 | do { | ||
| 1052 | #ifdef DEBUG_FILE_SAVE_PARSE_CRA1 | ||
| 1053 | int iTotalFrameNum = (rand() % 1200) + 1; | ||
| 1054 | #else | ||
| 1055 | int iTotalFrameNum = (rand() % 100) + 1; | ||
| 1056 | #endif | ||
| 1057 | EncodeDecodeParamBase p = kParamArray[8]; //720p by default | ||
| 1058 | |||
| 1059 | //Initialize Encoder | ||
| 1060 | prepareParam (1, 4, p.width, p.height, p.frameRate, ¶m_); | ||
| 1061 | param_.iRCMode = RC_TIMESTAMP_MODE; | ||
| 1062 | param_.iTargetBitrate = p.iTarBitrate; | ||
| 1063 | param_.uiIntraPeriod = 0; | ||
| 1064 | param_.eSpsPpsIdStrategy = CONSTANT_ID; | ||
| 1065 | param_.bEnableBackgroundDetection = true; | ||
| 1066 | param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false; | ||
| 1067 | param_.bPrefixNalAddingCtrl = 0;// (rand() % 2) ? true : false; | ||
| 1068 | param_.iEntropyCodingModeFlag = 0; | ||
| 1069 | param_.bEnableFrameSkip = true; | ||
| 1070 | param_.iMultipleThreadIdc = 0; | ||
| 1071 | param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate; | ||
| 1072 | param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1; | ||
| 1073 | param_.sSpatialLayers[0].sSliceArgument.uiSliceMode = | ||
| 1074 | SM_FIXEDSLCNUM_SLICE; // (rand() % 2) ? SM_SIZELIMITED_SLICE : SM_SINGLE_SLICE; | ||
| 1075 | if (param_.sSpatialLayers[0].sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE) { | ||
| 1076 | param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 1400; | ||
| 1077 | param_.uiMaxNalSize = 1400; | ||
| 1078 | } else { | ||
| 1079 | param_.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 0; | ||
| 1080 | param_.uiMaxNalSize = 0; | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | int rv = encoder_->InitializeExt (¶m_); | ||
| 1084 | ASSERT_TRUE (rv == cmResultSuccess); | ||
| 1085 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 1086 | EXPECT_EQ (uiGet, (uint32_t)ERROR_CON_DISABLE); //default value should be ERROR_CON_SLICE_COPY | ||
| 1087 | int32_t iTraceLevel = WELS_LOG_QUIET; | ||
| 1088 | encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 1089 | decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &iTraceLevel); | ||
| 1090 | |||
| 1091 | //Start for enc/dec | ||
| 1092 | int iIdx = 0; | ||
| 1093 | unsigned char* pData[3] = { NULL }; | ||
| 1094 | |||
| 1095 | EncodeDecodeFileParamBase pInput; //to conform with old functions | ||
| 1096 | pInput.width = p.width; | ||
| 1097 | pInput.height = p.height; | ||
| 1098 | pInput.frameRate = p.frameRate; | ||
| 1099 | prepareEncDecParam (pInput); | ||
| 1100 | while (iIdx++ < iTotalFrameNum) { // loop in frame | ||
| 1101 | EncodeOneFrame (1); | ||
| 1102 | #ifdef DEBUG_FILE_SAVE_PARSE_CRA1 | ||
| 1103 | //reset file if file size large | ||
| 1104 | if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) { | ||
| 1105 | fclose (fDataFile); | ||
| 1106 | fclose (fLenFile); | ||
| 1107 | fDataFile = fopen ("test_parseonly_crash.264", "wb"); | ||
| 1108 | fLenFile = fopen ("test_parseonly_crash_len.log", "w"); | ||
| 1109 | iFileSize = 0; | ||
| 1110 | decoder_->Uninitialize(); | ||
| 1111 | |||
| 1112 | SDecodingParam decParam; | ||
| 1113 | memset (&decParam, 0, sizeof (SDecodingParam)); | ||
| 1114 | decParam.uiTargetDqLayer = UCHAR_MAX; | ||
| 1115 | decParam.eEcActiveIdc = ERROR_CON_DISABLE; | ||
| 1116 | decParam.bParseOnly = true; | ||
| 1117 | decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT; | ||
| 1118 | |||
| 1119 | rv = decoder_->Initialize (&decParam); | ||
| 1120 | ASSERT_EQ (0, rv); | ||
| 1121 | } | ||
| 1122 | #endif | ||
| 1123 | if (info.eFrameType == videoFrameTypeSkip) | ||
| 1124 | continue; | ||
| 1125 | //deal with packets | ||
| 1126 | unsigned char* pBsBuf; | ||
| 1127 | iDecAuSize = 0; | ||
| 1128 | pucBuf = ucBuf_; //init buf start pos for decoder usage | ||
| 1129 | for (int iLayerNum = 0; iLayerNum < info.iLayerNum; iLayerNum++) { | ||
| 1130 | SLayerBSInfo* pLayerBsInfo = &info.sLayerInfo[iLayerNum]; | ||
| 1131 | pBsBuf = info.sLayerInfo[iLayerNum].pBsBuf; | ||
| 1132 | int iTotalNalCnt = pLayerBsInfo->iNalCount; | ||
| 1133 | for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL | ||
| 1134 | int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt]; | ||
| 1135 | //packet loss | ||
| 1136 | int iLossRateRange = (uiLoopRound % 20) + 1; //1-100 | ||
| 1137 | int iLossRate = (rand() % iLossRateRange); | ||
| 1138 | bool bPacketLost = (rand() % 101) > (100 - | ||
| 1139 | iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS | ||
| 1140 | if (!bPacketLost) { //no loss | ||
| 1141 | memcpy (pucBuf, pBsBuf, iPacketSize); | ||
| 1142 | pucBuf += iPacketSize; | ||
| 1143 | iDecAuSize += iPacketSize; | ||
| 1144 | } | ||
| 1145 | //update bs info | ||
| 1146 | pBsBuf += iPacketSize; | ||
| 1147 | } //nal | ||
| 1148 | } //layer | ||
| 1149 | |||
| 1150 | #ifdef DEBUG_FILE_SAVE_PARSE_CRA1 | ||
| 1151 | //save to file | ||
| 1152 | if (iDecAuSize != 0) { | ||
| 1153 | fwrite (ucBuf_, 1, iDecAuSize, fDataFile); | ||
| 1154 | fflush (fDataFile); | ||
| 1155 | iFileSize += iDecAuSize; | ||
| 1156 | } | ||
| 1157 | |||
| 1158 | //save to len file | ||
| 1159 | unsigned long ulTmp[4]; | ||
| 1160 | ulTmp[0] = ulTmp[1] = ulTmp[2] = iIdx; | ||
| 1161 | ulTmp[3] = iDecAuSize; | ||
| 1162 | fwrite (ulTmp, sizeof (unsigned long), 4, fLenFile); // index, timeStamp, data size | ||
| 1163 | fflush (fLenFile); | ||
| 1164 | #endif | ||
| 1165 | |||
| 1166 | //decode | ||
| 1167 | pData[0] = pData[1] = pData[2] = 0; | ||
| 1168 | memset (&BsInfo_, 0, sizeof (SParserBsInfo)); | ||
| 1169 | |||
| 1170 | rv = decoder_->DecodeParser (ucBuf_, iDecAuSize, &BsInfo_); | ||
| 1171 | rv = decoder_->DecodeParser (NULL, 0, &BsInfo_); //reconstruction | ||
| 1172 | //guarantee decoder EC status | ||
| 1173 | decoder_->GetOption (DECODER_OPTION_ERROR_CON_IDC, &uiGet); | ||
| 1174 | EXPECT_EQ (uiGet, (uint32_t)ERROR_CON_DISABLE); | ||
| 1175 | } //frame | ||
| 1176 | uiLoopRound++; | ||
| 1177 | if (uiLoopRound >= (1 << 30)) | ||
| 1178 | uiLoopRound = 0; | ||
| 1179 | #ifdef DEBUG_FILE_SAVE_PARSE_CRA1 | ||
| 1180 | if (uiLoopRound % 10 == 0) | ||
| 1181 | printf ("run %d times.\n", uiLoopRound); | ||
| 1182 | } while (1); | ||
| 1183 | fclose (fDataFile); | ||
| 1184 | fclose (fLenFile); | ||
| 1185 | #else | ||
| 1186 | } | ||
| 1187 | while (0); | ||
| 1188 | #endif | ||
| 1189 | |||
| 1190 | } | ||
| 982 | 1191 | ||
| 983 | 1192 | ||