Showing the changes to test/encoder/EncUT_EncoderExt.cpp (1 of 7 files). Show all
Unified · Split
| @@ -4,6 +4,7 @@ · 3 unmodified lines | |||
| 4 | #include "codec_app_def.h" | 4 | #include "codec_app_def.h" |
| 5 | #include "svc_enc_slice_segment.h" | 5 | #include "svc_enc_slice_segment.h" |
| 6 | #include "test_stdint.h" | 6 | #include "test_stdint.h" |
| 7 | #include "utils/FileInputStream.h" | ||
| 7 | //TODO: consider using BaseEncoderTest class from #include "../BaseEncoderTest.h" | 8 | //TODO: consider using BaseEncoderTest class from #include "../BaseEncoderTest.h" |
| 8 | 9 | ||
| 9 | class EncoderInterfaceTest : public ::testing::Test { | 10 | class EncoderInterfaceTest : public ::testing::Test { |
| @@ -1054,3 +1055,104 @@ TEST_F (EncoderInterfaceTest, DiffResolutionCheck) { · 1044 unmodified lines | |||
| 1054 | // finish | 1055 | // finish |
| 1055 | pPtrEnc->Uninitialize(); | 1056 | pPtrEnc->Uninitialize(); |
| 1056 | } | 1057 | } |
| 1058 | |||
| 1059 | TEST_F (EncoderInterfaceTest, NalSizeChecking) { | ||
| 1060 | // int uiTraceLevel = WELS_LOG_DETAIL; | ||
| 1061 | // pPtrEnc->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel); | ||
| 1062 | |||
| 1063 | pParamExt->iPicWidth = 1280; | ||
| 1064 | pParamExt->iPicHeight = 720; | ||
| 1065 | pParamExt->iPicWidth += (rand() << 1) % IMAGE_VARY_SIZE; | ||
| 1066 | pParamExt->iPicHeight += (rand() << 1) % IMAGE_VARY_SIZE; | ||
| 1067 | pParamExt->fMaxFrameRate = 30; | ||
| 1068 | pParamExt->iTemporalLayerNum = rand()%3; | ||
| 1069 | pParamExt->iSpatialLayerNum = rand()%4; | ||
| 1070 | pParamExt->iNumRefFrame = AUTO_REF_PIC_COUNT; | ||
| 1071 | pParamExt->iSpatialLayerNum = WELS_CLIP3(pParamExt->iSpatialLayerNum,1,4); | ||
| 1072 | |||
| 1073 | pParamExt->iMultipleThreadIdc = 1;//multi-thread can't control size. will be fixed. | ||
| 1074 | pParamExt->iEntropyCodingModeFlag = rand()%2; | ||
| 1075 | int iMaxNalSize =rand()%5000; | ||
| 1076 | iMaxNalSize = WELS_CLIP3(iMaxNalSize,1000,5000); | ||
| 1077 | pParamExt->uiMaxNalSize = iMaxNalSize; | ||
| 1078 | for(int i = 0;i<pParamExt->iSpatialLayerNum;i++){ | ||
| 1079 | pParamExt->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_SIZELIMITED_SLICE; | ||
| 1080 | pParamExt->sSpatialLayers[i].sSliceArgument.uiSliceSizeConstraint = iMaxNalSize; | ||
| 1081 | pParamExt->sSpatialLayers[i].iVideoHeight = pParamExt->iPicHeight; | ||
| 1082 | pParamExt->sSpatialLayers[i].iVideoWidth = pParamExt->iPicWidth; | ||
| 1083 | int bitrate = rand()%3000000; | ||
| 1084 | pParamExt->sSpatialLayers[i].iSpatialBitrate = WELS_CLIP3(bitrate,500000,3000000) ; | ||
| 1085 | pParamExt->iTargetBitrate+= pParamExt->sSpatialLayers[i].iSpatialBitrate; | ||
| 1086 | pParamExt->sSpatialLayers[i].fFrameRate = 30; | ||
| 1087 | } | ||
| 1088 | int iResult = pPtrEnc->InitializeExt (pParamExt); | ||
| 1089 | const int kiFrameNumber = TEST_FRAMES; | ||
| 1090 | |||
| 1091 | m_iWidth = pParamExt->iPicWidth; | ||
| 1092 | m_iHeight = pParamExt->iPicHeight; | ||
| 1093 | m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1; | ||
| 1094 | delete []pYUV; | ||
| 1095 | pYUV = new unsigned char [m_iPicResSize]; | ||
| 1096 | FileInputStream fileStream; | ||
| 1097 | ASSERT_TRUE (fileStream.Open ("res/Cisco_Absolute_Power_1280x720_30fps.yuv")); | ||
| 1098 | PrepareOneSrcFrame(); | ||
| 1099 | for (int i = 0; i < kiFrameNumber; i ++) { | ||
| 1100 | if(fileStream.read (pYUV, m_iPicResSize) != m_iPicResSize){ | ||
| 1101 | int iStartX = rand() % (m_iPicResSize >> 1); | ||
| 1102 | int iEndX = (iStartX + (rand() % MEM_VARY_SIZE)) % m_iPicResSize; | ||
| 1103 | for (int j = iStartX; j < iEndX; j++) | ||
| 1104 | pYUV[j] = rand() % 256; | ||
| 1105 | |||
| 1106 | } | ||
| 1107 | iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | ||
| 1108 | EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | ||
| 1109 | pSrcPic->uiTimeStamp += 30; | ||
| 1110 | |||
| 1111 | for (int i = 0; i < sFbi.iLayerNum; ++i) { | ||
| 1112 | for (int j = 0; j < sFbi.sLayerInfo[i].iNalCount; ++j) { | ||
| 1113 | int length = sFbi.sLayerInfo[i].pNalLengthInByte[j]; | ||
| 1114 | EXPECT_LE (length, iMaxNalSize); | ||
| 1115 | } | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | } | ||
| 1119 | pParamExt->iPicWidth = 1280; | ||
| 1120 | pParamExt->iPicHeight = 720; | ||
| 1121 | pParamExt->iPicWidth += (rand() << 1) % IMAGE_VARY_SIZE; | ||
| 1122 | pParamExt->iPicHeight += (rand() << 1) % IMAGE_VARY_SIZE; | ||
| 1123 | m_iWidth = pParamExt->iPicWidth; | ||
| 1124 | m_iHeight = pParamExt->iPicHeight; | ||
| 1125 | m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1; | ||
| 1126 | delete []pYUV; | ||
| 1127 | pYUV = new unsigned char [m_iPicResSize]; | ||
| 1128 | |||
| 1129 | iResult = pPtrEnc->InitializeExt (pParamExt); | ||
| 1130 | PrepareOneSrcFrame(); | ||
| 1131 | |||
| 1132 | ENCODER_OPTION eOptionId = ENCODER_OPTION_SVC_ENCODE_PARAM_EXT; | ||
| 1133 | memcpy (pOption, pParamExt, sizeof (SEncParamExt)); | ||
| 1134 | pOption ->iPicWidth = m_iWidth; | ||
| 1135 | pOption ->iPicHeight = m_iHeight; | ||
| 1136 | iResult = pPtrEnc->SetOption (eOptionId, pOption); | ||
| 1137 | EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | ||
| 1138 | |||
| 1139 | for (int i = 0; i < kiFrameNumber; i ++) { | ||
| 1140 | int iStartX = rand() % (m_iPicResSize >> 1); | ||
| 1141 | int iEndX = (iStartX + (rand() % MEM_VARY_SIZE)) % m_iPicResSize; | ||
| 1142 | for (int j = iStartX; j < iEndX; j++) | ||
| 1143 | pYUV[j] = rand() % 256; | ||
| 1144 | |||
| 1145 | iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | ||
| 1146 | EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | ||
| 1147 | pSrcPic->uiTimeStamp += 30; | ||
| 1148 | |||
| 1149 | for (int i = 0; i < sFbi.iLayerNum; ++i) { | ||
| 1150 | for (int j = 0; j < sFbi.sLayerInfo[i].iNalCount; ++j) { | ||
| 1151 | int length = sFbi.sLayerInfo[i].pNalLengthInByte[j]; | ||
| 1152 | EXPECT_LE (length, iMaxNalSize); | ||
| 1153 | } | ||
| 1154 | } | ||
| 1155 | } | ||
| 1156 | iResult = pPtrEnc->Uninitialize(); | ||
| 1157 | EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | ||
| 1158 | } | ||