Showing the changes to test/encoder/EncUT_EncoderExt.cpp (1 of 7 files). Show all
Unified · Split
| @@ -636,6 +636,65 @@ TEST_F (EncoderInterfaceTest, BasicInitializeTestAutoAdjustment) { · 635 unmodified lines | ||
| 636 | 636 | EXPECT_GE (sEncParamBase.fMaxFrameRate, 1.0); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | +TEST_F (EncoderInterfaceTest, ForceIntraFrameSimulCastAVC) { | |
| 640 | + SEncParamExt sEncParamExt; | |
| 641 | + pPtrEnc->GetDefaultParams (&sEncParamExt); | |
| 642 | + sEncParamExt.iUsageType = CAMERA_VIDEO_REAL_TIME; | |
| 643 | + int iSpatialLayerNum = rand() % MAX_SPATIAL_LAYER_NUM; | |
| 644 | + sEncParamExt.iSpatialLayerNum = WELS_CLIP3 (iSpatialLayerNum, 1, MAX_SPATIAL_LAYER_NUM); | |
| 645 | + | |
| 646 | + | |
| 647 | + sEncParamExt.iPicWidth = 1280; | |
| 648 | + sEncParamExt.iPicHeight = 720; | |
| 649 | + sEncParamExt.iTargetBitrate = 0; //!=0 | |
| 650 | + sEncParamExt.iRCMode = RC_BITRATE_MODE; //-1, 0, 1, 2 | |
| 651 | + sEncParamExt.bEnableFrameSkip = false; | |
| 652 | + sEncParamExt.fMaxFrameRate = 30; //!=0 | |
| 653 | + sEncParamExt.bSimulcastAVC = 1; | |
| 654 | + | |
| 655 | + for (int iNum = sEncParamExt.iSpatialLayerNum - 1; iNum >= 0 ; iNum--) { | |
| 656 | + int iScale = 1 << ((sEncParamExt.iSpatialLayerNum - 1) - iNum); | |
| 657 | + sEncParamExt.sSpatialLayers[iNum].iVideoWidth = sEncParamExt.iPicWidth / iScale; | |
| 658 | + sEncParamExt.sSpatialLayers[iNum].iVideoHeight = sEncParamExt.iPicHeight / iScale; | |
| 659 | + sEncParamExt.sSpatialLayers[iNum].iSpatialBitrate = (sEncParamExt.sSpatialLayers[iNum].iVideoWidth * | |
| 660 | + sEncParamExt.sSpatialLayers[iNum].iVideoHeight) / 3; | |
| 661 | + sEncParamExt.iTargetBitrate += sEncParamExt.sSpatialLayers[iNum].iSpatialBitrate; | |
| 662 | + } | |
| 663 | +// int uiTraceLevel = WELS_LOG_INFO; | |
| 664 | +// pPtrEnc->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel); | |
| 665 | + int iResult = pPtrEnc->InitializeExt (&sEncParamExt); | |
| 666 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)) << "iUsageType = " << sEncParamExt.iUsageType << | |
| 667 | + ", iPicWidth = " << sEncParamExt.iPicWidth << ", iPicHeight = " << sEncParamExt.iPicHeight << ", iTargetBitrate = " << | |
| 668 | + sEncParamExt.iTargetBitrate << ", fMaxFrameRate = " << sEncParamExt.fMaxFrameRate; | |
| 669 | + | |
| 670 | + int kiFrameNumber = rand() % 100; | |
| 671 | + if (kiFrameNumber < 20) | |
| 672 | + kiFrameNumber = 20; | |
| 673 | + for (int i = 0; i < kiFrameNumber; i ++) { | |
| 674 | + PrepareOneSrcFrame(); | |
| 675 | + bool bForceIdr = (i == (kiFrameNumber / 2)); | |
| 676 | + int iLayerNum = rand() % MAX_SPATIAL_LAYER_NUM; | |
| 677 | + iLayerNum = WELS_CLIP3 (iSpatialLayerNum, 0, sEncParamExt.iSpatialLayerNum - 1); | |
| 678 | + if (bForceIdr) { | |
| 679 | + pPtrEnc->ForceIntraFrame (true, iLayerNum); | |
| 680 | + } | |
| 681 | + | |
| 682 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 683 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 684 | + if (bForceIdr) { | |
| 685 | + for (int i = 0; i < sFbi.iLayerNum; ++i) { | |
| 686 | + if (sFbi.sLayerInfo[i].uiSpatialId == iLayerNum) { | |
| 687 | + EXPECT_EQ (sFbi.sLayerInfo[i].eFrameType, static_cast<int> (videoFrameTypeIDR)); | |
| 688 | + } | |
| 689 | + } | |
| 690 | + } | |
| 691 | + } | |
| 692 | + | |
| 693 | + pPtrEnc->Uninitialize(); | |
| 694 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 695 | +} | |
| 696 | + | |
| 697 | + | |
| 639 | 698 | TEST_F (EncoderInterfaceTest, ForceIntraFrame) { |
| 640 | 699 | SEncParamBase sEncParamBase; |
| 641 | 700 | GetValidEncParamBase (&sEncParamBase); |
| @@ -1057,96 +1116,96 @@ TEST_F (EncoderInterfaceTest, DiffResolutionCheck) { · 415 unmodified lines | ||
| 1057 | 1116 | } |
| 1058 | 1117 | |
| 1059 | 1118 | 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; | |
| 1119 | + // int uiTraceLevel = WELS_LOG_DETAIL; | |
| 1120 | + // pPtrEnc->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel); | |
| 1090 | 1121 | |
| 1091 | − m_iWidth = pParamExt->iPicWidth; | |
| 1092 | − m_iHeight = pParamExt->iPicHeight; | |
| 1093 | − m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1; | |
| 1094 | − if(pYUV) | |
| 1095 | − delete []pYUV; | |
| 1096 | − pYUV = new unsigned char [m_iPicResSize]; | |
| 1097 | − ASSERT_TRUE (pYUV != NULL); | |
| 1098 | − FileInputStream fileStream; | |
| 1099 | − ASSERT_TRUE (fileStream.Open ("res/Cisco_Absolute_Power_1280x720_30fps.yuv")); | |
| 1100 | − PrepareOneSrcFrame(); | |
| 1101 | − for (int i = 0; i < kiFrameNumber; i ++) { | |
| 1102 | − if(fileStream.read (pYUV, m_iPicResSize) != m_iPicResSize){ | |
| 1103 | − break; | |
| 1104 | − } | |
| 1105 | − iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 1106 | − EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 1107 | − pSrcPic->uiTimeStamp += 30; | |
| 1108 | − | |
| 1109 | − for (int i = 0; i < sFbi.iLayerNum; ++i) { | |
| 1110 | − for (int j = 0; j < sFbi.sLayerInfo[i].iNalCount; ++j) { | |
| 1111 | − int length = sFbi.sLayerInfo[i].pNalLengthInByte[j]; | |
| 1112 | − EXPECT_LE (length, iMaxNalSize); | |
| 1113 | − } | |
| 1114 | − } | |
| 1122 | + pParamExt->iPicWidth = 1280; | |
| 1123 | + pParamExt->iPicHeight = 720; | |
| 1124 | + pParamExt->iPicWidth += (rand() << 1) % IMAGE_VARY_SIZE; | |
| 1125 | + pParamExt->iPicHeight += (rand() << 1) % IMAGE_VARY_SIZE; | |
| 1126 | + pParamExt->fMaxFrameRate = 30; | |
| 1127 | + pParamExt->iTemporalLayerNum = rand() % 3; | |
| 1128 | + pParamExt->iSpatialLayerNum = rand() % 4; | |
| 1129 | + pParamExt->iNumRefFrame = AUTO_REF_PIC_COUNT; | |
| 1130 | + pParamExt->iSpatialLayerNum = WELS_CLIP3 (pParamExt->iSpatialLayerNum, 1, 4); | |
| 1131 | + | |
| 1132 | + pParamExt->iMultipleThreadIdc = 1;//multi-thread can't control size. will be fixed. | |
| 1133 | + pParamExt->iEntropyCodingModeFlag = rand() % 2; | |
| 1134 | + int iMaxNalSize = rand() % 5000; | |
| 1135 | + iMaxNalSize = WELS_CLIP3 (iMaxNalSize, 1000, 5000); | |
| 1136 | + pParamExt->uiMaxNalSize = iMaxNalSize; | |
| 1137 | + for (int i = 0; i < pParamExt->iSpatialLayerNum; i++) { | |
| 1138 | + pParamExt->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_SIZELIMITED_SLICE; | |
| 1139 | + pParamExt->sSpatialLayers[i].sSliceArgument.uiSliceSizeConstraint = iMaxNalSize; | |
| 1140 | + pParamExt->sSpatialLayers[i].iVideoHeight = pParamExt->iPicHeight; | |
| 1141 | + pParamExt->sSpatialLayers[i].iVideoWidth = pParamExt->iPicWidth; | |
| 1142 | + int bitrate = rand() % 3000000; | |
| 1143 | + pParamExt->sSpatialLayers[i].iSpatialBitrate = WELS_CLIP3 (bitrate, 500000, 3000000) ; | |
| 1144 | + pParamExt->iTargetBitrate += pParamExt->sSpatialLayers[i].iSpatialBitrate; | |
| 1145 | + pParamExt->sSpatialLayers[i].fFrameRate = 30; | |
| 1146 | + } | |
| 1147 | + int iResult = pPtrEnc->InitializeExt (pParamExt); | |
| 1148 | + const int kiFrameNumber = TEST_FRAMES; | |
| 1115 | 1149 | |
| 1116 | − } | |
| 1117 | − pParamExt->iPicWidth = 1280; | |
| 1118 | − pParamExt->iPicHeight = 720; | |
| 1119 | − pParamExt->iPicWidth += (rand() << 1) % IMAGE_VARY_SIZE; | |
| 1120 | − pParamExt->iPicHeight += (rand() << 1) % IMAGE_VARY_SIZE; | |
| 1121 | − m_iWidth = pParamExt->iPicWidth; | |
| 1122 | − m_iHeight = pParamExt->iPicHeight; | |
| 1123 | − m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1; | |
| 1150 | + m_iWidth = pParamExt->iPicWidth; | |
| 1151 | + m_iHeight = pParamExt->iPicHeight; | |
| 1152 | + m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1; | |
| 1153 | + if (pYUV) | |
| 1124 | 1154 | delete []pYUV; |
| 1125 | − pYUV = new unsigned char [m_iPicResSize]; | |
| 1126 | − ASSERT_TRUE (pYUV != NULL); | |
| 1127 | − iResult = pPtrEnc->InitializeExt (pParamExt); | |
| 1128 | − PrepareOneSrcFrame(); | |
| 1129 | − | |
| 1130 | − ENCODER_OPTION eOptionId = ENCODER_OPTION_SVC_ENCODE_PARAM_EXT; | |
| 1131 | − memcpy (pOption, pParamExt, sizeof (SEncParamExt)); | |
| 1132 | − pOption ->iPicWidth = m_iWidth; | |
| 1133 | − pOption ->iPicHeight = m_iHeight; | |
| 1134 | − iResult = pPtrEnc->SetOption (eOptionId, pOption); | |
| 1155 | + pYUV = new unsigned char [m_iPicResSize]; | |
| 1156 | + ASSERT_TRUE (pYUV != NULL); | |
| 1157 | + FileInputStream fileStream; | |
| 1158 | + ASSERT_TRUE (fileStream.Open ("res/Cisco_Absolute_Power_1280x720_30fps.yuv")); | |
| 1159 | + PrepareOneSrcFrame(); | |
| 1160 | + for (int i = 0; i < kiFrameNumber; i ++) { | |
| 1161 | + if (fileStream.read (pYUV, m_iPicResSize) != m_iPicResSize) { | |
| 1162 | + break; | |
| 1163 | + } | |
| 1164 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 1135 | 1165 | EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); |
| 1166 | + pSrcPic->uiTimeStamp += 30; | |
| 1136 | 1167 | |
| 1137 | − for (int i = 0; i < kiFrameNumber; i ++) { | |
| 1138 | − PrepareOneSrcFrame(); | |
| 1139 | − iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 1140 | − EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 1141 | − pSrcPic->uiTimeStamp += 30; | |
| 1142 | − | |
| 1143 | − for (int i = 0; i < sFbi.iLayerNum; ++i) { | |
| 1144 | − for (int j = 0; j < sFbi.sLayerInfo[i].iNalCount; ++j) { | |
| 1145 | − int length = sFbi.sLayerInfo[i].pNalLengthInByte[j]; | |
| 1146 | − EXPECT_LE (length, iMaxNalSize); | |
| 1147 | − } | |
| 1148 | − } | |
| 1168 | + for (int i = 0; i < sFbi.iLayerNum; ++i) { | |
| 1169 | + for (int j = 0; j < sFbi.sLayerInfo[i].iNalCount; ++j) { | |
| 1170 | + int length = sFbi.sLayerInfo[i].pNalLengthInByte[j]; | |
| 1171 | + EXPECT_LE (length, iMaxNalSize); | |
| 1172 | + } | |
| 1149 | 1173 | } |
| 1150 | − iResult = pPtrEnc->Uninitialize(); | |
| 1174 | + | |
| 1175 | + } | |
| 1176 | + pParamExt->iPicWidth = 1280; | |
| 1177 | + pParamExt->iPicHeight = 720; | |
| 1178 | + pParamExt->iPicWidth += (rand() << 1) % IMAGE_VARY_SIZE; | |
| 1179 | + pParamExt->iPicHeight += (rand() << 1) % IMAGE_VARY_SIZE; | |
| 1180 | + m_iWidth = pParamExt->iPicWidth; | |
| 1181 | + m_iHeight = pParamExt->iPicHeight; | |
| 1182 | + m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1; | |
| 1183 | + delete []pYUV; | |
| 1184 | + pYUV = new unsigned char [m_iPicResSize]; | |
| 1185 | + ASSERT_TRUE (pYUV != NULL); | |
| 1186 | + iResult = pPtrEnc->InitializeExt (pParamExt); | |
| 1187 | + PrepareOneSrcFrame(); | |
| 1188 | + | |
| 1189 | + ENCODER_OPTION eOptionId = ENCODER_OPTION_SVC_ENCODE_PARAM_EXT; | |
| 1190 | + memcpy (pOption, pParamExt, sizeof (SEncParamExt)); | |
| 1191 | + pOption ->iPicWidth = m_iWidth; | |
| 1192 | + pOption ->iPicHeight = m_iHeight; | |
| 1193 | + iResult = pPtrEnc->SetOption (eOptionId, pOption); | |
| 1194 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 1195 | + | |
| 1196 | + for (int i = 0; i < kiFrameNumber; i ++) { | |
| 1197 | + PrepareOneSrcFrame(); | |
| 1198 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 1151 | 1199 | EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); |
| 1200 | + pSrcPic->uiTimeStamp += 30; | |
| 1201 | + | |
| 1202 | + for (int i = 0; i < sFbi.iLayerNum; ++i) { | |
| 1203 | + for (int j = 0; j < sFbi.sLayerInfo[i].iNalCount; ++j) { | |
| 1204 | + int length = sFbi.sLayerInfo[i].pNalLengthInByte[j]; | |
| 1205 | + EXPECT_LE (length, iMaxNalSize); | |
| 1206 | + } | |
| 1207 | + } | |
| 1208 | + } | |
| 1209 | + iResult = pPtrEnc->Uninitialize(); | |
| 1210 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 1152 | 1211 | } |